Commit Graph

91 Commits

Author SHA1 Message Date
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
Pavel Yaskevich
fdfedc62bd [ConstraintSystem] NFC: Reverse direction of ShapeOf constraint
First type is the reduced shape of the second type (the pack type).
2023-05-03 10:44:10 -07:00
Pavel Yaskevich
bff6a896b2 [CSGen] Detect and diagnose invalid pack expansion expressions
Detect that pack expansion expression doesn't have any pack
references during constraint generation.

Resolves: rdar://107835215
2023-05-02 09:32:19 -07:00
Pavel Yaskevich
0db67464da [CSSimplify] If pack type has holes - its shape is a hole
Propagating holes to the shape helps avoid spurious diagnostics
about same-shape requirement failures.

Resolves: rdar://107675464
2023-05-02 09:32:19 -07:00
Pavel Yaskevich
3006f55327 [CSSimplify] Detect and diagnose passing a tuple to pack expansion that expects individual arguments 2023-05-02 09:32:19 -07:00
Pavel Yaskevich
03f88a0041 [CSSimplify] Add tailored diagnostics for same-shape mismatches related to arguments
Suggest to drop tuples, synthesized or remove extraneous arguments
based on pack shape mismatches.
2023-05-02 09:32:19 -07:00
Pavel Yaskevich
bbe305cd43 [ConstraintSystem] Add same-shape constraint
The constraint takes two pack types and makes sure that their
reduced shapes are equal. This helps with diagnostics because
constraint has access to the original pack expansion pattern
types.
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
dd813af0a7 Merge pull request #65445 from xedin/rdar-108064941
[Diagnostics] Suppress unused expression warning if result is discard…
2023-05-02 09:26:55 -07:00
Pavel Yaskevich
dc8c05ac13 [Diagnostics] Suppress unused expression warning if result is discardable pack expansion
Examine pack expansion pattern to determine whether expression
result could be discarded without a warning (applies to tuples
with a single unlabeled pack expansion element as well).

Resolves: rdar://108064941
2023-04-26 13:43:49 -07:00
Slava Pestov
290701cb4d Sema: Ban shadowing generic parameters from outer scopes
Code like that is usually indicative of programmer error, and does not
round-trip through module interface files since there is no source
syntax to refer to an outer generic parameter.

For source compatibility this is a warning, but becomes an error with
-swift-version 6.

Fixes rdar://problem/108385980 and https://github.com/apple/swift/issues/62767.
2023-04-25 17:41:23 -04:00
Slava Pestov
df5d531dc6 ASTPrinter: Fix printing of pack requirements
Also remove the flag for printing 'each' and make it always on.
2023-04-19 13:04:51 -04:00
Holly Borla
234b5dc660 [SE-0393] Require the repeat keyword for generic requirement expansions. 2023-04-12 22:04:01 -07:00
Sophia Poirier
a3baee9498 [Variadic Generics] fixit to remove keyword 'each' on non-pack types 2023-04-03 17:26:25 -07:00
Pavel Yaskevich
cf991ae99c Merge pull request #64733 from xedin/rdar-106775969
[CSSimplify] Exploaded tuple argument should assume param's label if …
2023-03-31 10:10:55 -07:00
Pavel Yaskevich
00fbdc7cb2 [CSApply] Use correct parameter index for default argument that follow pack expansions
`coerceCallArguments` has to be `ParameterList::getOrigParamIndex`
to determine "original" parameter version which could be used with
un-substituted parameter list.
2023-03-30 16:47:15 -07:00
Pavel Yaskevich
190081376d [CSApply] Teach coerceCallArguments about variadic generics
For variadic generic declarations we need to compute a substituted
version of bindings because all of the packs are exploded in the
substituted function type.

```swift
func fn<each T>(_: repeat each T) {}

fn("", 42)
```

The type of `fn` in the call is `(String, Int) -> Void` but bindings
have only one parameter at index `0` with two argument positions: 0, 1.
2023-03-30 15:02:34 -07:00
Pavel Yaskevich
b07dafab0f [CSSimplify] Exploaded tuple argument should assume param's label if first element doesn't have one
If tuple doesn't have a label for its first element
and parameter does, let's assume parameter's label
to aid argument matching. For example:

```swift
func test(val: Int, _: String) {}

test(val: (42, "")) // expands into `(val: 42, "")`
```

Resolves: rdar://106775969
2023-03-29 10:49:05 -07:00
Pavel Yaskevich
5571de116c Merge pull request #64676 from xedin/rdar-107280056
[ConstraintSystem] `openOpaqueType`: remove logic that duplicates `bindArchetypesFromContext`
2023-03-29 00:15:07 -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
Pavel Yaskevich
736fc8b375 Merge pull request #64608 from xedin/pack-expansion-param-in-init
[ConstraintSystem] Fix support for a single pack expansion parameter …
2023-03-28 09:32:58 -07:00