Commit Graph

672 Commits

Author SHA1 Message Date
Holly Borla
138c1170ea [CSGen] Declare generateWrappedPropertyTypeConstraints as a method
on ConstraintSystem.
2021-09-02 17:37:44 -07:00
Pavel Yaskevich
52307608e4 [ConstraintSystem] Get pattern from pattern binding for uninitialized variable targets
Instead of passing pattern directly, let's fetch it from the pattern
binding and remove extra argument from `SolutionApplicationTarget::forUninitializedVar`.
2021-09-02 11:41:43 -07:00
Hamish Knight
3e28bbbd2c Update for review feedback
- Remove OriginalArguments in favor of storing the
pre-rewritten argument list, which simplifies things
nicely
- Adopt llvm::indexed_accessor_iterator
2021-09-01 18:40:29 +01:00
Hamish Knight
8c2b88abc0 [CS] Adopt ArgumentList
- Explicitly limit favoring logic to only handle
unary args, this seems to have always been the
case, but needs to be handled explicitly now that
argument lists aren't exprs
- Update the ConstraintLocator simplification to
handle argument lists
- Store a mapping of locators to argument lists
in the constraint system
- Abstract more logic into a getArgumentLocator
method which retrieves an argument-to-param locator
from an argument anchor expr
2021-09-01 18:40:25 +01:00
Pavel Yaskevich
c1269883b8 [ConstraintSystem] Allow IUO types to be unrelated while forming a disjunction
Detect situations when type of a declaration hasn't been resolved yet
(one-way constraints would use a type variable to represent a type of IUO pattern),
and use additional type variable and a constraint to represent an
object type of a future optional type.

