Commit Graph

2101 Commits

Author SHA1 Message Date
Doug Gregor
5b0d1fd5f2 Don't open existentials for library builtin shims 2022-03-28 18:48:17 -07:00
Doug Gregor
0ca06295bc Suppress opened existentials for self-conforming existential metatype arguments 2022-03-28 18:48:17 -07:00
Doug Gregor
945790a6f5 as! and as? also indicate suppression of implicit existential opening 2022-03-28 13:33:29 -07:00
Luciano Almeida
de1bd2d478 [SR-16058][Sema] Consider wrapping type variable layers of optionality when warning about checked casts 2022-03-27 19:14:43 -03:00
Pavel Yaskevich
53617f0a4c Merge pull request #42036 from xedin/dont-infer-from-magic-defaults
[TypeChecker] SE-0347: Avoid type inference from caller-site defaults
2022-03-25 20:11:39 -07:00
Pavel Yaskevich
c03e8b5544 Merge pull request #41899 from xedin/rdar-90419017
[Diagnostics] Ignore type mismatches related to synthesized arguments
2022-03-25 14:47:52 -07:00
Pavel Yaskevich
5b9b4977e0 [TypeChecker] SE-0347: Avoid type inference from caller-site defaults
Such default expressions are injected as an argument to each call site,
so they cannot participate in inference at declaration site.
2022-03-25 13:10:04 -07:00
Pavel Yaskevich
8506d9dd98 Merge pull request #42022 from hborla/default-argument-fixes
[ConstraintSystem] Only attempt to infer a type from a default argument if there is a non-null callee.
2022-03-25 12:01:30 -07:00
Alex Hoppen
c6ef59676d [Sema] Don't crash in matchCallArguments if autoclosure type is not a function type
During code completion, the function type may be a placeholder type. Don't crash in those cases.
2022-03-25 09:36:06 +01:00
Alex Hoppen
d082ebb0ca [CodeCompletion] Don't report an extra argument failure if the code completion token is the first one in a call
This makes sure we don't penalize overloads with no arguments when calling
```swift
func foo() {}
func foo(_ arg: Int) {}
foo(#^COMPLETE^#
```
2022-03-25 09:36:05 +01:00
Holly Borla
0fdb9a38d2 [ConstraintSystem] Bail out of inference from default arguments if there
is no parameter list for the callee.

This can happen when the callee is a closure that has been assigned to
a variable.
2022-03-25 00:20:34 -07:00
Holly Borla
c71b7c500e [ConstraintSystem] Only attempt to infer a type from a default argument
if there is a non-null callee.

Otherwise, getParameterList(callee) will crash if the callee is a closure.
Closures can't have default arguments anyway, so there's no need to
attempt this new inference.
2022-03-24 23:26:24 -07:00
Xi Ge
6206d7cc9d sema: accept an array literal of enum case references as compile-time constant 2022-03-24 21:44:09 -07:00
Xi Ge
d26760e49a Merge pull request #42010 from nkcsgexi/90210674 2022-03-24 16:13:22 -07:00
Doug Gregor
25e71a3a3b Don't open an existential argument that's completely self-conforming.
Such existential arguments will already meet the requirements of a
generic function they are passed to, but would change runtime
semantics. Therefore, don't open the existential in such cases.
2022-03-24 13:08:00 -07:00
Xi Ge
121f39c790 sema: set locator properly when diagnosing constness mismatches
rdar://90210674
2022-03-24 12:47:28 -07:00
Doug Gregor
38c9d2e8dd Merge pull request #41992 from DougGregor/implicit-existential-opening-erase-or-reject 2022-03-23 21:03:54 -07:00
Doug Gregor
50451d2583 Type-erase contravariant uses of opened existentials in subsequent parameters.
When we open an existential argument in a call to a generic function,
type-erase contravariant uses of that opened existential in subsequent
parameters. This primarily impacts closure parameters, where we want
the closure to be provided with an existential parameter type rather
than permit the parameter to have opened existential type. This
prevents the opened existential type from being directly exposed in
the type system.

