Commit Graph

1681 Commits

Author SHA1 Message Date
Pavel Yaskevich
83bb9c1f5a [ConstraintSystem] Use fallback type constraint to default pack expansion
Binding of pack expansion types is delayed until solving but use
of `Defaultable` was preventing it from being considered early
because that constraint impacts binding set ranking, switching
to `FallbackType` constraint give us better semantics where pack
expansion type variables are going to be bound as soon as they
have a contextual type.

Resolves: rdar://110819621
2023-06-16 11:15:21 -07:00
Pavel Yaskevich
2ee646f47b [ConstraintSystem] NFC: Generalize DefaultClosureType constraint
This constraint is useful in more places than closures because
it gives a way to provide a "fallback type" without it having
effect on inference.
2023-06-16 11:15:15 -07:00
Pavel Yaskevich
f8bde217a6 Merge pull request #66035 from xedin/rdar-109245375
[Diagnostics] Skip overloaded locations where all solutions have the same type
2023-06-16 09:37:06 -07:00
Pavel Yaskevich
71432032d4 Merge pull request #66579 from xedin/allow-holes-in-diagnostic-mode-only
[ConstraintSystem] Allow generic parameters to bind to holes only in …
2023-06-13 10:58:23 -07:00
Pavel Yaskevich
cfbbb2807e [ConstraintSystem] Allow generic parameters to bind to holes only in diagnostic mode
If generic parameter gets opened during regular solving it cannot
be bound to a hole, that can only happen in diagnostic mode, so
let's not even try. Doing so also makes sure that there are no
inference side-effects related to holes because bindings are ranked
based on their attributes.
2023-06-12 16:29:59 -07:00
Holly Borla
cd752cca22 [NameLookup] Plumb source location arguments through all name lookup APIs.
This source location will be used to determine whether to add a name lookup
option to exclude macro expansions when the name lookup request is constructed.
Currently, the source location argument is unused.
2023-06-11 23:09:47 -07:00
Hamish Knight
b43d351197 [CS] Improve diagnostics a bit for pattern mismatch
There's still plenty of more work to do here for
pattern diagnostics, including introducing a
bunch of new locator elements, and handling things
like argument list mismatches. This at least lets
us fall back to a generic mismatch diagnostic.
2023-06-07 00:35:02 +01:00
Sophia Poirier
93864f6c15 [Variadic Generics] drop requirement of .element for tuple expansion rdar://107160966 2023-05-30 11:37:55 -04:00
Pavel Yaskevich
acf64e3c15 Merge pull request #66080 from xedin/rdar-109586440
[ConstraintSystem] Some more variadic generic fixes
2023-05-24 14:49:09 -07:00
Pavel Yaskevich
70e4cf0ac8 [ConstraintSystem] Limit assert in getFunctionArgApplyInfo to types without type parameter packs
If function type of some declaration has a at least on type parameter
pack it could mean that number of parameters in "applied" type could
be different from that of "interface" type.
2023-05-22 11:32:38 -07:00
Pavel Yaskevich
f12e24e85c [Diagnostics] Skip overloaded locations where all solutions have the same type
If there are multiple overloads, let's skip locations that produce
the same type across all of the solutions, such location is most
likely a consequence of ambiguity and not its source.

