-
Notifications
You must be signed in to change notification settings - Fork 229
Delete global constant pool from the parser #2826
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
1f3e7c9 to
92d9009
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is excellent! I don't have permission to officially "approve" on this repo, but I do approve :)
Left a few small comments/questions, but really happy with this!
Would you minding doing fixups on the various "fix"-style commits? Also, I think it would be useful if the Rust crate changes to add the new C types, was combined in the same commit that adds new types to C in the first place
| typedef struct { | ||
| int start; | ||
| int end; | ||
| } rbs_loc_range; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you considered explicitly naming this "legacy"? It's a bit wordier, but much more clear versus just having a rbs_loc_range vs rbs_location_range distinction.
| } rbs_loc_range; | |
| } rbs_legacy_loc_range; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks — I agree that making the distinction explicit would help.
I’m hesitant to use legacy, though, because I’m not planning to deprecate this in the Ruby codepath right now, and “legacy” tends to communicate “old + on the way out,” which isn’t what I mean here.
I’m open to a Ruby-specific rename, but I haven’t landed on a good name yet. (rbs_ruby_location_range???) In the meantime, would a brief comment in the file clarifying the intent/distinction be sufficient?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good reasoning, and I agree.
a brief comment in the file clarifying the intent/distinction be sufficient?
Yep!
| ALLOCATOR(), | ||
| full_loc, | ||
| colon_loc, | ||
| RBS_RANGE_LEX2AST(colon_range), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you help me understand why RBS_RANGE_LEX2AST applies here (but didn't before?), but not to full_loc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No good reason here. full_loc is declared as rbs_location_range, but colon_range is rbs_range_t.
Anyways, we need to fix this again. rbs_location_range is defined by character offsets, but Rust crate requires byte-offsets.
ext/rbs_extension/ast_translation.c
Outdated
| return EMPTY_ARRAY; | ||
| } | ||
|
|
||
| VALUE ruby_array = rb_ary_new(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| VALUE ruby_array = rb_ary_new(); | |
| VALUE ruby_array = rb_ary_new_capa((long) list->length); |
(technically size_t can be larger than long, so we can add an assertion to compare against LONG_MAX, but really, the length should never be anywhere close to that many)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(ooops, this change needs to be made on the templates/ext/rbs_extension/ast_translation.c.erb template, not the rendered ext/rbs_extension/ast_translation.c)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried this micro-optimization before, but it didn't improve the parsing performance. So, keeping the current code would be fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My eyes have just gone so attuned to finding unsized vector allocations :D They all stick out in bright red to me now lol
rust/ruby-rbs/build.rs
Outdated
| } | ||
| "rbs_ivar_name" => { | ||
| writeln!(file, " #[must_use]")?; | ||
| writeln!(file, " pub fn {}(&self) -> IvarName {{", field.name)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious, why do this from Rust code, rather than the usual ERB templates we use for C?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Personally I’m +1 on using the ERB templates for the Rust code as well, but I’m not fully sure—using build.rs would be more standard in the Rust community.
I’m happy to squash/fix up the commits that address review comments once everything looks good to reviewers. 👍 I’m not fully sure I can cleanly combine the Rust crate updates with the C type changes—those changes are a bit intertwined—but I’ll take a look and see what I can do. |
75d586c to
3bb60d4
Compare
044b1b2 to
107663b
Compare
107663b to
2bc0f90
Compare
Uses `ID` directly instead of constant_id.
* Rename `Type` to `Node` * Introduce another `Type` class * Explicit *constructor* parameters construction
2bc0f90 to
7595e20
Compare
The parser currently uses global constant pool and updates the pool during parsing through
RBS_KEYWORDnode. This is not thread-safe and we cannot run the parser in parallel. This PR is to remove the global constant pool andRBS_KEYWORDnode by:enums for symbol literal unions (for example, method/attributevisibilityis:public | :private)This is not a breaking change in Ruby library -- the
RBS::Locationstructure nor the union type attributes are not changed -- but introduces breaking changes in C level API.Flat location attributes
The nested
locationattributes are expanded to flat struct attributes.Instead of having one
locationattribute and sub-locations are stored under it,nodestructs directly have sub-locations are its attributes.The nested locations are then reconstructed in
ast_translation.c.C
enums for symbol literal unionsThe union attributes have their own
enumtypes.The values are translated to Ruby symbols (and
nil).