Commit Graph

111 Commits

Author SHA1 Message Date
Hamish Knight
3244bffe71 [CS] Handle TVO_CanBindToPack in mergeEquivalenceClasses
Previously we could incorrectly propagate `TVO_CanBindToPack` to a
type variable that cannot bound to a pack type.
2025-07-14 12:44:23 +01:00
Hamish Knight
d6037049b1 [CS] Ensure type variables are eliminated by Solution::simplifyType
`TypeSimplifier` may not eliminate type variables from e.g the
pattern types of pattern expansion types since they can remain
unresolved due to e.g having a placeholder count type. Make sure we
eliminate any remaining type variables along with the placeholders.
There's probably a more principled fix here, but this is a quick and
low risk fix we can hopefully take for 6.2.

rdar://154954995
2025-07-03 16:24:31 +01:00
James Brown
edb0fa7b3d [CS] Deep-equality match OpenedArchetypeTypes
When we have two distinct OpenedArchetypeTypes that have the same
interface type and UUID, we need to match their generic arguments.
2025-03-10 19:19:53 -04:00
Anthony Latsis
492462125d test: Decouple each placement test cases 2025-01-07 05:22:49 +00:00
Anthony Latsis
32cf2d8c2f Sema: Do better at diagnosing missing each 2025-01-07 05:22:48 +00:00
Pavel Yaskevich
fb54682753 [CSSimplify] Don't match pack expansion patterns if shapes are not the same
This helps to avoid spurious failures pointing to involved pattern types
because they won't match exactly if shape types are not the same.
2024-12-12 20:55:02 -08:00
Allan Shortlidge
f827e7c6d3 Tests: Remove -disable-availability-checking in variadic generics tests. 2024-10-20 15:37:15 -07:00
Holly Borla
dbda2738a6 [Features] Gate same-element requirements behind an experimental feature flag. 2024-07-15 10:19:32 -07:00
Holly Borla
e19aadc76d [Constraint System] Fix the shape class and context substitiutions for
opened element generic environments containing same-element requirements.
2024-07-15 10:19:32 -07:00
Holly Borla
2ea4586580 [Requirement Machine] Implement same-element requirements. 2024-07-15 10:19:32 -07:00
Slava Pestov
23be369c0e SILGen: Update for PackElementExpr captures
Fixes https://github.com/apple/swift/issues/68941.
Fixes https://github.com/apple/swift/issues/69282.
Fixes https://github.com/apple/swift/issues/72153.
Fixes rdar://110711746.
Fixes rdar://119212867.
Fixes rdar://124202697.
2024-05-30 16:39:49 -04:00
Pavel Yaskevich
bc3b2748bc [CSSyntacticElement] Bring type variables from outer pack expansion into scope
If closure appears inside of a pack expansion, the elements
that reference pack elements have to bring expansion's shape
type in scope to make sure that the shapes match.
2024-05-22 14:43:10 -07:00
Pavel Yaskevich
888ab81c1e [ConstraintSystem] Connect closure to outer pack expansions it appears in
Type variable reference collector needs to be augmented to collect
type variables associated with pack expansions that a closure references
elements of, otherwise it would get disconnected from the context.
2024-05-22 14:42:39 -07:00
Slava Pestov
da31c59bcb Sema: Track active pack expansions across closure boundaries 2024-04-30 21:38:45 -04:00
Slava Pestov
bc7044e944 Sema: Update diagnostics for openType() change
Some of these are minor regressions; they will be fixed on main but
not release/5.10.
2024-01-09 15:23:42 -05:00
Slava Pestov
770e6f98e3 AST: Correct '(each T).A' output for archetypes
isParameterPack() is always false for an archetype; we must test for a
PackArchetypeType here instead.
2024-01-02 15:41:13 -05:00
Holly Borla
48cb3309bd [Constraint System] Fix the shape class and context substitiutions for
opened element generic environments containing same-element requirements.
2023-12-03 21:51:41 -08:00
Sima Nerush
b0af0f762d Update diagnostics 2023-12-03 21:51:40 -08:00
Slava Pestov
73c18fb668 Sema: Better distinguish scalar from variadic generic argument positions, and reject pack expansion types there
We used to disallow pack expansions in generic argument lists of
protocols, but allow them for all other nominal types. However,
we only actually checked that the pack expansions match up if
the type itself was variadic.

Fix this by repurposing Context::ProtocolGenericArgument into
Context::ScalarGenericArgument, and using that when the type does
not have a parameter pack.

Context::GenericArgument is now Context::VariadicGenericArgument,
and we only use it if the type has a parameter pack, in which case
we use the PackMatcher, so any pack expansions in the wrong place
are caught there.

Fixes rdar://116716014 and https://github.com/apple/swift/issues/69088.
2023-10-11 10:39:26 -04:00
Manu
02b5fa2c8e Fix some typos in the codebase 2023-08-31 18:50:10 -03:00
Pavel Yaskevich
d5bb55eca4 [TypeChecker] NFC: Add a test-case for rdar://110847476 2023-07-24 12:22:25 -07:00
Pavel Yaskevich
eb86497493 [CSSimplify] Deplay member lookup until single-element tuple with pack expansion is sufficiently resolved
Such tuples should be treated specially because once pack expansion
is sufficiently resolved they'd get exploded and the resulting type
is what member lookup should use as a base.