Resolves: rdar://109245375
2023-05-20 12:08:54 -07:00
Pavel Yaskevich
84b212cc23 [ConstraintSytem] NFC: Remove unnecessary checking/counting from countDistinctOverloads 2023-05-18 17:02:59 -07:00
Pavel Yaskevich
3b1f392d0a Merge pull request #65785 from angela-laar/fix-covariant-erasure-for-constrained-existentials
Fix covariant erasure for constrained existentials
2023-05-18 16:58:45 -07:00
Angela Laar
a9f1096839 [Generic Signature] Unify generic upper bound functions
Opened existentials should be erased to the dependent upper bound
if the dependent member can be reduced to a concrete type. This
allows the generic signature to support parameterized protocol types
and bound generic class types by producing a more specific constraint
instead of just a plain protocol or class.
2023-05-17 15:33:50 -07:00
Angela Laar
5c818b3fd4 [Constraint System] Fix covariant erasure for constrained existentials
Constrained existentials should be type erased to an upper bound that is dependent on other type parameters.
2023-05-15 16:17:59 -07:00
Pavel Yaskevich
58ffca8f74 [ConstraintSystem] Don't produce partially matching note if none of the overloads matched 2023-05-09 14:11:38 -07:00
Hamish Knight
1be25895b8 [CS] Remove invalid DependentMemberType workaround for tuples
We can produce a hole here now without
regressing diagnostics.
2023-05-04 14:53:58 +01:00
Pavel Yaskevich
cbfec20f08 [CSSimplify] Propagate contextual types to pack expansion variables
If there are explicit generic arguments that fully resolves the
pack expansion, let's bind opened pack expansion to its contextual
type early (while resolving pack expansion variable), doing so
helps with performance and diagnostics.
2023-05-02 09:32:19 -07:00
Pavel Yaskevich
fd060f5dde [ConstraintSystem] Add a locator to openType and some of its callers
`openType` didn't need a locator before it was simply replacing generic
parameters with corresponding type variables but now, with opening of
pack expansions types, a locator is needed for pack expansion variables.
2023-05-02 09:32:19 -07:00
Pavel Yaskevich
ed23aec47e [ConstraintSystem] Record opened pack expansion type in the locator element 2023-05-02 09:32:19 -07:00
Pavel Yaskevich
218ccb145b [ConstraintSystem] Adjust openType and openUnboundGenericType to open pack expansion types
Replace all `PackExpansionType` with a special type variable
which would be resolved once the solver determines that there
is enough contextual information.
2023-05-02 09:32:16 -07:00
Pavel Yaskevich
62b6d010a1 [ConstraintSystem] Form a special one type binding set for pack expansion variables
Pack expansion type variable can only ever have one binding
which is handled by \c resolvePackExpansion.

There is no need to iterate over other bindings here because
there is no use for contextual types (unlike closures that can
propagate contextual information into the body).
2023-05-02 09:31:57 -07:00
Pavel Yaskevich
5985275e6c [ConstraintSystem] TypeSimplifier: Unwrap tuple if pack expansion variable is flattened
This is effectively the same as check `transformWithPosition` but
handles pack expansion type variables.
2023-05-02 09:31:57 -07:00
Pavel Yaskevich
f4a082d8f1 [ConstraintSystem] TypeSimplifier: If pattern and shape are packs - produce pattern type
The `transformWithPosition` would handle its flattening.
2023-05-02 09:31:57 -07:00
Pavel Yaskevich
ca534ef60a [ConstraintSystem] Handle presence of pack expansion type variables while matching 2023-05-02 09:31:57 -07:00
Pavel Yaskevich
c7ef47df0e [ConstraintSystem] TypeSimplifier: Prevent flattening of partially resolved pack expansions
If a pattern type of a pack expansion doesn't have all of the "pack capable"
type variables bound, we don't know what the structure is yet and expansion
cannot be flattened.
2023-05-02 09:31:57 -07:00
Pavel Yaskevich
39c2bbb1ea [ConstraintSystem] Implement pack expansion type opening
Models `PackExpansionType` as a type variable that can only
bind to `PackExpansionType` and `expansion of` constraint that
connects expansion variable to its pattern, shape types.
2023-05-02 09:31:57 -07:00
Pavel Yaskevich
6769e39ed7 [ConstraintSystem] Add a new locator element to identify pack expansion types 2023-05-02 09:31:56 -07:00
Pavel Yaskevich
0b7aeed4b8 [CSDiagnostics] Teach diagnoseConflictingGenericArguments about holes
Only fully resolved substitutions are eligible to be considered
as conflicting, if holes are involved in any position that automatically
disqualifies a generic parameter.

Resolves: rdar://108534555
Resolves: https://github.com/apple/swift/issues/63450
2023-04-27 14:58:26 -07:00
Pavel Yaskevich
7f87e6b697 [ConstraintSystem] Adjust bindArchetypesFromContext to produce Pack type
This aligns `bindArchetypesFromContext` with `getIdentitySubsitutionMap`
and other methods.
2023-03-28 13:14:37 -07:00
Pavel Yaskevich
fb574c8cc4 [ConstraintSystem] openOpaqueType: remove logic that duplicates bindArchetypesFromContext
`openGenericParameters` calls `bindArchetypesFromContext` which would bind all of the
external generic parameters in the opaque type signature.

Resolves: rdar://107280056
2023-03-28 13:14:30 -07:00
John McCall
c041d1061a Perform component-wise substitution of pack expansions immediately.
Substitution of a pack expansion type may now produce a pack type.
We immediately expand that pack when transforming a tuple, a function
parameter, or a pack.

