Author: Carl Friedrich Bolz <[email protected]>
Branch: unpickle-coroutine-trampoline
Changeset: r44421:a82ffce9bc55
Date: 2011-05-25 15:22 +0200
http://bitbucket.org/pypy/pypy/changeset/a82ffce9bc55/

Log:    kill support for resume points

diff --git a/pypy/rlib/rcoroutine.py b/pypy/rlib/rcoroutine.py
--- a/pypy/rlib/rcoroutine.py
+++ b/pypy/rlib/rcoroutine.py
@@ -29,7 +29,7 @@
 The type of a switch is determined by the target's costate.
 """
 
-from pypy.rlib.rstack import yield_current_frame_to_caller, resume_point
+from pypy.rlib.rstack import yield_current_frame_to_caller
 from pypy.rlib.objectmodel import we_are_translated
 
 from pypy.interpreter.error import OperationError
@@ -228,7 +228,6 @@
                         self.thunk = None
                         syncstate.switched(incoming_frame)
                         thunk.call()
-                        resume_point("coroutine__bind", state)
                     except Exception, e:
                         exc = e
                         raise
@@ -257,7 +256,6 @@
                 raise CoroutineDamage
             state = self.costate
             incoming_frame = state.update(self).switch()
-            resume_point("coroutine_switch", state, returns=incoming_frame)
             syncstate.switched(incoming_frame)
 
         def kill(self):
diff --git a/pypy/rlib/rstack.py b/pypy/rlib/rstack.py
--- a/pypy/rlib/rstack.py
+++ b/pypy/rlib/rstack.py
@@ -140,111 +140,6 @@
         return var
 
 
-def resume_point(label, *args, **kwds):
-    pass
-
-
-
-class ResumePointFnEntry(ExtRegistryEntry):
-    _about_ = resume_point
-
-    def compute_result_annotation(self, s_label, *args_s, **kwds_s):
-        from pypy.annotation import model as annmodel
-        return annmodel.s_None
-
-    def specialize_call(self, hop, **kwds_i):
-        from pypy.rpython.lltypesystem import lltype
-        from pypy.objspace.flow import model
-
-        assert hop.args_s[0].is_constant()
-        c_label = hop.inputconst(lltype.Void, hop.args_s[0].const)
-        args_v = hop.args_v[1:]
-        if 'i_returns' in kwds_i:
-            assert len(kwds_i) == 1
-            returns_index = kwds_i['i_returns']
-            v_return = args_v.pop(returns_index-1)
-            assert isinstance(v_return, model.Variable), \
-                   "resume_point returns= argument must be a Variable"
-        else:
-            assert not kwds_i
-            v_return = hop.inputconst(lltype.Void, None)
-
-        for v in args_v:
-            assert isinstance(v, model.Variable), "resume_point arguments must 
be Variables"
-
-        hop.exception_is_here()
-        return hop.genop('resume_point', [c_label, v_return] + args_v,
-                         hop.r_result)
-
-def resume_state_create(prevstate, label, *args):
-    raise RuntimeError("cannot resume states in non-translated versions")
-
-def concretify_argument(hop, index):
-    from pypy.objspace.flow import model
-
-    v_arg = hop.args_v[index]
-    if isinstance(v_arg, model.Variable):
-        return v_arg
-
-    r_arg = hop.rtyper.bindingrepr(v_arg)
-    return hop.inputarg(r_arg, arg=index)
-
-class ResumeStateCreateFnEntry(FrameStackTopReturningFnEntry):
-    _about_ = resume_state_create
-
-    def compute_result_annotation(self, s_prevstate, s_label, *args_s):
-        return FrameStackTopReturningFnEntry.compute_result_annotation(self)
-
-    def specialize_call(self, hop):
-        from pypy.rpython.lltypesystem import lltype
-
-        assert hop.args_s[1].is_constant()
-        c_label = hop.inputconst(lltype.Void, hop.args_s[1].const)
-
-        v_state = hop.inputarg(hop.r_result, arg=0)
-
-        args_v = []
-        for i in range(2, len(hop.args_v)):
-            args_v.append(concretify_argument(hop, i))
-
-        hop.exception_is_here()
-        return hop.genop('resume_state_create', [v_state, c_label] + args_v,
-                         hop.r_result)
-
-def resume_state_invoke(type, state, **kwds):
-    raise NotImplementedError("only works in translated versions")
-
-class ResumeStateInvokeFnEntry(ExtRegistryEntry):
-    _about_ = resume_state_invoke
-
-    def compute_result_annotation(self, s_type, s_state, **kwds):
-        from pypy.annotation.bookkeeper import getbookkeeper
-        assert s_type.is_constant()
-        return getbookkeeper().valueoftype(s_type.const)
-
-    def specialize_call(self, hop, **kwds_i):
-        from pypy.rpython.lltypesystem import lltype
-        v_state = hop.args_v[1]
-        
-        if 'i_returning' in kwds_i:
-            assert len(kwds_i) == 1
-            returning_index = kwds_i['i_returning']
-            v_returning = concretify_argument(hop, returning_index)
-            v_raising = hop.inputconst(lltype.Void, None)
-        elif 'i_raising' in kwds_i:
-            assert len(kwds_i) == 1
-            raising_index = kwds_i['i_raising']
-            v_returning = hop.inputconst(lltype.Void, None)
-            v_raising = concretify_argument(hop, raising_index)
-        else:
-            assert not kwds_i
-            v_returning = hop.inputconst(lltype.Void, None)
-            v_raising = hop.inputconst(lltype.Void, None)
-
-        hop.exception_is_here()
-        return hop.genop('resume_state_invoke', [v_state, v_returning, 
v_raising],
-                         hop.r_result)
-        
 # ____________________________________________________________
 
 def get_stack_depth_limit():
diff --git a/pypy/translator/stackless/frame.py 
b/pypy/translator/stackless/frame.py
--- a/pypy/translator/stackless/frame.py
+++ b/pypy/translator/stackless/frame.py
@@ -104,10 +104,8 @@
 
 class RestartInfo(object):
 
-    """A RestartInfo is created (briefly) for each graph that contains
-    a resume point.
-
-    In addition, a RestartInfo is created for each function that needs
+    """
+    A RestartInfo is created for each function that needs
     to do explicit stackless manipulations
     (e.g. code.yield_current_frame_to_caller)."""
 
