Commit Graph

4966 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
Argyrios Kyrtzidis 81f4ef3ef7 Merge pull request #89143 from akyrtzi/akyrtzi/pr/cas-input-index-stored-in-result
[CAS] Store the input index along the compiler results
2026-05-20 06:25:33 -07:00
Argyrios Kyrtzidis 429416cabd [CAS] Store the input index along the compiler results
This allows replaying the cached compiler results from an upstream CAS,
if we know the key, without needing access to the caching key input CAS tree.
2026-05-19 11:09:35 -07:00
Xi Ge 0e96664855 Merge pull request #89177 from nkcsgexi/serialize-hidden-type-layout 2026-05-16 06:20:06 -07:00
Xi Ge 00897a0efb [Serialization] Add precomputed layout table for hidden types
Add the module-format machinery that lets a Swift library record the
physical layout of hidden types (currently limited to C types imported via internal bridging header).
into binary modules, so downstream consumers can pull the layouts of these hidden types without
loading the internal dependency.

To test this, this change also added a frontend action to print hidden types' layouts
from both the module under compilation and all the modules being imported.
2026-05-15 10:07:19 -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
Allan Shortlidge c2c8470dac ModuleInterface: Remove warning about types shadowing modules.
Now that module selectors (SE-0491) are used by default when printing
.swiftinterface files, the following warning is unnecessary:

```
public struct <name> shadows module <name>, which may cause failures...
```

Remove the implementation of the warning entirely. Technically, we could keep
diagnosing the issue when use of module selectors in .swiftinterface files is
disabled via the `-disable-module-selectors-in-module-interface` flag, but on
balance it does not seem worth it since we don't anticipate any uses of that
flag aside from temporarily working around compiler bugs.

Resolves rdar://176476640.
2026-05-13 10:39:19 -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
Xi Ge 1c15202f8a Frontend: Add computeAbstractStructLayout for full struct layout computation
Computes per-field abstract layout (offset, size, alignment, mangled name,
bitwiseCopyable, isOpaque) for structs with both Clang-imported and Swift-native fields.

This API will be used from the library-side to serialize layout information to binary modules.
2026-05-08 14:10:06 -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
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
Erik Eckstein 9b94e6bd60 add FrontendStatsTracer for more SIL-related compiler phases 2026-05-07 09:52:09 +02:00
Xi Ge 5911603ce4 AST: introduce the AbstractTypeLayout struct and computeAbstractLayout()
function that queries Clang's ASTRecordLayout to extract size, alignment,
stride, bitwiseCopyable, and isOpaque for C-backed nominal types.

This also adds a -dump-abstract-layout frontend debugging flag that prints
layout info for Clang-backed stored property types in the primary source
file.
2026-05-06 16:14:13 -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
Steven Wu 8123d28cd2 Merge pull request #88629 from cachemeifyoucan/eng/PR-175436790
[Caching] CAS should support remote store/lookup
2026-04-30 12:49:37 -07:00
Henrik G. Olsson 83b0babaa1 disable -eager-macro-checking in import-as-instance-method.swift
Macro expansions in this test trigger warnings, because the listed Span
availability is wider than that of the FRT parameters. This also
triggers an assert since these functions are imported with 2 overloads
that both get macro expansions with warnings in them: one for the free
function, and one for the function re-mapped to a method. Since -verify
disambiguates expansions solely on source location, this use case is not
supported. Having 2 expansions share a source location is okay under
-verify, as long as they don't both have diagnostics emitted.

