Commit Graph

23610 Commits

Author SHA1 Message Date
Kavon Farvardin
8899d3b702 temporarily prevent Copyable types from using consuming and borrowing
There is a strong desire for "no-implicit-copy" semantics to be
applied to Copyable values marked with the newer `borrowing` and
`consuming` ownership specifiers. If we lock ourselves into what
SE-390 specifies now for Copyable types in the implementation, then
we'll have to introduce a source break when we want such values to
have the desired semantics.

Before there's wider adoption, I'm making it an error to use those
newer names. If for some reason this is enabling a critical
optimization for your use case, please use the old names instead:

 - `__owned` for `consuming` parameters
 - `__consuming` for `consuming` methods
 - `__shared` for `borrowing` parameters

 NOTE: the older names have their ownership attribute mangled into
 the name of the function itself, so there's a possibility of ABI
 breaks in the future if you move from the old name to the new one.
 There is some consideration being made to allow for a migration to
 the new names in the future without breaking ABI, so do reach out if
 this is an issue for you.

 resolves rdar://108538971
2023-05-03 13:47:06 -07:00
Pavel Yaskevich
8d0a977a45 [CSSimplify] Simplication of ExplicitGenericArguments constraint shouldn't produce ShapeOf
Fix `formUnsolvedConstraint` to use `ExplicitGenericArguments` instead
of `ShapeOf` when first type is not yet fully resolved.
2023-05-03 11:26:52 -07: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
Kavon Farvardin
4710fc675b Prevent noncopyable metatypes from being converted to Any
These metatypes are a gateway to more incorrect
uses of these noncopyable values because we don't
yet have the corresponding runtime support yet.
The other use cases of using metatypes of
noncopyable types in generics is not high enough to
warrant people using them yet.

resolves rdar://106452518
2023-05-03 10:23:11 -07:00
zoecarver
b2988f6e98 [diags][cxx-interop] Update diagnostic for 'begin' to suggest using a for-loop instead.
Does not fix the fix-it. The current fix it will be left as a stop-gap solution and we can hopefully update this fix it in the near future to actually plop in a for loop (too much work for this PR though).
2023-05-03 09:05:55 -07:00
Konrad `ktoso` Malawski
b847ee12ce Further hardening: new compiler + old SDK still diagnose correctly 2023-05-03 11:03:34 +09:00
Pavel Yaskevich
2d94327351 Merge pull request #65125 from xedin/pack-expansion-type-var
[ConstraintSystem] Model pack expansion types via type variables
2023-05-02 13:54:08 -07:00
Allan Shortlidge
872f45ded6 Merge pull request #65542 from tshortli/implicit-modify-inherit-spi
Sema: Inherit SPI groups when synthesizing modify accessor
2023-05-02 13:11:00 -07:00
Kavon Farvardin
6d01f25055 Merge pull request #65556 from kavon/barebones-suppress-copyable
Build support for `~Copyable` atop `@_moveOnly`
2023-05-02 11:48:26 -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
cb2fdd9b54 [CSDiagnostics] Add a diagnostic for pack expansions without pack references 2023-05-02 09:32:19 -07:00
Pavel Yaskevich
d8c8a39cc5 [CSFix] Add a fix to allow value pack expansions without pack references
Situations like `repeat x` where `x` is `Int` where pack expansion
expression doesn't have any pack references.
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
c74824e1ab [CSDiagnostics] Diagnose situations when value pack expansion does expect a tuple argument
Diagnose situation when a single argument to tuple type is passed to
a value pack expansion parameter that expects distinct N elements:

