path: root/class.c
diff options
authorAlan Wu <>2019-04-11 23:46:28 -0400
committerNobuyoshi Nakada <>2019-05-22 15:46:47 +0900
commitb00f280d4b9569e7153365d7e1c522b3d6b3c6cf (patch)
tree872700dc5ffaa9e3b0fec6f0d13df655704355d7 /class.c
parenta829be209fc5866f07adc93e8b2f1ddf7131ebfd (diff)
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]
Diffstat (limited to 'class.c')
1 files changed, 1 insertions, 4 deletions
diff --git a/class.c b/class.c
index 0cee5ca..6c71ec8 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)
/* 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;