Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix removing ivars from classes and modules #7314

Merged
merged 2 commits into from Feb 15, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion shape.c
Expand Up @@ -238,7 +238,9 @@ remove_shape_recursive(VALUE obj, ID id, rb_shape_t * shape, VALUE * removed)
// has the same attributes as this shape.
if (new_parent) {
bool dont_care;
rb_shape_t * new_child = get_next_shape_internal(new_parent, shape->edge_name, shape->type, &dont_care, true, false);
enum ruby_value_type type = BUILTIN_TYPE(obj);
bool new_shape_necessary = type != T_OBJECT;
rb_shape_t * new_child = get_next_shape_internal(new_parent, shape->edge_name, shape->type, &dont_care, true, new_shape_necessary);
new_child->capacity = shape->capacity;
if (new_child->type == SHAPE_IVAR) {
move_iv(obj, id, shape->next_iv_index - 1, new_child->next_iv_index - 1);
Expand Down
26 changes: 26 additions & 0 deletions test/ruby/test_shapes.rb
Expand Up @@ -108,6 +108,32 @@ def test_too_many_ivs_on_class
assert_false RubyVM::Shape.of(obj).too_complex?
end

def test_removing_when_too_many_ivs_on_class
obj = Class.new

(RubyVM::Shape::SHAPE_MAX_NUM_IVS + 2).times do
obj.instance_variable_set(:"@a#{_1}", 1)
end
(RubyVM::Shape::SHAPE_MAX_NUM_IVS + 2).times do
obj.remove_instance_variable(:"@a#{_1}")
end

assert_empty obj.instance_variables
end

def test_removing_when_too_many_ivs_on_module
obj = Module.new

(RubyVM::Shape::SHAPE_MAX_NUM_IVS + 2).times do
obj.instance_variable_set(:"@a#{_1}", 1)
end
(RubyVM::Shape::SHAPE_MAX_NUM_IVS + 2).times do
obj.remove_instance_variable(:"@a#{_1}")
end

assert_empty obj.instance_variables
end

def test_too_complex_ractor
assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}")
begin;
Expand Down