def test_forcevar(): jitstate = FakeJITState() gv = FakeGenVar() intbox = rvalue.IntRedBox("dummy kind", gv) assert intbox.forcevar(jitstate, rvalue.copy_memo(), False) is intbox doublebox = rvalue.DoubleRedBox("dummy kind", FakeGenConst()) box2 = doublebox.forcevar(jitstate, rvalue.copy_memo(), False) assert doublebox is not box2 assert not box2.is_constant() assert doublebox.genvar is not box2.genvar
def test_simple_merge_generalize(self): S = self.STRUCT constbox20 = makebox(20) oldbox = vmalloc(S, constbox20) frozenbox = oldbox.freeze(rvalue.freeze_memo()) # check that frozenbox matches oldbox exactly assert self.match(frozenbox, oldbox, []) # there is no FrozenVar constbox23 = makebox(23) newbox = vmalloc(S, constbox23) # non-exact match: a different constant box in the virtual struct field assert not self.match(frozenbox, newbox, [constbox23]) # constbox23 is what should be generalized with forcevar() # in order to get something that is at least as general as # both oldbox and newbox jitstate = FakeJITState() replace_memo = rvalue.copy_memo() forcedbox = constbox23.forcevar(jitstate, replace_memo, False) assert not forcedbox.is_constant() assert jitstate.curbuilder.ops == [ ('same_as', (signed_kind, constbox23.genvar), forcedbox.genvar) ] assert replace_memo.boxes == {constbox23: forcedbox} # change constbox to forcedbox inside newbox newbox.replace(replace_memo) assert (newbox.content.op_getfield(jitstate, self.fielddesc) is forcedbox) # check that now newbox really generalizes oldbox newfrozenbox = newbox.freeze(rvalue.freeze_memo()) assert self.match(newfrozenbox, oldbox, [constbox20])
def test_simple_merge_generalize(self): S = self.STRUCT constbox20 = makebox(20) oldbox = vmalloc(S, constbox20) frozenbox = oldbox.freeze(rvalue.freeze_memo()) # check that frozenbox matches oldbox exactly assert self.match(frozenbox, oldbox, []) # there is no FrozenVar constbox23 = makebox(23) newbox = vmalloc(S, constbox23) # non-exact match: a different constant box in the virtual struct field assert not self.match(frozenbox, newbox, [constbox23]) # constbox23 is what should be generalized with forcevar() # in order to get something that is at least as general as # both oldbox and newbox jitstate = FakeJITState() replace_memo = rvalue.copy_memo() forcedbox = constbox23.forcevar(jitstate, replace_memo, False) assert not forcedbox.is_constant() assert jitstate.curbuilder.ops == [ ('same_as', (signed_kind, constbox23.genvar), forcedbox.genvar)] assert replace_memo.boxes == {constbox23: forcedbox} # change constbox to forcedbox inside newbox newbox.replace(replace_memo) assert (newbox.content.op_getfield(jitstate, self.fielddesc) is forcedbox) # check that now newbox really generalizes oldbox newfrozenbox = newbox.freeze(rvalue.freeze_memo()) assert self.match(newfrozenbox, oldbox, [constbox20])