Commit Graph

604 Commits

Author SHA1 Message Date
Kathy Gray
5e407bce89 Diagnostics change for ambiguous overloads previously specifying 'this'
Updates the message to use the type or ValueDecl instead of this on previous 'Found this candidate' messages
Note: doees not yet change all test cases so more tests are failing

Improve Diagnostic message on overload ambiguitiy

Remove messages that say 'found this candidate' in favour of providing the type for the candidate to aid in selection when the candidates are presented in a dialogue window.

Fix more tests
2025-10-10 17:46:22 +01:00
Doug Gregor
66a730b638 [Embedded] Remove -mergeable-symbols
This option is no longer necessary, because we emit weak definitions
for any imported modules. Fixes rdar://158364032.
2025-09-08 17:44:51 -07:00
Doug Gregor
74e85c8416 [SIL] Track the parent module of a SIL global variable through serialization
As with SIL functions, track the parent module where a SIL global
variable was originally defined so that we can determine whether we
are outside of its original module for linkage purposes. Use this to
make sure we emit via a weak definition when emitting to a module
other than the originating module.

Fixes rdar://160153163.
2025-09-08 17:44:49 -07:00
Tim Kientzle
e5f9ffce12 Merge pull request #84024 from tbkka/tbkka-missing-embedded-allocators
Fill in two missing functions for Embedded Swift
2025-09-08 06:44:10 -07:00
Tim Kientzle
4368722a50 Test for swift_deallocUninitializedObject 2025-09-05 14:08:49 -07:00
Doug Gregor
ab15602af5 Merge pull request #84110 from DougGregor/lazy-irgen-global-variables
[IRGen] Lazily emit SIL global variables
2025-09-05 13:36:42 -07:00
Tim Kientzle
73e7df9e97 Test for swift_coroFrameAlloc 2025-09-04 18:05:14 -07:00
Doug Gregor
4009814783 [IRGen] Lazily emit SIL global variables
Delay the emission of SIL global variables that aren't externally
visible until they are actually used. This is the same lazy emission
approach that we use for a number of other entities, such as SIL
functions.

Part of rdar://158363967.
2025-09-04 13:03:15 -07:00
Doug Gregor
ba2af97a91 Merge pull request #84095 from DougGregor/embedded-deferred-codegen 2025-09-04 06:05:39 -07:00
Erik Eckstein
45b1a21e74 Optimizer: make ModulePassContext.specialize() also available in FunctionPassContext and add two argument flags
add `convertIndirectToDirect` and `isMandatory`
2025-09-04 08:15:45 +02:00
Doug Gregor
bee2369212 [Embedded] Treat the entrypoint function as having a unique definition
This ensures that one can use deferred code generation everywhere with
Embedded Swift and still get the appropriate entry symbol emitted.
2025-09-03 16:29:23 -07:00
Doug Gregor
ed93b46fa6 [Embedded] Introduce DeferredCodeGen feature.
Introduce an experimental feature DeferredCodeGen, that defers the
generation of LLVM IR (and therefore object code) for all entities
within an Embedded Swift module unless they have explicitly requested
to not be emitted into the client (e.g., with
`@_neverEmitIntoClient`).

This feature is meant to generalize and subsume
-emit-empty-object-file, relying on lazy emission of entities rather
than abruptly ending the compilation pipeline before emitting any IR.

Part of rdar://158363967.
2025-09-03 15:55:47 -07:00
Erik Eckstein
6df033b298 SIL: only use canonical substitution maps in SIL
* When constructing instructions which have substitution maps: initialize those with the canonical SubstitutionMap
* Also initialize SILFunction::ForwardingSubMap with the canonical one

Non-canonical substitution maps may prevent generic specializations.
This fixes a problem in Embedded Swift where an error is given because a function cannot be specialized, although it should.

https://github.com/swiftlang/swift/issues/83895
rdar://159065157
2025-08-29 22:31:04 +02:00
Doug Gregor
a5fa3edf54 Merge pull request #83909 from DougGregor/embedded-darwin-reserve-4kb
[Embedded] Only reserve 4KB in embedded Darwin targets
2025-08-26 04:55:46 -07:00
Doug Gregor
923689c2b4 [Embedded] Only reserve 4KB in embedded Darwin targets
Non-embedded Darwin targets reserve the first 4GB of address space. All
other targets reserve 4KB of address space. Make Embedded Darwin
targets only reserve the first 4KB (as with other targets), since they
aren't in userspace.

