Commit Graph

2599 Commits

Author SHA1 Message Date
Luciano Almeida
50130b052f [NFC] Adjusting a couple of comments for clarity 2023-09-05 18:18:40 -03:00
Luciano Almeida
0300139257 [Sema][Diagnostics] Improving diagnostics for function type coerce failure 2023-09-03 15:18:04 -03:00
Hamish Knight
c0ae9b950b Move out-of-place ThenStmt checking to constraint generation 2023-09-01 14:32:15 +01:00
Hamish Knight
6ee44f09b4 Introduce then statements
These allow multi-statement `if`/`switch` expression
branches that can produce a value at the end by
saying `then <expr>`. This is gated behind
`-enable-experimental-feature ThenStatements`
pending evolution discussion.
2023-09-01 14:32:14 +01:00
Pavel Yaskevich
ed046e5efe Merge pull request #68215 from xedin/rdar-112426330
[CSSimplify] Rework detection of missing/extraneous arguments in closure
2023-08-31 13:15:52 -07:00
Slava Pestov
361d49a843 AST: Remove DeclContext::getSelfProtocolType() 2023-08-30 15:15:08 -04:00
Pavel Yaskevich
1c8b8d981a [CSSimplify] Rework detection of missing/extraneous arguments in closure
Checking type variables is no longer necessary because constraint
system now stores types of all closures it encountered, this makes
detection logic more reliable as well.

Resolves: rdar://112426330
2023-08-30 10:47:41 -07:00
Pavel Yaskevich
b5b335c499 [CSSimplify] Modernize binary function argument reordering fix
The fix used incorrect locators for attempted argument conversions,
didn't check whether arguments are already re-ordered and allowed
fixes as visible side-effects from checking.

Resolves: rdar://114341979
2023-08-24 17:10:14 -07:00
Amritpan Kaur
71a94a859b [CSSimplify] Add checks for invalid keypath member refs 2023-08-21 13:01:22 -07:00
Pavel Yaskevich
d725e38cd2 Merge pull request #67971 from amritpan/kp-function-application
[ConstraintSystem] Resolve key path function applications via resolveKeyPath
2023-08-16 23:12:44 -07:00
Amritpan Kaur
f4764b32bf [CSSimplify] Attempt tryMatchRootAndValueFromType even if
missing member.
2023-08-16 14:28:05 -07:00
Amritpan Kaur
feb0f34993 [CSSimplify] For function type binding for key path types, add flag
to allow it to go through resolveKeyPath in matchTypesBindTypeVar.
2023-08-16 12:53:54 -07:00
Pavel Yaskevich
b34f9720e4 [CSSimplify] Adjust {Any, Partial}KeyPath bindings right before resolving
A type variable that represents a key path literal cannot be bound
directly to `AnyKeyPath` or `PartialKeyPath`, such types could only
be used for conversions.
It used to be the task of the binding inference to infer `AnyKeyPath`
and `PartiaKeyPath` as a `KeyPath` using previously generated type
variables for a root and value associated with key path literal
(previously stored in the locator).

Recently we switched over to storing key path information in the
constraint system and introduced `resolveKeyPath` method to gain
more control over how key path type variable gets assigned.

Getting information from the constraint system creates a problem
for the inference because "undo" for some bindings would be run
after solver scope has been erased, so instead of modifying bindings
in `inferFromRelational`, let's do that in `resolveKeyPath` right
before the key path type variable gets bound which seems to be a
better place for that logic anyway.

Resolves: rdar://113760727
2023-08-15 13:50:54 -07:00
Pavel Yaskevich
cedbdf920c Merge pull request #67759 from xedin/rdar-112617922
[CSSimplify] Relax `isBindable` requirements for pack expansion variables
2023-08-15 09:00:12 -07:00
Slava Pestov
c26cafc47a AST: Remove bogus PackExpansionType logic in lookupConformance() 2023-08-09 18:28:22 -04:00
Pavel Yaskevich
27413f5624 [CSSimplify] Relax isBindable requirements for pack expansion variables
If type variable we are about to bind represents a pack
expansion type, allow the binding to happen regardless of
what the \c type is, because contextual type is just a hint
in this situation and type variable would be bound to its
opened type instead.

