Skip to content

Prevent cross-module inlining of remaining @_extern(wasm) functions#631

Merged
kateinoigakukun merged 1 commit intomainfrom
fix/prevent-cross-module-inlining-i32
Feb 13, 2026
Merged

Prevent cross-module inlining of remaining @_extern(wasm) functions#631
kateinoigakukun merged 1 commit intomainfrom
fix/prevent-cross-module-inlining-i32

Conversation

@fjtrujy
Copy link
Contributor

@fjtrujy fjtrujy commented Feb 13, 2026

Summary

Extends the fix from #628 (b3ddd88f) to all remaining public @_extern(wasm) BridgeJS intrinsics that were missing the @inline(never) wrapper pattern:

  • _swift_js_throw
  • _swift_js_init_memory
  • _swift_js_push_string
  • _swift_js_push_i32
  • _swift_js_pop_i32
  • _swift_js_struct_cleanup
  • _swift_js_push_pointer

Problem

Without @inline(never) wrappers, the Swift compiler can inline these public @_extern(wasm, module: "bjs", ...) functions across module boundaries. When this happens, the wasm import module attribute changes from "bjs" to "env" (the default), causing a wasm-ld linker error:

wasm-ld: error: import module mismatch for symbol: $s13JavaScriptKit17_swift_js_pop_i32s5Int32VyF
>>> defined as bjs in JavaScriptKit.build/BridgeJSIntrinsics.swift.o
>>> defined as env in WASMGoodNotesLibrary.build/BridgeJS.swift.o

Fix

Applied the same pattern already used for f32/f64/pop_pointer: make the @_extern declaration private and wrap it with a @inline(never) public function that prevents cross-module inlining while preserving the correct wasm import module.

🤖 Generated with Claude Code

Extends the fix from b3ddd88 (which addressed f32/f64) to all remaining
public @_extern(wasm) BridgeJS intrinsics: i32, string, pointer, throw,
init_memory, and struct_cleanup.

Without @inline(never) wrappers, the Swift compiler can inline these
functions across module boundaries, causing the wasm import module
attribute to change from "bjs" to "env". This results in a wasm-ld
linker error when a downstream module (e.g. via BridgeJS codegen)
references the same symbol with a different import module.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@fjtrujy fjtrujy force-pushed the fix/prevent-cross-module-inlining-i32 branch from 872da4d to 1cf60d8 Compare February 13, 2026 10:51
@kateinoigakukun kateinoigakukun enabled auto-merge (squash) February 13, 2026 10:51
@kateinoigakukun kateinoigakukun merged commit bab0adb into main Feb 13, 2026
11 checks passed
@kateinoigakukun kateinoigakukun deleted the fix/prevent-cross-module-inlining-i32 branch February 13, 2026 11:18
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.

2 participants