Skip to content

generate extensions of wrapper types owned by other modules - #852

Open
Tatenda-k wants to merge 1 commit into
swiftlang:mainfrom
Tatenda-k:main
Open

generate extensions of wrapper types owned by other modules#852
Tatenda-k wants to merge 1 commit into
swiftlang:mainfrom
Tatenda-k:main

Conversation

@Tatenda-k

@Tatenda-k Tatenda-k commented Jul 27, 2026

Copy link
Copy Markdown

What

Teaches wrap-java to generate a Swift extension of a wrapper type that is defined in a different Swift module, containing only the members whose signatures or return type references at least one type wrapped by the module being generated.
Opt in per-module via a new manifest field:
"extendForeginclasses": ["java.lang.Class"]

Update

I have generated the foreign extensions.
I added classes to the extendForeignClasses arrays by running a script that regenerates every module and captures each [warning] Unable to translate '' '': Java class '' has not been translated . It then builds a Java-class → owning-module map from the classes map of every Sources/**/swift-java.config, and adds to the list if the dropped member's unresolved type is wrapped by a different module.
#18

@Tatenda-k
Tatenda-k requested a review from ktoso as a code owner July 27, 2026 17:11
Comment thread Sources/JavaStdlib/JavaLangReflect/JavaClass+Reflection.swift Outdated
Comment thread Sources/SwiftJavaTool/Commands/WrapJavaCommand.swift Outdated
Comment thread Sources/SwiftJavaConfigurationShared/Configuration.swift Outdated

@ktoso ktoso left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm supportive of the fix but it's pretty messy and very LLM-ish, would you mind refactoring it a bit please so it's more structured?

Also, the "follow up" should be done immediately in the same PR I think

Comment thread Sources/SwiftJavaTool/Commands/WrapJavaCommand.swift
Comment thread Sources/SwiftJavaToolLib/JavaClassTranslator.swift
@Tatenda-k
Tatenda-k force-pushed the main branch 3 times, most recently from 146fdf0 to 9867f20 Compare August 2, 2026 21:50
@Tatenda-k
Tatenda-k requested a review from ktoso August 2, 2026 21:53
Teaches wrap-java to generate a Swift extension of a wrapper type that is
defined in a different Swift module, containing only the members whose
signature or return type references at least one type wrapped by the module
being generated.

A module can only wrap a Java member when it can name every type in that
member's signature. Members mentioning a type wrapped by a downstream module
were silently dropped, and the downstream module had no way to add them back
except by hand -- java.lang.Class's reflection methods are the motivating
case, previously patched in by JavaClass+Reflection.swift.

Adds `extendForeignClasses` to the configuration: a module lists Java classes
whose Swift wrapper is owned elsewhere, and wrap-java emits an `extension` of
that wrapper containing exactly the members whose signature references a type
this module owns. Members the owning module could already express are left
alone, so nothing is duplicated.
@ktoso

ktoso commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Small comment while I'm reviewing -- I think this is good, but I'm wondering if we can get away without specififying the extended types in the configuration file. I'll look into it some more, but if you're interested in figuring that out that'd be great :)

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