Commit Graph

2023 Commits

Author SHA1 Message Date
Doug Gregor
020b69d4b6 [SE-0497] Implement @export attribute syntax
Implement the @export(implementation) and @export(interface) attributes
to replace @_alwaysEmitIntoClient and @_neverEmitIntoClient. Provide a
warning + Fix-It to start staging out the very-new
@_neverEmitIntoClient. We'll hold off on pushing folks toward
@_alwaysEmitIntoClient for a little longer.
2025-11-07 22:00:40 -08:00
Alexis Laferrière
1e1361f4ee Merge pull request #85369 from xymus/exportability-nle-classes-and-structs
Sema: Exportability check enums and classes in non-library-evolution mode
2025-11-07 09:19:25 -08:00
Alexis Laferrière
5bffd70452 Sema: Accept @_implementationOnly on enums and classes 2025-11-06 11:30:43 -08:00
Doug Gregor
a10194c0e3 Ensure that we don't diagnose the lack of initializer for @_extern variables 2025-11-06 11:20:57 -08:00
Doug Gregor
5b642f548f Extend @_extern to global and static variables
Allow external declaration of global variables via `@_extern(c)`. Such
variables need to have types represented in C (of course), have only
storage (no accessors), and cannot have initializers. At the SIL
level, we use the SIL asmname attribute to get the appropriate C name.

While here, slightly shore up the `@_extern(c)` checking, which should
fix issue #70776 / rdar://153515764.
2025-11-06 11:09:31 -08:00
Allan Shortlidge
3b77e2e64a AST: Introduce experimental support for an anyAppleOS availability domain.
`anyAppleOS` represents a meta-platform for availability checks that can be
used to check availability across all of Apple's operating systems. It
supports versions 26.0 and up since version 26.0 is the first OS version number
that is aligned accross macOS, iOS, watchOS, tvOS, and visionOS.

Apple platform-specific availability specification take precedence over
`anyAppleOS` availability specifications when specified simultaneously.

Resolves rdar://153834380.
2025-10-31 15:21:30 -07:00
Alexis Laferrière
94113f4a83 SE-496: Remove references to features CDecl and CImplementation 2025-10-29 17:31:20 -07:00
Alexis Laferrière
000c2604b0 SE-495: Make @c an official feature 2025-10-29 11:55:41 -07:00
Alexis Laferrière
74ea47a159 Merge pull request #84489 from xymus/c-identifier-only
Parser: Reject `@c` attributes using the string format
2025-10-27 09:17:31 -07:00
Hamish Knight
b5627c9337 Merge pull request #85145 from a7medev/autodiff-comma-fix-its
[Diagnostics] Add missing fix-its for unexpected/expected comma in attribute arguments
2025-10-27 09:08:16 +00:00
Ahmed Mahmoud
d0c2d8b317 [Diagnostics] Add fix-its for unexpected/expected comma in auto-diff attributes 2025-10-26 23:47:19 +03:00
Alexis Laferrière
7ec1d36215 Parser: Reject @c attributes using the string format
Reject `@c` attributes in the format of `@c("customName")` to accept
only `@c(customName)` and of course the bare `@c`.
2025-10-24 11:55:34 -07:00
Alexis Laferrière
659692e834 Tests: Update all uses of @c to use the identifier format 2025-10-24 11:55:34 -07:00
Kuba Mracek
b47227b57b Remaining test a code fixes for @_section->@section rename 2025-10-23 08:43:42 -07:00
Kuba Mracek
adeb40f261 SE-0492: Stabilize @_section/@_used into @section/@used
Removes the underscored prefixes from the @_section and @_used attributes, making them public as @section and @used respectively. The SymbolLinkageMarkers experimental feature has been removed as these attributes are now part of the standard language. Implemented expression syntactic checking rules per SE-0492.