```swift
struct S<each T> {
  func test(x: Int, _: repeat each T) {}
}

S<Int, String>().test(x: 42, (2, "b"))
```
2023-05-02 09:32:19 -07:00
Pavel Yaskevich
b9ef2cabe4 [CSFix] Add a skeleton of a fix for argument destructuring to match pack expansion 2023-05-02 09:32:19 -07:00
Pavel Yaskevich
b5aae065c2 [CSDiagnostics] Unwrap some packs types for diagnostics
If diagnostic references a `Pack{repeat ...}` unwrap it to underlying
pattern.
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
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
943ef19a1d [CSSimplify] Adjust replaceTypeVariablesWithFreshPacks to propagate holes
If type variable that is being replaces allowed holes, the new one
should not lose this property.
2023-05-02 09:32:19 -07:00
Pavel Yaskevich
38ee650719 [CSSimplify] Prevent contextual mismatch diagnostics from seeing one-element tuples
If solver had to introduce an unlabeled single-element tuple around
contextual type, let's strip it and fix as a regular contextual mismatch
(instead of a tuple mismatch) because this action should be transparent
to diagnostics.
2023-05-02 09:32:19 -07:00
Pavel Yaskevich
9365211d28 [CSDiagnostics] Teach generic parameter restoration logic about pack expansions
Just like in any other position, let's restore unresolved type variables
that represent generic parameters to their generic parameter type when
they are found in a pack expansion pattern type.
2023-05-02 09:32:19 -07:00
Pavel Yaskevich
9a395f091e [CSSimplify] Merge binding inference logic with PackElementOf constraint simplification
It's only safe to infer element type from `PackElementOf` constraint
when pattern type is fully resolved (because it can have pack element
archetypes which should be mapped out of context), the same applies
to the pattern type inference as well. Since constraints are re-activated
every time a referenced type variable is bound, simplication logic
can act as inference source by decaying into `Equal` constraints
where pattern/element type are resolved via surrounding information
first.
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
cc2b6ceefa [CSSimplify] Type matching should maintain tuples when matching types with pack expansions
Pack expansion flattening could result in lose of tuple structure
or introduce a single element tuples (which are effectively parens),
to aid in matching `matchTypes` should introduce/maintain tuples on
both sides of the comparison until the structure is known.
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
8a39f3f38d [CSBindings] Mark type variables that represent packs as involving type variables
Such type variables always depend on pack expansion variables.
2023-05-02 09:31:57 -07:00
Pavel Yaskevich
2ebade1b4f [CSSimplify] Delay matching if one of the types is a tuple with unresolved pack expansions
This handles situations like `Int <conv> (Int, (_: $T_exp)` or
`String arg conv (_: $T_exp)`. The matching has to be delayed
because the structure of the tuple type is not known until `$T_exp`
(which represents a pack expansion type) is resolved.
2023-05-02 09:31:57 -07:00
Pavel Yaskevich
07387803fe [CSSimplify] Introduce containsPackExpansionType that handles pack expansion variables
`TypeBase::constainsPackExpansionType` cannot handle this because
it leaves in AST.
2023-05-02 09:31:57 -07:00
Pavel Yaskevich
b0abb7f034 [CSSimplify] Delay .element lookup if pack expansion is not yet resolved 2023-05-02 09:31:57 -07:00
Pavel Yaskevich
d7c320821d [CSSimplify] Handle presence of pack expansion if tuples and shape constraints
Tuple types cannot be matched until all pack expansion variables
are resolved, the same is applicable to `shape of` constraints
because the structure of the pack is not fully resolved in such
cases.
2023-05-02 09:31:57 -07:00
Pavel Yaskevich
5340725df2 [CSSimplify] Prevent merging of type expansion type variables
Even if both sides are pack expansion variables they cannot be
merged because merging of them means merging of pattern and
shape types as well, which is easier to do when one of both
sides are bound.
2023-05-02 09:31:57 -07:00
Pavel Yaskevich
c130351634 [ConstraintSystem] Implement pack expansion variable resolution
A pack expansion type variable gets bound to its original pattern
type when solver can infer a contextual type for it. This makes
sure that pack expansion types are always matched via `matchTypes`
without `simplifyType` involvement which can expand them prematurely.
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
6437531dd7 [ConstraintSystem] Introduce TVO_PackExpansion
This flag indicates that a type variable could only be bound
to PackExpansionType and nothing else.
2023-05-02 09:31:56 -07:00
Pavel Yaskevich
5c2f77c5dc [AST] PackMatching: Make pack expansion type check pluggable
The constraint solver would supply its own version of the function
that can check for pack expansion type variables as well.
2023-05-02 09:31:56 -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
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
29fad35045 Merge pull request #65553 from xedin/move-leading-dot-fix-to-bindings
[CSBindings] NFC: Diagnose leading-dot inference failure when base type is…
2023-05-02 09:11:16 -07:00
Doug Gregor
db81593be4 Merge pull request #65559 from DougGregor/macro-attached-to-accessors-mangle 2023-05-02 07:02:42 -07:00
Konrad `ktoso` Malawski
8d6980ec10 [Executors] Make move to ExecutorJob binary compatible; deprecate Job 2023-05-02 14:44:11 +09:00
Alex Hoppen
01cebd68a8 [CodeComplete] Offer code completion for attached macro attributes
We need to teach code completion how to invoke the type checker for attached macro attributes. After that, everything started working.

rdar://105232015
2023-05-01 21:11:24 -07:00
Alex Hoppen
7e4b88bd04 [CodeCompletion] Provide argument label completions inside #externalMacro
rdar://108163809
rdar://108681394
2023-05-01 16:10:14 -07:00