Commit Graph

685 Commits

Author SHA1 Message Date
Arnold Schwaighofer
c1c05e1298 Merge pull request #85948 from aschwaighofer/embedded_enable_existential_support
[embedded] Enable support for existentials/boxed protocol types per default
2025-12-11 07:16:26 -08:00
Arnold Schwaighofer
d019f37b68 [embedded] Enable support for existentials/boxed protocol types per default
And enable this feature in production.
2025-12-10 08:50:23 -08:00
Arnold Schwaighofer
be78127c23 Merge pull request #85923 from aschwaighofer/embedded_existentials_requires_embedded
[embedded] Feature::EmbeddedExistentials requires Feature::Embedded
2025-12-10 07:13:45 -08:00
Arnold Schwaighofer
4730181c7a Merge pull request #85914 from aschwaighofer/embedded_foreign_type_metadata
[embedded] Add support for some foreign metadata
2025-12-10 06:58:55 -08:00
Arnold Schwaighofer
4d879967a7 [embedded] Feature::EmbeddedExistentials requires Feature::Embedded 2025-12-09 10:21:51 -08:00
Arnold Schwaighofer
0c7aded660 Merge pull request #85871 from aschwaighofer/lazy_metadata_emission_embedded_exist
[embedded] Lazily emit class metadata in embedded mode and apply shared linkage
2025-12-08 18:13:38 -08:00
Arnold Schwaighofer
d06929ccd2 [embedded] Add support for some foreign metadata 2025-12-08 15:35:43 -08:00
Arnold Schwaighofer
93e494bc40 Attempt to fix test on linux 2025-12-08 07:07:09 -08:00
Max Desiatov
fb0ec64b2d Merge pull request #85835 from MaxDesiatov/embedded-wasm-mutex 2025-12-06 13:35:39 +00:00
Arnold Schwaighofer
81dfb754ba [embedded] Apply shared linkage to metadata of public types in embedded with existential mode
We generate public metadata lazily which implies it could be emitted into a
different module. If we emit metadata for a public type into a module
other than its "home module" apply "shared" linkage.
2025-12-05 13:03:34 -08:00
eeckstein
d0f8ccef28 Merge pull request #85857 from eeckstein/fix-vtable-specialization
Embedded: allow generic class constructors
2025-12-05 20:17:52 +01:00
Max Desiatov
d33191e577 Use print instead of puts in embedded/wasm/mutex.swift 2025-12-05 14:53:45 +00:00
Arnold Schwaighofer
055f3e074d Merge pull request #85838 from aschwaighofer/embedded_exist_deferred_codegen
[embedded] When using existentials in embedded value witness tables can also have non unique definitions
2025-12-05 05:15:02 -08:00
Max Desiatov
bf7d5fdd62 Correct import in test/embedded/wasm/mutex.swift 2025-12-05 11:49:16 +00:00
Erik Eckstein
8b496f668f Embedded: allow generic class constructors
For example:

```
  public class C: MyClass {
    public init(p: some P) {
      // ...
    }
  }
```

Constructors are not called via the vtable (except "required" constructors).
Therefore we can allow generic constructors.

https://github.com/swiftlang/swift/issues/78150
rdar://138576752
2025-12-05 11:35:00 +01:00
Max Desiatov
6134ac9e0b Add embedded/wasm/mutex.swift for testing Mutex stdlib type 2025-12-04 22:50:01 +00:00
Arnold Schwaighofer
729cc1e08f [embedded] When using existentials in embedded value witness tables can also have non unique definitions 2025-12-04 09:11:50 -08:00
Arnold Schwaighofer
00a060d414 [embedded] Disable test that only works in non optimized mode
rdar://165656288
2025-12-03 15:23:04 -08:00
Doug Gregor
88fc259605 Merge pull request #85776 from DougGregor/extern-global-variables-embedded
[Embedded] Only strip "external" from global variables that have definitions
2025-12-01 22:25:50 -08:00
Arnold Schwaighofer
36a3c6e611 Merge pull request #85644 from aschwaighofer/wip_embedded_exits_with_eriks_changes_v1
[embedded] Fix associated type conformances for specialized witness tables
2025-12-01 16:40:31 -08:00
Doug Gregor
6b3935201d [Embedded] Only strip "external" from global variables that have definitions
Embedded Swift ends up rewriting the linkage of global variables as
part of linking together all of the Swift modules. Doing so for extern
global variables (e.g., ones meant to be implemented in C) breaks the
LLVM module, because they will never have definitions. Only make this
change when the global variable is a definition.
2025-12-01 15:47:32 -08:00
Arnold Schwaighofer
0c882d42ce Merge pull request #85625 from aschwaighofer/wip_embedded_cast_tuples
[embedded] Allow casting to tuples and tighten the check which existentials we support in embedded with existentials
2025-12-01 08:27:43 -08:00
Rauhul Varma
27ebe4dd95 Merge pull request #85492 from swiftlang/rauhul/cxx-exception-personality 2025-12-01 08:25:25 -08:00
eeckstein
9304ce951c Merge pull request #85707 from eeckstein/embedded-witness-method-specialization
embedded: change the function representation of directly called witness methods
2025-12-01 09:36:45 +01:00
Erik Eckstein
64dd574bea embedded: change the function representation of directly called witness methods
This is needed in Embedded Swift because the `witness_method` convention requires passing the witness table to the callee.
However, the witness table is not necessarily available.
A witness table is only generated if an existential value of a protocol is created.

