Commit Graph

363 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
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
Konrad `ktoso` Malawski df5af5f97c Cleanup: Use more UNINTERESTING_FEATURE where able to (#89537) 2026-05-29 23:54:25 -07: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
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
Alejandro Alonso 59920ddc9c Make BorrowInout interesting again 2026-05-21 10:15:39 -07:00
Alejandro Alonso 1a288f8a02 Reintroduce BorrowInout feature to guard Ref and MutableRef 2026-05-20 12:07:39 -07: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
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
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
Artem Chikin a7bbffd953 Merge pull request #88205 from artemcm/DiagnoseAttr
[Source Warning Control] Rename `@warn` to `@diagnose` & prevent printing it in Textual Interfaces
2026-05-07 16:52:22 +01: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
Alejandro Alonso b87c07a487 Rename Borrow and Inout to Ref and MutableRef 2026-05-01 16:54:42 -07:00
Artem Chikin 00001b93e4 [Source Warning Control] Exclude @diagnose from textual module interfaces
The @diagnose attribute only affects local diagnostic behavior within a declaration's body and has no API or ABI impact. It should not appear in .swiftinterface files, and should not cause declarations to be wrapped in #if $SourceWarningControl feature guards.
2026-04-29 10:39:29 +01:00
Artem Chikin 866371d73e [Source Warning Control] Rename '@warn' to '@diagnose'
Resolves rdar://173774670
2026-04-29 10:39:25 +01:00
Konrad Malawski 4e4769de49 Rename stale CallerIsolated to NonisolatedNonsending 2026-04-28 09:21:23 -07:00
Konrad Malawski 3beefe5bd8 Rename CallerIsolationInheriting -> NonisolatedNonsending 2026-04-28 09:21:23 -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
Kavon Farvardin e2f90d36b3 Merge pull request #88350 from kavon/reparenting-feature-guarding
Reparenting: improve interface feature guarding
2026-04-10 08:24:49 -07:00
Kavon Farvardin aca6d33542 Reparenting: be more defensive in feature guarding
Wouldn't expect it to be the case, but I guess Types
in the AST can be invalid when emitting an interface.
2026-04-09 08:40:49 -07:00
Kavon Farvardin f608fc03ef Reparenting: even more feature guarding improvements
The only known condfail scenario is inheriting from
a protocol P that inherits from a reparentable one R.

We already guard P if it mentions R in its inheritance clause.
So older compilers will simply report that "P" is missing in the
interface, which is a better error message than virally guarding
everything mentioning P. It's an ABI break anyway to do that
without introducing a `@reparented` extension, which needs a guard.

In theory, older compilers shouldn't have too much go wrong if they
were to ignore `@reparentable`, though the RequirementMachine and
witness tables will look different.

rdar://174263176
2026-04-08 10:48:40 -07:00
Kavon Farvardin 82bb7a76bd Reparenting: improve interface feature guarding
This should avoid a condfail when using an older compiler on the newer stdlib that contains the `@reparentable` BorrowingSequence.

rdar://174263176
2026-04-07 19:00:06 -07:00
Alejandro Alonso b6bf06e97e Guard Borrow and Inout definitions 2026-04-01 15:45:28 -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
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
Susana Monteiro 7a3ba1e6b7 Merge pull request #87882 from susmonteiro/susmonteiro/guard-swift-stdlib-version
[cxx-interop] Gate CxxBorrowingSequence behind Swift version check
2026-03-17 14:21:46 +00:00
susmonteiro e66793fcee [cxx-interop] Gate CxxBorrowingSequence behind Swift version check 2026-03-16 17:04:31 +00:00
Dario Rexin b595e463d4 Merge pull request #87663 from drexin/wip-typed-allocation-embedded
[IRGen] Add typed allocations for embedded Swift
2026-03-16 08:51:57 -07:00
Kavon Farvardin e5b2ead0d7 Sema: remove SE427NoInferenceOnExtension
The feature was added only to avoid a reverse-condfail
in the initial bring-up of noncopyable generics.

Nearly 2 years have passed since the last time I tried
to remove this old technical debt [1] and had to revert
it due to outdated build bots [2]. Hoping that won't be
a problem this time.

[1] 5b2f2cbfcf
[2] https://github.com/swiftlang/swift/pull/75267

resolves rdar://131560183
2026-03-11 09:57:47 -07:00
Dario Rexin 5b0da23150 [IRGen] Add typed allocations for embedded Swift
rdar://158239258

This change adds logic in the compiler to compute malloc type ids and emit them together with typed allocation calls. It also adds the new runtime function swift_allocObjectTyped, which calls typed malloc.
2026-03-05 12:41:16 -08:00
Allan Shortlidge 9724348f86 AST: Allow anyAppleOS availability without an experimental feature.
Resolves rdar://170988964.
2026-03-02 14:05:39 -08:00
susmonteiro 933903aae7 [cxx-interop] Gate CxxBorrowingSequence in swiftinterface behind 2026-02-27 18:24:01 +00:00
Nate Cook 5b082c5768 Add BorrowingSequence experimental feature flag (#87542)
This gates the ability to use the BorrowingSequence protocol's name (and
the names of the related types) behind a feature flag.

Landing this separately from #87483.
2026-02-26 23:11:30 -06:00
Erik Eckstein 0ae20ed07b SILGen: add Builtin.markDependence
It directly translates to the `mark_dependence` SIL instruction
2026-02-25 21:47:30 +01:00
Joe Groff 0a16152b40 Add a BorrowInout experimental feature flag.
This gates access to the new standard library `Borrow` and `Inout` types
until they are officially accepted.
2026-02-13 15:23:51 -08:00
John Hui 3e55ed0b7a Merge pull request #87016 from j-hui/lazily-import-methods 2026-02-12 19:42:11 -08:00
elsa af7069a10e Merge pull request #86811 from elsakeirouz/for-in-borrowing-support-no-stdlib-changes
ForEach support for Borrowing sequence

For testing purposes, this commit includes _BorrowingSequence and _BorrowingIterator protocols, with conformance for Span and InlineArray.
2026-02-12 10:08:24 +00:00
John Hui 259b31e035 [cxx-interop] Gate lazy member imports under ImportCxxMembersLazily feature flag
This behavior is currently gated on ImportCxxMembersLazily to provide
an easy off-ramp in case of qualification issues.
2026-02-11 17:47:29 -08:00
Elsa Keirouz 0e7419ea08 add experimental feature flag for borrowing for loop 2026-02-11 16:02:25 +00:00
Artem Chikin 2f0ba5820c Merge pull request #86500 from artemcm/LiteralExpressions
[Literal Expressions] Add support for simple constant-folded literal expressions
2026-02-09 16:20:09 +00:00
Artem Chikin 0bbd35242c [Literal Expressions] Add support for simple constant-folded literal expressions
This change adds an experimental feature 'LiteralExpressions` which allows for use of simple binary expressions of integer type composed of literal value operands.

For now, such literal expressions are only supported in initializers of '@section` values.
2026-02-09 11:35:45 +00:00
Hamish Knight bc65846be2 [Sema] SE-0502: Enable ExcludePrivateFromMemberwiseInit by default
Enable the feature by default, and add an experimental feature
`DeprecateCompatMemberwiseInit` to control the deprecation behavior
which was deferred from the proposal.
2026-02-06 11:50:40 +00:00
Aidan Hall e98a7a6bf8 Merge pull request #86842 from aidan-hall/just-func-type-lifetimes-try-print
LifetimeDependence: Support function types
2026-02-06 10:09:25 +00:00
Aidan Hall 805d8e9e26 Add language feature ClosureLifetimes 2026-02-05 14:50:14 +00:00
Meghana Gupta a3a3134037 Guard borrow/mutate accessors in swiftinterface files 2026-02-04 07:16:28 -08:00
Kavon Farvardin 4a7cedcf1e Reparenting: introduce new attributes
A protocol that's been reparented declares it
by writing `@reparented` in its inheirtance clause
for each new parent. You can introduce a `@reparented`
parent to a pre-existing ABI-stable protocol's
inheritance hierarchy.

Only protocols declared to be  `@reparentable` can be
used to reparent other protocols. Adding or removing
the `@reparentable` attribute is ABI-breaking, as it
effects the type metadata layout. Thus, reparentable
protocols must be born as such to use them with
protocols that are already ABI-stable.

This set of changes does not include the actual
implementation of ABI-stable reparenting.
2026-02-03 16:39:19 -08:00