Commit Graph

850 Commits

Author SHA1 Message Date
Anton Korobeynikov
797f500286 Add basic boilerplate for AST coroutines and yields 2025-11-12 21:02:25 -08:00
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
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
Kuba (Brecka) Mracek
b6c29f1ce6 Merge pull request #85136 from kubamracek/section-top-level
SE-0492: Handle top-level `@section`-annotated globals
2025-11-04 11:15:50 -08:00
Kuba Mracek
ee623f8d59 Add @section/@const handling of globals to ASTGen too 2025-11-03 13:47:51 -08:00
Allan Shortlidge
80a292be00 ASTGen: Work around a retroactive conformance bug in Swift 6.2.
The Swift 6.2 compiler emits spurious warnings about retroactive conformances
to protocols that are inherited through a protocol that is written module
qualified in the inheritance clause. Suppress the warnings by making the
inherited conformances explicit and module qualified.
2025-10-26 18:00:05 -07:00
Allan Shortlidge
bf9598ae77 ASTGen: Fix an implicit pointer conversion warning. 2025-10-26 18:00:05 -07:00
Allan Shortlidge
2eca462cbd ASTGen: Remove an unnecessary try. 2025-10-26 18:00:05 -07:00
Allan Shortlidge
fce3adb86a Merge pull request #85132 from tshortli/fix-warnings
Fix various warnings
2025-10-25 01:04:26 -07:00
Allan Shortlidge
d6c9080816 ASTGen: Suppress spurious retroactive conformance warnings.
The Swift 6.2 compiler has a bug where it diagnoses inherited conformances as
retroactive even if they are inherited through a protocol that has been written
module-qualified in the inheritance list. Work around this bug to avoid
superflous warnings.

NFC.
2025-10-24 19:47:15 -07:00
Kavon Farvardin
2d881bdc9c ManualOwnership: provide ability to apply to entire compilation unit
With this patch, I'm flipping the polarity of things.

The flag `-enable-experimental-feature ManualOwnership` now turns on the diagnostics,
but they're all silenced by default. So, you need to add -Wwarning or -Werror to
your build settings to turn on the specific diagnostics you care about.

These are the diagnostic groups relevant to the feature:

- SemanticCopies aka "explicit copies mode"
- DynamicExclusivity

For example, the build setting `-Werror SemanticCopies` now gives you errors about
explicit copies, just as before, but now you can make them just warnings with -Wwarning.

To opt-out a declaration from everything when using the feature, use @_noManualOwnership.

@_manualOwnership is no longer an attribute as a result.

resolves rdar://163372569
2025-10-24 18:54:07 -07:00
Kuba (Brecka) Mracek
eb23d3bc0a Merge pull request #85074 from kubamracek/section
SE-0492: Stabilize @_section/@_used into @section/@used
2025-10-24 12:29:48 -07:00
Kuba (Brecka) Mracek
66eef684ee Merge pull request #80212 from kubamracek/object-file-format
Add #objectFormat compilation conditional (SE-0492)
2025-10-23 12:58:23 -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
Becca Royal-Gordon
d8d226c966 Merge pull request #84362 from beccadax/mod-squad-parse
[SE-0491] Parse and ASTGen module selectors
2025-10-17 23:34:11 -07:00
Rintaro Ishizaki
6a1604ba09 [ASTPrinter/Parse] Disambiguate accessor block in .swiftinterface
.swiftinterface sometimes prints a pattern binding initializer and the
accessor block. However the parser doesn't expect such constructs and
the disambiguation from trailing closures would be fragile. To make it
reliable, introduce a disambiguation marker `@_accessorBlock` .
`ASTPrinter` prints it right after `{` only if 1) The accessor block is
for a pattern binding declaration, 2) the decl has an initializer
printed, and 3) the non-observer accessor block is being printed. In the
parser, if the block after an initializer starts with
`{ @_accessorBlock`, it's always parsed as an accessor block instead of
a trailing closure.

rdar://140943107
2025-10-16 22:16:29 -07:00
Kuba Mracek
c3f865be4a Add #objectFormat compilation conditional (SE-0492) 2025-10-16 15:15:27 -07:00
Becca Royal-Gordon
683ce9d639 Update and test ASTGen for module selectors 2025-10-16 13:30:30 -07:00
Becca Royal-Gordon
fa5594a862 [NFC] [ASTGen] Don’t form PBDs without SourceLocs
A PatternBindingEntry formed from a MissingPatternSyntax has no valid SourceLocs in it, and a PatternBindingDecl containing only PatternBindingEntries with no valid SourceLocs trips an assertion during availability checking. (Generating dummy SourceLocs can cause invalid overlaps between AvailabilityScopes, so that’s not a workable solution.) The fix is to:

