Commit Graph

6300 Commits

Author SHA1 Message Date
Gábor Horváth
fa65cc9b2b [cxx-interop] Add attribute to hide Swift declarations from interop
Explanation: We generate declarations in the C++ interop header with
"unavailable" annotations when we cannot export something to C++. These
declarations can collide with existing names. Previously, there were no
ways to resolve these name collisions. This PR introduces a new
attribute to hide declarations from the interop header.
Issues: rdar://158843666
Original PRs: #82616
Risk: Low, this adds a new, straightforward code path.
Testing: Added a compiler test.
Reviewers: @egorzhdan
2025-09-02 13:28:27 +01:00
Pavel Yaskevich
0286f4ab82 [AST/Sema] SE-0487: Expand @nonexhaustive attribute to support warn argument
The spelling `@nonexhaustive(warn)` replaces `@preEnumExtensibility`
attriubte.

(cherry picked from commit 43eec8fede)
2025-08-18 23:58:29 -07:00
Hamish Knight
f807cbe30e Enable InlineArray type sugar
Promote it from an experimental feature.

rdar://155607927
2025-07-11 13:26:24 +01:00
Hamish Knight
2add407ae8 [IDE] Bail from IDEInspectionSecondPassRequest if parserState is null
This shouldn't ever happen, but let's at least make sure we don't
crash.
2025-06-27 18:32:25 +01:00
Andrew Trick
102e5ecee1 Fix a compiler crash with '@'_lifetime(inout x), add diagnostic
This is a common mistake made more common be suggestions of existing diagnostic
that tell users not to use a 'copy' dependency.

Report a diagnostic error rather than crashing the compiler. Fix the diagnostic
output to make sense relative to the source location.

Fixes rdar://154136015 ([nonescapable] compiler assertion with @_lifetime(x: inout x))

(cherry picked from commit 080b68292d)
2025-06-26 12:58:40 -07:00
Meghana Gupta
58b714b968 Introduce a new suppressible experimental feature to guard @_lifetime 2025-06-11 08:03:40 -07:00
Meghana Gupta
a9b831788d Update spelling for representing lifetime dependencies to @_lifetime 2025-06-11 08:03:39 -07:00
Pavel Yaskevich
e5501d485a [AST] NFC: Capitalize UsingSpecifier::nonisolated for consistency
(cherry picked from commit 21ec5924f7)
2025-06-04 13:22:34 -07:00
Pavel Yaskevich
76886eb82b [Diagnostics] Tailor using diagnostic to current use-case - default isolation
(cherry picked from commit ec9132cb5a)
2025-06-04 13:22:34 -07:00
Pavel Yaskevich
d3f8fd8fd7 [AST/Sema] Hide using declaration behind DefaultIsolationPerFile experimental feature
(cherry picked from commit c246a7a372)
2025-06-04 13:22:32 -07:00
Pavel Yaskevich
89c3b0ba41 [Parse] Implement parsing for using declarations
(cherry picked from commit 4ad27ba61e)
2025-06-04 13:16:55 -07:00
Hamish Knight
f1c37f4e7d Change InlineArray sugar separator x -> of 2025-05-30 22:06:29 +01:00
Pavel Yaskevich
e12201769d [AST/Sema/SIL] Implement @_inheritActorContext(always)
- Extend `@_inheritActorContext` attribute to support optional `always` modifier.
  The new modifier will make closure context isolated even if the parameter is not
  captured by the closure.
- Implementation `@_inheritActorContext` attribute validation - it could only be
  used on parameter that have `@Sendable` or `sending` and `@isolated(any)` or
  `async` function type (downgraded to a warning until future major Swift mode
  to avoid source compatibility issues).
- Add a new language feature that guards use of `@_inheritActorContext(always)` in swift interface files
- Update `getLoweredLocalCaptures` to add an entry for isolation parameter implicitly captured by `@_inheritActorContext(always)`
- Update serialization code to store `always` modifier

(cherry picked from commit 04d46760bb)
(cherry picked from commit c050e8f75a)
(cherry picked from commit c0aca5384b)
(cherry picked from commit a4f6d710cf)
(cherry picked from commit 6c911f5d42)
(cherry picked from commit 17b8f7ef12)
2025-05-22 11:32:35 -07:00
Cal Stephens
e73beb435e Support trailing commas in types within expressions 2025-05-20 15:49:07 -07:00
Cal Stephens
f4bedbc720 Revert changes to trailing commas in attributes like @available 2025-05-20 15:49:03 -07:00
Cal Stephens
bad48874f0 Add trailing comma support in cases missing from Swift 6.1 2025-05-20 15:48:58 -07:00
Michael Gottesman
e92e9dff0c Make Feature a struct enum so we can put methods on it.
Just noticed this as I was looking at making other changes.

