Skip to content

Commit 2a94986

Browse files
committed
[GR-19220] Option to add chaos to data representations to stress specialization code paths (#2368)
PullRequest: truffleruby/2799
2 parents e72e607 + 8d07b0b commit 2a94986

File tree

16 files changed

+439
-236
lines changed

16 files changed

+439
-236
lines changed

spec/truffle/array/append_spec.rb

Lines changed: 81 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -23,102 +23,104 @@ def storage(ary)
2323
storage(ary).should == "empty"
2424
end
2525

26-
it "supports transitions from null storage" do
27-
ary = [] << 1
28-
ary.should == [1]
29-
storage(ary).should == "int[]"
30-
31-
ary = [] << @long
32-
ary.should == [@long]
33-
storage(ary).should == "long[]"
34-
35-
ary = [] << 1.33
36-
ary.should == [1.33]
37-
storage(ary).should == "double[]"
38-
39-
o = Object.new
40-
ary = [] << o
41-
ary.should == [o]
42-
storage(ary).should == "Object[]"
43-
end
26+
guard -> { !Truffle::Boot.get_option('chaos-data') } do
27+
it "supports transitions from null storage" do
28+
ary = [] << 1
29+
ary.should == [1]
30+
storage(ary).should == "int[]"
4431

45-
it "supports adding the same type" do
46-
ary = [1] << 2
47-
ary.should == [1, 2]
48-
storage(ary).should == "int[]"
32+
ary = [] << @long
33+
ary.should == [@long]
34+
storage(ary).should == "long[]"
4935

50-
ary = [@long] << @long+1
51-
ary.should == [@long, @long+1]
52-
storage(ary).should == "long[]"
36+
ary = [] << 1.33
37+
ary.should == [1.33]
38+
storage(ary).should == "double[]"
5339

54-
ary = [3.14] << 3.15
55-
ary.should == [3.14, 3.15]
56-
storage(ary).should == "double[]"
40+
o = Object.new
41+
ary = [] << o
42+
ary.should == [o]
43+
storage(ary).should == "Object[]"
44+
end
5745

58-
a, b = Object.new, Object.new
59-
ary = [a] << b
60-
ary.should == [a, b]
61-
storage(ary).should == "Object[]"
62-
end
46+
it "supports adding the same type" do
47+
ary = [1] << 2
48+
ary.should == [1, 2]
49+
storage(ary).should == "int[]"
6350

64-
it "supports long[] << int" do
65-
long_ary = [@long, @long+1, @long+2]
66-
storage(long_ary).should == "long[]"
51+
ary = [@long] << @long+1
52+
ary.should == [@long, @long+1]
53+
storage(ary).should == "long[]"
6754

68-
long_ary << 1
69-
long_ary.should == [@long, @long+1, @long+2, 1]
70-
storage(long_ary).should == "long[]"
71-
end
55+
ary = [3.14] << 3.15
56+
ary.should == [3.14, 3.15]
57+
storage(ary).should == "double[]"
7258

73-
it "supports int[] << long and goes to long[]" do
74-
# Make sure long[] is chosen even if there was a int[] << Object before
75-
2.times do |i|
76-
setup = (i == 0)
59+
a, b = Object.new, Object.new
60+
ary = [a] << b
61+
ary.should == [a, b]
62+
storage(ary).should == "Object[]"
63+
end
7764

78-
ary = [0, 1, 2]
79-
storage(ary).should == "int[]"
65+
it "supports long[] << int" do
66+
long_ary = [@long, @long+1, @long+2]
67+
storage(long_ary).should == "long[]"
8068

81-
obj = (i == 0) ? Object.new : @long
82-
ary << obj
83-
ary.should == [0, 1, 2, obj]
84-
storage(ary).should == (setup ? "Object[]" : "long[]")
69+
long_ary << 1
70+
long_ary.should == [@long, @long+1, @long+2, 1]
71+
storage(long_ary).should == "long[]"
8572
end
86-
end
8773

88-
it "supports int[] << double" do
89-
ary = [0, 1, 2]
90-
storage(ary).should == "int[]"
74+
it "supports int[] << long and goes to long[]" do
75+
# Make sure long[] is chosen even if there was a int[] << Object before
76+
2.times do |i|
77+
setup = (i == 0)
9178

92-
ary << 1.34
93-
ary.should == [0, 1, 2, 1.34]
94-
storage(ary).should == "Object[]"
95-
end
79+
ary = [0, 1, 2]
80+
storage(ary).should == "int[]"
9681

97-
it "supports long[] << double" do
98-
long_ary = [@long, @long+1, @long+2]
99-
storage(long_ary).should == "long[]"
82+
obj = (i == 0) ? Object.new : @long
83+
ary << obj
84+
ary.should == [0, 1, 2, obj]
85+
storage(ary).should == (setup ? "Object[]" : "long[]")
86+
end
87+
end
10088

101-
long_ary << 1.34
102-
long_ary.should == [@long, @long+1, @long+2, 1.34]
103-
storage(long_ary).should == "Object[]"
104-
end
89+
it "supports int[] << double" do
90+
ary = [0, 1, 2]
91+
storage(ary).should == "int[]"
10592

106-
it "supports double[] << int" do
107-
ary = [3.14, 3.15]
108-
storage(ary).should == "double[]"
93+
ary << 1.34
94+
ary.should == [0, 1, 2, 1.34]
95+
storage(ary).should == "Object[]"
96+
end
10997

110-
ary << 4
111-
ary.should == [3.14, 3.15, 4]
112-
storage(ary).should == "Object[]"
113-
end
98+
it "supports long[] << double" do
99+
long_ary = [@long, @long+1, @long+2]
100+
storage(long_ary).should == "long[]"
114101

115-
it "supports Object[] << int" do
116-
o = Object.new
117-
ary = [o]
118-
storage(ary).should == "Object[]"
102+
long_ary << 1.34
103+
long_ary.should == [@long, @long+1, @long+2, 1.34]
104+
storage(long_ary).should == "Object[]"
105+
end
119106

120-
ary << 4
121-
ary.should == [o, 4]
122-
storage(ary).should == "Object[]"
107+
it "supports double[] << int" do
108+
ary = [3.14, 3.15]
109+
storage(ary).should == "double[]"
110+
111+
ary << 4
112+
ary.should == [3.14, 3.15, 4]
113+
storage(ary).should == "Object[]"
114+
end
115+
116+
it "supports Object[] << int" do
117+
o = Object.new
118+
ary = [o]
119+
storage(ary).should == "Object[]"
120+
121+
ary << 4
122+
ary.should == [o, 4]
123+
storage(ary).should == "Object[]"
124+
end
123125
end
124126
end

spec/truffle/array/element_set_spec.rb

Lines changed: 76 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -17,80 +17,82 @@ def storage(ary)
1717
@long = 1 << 52
1818
end
1919

20-
it "migrates to the most specific storage if initially empty" do
21-
ary = []
22-
ary[0] = Object.new
23-
storage(ary).should == "Object[]"
24-
25-
ary = []
26-
ary[0] = 3.14
27-
storage(ary).should == "double[]"
28-
29-
ary = []
30-
ary[0] = @long
31-
storage(ary).should == "long[]"
32-
33-
ary = []
34-
ary[0] = 1
35-
storage(ary).should == "int[]"
36-
end
37-
38-
it "keeps the same storage if compatible and in bounds" do
39-
ary = [Object.new, Object.new]
40-
ary[1] = Object.new
41-
storage(ary).should == "Object[]"
42-
43-
ary = [3.11, 3.12]
44-
ary[1] = 3.14
45-
storage(ary).should == "double[]"
46-
47-
ary = [@long-2, @long-1]
48-
ary[1] = @long
49-
storage(ary).should == "long[]"
50-
51-
ary = [@long-2, @long-1]
52-
ary[1] = 3
53-
storage(ary).should == "long[]"
54-
55-
ary = [0, 1]
56-
ary[1] = 2
57-
storage(ary).should == "int[]"
58-
end
59-
60-
it "generalizes if not compatible and in bounds" do
61-
ary = [3.11, 3.12]
62-
ary[1] = Object.new
63-
storage(ary).should == "Object[]"
64-
65-
ary = [@long-2, @long-1]
66-
ary[1] = 3.14
67-
storage(ary).should == "Object[]"
68-
69-
ary = [0, 1]
70-
ary[1] = @long
71-
storage(ary).should == "long[]"
72-
73-
ary = [0, 1]
74-
ary[1] = Object.new
75-
storage(ary).should == "Object[]"
76-
end
77-
78-
it "keeps the same storage if compatible and appending" do
79-
ary = [Object.new, Object.new]
80-
ary[2] = Object.new
81-
storage(ary).should == "Object[]"
82-
83-
ary = [3.11, 3.12]
84-
ary[2] = 3.14
85-
storage(ary).should == "double[]"
86-
87-
ary = [@long-2, @long-1]
88-
ary[2] = @long
89-
storage(ary).should == "long[]"
90-
91-
ary = [0, 1]
92-
ary[2] = 2
93-
storage(ary).should == "int[]"
20+
guard -> { !Truffle::Boot.get_option('chaos-data') } do
21+
it "migrates to the most specific storage if initially empty" do
22+
ary = []
23+
ary[0] = Object.new
24+
storage(ary).should == "Object[]"
25+
26+
ary = []
27+
ary[0] = 3.14
28+
storage(ary).should == "double[]"
29+
30+
ary = []
31+
ary[0] = @long
32+
storage(ary).should == "long[]"
33+
34+
ary = []
35+
ary[0] = 1
36+
storage(ary).should == "int[]"
37+
end
38+
39+
it "keeps the same storage if compatible and in bounds" do
40+
ary = [Object.new, Object.new]
41+
ary[1] = Object.new
42+
storage(ary).should == "Object[]"
43+
44+
ary = [3.11, 3.12]
45+
ary[1] = 3.14
46+
storage(ary).should == "double[]"
47+
48+
ary = [@long-2, @long-1]
49+
ary[1] = @long
50+
storage(ary).should == "long[]"
51+
52+
ary = [@long-2, @long-1]
53+
ary[1] = 3
54+
storage(ary).should == "long[]"
55+
56+
ary = [0, 1]
57+
ary[1] = 2
58+
storage(ary).should == "int[]"
59+
end
60+
61+
it "generalizes if not compatible and in bounds" do
62+
ary = [3.11, 3.12]
63+
ary[1] = Object.new
64+
storage(ary).should == "Object[]"
65+
66+
ary = [@long-2, @long-1]
67+
ary[1] = 3.14
68+
storage(ary).should == "Object[]"
69+
70+
ary = [0, 1]
71+
ary[1] = @long
72+
storage(ary).should == "long[]"
73+
74+
ary = [0, 1]
75+
ary[1] = Object.new
76+
storage(ary).should == "Object[]"
77+
end
78+
79+
it "keeps the same storage if compatible and appending" do
80+
ary = [Object.new, Object.new]
81+
ary[2] = Object.new
82+
storage(ary).should == "Object[]"
83+
84+
ary = [3.11, 3.12]
85+
ary[2] = 3.14
86+
storage(ary).should == "double[]"
87+
88+
ary = [@long-2, @long-1]
89+
ary[2] = @long
90+
storage(ary).should == "long[]"
91+
92+
ary = [0, 1]
93+
ary[2] = 2
94+
storage(ary).should == "int[]"
95+
end
9496
end
9597

9698
it "migrates to Object[] if writing out of bounds" do

spec/truffle/array/steal_array_storage.rb

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,27 @@ def storage(ary)
2020
@array = %i[first second third]
2121
end
2222

23-
it "should no-op when called on itself" do
24-
copy = @array.dup
23+
guard -> { !Truffle::Boot.get_option('chaos-data') } do
24+
it "should no-op when called on itself" do
25+
copy = @array.dup
2526

26-
Primitive.steal_array_storage(@array, @array)
27+
Primitive.steal_array_storage(@array, @array)
2728

28-
storage(@array).should == "Object[]"
29-
@array.should == copy
30-
end
29+
storage(@array).should == "Object[]"
30+
@array.should == copy
31+
end
3132

32-
it "should take ownership of the store" do
33-
other = [1, 2, 3, 4, 5]
34-
other_copy = other.dup
33+
it "should take ownership of the store" do
34+
other = [1, 2, 3, 4, 5]
35+
other_copy = other.dup
3536

36-
Primitive.steal_array_storage(@array, other)
37+
Primitive.steal_array_storage(@array, other)
3738

38-
storage(@array).should == "int[]"
39-
@array.should == other_copy
39+
storage(@array).should == "int[]"
40+
@array.should == other_copy
4041

41-
storage(other).should == "null"
42-
other.empty?.should == true
42+
storage(other).should == "null"
43+
other.empty?.should == true
44+
end
4345
end
4446
end

0 commit comments

Comments
 (0)