Resolves: SR-14893
Resolves: rdar://80271666
2021-08-30 11:59:43 -07:00
Pavel Yaskevich
83cc91869b Merge pull request #39031 from xedin/fix-uninit-var-pattern-binding
[ConstraintSystem] Store pattern binding associated with uninitialize…
2021-08-25 09:49:30 -07:00
Pavel Yaskevich
609ca72302 [ConstraintSystem] Store pattern binding associated with uninitialized variable
This is a follow-up to the uninitialized variable generalization.
Pattern binding declaration has to be stored together with the
variable because all of the entries in `SolutionApplicationTarget`
form a union.
2021-08-24 15:31:36 -07:00
Pavel Yaskevich
57c4b6a336 [ResultBuilders] Fix handling of multiple pattern bindings
`SolutionApplicationTargetsKey` was constructing pattern binding
entries with incorrect `kind`, which led to crashes for pattern
bindings with multiple initialized entries.
2021-08-24 12:37:12 -07:00
Pavel Yaskevich
d64c19ec37 [ConstraintSystem] Solution application target for uninitialized pattern binding 2021-08-17 14:23:57 -07:00
Pavel Yaskevich
a72b057829 [ConstraintSystem] Generalize solution target to support un-initialized variables
Rename `uninitializedWrappedVar` kind to `uninitializedVar` and
allow storage of patterns and indices into pattern binding entry.
2021-08-17 14:23:57 -07:00
Pavel Yaskevich
88e090b85c Merge pull request #38770 from xedin/rdar-56167233
[ConstraintSystem] Relax the left-over information check in `ComponentStep`
2021-08-06 15:15:32 -07:00
Holly Borla
9f71ee1b0a Merge pull request #38766 from hborla/wrapped-argument-conversions
[Property Wrappers] Fix a bug where wrapped arguments were not properly coerced to the wrapper generator input type.
2021-08-06 13:36:37 -04:00
Pavel Yaskevich
d8cdbcd0c7 [ConstraintSystem] Add InvalidState flag to indicate that any attempt to solve should fail
As soon as `InvalidState` flag is set solving of the constraint
system as aborted and all subsequent calls to `solveImpl` would
produce no solutions.
2021-08-06 10:03:05 -07:00
Pavel Yaskevich
1509accca2 [ConstraintSystem] Open only directly declared opaque types related to return statements (#38762)
* [ConstraintSystem] NFC: Rename `openOpaqueTypeRec` and make `openOpaqueType` private for individual types

* [ConstraintSystem] Require a contextual purpose for `openOpaqueType(Type, ...)`

Some of the contexts require special handling e.g. return type of a function
can only open directly declared opaque result type(s), this would be
implemented in a follow-up commit.

* [ConstraintSystem] Open only directly declared opaque types related to return statements

Re-establish a check which would only open opaque types directly
declared in the return type of a function/accessor declaration,
otherwise constraint system would end up with type variables it
has no context for if the type had generic parameters.

Resolves: rdar://81531010
2021-08-05 20:45:46 -04:00
Holly Borla
81f51804d6 [Property Wrappers] Unify the initializer type checking code paths between
wrapped parameters and wrapped properties.

This fixes a bug where @autoclosure was not propagated from the wrapper's
init(wrappedValue:) to a wrapped argument.
2021-08-05 15:38:28 -04:00
Hamish Knight
21e8a320ec [CS] Better handle paren fix-its for unresolved chains
I missed this case when previously improving the
logic here. As it turns out, using the raw anchor
as the root expression from which to derive parent
information is insufficient. This is because it
may not capture relevant parent exprs not a part
of the fix locator.

Instead, pass down a function that can be used to
derive the parent expressions from the constraint
system's own parent map. Also make sure to assign
to `expr` for the UnresolvedMemberChainResultExpr
case to make sure we correctly check for it as a
sub-expression.

Finally, now that we're looking at more parent
exprs, add logic to handle `try` and `await`
parents, as well as ClosureExprs and
CollectionExprs. I couldn't come up with a test
case for CollectionExpr, as we emit different
diagnostics in that case, but it's probably better
to tend on the side of being more future proof
there.

rdar://81512079
2021-08-04 14:34:24 +01:00
willtunnels
319b3e64aa Add support for opaque result types in structural positions (#38392)
* [TypeResolver][TypeChecker] Add support for structural opaque result types

* [TypeResolver][TypeChecker] Clean up changes that add structural opaque result types
2021-08-03 23:45:02 -04:00
Alex Hoppen
f42f961faf [Sema] Copy key path component types when merging solutions
In 2eeff365b1 I forgot to copy key path component types when applying a solution to the constraint system. That caused a crash in key path code completion.

Fixes rdar://81118700 [SR-14979]
2021-07-30 11:07:21 +02:00
Alex Hoppen
55f812ebf6 Merge pull request #38389 from ahoppen/pr/record-keypath-component-types-in-solution
[CodeCompletion] Record key path component types in the constraint system solution
2021-07-21 11:19:28 +02:00
Pavel Yaskevich
0ee1fb246f [ConstraintSystem] NFC: Add an ability to check binding producers for exhaustion 2021-07-16 14:18:01 -07:00
Pavel Yaskevich
f224202fbf [ConstraintSystem] NFC: Require all binding producers to implement needsToComputeNext
Instead of defaulting to `false`, let's make implementers of `BindingProducer`
consider what needs to happen.
2021-07-16 14:16:42 -07:00
Pavel Yaskevich
3e73f88512 [ConstraintSystem] NFC: Use stored result type while generating constraints for closures
Instead of passing/storing result type to constraint generator,
let's retrieve it from the constraint system when needed.
2021-07-14 16:28:26 -07:00
Alex Hoppen
2eeff365b1 [CodeCompletion] Record key path component types in the constraint system solution
The added test case fails because the result builder inside `List2` is being type checked twice: Once for every overload of `List2`. Because of the way that result builders are being type checked right now, each overload of `List2` creates a new type variable for the key components in `foo` and the constraint system only keeps track of the key path component -> type mapping for the last solution discovered.

When we are now trying to look up the type of the first key path component for the first solution, the constraint system returns the type variable that is being used by the second solution and simplifying that type variable through the first solution fails because it doesn’t know about the type variable.

To fix the issue, make sure that the solutions keep track of the their type variables associated to key path components. That way the first solution owns its own key path component -> type variable mapping and is thus also able to simplify the type variable it has associated with the component.

Fixes rdar://80522345 [SR-14916]
2021-07-14 17:57:29 +02:00
Alex Hoppen
f74a75f1d3 Merge pull request #38299 from ahoppen/pr/key-path-completion-fixes
[Sema] Fix two assertion failures/crashes in solver-based key-path completion
2021-07-08 09:45:15 +02:00
Alex Hoppen
917fdc9fc0 [Sema] Check completion key path component to determine if completion node was type checked in multi expression closure
To check whether the code completion node was type checked in a multi statement closure, we were assuming that we had a code completion *expression* and not considering that we could also complete in a key path component. When applicable, check if the completion key path component has a type to determine if the completion node was type checked as part of a multi-statement closure.

Resolves rdar://80271598 [SR-14891]
2021-07-08 00:24:14 +02:00
Robert Widmann
c64427fb6c Construct AutoClosureExpr With Deeper Parent Contexts
AutoClosureExprs created by the constraint system used to be constructed
with the decl context of the constraint system itself. This meant that
autoclosures in expressions nested in closures would initially be
parented onto any enclosing functions rather than the deepest closure
context. When we ran capture analysis and lookup from inside of the body
of these nascent values, we would fail to find declarations brought into
scope by those parent closures. This is especially relevant when
pre-typechecked code is involved since captures for those declarations
will be forced before their bodies have been recontextualized. See
issue #34230 for why we need to force things so early.

The attached test case demonstrates both bugs: The former a bogus lookup
through the parent context that would incorrectly reject this otherwise
well-formed code. The latter is a crash in SILGen when the capture
computation would fail to note $0.

Use the decl context of the solution application target, which is always
going to be the deepest user-written closure expression available to us,
and therefore the deepest scope that can introduce capturable variables.

rdar://79248469
2021-07-06 10:55:10 -07:00
OneUpWallStreet
25df5d2c48 Fixed some common grammatical errors in the comments. (#38248) 2021-07-05 01:00:48 -07:00
Pavel Yaskevich
8dc2251a7e [CSBindings] NFC: Add a unit test for closure result inference
Make sure that `Void` doesn't get attempted twice if it was
inferred directly or transitively.
2021-06-17 14:11:59 -07:00
Pavel Yaskevich
942ff69310 [CSBindings] Record produced types incrementally
Allow type variable binding producer to record types as they
are being produced. Otherwise it could be possible to re-discover
already explored types during `computeNext()` which leads to
duplicate bindings e.g. inferring fallback `Void` for a closure
result type when `Void` was already inferred as a direct/transitive
binding.
2021-06-17 13:47:48 -07:00
Pavel Yaskevich
9ab7702382 [ConstraintSystem] NFC: Add an accessor to determine whether type variable represents a key path 2021-05-28 17:53:55 -07:00
Slava Pestov
131d3f4bce Sema: Pass down a ModuleDecl instead of a DeclContext to conformsToProtocol()
... and a bunch of follow-up simplifications pushing ModuleDecls further
up, since I couldn't resist the yak shave.
2021-05-17 16:34:18 -04:00
Doug Gregor
220e29d674 Reinstate "async let", with "spawn let" as an alias. 2021-05-07 00:13:56 -07:00
Pavel Yaskevich
2f44f5bcd6 [ConstraintSystem] Extract logic that identifies application based on its argument node 2021-05-05 11:00:57 -07:00
Pavel Yaskevich
f5e672e985 Merge pull request #37216 from xedin/rdar-70610141
[Diagnostics] Improve diagnostics when passing `async` to a sync parameter
2021-05-05 10:10:05 -07:00
Pavel Yaskevich
21c161d7ae Merge pull request #37209 from LucianoPAlmeida/nfc-record-hole
[NFC][Sema] Changing API to facilitate recording pontential holes recursively
2021-05-03 12:59:41 -07:00
Pavel Yaskevich
53992d04b6 [ConstraintSystem] NFC: Extract async node identification into a function
It's useful not only for effect determination but for diagnostics as well.
2021-05-03 11:06:59 -07:00
Luciano Almeida
c069e86f83 [NFC][Sema] Changing API to facilitate recording pontential holes recursively 2021-05-01 23:06:25 -03:00
swift-ci
e152c14c0a Merge pull request #37162 from DougGregor/spawn-let 2021-04-30 02:19:16 -07:00
Doug Gregor
5d8174da57 [Concurrency] Introduce spawn let 2021-04-29 22:42:40 -07:00
Pavel Yaskevich
957e05cfb1 [Constraint] Allow constraints to be disabled only in "performance" mode 2021-04-27 16:11:47 -07:00
Rintaro Ishizaki
712e439fe9 Merge pull request #37069 from rintaro/ide-rdar76714968
[CodeCompletion] Peform complete `filterSolutions` in code completion
2021-04-26 18:21:41 -07:00
Rintaro Ishizaki
848031825e [CodeCompletion] Peform complete filterSolutions in code completion
Not-filtering solutions causes unacceptable slownesses in some cases.
For now, filter solutions as normal typechecking does to restore the
performance.

rdar://76714968
2021-04-26 13:03:32 -07:00
Pavel Yaskevich
51ff12d06e [ConstraintLocator] Augment ContextualType element to carry its purpose
Having purpose attached to the contextual type element makes it much
easier to diagnose contextual mismatches without involving constraint
system state.
2021-04-26 09:51:21 -07:00
Alejandro Alonso
444c35cf8d Merge pull request #36953 from Azoy/isType-isDeclType
[NFC] Introduce isDecl and getDeclType
2021-04-20 15:33:00 -04:00
Azoy
9ed732f0ab Introduce isDecl and getDeclType
fix enum logic issue

fix tests

guard against null types
2021-04-20 02:22:16 -04:00
Pavel Yaskevich
7e406a753d Merge pull request #36948 from Jumhyn/placeholder-type-get-fix
[Sema] Fix stale reference passed to PlaceholderType::get
2021-04-19 11:09:12 -07:00
Nathan Hawes
f75f5fe78d Merge pull request #36879 from nathawes/track-match-call-result
[ConstraintSystem] Record parameter bindings in solutions (NFC)
2021-04-18 06:10:23 +10:00
Frederick Kellison-Linn
237b73d7b2 [Sema] Fix stale reference passed to PlaceholderType::get 2021-04-16 23:00:12 -04:00
Nathan Hawes
c57c403ffa [ConstraintSystem] Record parameter bindings in solutions (NFC)
This saves us from needing to re-match args to params in CSApply and is also
useful for a forthcoming change migrating code completion in argument position
to use the solver-based typeCheckForCodeCompletion api.

rdar://76581093
2021-04-16 18:32:06 +10:00
Pavel Yaskevich
d57c112845 [ConstraintSystem] NFC: Replace isOperatorBindOverload with isOperatorDisjunction 2021-04-14 10:34:17 -07:00