These diagnostics are only emitted with -eager-macro-checking enabled,
since decls in clang modules are not normally typechecked by the Swift
compiler. The warning could be fixed by adding availability to imported
Swift function when they reference FRTs, but since it's not user
visible, silence it for now.
2026-04-29 12:30:47 -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
Keith Smiley 9d484d4ca1 Early return computeCXXStdlibOptions if disabled
https://github.com/swiftlang/swift/pull/88664/changes#r3141083622
2026-04-27 12:04:04 -07:00
Jan Svoboda 98ef9ba97a [modules] Rename LockFileManager function (#88652)
- **Explanation**: This PR simply reflects one function rename in LLVM.
- **Scope**: Tiny non-functional change.
- **Issues**: rdar://170738600
- **Risk**: None.
- **Testing**: Pre-merge testing.
2026-04-27 09:07:41 -07:00
Pavel Yaskevich 53e4e450b0 Merge pull request #88631 from xedin/fix-blocklist-extension-checking
[Frontend] Fix matching of blocklist extensions
2026-04-24 09:24:19 -07:00
Kavon Farvardin ffedccb3f3 Merge pull request #88307 from kavon/supp-assoc-types-enable
Enable SE-503 (SuppressedAssociatedTypesWithDefaults)
2026-04-23 18:59:14 -07:00
Steven Wu e594497466 Merge pull request #88587 from cachemeifyoucan/eng/PR-175263981
[Caching] Use on-disk path for first-time diagnostic emission with prefix mapping
2026-04-23 16:29:11 -07:00
Pavel Yaskevich a13bb50799 [Frontend] Fix matching of blocklist extensions
`llvm::sys::path::extension` produces an extension together with
the leading `.` which the original code didn't respect. We also
don't care about any other components as long as the last one is
`.yaml` or `.yml`.
2026-04-23 11:28:26 -07:00
Steven Wu f466f7ddc2 [Caching] CAS should support remote store/lookup
For cached output replay or storing compiler produced output, the CAS
should perform remote lookup/store if possible. This allows distributed
caching from plain `swiftc` invocation and unlocks distributed caching
from build systems like `cmake`.

If there is no remote CAS configured, this is NFC.

rdar://175436790
2026-04-23 11:13:00 -07: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
Steven Wu fd8dddc9cd [Caching] Use on-disk path for first-time diagnostic emission with prefix mapping
When CachedDiagnostics emits diagnostics for the first time (cache miss),
the file path shown was the internal prefix-mapped path instead of the real
on-disk path.

Apply remapFilePath when creating the buffer so first-time emission matches
the replay path.

rdar://175263981
2026-04-21 10:26:06 -07:00
Steven Wu 9a5ac1748b [Option] Make -const-gather-protocols-list a frontend argument
Make `-const-gather-protocols-list` behaves just like
`-const-gather-protocols-file` as a frontend flag. This is cause
swift-driver needs to query the frontend flag to see if the compiler
supports the feature. It was a driver flag only, which causes the
swift-driver failed to prefix mapping the file, results in build
failures.

rdar://175194244
2026-04-20 14:31:32 -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 f2eb7cb1a8 [SIL] Model @export(interface) and @export(implementation) on SIL functions
The `@export(interface)` and `@export(implementation)` attributes
SE-0497 are queried directly on AST nodes in several places within the
SIL pipeline. However, they don't persist when SIL functions are
serialized, meaning that clients of the original module might make
different assumptions about the availability of a given function's
definition.

Represent these attributes in a SIL function (as an optional
CodeGenerationModel), (de-)serialize them into the module, and add a
textual representation as SIL function attributes `[export_interface]`
and `[export_implementation]`.
2026-04-15 13:04:10 -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
Saleem Abdulrasool a431d0bf32 Merge pull request #88241 from compnerd/roots
ClangImporter: honour `--sysroot` for C library searches
2026-04-14 13:07:31 -07:00
Saleem Abdulrasool e3dd0235cd ClangImporter,Frontend: honour --sysroot for C/C++ library searches
We previously forwarded `-sysroot` as `-isysroot` which reached cc1, but
left the driver's view of sysroot empty which is used to derive the
system include paths. Thread `--sysroot=` into the clang importer,
ensuring that we do not do so with `-direct-clang-cc1-module-build` as
that directly goes to CC1 rather than the driver.
2026-04-07 15:44:43 -07:00
Steven Wu 6aacc38051 Merge pull request #88275 from cachemeifyoucan/eng/PR-173736094
[ConstExtract][Caching] Remap file path in ConstExtract JSON
2026-04-07 15:35:05 -07:00
Max Desiatov 090a8ff936 Embedded WASI: make import _Concurrency implicit (#88297)
**Explanation**: Existing `wasip1` triples for Embedded Swift already support concurrency, so this import should be implicit and no longer require package authors to make it explicit for Embedded Swift for WASI compatibility.
**Scope**: limited to Embedded Swift for Wasm;
**Risk**: low due to limited scope;
**Testing**: added a new lit test that verifies the change.
**Issue**: rdar://174021193
2026-04-05 07:17:27 -07:00
Steven Wu 5bddf886bb [ConstExtract][Caching] Remap file path in ConstExtract JSON
Fix that the `file` fields in ConstExtract JSON output are all prefix
mapped path when caching and prefix mapping are all enabled. This can
cause the consumers of the output failed to find the source file.

Now the JSON file is correct updated with the correct source file
location when caching is on. This allows both un-prefix-mapped source
location and relocatable source file location. As a bonus, now CAS
stores the compact version of the JSON file to save space without
affecting the pretty formatted final output file.

rdar://173736094
2026-04-02 10:15:54 -07:00
Allan Shortlidge 102581b597 ModuleInterface: Handle more synthesized conformance availability corner cases.
As a follow up to https://github.com/swiftlang/swift/pull/87832, continue
adjusting the algorithm for computing synthesized conformance availability.
When an outer declaration is `unavailable` in a more specific platform domain
and the inner declaration is `introduced:` in a less specific domain, the inner
declaration attribute does not override the outer declaration attribute.
Unavailability and introduction on separate axes of availability.

Resolves rdar://173724423.
2026-03-30 17:42:39 -07:00
Alexis Laferrière b29b7f6e32 Merge pull request #88168 from xymus/io-skip-only-when-strict
Serialization: Only skip serializing implementation-only decls in Strict mode
2026-03-30 11:58:30 -07:00
Alexis Laferrière 5a5fec9729 Serialization: Only skip writing implementation-only decls in Strict mode
Enable SkipImplementationOnlyDecls only in CheckImplementationOnlyStrict
mode. It was meant to be aligned with that mode in the first place and
has been causing issues at indexing on partially serialized AST trees.

rdar://173168470
2026-03-27 16:29:36 -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
Arnold Schwaighofer ddf30110e0 Merge pull request #88042 from aschwaighofer/aggressive_cmo_no_usable_from_inline
[cmo] [aggresive] Don't attach the usableFromInline attribute
2026-03-26 07:52:50 -07:00
Henrik G. Olsson 75f076b399 Merge pull request #87775 from Desel72/fix/issue-#87759
Support location markers in DiagnosticVerifier
2026-03-25 16:00:19 -07:00
Alexis Laferrière 43654566ae Frontend: Intro emit-polyglot-ast action 2026-03-25 11:36:15 -07:00
Allan Shortlidge 945f95f8d4 ModuleInterface: Improve availability inference for synthesized conformances.
When printing `.swiftinterface` files, implicit conformances may need to be
printed with inferred availability attributes. The existing algorithm for
determining which availability attributes to print needed a few updates to
better handle `anyAppleOS` availability attributes:

- `@available(anyAppleOS, ...)` attributes attached to a nested declaration
  should take priority over platform-specific `@available` attributes on outer
  declarations.
- At the same time, `@available(anyAppleOS, ...)` attributes attached to the
  _same_ declaration as a platform-specific `@available` attribute should not
  take priority. Instead, both attributes should be included in the inferred
  set.
2026-03-25 04:51:42 -07:00
Desel72 1842f73449 Support location markers in DiagnosticVerifier
Add support for named location markers in the diagnostic verifier's
-verify mode. A marker is defined by placing `// #name` in a comment
and referenced with `@#name` in expected-diagnostic comments.

This enables stable references to diagnostic locations that don't break
when lines are added or removed, and supports cross-file references
where an expected-error in one file references a marker in another.
2026-03-24 14:51:44 +01:00
Arnold Schwaighofer 72bd56de5b [cmo] [aggresive] Don't attach the usableFromInline attribute
in the CMO pass in aggressive mode

Changing the AST mid-pipeline is probably not a good idea.

rdar://173172456
2026-03-23 14:11:02 -07: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
Artem Chikin 0cefab9827 Merge pull request #87952 from artemcm/SpeculativeScanningCrashFix
[Dependency Scanner] Speculative fix for diagnostic consumer use-after-destroy in compiler sub-instances
2026-03-19 14:29:58 +00:00
Steven Wu b9700aa6cc [Caching] Do not update file if the same when cache replay
Make sure cache replay matches the same behavior as normal compilation
that the output is not written (timestamp preserved) when replaying
cache hits. This make sure the downstream dependencies are not
invalidated on a cache hit but the output doesn't change.
2026-03-17 16:59:21 -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