Esempio n. 1
0
 def test_auto_inline_graphs_from_anywhere(self):
     def leaf(n):
         return n
     def f(n):
         return leaf(n)
     t = self.translate(f, [int])
     f_graph = graphof(t, f)
     assert len(collect_called_graphs(f_graph, t)) == 1
     auto_inline_graphs(t, [f_graph], 32)
     assert len(collect_called_graphs(f_graph, t)) == 1
     auto_inline_graphs(t, [f_graph], 32, inline_graph_from_anywhere=True)
     assert len(collect_called_graphs(f_graph, t)) == 0
Esempio n. 2
0
    def test_auto_inlining_small_call_big_call_count(self):
        def leaf(n):
            total = 0
            i = 0
            while i < n:
                total += i
                if total > 100:
                    raise OverflowError
                i += 1
            return total

        def g(n):
            return leaf(n)

        def f(n):
            try:
                return g(n)
            except OverflowError:
                return -1

        eval_func, t = self.check_auto_inlining(f, [int], multiplier=10, call_count_check=True)
        f_graph = graphof(t, f)
        assert len(collect_called_graphs(f_graph, t)) == 0

        result = eval_func([10])
        assert result == 45
        result = eval_func([15])
        assert result == -1
Esempio n. 3
0
    def test_auto_inlining_small_call_big_call_count(self):
        def leaf(n):
            total = 0
            i = 0
            while i < n:
                total += i
                if total > 100:
                    raise OverflowError
                i += 1
            return total
        def g(n):
            return leaf(n)
        def f(n):
            try:
                return g(n)
            except OverflowError:
                return -1
        eval_func, t = self.check_auto_inlining(f, [int], multiplier=10,
                                           call_count_check=True)
        f_graph = graphof(t, f)
        assert len(collect_called_graphs(f_graph, t)) == 0

        result = eval_func([10])
        assert result == 45
        result = eval_func([15])
        assert result == -1
Esempio n. 4
0
 def check_access_directly_sanity(self, graphs):
     from rpython.translator.backendopt.inline import collect_called_graphs
     jit_graphs = set(graphs)
     for graph in collect_called_graphs(self.translator.entry_point_graph,
                                        self.translator):
         if graph in jit_graphs:
             continue
         assert not getattr(graph, 'access_directly', False)
Esempio n. 5
0
 def check_access_directly_sanity(self, graphs):
     from rpython.translator.backendopt.inline import collect_called_graphs
     jit_graphs = set(graphs)
     for graph in collect_called_graphs(self.translator.entry_point_graph,
                                        self.translator):
         if graph in jit_graphs:
             continue
         assert not getattr(graph, 'access_directly', False)
Esempio n. 6
0
    def test_list_iteration(self):
        def f():
            tot = 0
            for item in [1, 2, 3]:
                tot += item
            return tot

        eval_func, t = self.check_auto_inlining(f, [])
        f_graph = graphof(t, f)
        called_graphs = collect_called_graphs(f_graph, t)
        assert len(called_graphs) == 0

        result = eval_func([])
        assert result == 6
Esempio n. 7
0
    def test_list_iteration(self):
        def f():
            tot = 0
            for item in [1,2,3]:
                tot += item
            return tot

        eval_func, t = self.check_auto_inlining(f, [])
        f_graph = graphof(t, f)
        called_graphs = collect_called_graphs(f_graph, t)
        assert len(called_graphs) == 0

        result = eval_func([])
        assert result == 6