Skip to content

Port prototype rb generation to prism - #3140

Open
Earlopain wants to merge 4 commits into
ruby:masterfrom
Earlopain:prototype-rb-prism
Open

Port prototype rb generation to prism#3140
Earlopain wants to merge 4 commits into
ruby:masterfrom
Earlopain:prototype-rb-prism

Conversation

@Earlopain

Copy link
Copy Markdown
Contributor

On top of #3105

This just leaves the runtime on rubyvm, which is deprecated and I won't port.
Because of that, some helper methods are duplicated to work with both prism and rubyvm.

I tested this on rails, and out of 3435 files only 28 differ. That is mainly for string literals that are divided
by line continutions (previously they were embeded, now it's only saying it is a string)
Also some block optionality is changed for the better. For example (callable || block || :itself.to_proc).call now makes the block optional.
Actually, rbs generation previously crashed when run against rails. Now it doesn't (:

The other two commits are fixes for things I noticed along the way. They result in many (correct) changes in rbs compared to the current imlpementation, so I separated them so it's easier to compare.

Apart from porting to prism, this also does the following:

1. Remove `variable` tracking for `type_of0`. It contains `AST::TypeParam` but checked for inclusion of a Symbol.
There's no difference in the output even when this is fixed, so I just removed it entirely
2. Have the parse method return declarations, make it a class method.
Just more convenient with the new structure. Eventually `rb prototype` will do this as well
3. Allow to use it on jruby/truffleruby.
4. Split comment parsing from comment processing in the helper.
In rbi the comments now come from a plain parse. When `prototype rb` uses prism as well, `parse_comments` can be
removed (as well as most of the other helper methods there)

I tested this against code samples from https://github.com/Shopify/tapioca/blob/d029cc9c3f76865f61fdbaff68d75e18a0014764/spec/tapioca/gem/pipeline_spec.rb
The output is largely the same, and improved in some areas. For example, `type_member` with no paren
is no longer considered an untyped constant. Previously that was only the case for `type_member()` or when
an argument was passed like `type_member(:out)`.
@Earlopain
Earlopain force-pushed the prototype-rb-prism branch 2 times, most recently from 94d8a02 to 832eac2 Compare August 31, 2026 12:35
@Earlopain Earlopain mentioned this pull request Aug 31, 2026
This just leaves the runtime on rubyvm, which is deprecated and I won't port.
Because of that, some helper methods are duplicated to work with both prism and rubyvm.

I tested this on rails, and out of 3435 files only 28 differ. That is mainly for string literals that are divided
by line continutions (previously they were embeded, now it's only saying it a string)
Also some block optionality is changed for the better. For example `(callable || block || :itself.to_proc).call` now makes the block optional
The rubyvm code only handled `LIST` but should have checked `ZLIST` as well.
As such the type was untyped previously
For the first case it resovled to untyped
For the second case, it was `Array | untyped`

In both cases we know it will return an array
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