Commit Graph

2410 Commits

Author SHA1 Message Date
Frederick Kellison-Linn
b433724735 Remove default argument from getContextualType 2021-10-05 17:04:54 -04:00
Hamish Knight
f045350266 [CS] Clean up dynamic member overload choice checking
Add `OverloadChoice::isAnyDynamicMemberLookup`,
and use it to clean up a couple of places.
2021-10-01 12:54:08 +01:00
Hamish Knight
3d4006e697 [CS] Fix locator for dynamic member key-path IUO unwrap
We need to be looking at the callee locator here
for the recorded IUO unwrap.

SR-15249
2021-10-01 12:54:07 +01:00
zoecarver
d14281f643 [cxx-interop] Allow function templates with defaulted template type parameters to be called.
If a defaulted template type parameter is not used in the function's
signature, don't create a corresponding generic argument for that
template type. This allows us to call function templates with defaulted
template type parameters. This is very common in the standard library
for things like enable_if which is used to disable various
functions/overloads with SFINAE.

The biggest part of this change is going forward not all function
templates will be imported as generic functions in Swift. This should
work OK but we may discover there was some logic which only looked for
generic function when dealing with function templates.
2021-09-22 11:11:16 -07:00
Pavel Yaskevich
3a41f7af5f [ConstraintSystem] Add a new conversion - Swift to C pointers
Following pointer conversions are supported in argument positions (when referencing C/ObjC functions):

- Unsafe[Mutable]RawPointer -> Unsafe[Mutable]Pointer<[U]Int>
- Unsafe[Mutable]Pointer<Int{8, 16, ...}> -> Unsafe[Mutable]Pointer<UInt{8, 16, ...}>
2021-09-20 17:22:25 -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
1a756d1a50 Merge pull request #39079 from xedin/pb-application-improvements
[ConstraintSystem] Improvements to pattern binding checking
2021-08-30 15:52:57 -07:00
Rintaro Ishizaki
49547a5378 [NFC][Basic] Import llvm::isa_and_nonnull to 'swift' namespace
Just for convenicence.

* Replace `llvm::isa_and_nonnull` with imported `isa_and_nonnull`
* Repalce some `EXPR && isa<T>(EXPR)` with `isa_and_nonnull<T>(EXPR)`
2021-08-27 11:36:21 -07:00
Pavel Yaskevich
418e87ee06 [CSApply] Adjust flags for un-initialized pattern coercion
Coercion should be aligned with `PatternBindingEntryRequest::evaluate`
and that uses only one flag - `TypeResolverContext::PatternBindingDecl`.
2021-08-27 10:18:09 -07:00
Pavel Yaskevich
ac485b07ce [CSApply] Mark initializer as checked after it is set
Once coerced initializer expression has been set for
a particular pattern binding entry, let's mark it as
checked, otherwise decl checker might try to
re-typecheck it.
2021-08-27 10:16:26 -07:00
Pavel Yaskevich
9518286ca8 Merge pull request #38912 from xedin/generalize-unitialized-var-target
[ConstraintSystem] Generalize uninitialized wrapped variable targets
2021-08-23 13:20:55 -07:00
Frederick Kellison-Linn
ab7a95c18b [Sema] Delay function representation check until placeholders are bound 2021-08-19 14:53:33 -04:00
Pavel Yaskevich
c87e0e149a [ConstraintSystem] Implement uninitialized pattern binding support
This like `let x: Int` or `let (x, y), ...` are now supported by
the constraint solver.
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
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
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
Holly Borla
facb99d38b [CSApply] Coerce wrapped arguments to the wrapper generator input type in
coerceCallArguments.
2021-08-04 22:11:49 -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
Hamish Knight
28f5c5722b [Sema] Make sure to type ParenExpr as ParenType 2021-08-02 20:40:49 +01:00
Hamish Knight
b4bf12f7d2 [CSApply] Correctly update new trailing closure index
Update when coercing call arguments to account for
variadics and default arguments.
2021-08-02 12:59:41 +01:00
Hamish Knight
df566e3147 [AST] Rename decomposeInput/composeInput
Explicitly call out the fact we're dealing with
tuples.
2021-07-28 23:14:45 +01:00
Hamish Knight
72d4d9f1e9 [AST] Add some 'create' factory methods
This provides consistency with other AST nodes,
and will be useful for implementing ArgumentList
construction in the future.
2021-07-28 23:14:44 +01:00
Hamish Knight
c70f280e4a [AST] Add CallExpr::createImplicitEmpty
Add a convenience constructor for an implicit
nullary call. This will become more useful when
the argument parameter starts taking an
ArgumentList.
2021-07-28 23:14:43 +01:00
Hamish Knight
5d1fea24ad [CS] Don't consider implicit TupleExprs in exprNeedsParensOutsideFollowingOperator
Such implicit tuples may be used to represent
argument lists for e.g binary expressions, and as
such shouldn't be considered as parent exprs that
satisfy the role of parentheses.

