Commit Graph

18474 Commits

Author SHA1 Message Date
Pavel Yaskevich
eee7e1879f [CSDiagnostics] Add a diagnostic for missing each and provide a fix-it
Diagnose situations where value pack is referenced without an explicit 'each':

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

func test<each T>(v: repeat each T) {
  repeat compute(v) // should be `repeat compute(each v)`
}
```
2023-05-08 13:30:51 -07:00
Pavel Yaskevich
583649088a [AST/CSGen] Move expanded pack collection into constraint generator
This is going to help us identify and fix positions were 'each'
keyword is mising.
2023-05-08 13:30:51 -07:00
Slava Pestov
8f71dc928f Sema: Diagnose variadic enums, and inheritance from variadic classes
These are just temporary limitations.
2023-05-08 12:57:33 -04:00
Slava Pestov
2e9fd98933 Sema: Diagnose variadic types with more than one type parameter pack 2023-05-08 12:57:33 -04:00
Hamish Knight
d54ee5d680 Merge pull request #65744 from hamishknight/second-place 2023-05-08 17:49:09 +01:00
Ben Barham
1426980ba4 Merge pull request #65737 from bnbarham/expand-infinite-loop
[Macros] Terminate parsing expanded members if no progress is made
2023-05-08 09:19:57 -07:00
Alex Lorenz
a1dc63ec46 Merge pull request #65728 from hyp/eng/safe-overloads-and-unavailable-unemitted-decls-in-cxx
[interop][SwiftToCxx] avoid emitting ambiguous C++ overloads and emit unavailable type stubs for top level types that could not be emitted in the C++ section of the generated header
2023-05-07 06:25:03 -07:00
Hamish Knight
c0e013907e [AST] Allocate PlaceholderTypes in the correct arena
We shouldn't be allocating placeholders for type
variables in the permanent arena, and we should be
caching them such that equality works.

To achieve this, we need to introduce a new
"solver allocated" type property. This is required
because we don't want to mark placeholder types
with type variable originators as themselves having
type variables, as it's not part of their structural
type. Also update ErrorType to use this bit, though
I don't believe we currently create ErrorTypes
with type variable originators.
2023-05-06 20:42:02 +01:00
Kavon Farvardin
c260792e73 Merge pull request #65690 from kavon/forget-usage-fixes
`_forget` usage fixes to match SE-390
2023-05-06 11:50:10 -07:00
Alex Lorenz
74e87a9ae6 [interop][SwiftToCxx] do not expose move-only Swift types
Swift's consume semantics are not yet supported in C++
2023-05-06 07:12:46 -07:00
Ben Barham
cec1fa2dc1 [Macros] Terminate parsing expanded members if no progress is made
Resolves rdar://108563022.
2023-05-05 21:22:56 -07:00
Kavon Farvardin
578da4949d disallow "non-trivial" stored properties when using forget
We haven't quite got the semantics we want implemented
for `discard` aka `_forget` statements. Allowing people
to use `_forget` in noncopyable types that have stored
properties that require destruction will not let us
implement it the way we'd like in the future without
source break. But, if the type only has "trivial" stored
properties with a no-op destruction, like `Int`, then we
can still provide utility for users like FileDescriptor
who just want to disable the deinit and have nothing
fancy stored in the type itself.

rdar://108877261
2023-05-05 19:05:04 -07:00
Alex Lorenz
bf35e3f55a [interop][SwiftToCxx] provide a clear unavailable message for protocol decls in C++ 2023-05-05 17:03:28 -07:00
Alex Lorenz
aff3568a12 [interop][SwiftToCxx] emit unavailable type stubs for top level types that could not be emitted in the C++ section of the generated header 2023-05-05 17:03:26 -07:00
Kavon Farvardin
4943beb35e emit error if _forget is used on a type with no deinit
rdar://108877261
2023-05-05 14:50:48 -07:00
Kavon Farvardin
fc636caf61 Merge pull request #65691 from kavon/consuming-nonescaping-closures
consuming cannot be applied to nonescaping closures
2023-05-05 10:03:08 -07:00
Allan Shortlidge
0366c42293 Merge pull request #65557 from tshortli/unavailable-decl-optimization-stub
Introduce `stub` mode for `-unavailable-decl-optimization`
2023-05-05 09:11:41 -07:00
Rintaro Ishizaki
0a558117fb Merge pull request #65630 from rintaro/macro-plugin-intiialize-rdar108022847 2023-05-05 06:34:29 -07:00
Kavon Farvardin
32e89875e7 consuming cannot be applied to nonescaping closures
According to SE-377:

consuming cannot be applied to parameters of nonescaping closure type, which by their nature are always borrowed:

// ERROR: cannot `consume` a nonescaping closure
func foo(f: consuming () -> ()) {
}

This commit implements the error message.

rdar://108388132
2023-05-05 00:16:41 -07:00
Zoe Carver
143b0160d2 Merge pull request #65658 from zoecarver/for-in-loop
[diags][cxx-interop] for-loop -> for-in loop.
2023-05-04 16:39:55 -07:00
swift-ci
27d9d65872 Merge pull request #65512 from keith/ks/fix-missing-indexing-data-when-using-self-initializer
Fix missing indexing data when using Self initializer
2023-05-04 16:04:07 -07:00
Rintaro Ishizaki
e181a4d39c [Macros] Improve error handling for plugin errors 2023-05-04 14:40:28 -07:00
Keith Smiley
1d3a9baed2 Fix missing indexing data when using Self initializer
Fixes: https://github.com/apple/swift/issues/64686
2023-05-04 10:47:15 -07:00
zoecarver
408ce853d0 [diags][cxx-interop] for-loop -> for-in loop. 2023-05-04 10:26:45 -07:00
Zoe Carver
bd1cc4c64f Merge pull request #65617 from zoecarver/update-diag-text
[diags][cxx-interop] Update diagnostic for 'begin' to suggest using a for-loop instead.
2023-05-04 10:16:11 -07:00
Zoe Carver
f358cbea8e Merge pull request #65578 from zoecarver/disable-rvalue-ref
[cxx-interop] Disable rvalue references. We don't support them correc…
2023-05-04 10:15:56 -07:00
Kavon Farvardin
0b93ff4a9c Merge pull request #65570 from kavon/ownership-specifiers-noncopyable-only
temporarily prevent Copyable types from using `consuming` and `borrowing`
2023-05-03 21:46:15 -07:00
Alex Hoppen
53e57230a4 Merge pull request #65572 from ahoppen/ahoppen/macro-arg-completion
[CodeComplete] Offer code completion for attached macro attributes
2023-05-03 19:07:19 -07:00
Alex Hoppen
a39a77e8a2 Merge pull request #65526 from ahoppen/ahoppen/complete-in-macro-default-arg
[CodeComplete] Offer completion suggestions for default argument values inside the macro declaration + argument label inside `#externalMacro`
2023-05-03 18:58:35 -07:00
Alex Lorenz
50edc0b79b [interop] add more specific diagnostic when rvalue reference parameter isn't imported 2023-05-03 18:29:26 -07:00
Konrad `ktoso` Malawski
0bdb39f51e Merge pull request #65455 from ktoso/wip-bincompat-job-rename 2023-05-04 07:34:45 +09:00
Allan Shortlidge
d1416ddd56 SILGen: Stub unavailable functions.
When `-unavailable-decl-optimization=stub` is specified, insert a call to
`_diagnoseUnavailableCodeReached()` at the beginning of the function to cause
it to trap if executed at run time.

