-
Notifications
You must be signed in to change notification settings - Fork 227
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
base: master
Are you sure you want to change the base?
Conversation
Uses `ID` directly instead of constant_id.
1384b7d to
15d181e
Compare
1f3e7c9 to
92d9009
Compare
| #[must_use] | ||
| pub fn start(&self) -> i32 { | ||
| unsafe { (*self.pointer).rg.start.byte_pos } | ||
| self.range.start |
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 should be fixed. The
rbs_location_rangehas character index, but should have byte position here.
|
|
||
| use rbs_encoding_type_t::RBS_ENCODING_UTF_8; | ||
|
|
||
| static INIT: Once = Once::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.
We can remove this now since we no longer use it.
| rbs_constant_pool_init(RBS_GLOBAL_CONSTANT_POOL, 26); | ||
| }); | ||
| } | ||
| fn setup() {} |
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.
We can also remove this as it's empty.
| } | ||
| } | ||
|
|
||
| pub struct RBSLocation { |
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.
Since rbs_location_t has been renamed to rbs_location_range_t, we can rename this to RBSLocationRange. It still needs to hold a pointer.
| "alias_kind" | ||
| | "attribute_kind" | ||
| | "attribute_visibility" | ||
| | "method_definition_kind" | ||
| | "method_definition_visibility" | ||
| | "type_param_variance" => { |
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.
We should create Rust enums and return the enums for these instead of u32. This would allow us to leverage Rust's type system and provide better ergonomics.
| } | ||
| } | ||
|
|
||
| pub struct RBSLocationListIter { |
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.
We can remove this struct since we now use RBSLocationRangeList
| writeln!(file, " #[must_use]")?; | ||
| writeln!( | ||
| file, | ||
| " pub fn {}(&self) -> Option<rbs_location_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.
This should return the Rust RBSLocationRange struct.
| writeln!(file, " #[must_use]")?; | ||
| writeln!( | ||
| file, | ||
| " pub fn {}(&self) -> rbs_location_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.
This should also return the Rust RBSLocationRange struct.
| writeln!(file)?; | ||
| } | ||
| "rbs_location_range_list" => { | ||
| write_node_field_accessor(&mut file, field, "RBSLocationRangeList")?; |
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.
The write_node_field_accessor helper function is meant to add accessors to other nodes that need the parser. Location doesn't need it, so we need to treat it differently.
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).