This is a rare situation because only witness thunks have `witness_method` convention and those thunks are created as "transparent" functions, which means they are always inlined (after de-virtualization of a witness method call).
However, inlining - even of transparent functions - can fail for some reasons.

This change adds a new EmbeddedWitnessCallSpecialization pass:
If a function with `witness_method` convention is directly called, the function is specialized by changing the convention to `method` and the call is replaced by a call to the specialized function:

```
  %1 = function_ref @callee : $@convention(witness_method: P) (@guaranteed C) -> ()
  %2 = apply %1(%0) : $@convention(witness_method: P) (@guaranteed C) -> ()
...
sil [ossa] @callee : $@convention(witness_method: P) (@guaranteed C) -> () {
  ...
}
```
->
```
  %1 = function_ref @$e6calleeTfr9 : $@convention(method) (@guaranteed C) -> ()
  %2 = apply %1(%0) : $@convention(method) (@guaranteed C) -> ()
...
// specialized callee
sil shared [ossa] @$e6calleeTfr9 : $@convention(method) (@guaranteed C) -> () {
  ...
}
```

Fixes a compiler crash
rdar://165184147
2025-11-26 16:23:47 +01:00
Arnold Schwaighofer
b9f6454386 [embedded] Add support for storing/casting function types 2025-11-21 14:55:32 -08:00
Rauhul Varma
ce02872adf Add Embedded Swift Cxx exception personality
Users frequently run into a missing runtime symbol for Cxx exceptions
(`_swift_exceptionPersonality`) when mixing Embedded Swift and Cxx with
exceptions enabled. This leads to a confusing an hard to debug linker
error. This commit adds an implementation of this function to the
Embedded Swift runtime which simply fatal errors if a cxx exception is
caught in a Swift frame.

Issue: rdar://164423867
Issue: #85490
2025-11-21 11:12:10 -08:00
Erik Eckstein
fa3bfa3b10 embedded: don't try to specialize vtables of C++ imported reference-counted classes
Fixes a false compiler error

