Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions class.c
Original file line number Diff line number Diff line change
Expand Up @@ -868,10 +868,7 @@ rb_class_new(VALUE super)
rb_check_inheritable(super);
VALUE klass = rb_class_boot(super);

if (super != rb_cObject && super != rb_cBasicObject) {
RCLASS_SET_MAX_IV_COUNT(klass, RCLASS_MAX_IV_COUNT(super));
}

RCLASS_SET_MAX_IV_COUNT(klass, RCLASS_MAX_IV_COUNT(super));
RUBY_ASSERT(getenv("RUBY_BOX") || RCLASS_PRIME_CLASSEXT_WRITABLE_P(klass));

return klass;
Expand Down Expand Up @@ -1418,8 +1415,10 @@ Init_class_hierarchy(void)
rb_cBasicObject = boot_defclass("BasicObject", 0);
RCLASS_SET_ALLOCATOR(rb_cBasicObject, rb_class_allocate_instance);
FL_SET_RAW(rb_cBasicObject, RCLASS_ALLOCATOR_DEFINED);
RCLASS_SET_EXPECT_NO_IVAR(rb_cBasicObject);

rb_cObject = boot_defclass("Object", rb_cBasicObject);
rb_vm_register_global_object(rb_cObject);
RCLASS_SET_EXPECT_NO_IVAR(rb_cObject);

/* resolve class name ASAP for order-independence */
rb_set_class_path_string(rb_cObject, rb_cObject, rb_fstring_lit("Object"));
Expand Down
7 changes: 7 additions & 0 deletions doc/_regexp.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,13 @@ Regexp in extended mode:
re = /#{pattern}/x
re.match('MCMXLIII') # => #<MatchData "MCMXLIII" 1:"CM" 2:"XL" 3:"III">

Comments in regexp literals cannot include unescaped terminator
characters:

/
foo # the following slash \/ must be escaped
/x

=== Interpolation Mode

Modifier +o+ means that the first time a literal regexp with interpolations
Expand Down
11 changes: 0 additions & 11 deletions gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -3480,17 +3480,6 @@ rb_gc_mark_children(void *objspace, VALUE obj)
gc_mark_internal(ptr[i]);
}
}

attr_index_t fields_count = (attr_index_t)len;
if (fields_count) {
VALUE klass = RBASIC_CLASS(obj);

// Increment max_iv_count if applicable, used to determine size pool allocation
if (RCLASS_MAX_IV_COUNT(klass) < fields_count) {
RCLASS_SET_MAX_IV_COUNT(klass, fields_count);
}
}

break;
}

Expand Down
39 changes: 14 additions & 25 deletions imemo.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,44 +123,34 @@ rb_imemo_memo_new_value(VALUE a, VALUE b, VALUE c)
return memo;
}

static VALUE
imemo_fields_new(VALUE owner, size_t capa, bool shareable)
VALUE
rb_imemo_fields_new(VALUE owner, shape_id_t shape_id, bool shareable)
{
size_t capa = RSHAPE_CAPACITY(shape_id);
size_t embedded_size = offsetof(struct rb_fields, as.embed) + capa * sizeof(VALUE);
VALUE fields;
if (rb_gc_size_allocatable_p(embedded_size)) {
VALUE fields = rb_imemo_new(imemo_fields, owner, embedded_size, shareable);
RUBY_ASSERT(IMEMO_TYPE_P(fields, imemo_fields));
return fields;
fields = rb_imemo_new(imemo_fields, owner, embedded_size, shareable);
}
else {
VALUE fields = rb_imemo_new(imemo_fields, owner, sizeof(struct rb_fields), shareable);
fields = rb_imemo_new(imemo_fields, owner, sizeof(struct rb_fields), shareable);
IMEMO_OBJ_FIELDS(fields)->as.external.ptr = ALLOC_N(VALUE, capa);
FL_SET_RAW(fields, OBJ_FIELD_HEAP);
return fields;
}
RBASIC_SET_SHAPE_ID(fields, shape_id);
return fields;
}

VALUE
rb_imemo_fields_new(VALUE owner, size_t capa, bool shareable)
{
return imemo_fields_new(owner, capa, shareable);
}

static VALUE
imemo_fields_new_complex(VALUE owner, size_t capa, bool shareable)
rb_imemo_fields_new_complex(VALUE owner, shape_id_t shape_id, size_t capa, bool shareable)
{
VALUE fields = rb_imemo_new(imemo_fields, owner, sizeof(struct rb_fields), shareable);
IMEMO_OBJ_FIELDS(fields)->as.complex.table = st_init_numtable_with_size(capa);
FL_SET_RAW(fields, OBJ_FIELD_HEAP);
RBASIC_SET_SHAPE_ID(fields, shape_id);
return fields;
}

VALUE
rb_imemo_fields_new_complex(VALUE owner, size_t capa, bool shareable)
{
return imemo_fields_new_complex(owner, capa, shareable);
}

static int
imemo_fields_trigger_wb_i(st_data_t key, st_data_t value, st_data_t arg)
{
Expand All @@ -177,11 +167,12 @@ imemo_fields_complex_wb_i(st_data_t key, st_data_t value, st_data_t arg)
}