Resolves: rdar://112617922
2023-08-04 16:49:20 -07:00
Pavel Yaskevich
3dff3e5a49 [CSSimplify] Avoid eager matching between pack expansion and its contextual type
This is effectively a premature optimization. Contextual type might
not be fully resolved yet, so let's give solver a chance to do it for us.
2023-08-04 11:21:16 -07:00
Pavel Yaskevich
043d2aa3dd [CSSimplify] NFC: Straighten checking of type variable passed to resolvePackExpansion
The type variable should always be one for pack expansion type which
implies that locator always ends at `PackExpansionType`.
2023-08-03 14:11:09 -07:00
Hamish Knight
e22180ba2e [CS] Add missing break 2023-08-03 13:00:12 +01:00
Amritpan Kaur
3604551172 [CSSimplify] Handle keypathvalue constraint locator 2023-07-31 09:50:32 -07:00
Amritpan Kaur
36031f3b3d [CSSimplify] Prevent contextual type failure fix record 2023-07-31 09:50:27 -07:00
Pavel Yaskevich
9b3980573f Merge pull request #67297 from amritpan/build-out-resolve-kp
[ConstraintSystem] Set up keypath expressions typechecking
2023-07-27 09:52:09 -07:00
Amritpan Kaur
3140c12691 [CSSimplify] If keypath is malformed, do not attempt to 2023-07-26 20:32:30 -07:00
Amritpan Kaur
6296be7464 [CSSimplify] If bound type var is more optional
than a binding type var, attempt to match
types and solve.
2023-07-26 20:32:26 -07:00
Amritpan Kaur
5fa54dfc4d [CSSimplify] Delay matchTypes for key path values
until they are directly bound.
2023-07-25 22:16:28 -07:00
Pavel Yaskevich
b8915fa39a [CSSimplify] Repair should ignore situations where assignment source or destination are a hole
If either source or destination type is a hole conversion should
just be ignored because there is no r-value or other mismatch that
could be diagnosed in this case.
2023-07-24 12:09:04 -07:00
Pavel Yaskevich
9e388b40e1 [CSSimplify] Check that raw type is not a hole before checking RawRepresentable conformance
Placeholder types just like type variables are set up to return
a conformance ref which, in this case, would mean that we'd produce
an invalid diagnostic.
2023-07-24 11:15:50 -07:00
Pavel Yaskevich
33a37b9516 Merge pull request #67377 from xedin/rdar-112090069
[CSSimplify] Extend same-shape detection to account for pack archetypes
2023-07-24 10:01:29 -07:00
Pavel Yaskevich
eb86497493 [CSSimplify] Deplay member lookup until single-element tuple with pack expansion is sufficiently resolved
Such tuples should be treated specially because once pack expansion
is sufficiently resolved they'd get exploded and the resulting type
is what member lookup should use as a base.

Resolves: rdar://110721928
2023-07-21 13:10:34 -07:00
Pavel Yaskevich
5a5edcafc3 [CSSimplify] Extend same-shape detection to account for pack archetypes
`same-shape` mismatch detection logic shouldn't expect that types are
always packs because they could be either invalid (i.e. Void) or pack
archetypes too.

