Commit Graph

830 Commits

Author SHA1 Message Date
Doug Gregor 92dcbd17c6 [SIL] Explicitly keep the code generation model in SILGlobalVariable
Just like we do with SILFunction, allow a code generation model to be
specified on a SILGlobalVariable and maintain that through the printed
and serialized forms.
2026-05-20 08:35:22 -07:00
Doug Gregor ae942071ae @export(interface|implementation) on a property affects its accessors 2026-05-20 08:35:22 -07:00
Doug Gregor 5241b7492a Address code review comments 2026-05-20 08:35:22 -07:00
Doug Gregor 5e94f94926 Disable tests for wasm for the moment 2026-05-20 08:35:20 -07:00
Doug Gregor b393f0bfa8 [Embedded] Eliminate special-case handling of declarations used externally
Declarations that are potentially used externally, including those
exposed to foreign languages (e.g., via `@c`), placed in a specific
section (`@section`), or explicitly marked used (`@used`) are
generally eagerly emitted in IR. Embedded Swift was overriding this in
a partial manner, applying specific linkage rules to them to force
them to have unique definitions (regardless of the code generation
model) and then overriding the behavior later on when it came to lazy
emission.

Remove the special cases for Embedded. These declarations will now
follow the same linkage rules as all other declarations, greatly
simplifying the "is non-unique definition" check, and will be
considered as being emitted non-lazily.
2026-05-20 08:35:18 -07:00
Doug Gregor 7e07babbd0 Fix test for ELF 2026-05-20 08:35:14 -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
Doug Gregor 14bc0baecf Introduce the notion of an "effective" code generation model
The code generation model for a particular declaration or conformance
can be defined explicitly with `@export(interface)`,
`@export(implementation)`, or `@inlinable` (for declarations),
indicating where the definition will occur.

Embedded Swift also has some limitations on what can be emitted into
IR. For example, a generic function cannot be `@export(interface)`
because Embedded Swift does not support unspecialized generics.

Compute the effective code generation model based on what was
explicitly specified, the limitations of the model, and the default
code generation model for the given module, which defaults to
"inlinable" but can be made "implementation" by the DeferredCodeGen
feature. Use the effective code generation model for IR- and SIL-level
determinations of linkage and where to emit symbols.
[WIP] Start computing and using the "effective" code generation model

