swiftwasm / swiftwasm/JavaScriptKit

BridgeJS: Remove forced capture workaround in async thunk body closures once swiftlang/swift#89715 lands

オープン
#761 コメント 0 件 リアクション 0 件 担当者 1 名 GitHub で見る

@krodak がすでに取り組んでいます。

2026年6月10日 から。

主要言語
Swift
スター
986
フォーク
76
平均マージ
21時間 11分
マージ済み PR(30日)
4

説明

Tracks removal of the workaround introduced in #760.

Context

A zero-parameter async throws(JSException) export generates a captureless _bjs_makePromise body closure, which lowers via thin_to_thick_function and miscompiles on Wasm (swiftlang/swift#89320): the thrown error is corrupted across the async unwind, trapping in Promise_reject or rejecting with a garbage value. #760 works around this at the codegen level by forcing a capture in the emitted body closure (the capture must also be read in the body, since an unread capture list entry is dropped by capture analysis and the closure stays thin):

let __bjs_capture = 0
return _bjs_makePromise(resolve: Promise_resolve_SS, reject: Promise_reject) { [__bjs_capture] () async throws(JSException) -> String in
    _ = __bjs_capture
    return try await ping()
}

What to do once the compiler fix ships

The proper fix is swiftlang/swift#89715 (IRGen: fix async typed throws miscompiles on Wasm). Once it is available in the oldest Swift toolchain JavaScriptKit supports:

  • Remove asyncThrowsBodyForcesCapture and the forced-capture emission from ExportedThunkBuilder in Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift.
  • Regenerate snapshots and the AoT-committed bindings.
  • Keep the zeroArgAsyncThrows end-to-end regression test as the guard that the reject path still works without the workaround.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。