diff --git a/pypy/translator/stackless/test/test_coroutine_reconstruction.py 
b/pypy/translator/stackless/test/test_coroutine_reconstruction.py
deleted file mode 100644
--- a/pypy/translator/stackless/test/test_coroutine_reconstruction.py
+++ /dev/null
@@ -1,68 +0,0 @@
-from pypy.rlib import rcoroutine
-from pypy.rlib import rstack
-from pypy.rlib.rstack import resume_state_create
-from pypy.translator.stackless.test.test_transform import 
llinterp_stackless_function
-from pypy.rpython.lltypesystem.lloperation import llop
-from pypy.rpython.lltypesystem import lltype
-
-namespace = rcoroutine.make_coroutine_classes(object)
-syncstate = namespace['syncstate']
-AbstractThunk = namespace['AbstractThunk']
-Coroutine = namespace['Coroutine']
-
-class TestCoroutineReconstruction:
-
-    def setup_meth(self):
-        syncstate.reset()
-
-    def test_simple_ish(self):
-
-        output = []
-        def f(coro, n, x):
-            if n == 0:
-                coro.switch()
-                rstack.resume_point("f_0")
-                assert rstack.stack_frames_depth() == 9
-                return
-            f(coro, n-1, 2*x)
-            rstack.resume_point("f_1", coro, n, x)
-            output.append(x)
-
-        class T(AbstractThunk):
-            def __init__(self, arg_coro, arg_n, arg_x):
-                self.arg_coro = arg_coro
-                self.arg_n = arg_n
-                self.arg_x = arg_x
-            def call(self):
-                f(self.arg_coro, self.arg_n, self.arg_x)
-
-        def example():
-            main_coro = Coroutine.getcurrent()
-            sub_coro = Coroutine()
-            thunk_f = T(main_coro, 5, 1)
-            sub_coro.bind(thunk_f)
-            sub_coro.switch()
-
-            new_coro = Coroutine()
-            new_thunk_f = T(main_coro, 5, 1)
-            new_coro.bind(new_thunk_f)
-
-            costate = Coroutine._get_default_costate()
-            bottom = resume_state_create(None, 
"yield_current_frame_to_caller_1")
-            _bind_frame = resume_state_create(bottom, "coroutine__bind", 
costate)
-            f_frame_1 = resume_state_create(_bind_frame, "f_1", main_coro, 5, 
1)
-            f_frame_2 = resume_state_create(f_frame_1, "f_1", main_coro, 4, 2)
-            f_frame_3 = resume_state_create(f_frame_2, "f_1", main_coro, 3, 4)
-            f_frame_4 = resume_state_create(f_frame_3, "f_1", main_coro, 2, 8)
-            f_frame_5 = resume_state_create(f_frame_4, "f_1", main_coro, 1, 16)
-            f_frame_0 = resume_state_create(f_frame_5, "f_0")
-            switch_frame = resume_state_create(f_frame_0, "coroutine_switch", 
costate)
-
-            new_coro.frame = switch_frame
-
-            new_coro.switch()
-            return output == [16, 8, 4, 2, 1]
-
-        res = llinterp_stackless_function(example)
-        assert res == 1
-
diff --git a/pypy/translator/stackless/test/test_resume_point.py 
b/pypy/translator/stackless/test/test_resume_point.py
deleted file mode 100644
--- a/pypy/translator/stackless/test/test_resume_point.py
+++ /dev/null
@@ -1,457 +0,0 @@
-from pypy.translator.stackless.transform import StacklessTransformer
-from pypy.translator.stackless.test.test_transform import 
llinterp_stackless_function, rtype_stackless_function, one, 
run_stackless_function
-from pypy import conftest
-import py
-from pypy.rlib import rstack
-
-def do_backendopt(t):
-    from pypy.translator.backendopt import all
-    all.backend_optimizations(t)
-
-def transform_stackless_function(fn, callback_for_transform=None):
-    def wrapper(argv):
-        return fn()
-    t = rtype_stackless_function(wrapper)
-    if callback_for_transform:
-        callback_for_transform(t)
-    if conftest.option.view:
-        t.view()
-    st = StacklessTransformer(t, wrapper, False)
-    st.transform_all()
-
-def test_no_call():
-    def f(x, y):
-        x = x-1
-        rstack.resume_point("rp0", x, y) 
-        r = x+y
-        rstack.stack_unwind()
-        return r
-    def example():
-        v1 = f(one(),one()+one())
-        state = rstack.resume_state_create(None, "rp0", one(), 
one()+one()+one())
-        v2 = rstack.resume_state_invoke(int, state)
-        return v1*10 + v2
-##     transform_stackless_function(example)
-    res = llinterp_stackless_function(example, assert_unwind=False)
-    assert res == 24
-
-def test_bogus_restart_state_create():
-    def f(x, y):
-        x = x-1
-        rstack.resume_point("rp0", x, y) 
-        return x+y
-    def example():
-        v1 = f(one(),one()+one())
-        state = rstack.resume_state_create(None, "rp0", one())
-        return v1
-    info = py.test.raises(AssertionError, 
"transform_stackless_function(example)")
-    assert 'rp0' in str(info.value)
-    
-
-def test_call():
-    def g(x,y):
-        return x*y
-    def f(x, y):
-        z = g(x,y)
-        rstack.resume_point("rp1", y, returns=z) 
-        return z+y
-    def example():
-        v1 = f(one(),one()+one())
-        s = rstack.resume_state_create(None, "rp1", 5*one())
-        v2 = rstack.resume_state_invoke(int, s, returning=one()*7)
-        return v1*100 + v2
-    res = llinterp_stackless_function(example)
-    assert res == 412
-    res = run_stackless_function(example)
-    assert res == 412
-
-def test_returns_with_instance():
-    class C:
-        def __init__(self, x):
-            self.x = x
-    def g(x):
-        return C(x+1)
-    def f(x, y):
-        r = g(x)
-        rstack.resume_point("rp1", y, returns=r)
-        return r.x + y
-    def example():
-        v1 = f(one(),one()+one())
-        s = rstack.resume_state_create(None, "rp1", 5*one())
-        v2 = rstack.resume_state_invoke(int, s, returning=C(one()*3))
-        return v1*100 + v2
-    res = llinterp_stackless_function(example, assert_unwind=False)
-    assert res == 408
-    res = run_stackless_function(example)
-    assert res == 408
-
-def test_call_uncovered():
-    def g(x,y):
-        return x*y
-    def f(x, y):
-        z = g(x,y)
-        rstack.resume_point("rp1", y, returns=z)
-        return z+y+x
-    def example():
-        f(one(),one()+one())
-        return 0
-    e = py.test.raises(Exception, transform_stackless_function, example)
-    msg, = e.value.args
-    assert msg.startswith('not covered needed value at resume_point') and 
'rp1' in msg
-
-def test_chained_states():
-    def g(x, y):
-        x += 1
-        rstack.resume_point("rp1", x, y)
-        return x + y
-    def f(x, y, z):
-        y += 1
-        r = g(x, y)
-        rstack.resume_point("rp2", z, returns=r)
-        return r + z
-    def example():
-        v1 = f(one(), 2*one(), 3*one())
-        s2 = rstack.resume_state_create(None, "rp2", 2*one())
-        s1 = rstack.resume_state_create(s2, "rp1", 4*one(), 5*one())
-        return 100*v1 + rstack.resume_state_invoke(int, s1)
-    res = llinterp_stackless_function(example)
-    assert res == 811
-    res = run_stackless_function(example)
-    assert res == 811
-
-def test_return_instance():
-    class C:
-        pass
-    def g(x):
-        c = C()
-        c.x = x + 1
-        rstack.resume_point("rp1", c)
-        return c
-    def f(x, y):
-        r = g(x)
-        rstack.resume_point("rp2", y, returns=r)
-        return r.x + y
-    def example():
-        v1 = f(one(), 2*one())
-        s2 = rstack.resume_state_create(None, "rp2", 2*one())
-        c = C()
-        c.x = 4*one()
-        s1 = rstack.resume_state_create(s2, "rp1", c)
-        return v1*100 + rstack.resume_state_invoke(int, s1)
-    res = llinterp_stackless_function(example)
-    assert res == 406
-    res = run_stackless_function(example)
-    assert res == 406
-
-def test_really_return_instance():
-    class C:
-        pass
-    def g(x):
-        c = C()
-        c.x = x + 1
-        rstack.resume_point("rp1", c)
-        return c
-    def example():
-        v1 = g(one()).x
-        c = C()
-        c.x = 4*one()
-        s1 = rstack.resume_state_create(None, "rp1", c)
-        return v1*100 + rstack.resume_state_invoke(C, s1).x
-    res = llinterp_stackless_function(example)
-    assert res == 204
-    res = run_stackless_function(example)
-    assert res == 204
-
-def test_resume_and_raise():
-    def g(x):
-        rstack.resume_point("rp0", x)
-        if x == 0:
-            raise KeyError
-        return x + 1
-    def example():
-        v1 = g(one())
-        s = rstack.resume_state_create(None, "rp0", one()-1)
-        try:
-            v2 = rstack.resume_state_invoke(int, s)
-        except KeyError:
-            v2 = 42
-        return v1*100 + v2
-    res = llinterp_stackless_function(example)
-    assert res == 242
-    res = run_stackless_function(example)
-    assert res == 242
-    
-def test_resume_and_raise_and_catch():
-    def g(x):
-        rstack.resume_point("rp0", x)
-        if x == 0:
-            raise KeyError
-        return x + 1
-    def f(x):
-        x = x - 1
-        try:
-            r = g(x)
-            rstack.resume_point("rp1", returns=r)
-        except KeyError:
-            r = 42
-        return r - 1
-    def example():
-        v1 = f(one()+one())
-        s1 = rstack.resume_state_create(None, "rp1")
-        s0 = rstack.resume_state_create(s1, "rp0", one()-1)
-        v2 = rstack.resume_state_invoke(int, s0)
-        return v1*100 + v2
-    res = llinterp_stackless_function(example)
-    assert res == 141
-    res = run_stackless_function(example)
-    assert res == 141
-
-def test_invoke_raising():
-    def g(x):
-        rstack.resume_point("rp0", x)
-        return x + 1
-    def f(x):
-        x = x - 1
-        try:
-            r = g(x)
-            rstack.resume_point("rp1", returns=r)
-        except KeyError:
-            r = 42
-        return r - 1
-    def example():
-        v1 = f(one()+one())
-        s1 = rstack.resume_state_create(None, "rp1")
-        s0 = rstack.resume_state_create(s1, "rp0", 0)
-        v2 = rstack.resume_state_invoke(int, s0, raising=KeyError())
-        return v1*100 + v2
-    res = llinterp_stackless_function(example)
-    assert res == 141
-    res = run_stackless_function(example)
-    assert res == 141
-    
-
-def test_finally():
-    def f(x):
-        rstack.resume_point("rp1", x)        
-        return 1/x
-    def in_finally(x): 
-        rstack.resume_point("rp1.5", x)
-        return 2/x
-    def g(x):
-        r = y = 0
-        r += f(x)
-        try:
-            y = f(x)
-            rstack.resume_point("rp0", x, r, returns=y)
-        finally:
-            r += in_finally(x)
-        return r + y
-    def example():
-        return g(one())
-    transform_stackless_function(example)
-
-def test_except():
-    py.test.skip("please don't write code like this")
-    def f(x):
-        rstack.resume_point("rp1", x)        
-        return 1/x
-    def g(x):
-        r = y = 0
-        r += f(x)
-        try:
-            y = f(x)
-            rstack.resume_point("rp0", x, r, y, returns=y)
-        except ZeroDivisionError:
-            r += f(x)
-        return r + y
-    def example():
-        return g(one())
-    transform_stackless_function(example)
-
-def test_using_pointers():
-    from pypy.interpreter.miscutils import FixedStack
-    class Arguments:
-        def __init__(self, a, b, c, d, e):
-            pass
-    class W_Root:
-        pass
-    class FakeFrame:
-        def __init__(self, space):
-            self.space = space
-            self.valuestack = FixedStack()
-            self.valuestack.setup(10)
-            self.valuestack.push(W_Root())
-    class FakeSpace:
-        def call_args(self, args, kw):
-            return W_Root()
-        def str_w(self, ob):
-            return 'a string'
-    def call_function(f, oparg, w_star=None, w_starstar=None):
-        n_arguments = oparg & 0xff
-        n_keywords = (oparg>>8) & 0xff
-        keywords = None
-        if n_keywords:
-            keywords = {}
-            for i in range(n_keywords):
-                w_value = f.valuestack.pop()
-                w_key   = f.valuestack.pop()
-                key = f.space.str_w(w_key)
-                keywords[key] = w_value
-        arguments = [None] * n_arguments
-        for i in range(n_arguments - 1, -1, -1):
-            arguments[i] = f.valuestack.pop()
-        args = Arguments(f.space, arguments, keywords, w_star, w_starstar)
-        w_function  = f.valuestack.pop()
-        w_result = f.space.call_args(w_function, args)
-        rstack.resume_point("call_function", f, returns=w_result)
-        f.valuestack.push(w_result)
-    def example():
-        s = FakeSpace()
-        f = FakeFrame(s)
-        call_function(f, 100, W_Root(), W_Root())
-        return one()
-    transform_stackless_function(example, do_backendopt)
-
-def test_always_raising():
-    def g(out):
-        out.append(3)
-        rstack.resume_point('g')
-        raise KeyError
-
-    def h(out):
-        try:
-            # g is always raising, good enough to put the resume point
-            # before, instead of after!
-            rstack.resume_point('h', out)
-            g(out)
-        except KeyError:
-            return 0
-        return -1
-
-    def example():
-        out = []
-        x = h(out)
-        l  = len(out)
-        chain = rstack.resume_state_create(None, 'h', out)
-        chain = rstack.resume_state_create(chain, 'g')
-        x += rstack.resume_state_invoke(int, chain)
-        l += len(out)
-        return l*100+x
-
-    res = llinterp_stackless_function(example)
-    assert res == 200
-    res = run_stackless_function(example)
-    assert res == 200
-
-def test_more_mess():
-    from pypy.interpreter.miscutils import Stack
-
-    def new_framestack():
-        return Stack()
-
-    class FakeFrame:
-        pass
-    class FakeSlpFrame:
-        def switch(self):
-            rstack.stack_unwind()
-            return FakeSlpFrame()
-
-    class FakeCoState:
-        def update(self, new):
-            self.last, self.current = self.current, new
-            frame, new.frame = new.frame, None
-            return frame
-        def do_things_to_do(self):
-            self.do_things_to_do()
-
-    costate = FakeCoState()
-    costate.current = None
-
-    class FakeExecutionContext:
-        def __init__(self):
-            self.space = space
-            self.framestack = new_framestack()
-
-        def subcontext_new(coobj):
-            coobj.framestack = new_framestack()
-        subcontext_new = staticmethod(subcontext_new)
-
-        def subcontext_enter(self, next):
-            self.framestack = next.framestack
-
-        def subcontext_leave(self, current):
-            current.framestack = self.framestack
-
-    class FakeSpace:
-        def __init__(self):
-            self.ec = None
-        def getexecutioncontext(self):
-            if self.ec is None:
-                self.ec = FakeExecutionContext()
-            return self.ec
-
-    space = FakeSpace()
-
-    class MainCoroutineGetter(object):
-        def __init__(self):
-            self.costate = None
-        def _get_default_costate(self):
-            if self.costate is None:
-                costate = FakeCoState()
-                self.costate = costate
-                return costate
-            return self.costate
-
-    main_coroutine_getter = MainCoroutineGetter()
-    
-    class FakeCoroutine:
-        def __init__(self):
-            self.frame = None
-            self.costate = costate
-            space.getexecutioncontext().subcontext_new(self)
-            
-        def switch(self):
-            if self.frame is None:
-                raise RuntimeError
-            state = self.costate
-            incoming_frame = state.update(self).switch()
-            rstack.resume_point("coroutine_switch", self, state, 
returns=incoming_frame)
-            left = state.last
-            left.frame = incoming_frame
-            left.goodbye()
-            self.hello()
-            #main_coroutine_getter._get_default_costate().do_things_to_do()
-
-        def hello(self):
-            pass
-
-        def goodbye(self):
-            pass
-
-    class FakeAppCoroutine(FakeCoroutine):
-        def __init__(self):
-            FakeCoroutine.__init__(self)
-            self.space = space
-            
-        def hello(self):
-            ec = self.space.getexecutioncontext()
-            ec.subcontext_enter(self)
-
-        def goodbye(self):
-            ec = self.space.getexecutioncontext()
-            ec.subcontext_leave(self)
-
-    def example():
-        coro = FakeAppCoroutine()
-        othercoro = FakeCoroutine()
-        othercoro.frame = FakeSlpFrame()
-        if one():
-            coro.frame = FakeSlpFrame()
-        if one() - one():
-            coro.costate = FakeCoState()
-            coro.costate.last = coro.costate.current = othercoro
-        space.getexecutioncontext().framestack.push(FakeFrame())
-        coro.switch()
-        return one()
-
-    transform_stackless_function(example, do_backendopt)
diff --git a/pypy/translator/stackless/transform.py 
b/pypy/translator/stackless/transform.py
--- a/pypy/translator/stackless/transform.py
+++ b/pypy/translator/stackless/transform.py
@@ -112,19 +112,6 @@
 #         abort()
 #     return retval + x + 1
 
