Commit Graph

759 Commits

Author SHA1 Message Date
Doug Gregor
ccbcacfedd Merge pull request #86765 from DougGregor/embedded-swift-platform-header
Introduce a Platform Abstraction Layer for Embedded Swift
2026-03-04 11:25:50 -08:00
Doug Gregor
ae1e3d0865 Build a static library that implements the Embedded Swift platform layer on POSIX
The new library, swiftEmbeddedPlatformPOSIX, implements all of the
_swift_XYZ functions needed to support Embedded Swift as shims on top
of a POSIX system that provides posix_memalign, free, putchar, and so
on. This offers an easier way to bridge between the prior ad hoc
requirements of Embedded Swift and the newer platform abstraction
layer.

Part of rdar://164057124
2026-03-03 09:05:30 -08:00
Allan Shortlidge
fac8ed12ed Sema: Don't restrict the availability of any runtime features in Embedded. 2026-03-02 12:13:22 -08:00
Arnold Schwaighofer
00466f679f Merge pull request #87459 from aschwaighofer/embedded_cmo_no_usable_from_inline_hack
[embedded] Don't change AST decls with markUsableFromInline in embedded
2026-02-26 17:11:54 -08:00
Doug Gregor
7150c233cc Merge pull request #87496 from DougGregor/sil-deserialize-vtable-entries
[SIL deserialization] Keep reading vtable entries while there are vtable entries
2026-02-25 15:55:00 -08:00
Doug Gregor
453048d976 [SIL deserialization] Keep reading vtable entries while there are vtable entries
The logic here would keep reading vtable entries so long as some other
top-level record wasn't hit, then assert that the entry it found was a
vtable entry. However, the list of "top-level record kinds" was ad hoc
and doesn't regularly get updated. Switch to a loop that reads vtable
entries while there are vtable entries, since there's only one kind
here anyway.

Fixes an Embedded Swift crash where a SIL global variable was after the
vtable entries, rdar://171009492.
2026-02-25 10:53:55 -08:00
Arnold Schwaighofer
50611a66fb Fix another test 2026-02-25 09:58:56 -08:00
Arnold Schwaighofer
62b7fe0c6f Fix test verification 2026-02-25 09:29:06 -08:00
Arnold Schwaighofer
34325f8abb [embedded] Don't change AST decls with markUsableFromInline in embedded
The current approach of changing the AST mid compiler pipeline (in the
CMO pass) is not tenable/maintainable imo. We can't get different answers
throughout the compilation process about AST properties -- there is no
way about reasoning what things mean.

Instead, we treat internal and lower linkages as public for the purposes of
symbol visibility for linkage reasons in SIL/IRGen.

rdar://171083081
2026-02-25 08:11:53 -08:00
Erik Eckstein
e233b0b4d4 EmbeddedSwiftDiagnostics: ignore destroy_value with a dead_end flag
Fixes a false "deinit of non-copyable type not visible in the current module" error

rdar://171009835
2026-02-24 14:26:10 +01:00
Erik Eckstein
9f72071a3d embedded: specialize vtables of classes which are a target of cast operations
Even if the specific class is never created, we need to specialize a vtable, because it's used in IRGen for generating the code for the cast operation.

Fixes a crash in IRGen
https://github.com/swiftlang/swift/issues/87248
rdar://170435034
2026-02-23 10:50:25 +01:00
Erik Eckstein
ac072dad89 CrossModuleOptimization: correctly serialize value-type deinits
Serialize the module's SILMoveOnlyDeinit table. So that client modules can de-virtualize deinits.
So far this only worked for public non-copyable types.
This is especially important for embedded swift.