Fixes rdar://158981013.
2025-08-25 23:21:34 -07:00
Doug Gregor
f9394adf49 Merge pull request #83906 from DougGregor/specialized-deinit-in-destroy-outlining
[IRGen] Look for a specialized deinit when forming a call in IRGen
2025-08-25 21:48:53 -07:00
Doug Gregor
beeb45def1 [IRGen] Look for a specialized deinit when forming a call in IRGen
When outlining a destroy operation, we form direct calls to the deinit
of noncopyable types. For generic types, this was always calling into
unspecialized generics, which is... deeply unfortunate.

Look for a specialized deinit and call that instead. This eliminates a
compiler assertion in Embedded Swift, and should improve performance
with noncopyable generics elsewhere.

Fixes rdar://159054138 and #72627 / rdar://157131184.
2025-08-25 16:13:12 -07:00
Doug Gregor
fb1e769af4 Merge pull request #83820 from DougGregor/embedded-impl-only-never-emit-into-client
[Embedded] Introduce a test for @_implementationOnly + @_neverEmitIntoClient
2025-08-19 23:36:40 -07:00
Doug Gregor
ae8e95d5d9 [Embedded] Introduce a test for @_implementationOnly + @_neverEmitIntoClient
In Desktop Swift, @_implementationOnly imports allow one to hide the
implementation so long as you're careful to only reference entities
from the imported modules in code that gets compiled into the object
file and *not* referenced by the corresponding Swift module file.

Until very recently, there was no such affordance for Embedded Swift,
because all functions would have their SIL serialized to the Swift
module file. Using them from a client module would then attempt to
deserialize the SIL, loading the @_implementationOnly-imported module
and causing the compiler to abort. With the introduction of
@_neverEmitIntoClient, we now have a way to say "only in the object
file, never in the module file" for the definition of functions.

Introduce a test that makes sure @_implementationOnly +
@_neverEmitIntoClient has the desired effect of hiding the imported
modules from clients. It's still brittle and hard to use, just like
the existing @_implementationOnly, but this shows that it's at least
possible to do this implementation hiding in Embedded Swift.
2025-08-19 16:03:18 -07:00
Max Desiatov
6582ad92bc Embedded Wasm: enable import WASILibc
WASILibc wasn't built for the embedded stdlib in `stdlib/public/Platform/CMakeLists.txt`. New `copy_wasilibc_modulemap_embedded_resource` and `embedded-stdlib-platform-${triple}` targets are added, the latter for `wasm32-unknown-wasip1` only for now. Also added a `wasilibc_functions.swift` test to verify the result.

Resolves https://github.com/swiftlang/swift/issues/83513

rdar://157467412
2025-08-18 18:41:10 +01:00
Doug Gregor
2f60d729f0 Add @_neverEmitIntoClient to prohibit SIL serialization for a function
Part of the Embedded Swift linkage model, this attribute ensures that
the function it applies to has a strong definition in its owning
module, and that its SIL is never serialized. That way, other modules
will not have access to its definition.

Implements rdar://158364184.
2025-08-17 23:21:57 -07:00
Doug Gregor
9a20ebac5b [Embedded] Emit weak definitions for imported symbols
When Embedded Swift emits a symbol that was imported from another
module, ensure that the symbol is emitted as a weak definition. This
way, importing the same module (and using its symbol) into several
different modules doesn't cause duplicate-symbol errors at link time.
Rather, the linker will merge the different symbol definitions. This
makes Embedded Swift libraries work without resorting to
`-mergeable-symbols` or `-emit-empty-object-file`.
2025-08-17 15:26:08 -07:00
Doug Gregor
c91a4822d3 Serialize the "markedAsUsed" bit for SILGlobalVariable 2025-08-17 15:25:50 -07:00
Doug Gregor
b5e61cc4ad [SIL] Serialize the markedAsUsed bit in SILFunction
We were dropping this bit during serialization, so we don't know
whether the function was originally marked as "used".
2025-08-14 16:48:45 -07:00
Allan Shortlidge
4d41db3b5d Sema: Rationalize availability checking in unavailable contexts.
Correct several behaviors of availability checking in unavailable contexts that
were inconsistent with the checking model:

- Avoid diagnosing unintroduced and obsolted declarations in contexts that are
  unavailable in the same domain.
