Skip to content

BridgeJS: Fix optionals build error with Embedded Swift#734

Open
krodak wants to merge 1 commit intoswiftwasm:mainfrom
PassiveLogic:kr/fix-embedded-optional-spi
Open

BridgeJS: Fix optionals build error with Embedded Swift#734
krodak wants to merge 1 commit intoswiftwasm:mainfrom
PassiveLogic:kr/fix-embedded-optional-spi

Conversation

@krodak
Copy link
Copy Markdown
Member

@krodak krodak commented Apr 30, 2026

Overview

Fixes #689 - BridgeJS-generated code using optionals fails to compile when targeting Embedded Swift with cannot use conformance of 'Optional<Wrapped>' to '_BridgedAsOptional' here; the conformance is declared as SPI.

The root cause is that @_spi(BridgeJS) on the _BridgedAsOptional protocol declaration and its Optional conformance makes the entire conformance invisible in Embedded Swift, even when the consumer uses @_spi(BridgeJS) import JavaScriptKit. This appears to be an Embedded Swift compiler limitation where SPI-gated retroactive conformances on stdlib types are not resolved.

The fix removes @_spi(BridgeJS) from three places:

  1. The _BridgedAsOptional protocol declaration
  2. The Optional: _BridgedAsOptional conformance
  3. The JSUndefinedOr: _BridgedAsOptional conformance

The underscore-prefixed protocol name already signals internal API, and all methods on protocol extensions remain @_spi(BridgeJS)-gated, so there is no meaningful change to the public API surface.

Verified locally:

  • Builds for embedded wasm (swift-6.3-RELEASE_wasm-embedded) - previously failed
  • Builds for regular wasm (swift-6.3-RELEASE_wasm) - no regression
  • Embedded example still builds
  • BridgeJS codegen tests pass
  • Runtime tests pass (make unittest)

@krodak krodak self-assigned this Apr 30, 2026
Remove @_spi(BridgeJS) from _BridgedAsOptional protocol and its
Optional/JSUndefinedOr conformances so the conformances are visible
in Embedded Swift mode. The underscore-prefixed protocol name already
signals internal API, and all extension methods remain @_spi-gated.

Fixes swiftwasm#689
@krodak krodak force-pushed the kr/fix-embedded-optional-spi branch from 2c8ad10 to f21075c Compare April 30, 2026 10:57
@krodak krodak requested a review from kateinoigakukun April 30, 2026 11:14
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.

[BridgeJS] Optionals cause build error with Embedded Swift

1 participant