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.
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.
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.
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.
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.
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.
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.
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.
`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`.
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
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
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
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.
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]`.
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.
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.
**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
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
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.
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
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.
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.
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.