Example #1
0
def test_contains_unsupported_variable_type():
    def f(x):
        return x
    graph = support.getgraph(f, [5])
    for sf in [False, True]:
        for sll in [False, True]:
            for ssf in [False, True]:
                assert not contains_unsupported_variable_type(graph, sf,
                                                              sll, ssf)
    #
    graph = support.getgraph(f, [5.5])
    for sf in [False, True]:
        for sll in [False, True]:
            for ssf in [False, True]:
                res = contains_unsupported_variable_type(graph, sf, sll, ssf)
                assert res is not sf
    #
    graph = support.getgraph(f, [r_singlefloat(5.5)])
    for sf in [False, True]:
        for sll in [False, True]:
            for ssf in [False, True]:
                res = contains_unsupported_variable_type(graph, sf, sll, ssf)
                assert res == (not ssf)
    #
    graph = support.getgraph(f, [r_longlong(5)])
    for sf in [False, True]:
        for sll in [False, True]:
            for ssf in [False, True]:
                res = contains_unsupported_variable_type(graph, sf, sll, ssf)
                assert res == (sys.maxint == 2147483647 and not sll)
Example #2
0
def test_contains_unsupported_variable_type():
    def f(x):
        return x

    graph = support.getgraph(f, [5])
    for sf in [False, True]:
        for sll in [False, True]:
            for ssf in [False, True]:
                assert not contains_unsupported_variable_type(
                    graph, sf, sll, ssf)
    #
    graph = support.getgraph(f, [5.5])
    for sf in [False, True]:
        for sll in [False, True]:
            for ssf in [False, True]:
                res = contains_unsupported_variable_type(graph, sf, sll, ssf)
                assert res is not sf
    #
    graph = support.getgraph(f, [r_singlefloat(5.5)])
    for sf in [False, True]:
        for sll in [False, True]:
            for ssf in [False, True]:
                res = contains_unsupported_variable_type(graph, sf, sll, ssf)
                assert res == (not ssf)
    #
    graph = support.getgraph(f, [r_longlong(5)])
    for sf in [False, True]:
        for sll in [False, True]:
            for ssf in [False, True]:
                res = contains_unsupported_variable_type(graph, sf, sll, ssf)
                assert res == (sys.maxint == 2147483647 and not sll)
Example #3
0
def test_dont_look_inside():
    @jit.dont_look_inside
    def h(x):
        return x + 3

    graph = support.getgraph(h, [5])
    assert not JitPolicy().look_inside_graph(graph)
Example #4
0
def test_elidable():
    @jit.elidable
    def g(x):
        return x + 2

    graph = support.getgraph(g, [5])
    assert not JitPolicy().look_inside_graph(graph)
Example #5
0
def test_without_floats():
    graph = support.getgraph(lambda x: x+3.2, [5.4])
    policy = JitPolicy()
    policy.set_supports_floats(True)
    assert policy.look_inside_graph(graph)
    policy = JitPolicy()
    policy.set_supports_floats(False)
    assert not policy.look_inside_graph(graph)
Example #6
0
def test_without_floats():
    graph = support.getgraph(lambda x: x + 3.2, [5.4])
    policy = JitPolicy()
    policy.set_supports_floats(True)
    assert policy.look_inside_graph(graph)
    policy = JitPolicy()
    policy.set_supports_floats(False)
    assert not policy.look_inside_graph(graph)
Example #7
0
def test_loops():
    def g(x):
        i = 0
        while i < x:
            i += 1
        return i
    graph = support.getgraph(g, [5])
    assert not JitPolicy().look_inside_graph(graph)
Example #8
0
def test_unroll_safe():
    @jit.unroll_safe
    def h(x):
        i = 0
        while i < x:
            i += 1
        return i
    graph = support.getgraph(h, [5])
    assert JitPolicy().look_inside_graph(graph)
Example #9
0
def test_loops():
    def g(x):
        i = 0
        while i < x:
            i += 1
        return i

    graph = support.getgraph(g, [5])
    assert not JitPolicy().look_inside_graph(graph)
Example #10
0
def test_unroll_safe():
    @jit.unroll_safe
    def h(x):
        i = 0
        while i < x:
            i += 1
        return i

    graph = support.getgraph(h, [5])
    assert JitPolicy().look_inside_graph(graph)
Example #11
0
def test_unroll_safe_and_inline():
    @jit.unroll_safe
    def h(x):
        i = 0
        while i < x:
            i += 1
        return i
    h._always_inline_ = True

    def g(x):
        return h(x)

    graph = support.getgraph(h, [5])
    assert JitPolicy().look_inside_graph(graph)
Example #12
0
def test_unroll_safe_and_inline():
    @jit.unroll_safe
    def h(x):
        i = 0
        while i < x:
            i += 1
        return i

    h._always_inline_ = True

    def g(x):
        return h(x)

    graph = support.getgraph(h, [5])
    assert JitPolicy().look_inside_graph(graph)
Example #13
0
def test_str_join():
    def f(x, y):
        return "hello".join([str(x), str(y), "bye"])

    graph = support.getgraph(f, [5, 83])
    for block in graph.iterblocks():
        for op in block.operations:
            if op.opname == 'direct_call':
                funcptr = op.args[0].value
                called_graph = funcptr._obj.graph
                if JitPolicy().look_inside_graph(called_graph):
                    # the calls to join() and str() should be residual
                    mod = called_graph.func.__module__
                    assert (mod == 'pypy.rpython.rlist'
                            or mod == 'pypy.rpython.lltypesystem.rlist')
Example #14
0
def test_str_join():
    def f(x, y):
        return "hello".join([str(x), str(y), "bye"])

    graph = support.getgraph(f, [5, 83])
    for block in graph.iterblocks():
        for op in block.operations:
            if op.opname == 'direct_call':
                funcptr = op.args[0].value
                called_graph = funcptr._obj.graph
                if JitPolicy().look_inside_graph(called_graph):
                    # the calls to join() and str() should be residual
                    mod = called_graph.func.__module__
                    assert (mod == 'pypy.rpython.rlist' or
                            mod == 'pypy.rpython.lltypesystem.rlist')
Example #15
0
def test_elidable():
    @jit.elidable
    def g(x):
        return x + 2
    graph = support.getgraph(g, [5])
    assert not JitPolicy().look_inside_graph(graph)
Example #16
0
def test_regular_function():
    graph = support.getgraph(lambda x: x + 3, [5])
    assert JitPolicy().look_inside_graph(graph)
Example #17
0
def test_purefunction():
    @jit.purefunction
    def g(x):
        return x + 2
    graph = support.getgraph(g, [5])
    assert not JitPolicy().look_inside_graph(graph)
Example #18
0
def test_regular_function():
    graph = support.getgraph(lambda x: x+3, [5])
    assert JitPolicy().look_inside_graph(graph)
Example #19
0
def test_dont_look_inside():
    @jit.dont_look_inside
    def h(x):
        return x + 3
    graph = support.getgraph(h, [5])
    assert not JitPolicy().look_inside_graph(graph)