Skip to content

jextract: [SwiftType] optional, array, dictionary, and set into nominal type#649

Open
sidepelican wants to merge 9 commits intoswiftlang:mainfrom
sidepelican:asnominal
Open

jextract: [SwiftType] optional, array, dictionary, and set into nominal type#649
sidepelican wants to merge 9 commits intoswiftlang:mainfrom
sidepelican:asnominal

Conversation

@sidepelican
Copy link
Copy Markdown
Contributor

Problem

Currently, SwiftType defines optional, array, dictionary, and set as distinct cases.
However, these types are sometimes represented nominally (e.g., Optional<Int>).

This fragmentation forces us to implement logic for both .nominal and the specific cases (like .optional), leading to redundant code.
More importantly, it creates a risk of logic desynchronization; in fact, I've encountered issues where logic was updated for one case but overlooked for the other.

Solution

This PR unifies these special types into the .nominal case.

To preserve the original syntactic representation (such as Int? or [Int]), I have introduced SwiftNominalType.SugarName.
This allows us to handle these types as nominal while still maintaining their original "sugared" form in the grammar.

@sidepelican sidepelican requested a review from ktoso as a code owner March 27, 2026 07:34
Copy link
Copy Markdown
Collaborator

@ktoso ktoso left a comment

Choose a reason for hiding this comment

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

I like the idea but want to give this one a proper look but I'm away from computer today meh. Maybe I'll manage tonight, thank you!


import SwiftSyntax

enum SwiftKnownType: Equatable {
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.

This enum is a bit weird, we're 1:1 mapping things almost hmmm

@ktoso
Copy link
Copy Markdown
Collaborator

ktoso commented Mar 29, 2026

Sorry I'l finish reviewing tomorrow

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