Skip to content

Commit

Permalink
#3892: fix wrong assert in intutils, it should be an InvalidLoop instead
Browse files Browse the repository at this point in the history
I introduced the assert in 5909f5e0a75c. before that, inconsistent intersects
would just do nothing, which I am not sure is a better solution than raising
InvalidLoop
  • Loading branch information
cfbolz committed Mar 3, 2023
1 parent ed2e744 commit ba8a3c4
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
8 changes: 7 additions & 1 deletion rpython/jit/metainterp/optimizeopt/intutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,13 @@ def known_nonnegative(self):
return 0 <= self.lower

def intersect(self, other):
assert not self.known_gt(other) and not self.known_lt(other)
from rpython.jit.metainterp.optimize import InvalidLoop
if self.known_gt(other) or self.known_lt(other):
# they don't overlap, which makes the loop invalid
# this never happens in regular linear traces, but it can happen in
# combination with unrolling/loop peeling
raise InvalidLoop("two integer ranges don't overlap")

r = False
if self.make_ge_const(other.lower):
r = True
Expand Down
5 changes: 2 additions & 3 deletions rpython/jit/metainterp/optimizeopt/test/test_intbound.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,12 @@ def test_intersect():
assert not b.contains(n)

def test_intersect_bug():
from rpython.jit.metainterp.optimize import InvalidLoop
b1 = bound(17, 17)
b2 = bound(1, 1)
with pytest.raises(AssertionError):
with pytest.raises(InvalidLoop):
b1.intersect(b2)



def test_add_bound():
for _, _, b1 in some_bounds():
for _, _, b2 in some_bounds():
Expand Down
33 changes: 33 additions & 0 deletions rpython/jit/metainterp/test/test_ajit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3256,6 +3256,39 @@ def f1(n):
res = self.interp_operations(f, [127 - 256 * 29])
assert res == 127

def test_bug_inline_short_preamble_can_be_inconsistent_in_optimizeopt(self):
myjitdriver = JitDriver(greens = [], reds = "auto")
class Str(object):
_immutable_fields_ = ['s']
def __init__(self, s):
self.s = s

empty = Str("")
space = Str(" ")

def f(a, b):
line = " " * a + " a" * b
token = ""
res = []
index = 0
while True:
myjitdriver.jit_merge_point()
if index >= len(line):
break
char = line[index]
index += 1
if char == space.s:
if token != empty.s:
res.append(token)
token = empty.s
else:
token += char
return len(res)
args = [50, 50]
res = self.meta_interp(f, args)
assert res == f(*args)


class BaseLLtypeTests(BasicTests):

def test_identityhash(self):
Expand Down

0 comments on commit ba8a3c4

Please sign in to comment.