• Refuse to generate a PatternBindingEntry from a PatternBindingSyntax with a MissingPatternSyntax (MissingPatternSyntaxes at nested positions don’t have this problem)
• Refuse to generate a PatternBindingDecl with no PatternBindingEntries

This ensures that the invalid AST nodes are never formed.

No current test cases hit this problem, but certain invalid module selector tests can run into this situation when run with ASTGen.
2025-10-16 13:30:29 -07:00
Becca Royal-Gordon
c9bb85a875 [NFC] Add DeclNameLoc to specialize/dynamicReplacement 2025-10-16 13:30:28 -07:00
Hamish Knight
2b8a1cccfd [AST] Store owning Decl/DeclContext on CustomAttr
Introduce CustomAttrOwner that can store either a Decl for an
attached attribute, or a DeclContext for e.g a type or closure
attribute. Store this on CustomAttr such that we can query it from
the name lookup requests.
2025-10-13 13:37:29 +01:00
Meghana Gupta
73bc2ac0b0 Map BorrowAndMutateAccessors experimental feature to swift-syntax equivalent 2025-10-07 14:39:22 -07:00
Rintaro Ishizaki
9953b1e3db Merge pull request #84553 from rintaro/parser-recover-stmtlevel
[ASTGen] Update for UnexpectedCodeDeclSyntax addition
2025-10-03 17:09:07 -07:00
Meghana Gupta
fa7281d66e Introduce a new attribute @_unsafeSelfDependentResult
It can be used in borrow/mutate accessors to unsafely specify that the
result is dependent on the self access.
2025-10-02 07:42:07 -07:00
Arnold Schwaighofer
7853ba0a7f Merge pull request #84178 from aschwaighofer/inline_always
Add experimental feature `@inline(always)`
2025-10-01 07:23:24 -07:00
Arnold Schwaighofer
25a071efc8 Add experimental feature @inline(always)
The intent for `@inline(always)` is to act as an optimization control.
The user can rely on inlining to happen or the compiler will emit an error
message.

Because function values can be dynamic (closures, protocol/class lookup)
this guarantee can only be upheld for direct function references.

In cases where the optimizer can resolve dynamic function values the
attribute shall be respected.

rdar://148608854
2025-09-30 08:36:26 -07:00
Doug Gregor
2a46916536 Reseat CompilerBuildConfiguration on top of StaticBuildConfiguration
Now that we have a per-ASTContext StaticBuildConfiguration, reimplement
(almost) everything in CompilerBuildConfiguration to sit on top of it.
Only canImport requires the full ASTContext, so that gets its own
implementation, as does one other operation that can produce an error.
Aside from more code sharing, this provides additional validation that
the StaticBuildConfiguration we build is complete and accurate.
2025-09-29 18:42:15 -07:00
Doug Gregor
3082b04b75 [Macros] Feed the static build configuration into macro expansions
Thread the static build configuration (formed from language options) in
to the macro plugin handler, which will serialize it for use in the
macro implementation. test this with a simple macro that checks
whether a particular custom configuration (set via `-D`) is enabled or
not.

This required some re-layering, sinking the logic for building a
StaticBuildConfiguration from language options down into a new
swiftBasicSwift library, which sits on top of the C++ swiftBasic and
provides Swift functionality for it. That can be used by the C++
swiftAST to cache the StaticBuildConfiguration on the ASTContext,
making it available for other parts of ASTGen.
2025-09-29 18:42:15 -07:00
Doug Gregor
ae8f9d8234 Add -print-static-build-config to print a static build conformance
Introduce the ability to form a `StaticBuildConfiguration` from
language options. Add a frontend option `-print-static-build-config`
to then print that static build configuration as JSON in a manner that
can be decoded into a `StaticBuildConfiguration`.

Most of the change here is in sinking the bridged ASTContext queries
of language options into a new BridgedLangOptions. The printing of the
static build configuration only has a LangOptions (not an ASTContext),
so this refactoring is required for printing.
2025-09-29 18:42:14 -07:00
Rintaro Ishizaki
7a4b7aa92a [ASTGen] Update for UnexpectedCodeDeclSyntax addition 2025-09-27 12:04:09 -07:00
Kavon Farvardin
61fe8a9b8e introduce @_manualOwnership performance attribute
This attribute forces programmers to acknowledge every
copy that is required to happen in the body of the
function. Only those copies that make sense according
to Swift's ownership rules should be "required".