(cherry picked from commit 3ff9463957)
2025-05-14 16:07:04 -07:00
stzn
046c504a0e [Parse] Avoid parsing unsafe expression before binary or postfix op
rdar://150751248
2025-05-13 21:04:40 +01:00
Becca Royal-Gordon
31429fc522 [Legacy parser] No freestanding macros in @abi
SwiftSyntaxParser is already doing this, and we already diagnosed it in Sema anyway, so we’re just moving that diagnostic earlier so the ASTGen testing mode is happy. Also adding compiler tests for it.

Macro-related tests are not included in this commit; they require matching swift-syntax changes which are being negotiated.
2025-05-08 18:27:57 -07:00
Rintaro Ishizaki
bd6c04fe20 [Parse] Parse operator function with value generics
Operator function parsing has a heuristics to determine if `<` a part of
the operator name or the generic parameter clause. Handle `let` there
because value generics uses it.

rdar://149556573
(cherry picked from commit 682d2634ba)
2025-05-02 17:38:49 -07:00
kntkymt
80baae1c0c [Parser] fix parse trailing commna in string interpolation at the end of parseListItem flow instead 2025-04-22 01:55:38 +09:00
Pavel Yaskevich
c3c5a55668 [Parse] Tighten constraints in canParseNonisolatedAsTypeModifier
Accept it only if it's spelled `nonisolated(nonsending)` and nothing
else to minimize any possible source compatibility impact.
2025-04-16 13:20:16 -07:00
Pavel Yaskevich
06f880e65c [AST/ASTGen/Sema/Serialization] Remove @execution attribute
Complete the transition from `@execution` to `@concurrent` and `nonisolated(nonsending)`
2025-04-16 13:18:52 -07:00
Pavel Yaskevich
fde841704c [AST/Parse] Implement nonisolated(nonsending) type modifier 2025-04-16 10:06:08 -07:00
Pavel Yaskevich
d8c64c1ff0 [AST/Sema] Intoduce nonisolated(nonsending) as a replacement for @execution(caller) 2025-04-16 10:06:08 -07:00
Pavel Yaskevich
4a973f7b4b [AST/Sema] Replace @execution(concurrent) with @concurrent 2025-04-16 10:06:08 -07:00
Pavel Yaskevich
7c6ec33400 [Parse] Remove warning about @concurrent being alternative to @Sendable 2025-04-16 10:06:08 -07:00
Doug Gregor
5e29333d6b [SE-0470] Enable isolated conformances by default
The IsolatedConformances feature moves to a normal, supported feature.
Remove all of the experimental-feature flags on test cases and such.

The InferIsolatedConformances feature moves to an upcoming feature for
Swift 7. This should become an adoptable feature, adding "nonisolated"
where needed.

(cherry picked from commit 3380331e7e)
2025-04-14 16:38:22 -07:00
Meghana Gupta
96aeea9f2b Rename ParsedLifetimeDependenceKind::Scope -> ParsedLifetimeDependenceKind::Borrow 2025-04-09 10:18:11 -07:00
Meghana Gupta
91ad1451ce Add support for @lifetime(&arg) 2025-04-09 10:18:11 -07:00
Allan Shortlidge
873da73044 Parse: Improve MemberImportVisibility diags for appendLiteral(_:) calls.
Ensure compiler generated calls to `appendLiteral(_:)` have source locations for
diagnostics.

Partially resolves rdar://144535697.
2025-04-06 09:53:18 -07:00
Hamish Knight
2e1c37f1ab [ASTScope] Allow try in unfolded sequence to cover following elements
Rather than fixing-up in the parser, adjust the ASTScope logic such
that a `try` element in a SequenceExpr is considered as covering all
elements to the right of it. Cases where this isn't true are invalid,
and will be diagnosed during sequence folding. e.g:

```
0 * try foo() + bar()
_ = try foo() ~~~ bar() // Assuming `~~~` has lower precedence than `=`
```

This ensures we correctly handle `try` in assignment sequences, and
allows ASTGen to get the behavior for free.

