Commit Graph

4452 Commits

Author SHA1 Message Date
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
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
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
Ben Langmuir 768fb73f8b Merge pull request #87862 from benlangmuir/casoptions-adaptation
[cas] Adapt to clang::CASOptions change to remove internal cache of instances
2026-03-19 09:42:20 -07:00
Ben Langmuir 6e29396ede Merge pull request #87581 from benlangmuir/hash-xattr
[cas] Introduce a frontend option to write CAS hash to an xattr
2026-03-17 13:21:29 -07:00
Ben Langmuir 11312f84de [cas] Introduce a frontend option to write CAS hash to an xattr
With the new option, when doing caching we write the hash that we already
computed for the main output file to an extended attribute (xattr) on the file.
This is equivalent to clang's -fwrite-output-hash-xattr option.

The format of the xattr is
name: com.apple.clang.cas_output_hash
data:
* Null-terminated hash schema name, e.g. llvm.builtin.v2[BLAKE3].
* Hash length (4 bytes, little-endian).
* Hash bytes

rdar://171185394
2026-03-16 15:06:33 -07: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
Steven Wu f620d37dda Reapply: [Caching][NFC] Using llvm::cas::CASConfiguration
This no longer causes a regression in number of CAS instances.

Prefer llvm::cas::CASConfiguration where it used to clang::CASOption.

(cherry picked from commit 4f059033bb)
2026-03-13 15:41:36 -07:00
Steven Wu ab7667d217 [NFC] Cleanup for #87272
Remove unused variable and assumptions about CASID that should never be
true.
2026-03-12 17:16:16 -07:00
Kavon Farvardin 8f8b782531 Merge branch 'main' into se427-techdebt 2026-03-11 10:00:18 -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
Doug Gregor 204e9197f4 Merge pull request #87747 from DougGregor/oslog-section-name-global-var 2026-03-10 06:24:25 -07:00
Tony Allevato ea70fc2f5b Merge pull request #87729 from allevato/fuzzer-no-link
Support `-sanitize=fuzzer-no-link`.
2026-03-10 07:50:28 -04:00
Artem Chikin 1ba5ae1058 Merge pull request #87646 from artemcm/GuardSyntacticWarningsOnFeature
[Diagnostics] Guard the user-controlled behavior warning logic behind experimental feature
2026-03-10 09:32:13 +00:00
Doug Gregor 454237a083 Allow the OSLog module to specify the log string section name
When building the `OSLog` module, look for a variable named
`osLogStringSectionName`. It must have a string literal as its
initializer, which provides the section name where the log strings
should be emitted. The `OSLog` module should contain something like
this:

    let osLogStringSectionName = "__TEXT,__logit"

When not present, the compiler will default to
`__TEXT,__oslogstring,cstring_literals`, which was previously the
hardcoded section name. Now, OSLog can customize the name.

Implements rdar://171571056
2026-03-09 10:27:54 -07:00
Artem Chikin 8b395b3280 [Diagnostics] Guard the user-controlled behavior warning logic behind experimental feature
`-enable-experimental-feature SourceWarningControl` guards the actual *use* of `@warn` attribute, but it did not guard this logic which queries it, which is meant to be general in the absense of the attribute as well.

We are seeing some unintended compile time performance implications from this logic, so for now guard it behind the same experimental feature flag.

Related to rdar://171506799
2026-03-09 12:17:15 +00:00
Hamish Knight 451f7df952 [Sema] Fix type-checker assertion for SourceKit
We ought to properly fix this, but for now let's avoid asserting for
SourceKit.
2026-03-08 00:19:10 +00:00
Tony Allevato ca737c9b94 Support -sanitize=fuzzer-no-link.
This mirrors Clang's `-fsanitize=fuzzer-no-link`, which applies the
appropriate instrumentations but does not attempt to link to the
runtime library. More importantly, this suppresses the check in the
driver that fails the build if the library cannot be found. Since
libfuzzer is not distributed with Xcode, this allows users to build
it themselves or take it from a swift.org toolchain and use it
without having to physically copy/link it into their toolchain's
runtime directory.
2026-03-07 09:39:53 -05: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
Saleem Abdulrasool f81aa70e75 Basic, Sema: adjust for LLDB (NFC)
LLDB defines `lldb::private::swift::` which causes ambiguity for
lookups. Use aliases and fully qualified names to avoid the ambiguity.
This fixes some errors with building on Windows with the GNU driver.
2026-03-04 19:17:26 -08:00
Nate Cook 856b205170 De-underscore the BorrowingSequence protocols (#87483)
This replaces #87114, aligning the `BorrowingSequence` protocols and
related types to the Swift Evolution proposal, and without included
reparenting of `Sequence`.
2026-03-04 07:13:20 -06:00
Allan Shortlidge 9724348f86 AST: Allow anyAppleOS availability without an experimental feature.
Resolves rdar://170988964.
2026-03-02 14:05:39 -08:00
Slava Pestov 9336f9860a Merge pull request #87159 from slavapestov/exact-bindings
Sema: Exact bindings
2026-02-27 11:54:32 -05:00