File: test_greenfield.py

package info (click to toggle)
pypy 7.0.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 107,216 kB
  • sloc: python: 1,201,787; ansic: 62,419; asm: 5,169; cpp: 3,017; sh: 2,534; makefile: 545; xml: 243; lisp: 45; awk: 4
file content (89 lines) | stat: -rw-r--r-- 2,962 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import pytest
from rpython.jit.metainterp.test.support import LLJitMixin
from rpython.rlib.jit import JitDriver, assert_green

pytest.skip("this feature is disabled at the moment!")

# note why it is disabled: before d721da4573ad
# there was a failing assert when inlining python -> sre -> python:
# https://bitbucket.org/pypy/pypy/issues/2775/
# this shows, that the interaction of greenfields and virtualizables is broken,
# because greenfields use MetaInterp.virtualizable_boxes, which confuses
# MetaInterp._nonstandard_virtualizable somehow (and makes no sense
# conceptually anyway). to fix greenfields, the two mechanisms would have to be
# disentangled.

class GreenFieldsTests:

    def test_green_field_1(self):
        myjitdriver = JitDriver(greens=['ctx.x'], reds=['ctx'])
        class Ctx(object):
            _immutable_fields_ = ['x']
            def __init__(self, x, y):
                self.x = x
                self.y = y
        def f(x, y):
            ctx = Ctx(x, y)
            while 1:
                myjitdriver.can_enter_jit(ctx=ctx)
                myjitdriver.jit_merge_point(ctx=ctx)
                ctx.y -= 1
                if ctx.y < 0:
                    return ctx.y
        def g(y):
            return f(5, y) + f(6, y)
        #
        res = self.meta_interp(g, [7])
        assert res == -2
        self.check_trace_count(2)
        self.check_resops(guard_value=0)

    def test_green_field_2(self):
        myjitdriver = JitDriver(greens=['ctx.x'], reds=['ctx'])
        class Ctx(object):
            _immutable_fields_ = ['x']
            def __init__(self, x, y):
                self.x = x
                self.y = y
        def f(x, y):
            ctx = Ctx(x, y)
            while 1:
                myjitdriver.can_enter_jit(ctx=ctx)
                myjitdriver.jit_merge_point(ctx=ctx)
                ctx.y -= 1
                if ctx.y < 0:
                    pass     # to just make two paths
                if ctx.y < -10:
                    return ctx.y
        def g(y):
            return f(5, y) + f(6, y)
        #
        res = self.meta_interp(g, [7])
        assert res == -22
        self.check_trace_count(4)
        self.check_resops(guard_value=0)

    def test_green_field_3(self):
        myjitdriver = JitDriver(greens=['ctx.x'], reds=['ctx'])
        class Ctx(object):
            _immutable_fields_ = ['x']
            def __init__(self, x, y):
                self.x = x
                self.y = y
        def f(x, y):
            ctx = Ctx(x, y)
            while ctx.y > 0:
                myjitdriver.can_enter_jit(ctx=ctx)
                myjitdriver.jit_merge_point(ctx=ctx)
                assert_green(ctx.x)
                ctx.y -= ctx.x
            return -2100
        def g():
            return f(5, 35) + f(6, 42)
        #
        res = self.meta_interp(g, [])
        assert res == -4200


class TestLLtypeGreenFieldsTests(GreenFieldsTests, LLJitMixin):
    pass