Skip to content

Add rewriter option to erase generics#946

Open
dejmedus wants to merge 4 commits into
jb-erase-generic-types-optionfrom
jb-erase-generic-types
Open

Add rewriter option to erase generics#946
dejmedus wants to merge 4 commits into
jb-erase-generic-types-optionfrom
jb-erase-generic-types

Conversation

@dejmedus

@dejmedus dejmedus commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

May be easier to review by commit :)

Sorbet ignores generic types at runtime as they cannot be enforced. This means in runtime contexts we can drop generic types entirely, simplifying the RBS to Sorbet signature translation

This PR adds an erase_generic_types option to the RBSCommentsToSorbetSigs rewriter and --erase-generic-types flag to CLI. When enabled generic Foo[Bar] will become Foo and type members will become type aliases of T.anything

@dejmedus dejmedus force-pushed the jb-erase-generic-types branch 3 times, most recently from 31c1d26 to 2146722 Compare June 16, 2026 21:39
@dejmedus dejmedus changed the base branch from main to jb-refactor-type-translator June 16, 2026 21:40
@dejmedus

dejmedus commented Jun 16, 2026

Copy link
Copy Markdown
Contributor Author

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

Base automatically changed from jb-refactor-type-translator to main June 16, 2026 21:57
@dejmedus dejmedus changed the base branch from main to graphite-base/946 July 13, 2026 16:15
@dejmedus dejmedus force-pushed the jb-erase-generic-types branch from 2146722 to b5fa3f7 Compare July 13, 2026 16:15
@dejmedus dejmedus changed the base branch from graphite-base/946 to jb-erase-generic-types-option July 13, 2026 16:15
dejmedus added 4 commits July 14, 2026 16:00
Sorbet erases generic types at runtime as they cannot
be enforced. This means in runtime contexts
we can drop generic types entirely, simplifying
the rbs to sorbet signature translation

This commit adds an `erase_generic_types` option to
the `RBSCommentsToSorbetSigs` rewriter. When set,
generic args are dropped from translated sigs
(`Box[Integer]` to `Box`) and `extend T::Generic`
is not added
Expose a flag to set the `erase_generic_types` option
in `Spoom::Sorbet::Translate.rbs_comments_to_sorbet_sigs`
so CLI users can drop generic types when translating
from RBS to RBI
When erasing generic types we replace `type_member`s
with a `T.anything` type alias of the same name.
Qualifying `T.type_alias` to `::T.type_alias` ensures
we avoid conflicts like `T = T.type_alias`. This
matches
@dejmedus dejmedus force-pushed the jb-erase-generic-types branch from b5fa3f7 to 341e370 Compare July 14, 2026 22:09
@dejmedus dejmedus force-pushed the jb-erase-generic-types-option branch from f95dbf3 to 0679934 Compare July 14, 2026 22:09
@dejmedus dejmedus marked this pull request as ready for review July 15, 2026 00:45
@dejmedus dejmedus requested a review from a team as a code owner July 15, 2026 00:45
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.

1 participant