Skip to content

Commit

Permalink
[Feature #19579] Remove !USE_RVARGC code (#7655)
Browse files Browse the repository at this point in the history
Remove !USE_RVARGC code

[Feature #19579]

The Variable Width Allocation feature was turned on by default in Ruby
3.2. Since then, we haven't received bug reports or backports to the
non-Variable Width Allocation code paths, so we assume that nobody is
using it. We also don't plan on maintaining the non-Variable Width
Allocation code, so we are going to remove it.
  • Loading branch information
peterzhu2118 committed Apr 4, 2023
1 parent 1190ec6 commit 1da2e7f
Show file tree
Hide file tree
Showing 18 changed files with 17 additions and 320 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/compilers.yml
Expand Up @@ -175,8 +175,6 @@ jobs:
# - { name: USE_THREAD_CACHE=0, env: { cppflags: '-DUSE_THREAD_CACHE=0' } }
# - { name: USE_TRANSIENT_HEAP=0, env: { cppflags: '-DUSE_TRANSIENT_HEAP=0' } }
- { name: USE_RUBY_DEBUG_LOG=1, env: { cppflags: '-DUSE_RUBY_DEBUG_LOG=1' } }
- { name: USE_RVARGC=0, env: { cppflags: '-DUSE_RVARGC=0' } }
# - { name: USE_RVARGC=1, env: { cppflags: '-DUSE_RVARGC=1' } }
# - { name: USE_DEBUG_COUNTER, env: { cppflags: '-DUSE_DEBUG_COUNTER=1', RUBY_DEBUG_COUNTER_DISABLE: '1' } }

- { name: DEBUG_FIND_TIME_NUMGUESS, env: { cppflags: '-DDEBUG_FIND_TIME_NUMGUESS' } }
Expand Down
22 changes: 0 additions & 22 deletions array.c
Expand Up @@ -47,13 +47,8 @@ VALUE rb_cArray;
* 2: RARRAY_SHARED_FLAG (equal to ELTS_SHARED)
* The array is shared. The buffer this array points to is owned by
* another array (the shared root).
* if USE_RVARGC
* 3-9: RARRAY_EMBED_LEN
* The length of the array when RARRAY_EMBED_FLAG is set.
* else
* 3-4: RARRAY_EMBED_LEN
* The length of the array when RARRAY_EMBED_FLAG is set.
* endif
* 12: RARRAY_SHARED_ROOT_FLAG
* The array is a shared root that does reference counting. The buffer
* this array points to is owned by this array but may be pointed to
Expand Down Expand Up @@ -188,13 +183,9 @@ ARY_SET(VALUE a, long i, VALUE v)
static long
ary_embed_capa(VALUE ary)
{
#if USE_RVARGC
size_t size = rb_gc_obj_slot_size(ary) - offsetof(struct RArray, as.ary);
assert(size % sizeof(VALUE) == 0);
return size / sizeof(VALUE);
#else
return RARRAY_EMBED_LEN_MAX;
#endif
}

static size_t
Expand All @@ -206,11 +197,7 @@ ary_embed_size(long capa)
static bool
ary_embeddable_p(long capa)
{
#if USE_RVARGC
return rb_gc_size_allocatable_p(ary_embed_size(capa));
#else
return capa <= RARRAY_EMBED_LEN_MAX;
#endif
}

bool
Expand Down Expand Up @@ -791,9 +778,6 @@ ary_alloc_embed(VALUE klass, long capa)
{
size_t size = ary_embed_size(capa);
assert(rb_gc_size_allocatable_p(size));
#if !USE_RVARGC
assert(size <= sizeof(struct RArray));
#endif
RVARGC_NEWOBJ_OF(ary, struct RArray, klass,
T_ARRAY | RARRAY_EMBED_FLAG | (RGENGC_WB_PROTECTED_ARRAY ? FL_WB_PROTECTED : 0),
size);
Expand Down Expand Up @@ -906,9 +890,6 @@ ec_ary_alloc_embed(rb_execution_context_t *ec, VALUE klass, long capa)
{
size_t size = ary_embed_size(capa);
assert(rb_gc_size_allocatable_p(size));
#if !USE_RVARGC
assert(size <= sizeof(struct RArray));
#endif
RB_RVARGC_EC_NEWOBJ_OF(ec, ary, struct RArray, klass,
T_ARRAY | RARRAY_EMBED_FLAG | (RGENGC_WB_PROTECTED_ARRAY ? FL_WB_PROTECTED : 0),
size);
Expand Down Expand Up @@ -1033,7 +1014,6 @@ rb_ary_memsize(VALUE ary)
static VALUE
ary_make_shared(VALUE ary)
{
assert(USE_RVARGC || !ARY_EMBED_P(ary));
ary_verify(ary);

if (ARY_SHARED_P(ary)) {
Expand Down Expand Up @@ -4741,7 +4721,6 @@ rb_ary_replace(VALUE copy, VALUE orig)
ary_memcpy(copy, 0, RARRAY_LEN(orig), RARRAY_CONST_PTR_TRANSIENT(orig));
ARY_SET_EMBED_LEN(copy, RARRAY_LEN(orig));
}
#if USE_RVARGC
/* orig is embedded but copy does not have enough space to embed the
* contents of orig. */
else if (ARY_EMBED_P(orig)) {
Expand All @@ -4757,7 +4736,6 @@ rb_ary_replace(VALUE copy, VALUE orig)
// bad state from the edits above.
ary_memcpy(copy, 0, len, RARRAY_CONST_PTR_TRANSIENT(orig));
}
#endif
/* Otherwise, orig is on heap and copy does not have enough space to embed
* the contents of orig. */
else {
Expand Down
6 changes: 0 additions & 6 deletions debug.c
Expand Up @@ -53,14 +53,8 @@ const union {
rb_econv_result_t econv_result;
enum ruby_preserved_encindex encoding_index;
enum ruby_robject_flags robject_flags;
#if !USE_RVARGC
enum ruby_robject_consts robject_consts;
#endif
enum ruby_rmodule_flags rmodule_flags;
enum ruby_rstring_flags rstring_flags;
#if !USE_RVARGC
enum ruby_rstring_consts rstring_consts;
#endif
enum ruby_rarray_flags rarray_flags;
enum ruby_rarray_consts rarray_consts;
enum {
Expand Down
9 changes: 0 additions & 9 deletions ext/-test-/string/cstr.c
Expand Up @@ -62,12 +62,7 @@ bug_str_unterminated_substring(VALUE str, VALUE vbeg, VALUE vlen)
if (RSTRING_LEN(str) < beg + len) rb_raise(rb_eIndexError, "end: %ld", beg + len);
str = rb_str_new_shared(str);
if (STR_EMBED_P(str)) {
#if USE_RVARGC
RSTRING(str)->as.embed.len = (short)len;
#else
RSTRING(str)->basic.flags &= ~RSTRING_EMBED_LEN_MASK;
RSTRING(str)->basic.flags |= len << RSTRING_EMBED_LEN_SHIFT;
#endif
memmove(RSTRING(str)->as.embed.ary, RSTRING(str)->as.embed.ary + beg, len);
}
else {
Expand Down Expand Up @@ -116,11 +111,7 @@ bug_str_s_cstr_noembed(VALUE self, VALUE str)
Check_Type(str, T_STRING);
FL_SET((str2), STR_NOEMBED);
memcpy(buf, RSTRING_PTR(str), capacity);
#if USE_RVARGC
RBASIC(str2)->flags &= ~(STR_SHARED | FL_USER5 | FL_USER6);
#else
RBASIC(str2)->flags &= ~RSTRING_EMBED_LEN_MASK;
#endif
RSTRING(str2)->as.heap.aux.capa = capacity;
RSTRING(str2)->as.heap.ptr = buf;
RSTRING(str2)->as.heap.len = RSTRING_LEN(str);
Expand Down

0 comments on commit 1da2e7f

Please sign in to comment.