Skip to content

NCF: BridgeJS: Generalize Optional stack ABI for Array, Dictionary, and Struct types#618

Merged
kateinoigakukun merged 1 commit intoswiftwasm:mainfrom
PassiveLogic:kr/stack-abi-generalization
Feb 12, 2026
Merged

NCF: BridgeJS: Generalize Optional stack ABI for Array, Dictionary, and Struct types#618
kateinoigakukun merged 1 commit intoswiftwasm:mainfrom
PassiveLogic:kr/stack-abi-generalization

Conversation

@krodak
Copy link
Member

@krodak krodak commented Feb 11, 2026

Overview

First part of attempts to simplify codegen a bit. This PR introduces a generic Optional: _BridgedSwiftStackType conformance for stack-based types (Array, Dictionary, Struct), replacing inline codegen with unified bridgeJSLiftParameter() / bridgeJSLowerReturn() calls. This reduces codegen complexity by not requiring type-specific Optional handling each time.

Changes

BridgeJSIntrinsics.swift

  • _BridgedSwiftGenericOptionalStackType marker protocol - inherits _BridgedSwiftStackType where StackLiftResult == Self. Only Array, Dictionary, and _BridgedSwiftStruct conform. This keeps the generic Optional conformance scoped to stack-based types while primitives, enums, and heap objects retain their existing type-specific Optional extensions.

  • Generic Optional: _BridgedSwiftStackType conformance - provides bridgeJSLiftParameter() (pops isSome from stack, delegates to Wrapped.bridgeJSLiftParameter()) and bridgeJSLowerReturn() (pushes wrapped value then isSome flag).

  • Removed duplicate/dead code replaced by generic conformance

ExportSwift.swift

  • Simplified liftNullableExpression - removed the .array special case that generated inline if-else blocks; arrays now go through the same Optional<T>.bridgeJSLiftParameter() path as other types.
  • Simplified lowerOptionalStatements - .array, .dictionary, .swiftStruct cases now emit a single accessor.bridgeJSLowerReturn() instead of 5-line inline if-let + push patterns.
  • Simplified liftParameterInfo - Optional wrapping a stack-based type (empty params) returns empty params (fully stack-based), while Optional<primitive> keeps direct WASM params.

JSGlueGen.swift

  • Optional struct/array/dictionary parameters now push isSome to i32Stack instead of passing as a direct WASM argument, matching the fully stack-based ABI

@krodak krodak self-assigned this Feb 11, 2026
Copy link
Member

@kateinoigakukun kateinoigakukun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good first step, thanks!

@kateinoigakukun kateinoigakukun merged commit 1b99431 into swiftwasm:main Feb 12, 2026
11 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