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
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.
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
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
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
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.
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
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.
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
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.
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.
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.
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
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.