I had to duplicate the component-wise transformation logic in the
simplifyType transform, which I'm not pleased about, but a little
code duplication seemed a lot better than trying to unify the code
in two very different places.

I think we're very close to being able to assert that pack expansion
shapes are either pack archetypes or pack parameters; unfortunately,
the pack matchers intentionally produce expansions of packs, and I
didn't want to add that to an already-large patch.
2023-03-26 04:12:59 -04:00
Alex Hoppen
cebc084367 [CS] Fix locator simplification with 'Member' path element
Previously, a `Member` path element in a `ConstraintLocator` was simplified to the base on which the member was accessed. This is incorrect.
2023-03-20 09:19:21 -07:00
Luciano Almeida
4d981e3c0b Merge pull request #63904 from LucianoPAlmeida/ambiguous-overload
[Sema] Diagnose function coercion ambiguity
2023-03-15 23:18:00 -03:00
John McCall
09018a8981 [NFC] Store interface shape types in opened element environments 2023-03-15 17:25:04 -04:00
Luciano Almeida
4ebedc8333 [Sema] Adjust getCalleeLocator to look into coercion operand 2023-03-14 23:06:11 -03:00
Pavel Yaskevich
438ee330f1 [ConstraintSystem] Add new conversion kind - ArrayToCPointer
It's `ArrayToPointer` conversion that has PointerToCPointer
semantics for (un-)signed integer element types.
2023-03-14 11:22:52 -07:00
Hamish Knight
ab3a8c3cd2 Merge pull request #64335 from hamishknight/less-generic
Better enforce GenericFunctionType TypeVariableType invariant
2023-03-14 16:16:30 +00:00
Hamish Knight
c1d6f1c5d5 Better enforce GenericFunctionType TypeVariableType invariant
Enforce that we don't have any type variables
present in either the result or parameter types.
To ensure the constraint system doesn't violate
this invariant, refactor `getTypeOfMemberReference`
slightly to avoid construction of a
`GenericFunctionType` as a means of opening the
generic parameters of the context for a VarDecl.
2023-03-13 22:08:07 +00:00
Pavel Yaskevich
d637362845 Merge pull request #64322 from xedin/locator-last-cleanup
[CSSolver] NFC: Replace some uses of `last()` with `endsWith()`
2023-03-13 13:51:20 -07:00
Pavel Yaskevich
c106705883 [CSSolver] NFC: Replace some uses of last() with endsWith() 2023-03-13 11:24:15 -07:00
Luciano Almeida
6d85bd54d3 [Sema] Handle coercion in ambiguity note emission 2023-03-12 15:26:38 -03:00
Luciano Almeida
a93eff131c [ConstraintSystem] Add getLocatorForAmbiguity helper for ambiguity logic 2023-03-11 18:47:53 -03:00
Luciano Almeida
9abda4a225 [ConstraintSystem] Removing looking through coercion in getCalleeLocator 2023-03-11 18:47:52 -03:00
Pavel Yaskevich
62d25bae8a [ConstraintSystem] Variadics: Pack expansion materialization operates on loaded tuples
If the base tuple of `.element` is l-value, it has to be loaded
before pack expansion could be materialized.
2023-03-10 16:53:14 -08:00
Pavel Yaskevich
8b63ce8273 Merge pull request #64143 from xedin/ambiguity-diag-improvements
[ConstraintSystem] A couple of improvements to ambiguity diagnostics
2023-03-07 11:57:51 -08:00
Holly Borla
75c1b6e199 Merge pull request #64166 from hborla/parameter-pack-substitution 2023-03-07 06:39:50 -08:00
Holly Borla
e7f82bc6e7 [ConstraintSystem] Record both the UUID and the shape class for opened pack
element environments.

This allows the constraint system to ensure that for a given pack expansion locator,
the given shape class is always the same when requesting the element environment.
If the shape class differs, it means there's a same-shape requirement failure, which
will be diagnosed via the ShapeOf constraint simplification.
2023-03-06 21:22:35 -08:00
Hamish Knight
2976edbe20 [CS] Rename SolutionApplicationTarget -> SyntacticElementTarget 2023-03-06 20:54:06 +00:00
Hamish Knight
570b9f31df [CS] Split out SolutionApplicationTarget.h
Some clients such as code completion ought to be
able to reference this without pulling in the
entirety of ConstraintSystem.h.
2023-03-06 20:54:03 +00:00