rdar://132872235
2025-04-02 12:46:21 +01:00
Artem Chikin
66334f8f1b Merge pull request #79290 from artemcm/ConstProtoSIL
[Compile Time Values] Implement a mandatory SIL pass to verify '@const' values
2025-04-01 00:12:27 -07:00
Artem Chikin
281f84da0f [Compile Time Values] Rewrite the 'Diagnose Unknown Compile Time Values' diagnostic pass in Swift 2025-03-28 10:30:07 -07:00
Anthony Latsis
fffa8c2f51 Diag: Abstract away some calls to DeclAttribute::getAttrName 2025-03-28 02:01:27 +00:00
Hamish Knight
42e554ef7d [Parse] Set AttrRange for @nonisolated
Make sure we set the `AttrRange` in cases where `@` is present, but
`unsafe` isn't present.

rdar://147965036
2025-03-27 18:48:55 +00:00
Becca Royal-Gordon
d2276362a4 Support @abi on subscripts
And make sure we reject it on `deinit`s and accessors.
2025-03-26 10:47:57 -07:00
Becca Royal-Gordon
b4d545f873 [NFC] Fix AllowFeatureSuppressionAttr atLoc 2025-03-26 10:47:12 -07:00
Nate Chandler
317a379693 [DefaultOverrides] SIL printing/parsing. 2025-03-25 07:22:14 -07:00
Hamish Knight
f8ab391737 Introduce type sugar for InlineArray (#80087)
* [CS] Decline to handle InlineArray in shrink

Previously we would try the contextual type `(<int>, <element>)`,
which is wrong. Given we want to eliminate shrink, let's just bail.

* [Sema] Sink `ValueMatchVisitor` into `applyUnboundGenericArguments`

Make sure it's called for sugar code paths too. Also let's just always
run it since it should be a pretty cheap check.

* [Sema] Diagnose passing integer to non-integer type parameter

This was previously missed, though would have been diagnosed later
as a requirement failure.

* [Parse] Split up `canParseType` 

While here, address the FIXME in `canParseTypeSimpleOrComposition`
and only check to see if we can parse a type-simple, including
`each`, `some`, and `any` for better recovery.

* Introduce type sugar for InlineArray

Parse e.g `[3 x Int]` as type sugar for InlineArray. Gated behind
an experimental feature flag for now.
2025-03-23 15:31:37 -07:00
Rintaro Ishizaki
92a6fece48 [ASTGen] ObjC improvements
* Generate `#selector(...)` expression
* Generate `#keyPath(...)` expression
* Implicit `@objc` attribute for `@_objcImplementation` attribute
2025-03-20 05:04:58 -07:00
Hamish Knight
b1adb78579 Merge pull request #80143 from hamishknight/add-loc 2025-03-20 10:02:35 +00:00
Amritpan Kaur
3c30d68d2e Merge pull request #78823 from amritpan/method-keypaths
[Sema/SILGen/IRGen] Implement method & initializer keypaths.
2025-03-19 18:59:17 -07:00
Hamish Knight
6942c9bfc7 [IDE] Add pretty stack trace entry for IDE inspection location
Make it easier to reproduce e.g completion crashes by logging the
location the inspection was done at.
2025-03-19 22:11:17 +00:00
Amritpan Kaur
0c614e09d1 [Expr/AST] Add unresolvedApply component to handle method arguments. 2025-03-19 08:56:03 -07:00
Amritpan Kaur
811d54901b [NFC] Rename unresolvedProperty to unresolvedMember
to generalize for both properties and method members.
2025-03-19 08:53:18 -07:00
Joe Groff
24a91bba5d Merge pull request #80038 from jckarter/addressable-for-deps-lowering
SIL: Lower fields that are conditionally addressable because of a dependency.
2025-03-17 21:28:33 -07:00
Alex Hoppen
829e03c104 Merge pull request #79974 from a7medev/feature/complete-single-option-decl-attrs 2025-03-17 15:40:00 -07:00
Joe Groff
c949e6295f SIL: Lower fields that are conditionally addressable because of a dependency.
Parameters of generic type need to be treated as potentially
addressable-for-dependencies, but we don't want callers using the generic
function with concrete types that are known not to be addressable-for-
dependencies to be overconstrained. In SILFunctionType lowering, lower
these dependencies distinctly as conditionally addressable, meaning that
the dependency on an argument depends on whether the concrete type of
that argument is (potentially) addressable-for-dependencies or not.
2025-03-15 16:07:03 -07:00
Ahmed Mahmoud
78990ffe3f [IDE] Pass ParameterizedDeclAttributeKind to parseSingleAttrOption rather than completion callback 2025-03-14 13:19:53 +02:00