rdar://166051414
2026-02-19 09:59:07 +01:00
Doug Gregor
29e9fbb3e4 Merge pull request #87054 from DougGregor/embedded-swift-less-unicode
[Embedded] Make a few standard library functions not depend on the Unicode tables
2026-02-07 12:23:13 -08:00
Doug Gregor
91055b413a Note that test is passing on wasi 2026-02-07 07:33:18 -08:00
Arnold Schwaighofer
28523611b8 Merge pull request #87045 from aschwaighofer/embedded_typemetadata_duplicate_symbol_fix
[embedded] [IRGen] Avoid creating "aliases" for type metadata address points in client modules
2026-02-07 05:31:09 -08:00
Doug Gregor
b09a82b17a Eliminate string copy from readLine's newline removal code
Thanks for the prod, Rauhul
2026-02-06 19:58:15 -08:00
Doug Gregor
eed25ef52d Make StaticBigInt's debugDescription no longer depend on the Unicode tables 2026-02-06 15:22:59 -08:00
Doug Gregor
708115195e Ensure that readLine doesn't require the Unicode tables 2026-02-06 15:01:48 -08:00
Doug Gregor
1e8317803e Make Bool's conformance to LosslessStringConvertible not use String.==
String.== performs normalization, which brings in the Unicode tables.
Don't use it for Bool's conformance to LosslessStringConvertible,
which doesn't need it. It's only the "true" and "false" strings that
matter.
2026-02-06 14:10:38 -08:00
Arnold Schwaighofer
3dd5286d48 [embedded] [IRGen] Avoid creating "aliases" for type metadata address points in client modules
We don't need to export the type metadata address point alias in clients that
lazily emit other module's type metadata. There will be an exported
metadata symbol in the originating module for that purpose.

Instead, satisfy any local uses of the metadata address point uses by its
underlying address computation.

This is to workaround a bug where LLVM generates the wrong assembly for
weak aliases that point to an offset of another symbol.

```
@"$e1C7MyClassCySiGN" = weak_odr hidden alias %swift.type, getelementptr
inbounds (<{ ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }>,
ptr @"$e1C7MyClassCySiGMf", i32 0, i32 1)
```

Generates:

```
.weak_reference _$e1C7MyClassCySiGN
.private_extern _$e1C7MyClassCySiGN
.alt_entry  _$e1C7MyClassCySiGN
  _$e1C7MyClassCySiGN = _$e1C7MyClassCySiGMf+8
```

Instead of

```
.weak_definition _$e1C7MyClassCySiGN
.private_extern _$e1C7MyClassCySiGN
.alt_entry  _$e1C7MyClassCySiGN
  _$e1C7MyClassCySiGN = _$e1C7MyClassCySiGMf+8
```

Leading for "weak"ness to be ignored and duplicate type medata symbol linkage
errors.

rdar://169573918
2026-02-06 12:24:08 -08:00
Doug Gregor
d003f1dcca Use condfail_message in _debugPrecondition and make it more transparent
Improve debugging from core dumps for Embedded Swift by using condfail
rather than trap within _debugPrecondition, and make the call stack
transparent enough that we promote these out to callers.

Fixes rdar://159471659.
2026-02-06 11:33:38 -08:00
eeckstein
4ae970e634 Merge pull request #86741 from eeckstein/argument-effects
SIL: assume a read-effect for unused indirect arguments
2026-01-24 07:56:21 +01:00
Arnold Schwaighofer
e6ea70720c Merge pull request #86691 from aschwaighofer/embedded_existential_fix_outline_path
[embedded] [existentials] Fix the on-heap storage paths - what was I thinking
2026-01-23 07:24:41 -08:00
Erik Eckstein
535a58e3fb SIL: assume a read-effect for unused indirect arguments
Even if an indirect argument is unused, pretend that the function reads from it.
If the unused argument is passed to another generic function and that function is specialized,
the argument may be re-abstracted and the specializer inserts a load from the indirect argument.
Therefore we must be prepared that unused indirect argument might get loaded from at some time.

Fixes a compiler crash
rdar://168623362
2026-01-23 15:58:23 +01:00
Doug Gregor
a9507cf6d9 Update Embedded Swift runtime tests for EmbeddedDynamicExclusivity 2026-01-22 21:24:22 -08:00
Doug Gregor
cc2fc8ae65 [Embedded] Put dynamic exclusivity behind a second experimental feature
We need to stage in the behavior change to enable dynamic exclusivity
checking for Embedded Swift. For now, ignore
`-enforce-exclusivity=checked` in Embedded Swift unless the
experimental feature `EmbeddedDynamicExclusivity` is also enabled.