The way this is implemented as of now is to flag each
non-explicit copy in a function, coming from SILGen, as
an error through PerformanceDiagnostics.
2025-09-17 13:51:57 -07:00
Doug Gregor
01873c996f Merge pull request #84283 from DougGregor/embedded-swift-untyped-throws-restriction
[Embedded] Diagnose untyped throws as an Embedded Swift restriction
2025-09-15 12:55:16 -07:00
Doug Gregor
865c643cac Suppress Embedded Restriction diagnostics in code that won't be compiled as Embedded
When emitting diagnostics for the Embedded Swift restrictions outside
of Embedded Swift mode, consider `#if $Embedded` and `#if
hasFeature(Embedded)` configurations. If the code where we would emit
the diagnostic would be disabled in Embedded Swift by one of those
checks, don't emit the diagnostic. This helps code that can compile
either with Embedded or regular Swift stay within the restrictions on
Embedded Swift.
2025-09-15 07:10:00 -07:00
Meghana Gupta
a09e258f7f Enable SIL parsing of borrow and mutate accessors 2025-09-09 14:45:49 -07:00
Evan Wilde
6b92d1dfb4 ASTGen: Fix disable implicit string processing import
The flag is a frontend flag not a driver flag. Fixing how that is
passed.
2025-09-05 10:41:02 -07:00
Saleem Abdulrasool
7a03e8ffc8 ASTGen: prevent _StringProcessing from being loaded
When building the ASTGen library, we are building `_StringProcessing`.
If the SDK version is loaded, it causes confusion over the local
definition and the SDK definition. Avoid the implicit loading of the
module.
2025-09-04 10:00:16 -07:00
Doug Gregor
2f60d729f0 Add @_neverEmitIntoClient to prohibit SIL serialization for a function
Part of the Embedded Swift linkage model, this attribute ensures that
the function it applies to has a strong definition in its owning
module, and that its SIL is never serialized. That way, other modules
will not have access to its definition.

Implements rdar://158364184.
2025-08-17 23:21:57 -07:00
Hamish Knight
396a6a8fe6 Enable InlineArray type sugar
Promote it from an experimental feature.

rdar://155607927
2025-08-04 15:16:30 +01:00
Anthony Latsis
5620abbad8 Bridging: Bridge swift::CharSourceRange directly 2025-07-15 21:34:48 +01:00
Anthony Latsis
9001ce4687 Bridging: Bridge swift::SourceRange directly 2025-07-15 21:33:28 +01:00
Anthony Latsis
6eb5d7d857 Bridging: Bridge swift::SourceLoc directly 2025-07-15 21:33:06 +01:00
Anthony Latsis
8cbf5a26e4 Bridging: Bridge swift::DeclBaseName directly 2025-07-10 17:58:13 +01:00
Anthony Latsis
0e0fbc4160 Bridging: Bridge swift::Identifier directly 2025-07-10 17:58:13 +01:00
Pavel Yaskevich
0444d297b6 [AST/Sema] SE-0487: Remove @preEnumExtensibility attribute 2025-07-04 11:06:44 -07:00
Pavel Yaskevich
fe1ae75711 [AST/Sema] SE-0487: Rename @extensible into @nonexhaustive
This is an accepted spelling for the attribute. This commit
also renames the feature flag from `ExtensibleAttribute` to
`NonexhaustiveAttribute` to match the spelling of the attribute.
2025-07-03 17:50:05 -07:00
Alexis Laferrière
81a0f98783 Merge pull request #82194 from xymus/cdecl-parser
Parser: Accept `@cdecl` with an optional identifier for a custom C name
2025-06-27 15:06:11 -07:00
Anthony Latsis
dd78cd6dbe ASTBridging: Bridge swift::PlatformKind directly 2025-06-20 16:46:03 +01:00
Anthony Latsis
de46b95e7e ASTBridging: Bridge swift::GenericTypeParamKind directly 2025-06-20 16:46:03 +01:00
Anthony Latsis
30a8b59c6e ASTBridging: Bridge swift::TypeAttrKind directly 2025-06-19 18:11:40 +01:00
Anthony Latsis
8501c8776e ASTBridging: Bridge swift::ExternKind directly 2025-06-19 18:11:40 +01:00