Commit Graph

1589 Commits

Author SHA1 Message Date
Sophia Poirier
fa41015ae4 [ConstraintSystem] implement implicit pack materialization for abstract tuples instead of explicit '.element' 2023-07-14 10:32:38 -07:00
Alex Hoppen
00eaed3af9 [CodeCompletion] Migrate postfix expr completion to solver-based 2023-07-07 19:51:01 +02:00
Alex Hoppen
6cec68e302 [IDE] Ignore score kinds that represent implicit conversions when solving for code completion
Ignore conversion score increases during code completion to make sure we don't filter solutions that might start receiving the best score based on a choice of the code completion token.
2023-07-07 19:50:46 +02:00
Sophia Poirier
63e30b5525 [Variadic Generics] add tracking of pack environments for pack elements to Constraint System 2023-07-06 13:44:10 -07:00
Evan Wilde
250082df25 [NFC] Reformat all the LLVMs
Reformatting everything now that we have `llvm` namespaces. I've
separated this from the main commit to help manage merge-conflicts and
for making it a bit easier to read the mega-patch.
2023-06-27 09:03:52 -07:00
Evan Wilde
f3ff561c6f [NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
                     bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".

I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
2023-06-27 09:03:52 -07:00
Pavel Yaskevich
2227930d03 [ConstraintSystem] Adjust the way pack parameters are opened
Although variadic type is declared without `repeat` each of
its generic arguments is supposed to be a PackType which is
modeled in the interface type as `Pack{repeat ...}`. When
reference to such a type is opened by the constraint solver
we need to drop the Pack{repeat ...} structure because the
type variable would represent a pack type so `S<each T>`
is opened as `S<$T0>` instead of `S<Pack{repeat $T0}>`.

Resolves: https://github.com/apple/swift/issues/66095
2023-06-23 18:03:42 -07:00
Pavel Yaskevich
199616a49b Merge pull request #66708 from xedin/generalize-default-closure-type-constraint
[ConstraintSystem] Use fallback type constraint to default pack expansion
2023-06-19 00:47:18 -07:00
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