Addresses rdar://168618037, a regression in Embedded Swift code that
is passing `-enforce-exclusivity=checked` explicitly.
2026-01-22 21:22:19 -08:00
Doug Gregor
df74a5b005 Merge pull request #86673 from DougGregor/dynamic-exclusivity-embedded
Enable dynamic exclusivity checking runtime in Embedded Swift
2026-01-22 14:41:32 -08:00
Alexis Laferrière
c8f99af698 Merge pull request #86335 from xymus/exportability-nle-warn
Sema: Enable exportability checks in non-library-evolution mode as warnings by default
2026-01-22 09:47:52 -08:00
Arnold Schwaighofer
16b31b8292 Fix wasi test 2026-01-22 07:18:27 -08:00
Doug Gregor
5720e3c6b9 [Embedded] Split out the single vs. multi-treaded exclusivity runtime tests 2026-01-22 07:00:25 -08:00
Arnold Schwaighofer
25dd981911 [embedded] [existentials] Fix the on-heap storage paths
Call swift_releaseBox on all the copy-on-write paths of existentials.
2026-01-21 09:38:27 -08:00
Doug Gregor
b12ad088ce [Embeddded] Make _swift_(get|set)ExclusivityTLS platform-provided
Swift's dynamic exclusivity checking relies on two functions,
_swift_getExclusivityTLS and _swift_setExclusivityTLS, to properly
deal with multi-threaded contexts. In the non-Embedded standard
library, these are provided by the Swift runtime.

For Embedded Swift, we cannot rely on having thread-local storage.
Instead, require the platform to provide these two entrypoints. To
make things simpler, we offer two implementations one can link in:

- libswiftExclusivitySingleThreaded.a: single-threaded implementation
- libswiftExclusivityC11ThreadLocal.a: multi-threaded implementation that
uses C11 thread-locals

Embedded Swift programs using dynamic exclusivity can link in one of
these libraries, or can implement its own versions of these two
functions. A platform can choose to provide them if it has different
mechanisms for thread-local storage.

This makes dynamic exclusivity checking generally usable in Embedded
Swift, rdar://159115910.
2026-01-20 20:07:42 -08:00
Doug Gregor
3e5eb9a369 Enable dynamic exclusivity checking runtime in Embedded Swift
Start building the dynamic exclusivity checking code in Embedded Swift.
It will be used when dynamic exclusivity checking is enabled (via
`-enforce-exclusivity=checked`), and dead-code-stripped otherwise. Note
that we deliberately avoid linking `swift_(begin|end)Access` in
modules that don't have exclusivity enforcement enabled to aid with
dead-code stripping.

Also note that, unlike in non-Embedded Swift, exclusivity checking
cannot be disabled at runtime by setting
_swift_disableExclusivityChecking to `false`. We need the ability to
constant-initialize global variables to bring that functionality into
Embedded Swift.

Tracked by rdar://159115910.
2026-01-20 20:07:38 -08:00
Max Desiatov
8a16a26f0e Merge pull request #86639 from MaxDesiatov/embedded-wasm-tests
test/embedded: Enable more tests for Wasm

Before:

```
Total Discovered Tests: 255
  Unsupported      : 100 (39.22%)
  Passed           : 154 (60.39%)
  Expectedly Failed:   1 (0.39%)
```

After:

```
Total Discovered Tests: 255
  Unsupported      :  41 (16.08%)
  Passed           : 210 (82.35%)
  Expectedly Failed:   4 (1.57%)
```

Work in progress on https://github.com/swiftlang/swift/issues/83482.

rdar://157304207
2026-01-20 19:21:48 +00:00
Max Desiatov
a636a12aa1 test/embedded: Enable more tests for Wasm
Before:

```
Total Discovered Tests: 255
  Unsupported      : 100 (39.22%)
  Passed           : 154 (60.39%)
  Expectedly Failed:   1 (0.39%)
```

After:

```
Total Discovered Tests: 255
  Unsupported      :  41 (16.08%)
  Passed           : 210 (82.35%)
  Expectedly Failed:   4 (1.57%)
```

Work in progress on https://github.com/swiftlang/swift/issues/83482.

