def test_indirect_sometimes_residual_pure_but_fixed_red_call(self, setup=setup_for_indirect_call): def h1(x): return x-2 def h2(x): return x*4 call, lst = setup(h1, h2) def f(n, x): frozenl = hint(lst, deepfreeze=True) h = frozenl[n&1] z = call(h, x) hint(z, concrete=True) return z P = StopAtXPolicy(h1) P.oopspec = True P.entrypoint_returns_red = False hs, hannotator = self.hannotate(f, [int, int], policy=P, annotator=True) assert hs.is_green() #tsgraph = graphof(hannotator.translator, h2) #hs = hannotator.binding(tsgraph.getargs()[0]) #assert hs.is_green() tsgraph = graphof(hannotator.translator, f) hs = hannotator.binding(tsgraph.getargs()[0]) assert hs.is_green() hs = hannotator.binding(tsgraph.getargs()[1]) assert hs.is_green()
def test_indirect_sometimes_residual_pure_red_call(self, setup=setup_for_indirect_call): def h1(x): return x-2 def h2(x): return x*4 call, lst = setup(h1, h2) def f(n, x): frozenl = hint(lst, deepfreeze=True) h = frozenl[n&1] return call(h, x) P = StopAtXPolicy(h1) P.oopspec = True P.entrypoint_returns_red = False hs, hannotator = self.hannotate(f, [int, int], policy=P, annotator=True) assert not hs.is_green() assert isinstance(hs, SomeLLAbstractConstant) tsgraph = graphof(hannotator.translator, h2) hs = hannotator.binding(tsgraph.getargs()[0]) assert not hs.is_green()
def test_manual_marking_of_pure_functions(self): d = {} def h1(s): try: return d[s] except KeyError: d[s] = r = hash(s) return r h1._pure_function_ = True def f(n): hint(n, concrete=True) if n == 0: s = "abc" else: s = "123" a = h1(s) return a P = StopAtXPolicy(h1) P.oopspec = True P.entrypoint_returns_red = False hs = self.hannotate(f, [int], policy=P) assert hs.is_green()