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
Handle running out of shapes in Object#dup
#8799
Merged
peterzhu2118
merged 5 commits into
ruby:master
from
Shopify:update-rb_obj_copy_ivar-assertion
Oct 31, 2023
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9c77c93
Handle running out of shapes in `Object#dup`
byroot 6e7b7ea
Handle SHAPE_TOO_COMPLEX in `generic_ivar_set`
byroot 73d074e
Fix "too complex" iv sets on generic ivar objects
tenderlove fcfff26
Create table for too complex generic variables
peterzhu2118 9b166d8
Add ST table to gen_ivtbl for complex shapes
peterzhu2118 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -184,6 +184,32 @@ def test_removing_when_too_many_ivs_on_module | |
assert_empty obj.instance_variables | ||
end | ||
|
||
def test_too_complex_geniv | ||
assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}") | ||
begin; | ||
class TooComplex < Hash | ||
attr_reader :very_unique | ||
end | ||
|
||
obj = Object.new | ||
i = 0 | ||
while RubyVM::Shape.shapes_available > 0 | ||
obj.instance_variable_set(:"@a#{i}", 1) | ||
i += 1 | ||
end | ||
|
||
(RubyVM::Shape::SHAPE_MAX_VARIATIONS * 2).times do | ||
TooComplex.new.instance_variable_set(:"@unique_#{_1}", 1) | ||
end | ||
|
||
tc = TooComplex.new | ||
tc.instance_variable_set(:@very_unique, 3) | ||
tc.instance_variable_set(:@very_unique2, 4) | ||
assert_equal 3, tc.instance_variable_get(:@very_unique) | ||
assert_equal 4, tc.instance_variable_get(:@very_unique2) | ||
end; | ||
end | ||
|
||
def test_use_all_shapes_then_freeze | ||
assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}") | ||
begin; | ||
|
@@ -226,6 +252,52 @@ def initialize | |
end; | ||
end | ||
|
||
def test_run_out_of_shape_generic_ivar_set | ||
assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}") | ||
begin; | ||
class TooComplex < Hash | ||
end | ||
|
||
# Try to run out of shapes | ||
o = Object.new | ||
i = 0 | ||
while RubyVM::Shape.shapes_available > 0 | ||
o.instance_variable_set(:"@i#{i}", 1) | ||
i += 1 | ||
end | ||
|
||
tc = TooComplex.new | ||
tc.instance_variable_set(:@a, 1) | ||
tc.instance_variable_set(:@b, 2) | ||
end; | ||
end | ||
|
||
def test_run_out_of_shape_rb_obj_copy_ivar | ||
assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}") | ||
begin; | ||
class A | ||
def initialize | ||
init # Avoid right sizing | ||
end | ||
|
||
def init | ||
@a = @b = @c = @d = @e = @f = 1 | ||
end | ||
end | ||
|
||
a = A.new | ||
|
||
o = Object.new | ||
i = 0 | ||
while RubyVM::Shape.shapes_available > 1 | ||
o.instance_variable_set(:"@i#{i}", 1) | ||
i += 1 | ||
end | ||
|
||
a.dup | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So here we create a first instance of Then after running out of shapes we dup it, Ruby tries to rebuild the correct shape tree and run out of shapes in the middle of the process. |
||
end; | ||
end | ||
|
||
def test_use_all_shapes_module | ||
assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}") | ||
begin; | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found another crash on our CI, so I pushed a second commit to handle it.
I'm running yet another build to see if there's other cases we don't handle.