Also fix the callers to use the raw anchor as the
root expression they pass to provide an accurate
parent map. This requires sinking the
UnresolvedMemberChainResultExpr handling logic into
`getPrecedenceParentAndIndex`.

rdar://81109287
2021-07-26 18:17:01 +01:00
Robert Widmann
1329f3cfbd [NFC] Lift getGenericEnvironment() into GenericSignature 2021-07-22 23:33:02 -07:00
Robert Widmann
d86551de67 Lift Requirement and Parameter Accessors up to GenericSignature
Start treating the null {Can}GenericSignature as a regular signature
with no requirements and no parameters. This not only makes for a much
safer abstraction, but allows us to simplify a lot of the clients of
GenericSignature that would previously have to check for null before
using the abstraction.
2021-07-22 23:27:05 -07: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
Holly Borla
a9bd6b5178 [CSApply] Always map types out of context when setting interface types for wrapped
closure parameters.
2021-07-19 11:01:15 -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
Alex Hoppen
d64b8ecea6 [CodeCompletion] Migrate key path completion to be solver based
This commit essentially consistes of the following steps:
- Add a new code completion key path component that represents the code completion token inside a key path. Previously, the key path would have an invalid component at the end if it contained a code completion token.
- When type checking the key path, model the code completion token’s result type by a new type variable that is unrelated to the previous components (because the code completion token might resolve to anything).
- Since the code completion token is now properly modelled in the constraint system, we can use the solver based code completion implementation and inspect any solution determined by the constraint solver. The base type for code completion is now the result type of the key path component that preceeds the code completion component.

This resolves bugs where code completion was not working correctly if the key path’s type had a generic base or result type. It’s also nice to have moved another completion type over to the solver-based implementation.

Resolves rdar://78779234 [SR-14685] and rdar://78779335 [SR-14703]
2021-06-25 23:19:35 +02:00
Hamish Knight
c1b1feb8e7 [AST] Clean up CaptureListEntry
Don't store a VarDecl separately, expose a `getVar`
accessor that forwards onto `getSingleVar`, and
rename `Init` to `PBD`.
2021-06-08 22:56:06 +01:00
Pavel Yaskevich
8ab8b2e3e9 [CSApply] Load l-value before wrapping it in try expression
Just like `try?` other types of try - `try` and `try!` have to load
the value before using it.

Resolve: rdar://78102266
2021-05-24 10:23:32 -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
Holly Borla
96b0cb545f [CSApply] NFC: Clean up some duplicated logic for propagating
`async` from contextual types to closure types.

This preserves the behavior that `async` is propagated to closures that
should inherit the surrounding actor context, even if the closure is an
argument to a reasync function.
2021-05-05 18:49:38 -07:00
Holly Borla
8e78c8b35c [CSApply] Propagate 'async' from contextual types to closures, unless the closure
is an argument to a 'reasync' function.
2021-05-05 11:35:40 -07:00
Hamish Knight
ae37545a13 Merge pull request #37062 from hamishknight/sup
[AST] Remove 'is super' bit on ApplyExpr
2021-04-26 12:44:57 -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
Hamish Knight
d309caea11 [AST] Remove 'is super' bit on ApplyExpr
This appears to be equivalent to
`getArg()->isSuperExpr()`. Let's use that instead.
2021-04-26 12:06:52 +01:00
Doug Gregor
6928c3f1c9 Make sure that we perform the actor hop for @_inheritActorContext 2021-04-21 17:35:17 -07:00
Doug Gregor
b9f1e7f626 [Concurrency] Add @_inheritActorContext hidden parameter attribute.
This new attribute can be used on parameters of `@Sendable async` type
to indicate that the closures arguments passed to such parameters
should inherit the actor context where they are formed, which is not
the normal behavior for `@Sendable` closures.

Another part of rdar://76927008.
2021-04-21 15:23:27 -07:00
Doug Gregor
abfc9bcdc4 Add @_implicitSelfCapture attribute to disable "self." requirement.
Add a new parameter attribute `@_implicitSelfCapture` that disables the
requirement to explicitly use `self.` to refer to a member of `self`
in an escaping closure.

Part of rdar://76927008.
2021-04-20 17:26:07 -07: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
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
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
swift-ci
b941835484 Merge pull request #35398 from kavon/async-initializers 2021-04-15 14:27:09 -07:00