VALUE
rb_imemo_fields_new_complex_tbl(VALUE owner, st_table *tbl, bool shareable)
rb_imemo_fields_new_complex_tbl(VALUE owner, shape_id_t shape_id, st_table *tbl, bool shareable)
{
VALUE fields = rb_imemo_new(imemo_fields, owner, sizeof(struct rb_fields), shareable);
IMEMO_OBJ_FIELDS(fields)->as.complex.table = tbl;
FL_SET_RAW(fields, OBJ_FIELD_HEAP);
RBASIC_SET_SHAPE_ID(fields, shape_id);
st_foreach(tbl, imemo_fields_trigger_wb_i, (st_data_t)fields);
return fields;
}
Expand All @@ -196,16 +187,14 @@ rb_imemo_fields_clone(VALUE fields_obj)
st_table *src_table = rb_imemo_fields_complex_tbl(fields_obj);

st_table *dest_table = xcalloc(1, sizeof(st_table));
clone = rb_imemo_fields_new_complex_tbl(rb_imemo_fields_owner(fields_obj), dest_table, false /* TODO: check */);
clone = rb_imemo_fields_new_complex_tbl(rb_imemo_fields_owner(fields_obj), shape_id, dest_table, false /* TODO: check */);

st_replace(dest_table, src_table);
RBASIC_SET_SHAPE_ID(clone, shape_id);

st_foreach(dest_table, imemo_fields_complex_wb_i, (st_data_t)clone);
}
else {
clone = imemo_fields_new(rb_imemo_fields_owner(fields_obj), RSHAPE_CAPACITY(shape_id), false /* TODO: check */);
RBASIC_SET_SHAPE_ID(clone, shape_id);
clone = rb_imemo_fields_new(rb_imemo_fields_owner(fields_obj), shape_id, false /* TODO: check */);
VALUE *fields = rb_imemo_fields_ptr(clone);
attr_index_t fields_count = RSHAPE_LEN(shape_id);
MEMCPY(fields, rb_imemo_fields_ptr(fields_obj), VALUE, fields_count);
Expand Down
18 changes: 17 additions & 1 deletion internal/class.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ struct rb_classext_struct {
bool iclass_is_origin : 1;
bool iclass_origin_shared_mtbl : 1;
bool superclasses_with_self : 1;
bool expect_no_ivar : 1;
VALUE classpath;
};
typedef struct rb_classext_struct rb_classext_t;
Expand Down Expand Up @@ -514,7 +515,7 @@ RCLASS_WRITABLE_ENSURE_FIELDS_OBJ(VALUE obj)
RUBY_ASSERT(RB_TYPE_P(obj, RUBY_T_CLASS) || RB_TYPE_P(obj, RUBY_T_MODULE));
rb_classext_t *ext = RCLASS_EXT_WRITABLE(obj);
if (!ext->fields_obj) {
RB_OBJ_WRITE(obj, &ext->fields_obj, rb_imemo_fields_new(obj, 1, true));
RB_OBJ_WRITE(obj, &ext->fields_obj, rb_imemo_fields_new(obj, ROOT_SHAPE_ID, true));
}
return ext->fields_obj;
}
Expand Down Expand Up @@ -731,9 +732,24 @@ RCLASS_SET_ATTACHED_OBJECT(VALUE klass, VALUE attached_object)
static inline void
RCLASS_SET_MAX_IV_COUNT(VALUE klass, attr_index_t count)
{
RUBY_ASSERT(klass != rb_cObject);
RUBY_ASSERT(klass != rb_cBasicObject);

RCLASS_MAX_IV_COUNT(klass) = count;
}

static inline void
RCLASS_SET_EXPECT_NO_IVAR(VALUE klass)
{
RCLASS_EXT_PRIME(klass)->expect_no_ivar = true;
}

static inline bool
RCLASS_EXPECT_NO_IVAR(VALUE klass)
{
return RCLASS_EXT_PRIME(klass)->expect_no_ivar;
}

static inline void
RCLASS_SET_CLONED(VALUE klass, bool cloned)
{
Expand Down
6 changes: 3 additions & 3 deletions internal/imemo.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,9 @@ STATIC_ASSERT(imemo_fields_complex_offset, offsetof(struct RObject, as.heap.fiel

#define IMEMO_OBJ_FIELDS(fields) ((struct rb_fields *)fields)

VALUE rb_imemo_fields_new(VALUE owner, size_t capa, bool shareable);
VALUE rb_imemo_fields_new_complex(VALUE owner, size_t capa, bool shareable);
VALUE rb_imemo_fields_new_complex_tbl(VALUE owner, st_table *tbl, bool shareable);
VALUE rb_imemo_fields_new(VALUE owner, /* shape_id_t */ uint32_t shape_id, bool shareable);
VALUE rb_imemo_fields_new_complex(VALUE owner, /* shape_id_t */ uint32_t shape_id, size_t capa, bool shareable);
VALUE rb_imemo_fields_new_complex_tbl(VALUE owner, /* shape_id_t */ uint32_t shape_id, st_table *tbl, bool shareable);
VALUE rb_imemo_fields_clone(VALUE fields_obj);
void rb_imemo_fields_clear(VALUE fields_obj);

Expand Down
1 change: 1 addition & 0 deletions object.c
Original file line number Diff line number Diff line change
Expand Up @@ -2224,6 +2224,7 @@ rb_class_initialize(int argc, VALUE *argv, VALUE klass)
}
}
rb_class_set_super(klass, super);
RCLASS_SET_MAX_IV_COUNT(klass, RCLASS_MAX_IV_COUNT(super));
RCLASS_SET_ALLOCATOR(klass, RCLASS_ALLOCATOR(super));
rb_make_metaclass(klass, RBASIC(super)->klass);
rb_class_inherited(super, klass);
Expand Down
Loading