Commit Graph

1666 Commits

Author SHA1 Message Date
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
Pavel Yaskevich
342e5f6725 Merge pull request #64036 from xedin/rdar-106054263
[CSSimplify] Detect and diagnose generic argument mismatches individually
2023-03-06 10:18:09 -08:00
Pavel Yaskevich
4f2a1752c2 [ConstraintSystem] Produce ambiguity notes based on the fix aggregate
It shouldn't matter how many fixes does the solution have overall,
what matter is how many fixes are there for the location in question.
2023-03-06 10:17:51 -08:00
swift-ci
eb3cbdeb1c Merge pull request #64131 from DougGregor/macro-generic-interface-type
Make the interface type of a generic macro into a GenericFunctionType.
2023-03-06 01:54:08 -08:00
Doug Gregor
af3b41625f Make the interface type of a generic macro into a GenericFunctionType.
This correctly models their type in the type system, and fixes the
redeclaration issue reported in rdar://104183961.
2023-03-05 22:38:08 -08:00
Holly Borla
e6f29f8f93 Merge pull request #64119 from hborla/pack-expansion-shape-crash
[Diagnostics] Diagnose pack element expressions containing a non-pack a subexpression.
2023-03-05 10:11:02 -08:00
Holly Borla
8012e45109 [Diagnostics] Diagnose pack element expressions containing a non-pack subexpression. 2023-03-05 00:11:54 -08:00
Kavon Farvardin
091d63a5c8 revise how the Copyable constraint is added
The _Copyable constraint was implemented as a marker protocol.
That protocol is part of the KnownProtocol's in the compiler.
When `ASTContext::getProtocol(KnownProtocolKind kind)` tries
to find the ProtocolDecl for Copyable, it will look in the
stdlib module (i.e., Swift module), which is where I initially
planned to put it.

That created problems initially when some regression tests
use `-parse-stdlib` failed to do that protocol lookup, which is
essential for adding the constraint (given the current implementation).

That led to believe we need to pull Copyable out of the stdlib, but that's
wrong. In fact, when building the Swift module itself, we do `-parse-stdlib`
but we also include `-module-name Swift`. This causes the _Copyable protocol
defined in the Stdlib to be correctly discovered while building the stdlib
itself (see the test case in this commit). So, the only downside of
having the Copyable protocol in the Stdlib is that `-parse-stdlib` tests
in the compiler can't use move-only types correctly, as they'll be
allowed in generic contexts. No real program would build like this.

Until I have time to do a further refactoring, this is an acceptable trade-off.

fixes rdar://104898230
2023-03-04 11:42:09 -08:00
Pavel Yaskevich
17b09a801e [ConstraintSystem] Add a locator element to represent a generic type
This locator is going to be used as a "parent" element for
"generic argument" elements.
2023-03-03 18:50:46 -08:00
Holly Borla
ad3a385cd2 [Sema] Eliminate single-element tuples after parameter pack substitution. 2023-03-02 19:37:52 -08:00
Andrew Trick
f1ff6958a3 Merge pull request #63825 from atrick/diagnose-implicit-raw-bitwise
Warn on implicit pointer conversion from nontrivial inout values.
2023-03-02 10:57:30 -08:00
Holly Borla
b78b6b9a77 Merge pull request #63991 from hborla/materialize-pack-from-tuple
[ConstraintSystem] Implement type checking for converting a tuple to a pack using the `.element` syntax.
2023-03-01 16:19:33 -08:00
Kavon Farvardin
cc0b668efb Merge pull request #63922 from kavon/standard-issue-neuralyzer
Implement the `forget` statement (as `_forget`)
2023-03-01 11:10:25 -08:00
Doug Gregor
bd35cdb865 Merge pull request #63985 from DougGregor/expression-macros-effects 2023-03-01 06:52:43 -08:00
Alex Hoppen
2108674ec1 Merge pull request #63849 from ahoppen/ahoppen/equivalent-type-vars
[IDE] Inspect all equivalent type variables to replace a type variable by an archetype
2023-03-01 14:36:30 +01:00
Holly Borla
509188630b [ConstraintSystem] Implement type checking for converting a tuple to a
pack using the `.element` syntax.
2023-02-28 22:56:59 -08:00