Skip to content

BridgeJS: Support generic functions on imported JS APIs - #18

Closed
krodak wants to merge 2 commits into
mainfrom
kr/stack-abi-generics-import
Closed

BridgeJS: Support generic functions on imported JS APIs#18
krodak wants to merge 2 commits into
mainfrom
kr/stack-abi-generics-import

Conversation

@krodak

@krodak krodak commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

Summary

Import half of generic function support (swiftwasm#398), split out of swiftwasm#787 per review. An imported @JSFunction can take a type parameter, so one declaration covers every bridged type:

@JSFunction func parse<T: BridgedSwiftGenericBridgeable>(_ json: String) throws(JSException) -> T

let user: User = try parse(jsonString)   // T inferred from the call site

T can be any primitive, String, JSValue, or a @JS struct/enum/final class, bare or as T?, [T], [String: T]. Also works on @JSClass inits, methods and statics, and for return-only generics. Exported generics are rejected with a diagnostic and land separately on top of this ABI.

How it works

Builds without generics don't get the JS generic runtime, just a no-op registration hook per module with @JS types.

Test plan

  • Codegen + link snapshots: free functions, inits, methods, statics, mixed/multiple params, return-only, wrapped forms
  • Diagnostics: import constraints, export rejection
  • ImportGenericAPITests: runtime round-trip of every bridgeable type through real JS, including JSON.parse
  • Examples/Embedded builds a generic round-trip in CI
  • Cross-module registration + runtime gating link tests

@krodak
krodak force-pushed the kr/stack-abi-generics-import branch 2 times, most recently from c995dfb to adbbb6f Compare August 10, 2026 13:04
@krodak
krodak force-pushed the kr/stack-abi-generics-import branch from adbbb6f to 3561938 Compare August 10, 2026 13:33
@krodak krodak closed this Aug 10, 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