- Diagnose unavailability normally in type signature contexts.
2025-08-08 07:57:44 -07:00
Max Desiatov
6d042aeb4a Embedded WASI: fix storeEnumTagSinglePayload type mismatch (#83480)
This is a follow up to https://github.com/swiftlang/swift/pull/80862, where `storeEnumTagSinglePayload` in a special implementation of `ResultTypeInfo` for Embedded Swift had a mismatching number of arguments. The actual declaration of it in `ABI/ValueWitness.def` clearly includes one more argument.

```
/// void (*storeEnumTagSinglePayload)(T* enum, UINT_TYPE whichCase,
///                                   UINT_TYPE emptyCases, M *self);
/// Given uninitialized memory for an instance of a single payload enum with a
/// payload of this witness table's type (e.g Optional<ThisType>), store the
/// tag.
FUNCTION_VALUE_WITNESS(storeEnumTagSinglePayload,
                       StoreEnumTagSinglePayload,
                       VOID_TYPE,
                       (MUTABLE_VALUE_TYPE, UINT_TYPE, UINT_TYPE, TYPE_TYPE))
```

This function type mismatch is illegal when targeting Wasm and traps at run time.

Similarly to #80862, we're passing `nullptr` as the newly added argument, which is equivalent to the existing behavior on other platforms.

rdar://157219474
2025-08-01 15:38:59 -07:00
eeckstein
10345d3ad0 Merge pull request #83485 from eeckstein/fix-test
tests: disable embedded/unowned-task-executor.swift for arm64e
2025-08-01 22:46:28 +02:00
Erik Eckstein
f475480cde tests: disable embedded/unowned-task-executor.swift for arm64e
The check lines do not match ptrauch code
rdar://157170056
2025-08-01 17:45:19 +02:00
Max Desiatov
9a1a60e157 test/embedded: enable more tests for wasip1 2025-08-01 15:04:32 +01:00
Max Desiatov
1eef09ad34 Embedded WASI: fix InitializeWithCopy VWT type mismatch
Fixes Embedded Swift concurrency tests that crash with this stack trace:

```
Error: Trap: indirect call type mismatch, expected FunctionType(parameters: [WasmTypes.ValueType.i32, WasmTypes.ValueType.i32], results: []), got FunctionType(parameters: [W
asmTypes.ValueType.i32, WasmTypes.ValueType.i32, WasmTypes.ValueType.i32], results: [WasmTypes.ValueType.i32])
    0: swift::AsyncTask::completeFuture(swift::AsyncContext*)
    1: completeTaskAndRelease(swift::AsyncContext*, swift::SwiftError*)
    2: completeTaskWithClosure(swift::AsyncContext*, swift::SwiftError*)
    3: $exIeAgHr_xs5Error_pIegHrzo_s8SendableRzs5NeverORs_r0_lTRyt_Tg5TATQ0_
    4: $exIeAgHr_xs5Error_pIegHrzo_s8SendableRzs5NeverORs_r0_lTRyt_Tg5TQ0_
    5: $e1a4MainV4mainyyYaFZyyYacfU_TATQ0_
    6: $e1a4MainV4mainyyYaFZyyYacfU_TY1_
    7: swift_task_switch
    8: $e1a4MainV4mainyyYaFZyyYacfU_TQ0_
    9: $e1a4testSiyYaFTY0_
    10: swift::runJobInEstablishedExecutorContext(swift::Job*)
    11: swift_job_run
    12: $es19CooperativeExecutorC8runUntilyySbyXEKF
    13: $es19CooperativeExecutorCs07RunLoopB0ssACP3runyyKFTW
    14: swift_task_asyncMainDrainQueueImpl
    15: swift_task_asyncMainDrainQueue
    16: main
    17: __main_void
    18: _start
    19: unknown
```
2025-08-01 13:03:10 +01:00
Max Desiatov
d7e82dd4ef Enable more embedded tests for OS=wasip1 2025-07-31 17:12:59 +01:00
Max Desiatov
7ec0837778 Embedded WASI: fix concurrency-deleted-method.swift test
The test was crashing due to `swift_unreachable("custom executors not supported in embedded Swift")` line in `swift_task_enqueueImpl`, as the corresponding non-embedded codepath was relying on an unspecialized generic function `_swift_task_enqueueOnExecutor` defined in `Executor.swift`. Unspecialized generics are unavailable in Embedded Swift, and such `@silgen_name` function can't be specialized when used from concurrency runtime code written in C/C++. We can redefine this function for Embedded Swift as using a class-bound existential instead, and re-enable this codepath with a slightly different call that avoids the use of unavailable `swift_getObjectType` function from the non-embedded runtime.
2025-07-31 16:00:40 +01:00
Erik Eckstein
3687099f85 tests: fix the requirements for embedded/unowned-task-executor.swift
rdar://157120950
2025-07-30 19:47:15 +02:00
eeckstein
a76ee5ea9f Merge pull request #83391 from eeckstein/fix-wt-specialization
embedded: don't try to specialize witness tables for abstract conformances
2025-07-29 16:49:11 +02:00
Erik Eckstein
8ac25d915b embedded: don't try to specialize witness tables for abstract conformances
If the conformance is abstract the witness table is specialized elsewhere - at the place where the concrete conformance is referenced.
Fixes a compiler crash.
2025-07-29 09:45:52 +02:00
Allan Shortlidge
9302cbe568 Sema: Diagnose @dynamicMemberLookup subscripts that are not accessible enough.
Since this is a source breaking change, downgrade the diagnostic to a warning
until the next language version unless library evolution is enabled, in which
case this would have resulted in a broken `.swiftinterface` and it therefore
makes sense to diagnose eagerly.

Resolves rdar://156919010.
2025-07-28 22:36:39 -07:00
Allan Shortlidge
da7a215f61 Sema: Diagnose overrides that are unavailable in Embedded Swift. 2025-07-26 18:46:06 -07:00
Max Desiatov
f20417c55a Enable concurrency-deleted-method.swift test for wasip1 (#83236)
The test is only partially enabled: we only check for IR correctness and correct linking. We don't run the tests on WASI yet due to unrelated issues that are going to be resolved separately.
2025-07-25 16:24:32 -07:00
Slava Pestov
ca50986f3a Merge pull request #83308 from slavapestov/fix-rdar156095800
Embedded Swift: Fix === and !== with existential
2025-07-25 08:41:38 -04:00
Slava Pestov
b7766b6361 stdlib: Use the original === and !== operators on embedded
It seems that the restriction preventing these from working was
lifted.

The behavioral difference is that in Swift 5 mode, we don't
actually open AnyObject like this, so the old operator could
not be used with class-bound existentials.

I added a trivial test case just to ensure that calls to ===
type check correctly in both language modes.

Fixes rdar://156095800.
2025-07-24 15:25:30 -04:00
Max Desiatov
9c6fba67cf test/embedded: re-enable hello.swift for wasip1 (#83290)
This test was disabled by mistake after renaming `wasi` to `wasip1` component of WASI triples.
2025-07-24 11:39:58 -07:00
Max Desiatov
328dd1f753 test/embedded/avr: testStdlibFunctioning.swift is unsupported on Wasm (#83284)
This test should not run as a part of Embedded Swift for Wasm test suite, but somehow it does in this run: https://ci.swift.org/job/oss-swift-pr-test-crosscompile-wasm-ubuntu-20_04/3262/console
2025-07-24 06:28:06 -07:00
Max Desiatov
67c4be0ac2 Update tests for wasi -> wasip1 triple change
Fixes a regression introduced with https://github.com/swiftlang/swift/pull/83167
2025-07-23 10:10:47 +01:00
Max Desiatov
64a8bf8fde test: simpler sed expression in dependencies-random.swift 2025-07-23 10:10:47 +01:00
Max Desiatov
9a02717d2e test/embedded/dependencies-random: use sed instead of ex 2025-07-23 10:10:47 +01:00
Max Desiatov
03f7ebc890 test/CMakeLists.txt: run Embedded Swift for Wasm tests
Run new `check-swift-embedded-wasi` target from `test/CMakeLists.txt`, tweak `lit.cfg` to support both `-wasi` and `-wasip1` triples, exclude unsupported tests based on `CPU=wasm32` instead of `OS=wasi`.
2025-07-23 10:10:47 +01:00
Erik Eckstein
b68cafb870 SIL: allow casts to class-bound archetypes to be done as scalar-casts instead of address-casts
This allows such casts to be done in embedded swift.

rdar://156302495
2025-07-22 07:04:37 +02:00
Max Desiatov
0c4e56174b Merge pull request #82399 from swiftlang/maxd/embedded-wasm-tests
These tests still require a manual `lit.py` invocation for Wasm, which will be added as a separate CMake target in a future PR.
2025-07-04 15:36:15 +01:00
Erik Eckstein
2b8c63dcd3 MandatoryPerformanceOptimizations: don't specialize vtables for thin class metatype instructions
Fixes a wrong compiler error for imported C++ classes with custom reference counting.
rdar://154947835
2025-07-03 16:21:21 +02:00
Max Desiatov
ca3d6bcdbf Restrict Wasm tests to wasip1 in lit.local.cfg 2025-07-01 15:40:05 +01:00