Skip to content

BridgeJS: Include namespace prefix in ABI names for namespace-nested classes and structs#683

Merged
krodak merged 1 commit intoswiftwasm:mainfrom
PassiveLogic:kr/namespace-abi-names
Feb 27, 2026
Merged

BridgeJS: Include namespace prefix in ABI names for namespace-nested classes and structs#683
krodak merged 1 commit intoswiftwasm:mainfrom
PassiveLogic:kr/namespace-abi-names

Conversation

@krodak
Copy link
Member

@krodak krodak commented Feb 27, 2026

Overview

ABI names for namespace-nested classes omit the namespace, causing symbol collisions when two namespace enums contain a class with the same bare name. For example, @JS enum Utils { @JS class Converter {} } and @JS enum Formatting { @JS class Converter {} } both produce bjs_Converter_init.

This PR adds an abiName computed property to ExportedClass and ExportedStruct that joins namespace + name with _, then updates all ABI name generation sites to use it.

1. Skeleton model - Added abiName to ExportedClass and ExportedStruct in BridgeJSSkeleton.swift. Returns namespace_name when namespaced, bare name otherwise.

2. SwiftToSkeleton - Constructor, method, static method, and static property ABI names now use abiName from the looked-up class/struct instead of the bare name from the parser state.

3. ExportSwift - Deinit, wrap, and PropertyRenderingContext.className now use abiName.

4. BridgeJSLink - Deinit, wrap, property className, and struct helper Wasm intrinsic names (swift_js_struct_lower_* / swift_js_struct_lift_*) now use abiName.

Before:

bjs_Converter_init, bjs_Converter_deinit, bjs_HTTPServer_call

After:

bjs_Utils_Converter_init, bjs_Utils_Converter_deinit, bjs_Networking_API_HTTPServer_call

5. Collision test - Added @JS enum Formatting { @JS class Converter } alongside @JS enum Utils { @JS class Converter } in the EnumNamespace test input to validate distinct ABI names.

Top-level (non-namespaced) classes and structs are unaffected - abiName falls back to name.

@krodak krodak force-pushed the kr/namespace-abi-names branch from 085ad29 to c03f108 Compare February 27, 2026 16:30
@krodak krodak self-assigned this Feb 27, 2026
@krodak krodak force-pushed the kr/namespace-abi-names branch from c03f108 to 494ed16 Compare February 27, 2026 16:42
@krodak krodak merged commit 1750eff into swiftwasm:main Feb 27, 2026
12 checks passed
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