Note that we do not need to perform this erasure when the argument is
a reference to a generic function, because there it is suitable to
infer that the generic arguments are the opened archetypes. This
subsumes the use case for `_openExistential`.
2022-03-23 15:22:06 -07:00
Pavel Yaskevich
9d413b3668 Merge pull request #41939 from xedin/rdar-87407899
[Diagnostics] Fix out-of-bounds index while fixing argument mismatch
2022-03-22 22:46:54 -07:00
Alex Hoppen
1ef2c5972c Merge pull request #41917 from ahoppen/pr/filter-overloads-if-no-cc-token
[CodeCompletion] Filter overloads if their function application doesn't contain the code completion token
2022-03-22 12:11:29 +01:00
Alex Hoppen
045302b4cb [CodeCompletion] Filter overloads if their function application doesn't contain the code completion token
When solving for code completion, we weren't disabling overloads because the call might be malfored in the presence of a code completion token (because the user is only now writing the function call). But this logic doesn't apply to function calls that don't even involve the code completion token, which happens if completing in result builders.

I am hoping that this significantly improves code completion performance inside result builders.
2022-03-22 08:07:46 +01:00
Pavel Yaskevich
b6c2b3edff [Diagnostics] Fix out-of-bounds index while fixing argument mismatch
Although the overload choice has two parameters, it doesn't
mean that there are exactly two arguments passed to it.

Resolves: rdar://87407899
2022-03-21 14:57:50 -07:00
Alex Hoppen
458ce70245 Merge pull request #41633 from ahoppen/pr/solver-based-global-completions
[CodeCompletion] Migrate expression completions to solver-based
2022-03-21 20:02:47 +01:00
Alex Hoppen
e2a62f1a60 [CodeCompletion] Migrate expression completions to solver-based 2022-03-21 13:00:33 +01:00
Pavel Yaskevich
fc83c6fa68 [Diagnostics] Ignore type mismatches related to synthesized arguments
The main issue is the absence of the argument itself.

Resolves: rdar://90419017
2022-03-18 14:54:15 -07:00
Alex Hoppen
82fc059018 [CodeCompletion] Store ignored arguments as Expr * instead of ConstraintLocators
This avoids the construction of `ConstraintLocator`s.
2022-03-18 15:14:31 +01:00
Alex Hoppen
f538d33e5f [CodeCompletion][Sema] Migrate CallArgurment position completion to the solver-based implementation
This hooks up call argument position completion to the typeCheckForCodeCompletion API to generate completions from all the solutions the constraint solver produces (even those requiring fixes), rather than relying on a single solution being applied to the AST (if any).

Co-authored-by: Nathan Hawes <nathan.john.hawes@gmail.com>
2022-03-17 15:15:54 +01:00
Robert Widmann
43189db520 Merge pull request #41845 from CodaFi/flag-sitter 2022-03-16 22:15:12 -07:00
Luciano Almeida
1505d7cc14 [Diagnostic][Sema] Record locator with OptionalPayload dropped for contextual mismatch fixes for existentials 2022-03-16 18:31:50 -03:00
Robert Widmann
363954a416 Put Variadic Generics Behind a Flag 2022-03-16 14:22:03 -07:00
Robert Widmann
4efcb825f5 Unlock Opaque Types in Parameterized Protocols
Represent this in much the same way that collections do by creating an opaque value representing the source argument, and a conversion expression representing the destination argument.
2022-03-08 23:45:37 -08:00
Robert Widmann
635d253eb6 Unify ParameterizedProtocolTypes
Add deep equality typing rules for

P =~= Q, T == X, U == Y, V == Z, ...
--------------------------------
P<T, U, V, ...> == Q<X, Y, Z, ...>

Also add existential matching rules to discharge the constraints on parameterized protocols against concrete types. e.g.

class C: P { typealias T = Int }
func foo<T>(_ x: P<T>) {}
foo(C())

