Commit Graph

2010 Commits

Author SHA1 Message Date
Pavel Yaskevich
b03021dbb7 [TypeChecker] SE-0347: Enable type inference from default expressions 2022-04-06 15:03:00 -07:00
Pavel Yaskevich
d727a79963 Merge pull request #42146 from xedin/rdar-91145060
[ConstraintSystem] Cache types of `~=` components
2022-04-04 10:35:52 -07:00
Alex Hoppen
0ded798ceb Merge pull request #42006 from ahoppen/pr/prepare-for-migrate-postfixexprparen
[CodeCompletion][Sema] Multiple improvements to prepare for migration of PostfixExprParen to solver-based
2022-04-03 16:43:36 +02:00
Pavel Yaskevich
8b8ccb488a [ConstraintSystem] Cache types of ~= components
While synthesizing `~=` application for multi-statement closures or
result builder, solver shouldn't set types directly to newly
created AST nodes because they might not be fully resolved, instead
such types have to be recorded in the constraint system and then
set during solution application.

Resolves: rdar://91145060.
2022-04-01 14:00:43 -07:00
Doug Gregor
b94d6eb874 Merge pull request #42121 from xedin/rdar-91110069
[ConstraintSystem] Fix a bug in existential Self erasure
2022-03-31 20:55:34 -07:00
Pavel Yaskevich
9e3432a833 [ConstraintSystem] Fix a bug in existential Self erasure
`typeEraseExistentialSelfReferences` shouldn't account for
contextual signature because that signature could have
generic parameters of it's own unrelated to the reference
which would be located before generic parameters of the
member, e.g. when the code is located in a protocol extension,
which invalidates the assumption that `Self` is located at
depth = 0, index = 0.

Resolves: rdar://91110069
2022-03-31 13:19:33 -07:00
Luciano Almeida
df913c9832 Merge pull request #42050 from LucianoPAlmeida/SR-16058-casts
[SR-16058][Sema] Consider wrapping type variable layers of optionality when warning about checked casts
2022-03-30 23:44:54 -03:00
Doug Gregor
0927c9f2fa Restrict implicit opening of existentials based on the generic function's requirements
Rather than looking solely at the existential argument of a generic
function to determine whether it self-conforms, compare the
existential argument against each of the protocols to which the
corresponding generic parameter conforms. This better models when the
existential value itself will successfully meet the requirements of
the generic function, and therefore not require opening.

This provides far better source compatibility by not changing
semantics of existing, well-formed calls, and eliminates the need to
special-case CoW-related operations in the standard library.
2022-03-29 11:59:29 -07:00
Doug Gregor
efd19658ca Revert "Don't open existentials for library builtin shims"
This reverts commit 5b0d1fd5f2.
2022-03-29 11:59:28 -07:00
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