-
Notifications
You must be signed in to change notification settings - Fork 217
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
Extract out usages of Ruby IDs #2175
base: master
Are you sure you want to change the base?
Conversation
4ee0431
to
fa6470f
Compare
@@ -221,9 +239,9 @@ static VALUE rbs_new_location_from_loc_range(VALUE buffer, rbs_loc_range rg) { | |||
static VALUE location_aref(VALUE self, VALUE name) { | |||
rbs_loc *loc = rbs_check_location(self); | |||
|
|||
ID id = SYM2ID(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.
I think this used to leak memory, since SYM2ID
would allocate a static symbol.
@@ -1023,8 +1031,13 @@ static VALUE parse_simple(parserstate *state) { | |||
return parse_symbol(state); | |||
} | |||
case tUIDENT: { | |||
ID name = INTERN_TOKEN(state, state->current_token); |
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 INTERN_TOKEN
macro was calling rb_intern3()
, which was slowly leaking memory by creating static ("immortal") symbols.
The replacement rbs_constant_pool_find()
function uses rb_check_id_cstr()
instead, which checks for a match without intern a new symbol if there wasn't one.
|
||
/** The overall constant pool, which stores constants found while parsing. */ | ||
typedef struct { | ||
void *dummy; // Workaround for structs not being allowed to be empty. |
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.
Eventually, this will be replaced with the real storage that will store the constant pool, instead of the one built into the Ruby VM.
fa6470f
to
0b4f69e
Compare
0b4f69e
to
3ae33c6
Compare
This PR extracts out an
rbs_constant_pool
interface, which mimics thepm_constant_pool
from Prism.I use it to wrap all usages of
ID
as location child keys, instead of directly depending Ruby APIs likerb_intern()
,ID2SYM
,SYM2ID
, etc. This includes the keys used to identify the children in arb_loc
, and the keys used in the parser's typevar tables.For now, this is just a dummy implementation which delegates to those same Ruby APIs, but will eventually be replaced with Prism's real logic, which doesn't depend on
ruby.h
at all.For easier reviewing, have a look at each commit separately.