From 27adf5321eabb588ecf20a0c3879e931a7345151 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sat, 1 Oct 2022 15:58:47 +0900 Subject: [PATCH] Add macros for assertions --- vm_insnhelper.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/vm_insnhelper.c b/vm_insnhelper.c index a662de468d..98138f5922 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -1117,6 +1117,11 @@ fill_ivar_cache(const rb_iseq_t *iseq, IVC ic, const struct rb_callcache *cc, in } } +#define ractor_incidental_shareable_p(cond, val) \ + (!(cond) || rb_ractor_shareable_p(val)) +#define ractor_object_incidental_shareable_p(obj, val) \ + ractor_incidental_shareable_p(rb_ractor_shareable_p(obj), val) + ALWAYS_INLINE(static VALUE vm_getivar(VALUE, ID, const rb_iseq_t *, IVC, const struct rb_callcache *, int)); static inline VALUE vm_getivar(VALUE obj, ID id, const rb_iseq_t *iseq, IVC ic, const struct rb_callcache *cc, int is_attr) @@ -1138,7 +1143,7 @@ vm_getivar(VALUE obj, ID id, const rb_iseq_t *iseq, IVC ic, const struct rb_call LIKELY(index < ROBJECT_NUMIV(obj))) { val = ROBJECT_IVPTR(obj)[index]; - VM_ASSERT(rb_ractor_shareable_p(obj) ? rb_ractor_shareable_p(val) : true); + VM_ASSERT(ractor_object_incidental_shareable_p(obj, val)); } else if (FL_TEST_RAW(obj, FL_EXIVAR)) { val = rb_ivar_generic_lookup_with_index(obj, id, index); @@ -1159,7 +1164,7 @@ vm_getivar(VALUE obj, ID id, const rb_iseq_t *iseq, IVC ic, const struct rb_call if (ent->index < ROBJECT_NUMIV(obj)) { val = ROBJECT_IVPTR(obj)[ent->index]; - VM_ASSERT(rb_ractor_shareable_p(obj) ? rb_ractor_shareable_p(val) : true); + VM_ASSERT(ractor_object_incidental_shareable_p(obj, val)); } } } @@ -5042,7 +5047,7 @@ static inline bool vm_inlined_ic_hit_p(VALUE flags, VALUE value, const rb_cref_t *ic_cref, const VALUE *reg_ep) { if ((flags & IMEMO_CONST_CACHE_SHAREABLE) || rb_ractor_main_p()) { - VM_ASSERT((flags & IMEMO_CONST_CACHE_SHAREABLE) ? rb_ractor_shareable_p(value) : true); + VM_ASSERT(ractor_incidental_shareable_p(flags & IMEMO_CONST_CACHE_SHAREABLE, value)); return (ic_cref == NULL || // no need to check CREF ic_cref == vm_get_cref(reg_ep));