rdar://165209061
2025-11-21 16:33:49 +01:00
Arnold Schwaighofer
16206fad9f [embedded] Enable all tests in general-existentials1.swift 2025-11-21 06:48:51 -08:00
Arnold Schwaighofer
a5aa929d1f [embedded] Existentials: enable tests that now pass 2025-11-21 06:37:47 -08:00
Arnold Schwaighofer
003273c12e Test on macOS only 2025-11-20 13:27:24 -08:00
Arnold Schwaighofer
ffca3b4623 [embedded] Fix associate type conformances involving specialized conformances 2025-11-20 13:10:44 -08:00
Erik Eckstein
4191543855 MandatoryPerformanceOptimizations: specialize witness tables for general existentials 2025-11-20 10:56:22 -08:00
Arnold Schwaighofer
920def9319 [embedded] One more test 2025-11-20 10:16:19 -08:00
Arnold Schwaighofer
8beaad60bd [embedded] Allow casting to tuples 2025-11-20 10:03:39 -08:00
Arnold Schwaighofer
f7aae22e43 [embedded] A few more test cases for existential casting 2025-11-20 07:34:33 -08:00
Arnold Schwaighofer
3cff05d540 [embedded] Implement swift_dynamicCast suport for casts from existential to concrete type 2025-11-19 14:41:37 -08:00
Arnold Schwaighofer
84501bd6e2 Also test in optimized mode 2025-11-17 12:48:48 -08:00
Arnold Schwaighofer
62ac48a17e Complete support for outline existential storage
... or so I believe
2025-11-17 12:48:45 -08:00
Arnold Schwaighofer
eda5eadfd4 Start outline storage support: Add swift_allocBox/deallocBox
Code using the outline heap storage path will crash and burn because
support is incomplete. But at least inline storage existential
inhabitants should compile and run.
2025-11-17 12:46:35 -08:00
Arnold Schwaighofer
f38ad4b09f Start support for protocol witness tables 2025-11-17 12:46:35 -08:00
Arnold Schwaighofer
4285a2169d IRGen: Start support for embedded existentials
Allow storing struct, enum, and tuple types in an any.
2025-11-17 12:46:35 -08:00
Doug Gregor
b21485dd1f Only foreign thunks need to be serialized, not foreign definitions
This eliminates a SIL verification error with `@c` functions, which
provide definitions for foreign entrypoints. We were serializing @c
definitions when we shouldn't be, which would cause problems down the
line if those @c definitions referenced something internal that they
shouldn't.
2025-11-13 18:39:08 -08:00
Michael Gottesman
ab272fd429 Disable test when asan is enabled to unblock asan build.
rdar://159992660
2025-11-11 09:19:17 -08:00
Doug Gregor
020b69d4b6 [SE-0497] Implement @export attribute syntax
Implement the @export(implementation) and @export(interface) attributes
to replace @_alwaysEmitIntoClient and @_neverEmitIntoClient. Provide a
warning + Fix-It to start staging out the very-new
@_neverEmitIntoClient. We'll hold off on pushing folks toward
@_alwaysEmitIntoClient for a little longer.
2025-11-07 22:00:40 -08:00
Doug Gregor
ba507ab822 Merge pull request #85203 from DougGregor/clang-decl-asmname 2025-11-01 20:46:50 -07:00
Doug Gregor
f267f62f65 [SILGen] Consistently use SIL asmname for foreign function/variable references
Whenever we have a reference to a foreign function/variable in SIL, use
a mangled name at the SIL level with the C name in the asmname
attribute. The expands the use of asmname to three kinds of cases that
it hadn't been used in yet:

* Declarations imported from C headers/modules
* @_cdecl @implementation of C headers/modules
* @_cdecl functions in general

Some code within the SIL pipeline makes assumptions that the C names of
various runtime functions are reflected at the SIL level. For example,
the linking of Embedded Swift runtime functions is done by-name, and
some of those names refer to C functions (like `swift_retain`) and
others refer to Swift functions that use `@_silgen_name` (like
`swift_getDefaultExecutor`). Extend the serialized module format to
include a table that maps from the asmname of functions/variables over
to their mangled names, so we can look up functions by asmname if we
want. These tables could also be used for checking for declarations
that conflict on their asmname in the future. Right now, we leave it
up to LLVM or the linker to do the checking.

`@_silgen_name` is not affected by these changes, nor should it be:
that hidden feature is specifically meant to affect the name at the
SIL level.

The vast majority of test changes are SIL tests where we had expected
to see the C/C++/Objective-C names in the tests for references to
foreign entities, and now we see Swift mangled names (ending in To).
The SIL declarations themselves will have a corresponding asmname.

Notably, the IRGen tests have *not* changed, because we generally the
same IR as before. It's only the modeling at the SIL lever that has
changed.

Another part of rdar://137014448.
2025-10-29 19:35:55 -07:00
Alexis Laferrière
94113f4a83 SE-496: Remove references to features CDecl and CImplementation 2025-10-29 17:31:20 -07:00
Alexis Laferrière
74ea47a159 Merge pull request #84489 from xymus/c-identifier-only
Parser: Reject `@c` attributes using the string format
2025-10-27 09:17:31 -07:00
Kuba (Brecka) Mracek
eb23d3bc0a Merge pull request #85074 from kubamracek/section
SE-0492: Stabilize @_section/@_used into @section/@used
2025-10-24 12:29:48 -07:00