FIXUP linkage of the alias symbol
2026-05-20 08:35:11 -07:00
Doug Gregor d0944bd387 [Embedded] Only build tests with an optimized standard library
Fixes rdar://176819678, where a debug standard library meant that the
embedded tests would fail.
2026-05-11 21:50:08 -07:00
Doug Gregor 7195c1d665 Merge pull request #89018 from DougGregor/embedded-witness-table-parallel-wmo-no-got
[Embedded] Add test for appropriate witness table relocations
2026-05-11 21:45:08 -07:00
Doug Gregor 436f7df3a8 [Embedded] Add test for appropriate witness table relocations
When using parallel whole module optimization (-num-threads N), we were
getting GOT entries for references to witness tables that show up in
another object file of the same module. These are not necessary and
were getting linked into NULL references, causing crashes later on.
The recent implementation of `@export(interface)` for type metadata and
protocol witness tables (pull request #88979) fixed this as a drive-by
improvement, eliminating the GOT entry and using a normal relocation.
Add a test to make sure it stays fixed.
2026-05-11 16:32:00 -07:00
Doug Gregor 86febb3a3e Merge pull request #88979 from DougGregor/export-interface-types-and-conformances
[Embedded] Extend @export(interface) to non-generic types and protocol conformances
2026-05-11 11:25:10 -07:00
Doug Gregor fe62ceebf0 Update test for Linux 2026-05-10 22:01:13 -07:00
Doug Gregor 7c3b534eab Diagnose @export(interface) on generic types in embedded swift 2026-05-10 15:34:30 -07:00
Doug Gregor f6f379daab [Embedded] Extend @export(interface) to protocol conformances
Protocol conformances normally have shared linkage in Embedded Swift.
However, allow the use of @export(interface) on conformances (by way
of their enclosing nominal type or extension), which will emit the
witness tables for those conformances as strong symbols in the owning
module, and references to these symbols from other modules.
2026-05-08 16:25:46 -07:00
Doug Gregor 4934c6af3d [Embedded] Witness tables should always have shared linkage in embedded mode
At the SIL level, ensure that witness tables always have shared linked
when building Embedded Swift. This is the correct starting point, to be
revised for @export(interface).
2026-05-08 15:14:23 -07:00
Allan Shortlidge 18e4fd76b5 Merge pull request #88886 from tshortli/improve-use-any-apple-os-diags
Sema: Improve `UseAnyAppleOSAvailability` diagnostics
2026-05-08 14:41:40 -07:00
Doug Gregor 09dd9db3e1 [Embedded] Extend @export(interface) to non-generic types
@export(interface) makes it so that Embedded Swift will emit a strong
definition of a symbol in its defining module, and use that symbol in
other modules. Extend this notion to non-generic types, where we will
emit a strong definition for the full type metadata, and let it be
referenced from other modules rather than the lazy, shared emission.

Implements rdar://176392354.
2026-05-08 14:23:21 -07:00
Doug Gregor 44d3b2a7a0 Require no-asserts harder 2026-05-06 15:18:10 -07:00
Doug Gregor 395d2daaa2 Give more detailed output when this test fails 2026-05-06 12:17:00 -07:00
Allan Shortlidge cea706a03f AST: Improve InFlightDiagnostic::fixItRemove() heuristics.
If the fix-it would remove a range that is followed by a newline and the
remaining text on the line is empty or all whitespace then remove the entire
line. This produces better results when a fix-it removes an attribute that is
written on a line by itself.
2026-05-06 11:03:30 -07:00
Doug Gregor 41a16dd8b6 Eliminate abstract C++ methods from the Embedded Concurrency library
Use unreachable methods instead of abstract methods in the Embedded
concurrency library, so that the C++ compiler doesn't inject a
reference to __cxa_pure_virtual, which is in the C++ runtime.
2026-05-06 10:35:40 -07:00
Doug Gregor 5b2dbd6d56 Use swift_slowAlloc/swift_slowDealloc for task allocator slabs
Rather than always calling malloc/free, parameterize the StackAllocator
on the underlying global allocator. The default uses malloc/free, so
most uses of StackAllocator are unchanged by this refactoring.

In the embedded concurrency library, swap in an global allocator that
uses swift_slowAllloc/swift_slowDealloc instead, eliminating the
remaining malloc/free references so everything goes through the
platform abstraction layer. For now, don't change the non-embedded
concurrency library in the same manner.
2026-05-06 10:35:34 -07:00
Doug Gregor 730a08cb1f [Embedded Concurrency] Drop dependencies on puts, strlen, strncpy, v(sn)printf.
Avoid more of the C standard library to reduce dependencies and code
size. This removes a bunch of code used to format nice fatal error
messages, reducing code size at some cost to debuggability. This is a
deliberate tradeoff in Embedded Swift.

We had to do a silly trick to avoid strlen, because LLVM likes to
pattern-match the loop and inject the standard library dependency,
which we do not want.
2026-05-05 23:33:46 -07:00
Doug Gregor cb5b0ee938 [Embedded Concurrency] Route fatal errors to a new _swift_fatalError
Fatal errors in the concurrency runtime used a mix of
swift_Concurrency_fatalError[v] and manual calls to abort(). Drop the
dependency on abort() by routing all true fatal errors through
swift_Concurrency_fatalErrorv and eventually to a new
`_swift_fatalError` C entrypoint defined in the Embedded Swift
runtime, which (optionally) prints and then (always) traps.
2026-05-05 18:06:30 -07:00
Doug Gregor ac3ee38ea7 [Embedded Concurrency] Drop distributed-actor-specific functionality
The concurrency library accounts for distributed actors, which
introduces some dependencies on metadata computations that we don't
want. Distributed actors are not supported in Embedded Swift, so
remove these functions to drop the external reference.
2026-05-05 17:16:15 -07:00
Doug Gregor 4cffd16c2b [Embedded Concurrency] Cut out the failed check logging function.
This function isn't used in the Embedded Concurrency library, and
refers to another logging function that isn't provided in the Embedded
Swift runtime.
2026-05-05 16:56:36 -07:00
Doug Gregor cc5d46a5b4 Drop references to debugger-reporting functionality from Embedded Concurrency
Embedded Swift doesn't provide reporting to a debugger, which entails
system dependencies we don't model. Remove this functionality from the
Embedded Concurrency build.

Part of rdar://176300169.
2026-05-05 14:23:04 -07:00
Doug Gregor f6fd1d8025 Merge pull request #88674 from DougGregor/embedded-swift-armv8m
[Embedded] Build standard library & friends for ARMv8-M and ARMv8.1-M
2026-05-03 23:45:17 -07:00
Doug Gregor 9ab4fcdbce Merge pull request #88739 from DougGregor/embedded-fp-parsing
[Embedded] Avoid `if #available` in Embedded Swift standard library
2026-05-01 02:35:59 -07:00
Doug Gregor 0a56f4a94e Generalize test 2026-04-30 22:02:13 -07:00
Jonathan Grynspan e526ae36e8 Allow String.init(describing:) in Embedded Swift (sometimes). (#88738)
This PR allows the use, in Embedded Swift, of the overloads of
`String.init(describing:)` that are constrained to specific protocols
(currently `CustomStringConvertible` and `TextOutputStreamable`). These
overloads can be fully supported in Embedded Swift as they do not rely
on runtime type inspection and just call through to protocol
requirements known at compile time.

- **Explanation**: Allows some uses of `String.init(describing:)` in
Embedded Swift.
- **Scope**: Embedded Swift, stringification
- **Issues**: rdar://139729101
- **Risk**: Low
- **Testing**: Existing CI coverage and new test file.
2026-04-30 17:50:26 -07:00
Doug Gregor 079a56f027 Make this an IR-checking test 2026-04-30 16:07:24 -07:00
Doug Gregor d6e228381d [Embedded] Avoid if #available in Embedded Swift standard library
Inlinable code that uses `if #available` in the standard library
currently ends up referencing _stdlib_isOSVersionAtLeast. Avoid using
it in the floating point parsing code.

Fixes #88698 / rdar://175730290
2026-04-30 15:48:24 -07:00
Doug Gregor a5a1bcf1ac Merge pull request #88722 from DougGregor/embedded-dynamic-cast
[Embedded] Reimplement dynamic casting for Embedded Swift
2026-04-30 14:24:48 -07:00
Doug Gregor 5d7f6e6795 Merge pull request #88745 from DougGregor/embedded-concurrency-tasklocal
[Embedded] Add test for @TaskLocal in Embedded Swift concurrency
2026-04-30 10:08:53 -07:00
Doug Gregor e270102a39 Update REQUIRES line 2026-04-29 18:29:26 -07:00
Doug Gregor 4b39ea7f87 [Embedded] Add test for @TaskLocal in Embedded Swift concurrency
Tracked by rdar://143935454
2026-04-29 16:47:04 -07:00
Doug Gregor 4efdaff916 Stub out arc4random_buf in test 2026-04-28 20:26:45 -07:00
Doug Gregor 29ea399833 [Embedded] Reimplement dynamic casting for Embedded Swift
The Embedded Swift dynamic casting logic was getting a bit tangled, and
used some heuristics for figuring out the existential representation
that didn't always work, e.g., with class-bound types.

Reimplement the entire thing using the same general approach that the
non-Embedded runtime uses, albeit simplified greatly because Embedded
Swift doesn't permit casting to existential types (only *from*
existential types). The new implementation correctly unwraps all levels
of existential, short-circuits where appropriate, and "takes" wherever
possible.

This change does require emitting some more metadata than we did
before, because it is necessary to handle the different existential
representations correctly. Previously, the compiler would pass a NULL
pointer as the "source" metadata to `swift_dynamicCast`, then try to
figure out what it was given by inspecting the source pointer. This is
insufficient for distinguishing the various existential representations
(opaque, class-bound, error) and relied on heuristics. Start passing
destination metadata to this function, just as we do in non-Embedded
Swift. This means we'll end up generating some more metadata for
existential types (like `any P`) that we wouldn't have before, but
it's still pay-per-use and they are relatively small. All of the other
metadata that can flow here will already have been created for other
reasons, e.g., because classes already have it in their vtable.

This also extends the metadata associated with existential types by one
more word (from 2 to 3). The new word is used to provide the
existential representation, which is needed for dynamic casting as
described above.
2026-04-28 15:07:56 -07:00
Doug Gregor 08fa11ecd6 Merge pull request #88678 from DougGregor/embedded-metatypes
[Embedded] Lift the restriction on the use of metatypes in Embedded Swift
2026-04-28 13:01:27 -07:00
Pavel Yaskevich 0eba09f824 Merge pull request #88600 from xedin/harden-sil-function-actor-isolation-propagation
[SIL] SILFunction: Always set actor isolation during initialization
2026-04-28 06:15:25 -07:00
Doug Gregor e0fdde7403 [Embedded Swift] Deal with multi-wrapped "any Error" existentials when casting
Teach swift_dynamicCast to repeatedly unwrap "any Error" existentials
before matching the concrete type.

Required to make rdar://175590869 work through AsyncStream.
2026-04-27 14:02:05 -07:00
Doug Gregor 2aabf1109d [Embedded Swift] Lazily emit metadata for metatypes and existentials
Following the emission of metadata for tuple and function types, also
lazily emit (sparse) metadata for metatype and existential types. This
is needed when forming existential values.
2026-04-27 14:02:04 -07:00
Doug Gregor 48fdf5050e [Embedded Swift] Drop restrictions on this test, it should work anywhere 2026-04-27 14:02:04 -07:00
Doug Gregor 1be4208e4c [Embedded] Handle metatypes of metatypes 2026-04-27 14:02:03 -07:00
Doug Gregor 46389f7d7e [Embedded] Start allowing metatypes in Embedded Swift
Now that we have generalized existentials in Embedded Swift, we also
have all of the infrastructure for metatypes. They're lazily
constructed on an as-needed basis, but otherwise work the same way as
in non-Embedded Swift.

Fixes rdar://145706221.
2026-04-27 14:02:03 -07:00
Doug Gregor 0d9bfd5b7a [Embedded Concurrency] Add test for throwing task groups 2026-04-27 14:02:01 -07:00
Doug Gregor 16bfa9be97 [Embedded] Enable throwing in the concurrency library
Now that we have untyped throws support in Embedded Swift, remove the
special cases that trapped when a task (or anything built on it)
throws. Introduce some tests that ensure that we can throw errors
through a Task or "async let" and catch the error.

Fixes rdar://175590869.
2026-04-25 11:50:31 -07:00
Doug Gregor f161a60e12 [Embedded] Build standard library & friends for ARMv8-M and ARMv8.1-M
Implements rdar://152598746.
2026-04-25 08:33:14 -07:00