ruby-changes:71930
From: Jemma <ko1@a...>
Date: Tue, 24 May 2022 03:04:50 +0900 (JST)
Subject: [ruby-changes:71930] 80ad0e751f (master): Remove unnecessary module flag, add module assertions to other module flags
https://git.ruby-lang.org/ruby.git/commit/?id=80ad0e751f From 80ad0e751f4c9aa13a581b61b348c34ede7f3956 Mon Sep 17 00:00:00 2001 From: Jemma Issroff <jemmaissroff@g...> Date: Thu, 5 May 2022 15:10:36 -0400 Subject: Remove unnecessary module flag, add module assertions to other module flags --- class.c | 5 +++-- eval.c | 13 +++++-------- include/ruby/internal/core/rclass.h | 10 ---------- vm_insnhelper.c | 2 +- vm_method.c | 2 +- yjit/src/codegen.rs | 2 +- 6 files changed, 11 insertions(+), 23 deletions(-) diff --git a/class.c b/class.c index e752cf87d9..0255a7c7e6 100644 --- a/class.c +++ b/class.c @@ -1268,11 +1268,12 @@ do_include_modules_at(const VALUE klass, VALUE c, VALUE module, int search_super https://github.com/ruby/ruby/blob/trunk/class.c#L1268 rb_module_add_to_subclasses_list(m, iclass); } - if (FL_TEST(klass, RMODULE_IS_REFINEMENT)) { + if (BUILTIN_TYPE(klass) == T_MODULE && FL_TEST(klass, RMODULE_IS_REFINEMENT)) { VALUE refined_class = rb_refinement_module_get_refined_class(klass); rb_id_table_foreach(RCLASS_M_TBL(module), add_refined_method_entry_i, (void *)refined_class); + RUBY_ASSERT(BUILTIN_TYPE(c) == T_MODULE); FL_SET(c, RMODULE_INCLUDED_INTO_REFINEMENT); } @@ -1497,7 +1498,7 @@ rb_mod_ancestors(VALUE mod) https://github.com/ruby/ruby/blob/trunk/class.c#L1498 { VALUE p, ary = rb_ary_new(); VALUE refined_class = Qnil; - if (FL_TEST(mod, RMODULE_IS_REFINEMENT)) { + if (BUILTIN_TYPE(mod) == T_MODULE && FL_TEST(mod, RMODULE_IS_REFINEMENT)) { refined_class = rb_refinement_module_get_refined_class(mod); } diff --git a/eval.c b/eval.c index 237c0fbd66..a059987824 100644 --- a/eval.c +++ b/eval.c @@ -1129,7 +1129,7 @@ rb_mod_include(int argc, VALUE *argv, VALUE module) https://github.com/ruby/ruby/blob/trunk/eval.c#L1129 CONST_ID(id_append_features, "append_features"); CONST_ID(id_included, "included"); - if (FL_TEST(module, RMODULE_IS_REFINEMENT)) { + if (BUILTIN_TYPE(module) == T_MODULE && FL_TEST(module, RMODULE_IS_REFINEMENT)) { rb_raise(rb_eTypeError, "Refinement#include has been removed"); } @@ -1183,7 +1183,7 @@ rb_mod_prepend(int argc, VALUE *argv, VALUE module) https://github.com/ruby/ruby/blob/trunk/eval.c#L1183 int i; ID id_prepend_features, id_prepended; - if (FL_TEST(module, RMODULE_IS_REFINEMENT)) { + if (BUILTIN_TYPE(module) == T_MODULE && FL_TEST(module, RMODULE_IS_REFINEMENT)) { rb_raise(rb_eTypeError, "Refinement#prepend has been removed"); } @@ -1264,7 +1264,6 @@ rb_using_refinement(rb_cref_t *cref, VALUE klass, VALUE module) https://github.com/ruby/ruby/blob/trunk/eval.c#L1264 } } } - FL_SET(module, RMODULE_IS_OVERLAID); superclass = refinement_superclass(superclass); c = iclass = rb_include_class_new(module, superclass); RB_OBJ_WRITE(c, &RCLASS_REFINED_CLASS(c), klass); @@ -1273,7 +1272,6 @@ rb_using_refinement(rb_cref_t *cref, VALUE klass, VALUE module) https://github.com/ruby/ruby/blob/trunk/eval.c#L1272 module = RCLASS_SUPER(module); while (module && module != klass) { - FL_SET(module, RMODULE_IS_OVERLAID); c = RCLASS_SET_SUPER(c, rb_include_class_new(module, RCLASS_SUPER(c))); RB_OBJ_WRITE(c, &RCLASS_REFINED_CLASS(c), klass); module = RCLASS_SUPER(module); @@ -1362,13 +1360,11 @@ add_activated_refinement(VALUE activated_refinements, https://github.com/ruby/ruby/blob/trunk/eval.c#L1360 c = RCLASS_SUPER(c); } } - FL_SET(refinement, RMODULE_IS_OVERLAID); superclass = refinement_superclass(superclass); c = iclass = rb_include_class_new(refinement, superclass); RB_OBJ_WRITE(c, &RCLASS_REFINED_CLASS(c), klass); refinement = RCLASS_SUPER(refinement); while (refinement && refinement != klass) { - FL_SET(refinement, RMODULE_IS_OVERLAID); c = RCLASS_SET_SUPER(c, rb_include_class_new(refinement, RCLASS_SUPER(c))); RB_OBJ_WRITE(c, &RCLASS_REFINED_CLASS(c), klass); refinement = RCLASS_SUPER(refinement); @@ -1421,6 +1417,7 @@ rb_mod_refine(VALUE module, VALUE klass) https://github.com/ruby/ruby/blob/trunk/eval.c#L1417 VALUE superclass = refinement_superclass(klass); refinement = rb_refinement_new(); RCLASS_SET_SUPER(refinement, superclass); + RUBY_ASSERT(BUILTIN_TYPE(refinement) == T_MODULE); FL_SET(refinement, RMODULE_IS_REFINEMENT); CONST_ID(id_refined_class, "__refined_class__"); rb_ivar_set(refinement, id_refined_class, klass); @@ -1511,7 +1508,7 @@ used_modules_i(VALUE _, VALUE mod, VALUE ary) https://github.com/ruby/ruby/blob/trunk/eval.c#L1508 { ID id_defined_at; CONST_ID(id_defined_at, "__defined_at__"); - while (FL_TEST(rb_class_of(mod), RMODULE_IS_REFINEMENT)) { + while (BUILTIN_TYPE(rb_class_of(mod)) == T_MODULE && FL_TEST(rb_class_of(mod), RMODULE_IS_REFINEMENT)) { rb_ary_push(ary, rb_attr_get(rb_class_of(mod), id_defined_at)); mod = RCLASS_SUPER(mod); } @@ -1562,7 +1559,7 @@ rb_mod_s_used_modules(VALUE _) https://github.com/ruby/ruby/blob/trunk/eval.c#L1559 static int used_refinements_i(VALUE _, VALUE mod, VALUE ary) { - while (FL_TEST(rb_class_of(mod), RMODULE_IS_REFINEMENT)) { + while (BUILTIN_TYPE(rb_class_of(mod)) == T_MODULE && FL_TEST(rb_class_of(mod), RMODULE_IS_REFINEMENT)) { rb_ary_push(ary, rb_class_of(mod)); mod = RCLASS_SUPER(mod); } diff --git a/include/ruby/internal/core/rclass.h b/include/ruby/internal/core/rclass.h index 13a33a28bd..6d450917db 100644 --- a/include/ruby/internal/core/rclass.h +++ b/include/ruby/internal/core/rclass.h @@ -26,7 +26,6 @@ https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/core/rclass.h#L26 #include "ruby/internal/cast.h" /** @cond INTERNAL_MACRO */ -#define RMODULE_IS_OVERLAID RMODULE_IS_OVERLAID #define RMODULE_IS_REFINEMENT RMODULE_IS_REFINEMENT #define RMODULE_INCLUDED_INTO_REFINEMENT RMODULE_INCLUDED_INTO_REFINEMENT /** @endcond */ @@ -55,15 +54,6 @@ https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/core/rclass.h#L54 * Why is it here, given RClass itself is not? */ enum ruby_rmodule_flags { - - /** - * This flag has something to do with refinements... I guess? It is set on - * occasions for modules that are refined by refinements, but it seems - * ... nobody cares about such things? Not sure but this flag could - * perhaps be a write-only information. - */ - RMODULE_IS_OVERLAID = RUBY_FL_USER2, - /** * This flag has something to do with refinements. A module created using * rb_mod_refine() has this flag set. This is the bit which controls diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 2eb9fd8630..1e40088ffa 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -3798,6 +3798,7 @@ static inline VALUE https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L3798 vm_search_normal_superclass(VALUE klass) { if (BUILTIN_TYPE(klass) == T_ICLASS && + RB_TYPE_P(RBASIC(klass)->klass, T_MODULE) && FL_TEST_RAW(RBASIC(klass)->klass, RMODULE_IS_REFINEMENT)) { klass = RBASIC(klass)->klass; } @@ -3840,7 +3841,6 @@ vm_search_super_method(const rb_control_frame_t *reg_cfp, struct rb_call_data *c https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L3841 } if (BUILTIN_TYPE(current_defined_class) != T_MODULE && - !FL_TEST_RAW(current_defined_class, RMODULE_INCLUDED_INTO_REFINEMENT) && reg_cfp->iseq != method_entry_iseqptr(me) && !rb_obj_is_kind_of(recv, current_defined_class)) { VALUE m = RB_TYPE_P(current_defined_class, T_ICLASS) ? diff --git a/vm_method.c b/vm_method.c index a10f90e7a3..b12d134dce 100644 --- a/vm_method.c +++ b/vm_method.c @@ -858,7 +858,7 @@ rb_method_entry_make(VALUE klass, ID mid, VALUE defined_class, rb_method_visibil https://github.com/ruby/ruby/blob/trunk/vm_method.c#L858 rb_class_modify_check(klass); } - if (FL_TEST(klass, RMODULE_IS_REFINEMENT)) { + if (RB_TYPE_P(klass, T_MODULE) && FL_TEST(klass, RMODULE_IS_REFINEMENT)) { VALUE refined_class = rb_refinement_module_get_refined_class(klass); rb_add_refined_method_entry(refined_class, mid); } diff --git a/yjit/src/codegen.rs b/yjit/src/codegen.rs index e64f269cfe..3591e05b3d 100644 --- a/yjit/src/codegen.rs +++ b/yjit/src/codegen.rs @@ -5035,7 +5035,7 @@ fn gen_invokesuper( https://github.com/ruby/ruby/blob/trunk/yjit/src/codegen.rs#L5035 // vm_search_normal_superclass let rbasic_ptr: *const RBasic = current_defined_class.as_ptr(); if current_defined_class.builtin_type() == RUBY_T_ICLASS - && unsafe { FL_TEST_RAW((*rbasic_ptr).klass, VALUE(RMODULE_IS_REFINEMENT)) != VALUE(0) } + && unsafe { RB_TYPE_P((*rbasic_ptr).klass, RUBY_T_MODULE) && FL_TEST_RAW((*rbasic_ptr).klass, VALUE(RMODULE_IS_REFINEMENT)) != VALUE(0) } { return CantCompile; } -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/