File tree Expand file tree Collapse file tree 7 files changed +40
-13
lines changed
src/main/ruby/truffleruby/core Expand file tree Collapse file tree 7 files changed +40
-13
lines changed Original file line number Diff line number Diff line change @@ -25,13 +25,13 @@ def self.check_recursion_to_depth(obj, depth)
25
25
26
26
def self . check_double_recursion_equality_to_depth ( obj1 , obj2 , depth )
27
27
# checks that obj1 and obj2 are both recursive and equal structurally
28
- # (because detect_recursion on two objects is only used during object comparison,
28
+ # (because detect_pair_recursion on two objects is only used during object comparison,
29
29
# and aborts after inequality is discovered)
30
30
return false unless obj1 . class == obj2 . class
31
31
return false unless obj1 . respond_to? ( :each )
32
32
return false unless obj1 . size == obj2 . size
33
33
34
- Truffle ::ThreadOperations . detect_recursion ( obj1 , obj2 ) do
34
+ Truffle ::ThreadOperations . detect_pair_recursion ( obj1 , obj2 ) do
35
35
if depth > 1
36
36
if obj1 . class == Hash
37
37
obj1 . each do |key , val |
Original file line number Diff line number Diff line change @@ -89,7 +89,7 @@ def <=>(other)
89
89
90
90
total = other . size
91
91
92
- Truffle ::ThreadOperations . detect_recursion self , other do
92
+ Truffle ::ThreadOperations . detect_pair_recursion self , other do
93
93
i = 0
94
94
count = Primitive . min ( total , size )
95
95
@@ -132,7 +132,7 @@ def ==(other)
132
132
133
133
return false unless size == other . size
134
134
135
- Truffle ::ThreadOperations . detect_recursion self , other do
135
+ Truffle ::ThreadOperations . detect_pair_recursion self , other do
136
136
i = 0
137
137
total = size
138
138
@@ -325,7 +325,7 @@ def eql?(other)
325
325
return false unless other . kind_of? ( Array )
326
326
return false if size != other . size
327
327
328
- Truffle ::ThreadOperations . detect_recursion self , other do
328
+ Truffle ::ThreadOperations . detect_pair_recursion self , other do
329
329
i = 0
330
330
each do |x |
331
331
return false unless x . eql? other [ i ]
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ module Comparable
30
30
def ==( other )
31
31
return true if equal? ( other )
32
32
33
- return false if Truffle ::ThreadOperations . detect_recursion ( self , other ) do
33
+ return false if Truffle ::ThreadOperations . detect_pair_recursion ( self , other ) do
34
34
unless comp = ( self <=> other )
35
35
return false
36
36
end
Original file line number Diff line number Diff line change @@ -137,7 +137,7 @@ def eql_op(op, other)
137
137
138
138
return false unless other . size == size
139
139
140
- Truffle ::ThreadOperations . detect_recursion self , other do
140
+ Truffle ::ThreadOperations . detect_pair_recursion self , other do
141
141
each_pair do |key , value |
142
142
other_value = other . _get_or_undefined ( key )
143
143
Original file line number Diff line number Diff line change @@ -1585,7 +1585,7 @@ def <=>(other)
1585
1585
return Primitive . string_cmp self , other
1586
1586
end
1587
1587
1588
- Truffle ::ThreadOperations . detect_recursion self , other do
1588
+ Truffle ::ThreadOperations . detect_pair_recursion self , other do
1589
1589
if other . respond_to? ( :<=> ) && !other . respond_to? ( :to_str )
1590
1590
return nil unless tmp = ( other <=> self )
1591
1591
elsif other . respond_to? ( :to_str )
Original file line number Diff line number Diff line change @@ -188,7 +188,7 @@ def to_s
188
188
def ==( other )
189
189
return false if self . class != other . class
190
190
191
- Truffle ::ThreadOperations . detect_recursion self , other do
191
+ Truffle ::ThreadOperations . detect_pair_recursion self , other do
192
192
return self . values == other . values
193
193
end
194
194
@@ -270,7 +270,7 @@ def eql?(other)
270
270
return true if equal? other
271
271
return false if self . class != other . class
272
272
273
- Truffle ::ThreadOperations . detect_recursion self , other do
273
+ Truffle ::ThreadOperations . detect_pair_recursion self , other do
274
274
_attrs . each do |var |
275
275
mine = Primitive . object_hidden_var_get ( self , var )
276
276
theirs = Primitive . object_hidden_var_get ( other , var )
Original file line number Diff line number Diff line change 63
63
module Truffle ::ThreadOperations
64
64
65
65
# detect_recursion will return if there's a recursion
66
- # on obj (or the pair obj+paired_obj) .
66
+ # on obj.
67
67
# If there is one, it returns true.
68
68
# Otherwise, it will yield once and return false.
69
- def self . detect_recursion ( obj , paired_obj = nil )
69
+ def self . detect_recursion ( obj )
70
+ unless Primitive . object_can_contain_object obj
71
+ yield
72
+ return false
73
+ end
74
+
75
+ id = obj . object_id
76
+ objects = Primitive . thread_recursive_objects
77
+
78
+ if objects [ id ]
79
+ true
80
+ else
81
+ objects [ id ] = true
82
+ begin
83
+ yield
84
+ ensure
85
+ objects . delete id
86
+ end
87
+ false
88
+ end
89
+ end
90
+ Truffle ::Graal . always_split method ( :detect_recursion )
91
+
92
+ # detect_recursion will return if there's a recursion
93
+ # on the pair obj+paired_obj.
94
+ # If there is one, it returns true.
95
+ # Otherwise, it will yield once and return false.
96
+ def self . detect_pair_recursion ( obj , paired_obj )
70
97
unless Primitive . object_can_contain_object obj
71
98
yield
72
99
return false
@@ -118,7 +145,7 @@ def self.detect_recursion(obj, paired_obj=nil)
118
145
119
146
false
120
147
end
121
- Truffle ::Graal . always_split method ( :detect_recursion )
148
+ Truffle ::Graal . always_split method ( :detect_pair_recursion )
122
149
123
150
class InnerRecursionDetected < Exception ; end # rubocop:disable Lint/InheritException
124
151
You can’t perform that action at this time.
0 commit comments