Skip to content

emit-tsd: support multi-value-return wasm functions instead of asserting#26965

Closed
guybedford wants to merge 1 commit into
emscripten-core:mainfrom
guybedford:emit-tsd-multivalue
Closed

emit-tsd: support multi-value-return wasm functions instead of asserting#26965
guybedford wants to merge 1 commit into
emscripten-core:mainfrom
guybedford:emit-tsd-multivalue

Conversation

@guybedford
Copy link
Copy Markdown
Collaborator

A wasm function returning multiple values trips a hard assertion in create_tsd and aborts the whole --emit-tsd pass:

assert len(functype.returns) <= 1, 'One return type only supported'

Multi-value return is standardized wasm and shows up in real toolchains — most notably wasm-bindgen, which emits (i32, i32) ptr+len pairs for any Rust export returning String, Vec<u8>, Result<T, E>, etc. on wasm32-unknown-emscripten. The wasm is valid; only the TSD pass crashes.

Replace the assert with the natural translation: a wasm function returning (i32, i32) becomes a TS function returning [number, number]. Empty- and single-return paths are unchanged.

The raw tuple isn't always what consumers ultimately want (wasm-bindgen's JS glue wraps these into a single JS value), but emitting something lets the .d.ts parse and lets downstream .d.ts mergers intersect with more precise types.

Test: test/other/test_emit_tsd_multivalue.c compiles a struct-returning function with -mmultivalue -Xclang -target-abi -Xclang experimental-mv and asserts the generated .d.ts contains the tuple type. Without the fix the new test reproduces the original AssertionError; with it, all existing --emit-tsd tests continue to pass.

A wasm function returning multiple values (e.g. wasm-bindgen's ptr+len
pair for `pub fn foo() -> String`) tripped a hard assertion in
`create_tsd` and aborted the whole --emit-tsd pass.  Surface multi-value
returns as a TypeScript tuple type instead.
@guybedford
Copy link
Copy Markdown
Collaborator Author

Closing in favour of #26966.

@guybedford guybedford closed this May 16, 2026
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