Major parts:
- Renamed @_section to @section and @_used to @used
- Removed the SymbolLinkageMarkers experimental feature
- Added parsing support for the old underscored names with deprecation warnings
- Updated all tests and examples to use the new attribute names
- Added syntactic validation for @section to align with SE-0492 (reusing the legality checker by @artemcm)
- Changed @DebugDescription macro to explicitly use a tuple type instead of type inferring it, to comply with the expression syntax rules
- Added a testcase for the various allowed and disallowed syntactic forms, `test/ConstValues/SectionSyntactic.swift`.
2025-10-22 16:05:39 -07:00
Allan Shortlidge
463bf91f68 AST: Rename Swift runtime availability domain to StandaloneSwiftRuntime.
This name will distinguish the standalone Swift runtime availability domain
from the domain for the built-in Swift runtime on supported targets.
2025-10-21 21:55:25 -07:00
Allan Shortlidge
16dee385bf AST/Basic: Introduce the StandaloneSwiftAvailability experimental feature.
This experimental feature will be used to force the compiler to treat `Swift`
runtime availability as separate from platform availability when compiling for
targets that have the Swift runtime built-in.
2025-10-21 21:55:24 -07:00
Mads Odgaard
c92e5b47f3 Merge pull request #84574 from madsodgaard/android-availability 2025-10-20 10:40:37 +09:00
Hamish Knight
a83ea3c8bb Merge pull request #84745 from hamishknight/fishmonger
[Evaluator] Enforce consistent results for cyclic requests
2025-10-09 17:08:04 +01:00
Allan Shortlidge
1a86cd9c26 AST: Introduce a Swift runtime availability domain.
Add support for the `Swift` availability domain, which represents availability
with respect to the Swift runtime. Use of this domain is restricted by the
experimental feature `SwiftRuntimeAvailability`.
2025-10-08 17:31:57 -07:00
Allan Shortlidge
2d8465b043 AST: Introduce the SwiftLanguageMode availability domain spelling.
Require `-enable-experimental-feature SwiftRuntimeAvailability` to use this new
spelling.
2025-10-08 15:46:34 -07:00
Hamish Knight
e7c7239587 [Sema] Insert ErrorType same-type constraints for placeholder signatures
This helps avoid producing more downstream errors. This changes
`GenericSignature::forInvalid` to produce the same signature as e.g
`<T where T == Undefined>`. This subsumes the need to introduce
conformance requirements for invertible protocols.
2025-10-08 21:16:02 +01:00
Henrik G. Olsson
cbc0ec3b88 Add -verify-ignore-unrelated where necessary (NFC)
These are tests that fail in the next commit without this flag. This
does not add -verify-ignore-unrelated to all tests with -verify, only
the ones that would fail without it. This is NFC since this flag is
currently a no-op.
2025-10-04 14:19:52 -07:00
Alexis Laferrière
e5a9b6463d Merge pull request #84381 from xymus/rename-cdecl-to-c
Parser: Rename the experimental attribute `@cdecl` to the shorter `@c`
2025-09-23 14:58:46 -07:00
Doug Gregor
6e6dc4b063 Merge pull request #81054 from DataCorrupted/FixTypedThrow
[Sema] @objc functions shall not have typed throw
2025-09-22 18:21:52 -07:00
Alexis Laferrière
9ec824c20b Parser: Rename the experimental attribute @cdecl to @c
There's no users of `@cdecl` yet so we can do a direct rename. The
legacy `@_cdecl` remains unaffected.
2025-09-19 11:55:07 -07:00
Allan Shortlidge
0647da5416 AST: Introduce an "always enabled" custom availability domain kind.
An always enabled availability domain is implicitly available in all contexts,
so uses of declarations that are marked as `@available` in the domain are never
rejected. This is useful for an availability domain representing a feature flag
that has become permanently enabled.

Partially resolves rdar://157593409.
2025-09-11 14:39:05 -07:00
Gabor Horvath
7ac9a81b1e [cxx-interop] Add attribute to hide Swift declarations from interop
This can help work around problems when the names of a C++ declaration
and a Swift declaration would collide, or to temporarily work around
compiler bugs.

