Remove unnecessary module flag, add module assertions to other module flags

This commit is contained in:
Jemma Issroff 2022-05-05 15:10:36 -04:00 коммит произвёл Aaron Patterson
Родитель 37ccf91bfb
Коммит 80ad0e751f
6 изменённых файлов: 11 добавлений и 23 удалений

Просмотреть файл

@ -1268,11 +1268,12 @@ do_include_modules_at(const VALUE klass, VALUE c, VALUE module, int search_super
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)
{
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);
}

13
eval.c
Просмотреть файл

@ -1129,7 +1129,7 @@ rb_mod_include(int argc, VALUE *argv, VALUE module)
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)
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)
}
}
}
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)
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,
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)
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)
{
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 _)
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);
}

Просмотреть файл

@ -26,7 +26,6 @@
#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 @@
* 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

Просмотреть файл

@ -3798,6 +3798,7 @@ static inline VALUE
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
}
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) ?

Просмотреть файл

@ -858,7 +858,7 @@ rb_method_entry_make(VALUE klass, ID mid, VALUE defined_class, rb_method_visibil
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);
}

Просмотреть файл

@ -5035,7 +5035,7 @@ fn gen_invokesuper(
// 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;
}