-class SymbolicRestartNumber(ComputedIntSymbolic):
-    def __init__(self, label, value=None):
-        ComputedIntSymbolic.__init__(self, self._getvalue)
-        self.label = label
-        self.value = value
-
-    def _getvalue(self):
-        # argh, we'd like to assert-fail if value is None here, but we
-        # get called too early (during databasing) for this to be
-        # valid.  so we might return None and rely on the database
-        # checking that this only happens before the database is
-        # complete.
-        return self.value
 
 # the strategy for sharing parts of the resume code:
 #
@@ -248,8 +235,7 @@
         self.stackless_gc = stackless_gc
 
     def analyze_simple_operation(self, op, graphinfo):
-        if op.opname in ('yield_current_frame_to_caller', 'resume_point',
-                'resume_state_invoke', 'resume_state_create', 
'stack_frames_depth',
+        if op.opname in ('yield_current_frame_to_caller', 'stack_frames_depth',
                 'stack_switch', 'stack_unwind', 'stack_capture',
                 'get_stack_depth_limit', 'set_stack_depth_limit'):
             return True
@@ -458,24 +444,11 @@
 
         self.is_finished = False
 
-        # only for sanity checking, but still very very important
-        self.explicit_resume_point_data = {}
-        
-        self.symbolic_restart_numbers = {}
-
-        # register the prebuilt restartinfos & give them names for use
-        # with resume_state_create
         # the mauling of frame_typer internals should be a method on 
FrameTyper.
         for restartinfo in frame.RestartInfo.prebuilt:
             name = restartinfo.func_or_graph.__name__
             for i in range(len(restartinfo.frame_types)):
-                label = name + '_' + str(i)
-                assert label not in self.symbolic_restart_numbers
-                # XXX we think this is right:
-                self.symbolic_restart_numbers[label] = SymbolicRestartNumber(
-                    label, len(self.masterarray1) + i)
                 frame_type = restartinfo.frame_types[i]
-                self.explicit_resume_point_data[label] = frame_type
                 self.frametyper.ensure_frame_type_for_types(frame_type)
             self.register_restart_info(restartinfo)
 
@@ -589,156 +562,6 @@
                 # yes
                 convertblock.exits[0].args[index] = newvar
         # end ouch!
-        
-    def handle_resume_point(self, block, i):
-        # in some circumstances we might be able to reuse
-        # an already inserted resume point
-        op = block.operations[i]
-        if i == len(block.operations) - 1:
-            link = block.exits[0]
-            nextblock = None
-        else:
-            link = split_block(None, block, i+1)
-            i = 0
-            nextblock = link.target
-
-        label = op.args[0].value
-
-        parms = op.args[1:]
-        if not isinstance(parms[0], model.Variable):
-            assert parms[0].value is None
-            parms[0] = None
-        args = vars_to_save(block)
-        for a in args:
-            if a not in parms:
-                raise Exception, "not covered needed value at resume_point 
%r"%(label,)
-        if parms[0] is not None: # returns= case
-            res = parms[0]
-            args = [arg for arg in args if arg is not res]
-        else:
-            args = args
-            res = op.result
-
-        (FRAME_TYPE, varsforcall, saver) = 
self.frametyper.frame_type_for_vars(parms[1:])
-
-        if label in self.explicit_resume_point_data:
-            OTHER_TYPE = self.explicit_resume_point_data[label]
-            assert FRAME_TYPE == OTHER_TYPE, "inconsistent types for label 
%r"%(label,)
-        else:
-            self.explicit_resume_point_data[label] = FRAME_TYPE
-
-        self._make_resume_handling(FRAME_TYPE, varsforcall, res, block.exits)
-
-        restart_number = len(self.masterarray1) + len(self.resume_blocks) - 1
-
-        if label in self.symbolic_restart_numbers:
-            symb = self.symbolic_restart_numbers[label]
-            assert symb.value is None
-            symb.value = restart_number
-        else:
-            symb = SymbolicRestartNumber(label, restart_number)
-            self.symbolic_restart_numbers[label] = symb
-
-        return nextblock
-
-    def handle_resume_state_create(self, block, i):
-        op = block.operations[i]
-        llops = LowLevelOpList()
-        label = op.args[1].value
-        parms = op.args[2:]
-        FRAME_TYPE, varsforcall, saver = 
self.frametyper.frame_type_for_vars(parms)
-
-        if label in self.explicit_resume_point_data:
-            OTHER_TYPE = self.explicit_resume_point_data[label]
-            assert FRAME_TYPE == OTHER_TYPE, "inconsistent types for label 
%r"%(label,)
-        else:
-            self.explicit_resume_point_data[label] = FRAME_TYPE
-
-        if label in self.symbolic_restart_numbers:
-            symb = self.symbolic_restart_numbers[label]
-        else:
-            symb = SymbolicRestartNumber(label)
-            self.symbolic_restart_numbers[label] = symb
-
-        # this is rather insane: we create an exception object, pass
-        # it to the saving function, then read the thus created state
-        # out of and then clear global_state.top
-        c_EXC = model.Constant(self.unwind_exception_type.TO, lltype.Void)
-        c_flags = model.Constant({'flavor': 'gc'}, lltype.Void)
-        v_exc = llops.genop('malloc', [c_EXC, c_flags],
-                            resulttype = self.unwind_exception_type)
-        llops.genop('setfield', [v_exc,
-                                 model.Constant('inst_depth', lltype.Void),
-                                 model.Constant(0, lltype.Signed)])
-
-        realvarsforcall = []
-        for v in varsforcall:
-            if v.concretetype != lltype.Void:
-                realvarsforcall.append(gen_cast(llops, 
storage_type(v.concretetype), v))
-        
-        llops.genop('direct_call',
-                    [model.Constant(saver, lltype.typeOf(saver)), v_exc,
-                     model.Constant(symb, lltype.Signed)] + realvarsforcall,
-                    resulttype = lltype.Void)
-        v_state = varoftype(lltype.Ptr(frame.STATE_HEADER))
-        v_state_hdr = llops.genop("getfield",
-                                  [self.ll_global_state, self.c_inst_top_name],
-                                  resulttype=lltype.Ptr(STATE_HEADER))
-        v_state = gen_cast(llops, lltype.Ptr(FRAME_TYPE), v_state_hdr)
-        llops.genop("setfield",
-                    [self.ll_global_state, self.c_inst_top_name, 
self.c_null_state])
-
-        v_prevstate = gen_cast(llops, lltype.Ptr(frame.STATE_HEADER), 
op.args[0])
-        llops.genop('direct_call', [self.set_back_pointer_ptr,
-                                    v_state_hdr, v_prevstate])
-        llops.append(model.SpaceOperation('cast_opaque_ptr', [v_state_hdr], 
op.result))
-        block.operations[i:i+1] = llops
-
-    def handle_resume_state_invoke(self, block):
-        op = block.operations[-1]
-        assert op.opname == 'resume_state_invoke'
-        # some commentary.
-        #
-        # we don't want to write 155 or so different versions of
-        # resume_after_foo that appear to the annotator to return
-        # different types.  we take advantage of the fact that this
-        # function always raises UnwindException and have it (appear
-        # to) return Void.  then to placate all the other machinery,
-        # we pass a constant zero-of-the-appropriate-type along the
-        # non-exceptional link (which we know will never be taken).
-        # Nota Bene: only mutate a COPY of the non-exceptional link
-        # because the non-exceptional link has been stored in
-        # self.resume_blocks and we don't want a constant "zero" in
-        # there.
-        v_state = op.args[0]
-        v_returning = op.args[1]
-        v_raising = op.args[2]
-        llops = LowLevelOpList()
-
-        if v_raising.concretetype == lltype.Void:
-            erased_type = storage_type(v_returning.concretetype)
-            resume_after_ptr = self.resume_afters[erased_type]
-            v_param = v_returning
-        else:
-            assert v_returning.concretetype == lltype.Void
-            erased_type = self.exception_type
-            resume_after_ptr = self.resume_after_raising_ptr
-            v_param = v_raising
-
-        if erased_type != v_param.concretetype:
-            v_param = gen_cast(llops, erased_type, v_param)
-        llops.genop('direct_call', [resume_after_ptr, v_state, v_param],
-                    resulttype=lltype.Void)
-
-        del block.operations[-1]
-        block.operations.extend(llops)
-
-        noexclink = block.exits[0].copy()
-        realrettype = op.result.concretetype
-        for i, a in enumerate(noexclink.args):
-            if a is op.result:
-                noexclink.args[i] = model.Constant(realrettype._defl(), 
realrettype)
-        block.recloseblock(*((noexclink,) + block.exits[1:]))        
 
     def insert_unwind_handling(self, block, i):
         # for the case where we are resuming to an except:
@@ -821,19 +644,8 @@
                 op = replace_with_call(self.operation_replacement[op.opname])
                 stackless_op = True
 
-            if op.opname == 'resume_state_create':
-                self.handle_resume_state_create(block, i)
-                continue # go back and look at that malloc
-                        
             if (op.opname in ('direct_call', 'indirect_call')
                 or self.analyzer.analyze(op)):
-                if op.opname == 'resume_point':
-                    block = self.handle_resume_point(block, i)
-                    if block is None:
-                        return
-                    else:
-                        i = 0
-                        continue
 
                 if not stackless_op and not self.analyzer.analyze(op):
                     i += 1
@@ -849,9 +661,7 @@
                     continue
 
                 nextblock = self.insert_unwind_handling(block, i)
-                if op.opname == 'resume_state_invoke':
-                    self.handle_resume_state_invoke(block)
-                
+
                 if nextblock is None:
                     return
 
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to