Resolves: rdar://110721928
2023-07-21 13:10:34 -07:00
Pavel Yaskevich
dbb38f1bf3 Merge pull request #67435 from xedin/rdar-112029630
[CSRanking] Augment overload ranking to account for variadic generics
2023-07-21 09:44:01 -07:00
Holly Borla
7b586d20cc [Type Resolution] Only allow each applied directly to a type parameter pack. 2023-07-20 15:29:53 -07:00
Pavel Yaskevich
b98cd11f12 [CSRanking] Augment overload ranking to account for variadic generics
If one of the choices is variadic generic, let's use `matchCallArguments`
to find argument/parameter mappings and form pack expansions for arguments
when necessary.

Resolves: rdar://112029630
2023-07-20 10:15:08 -07:00
Sophia Poirier
fa41015ae4 [ConstraintSystem] implement implicit pack materialization for abstract tuples instead of explicit '.element' 2023-07-14 10:32:38 -07:00
Sima Nerush
83a7e05608 [Sema] Record a fix about extra parens for computed properties (#67042)
Co-authored-by: Sima Nerush <sima_nerush@apple.com>
2023-07-10 14:34:32 -07: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
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
Sima Nerush
e1d2198399 [TypeResolution] Ban local variable packs (#66622)
* Ban explicit local variable packs

* Ban inferred local variable packs
2023-06-16 11:23:41 -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
Holly Borla
e42667bde6 [Diagnostics] Suppress printing explicit pack types in the ASTPrinter instead of
stripping PackType out of diagnostic arguments.

There are places in the type printing code that assume the substitution for a
type parameter pack is always a pack, and violating that invariant will crash
the compiler. We also never want to print 'Pack{...}' in diagnostics anyway,
so the print option is a better approach and fixes a few existing tests that still
contained 'Pack{...}' in error messages.
2023-06-14 11:57:18 -07:00
Holly Borla
d6fe62542a [GenericEnvironment] Don't apply outer context substitutions before
type.subst in mapTypeIntoContext.

The outer context substitutions are already applied when invoking
QueryInterfaceTypeSubstitutions. Applying the context substitutions
before subst also causes problems because QueryInterfaceTypeSubstitutions
will return a null type if given an archetype, which manifested with
opened pack element environments.
2023-06-12 23:07:21 -07:00
Slava Pestov
1957bd6065 Sema: Reword diagnostics to say 'without a type annotation' instead of 'without more context' 2023-06-09 17:44:42 -04:00
Slava Pestov
05daaae0fd ASTPrinter: Tweak PackExpansionType printing 2023-06-06 14:18:37 -04: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
fe6cfe2d85 [CSDiagnostics] Diagnose conformance failures related to pack expansion patterns 2023-05-23 09:47:48 -07:00
Pavel Yaskevich
1e03cdc102 [AST] PackMacher: Match pack expansion elements pair-wise if pack arity matches
This covers situations like `Pack{repeat each T1, repeat each T2}`
vs. `Pack{repeat $T1, repeat $T2}` where type variables are allowed
to bind to packs.

Resolves: rdar://109539394
2023-05-22 14:20:31 -07:00
Pavel Yaskevich
a987861d1c Merge pull request #65806 from xedin/rdar-108977234
[CSSimplify] Detect and diagnose conformance failures related to AnyHashable conversion
2023-05-16 09:56:41 -07:00
Pavel Yaskevich
fdf6d62ece Merge pull request #65830 from xedin/rdar-108904190
[CSSimplify] Allow converting pack expansion types and tuples with pack expansions to Void for closure result
2023-05-16 09:56:27 -07:00
Slava Pestov
e9e6a51c82 Unconditionally enable variadic generic types now that SE-0398 has been accepted 2023-05-15 23:32:52 -04:00
Pavel Yaskevich
96cbc01822 Merge pull request #65861 from xedin/rdar-109160060
[CSSimplify] Allow conversions between tuples with pack expansions and `Any`
2023-05-15 16:20:50 -07:00
Pavel Yaskevich
dc4ee4b61a [CSSimplify] Allow converting tuple with pack expansions to Void for closure result
Maintains existing rule where single-expression closure is allowed
to convert to contextual function type with `Void` result.
2023-05-15 16:20:01 -07:00
Pavel Yaskevich
effa261266 [CSSimplify] Move invalid pack expansion check to enable closure result conversion
Checking for pack expansion type mismatch impedes non-Void-to-Void
conversion allowed for single-expression closures.

Resolves: rdar://108904190
2023-05-15 16:19:59 -07:00
Pavel Yaskevich
406b7a62c7 Merge pull request #65718 from xedin/diagnose-missing-each-in-expr-context
[ConstraintSystem] Detect and diagnose missing 'each' and provide a fix-it
2023-05-15 16:18:55 -07:00
Pavel Yaskevich
181d2d1371 [CSSimplify] Allow conversions between tuples with pack expansions and Any
Don't attempt to wrap `Any` into a single-element tuple to match
against a tuple with pack expansions, this conversion would be
handled by existential promotion if it's allowed, otherwise it
would produce an error.

Resolves: rdar://109160060
2023-05-11 10:05:15 -07:00
Pavel Yaskevich
4a2d139f07 [Diagnostics] NFC: Add a test-case for rdar://108977234 2023-05-09 14:11:45 -07:00
Pavel Yaskevich
440bc39207 [Diagnostics] Don't print pack element archetypes in diagnostics 2023-05-09 14:11:45 -07:00
Pavel Yaskevich
e3d1317208 [ConstraintSystem] Detect and diagnose missing each for value pack reference
Detect that a value pack is missing 'each' keyword during constraint
generation and fix-it by injecting `PackElementExpr`.
2023-05-08 13:30:51 -07:00
Slava Pestov
2e9fd98933 Sema: Diagnose variadic types with more than one type parameter pack 2023-05-08 12:57:33 -04:00