From b00f280d4b9569e7153365d7e1c522b3d6b3c6cf Mon Sep 17 00:00:00 2001 From: Alan Wu Date: Thu, 11 Apr 2019 23:46:28 -0400 Subject: Eagerly name modules and classes * variable.c: make the hidden ivars `classpath` and `tmp_classpath` the source of truth for module and constant names. Assign to them when modules are bind to constants. * variable.c: remove references to module name cache, as what used to be the cache is now the source of truth. Remove rb_class_path_no_cache(). * variable.c: remove the hidden ivar `classid`. This existed for the purposes of module name search, which is now replaced. Also, remove the associated rb_name_class(). * class.c: use rb_set_class_path_string to set the name of Object during boot. Must use a fstring as this runs before rb_cString is initialized and creating a normal string leads to a VALUE without a class. * spec/ruby/core/module/name_spec.rb: add a few specs to specify what happens to Module#name across multiple operations. These specs pass without other code changes in this commit. [Feature #15765] --- class.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'class.c') diff --git a/class.c b/class.c index 0cee5caae2..6c71ec8bd0 100644 --- a/class.c +++ b/class.c @@ -537,7 +537,6 @@ boot_defclass(const char *name, VALUE super) VALUE obj = rb_class_boot(super); ID id = rb_intern(name); - rb_name_class(obj, id); rb_const_set((rb_cObject ? rb_cObject : obj), id, obj); rb_vm_add_root_module(id, obj); return obj; @@ -551,7 +550,7 @@ Init_class_hierarchy(void) rb_gc_register_mark_object(rb_cObject); /* resolve class name ASAP for order-independence */ - rb_class_name(rb_cObject); + rb_set_class_path_string(rb_cObject, rb_cObject, rb_fstring_lit("Object")); rb_cModule = boot_defclass("Module", rb_cObject); rb_cClass = boot_defclass("Class", rb_cModule); @@ -669,7 +668,6 @@ rb_define_class(const char *name, VALUE super) } klass = rb_define_class_id(id, super); rb_vm_add_root_module(id, klass); - rb_name_class(klass, id); rb_const_set(rb_cObject, id, klass); rb_class_inherited(super, klass); @@ -767,7 +765,6 @@ rb_define_module_id(ID id) VALUE mdl; mdl = rb_module_new(); - rb_name_class(mdl, id); return mdl; } -- cgit v1.2.3