Skip to content

Support Embedded Swift in the core engine - #395

Merged
kateinoigakukun merged 1 commit into
mainfrom
katei/embedded-core
Jul 29, 2026
Merged

Support Embedded Swift in the core engine#395
kateinoigakukun merged 1 commit into
mainfrom
katei/embedded-core

Conversation

@kateinoigakukun

Copy link
Copy Markdown
Member

Part of the incremental upstreaming of Embedded Swift support (#357). Follows #394.

This makes the core engine build and run with -enable-experimental-feature Embedded. Embedded Swift 6.5 supports untyped throws and any Error, so the interpreter shares one untyped execution pipeline on every platform — no typed-throws variants, no error-carrying trap cases, and every instruction (including atomics and exception handling) stays available under Embedded.

Capability differences are expressed through traits where possible; #if $Embedded remains only for true compile necessities:

  • AtomicParkingLot's blocking half is gated on the MultiThread trait. Single-threaded builds can't create shared memories, so atomic.wait/notify trap before reaching the parking lot; an inert stub satisfies the type checker. Wait deadlines go through a new ParkingDeadline platform type instead of ContinuousClock at the instruction site. The CI trait lists now include the default-on MultiThread trait, which they had silently dropped.
  • The profiler is gated on the FileSystem trait (it writes its trace to a file), and instruction dumping (wasmkit explore) is gated on a new default-on Disassembler trait.
  • Direct threading is disabled under Embedded — it requires the swifttailcc convention, which Embedded targets (like WASI) don't provide; the token-threaded interpreter is used instead.
  • mmap-based virtual memory is excluded on targets without an OS.
  • Instruction.emitImmediate(to:) is generated so the translator avoids calling default protocol methods on existentials; a few key-path literals become closures.

Verified on hardware: the ESP32-C6 build and a QEMU run of the demo (guest→host calls, and a host error thrown from a host function caught by identity in the embedder) pass. The example project and portable smoke test land in a follow-up PR.

The interpreter shares one untyped-throws execution pipeline on every
platform: Embedded Swift 6.5 supports untyped throws and `any Error`, so no
typed-throws variants or error-carrying trap cases are needed, and every
instruction (including atomics and exception handling) stays available.

Capability differences are expressed through traits where possible, and
`#if $Embedded` remains only for true compile necessities:

- The blocking half of AtomicParkingLot is gated on the MultiThread trait
  (single-threaded builds cannot create shared memories, so
  `atomic.wait`/`notify` trap before reaching the parking lot; an inert
  stub satisfies the type checker). Wait deadlines are computed via a new
  ParkingDeadline platform type instead of using ContinuousClock at the
  instruction site. CI trait lists now include the default-on MultiThread
  trait, which they had silently dropped.
- The profiler is gated on the FileSystem trait (it writes its trace to a
  file), and the instruction-dumping code (`wasmkit explore`) is gated on a
  new default-on Disassembler trait.
- Direct threading is disabled under Embedded; it requires the swifttailcc
  convention, which Embedded targets (like WASI) do not provide.
- mmap-based virtual memory is excluded on targets without an OS.
- `Instruction.emitImmediate(to:)` is now generated so the translator
  avoids calling default protocol methods on existentials, and key-path
  literals are replaced with closures on shared paths.
@kateinoigakukun
kateinoigakukun added this pull request to the merge queue Jul 29, 2026
Merged via the queue into main with commit 695cdb3 Jul 29, 2026
17 checks passed
@kateinoigakukun
kateinoigakukun deleted the katei/embedded-core branch July 29, 2026 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant