Skip to content

Commit 80ad0e7

Browse files
jemmaissrofftenderlove
authored andcommitted
Remove unnecessary module flag, add module assertions to other module flags
1 parent 37ccf91 commit 80ad0e7

File tree

6 files changed

+11
-23
lines changed

6 files changed

+11
-23
lines changed

class.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,11 +1268,12 @@ do_include_modules_at(const VALUE klass, VALUE c, VALUE module, int search_super
12681268
rb_module_add_to_subclasses_list(m, iclass);
12691269
}
12701270

1271-
if (FL_TEST(klass, RMODULE_IS_REFINEMENT)) {
1271+
if (BUILTIN_TYPE(klass) == T_MODULE && FL_TEST(klass, RMODULE_IS_REFINEMENT)) {
12721272
VALUE refined_class =
12731273
rb_refinement_module_get_refined_class(klass);
12741274

12751275
rb_id_table_foreach(RCLASS_M_TBL(module), add_refined_method_entry_i, (void *)refined_class);
1276+
RUBY_ASSERT(BUILTIN_TYPE(c) == T_MODULE);
12761277
FL_SET(c, RMODULE_INCLUDED_INTO_REFINEMENT);
12771278
}
12781279

@@ -1497,7 +1498,7 @@ rb_mod_ancestors(VALUE mod)
14971498
{
14981499
VALUE p, ary = rb_ary_new();
14991500
VALUE refined_class = Qnil;
1500-
if (FL_TEST(mod, RMODULE_IS_REFINEMENT)) {
1501+
if (BUILTIN_TYPE(mod) == T_MODULE && FL_TEST(mod, RMODULE_IS_REFINEMENT)) {
15011502
refined_class = rb_refinement_module_get_refined_class(mod);
15021503
}
15031504

eval.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,7 +1129,7 @@ rb_mod_include(int argc, VALUE *argv, VALUE module)
11291129
CONST_ID(id_append_features, "append_features");
11301130
CONST_ID(id_included, "included");
11311131

1132-
if (FL_TEST(module, RMODULE_IS_REFINEMENT)) {
1132+
if (BUILTIN_TYPE(module) == T_MODULE && FL_TEST(module, RMODULE_IS_REFINEMENT)) {
11331133
rb_raise(rb_eTypeError, "Refinement#include has been removed");
11341134
}
11351135

@@ -1183,7 +1183,7 @@ rb_mod_prepend(int argc, VALUE *argv, VALUE module)
11831183
int i;
11841184
ID id_prepend_features, id_prepended;
11851185

1186-
if (FL_TEST(module, RMODULE_IS_REFINEMENT)) {
1186+
if (BUILTIN_TYPE(module) == T_MODULE && FL_TEST(module, RMODULE_IS_REFINEMENT)) {
11871187
rb_raise(rb_eTypeError, "Refinement#prepend has been removed");
11881188
}
11891189

@@ -1264,7 +1264,6 @@ rb_using_refinement(rb_cref_t *cref, VALUE klass, VALUE module)
12641264
}
12651265
}
12661266
}
1267-
FL_SET(module, RMODULE_IS_OVERLAID);
12681267
superclass = refinement_superclass(superclass);
12691268
c = iclass = rb_include_class_new(module, superclass);
12701269
RB_OBJ_WRITE(c, &RCLASS_REFINED_CLASS(c), klass);
@@ -1273,7 +1272,6 @@ rb_using_refinement(rb_cref_t *cref, VALUE klass, VALUE module)
12731272

12741273
module = RCLASS_SUPER(module);
12751274
while (module && module != klass) {
1276-
FL_SET(module, RMODULE_IS_OVERLAID);
12771275
c = RCLASS_SET_SUPER(c, rb_include_class_new(module, RCLASS_SUPER(c)));
12781276
RB_OBJ_WRITE(c, &RCLASS_REFINED_CLASS(c), klass);
12791277
module = RCLASS_SUPER(module);
@@ -1362,13 +1360,11 @@ add_activated_refinement(VALUE activated_refinements,
13621360
c = RCLASS_SUPER(c);
13631361
}
13641362
}
1365-
FL_SET(refinement, RMODULE_IS_OVERLAID);
13661363
superclass = refinement_superclass(superclass);
13671364
c = iclass = rb_include_class_new(refinement, superclass);
13681365
RB_OBJ_WRITE(c, &RCLASS_REFINED_CLASS(c), klass);
13691366
refinement = RCLASS_SUPER(refinement);
13701367
while (refinement && refinement != klass) {
1371-
FL_SET(refinement, RMODULE_IS_OVERLAID);
13721368
c = RCLASS_SET_SUPER(c, rb_include_class_new(refinement, RCLASS_SUPER(c)));
13731369
RB_OBJ_WRITE(c, &RCLASS_REFINED_CLASS(c), klass);
13741370
refinement = RCLASS_SUPER(refinement);
@@ -1421,6 +1417,7 @@ rb_mod_refine(VALUE module, VALUE klass)
14211417
VALUE superclass = refinement_superclass(klass);
14221418
refinement = rb_refinement_new();
14231419
RCLASS_SET_SUPER(refinement, superclass);
1420+
RUBY_ASSERT(BUILTIN_TYPE(refinement) == T_MODULE);
14241421
FL_SET(refinement, RMODULE_IS_REFINEMENT);
14251422
CONST_ID(id_refined_class, "__refined_class__");
14261423
rb_ivar_set(refinement, id_refined_class, klass);
@@ -1511,7 +1508,7 @@ used_modules_i(VALUE _, VALUE mod, VALUE ary)
15111508
{
15121509
ID id_defined_at;
15131510
CONST_ID(id_defined_at, "__defined_at__");
1514-
while (FL_TEST(rb_class_of(mod), RMODULE_IS_REFINEMENT)) {
1511+
while (BUILTIN_TYPE(rb_class_of(mod)) == T_MODULE && FL_TEST(rb_class_of(mod), RMODULE_IS_REFINEMENT)) {
15151512
rb_ary_push(ary, rb_attr_get(rb_class_of(mod), id_defined_at));
15161513
mod = RCLASS_SUPER(mod);
15171514
}
@@ -1562,7 +1559,7 @@ rb_mod_s_used_modules(VALUE _)
15621559
static int
15631560
used_refinements_i(VALUE _, VALUE mod, VALUE ary)
15641561
{
1565-
while (FL_TEST(rb_class_of(mod), RMODULE_IS_REFINEMENT)) {
1562+
while (BUILTIN_TYPE(rb_class_of(mod)) == T_MODULE && FL_TEST(rb_class_of(mod), RMODULE_IS_REFINEMENT)) {
15661563
rb_ary_push(ary, rb_class_of(mod));
15671564
mod = RCLASS_SUPER(mod);
15681565
}

include/ruby/internal/core/rclass.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include "ruby/internal/cast.h"
2727

2828
/** @cond INTERNAL_MACRO */
29-
#define RMODULE_IS_OVERLAID RMODULE_IS_OVERLAID
3029
#define RMODULE_IS_REFINEMENT RMODULE_IS_REFINEMENT
3130
#define RMODULE_INCLUDED_INTO_REFINEMENT RMODULE_INCLUDED_INTO_REFINEMENT
3231
/** @endcond */
@@ -55,15 +54,6 @@
5554
* Why is it here, given RClass itself is not?
5655
*/
5756
enum ruby_rmodule_flags {
58-
59-
/**
60-
* This flag has something to do with refinements... I guess? It is set on
61-
* occasions for modules that are refined by refinements, but it seems
62-
* ... nobody cares about such things? Not sure but this flag could
63-
* perhaps be a write-only information.
64-
*/
65-
RMODULE_IS_OVERLAID = RUBY_FL_USER2,
66-
6757
/**
6858
* This flag has something to do with refinements. A module created using
6959
* rb_mod_refine() has this flag set. This is the bit which controls

vm_insnhelper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3798,6 +3798,7 @@ static inline VALUE
37983798
vm_search_normal_superclass(VALUE klass)
37993799
{
38003800
if (BUILTIN_TYPE(klass) == T_ICLASS &&
3801+
RB_TYPE_P(RBASIC(klass)->klass, T_MODULE) &&
38013802
FL_TEST_RAW(RBASIC(klass)->klass, RMODULE_IS_REFINEMENT)) {
38023803
klass = RBASIC(klass)->klass;
38033804
}
@@ -3840,7 +3841,6 @@ vm_search_super_method(const rb_control_frame_t *reg_cfp, struct rb_call_data *c
38403841
}
38413842

38423843
if (BUILTIN_TYPE(current_defined_class) != T_MODULE &&
3843-
!FL_TEST_RAW(current_defined_class, RMODULE_INCLUDED_INTO_REFINEMENT) &&
38443844
reg_cfp->iseq != method_entry_iseqptr(me) &&
38453845
!rb_obj_is_kind_of(recv, current_defined_class)) {
38463846
VALUE m = RB_TYPE_P(current_defined_class, T_ICLASS) ?

vm_method.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ rb_method_entry_make(VALUE klass, ID mid, VALUE defined_class, rb_method_visibil
858858
rb_class_modify_check(klass);
859859
}
860860

861-
if (FL_TEST(klass, RMODULE_IS_REFINEMENT)) {
861+
if (RB_TYPE_P(klass, T_MODULE) && FL_TEST(klass, RMODULE_IS_REFINEMENT)) {
862862
VALUE refined_class = rb_refinement_module_get_refined_class(klass);
863863
rb_add_refined_method_entry(refined_class, mid);
864864
}

yjit/src/codegen.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5035,7 +5035,7 @@ fn gen_invokesuper(
50355035
// vm_search_normal_superclass
50365036
let rbasic_ptr: *const RBasic = current_defined_class.as_ptr();
50375037
if current_defined_class.builtin_type() == RUBY_T_ICLASS
5038-
&& unsafe { FL_TEST_RAW((*rbasic_ptr).klass, VALUE(RMODULE_IS_REFINEMENT)) != VALUE(0) }
5038+
&& unsafe { RB_TYPE_P((*rbasic_ptr).klass, RUBY_T_MODULE) && FL_TEST_RAW((*rbasic_ptr).klass, VALUE(RMODULE_IS_REFINEMENT)) != VALUE(0) }
50395039
{
50405040
return CantCompile;
50415041
}

0 commit comments

Comments
 (0)