diff --git a/ChangeLog b/ChangeLog index 11747742e3..7c66c50472 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Mon Oct 8 23:02:19 2012 Shugo Maeda + + * eval.c, gc.c, iseq.c, node.h, vm_insnhelper.c, vm_insnhelper.h, + vm_method.c: rename omod and overlaid modules to refinements. + + * eval.c (hidden_identity_hash_new): renamed from identity_hash_new. + Sun Oct 7 04:50:00 2012 Zachary Scott * lib/abbrev.rb: Documentation examples for Abbrev. diff --git a/eval.c b/eval.c index 053d4ac8bf..c7e722323f 100644 --- a/eval.c +++ b/eval.c @@ -1041,35 +1041,35 @@ void check_class_or_module(VALUE obj) } static VALUE -identity_hash_new() +hidden_identity_hash_new() { VALUE hash = rb_hash_new(); rb_funcall(hash, rb_intern("compare_by_identity"), 0); - RBASIC(hash)->klass = 0; + RBASIC(hash)->klass = 0; /* hide from ObjectSpace */ return hash; } void -rb_overlay_module(NODE *cref, VALUE klass, VALUE module) +rb_using_refinement(NODE *cref, VALUE klass, VALUE module) { VALUE iclass, c, superclass = klass; check_class_or_module(klass); Check_Type(module, T_MODULE); - if (NIL_P(cref->nd_omod)) { - cref->nd_omod = identity_hash_new(); + if (NIL_P(cref->nd_refinements)) { + cref->nd_refinements = hidden_identity_hash_new(); } else { if (cref->flags & NODE_FL_CREF_OMOD_SHARED) { - cref->nd_omod = rb_hash_dup(cref->nd_omod); + cref->nd_refinements = rb_hash_dup(cref->nd_refinements); cref->flags &= ~NODE_FL_CREF_OMOD_SHARED; } - if (!NIL_P(c = rb_hash_lookup(cref->nd_omod, klass))) { + if (!NIL_P(c = rb_hash_lookup(cref->nd_refinements, klass))) { superclass = c; while (c && TYPE(c) == T_ICLASS) { if (RBASIC(c)->klass == module) { - /* already overlaid module */ + /* already used refinement */ return; } c = RCLASS_SUPER(c); @@ -1086,7 +1086,7 @@ rb_overlay_module(NODE *cref, VALUE klass, VALUE module) RCLASS_REFINED_CLASS(c) = klass; module = RCLASS_SUPER(module); } - rb_hash_aset(cref->nd_omod, klass, iclass); + rb_hash_aset(cref->nd_refinements, klass, iclass); rb_clear_cache_by_class(klass); } @@ -1095,21 +1095,21 @@ using_module_i(VALUE klass, VALUE module, VALUE arg) { NODE *cref = (NODE *) arg; - rb_overlay_module(cref, klass, module); + rb_using_refinement(cref, klass, module); return ST_CONTINUE; } void rb_using_module(NODE *cref, VALUE module) { - ID id_overlaid_modules; - VALUE overlaid_modules; + ID id_refinements; + VALUE refinements; check_class_or_module(module); - CONST_ID(id_overlaid_modules, "__overlaid_modules__"); - overlaid_modules = rb_attr_get(module, id_overlaid_modules); - if (NIL_P(overlaid_modules)) return; - rb_hash_foreach(overlaid_modules, using_module_i, (VALUE) cref); + CONST_ID(id_refinements, "__refinements__"); + refinements = rb_attr_get(module, id_refinements); + if (NIL_P(refinements)) return; + rb_hash_foreach(refinements, using_module_i, (VALUE) cref); } /* @@ -1130,7 +1130,7 @@ rb_mod_using(VALUE self, VALUE module) CONST_ID(id_using_modules, "__using_modules__"); using_modules = rb_attr_get(self, id_using_modules); if (NIL_P(using_modules)) { - using_modules = identity_hash_new(); + using_modules = hidden_identity_hash_new(); rb_ivar_set(self, id_using_modules, using_modules); } rb_hash_aset(using_modules, module, Qtrue); @@ -1170,8 +1170,8 @@ refinement_module_include(int argc, VALUE *argv, VALUE module) while (RUBY_VM_VALID_CONTROL_FRAME_P(cfp, end_cfp)) { if (RUBY_VM_NORMAL_ISEQ_P(cfp->iseq) && (cref = rb_vm_get_cref(cfp->iseq, cfp->ep)) && - !NIL_P(cref->nd_omod) && - !NIL_P(c = rb_hash_lookup(cref->nd_omod, klass))) { + !NIL_P(cref->nd_refinements) && + !NIL_P(c = rb_hash_lookup(cref->nd_refinements, klass))) { while (argc--) { VALUE mod = argv[argc]; if (rb_class_inherited_p(module, mod)) { @@ -1200,17 +1200,17 @@ rb_mod_refine(VALUE module, VALUE klass) { NODE *cref = rb_vm_cref(); VALUE mod; - ID id_overlaid_modules, id_refined_class; - VALUE overlaid_modules; + ID id_refinements, id_refined_class; + VALUE refinements; check_class_or_module(klass); - CONST_ID(id_overlaid_modules, "__overlaid_modules__"); - overlaid_modules = rb_attr_get(module, id_overlaid_modules); - if (NIL_P(overlaid_modules)) { - overlaid_modules = identity_hash_new(); - rb_ivar_set(module, id_overlaid_modules, overlaid_modules); + CONST_ID(id_refinements, "__refinements__"); + refinements = rb_attr_get(module, id_refinements); + if (NIL_P(refinements)) { + refinements = hidden_identity_hash_new(); + rb_ivar_set(module, id_refinements, refinements); } - mod = rb_hash_lookup(overlaid_modules, klass); + mod = rb_hash_lookup(refinements, klass); if (NIL_P(mod)) { mod = rb_module_new(); CONST_ID(id_refined_class, "__refined_class__"); @@ -1219,8 +1219,8 @@ rb_mod_refine(VALUE module, VALUE klass) refinement_module_method_added, 1); rb_define_singleton_method(mod, "include", refinement_module_include, -1); - rb_overlay_module(cref, klass, mod); - rb_hash_aset(overlaid_modules, klass, mod); + rb_using_refinement(cref, klass, mod); + rb_hash_aset(refinements, klass, mod); } rb_mod_module_eval(0, NULL, mod); return mod; diff --git a/gc.c b/gc.c index 6301f6123d..735ae85baa 100644 --- a/gc.c +++ b/gc.c @@ -2733,7 +2733,7 @@ gc_mark_children(rb_objspace_t *objspace, VALUE ptr) break; case NODE_CREF: - gc_mark(objspace, obj->as.node.nd_omod); + gc_mark(objspace, obj->as.node.nd_refinements); gc_mark(objspace, (VALUE)obj->as.node.u1.node); ptr = (VALUE)obj->as.node.u3.node; goto again; diff --git a/insns.def b/insns.def index b331de5786..0afc2f799a 100644 --- a/insns.def +++ b/insns.def @@ -1027,7 +1027,7 @@ invokesuper if (me && me->def->type == VM_METHOD_TYPE_ISEQ && me->def->body.iseq == ip) { klass = RCLASS_SUPER(klass); - me = rb_method_entry_get_with_omod(Qnil, klass, id, &klass); + me = rb_method_entry_get_with_refinements(Qnil, klass, id, &klass); } CALL_METHOD(num, blockptr, flag, id, me, recv, klass); diff --git a/iseq.c b/iseq.c index 9313f6f80e..5bfad431d8 100644 --- a/iseq.c +++ b/iseq.c @@ -202,11 +202,11 @@ set_relation(rb_iseq_t *iseq, const VALUE parent) if (type == ISEQ_TYPE_TOP) { /* toplevel is private */ iseq->cref_stack = NEW_CREF(rb_cObject); - iseq->cref_stack->nd_omod = Qnil; + iseq->cref_stack->nd_refinements = Qnil; iseq->cref_stack->nd_visi = NOEX_PRIVATE; if (th->top_wrapper) { NODE *cref = NEW_CREF(th->top_wrapper); - cref->nd_omod = Qnil; + cref->nd_refinements = Qnil; cref->nd_visi = NOEX_PRIVATE; cref->nd_next = iseq->cref_stack; iseq->cref_stack = cref; @@ -214,7 +214,7 @@ set_relation(rb_iseq_t *iseq, const VALUE parent) } else if (type == ISEQ_TYPE_METHOD || type == ISEQ_TYPE_CLASS) { iseq->cref_stack = NEW_CREF(0); /* place holder */ - iseq->cref_stack->nd_omod = Qnil; + iseq->cref_stack->nd_refinements = Qnil; } else if (RTEST(parent)) { rb_iseq_t *piseq; @@ -1657,7 +1657,7 @@ rb_iseq_clone(VALUE iseqval, VALUE newcbase) } if (newcbase) { iseq1->cref_stack = NEW_CREF(newcbase); - iseq1->cref_stack->nd_omod = iseq0->cref_stack->nd_omod; + iseq1->cref_stack->nd_refinements = iseq0->cref_stack->nd_refinements; iseq1->cref_stack->nd_visi = iseq0->cref_stack->nd_visi; if (iseq0->cref_stack->nd_next) { iseq1->cref_stack->nd_next = iseq0->cref_stack->nd_next; diff --git a/method.h b/method.h index 9e7a615a6c..3d8a0e44ce 100644 --- a/method.h +++ b/method.h @@ -91,8 +91,8 @@ void rb_add_method_cfunc(VALUE klass, ID mid, VALUE (*func)(ANYARGS), int argc, rb_method_entry_t *rb_add_method(VALUE klass, ID mid, rb_method_type_t type, void *option, rb_method_flag_t noex); rb_method_entry_t *rb_method_entry(VALUE klass, ID id, VALUE *define_class_ptr); -rb_method_entry_t *rb_method_entry_get_with_omod(VALUE omod, VALUE klass, ID id, VALUE *define_class_ptr); -rb_method_entry_t *rb_method_entry_get_without_cache(VALUE klass, VALUE omod, ID id, VALUE *define_class_ptr); +rb_method_entry_t *rb_method_entry_get_with_refinements(VALUE refinements, VALUE klass, ID id, VALUE *define_class_ptr); +rb_method_entry_t *rb_method_entry_get_without_cache(VALUE klass, VALUE refinements, ID id, VALUE *define_class_ptr); rb_method_entry_t *rb_method_entry_set(VALUE klass, ID mid, const rb_method_entry_t *, rb_method_flag_t noex); int rb_method_entry_arity(const rb_method_entry_t *me); diff --git a/node.h b/node.h index 19e9129763..09186094ba 100644 --- a/node.h +++ b/node.h @@ -281,7 +281,7 @@ typedef struct RNode { #define nd_set_line(n,l) \ RNODE(n)->flags=((RNODE(n)->flags&~(-1<cfp); NODE *cref = NEW_CREF(klass); - cref->nd_omod = Qnil; + cref->nd_refinements = Qnil; cref->nd_visi = noex; if (blockptr) { @@ -1151,7 +1151,7 @@ vm_cref_push(rb_thread_t *th, VALUE klass, int noex, rb_block_t *blockptr) } /* TODO: why cref->nd_next is 1? */ if (cref->nd_next && cref->nd_next != (void *) 1 && - !NIL_P(cref->nd_next->nd_omod)) { + !NIL_P(cref->nd_next->nd_refinements)) { COPY_CREF_OMOD(cref, cref->nd_next); } diff --git a/vm_insnhelper.h b/vm_insnhelper.h index 25459f157a..11833386f2 100644 --- a/vm_insnhelper.h +++ b/vm_insnhelper.h @@ -171,8 +171,8 @@ enum vm_regan_acttype { /**********************************************************/ #define COPY_CREF_OMOD(c1, c2) do { \ - (c1)->nd_omod = (c2)->nd_omod; \ - if (!NIL_P((c2)->nd_omod)) { \ + (c1)->nd_refinements = (c2)->nd_refinements; \ + if (!NIL_P((c2)->nd_refinements)) { \ (c1)->flags |= NODE_FL_CREF_OMOD_SHARED; \ (c2)->flags |= NODE_FL_CREF_OMOD_SHARED; \ } \ diff --git a/vm_method.c b/vm_method.c index 51724bc248..fb656b3e8b 100644 --- a/vm_method.c +++ b/vm_method.c @@ -21,7 +21,7 @@ struct cache_entry { /* method hash table. */ VALUE filled_version; /* filled state version */ ID mid; /* method's id */ VALUE klass; /* receiver's class */ - VALUE omod; /* overlay modules */ + VALUE refinements; /* refinements */ rb_method_entry_t *me; VALUE defined_class; }; @@ -405,16 +405,17 @@ lookup_method_table(VALUE klass, ID id, st_data_t *body) } static inline rb_method_entry_t* -search_method_with_omod(VALUE klass, ID id, VALUE omod, VALUE *defined_class_ptr) +search_method_with_refinements(VALUE klass, ID id, VALUE refinements, + VALUE *defined_class_ptr) { st_data_t body; VALUE iclass, skipped_class = Qnil; for (body = 0; klass; klass = RCLASS_SUPER(klass)) { if (klass != skipped_class) { - iclass = rb_hash_lookup(omod, klass); + iclass = rb_hash_lookup(refinements, klass); if (NIL_P(iclass) && BUILTIN_TYPE(klass) == T_ICLASS) { - iclass = rb_hash_lookup(omod, RBASIC(klass)->klass); + iclass = rb_hash_lookup(refinements, RBASIC(klass)->klass); if (!NIL_P(iclass)) iclass = copy_refinement_iclass(iclass, klass); } @@ -432,7 +433,7 @@ search_method_with_omod(VALUE klass, ID id, VALUE omod, VALUE *defined_class_ptr } static inline rb_method_entry_t* -search_method_without_omod(VALUE klass, ID id, VALUE *defined_class_ptr) +search_method_without_refinements(VALUE klass, ID id, VALUE *defined_class_ptr) { st_data_t body; @@ -446,13 +447,14 @@ search_method_without_omod(VALUE klass, ID id, VALUE *defined_class_ptr) } static rb_method_entry_t* -search_method(VALUE klass, ID id, VALUE omod, VALUE *defined_class_ptr) +search_method(VALUE klass, ID id, VALUE refinements, VALUE *defined_class_ptr) { - if (NIL_P(omod)) { - return search_method_without_omod(klass, id, defined_class_ptr); + if (NIL_P(refinements)) { + return search_method_without_refinements(klass, id, defined_class_ptr); } else { - return search_method_with_omod(klass, id, omod, defined_class_ptr); + return search_method_with_refinements(klass, id, refinements, + defined_class_ptr); } } @@ -463,18 +465,19 @@ search_method(VALUE klass, ID id, VALUE omod, VALUE *defined_class_ptr) * rb_method_entry() simply. */ rb_method_entry_t * -rb_method_entry_get_without_cache(VALUE klass, VALUE omod, ID id, +rb_method_entry_get_without_cache(VALUE klass, VALUE refinements, ID id, VALUE *defined_class_ptr) { VALUE defined_class; - rb_method_entry_t *me = search_method(klass, id, omod, &defined_class); + rb_method_entry_t *me = search_method(klass, id, refinements, + &defined_class); if (ruby_running) { struct cache_entry *ent; - ent = cache + EXPR1(klass, omod, id); + ent = cache + EXPR1(klass, refinements, id); ent->filled_version = GET_VM_STATE_VERSION(); ent->klass = klass; - ent->omod = omod; + ent->refinements = refinements; ent->defined_class = defined_class; if (UNDEFINED_METHOD_ENTRY_P(me)) { @@ -494,22 +497,23 @@ rb_method_entry_get_without_cache(VALUE klass, VALUE omod, ID id, } rb_method_entry_t * -rb_method_entry_get_with_omod(VALUE omod, VALUE klass, ID id, - VALUE *defined_class_ptr) +rb_method_entry_get_with_refinements(VALUE refinements, VALUE klass, ID id, + VALUE *defined_class_ptr) { #if OPT_GLOBAL_METHOD_CACHE struct cache_entry *ent; - ent = cache + EXPR1(klass, omod, id); + ent = cache + EXPR1(klass, refinements, id); if (ent->filled_version == GET_VM_STATE_VERSION() && - ent->mid == id && ent->klass == klass && ent->omod == omod) { + ent->mid == id && ent->klass == klass && + ent->refinements == refinements) { if (defined_class_ptr) *defined_class_ptr = ent->defined_class; return ent->me; } #endif - return rb_method_entry_get_without_cache(klass, omod, id, + return rb_method_entry_get_without_cache(klass, refinements, id, defined_class_ptr); } @@ -517,12 +521,13 @@ rb_method_entry_t * rb_method_entry(VALUE klass, ID id, VALUE *defined_class_ptr) { NODE *cref = rb_vm_cref(); - VALUE omod = Qnil; + VALUE refinements = Qnil; - if (cref && !NIL_P(cref->nd_omod)) { - omod = cref->nd_omod; + if (cref && !NIL_P(cref->nd_refinements)) { + refinements = cref->nd_refinements; } - return rb_method_entry_get_with_omod(omod, klass, id, defined_class_ptr); + return rb_method_entry_get_with_refinements(refinements, klass, id, + defined_class_ptr); } static void @@ -712,8 +717,8 @@ rb_undef(VALUE klass, ID id) { rb_method_entry_t *me; NODE *cref = rb_vm_cref(); - VALUE omod = Qnil; - void rb_overlay_module(NODE *cref, VALUE klass, VALUE module); + VALUE refinements = Qnil; + void rb_using_refinement(NODE *cref, VALUE klass, VALUE module); if (NIL_P(klass)) { rb_raise(rb_eTypeError, "no class to undef method"); @@ -729,10 +734,10 @@ rb_undef(VALUE klass, ID id) rb_warn("undefining `%s' may cause serious problems", rb_id2name(id)); } - if (cref && !NIL_P(cref->nd_omod)) { - omod = cref->nd_omod; + if (cref && !NIL_P(cref->nd_refinements)) { + refinements = cref->nd_refinements; } - me = search_method(klass, id, omod, 0); + me = search_method(klass, id, refinements, 0); if (UNDEFINED_METHOD_ENTRY_P(me)) { const char *s0 = " class"; @@ -755,7 +760,7 @@ rb_undef(VALUE klass, ID id) if (!RTEST(rb_class_inherited_p(klass, me->klass))) { VALUE mod = rb_module_new(); - rb_overlay_module(cref, klass, mod); + rb_using_refinement(cref, klass, mod); klass = mod; } rb_add_method(klass, id, VM_METHOD_TYPE_UNDEF, 0, NOEX_PUBLIC);