Should cause T to unify against C.T = Int
2022-03-08 22:01:21 -08:00
Doug Gregor
69c998f70a [Constraint system] Have simplifyOpenedExistentialOfConstraint use openExistentialType
... rather than re-implementing it.
2022-03-08 10:32:29 -08:00
Doug Gregor
02a13f3507 Allow explicit "as <existential-type>" to disable implicit opening of existentials 2022-03-08 10:31:35 -08:00
Robert Widmann
ab44a07045 Convert DeclContext Parameters to their Associated Generic Signatures Instead 2022-03-07 22:54:23 -08:00
Robert Widmann
d6186c9cfb Add a DeclContext Parameter to Opened Archetype Construction
This ensures that opened archetypes always inherit any outer generic parameters from the context in which they reside. This matters because class bounds may bind generic parameters from these outer contexts, and without the outer context you can wind up with ill-formed generic environments like

<τ_0_0, where τ_0_0 : C<T>, τ_0_0 : P>

Where T is otherwise unbound because there is no entry for it among the generic parameters of the environment's associated generic signature.
2022-03-07 22:54:22 -08:00
Pavel Yaskevich
26d85520a2 Merge pull request #41589 from xedin/handle-expr-patterns-in-the-solver
[ConstraintSystem] Support solving expression patterns via injecting call to `~=` operator
2022-03-02 16:33:52 -08:00
swift-ci
ad903094c0 Merge pull request #41386 from beccadax/your-library-is-overdue
Weaken some type checks for @preconcurrency decls
2022-03-01 16:13:59 -08:00
Pavel Yaskevich
59154d6d71 [ConstraintSystem] Support solving expression patterns via injecting call to ~= operator
Augment the constraint solver to fallback to implicit `~=` application
when member couldn't be found for `EnumElement` patterns because
`case` statement should be able to match enum member directly, as well
as through an implicit `~=` operator application.
2022-02-28 17:02:28 -08:00
Pavel Yaskevich
5ec5ffcfda Merge pull request #41570 from xedin/add-expr-pattern-handling-to-solver
[ConstraintSystem] Add support for expression patterns
2022-02-28 09:39:26 -08:00
Pavel Yaskevich
50d0508a4b [ConstraintSystem] Add a new contextual type purpose - expression pattern
This makes it possible to associate expression with its parent pattern.
2022-02-25 12:30:22 -08:00
Pavel Yaskevich
8cfdb9999c Merge pull request #41436 from xedin/allow-specialization-from-default-expr
[TypeChecker] Allow inference from default expressions in certain scenarios (under a flag)
2022-02-24 08:57:42 -08:00
Pavel Yaskevich
bf820c5dab [CSDiagnostics] Look through l-value conversions when mismatch is in subscript setter
`repairFailures` needs a special case when l-value conversion is
associated with a result type of subscript setter because otherwise
it falls through and treats result type as if it's an argument type,
which leads to crashes.

Resolves: rdar://84580119
2022-02-21 16:32:25 -08:00
Pavel Yaskevich
82b955b93c [CSDiagnostics] Detect and diagnose contextual mismatches with default value 2022-02-21 09:59:54 -08:00
Pavel Yaskevich
aa286b7bf4 [CSSimplify] Check whether parameter refers to generic parameters before attempting inference from default 2022-02-21 09:59:54 -08:00
Pavel Yaskevich
aea76ca358 [TypeChecker] Extend type inference from default expressions to handle nested generic parameters
Adds support for parameter types like `[T?]` or `[(T, U?)]`,
and relaxes restriction on same-type generic parameters.

A same-type requirement is acceptable if it only includes
in-scope generic parameters and concrete types i.e. `T.X == Int`
if accepted if `T` is referenced only by a parameter default
expression is being applied to.
2022-02-21 09:59:54 -08:00
Pavel Yaskevich
a6e84b3d05 [ConstraintSystem] Add call site support for type inference from default expressions 2022-02-21 09:59:53 -08:00
Doug Gregor
4141e20ad6 Revert "Allow existential opening for parameters of optional type."
This reverts commit 6e7fff7e65283ae9b25116fa6b75ba92fd2f2a58. The
asymmetry between opening for optional parameters and optional
arguments is surprising enough that we're currently opting not to
allow them.
2022-02-18 11:22:57 -08:00
Doug Gregor
e1f68b26c5 Allow existential opening for parameters of optional type. 2022-02-18 11:22:57 -08:00
Doug Gregor
e30c8a5c09 Allow opening existentials for inout parameters. 2022-02-18 11:22:57 -08:00