rdar://152838988&140802127&158843666
2025-09-01 12:29:34 +01:00
Pavel Yaskevich
a7ecd309d4 [AST] SE-0487: Promote NonexhaustiveAttribute to a language feature
The proposal [has been accepted](https://forums.swift.org/t/accepted-se-0487-nonexhaustive-enums/81508)
which makes the feature experimental no longer.
2025-08-20 00:39:51 -07:00
Allan Shortlidge
5ae0ad6a8f AST: Allow obsoletion in Swift version to disambiguate overloads consistently.
It must be possible to disambiguate overloads using the module-wide Swift
language version, even in contexts that are themselves obsolete in the current
Swift language version.

Resolves rdar://158620835.
2025-08-18 17:20:42 -07:00
Hamish Knight
114ea293c4 Merge pull request #82058 from a7medev/feat/access-control-set-fix-it
[Diagnostics] Add fix-its for missing `set` and `)` after access modifier
2025-08-16 18:42:28 +01:00
Ahmed Mahmoud
66a12352e4 [Test] Remove expected-error for invalid declaration after expected 'set' fix-it 2025-08-15 18:15:12 +03:00
Allan Shortlidge
db117bfefe Sema: Don't apply access level fix-it to @dynamicMemberLookup subscript.
The adjusted access level for the subscript shouldn't be fixed automatically
since sometimes the diagnostic is a warning and other times automatically
applying the fix-it immediately causes other errors, which can be confusing.

Resolves rdar://158261884.
2025-08-13 23:13:07 -07:00
Ahmed Mahmoud
edacf85aea [Test] Test no fix-it for access-control set in place of unrelated code 2025-08-10 02:16:12 +03:00
Ahmed Mahmoud
9df52be469 [Diagnostics] Add tests for accessibility expected set fix-its 2025-08-10 01:41:08 +03:00
Allan Shortlidge
4d41db3b5d Sema: Rationalize availability checking in unavailable contexts.
Correct several behaviors of availability checking in unavailable contexts that
were inconsistent with the checking model:

- Avoid diagnosing unintroduced and obsolted declarations in contexts that are
  unavailable in the same domain.
- Diagnose unavailability normally in type signature contexts.
2025-08-08 07:57:44 -07:00
Hamish Knight
fb7f2d0ff2 [CS] Limit the number of chained @dynamicMemberLookup lookups
Set an upper bound on the number of chained lookups we attempt to
avoid spinning while trying to recursively apply the same dynamic
member lookup to itself.

rdar://157288911
2025-08-01 19:08:04 +01:00
Anthony Latsis
103521394b Merge pull request #82989 from CrazyFanFan/feature/fix-it-add-static-main
[Diagnostics] Add fix-it to `@main` struct without main static function.
2025-07-31 01:25:37 +01:00
Allan Shortlidge
9302cbe568 Sema: Diagnose @dynamicMemberLookup subscripts that are not accessible enough.
Since this is a source breaking change, downgrade the diagnostic to a warning
until the next language version unless library evolution is enabled, in which
case this would have resulted in a broken `.swiftinterface` and it therefore
makes sense to diagnose eagerly.

Resolves rdar://156919010.
2025-07-28 22:36:39 -07:00
Allan Shortlidge
7d866bfe69 AST: Skip serializing non-public accessors of @backDeployed properties.
Avoids a crash in SILGen when skipping non-inlinable function bodies.

Resolves rdar://136853454.
2025-07-27 21:25:44 -07:00
Allan Shortlidge
8cb20c3f4e AST: Fix a crash when handling duplicate available attrs. 2025-07-25 15:14:53 -07:00
Crazy凡
061ce725d7 [Diagnostics] Add fix-it to @main struct without main static function. 2025-07-23 15:04:26 +08:00
Allan Shortlidge
034c62cf01 AST: Generalize availability fix-its to support custom availability domains.
Resolves rdar://156118254.
2025-07-18 13:27:08 -07:00
Allan Shortlidge
a3fbe3d530 AST: Introduce queries on Decl for active @available attrs.
Use these queries to replace some duplicated code. Also, move the
`attr_inlinable_available.swift` test to the `Availability` sub-directory since
the test has more to do with availability checking than it has to do
specifically with the `@inlinable` attr.
2025-07-18 13:27:08 -07:00
Anthony Latsis
d7ec3a34bb Merge pull request #83094 from swiftlang/jepa-main
Sema: Make `@concurrent` not imply `async` on closures
2025-07-17 01:54:04 +01:00
Anthony Latsis
58d5059617 Sema: Make @concurrent not imply async on closures
The present approach is not prudent because `@concurrent` synchronous
functions, a natural extension, are a likely-to-happen future direction,
whereas the current inference rule is entirely grounded on `@concurrent`
being exclusive to async functions.

If we were to ship this rule, we would have to keep the promise for
backwards compatibility when implementing the aforementioned future
direction, replacing one inconsistency with another, and possibly
introducing new bug-prone expression checking code.

```swift
func foo(_: () -> Void) {}
func foo(_: () async -> Void) {}

// In a future without this change and  `@concurrent` synchronous
// functions accepted, the first call resolves to the first overload,
// and the second call resolves to the second, despite `@concurrent` no
// longer implying `async`.
foo { }
foo { @concurrent in }
```

This change also drops the fix-it for removing `@concurrent` when used
on a synchronous closure. With the inference rule gone, and the
diagnosis delayed until after solution application, this error raises a
fairly balanced choice between removing the attribute and being
explicit about the effect, where a unilateral suggestion is quite
possibly more harmful than useful.
2025-07-16 20:46:29 +01:00
Allan Shortlidge
d09e117dc0 AST: Canonicalize platform versions for @backDeployed attrs.
Also, diagnose invalid platform versions.

Part of rdar://155558161.
2025-07-14 16:40:16 -07:00
Pavel Yaskevich
d8a12e9b75 Merge pull request #82925 from xedin/remove-concurrency-attr-clash-downgrade
[Concurrency] Don't downgrade explicit isolation attribute clashes
2025-07-11 10:52:06 -07:00
Pavel Yaskevich
a9373c0f3f [Concurrency] Don't downgrade explicit isolation attribute clashes
The compiler shouldn't accept mismatch in explicit isolation attributes
because it could lead to incorrect isolation selection.
2025-07-09 10:59:13 -07:00
Alexis Laferrière
9e953d2f96 Merge pull request #82891 from xymus/cdecl-reserved-names
Sema: Report the use of reserved names by `@cdecl` functions
2025-07-09 09:22:03 -07:00