Skip to content

BridgeJS: Support protocol refinement and constrained imports - #815

Open
krodak wants to merge 1 commit into
swiftwasm:mainfrom
PassiveLogic:kr/protocol-refinement-upstream
Open

krodak wants to merge 1 commit into
swiftwasm:mainfrom
PassiveLogic:kr/protocol-refinement-upstream

Conversation

@krodak

@krodak krodak commented Sep 22, 2026 •

Copy link
Copy Markdown
Member

Overview

Support same-module @JS protocol refinement and protocol constraints on generic JavaScript imports.

Generated implementations live in wrapper-only protocol extensions, so Swift resolves inheritance without copying members. TypeScript interfaces use extends. Protocol-qualified helper names also prevent collisions between same-named methods; Wasm import names are unchanged.

Example

import JavaScriptKit

@JS protocol Identified { var id: String { get } }
@JS protocol Named { var name: String { get } }
@JS protocol NamedEntity: Identified, Named {}

@JS func describe(_ value: NamedEntity) -> String {
    "\(value.id): \(value.name)"
}
const text = exports.describe({ id: "42", name: "Main building" });

This returns "42: Main building". Previously, the generated wrapper was missing the inherited requirements.

Generic Imports

@JS protocol Node: Identified, Named, BridgedSwiftGenericBridgeable {}

@JSFunction func roundTrip<T: Node>(_ value: T) throws(JSException) -> T

Generates roundTrip<T extends Node>(value: T): T. Qualified constraints such as GraphKit.Node are preserved. Concrete conformers must expose the required members to JavaScript.

Limitations

Dependency protocols can be used as generic constraints, but cannot be refined locally. Anonymous existential parameters such as any (Identified & Named) remain unsupported.

Test Plan

  • BridgeJS tests with SwiftSyntax 600-603 and npm run check:bridgejs-dts.
  • ./Utilities/bridge-js-generate.sh (no drift).
  • make unittest SWIFT_SDK_ID=swift-6.3.1-RELEASE_wasm BUILD_SYSTEM=native, covering refinement, inherited accessors, and constrained imports.
  • ./Utilities/format.swift and git diff --check.

@krodak krodak self-assigned this Sep 22, 2026
@krodak
krodak force-pushed the kr/protocol-refinement-upstream branch from a88f64f to edca6f9 Compare September 22, 2026 13:48

This branch has not been deployed

No deployments
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