Resolves: rdar://112090069
2023-07-20 22:50:22 -07:00
Pavel Yaskevich
59908eeb0d [CSGen] Suppress favoring in presence of non-disfavored variadic generic overloads
Since this type of early favoring checks number of arguments and matches
labels it would always favor non-variadic overloads which is incorrect.
2023-07-20 10:02:59 -07:00
Sophia Poirier
8173c721eb [ConstraintSystem] remove TupleType::isSingleUnlabeledPackExpansion in favor of constraints::getPatternTypeOfSingleUnlabeledPackExpansionTuple 2023-07-19 15:10:40 -07:00
Amritpan Kaur
e7853368db [CSSimplify] Resolve key path expression
by creating a BoundGenericType for the keypath expr
with the keypath base and replacing the value with
the value typeVar that will be resolved when the value
typeVar is directly bound.
2023-07-18 15:16:07 -07:00
Sophia Poirier
6e47a36808 Merge pull request #67292 from sophiapoirier/pack-stored-propety-shadows-global
[ConstraintSystem] implement implicit pack materialization for abstract tuples instead of explicit '.element'
2023-07-14 15:11:05 -07:00
Sophia Poirier
fa41015ae4 [ConstraintSystem] implement implicit pack materialization for abstract tuples instead of explicit '.element' 2023-07-14 10:32:38 -07:00
Slava Pestov
8a132c0248 Sema: Replace some usages of mapPackTypeIntoElementContext() with mapContextualPackTypeIntoElementContext() 2023-07-12 18:02:14 -04:00
Pavel Yaskevich
4760b95282 Merge pull request #67183 from xedin/convert-effects-into-storageRestrictions
[AST/Sema] Implement @storageRestrictions attribute
2023-07-11 11:57:14 -07:00
Pavel Yaskevich
62719b05ac Merge pull request #67157 from amritpan/kp-declcontext
[Constraint System] Store key path root, value, and decl context for use across constraint system.
2023-07-10 23:09:09 -07:00
Amritpan Kaur
1d8e7ef2fe [CSGen] Record keypath for use across constraint system. 2023-07-10 15:54:22 -07:00
Sima Nerush
83a7e05608 [Sema] Record a fix about extra parens for computed properties (#67042)
Co-authored-by: Sima Nerush <sima_nerush@apple.com>
2023-07-10 14:34:32 -07:00
Alex Hoppen
6cec68e302 [IDE] Ignore score kinds that represent implicit conversions when solving for code completion
Ignore conversion score increases during code completion to make sure we don't filter solutions that might start receiving the best score based on a choice of the code completion token.
2023-07-07 19:50:46 +02:00
Pavel Yaskevich
e337a3947d [ConstraintSystem] Implement tap expression checking in the solver
Generate a conjunction for each tap expression body as soon as it
gets a contextual type instead of separate post-factum type-checking
via `typeCheckTapBody`.
2023-07-07 19:50:46 +02:00
Pavel Yaskevich
28a39d6df1 [AST] NFC: Add a way to request initialized/accesses properties from init accessor 2023-07-07 10:00:36 -07:00
Andrew Savonichev
b6acb6fbef [AutoDiff] Check @noDerivative for function type comparison (#67121)
As described in the issue #62922, the compiler should not allow to discard @noDerivative attribute and keep @differentiable. The patch adds a diagnostic for this case.

Resolves #62922.
2023-07-06 15:21:30 -07:00
Pavel Yaskevich
c50263c730 Merge pull request #66971 from xedin/fix-specialization-issues
[ConstraintSystem] Fix a couple of issues related to generic specialization
2023-06-29 12:25:11 -07:00
Pavel Yaskevich
de729e2a0c [CSSimplify] Adjust typalias declaration handling for generic specialization 2023-06-29 00:06:00 -07:00
Pavel Yaskevich
b9b21fc597 [CSSimplify] Detect and diagnose attempts to specialize types with invalid number of arguments 2023-06-27 17:24:39 -07:00
Pavel Yaskevich
cd057bba27 [CSFix] Add a fix to detect type specialization arity mismatches
The situations where number of parameters and arguments didn't match.
2023-06-27 17:24:39 -07:00
Pavel Yaskevich
2bbda09043 [CSSimplify] Detect and diagnose attempts to specialize non-generic types/aliases 2023-06-27 17:24:38 -07:00
Pavel Yaskevich
ab2f47b92f [CSFix] Add a fix to detect invalid specialization of non-generic types 2023-06-27 17:24:38 -07:00