rdar://157304207
2026-01-19 17:24:54 +00:00
Doug Gregor
1c6265659b Drop unnecessary -fptrauth-calls Clang option
It causes issues in some configurations, and has nothing to do with
what this test is testing. Fixes rdar://166922694.
2026-01-16 14:43:10 -08:00
Arnold Schwaighofer
798af3aa3d Fix test on wasi 2026-01-14 07:40:25 -08:00
Arnold Schwaighofer
1c2579d65b Try to fix linux - the second attempt 2026-01-13 15:55:04 -08:00
Arnold Schwaighofer
20dd7577cb Fix test on linux 2026-01-13 08:41:49 -08:00
Arnold Schwaighofer
1fa08f7ba7 [embedded] Link newly created specialized functions to bring in witness tables
Specialization might create new references to conformances. A
specialized init_existential_ref might now refer to a concrete
conformance.
In Embedded swift protocol witness tables are emitted lazily. Therefore
deserialization of the sil_witness_table becomes mandatory if it is
referenced because we can't rely on it being defined in the originating
module.

rdar://167843592
2026-01-12 12:44:00 -08:00
Henrik G. Olsson
7c5c6658cc Merge pull request #86457 from ramonasuncion/fix-embedded-depends
[Test][Embedded] Make dependencies compatible with lit shell
2026-01-12 08:21:35 -08:00
Henrik G. Olsson
47bf39ad50 Merge pull request #85910 from ramonasuncion/test-embedded-depends-lit-more-fixes
[Test][Embedded] Update embedded dependency test suite
2026-01-10 20:47:32 -08:00
Ramon Asuncion
b33fc52fbd [Test][Embedded] Make dependencies compatible with lit shell 2026-01-10 19:18:43 -05:00
Henrik G. Olsson
c1fd35e67e Merge pull request #86427 from ramonasuncion/test-embedded-depends-random
[Test][Embedded] Make dependencies random compatible with lit shell
2026-01-10 16:02:26 -08:00
Ramon Asuncion
42ea66c07a [Test][Embedded] Redirect comm output to file before checking size 2026-01-10 15:23:03 -05:00
Henrik G. Olsson
b8c7652044 Merge pull request #85881 from ramonasuncion/test-embedded-depends-lit
[Test][Embedded] Make dependencies print compatible with lit shell
2026-01-10 12:06:23 -08:00
Ramon Asuncion
575a5f30b7 [Test][Embedded] Fix sorted order in allowed-dependencies_wasi.txt 2026-01-10 13:33:28 -05:00
Ramon Asuncion
dfd7a05ca1 [Test][Embedded] Use split-file and presorted depends list for internal shell 2026-01-09 13:40:01 -05:00
Ramon Asuncion
8ce6a59e14 [Test][Embedded] Remove trailing newline to satisfy comm 2026-01-09 13:04:30 -05:00
Doug Gregor
d73cd34805 Always suppress swift_(begin|end)Access calls with -enforce-exclusivity=unchecked
The exclusivity enforcement command-line flags currently impact the
generation of SIL within the current module. However, it does not
impact any SIL that was deserialized from another module, which means
that `-enforce-exclusivity=unchecked` doesn't actually remove all of
the dynamic exclusivity checks.

When dynamic exclusivity is disabled, lower SIL
begin_access/end_access instructions to nothing to ensure that we
won't do any dynamic exclusivity checks.

Use this to better model the reality of dynamic exclusivity checking
in Embedded Swift, which effectively turned off all dynamic
exclusivity checking by having empty stub implementations of
swift_(begin|end)Access. Instead, have Embedded Swift default to
`-enforce-exclusivity=unchecked`, so that it never emits calls to
swift_(begin|end)Access. Remove the stub implementations of
swift_(begin|end)Access from the Embedded Swift runtime, since we will
no longer generate calls to them by default.

Moving forward, this will allow us to conditionally enable the new
implementation of dynamic exclusivity checking by specifying
`-enforce-exclusivity=checked` for Embedded Swift builds. We'll stage
that in over time to avoid breaking existing Embedded Swift clients.
2026-01-09 09:26:39 -08:00