Commit Graph

4472 Commits

Author SHA1 Message Date
Meghana Gupta f2e5629edf Add a feature for Builtin.dereferenceable 2026-06-10 09:40:24 +05:30
Erik Eckstein 4a8444ad42 add Builtin.gepProjection
It's like Builtin.gep, but marks the resulting `index_addr` as a projection, meaning the result can only reach the single element at the given index and cannot be used for general pointer arithmetic by chaining `index_addr` instructions.
2026-06-09 16:17:53 +02:00
Paul Passeron 425cd0ebd7 [experimental] Infrastructure for derived conformances via macros (#89419)
**Overview**:
This PR introduces the basic infrastructure needed to eventually migrate
derived macros generation from hand-crafted AST nodes to macros. No
conformance have been migrated yet.

**Motivation**:
Derived conformances (e.g. `Equatable`, `Hashable`, `Codable`, ...) are
currently implemented as a special case in the compiler, producing
synthetic AST nodes directly. Migrating this to macros will hopefully
unify the code path with the existing macro expansion infrastructure,
make conformance synthesis easier to extend and test as well as reducing
the amount of special cases in the compiler.

**Changes**:
- New experimental feature flag `DeriveConformancesViaMacros`:
Introduces the flag that will eventually gate the new derived
conformance code paths. It does not control any behaviour for the moment
as none have been migrated yet but this enables future changes to be
built incrementally.
- New GeneratedSourceInfo and SourceFile kinds `SyntheticMacro`:
Introduces new GSI and SourceFile kinds named `SyntheticMacro` to
represent macros synthesized by the compiler. Since macros need a real
buffer to expand, this is the kind of source file and GSI associated
with those buffers.
- Conformance derivation via macros API:
Introduces the `deriveRequirementViaMacro` function that produces the
required witness via macro expansion.

See https://github.com/swiftlang/llvm-project/pull/13124 for
llvm-related changes.

**Next steps**:
- Macros do not contain any semantic information, especially regarding
types. Therefore it is necessary to provide them with type information
as an argument so they can eventually derive the conformances. A
separate PR is being created to generate this type information as
strings containing swift-parsable code for easy parsing on the macro
end.
- Implement derived conformance synthesis for individual protocols using
the new infrastructure, like `Equatable` or `Hashable` for starters.
- Wire the experimental flag to gate the new path once an implementation
exists

---------

Co-authored-by: Hamish Knight <hamish_knight@apple.com>
2026-06-08 14:23:58 +01:00
Doug Gregor 67c82cb991 Merge pull request #89741 from DougGregor/freestanding-concurrency-global-executor
[Cooperative global executor] Drop explicit <chrono> usage
2026-06-06 18:22:06 -07:00
Tony Allevato bd216eb75a Merge pull request #89125 from allevato/raw-identifier-decl-names
Handle raw identifiers correctly in renamed APIs.
2026-06-06 19:22:43 -04:00
Doug Gregor 64f98f8b57 [Cooperative global executor] Drop explicit <chrono> usage
The cooperative global executor uses <chrono> for its handling of
times. This creates a dependency on a C++11 standard library, and
doesn't actually work with freestanding implementations like we want
for Embedded Swift.

Replace this <chrono> usage with swift_sleep / swift_get_time from
the concurrency library, which already considers various
platform-specific implementations before falling back to <chrono>.

Enable -ffreestanding for the embedded Concurrency library and its
support libraries.
2026-06-06 11:53:07 -07:00
Egor Zhdan df7d8cb3a6 [cxx-interop] Guard FRT inheritance behind an experimental feature flag
This is a follow-up to 6c464579.

Importing superclasses of C++ foreign reference types can introduce source breaks in Swift under some circumstances.

This change puts the feature behind an experimental flag.

rdar://178736469
2026-06-06 15:43:32 +01:00
Michael Gottesman 9d4a80fdea Merge pull request #89560 from gottesmm/pr-86ad485815bcc71e92b6156364f7094d13ece0a0
[flow-isolation] Gate global-actor flow-isolation delegation behind FlowIsolationGlobalActor feature
2026-05-29 19:08:34 -07:00
Michael Gottesman 8d605afb71 [flow-isolation] Gate global-actor flow-isolation delegation behind FlowIsolationGlobalActor feature
Previously, the Sema changes that defer checking of global-actor-isolated
initializers (and the global-actor-isolated stored properties they access) to
the SIL-level flow-isolation pass were enabled unconditionally whenever strict
concurrency was complete.

This introduces a new experimental feature, FlowIsolationGlobalActor, and gates
those two Sema delegation code paths behind it:

  - isolatedConstructorRequiresFlowIsolation's GlobalActor case, which makes
    synchronous global-actor-isolated nominal-type initializers use
    flow-sensitive isolation.
  - ActorReferenceResult::Builder::build's checkedByFlowIsolation delegation,
    which suppresses the cross-isolation Sema diagnostic in favor of the
    flow-isolation pass.

With the feature off, we restore the prior Sema behavior. Since the SIL passes
key off usesFlowSensitiveIsolation, gating Sema is sufficient end-to-end.

The dedicated flow_isolation_* tests and the shared tests whose expectations
were updated for this behavior now enable the feature explicitly. A small,
standalone flow_isolation_no_feature.swift test validates that the old behavior
is restored without the flag and is easy to delete once the feature becomes the
default.
2026-05-29 13:37:27 -07:00
Konrad `ktoso` Malawski 74752f936a [Concurrency] Guard noncopyable continuation builtin uses (#89524) 2026-05-29 11:26:34 -07:00
Sam Pyankov 73852c2195 Merge pull request #89190 from sepy97/ipi-clang-modules
Sema: Enforce IPI library level for Clang modules
2026-05-27 17:50:33 -07:00
Sam Pyankov e292be9a1b Sema: Enforce IPI library level for Clang modules
Add -ipi-clang-module flag to enforce IPI library level for Clang modules.
Compiler stores names of those modules and checks them during typechecking.

rdar://177196788
2026-05-27 10:04:15 -07:00
Alejandro Alonso 4de6552972 Merge pull request #89300 from Azoy/welcome-back-borrowinout-feature
[stdlib] Reintroduce BorrowInout feature to guard Ref and MutableRef
2026-05-26 14:35:03 -07:00
Henrik G. Olsson 8cab956b23 Merge pull request #88548 from hnrklssn/verify-child-notes
[DiagnosticVerifier] add -verify-child-notes
2026-05-21 17:10:28 -07:00
Kavon Farvardin 2bdaa53b5d Convert PreInverseGenericsExcept to a SUPPRESSIBLE_EXPERIMENTAL_FEATURE
The suppression can help us avoid a typechecking condfail,
though the mangled names of any symbols will be wrong as we simply
omit the attribute in this simplistic suppression strategy.

related to rdar://176395527
2026-05-20 17:35:12 -07:00
Anthony Latsis c36f87b6b2 Merge pull request #89281 from swiftlang/jepa-main4
Address upstream llvm deprecation
2026-05-20 21:49:50 +01:00
Alejandro Alonso 1a288f8a02 Reintroduce BorrowInout feature to guard Ref and MutableRef 2026-05-20 12:07:39 -07:00
Anthony Latsis 405d21b92f Address upstream llvm deprecation
See https://github.com/llvm/llvm-project/pull/174109.
2026-05-20 16:57:38 +01:00
Doug Gregor 7d48e98f5e Replace the DeferredCodeGen feature with CodeGenerationModel=<model>
The default code generation model for Embedded Swift is "inlinable".
DeferredCodeGen made the default code generation model
"implementation", and there was no spelling for "interface".

Introduce the experimental feature CodeGenerationModel=<model>, which
can be any of those three options. The default remains "inlinable", but
one can now specify "implementation" (which keeps most everything in
SIL) or "interface" (which only keeps the generic things in SIL). The
"interface" mode is more like non-embedded Swift for non-generic
declarations, emitting them into the IR (only) but not SIL. Generic
declarations would remain in SIL.

Implements rdar://172433062.
2026-05-20 08:35:13 -07:00
Tony Allevato 0924981eab Handle raw identifiers correctly in renamed APIs.
This change adds support for raw identifiers when renaming APIs in
Swift. This includes APIs defined in Swift (using the
`@availability(..., renamed: ...)` attribute), as well as C/Objective-C
(using either the `swift_name` attribute or APINotes). All of these take
decl names as strings, and so the parsing for these requires that any
decl name components (the base name or the argument labels) must have
surrounding backticks in order to be treated correctly as a raw
identifier.

Getting this working required some refactoring of `ParsedDeclName`
since it previously assumed that it could just split around delimiters
like `.`, `(`, and `:`. That's no longer guaranteed to work, so I've
introduced backtick-aware split helpers to deal with this. Likewise,
`ParsedDeclName` now keeps track of special decl base names (like
`init` and `subscript`) to ensure that they're handled properly and
not incorrectly escaped under the new logic.
2026-05-17 21:03:18 -04:00
Michael Gottesman de8ffa5c96 Merge pull request #88936 from gottesmm/pr-8c09d3b5dc72a3bf501f3feea39e69b786040836
[diagnostic] Convert swift-diagnostics-assert-on-{error,warning} from llvm::cl::opt globals to Swift frontend flags
2026-05-15 17:26:01 -07:00
Kavon Farvardin 19119ad88a introduce @_preInverseGenerics(except:)
@_preInverseGenerics(except: <inverses>) is an extension of the existing
@_preInverseGenerics attribute that provides selective control over which
inverse requirements are mangled into a declaration's symbol name.

While the bare @_preInverseGenerics strips all inverse constraints
(~Copyable and ~Escapable) from mangling, the 'except:' form allows specific
inverses to be retained. This is needed when a type like Span already had
~Copyable mangled into its ABI-stable symbols and now needs to retroactively
adopt ~Escapable without changing those existing symbols. You can now express
that with `@_preInverseGenerics(except: ~Copyable)` to strip-out every inverse
except ~Copyable to preserve the pre-existing ~Copyable-containing symbols.

It requires the new experimental feature `PreInverseGenericsExcept`.

rdar://176395527
2026-05-14 18:27:00 -07:00
Michael Gottesman c36f842bed [diagnostic] Convert diagnostics-assert-on-{error,warning} and sil-region-isolation-assert-on-unknown-pattern from llvm::cl::opt globals to Swift frontend flags, and add -diagnostics-assert-on-group
llvm::cl::opt flags are compiled out in non-asserts builds, making these
debug flags unavailable in an important category of use cases — debugging
a release compiler in lldb. By promoting them to Swift frontend flags stored
in DiagnosticOptions/SILOptions, they are available in all build
configurations.

The three existing flags are migrated:
  -diagnostics-assert-on-error
  -diagnostics-assert-on-warning
  -sil-region-isolation-assert-on-unknown-pattern
    (backing field renamed to AbortOnUnknownRegionIsolationPatternError)

A new flag is added:
  -diagnostics-assert-on-group <group>
    Traps when any diagnostic belonging to the named group is emitted,
    allowing targeted breakpoints on a single diagnostic group rather than
    all errors or all warnings.

The assert-on-{error,warning,group} flags are intentionally kept separate
from the normal diagnostic suppression/escalation machinery so that they
remain useful while other diagnostics are also being emitted.

Tests are added for all four flags.
2026-05-14 17:36:08 -07:00
Artem Chikin e1b0e520b3 Merge pull request #88950 from artemcm/DefaultSourceWarningControl
[SourceWarningControl] Promote `@diagnose` attribute to a default language feature
2026-05-11 17:03:04 +01:00
Artem Chikin 740800dd21 [SourceWarningControl] Promote '@diagnose' attribute to a default language feature
No longer experimental as of approval of SE-0522.

Resolves rdar://176535491
2026-05-08 09:59:11 +01:00
Henrik G. Olsson 8e7036f78b Merge pull request #88621 from hnrklssn/swiftify-span-typedefless
[Swiftify] enable safe wrappers for std::span without typedef
2026-05-07 09:56:47 -07:00
Xi Ge 6112096f0e [Sema] Add experimental feature flag to allow internal bridging header types in stored property layout
In non-resilient modules, stored properties are implicitly exported for layout purposes, preventing the use of types from an internal
bridging header. This adds the AbstractStoredPropertyLayout experimental feature flag that suppresses the exportability diagnostic
specifically for layout-contributing stored properties (ImplicitlyPublicVarDecl and ImplicitlyPublicVarDeclOpenClass), enabling a
public struct to contain private stored properties of C types imported via -internal-import-bridging-header.

This is the first step toward encoding abstract layout information in the .swiftmodule so that clients can allocate, copy, and
destroy values without loading the internal C dependency.
2026-05-05 10:28:20 -07:00
Pavel Yaskevich 4201e579be Merge pull request #88162 from CognitiveDisson/feat/scope-based-expression-type-checking-warnings
[Sema] Add scope-based analogues of -warn-long-expression-type-checking
2026-05-04 06:35:35 -07:00
Alejandro Alonso b87c07a487 Rename Borrow and Inout to Ref and MutableRef 2026-05-01 16:54:42 -07:00
Kavon Farvardin f223048597 Merge pull request #88746 from kavon/manualownership-in-production
ManualOwnership: permit use in production builds
2026-04-30 11:10:51 -07:00
Kavon Farvardin 7b00c44149 ManualOwnership: permit use in production builds
This feature is just to enable a new set of diagnostics
that one can opt-into with `@diagnose` (nee `@warn`) or
with `-Wwarning`/`-Werror`.

There's no material impact on programs; it's more of a SIL pass
that you can opt into turning on that will emit diagnostics.

The current implementation does slightly change the emitted
code, so it's not just on-always until it's fully tested.

For example, it does change how no-implicit-copies enforcement
happens for `borrowing` parameters of functions, making it
effectively optional based on your preference for seeing warnings
about `SemanticCopies`. I think that's a better direction to head
towards anyway.

rdar://175897573
2026-04-29 17:31:52 -07:00
Henrik G. Olsson 3a2ec2b51b [Macros] add -eager-macro-checking frontend option
Normally macro expansions are typechecked through the normal traversal
of the AST. This does not happen with macro expansions in clang modules
however, since the clang module is not traversed by the typechecker.
This is not too problematic, since all the code in clang modules is
generated by the toolchain, so incorrect code would only occur when
there's a bug in the toolchain. Catching these bugs would be a lot
easier if we actually ran the typechecker during testing. We don't want
to do this normally, as it breaks the laziness of the typechecking, so
this adds -eager-macro-checking to specifically enable this behavior.
It's intended for testing purposes only.
2026-04-29 12:30:47 -07:00
Aidan Hall fb2aa63295 Merge pull request #87217 from aidan-hall/lifedep-infer-closure-dependence
LifetimeDependence closure context dependence
2026-04-27 16:23:04 +01:00
Aidan Hall 34a7dc2181 FlagSet: Functional-style builder methods for flags 2026-04-24 15:54:30 +01:00
CognitiveDisson 575e69f90e [Sema] Add scope-based analogues of -warn-long-expression-type-checking 2026-04-23 10:46:03 +01:00
Kavon Farvardin 610a9f98ed SuppAssocTypes: enable SE-503 by default 2026-04-22 22:11:41 -07:00
Henrik G. Olsson aa1f0f2bfb [DiagnosticVerifier] add -verify-child-notes
With this option enabled the DiagnosticVerifier enforces a strict child
note hierarchy: if a note has a parent diagnostic (which it should), it
can only be matched by an expected-note matcher in the {{children:}}
block of the matcher of its parent diagnostic. This makes it clear when
reviewing which note belongs to which diagnostic, and lets
update-verify-tests keep that structure (support in update-verify-tests
not yet added). If the note is far away from the parent it can be
matched with a line marker (#foo on the line of the emitted note).

Without this option enabled (default behavior) {{children:}} blocks are
an error.

Additionally, change the verification error sort order to use buffer
ID as the primary key (address within buffer as secondary), so that
error output is stable across source files in multi-file compilations.
2026-04-19 14:18:20 -07:00
Tim Kientzle c46cabde95 Merge pull request #88504 from tbkka/tbkka-yielding-in-swiftinterface
Write `yielding` accessor names to swiftinterface files
2026-04-19 13:35:54 -07:00
Doug Gregor aad51cab01 [Embedded] Remove the ability to disable existentials in Embedded Swift
Support for existentials in Embedded Swift has been available for a
little while now and appears to be solid. Remove the ability to disable
them (via `-disable-experimental-feature EmbeddedExistentials`), both
because it simplifies the code and because it's an ABI break to
disable the feature.
2026-04-17 17:38:01 -07:00
Doug Gregor 8713c13bef Centralize computation of the "code generation model" for object code & SIL
For a given function, we might end up emitting it's definition as
object code, serialized SIL, or both. The @export, @inlinable, and
@inline(always) attributes provide control of this behavior at the
declaration level.

Centralize the query function that will look for each of these
attributes and map down to a specific "code generation model", whose 3
options follow the naming from SE-0497: interface, inlinable, and
implementation. Use this one computation to back the queries for
"always emit into client", "never emit into client", and "inlinable"
so we can't get inconsistent results from places that are doing
one-off checks for these attributes.
2026-04-15 13:03:55 -07:00
Tim Kientzle c85ebdaed5 Write yielding accessor names to swiftinterface files
Back in January, I updated the swiftinterface _reading_ code to accept either
`read`/`modify` or `yielding borrow`/`yielding mutate`.  That update has been
around for long enough that we can now switch over the swiftinterface _writing_
code to emit the standard final `yielding borrow`/`yielding mutate` spellings.

Interface files written with the old spellings will continue to be
accepted for some time (likely a year or more).
2026-04-15 12:34:46 -07:00
Meghana Gupta 3d3d476b6f Merge pull request #88107 from meg-gupta/enableborrow
Enable BorrowAndMutateAccessors by default
2026-03-27 12:43:02 -07:00
Alexis Laferrière 1af6d6d28e Merge pull request #87353 from xymus/polyglot-ast-gen
ClangImporter: Services to parse Objective-C code and generate a `@objc @implementation` stub
2026-03-27 12:18:56 -07:00
Meghana Gupta d6e220669f Enable BorrowAndMutateAccessors by default 2026-03-25 16:52:39 -07:00
Konrad `ktoso` Malawski 923e8da19a [Concurrency] guard cancel shields vs unsuported SDKs (#88089)
Otherwise we can emit those funcs into clients whose SDK doesn't know
about the builtins and fail compilation with module 'Builtin' has no
member named 'taskCancellationShieldPush'

resolves rdar://173170400
2026-03-26 04:30:01 +09:00
Alexis Laferrière 43654566ae Frontend: Intro emit-polyglot-ast action 2026-03-25 11:36:15 -07:00
Konrad Malawski 9aeeb328ed [Concurrency] guard cancel shields vs unsuported SDKs
Otherwise we can emit those funcs into clients whose SDK doesn't know
about the builtins and fail compilation with module 'Builtin' has no member named 'taskCancellationShieldPush'

resolves rdar://173170400
2026-03-25 14:51:25 +09:00
Allan Shortlidge 9a25399f81 Make StrictAccessControl an experimental feature.
It was originally introduced as an upcoming feature, but there isn't any
precedent for using upcoming features as a way to opt-in to type checking fixes
without an associated Swift Evolution proposal. Rather than using a "feature" to
control this behavior, it would probably be better to offer a way to use
`-Werror` to upgrade these warnings to errors.
2026-03-24 17:59:40 -07:00
Pavel Yaskevich de8b2fb22c [Frontend] SE-0518: Turn TildeSendable into a language feature
The proposal has been accepted and `~Sendable` doesn't require
an explicitly enabled experimental flag.
2026-03-20 10:27:12 -07:00
John McCall 0b6a4e21ff Add properly paired builtins for pushing and popping task-local values
I can't quite enable modeling their stack effects in this patch because
SILGen generates improperly-nested allocations; that'll be fixed in a
follow-up.
2026-03-20 00:21:40 -04:00