Part of rdar://107388493
2023-05-03 15:19:31 -07:00
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
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
Hamish Knight
2338b4cce3 Merge pull request #65472 from hamishknight/buffering 2023-05-03 10:00:50 +01: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
949612553a Merge pull request #65568 from tshortli/expression-attr-condfail
Revert #64269
2023-05-02 13:13:52 -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
cb2fdd9b54 [CSDiagnostics] Add a diagnostic for pack expansions without pack references 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
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
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
Hamish Knight
100244a0c3 Avoid computing generated source notes on child notes
This could cause us to double up on the same note
for nested macro expansions, as we'd generate the
note, then when recursing back through the function
we'd compute the same note again. Also remove the
seemingly unused `lastBufferID` param.
2023-05-02 16:21:44 +01: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
Allan Shortlidge
ffaa1d5dbc Revert "[Macros] Treat FreestandingExpressionMacros as a suppressible feature"
This reverts commit b412c6c884.

Resolves rdar://108591384
2023-05-01 19:44:39 -07:00
Kavon Farvardin
ee819c80a9 Build support for ~Copyable atop @_moveOnly
We parse `~Copyable` in an inheritance clause of enum and
struct decls as a synonym for the `@_moveOnly` attribute
being added to that decl. This completely side-steps the
additional infrastructure for generalized suppressed
conformances in favor of a minimal solution. One benefit of
this minimal solution is that it doesn't risk introducing
any back-compat issues with older compilers or stdlibs.

The trade-off is that we're more committed to supporting
`@_moveOnly` in compiled modules in the future. In fact,
this change does not deprecate `@_moveOnly` in any way.

resolves rdar://106775103
2023-05-01 14:36:39 -07:00
Alex Hoppen
237c70ea9c [CodeComplete] Offer completion suggestions for default argument values inside the macro declaration
We were not type checking the default argument initializer because `MacroDecl` is not an `AbstractFucntionDecl`. Add `MacroDecl` to the list of nodes we know how to get parameters from.

rdar://108163564
2023-05-01 13:48:18 -07:00