Armin Rigo avatar Armin Rigo committed ab50773

Intermediate check-in

Comments (0)

Files changed (17)

pypy/config/pypyoption.py

                cmdline="--translationmodules",
                suggests=[("objspace.allworkingmodules", False)]),
 
-    BoolOption("geninterp", "specify whether geninterp should be used",
-               default=False),
-
     BoolOption("logbytecodes",
                "keep track of bytecode usage",
                default=False),
             config.objspace.std.suggest(withsmalllong=True)
         # xxx other options? ropes maybe?
 
-    # completely disable geninterp in a level 0 translation
-    if level == '0':
-        config.objspace.suggest(geninterp=False)
-
     # some optimizations have different effects depending on the typesystem
     if type_system == 'ootype':
         config.objspace.std.suggest(multimethods="doubledispatch")

pypy/config/translationoption.py

 
     # Flags of the TranslationContext:
     BoolOption("simplifying", "Simplify flow graphs", default=True),
-    BoolOption("builtins_can_raise_exceptions",
-               "When true, assume any call to a 'simple' builtin such as "
-               "'hex' can raise an arbitrary exception",
-               default=False,
-               cmdline=None),
     BoolOption("list_comprehension_operations",
                "When true, look for and special-case the sequence of "
                "operations that results from a list comprehension and "

pypy/interpreter/gateway.py

         self.filename = filename
         self.source = str(py.code.Source(source).deindent())
         self.modname = modname
-        # look at the first three lines for a NOT_RPYTHON tag
-        first = "\n".join(source.split("\n", 3)[:3])
-        if "NOT_RPYTHON" in first:
-            self.can_use_geninterp = False
-        else:
-            self.can_use_geninterp = True
         # make source code available for tracebacks
         lines = [x + "\n" for x in source.split("\n")]
         py.std.linecache.cache[filename] = (1, None, lines, filename)
 
     def __repr__(self):
-        return "<ApplevelClass filename=%r can_use_geninterp=%r>" % (self.filename, self.can_use_geninterp)
+        return "<ApplevelClass filename=%r>" % (self.filename,)
 
     def getwdict(self, space):
         return space.fromcache(ApplevelCache).getorbuild(self)
 
     def build(self, app):
         "NOT_RPYTHON.  Called indirectly by Applevel.getwdict()."
-        if self.space.config.objspace.geninterp and app.can_use_geninterp:
-            return PyPyCacheDir.build_applevelinterp_dict(app, self.space)
-        else:
-            return build_applevel_dict(app, self.space)
+        return build_applevel_dict(app, self.space)
 
 
 # __________ pure applevel version __________
                 filename=self.filename)
     return w_glob
 
-# __________ geninterplevel version __________
-
-class PyPyCacheDir:
-    "NOT_RPYTHON"
-    # similar to applevel, but using translation to interp-level.
-    # This version maintains a cache folder with single files.
-
-    def build_applevelinterp_dict(cls, self, space):
-        "NOT_RPYTHON"
-        # N.B. 'self' is the ApplevelInterp; this is a class method,
-        # just so that we have a convenient place to store the global state.
-        if not cls._setup_done:
-            cls._setup()
-
-        from pypy.translator.geninterplevel import translate_as_module
-        import marshal
-        scramble = md5(cls.seed)
-        scramble.update(marshal.dumps(self.source))
-        key = scramble.hexdigest()
-        initfunc = cls.known_code.get(key)
-        if not initfunc:
-            # try to get it from file
-            name = key
-            if self.filename:
-                prename = os.path.splitext(os.path.basename(self.filename))[0]
-            else:
-                prename = 'zznoname'
-            name = "%s_%s" % (prename, name)
-            try:
-                __import__("pypy._cache."+name)
-            except ImportError, x:
-                # print x
-                pass
-            else:
-                initfunc = cls.known_code[key]
-        if not initfunc:
-            # build it and put it into a file
-            initfunc, newsrc = translate_as_module(
-                self.source, self.filename, self.modname)
-            fname = cls.cache_path.join(name+".py").strpath
-            f = file(get_tmp_file_name(fname), "w")
-            print >> f, """\
-# self-destruct on double-click:
-if __name__ == "__main__":
-    from pypy import _cache
-    import os
-    namestart = os.path.join(os.path.split(_cache.__file__)[0], '%s')
-    for ending in ('.py', '.pyc', '.pyo'):
-        try:
-            os.unlink(namestart+ending)
-        except os.error:
-            pass""" % name
-            print >> f
-            print >> f, newsrc
-            print >> f, "from pypy._cache import known_code"
-            print >> f, "known_code[%r] = %s" % (key, initfunc.__name__)
-            f.close()
-            rename_tmp_to_eventual_file_name(fname)
-        w_glob = initfunc(space)
-        return w_glob
-    build_applevelinterp_dict = classmethod(build_applevelinterp_dict)
-
-    _setup_done = False
-
-    def _setup(cls):
-        """NOT_RPYTHON"""
-        lp = py.path.local
-        import pypy, os
-        p = lp(pypy.__file__).new(basename='_cache').ensure(dir=1)
-        cls.cache_path = p
-        ini = p.join('__init__.py')
-        try:
-            if not ini.check():
-                raise ImportError  # don't import if only a .pyc file left!!!
-            from pypy._cache import known_code, \
-                 GI_VERSION_RENDERED
-        except ImportError:
-            GI_VERSION_RENDERED = 0
-        from pypy.translator.geninterplevel import GI_VERSION
-        cls.seed = md5(str(GI_VERSION)).digest()
-        if GI_VERSION != GI_VERSION_RENDERED or GI_VERSION is None:
-            for pth in p.listdir():
-                if pth.check(file=1):
-                    try:
-                        pth.remove()
-                    except: pass
-            f = file(get_tmp_file_name(str(ini)), "w")
-            f.write("""\
-# This folder acts as a cache for code snippets which have been
-# compiled by compile_as_module().
-# It will get a new entry for every piece of code that has
-# not been seen, yet.
-#
-# Caution! Only the code snippet is checked. If something
-# is imported, changes are not detected. Also, changes
-# to geninterplevel or gateway are also not checked.
-# Exception: There is a checked version number in geninterplevel.py
-#
-# If in doubt, remove this file from time to time.
-
-GI_VERSION_RENDERED = %r
-
-known_code = {}
-
-# self-destruct on double-click:
-def harakiri():
-    import pypy._cache as _c
-    import py
-    lp = py.path.local
-    for pth in lp(_c.__file__).dirpath().listdir():
-        try:
-            pth.remove()
-        except: pass
-
-if __name__ == "__main__":
-    harakiri()
-
-del harakiri
-""" % GI_VERSION)
-            f.close()
-            rename_tmp_to_eventual_file_name(str(ini))
-        import pypy._cache
-        cls.known_code = pypy._cache.known_code
-        cls._setup_done = True
-    _setup = classmethod(_setup)
-
-
-def gethostname(_cache=[]):
-    if not _cache:
-        try:
-            import socket
-            hostname = socket.gethostname()
-        except:
-            hostname = ''
-        _cache.append(hostname)
-    return _cache[0]
-
-def get_tmp_file_name(fname):
-    return '%s~%s~%d' % (fname, gethostname(), os.getpid())
-
-def rename_tmp_to_eventual_file_name(fname):
-    # generated files are first written to the host- and process-specific
-    # file 'tmpname', and then atomically moved to their final 'fname'
-    # to avoid problems if py.py is started several times in parallel
-    tmpname = get_tmp_file_name(fname)
-    try:
-        os.rename(tmpname, fname)
-    except (OSError, IOError):
-        os.unlink(fname)    # necessary on Windows
-        os.rename(tmpname, fname)
-
 # ____________________________________________________________
 
 def appdef(source, applevel=ApplevelClass, filename=None):
         return build_applevel_dict(self, space)
 
 
-class applevelinterp_temp(ApplevelClass):
-    hidden_applevel = False
-    def getwdict(self, space):   # no cache
-        return PyPyCacheDir.build_applevelinterp_dict(self, space)
-
 # app2interp_temp is used for testing mainly
 def app2interp_temp(func, applevel_temp=applevel_temp, filename=None):
     """ NOT_RPYTHON """

pypy/interpreter/test/test_appinterp.py

 
 import py
-from pypy.interpreter.gateway import appdef, ApplevelClass, applevel_temp, applevelinterp_temp
+from pypy.interpreter.gateway import appdef, ApplevelClass, applevel_temp
 from pypy.interpreter.error import OperationError
 
 def test_execwith_novars(space): 
     w_res = g(space, space.wrap(10), space.wrap(1))
     assert space.eq_w(w_res, space.wrap(-9))
 
-def test_applevelinterp_functions(space):
-    test_applevel_functions(space, applevel_temp = applevelinterp_temp)
-
 def test_applevel_class(space, applevel_temp = applevel_temp):
     app = applevel_temp('''
         class C(object):
     w_clsattr = space.getattr(c, space.wrap('attr'))
     assert space.eq_w(w_clsattr, space.wrap(17))
 
-def test_applevelinterp_class(space):
-    test_applevel_class(space, applevel_temp = applevelinterp_temp)
-
 def app_test_something_at_app_level(): 
     x = 2
     assert x/2 == 1
         w_str = space1.getattr(w_mymod1, space1.wrap("hi"))
         assert space1.str_w(w_str) == "hello"
 
-    def test_geninterp_can_unfreeze(self):
+    def test_random_stuff_can_unfreeze(self):
         # When a module contains an "import" statement in applevel code, the
         # imported module is initialized, possibly after it has been already
         # frozen.

pypy/interpreter/test/test_gateway.py

         g3 = gateway.app2interp_temp(noapp_g3, gateway.applevel_temp)
         assert self.space.eq_w(g3(self.space, w('foo'), w('bar')), w('foobar'))
 
-    def test_app2interp2(self):
-        """same but using transformed code"""
-        w = self.space.wrap
-        def noapp_g3(a, b):
-            return a+b
-        g3 = gateway.app2interp_temp(noapp_g3, gateway.applevelinterp_temp)
-        assert self.space.eq_w(g3(self.space, w('foo'), w('bar')), w('foobar'))
-
     def test_app2interp_general_args(self):
         w = self.space.wrap
         def app_general(x, *args, **kwds):

pypy/module/__builtin__/app_inspect.py

 from __pypy__ import lookup_special
 
 def _caller_locals(): 
-    # note: the reason why this is working is because the functions in here are
-    # compiled by geninterp, so they don't have a frame
     return sys._getframe(0).f_locals 
 
 def vars(*obj):
         except AttributeError:
             raise TypeError, "vars() argument must have __dict__ attribute"
 
-# Replaced by the interp-level helper space.callable(): 
-##def callable(ob):
-##    import __builtin__ # XXX this is insane but required for now for geninterp
-##    for c in type(ob).__mro__:
-##        if '__call__' in c.__dict__:
-##            if isinstance(ob, __builtin__._instance): # old style instance!
-##                return getattr(ob, '__call__', None) is not None
-##            return True
-##    else:
-##        return False
-
 def dir(*args):
     """dir([object]) -> list of strings
 

pypy/module/pypyjit/policy.py

 
         if mod == 'pypy.rlib.rbigint' or mod == 'pypy.rlib.rlocale' or mod == 'pypy.rlib.rsocket':
             return False
-        if '_geninterp_' in func.func_globals: # skip all geninterped stuff
-            return False
         if mod.startswith('pypy.interpreter.astcompiler.'):
             return False
         if mod.startswith('pypy.interpreter.pyparser.'):

pypy/module/pypyjit/test/test_policy.py

     from pypy.rlib.rlocale import setlocale
     assert not pypypolicy.look_inside_function(setlocale)
 
-def test_geninterp():
-    d = {'_geninterp_': True}
-    exec """def f():
-        pass""" in d
-    assert not pypypolicy.look_inside_function(d['f'])
-
 def test_astcompiler():
     from pypy.interpreter.astcompiler import ast
     assert not pypypolicy.look_inside_function(ast.AST.walkabout)

pypy/module/rbench/__init__.py

-# Package initialisation
-from pypy.interpreter.mixedmodule import MixedModule
-
-class Module(MixedModule):
-    """geninterpreted benchmarks"""
-
-    appleveldefs = {
-        'pystone': 'app_bench.pystone',
-        'richards': 'app_bench.richards',
-        }
-    
-    interpleveldefs = {}

pypy/module/rbench/app_bench.py

-from pypy.translator.test.rpystone import main as pystone
-from pypy.translator.goal.richards import main as richards

pypy/objspace/flow/objspace.py

     is_ = None     # real version added by add_operations()
     id  = None     # real version added by add_operations()
 
-    def newdict(self):
+    def newdict(self, module="ignored"):
         if self.concrete_mode:
             return Constant({})
         return self.do_operation('newdict')
         except UnwrapException:
             raise Exception, "non-constant except guard"
         if check_class in (NotImplementedError, AssertionError):
-            # if we are in geninterp, we cannot catch these exceptions
-            if not self.config.translation.builtins_can_raise_exceptions:
-                raise error.FlowingError("Catching %s is not valid in RPython" %
-                                         check_class.__name__)
+            raise error.FlowingError("Catching %s is not valid in RPython" %
+                                     check_class.__name__)
         if not isinstance(check_class, tuple):
             # the simple case
             return ObjSpace.exception_match(self, w_exc_type, w_check_class)
         exceptions = [Exception]   # *any* exception by default
         if isinstance(w_callable, Constant):
             c = w_callable.value
-            if not self.config.translation.builtins_can_raise_exceptions:
-                if (isinstance(c, (types.BuiltinFunctionType,
-                                   types.BuiltinMethodType,
-                                   types.ClassType,
-                                   types.TypeType)) and
-                      c.__module__ in ['__builtin__', 'exceptions']):
-                    exceptions = operation.implicit_exceptions.get(c)
+            if (isinstance(c, (types.BuiltinFunctionType,
+                               types.BuiltinMethodType,
+                               types.ClassType,
+                               types.TypeType)) and
+                  c.__module__ in ['__builtin__', 'exceptions']):
+                exceptions = operation.implicit_exceptions.get(c)
         self.handle_implicit_exceptions(exceptions)
         return w_res
 
     def handle_implicit_exceptions(self, exceptions):
         if not exceptions:
             return
-        if not self.config.translation.builtins_can_raise_exceptions:
-            # clean up 'exceptions' by removing the non-RPythonic exceptions
-            # which might be listed for geninterp.
-            exceptions = [exc for exc in exceptions
-                              if exc is not TypeError and
-                                 exc is not AttributeError]
-        if exceptions:
-            # catch possible exceptions implicitly.  If the OperationError
-            # below is not caught in the same function, it will produce an
-            # exception-raising return block in the flow graph.  Note that
-            # even if the interpreter re-raises the exception, it will not
-            # be the same ImplicitOperationError instance internally.
-            context = self.getexecutioncontext()
-            outcome, w_exc_cls, w_exc_value = context.guessexception(*exceptions)
-            if outcome is not None:
-                # we assume that the caught exc_cls will be exactly the
-                # one specified by 'outcome', and not a subclass of it,
-                # unless 'outcome' is Exception.
-                #if outcome is not Exception:
-                    #w_exc_cls = Constant(outcome) Now done by guessexception itself
-                    #pass
-                 raise operation.ImplicitOperationError(w_exc_cls, w_exc_value)
+        for exc in exceptions:    # just for sanity-checking
+            assert exc is not TypeError
+            assert exc is not AttributeError
+        # catch possible exceptions implicitly.  If the OperationError
+        # below is not caught in the same function, it will produce an
+        # exception-raising return block in the flow graph.  Note that
+        # even if the interpreter re-raises the exception, it will not
+        # be the same ImplicitOperationError instance internally.
+        context = self.getexecutioncontext()
+        outcome, w_exc_cls, w_exc_value = context.guessexception(*exceptions)
+        if outcome is not None:
+            # we assume that the caught exc_cls will be exactly the
+            # one specified by 'outcome', and not a subclass of it,
+            # unless 'outcome' is Exception.
+            #if outcome is not Exception:
+                #w_exc_cls = Constant(outcome) Now done by guessexception itself
+                #pass
+             raise operation.ImplicitOperationError(w_exc_cls, w_exc_value)
 
     def w_KeyboardInterrupt(self):
         # the reason to do this is: if you interrupt the flowing of a function

pypy/objspace/flow/specialcase.py

         else:
             raise Exception, "should call %r with exactly %d arguments" % (
                 fn, Arity[opname])
-    if space.config.translation.builtins_can_raise_exceptions:
-        # in this mode, avoid constant folding and raise an implicit Exception
-        w_result = space.do_operation(opname, *args_w)
-        space.handle_implicit_exceptions([Exception])
-        return w_result
-    else:
-        # in normal mode, completely replace the call with the underlying
-        # operation and its limited implicit exceptions semantic
-        return getattr(space, opname)(*args_w)
-
-
-# This is not a space cache.
-# It is just collecting the compiled functions from all the source snippets.
-
-class FunctionCache(Cache):
-    """A cache mapping applevel instances to dicts with simple functions"""
-
-    def _build(app):
-        """NOT_RPYTHON.
-        Called indirectly by ApplevelClass.interphook().appcaller()."""
-        dic = {}
-        if not app.can_use_geninterp:
-            return None
-        if app.filename is not None:
-            dic['__file__'] = app.filename
-        dic['__name__'] = app.modname
-        exec py.code.Source(app.source).compile() in dic
-        return dic
-    _build = staticmethod(_build)
+    # completely replace the call with the underlying
+    # operation and its limited implicit exceptions semantic
+    return getattr(space, opname)(*args_w)
 
 # _________________________________________________________________________
 # a simplified version of the basic printing routines, for RPython programs
     os.write(1, s)
 # _________________________________________________________________________
 
-compiled_funcs = FunctionCache()
-
-def sc_applevel(space, app, name, args_w):
-    dic = compiled_funcs.getorbuild(app)
-    if not dic:
-        return None # signal that this is not RPython
-    func = dic[name]
-    if getattr(func, '_annspecialcase_', '').startswith('flowspace:'):
-        # a hack to replace specific app-level helpers with simplified
-        # RPython versions
-        name = func._annspecialcase_[len('flowspace:'):]
-        if name == 'print_item':    # more special cases...
-            w_s = space.do_operation('str', *args_w)
-            args_w = (w_s,)
-        func = globals()['rpython_' + name]
-    else:
-        # otherwise, just call the app-level helper and hope that it
-        # is RPython enough
-        pass
-    return space.do_operation('simple_call', Constant(func), *args_w)
-
 def sc_r_uint(space, r_uint, args):
     args_w, kwds_w = args.unpack()
     assert not kwds_w
     # this is now routed through the objspace, directly.
     # space.specialcases[fn] = sc_normalize_exception
     space.specialcases[__import__] = sc_import
-    # redirect ApplevelClass for print et al.
-    space.specialcases[ApplevelClass] = sc_applevel
     # turn calls to built-in functions to the corresponding operation,
     # if possible
     for fn in OperationName:

pypy/objspace/flow/test/test_objspace.py

         g = self.codetest(f)
 
 
-class TestGenInterpStyle(Base):
-    def setup_class(cls):
-        cls.space = FlowObjSpace()
-        cls.space.config.translation.builtins_can_raise_exceptions = True
-
-    def reraiseAttributeError(v):
-        try:
-            x = getattr(v, "y")
-        except AttributeError:
-            raise
-
-    def test_reraiseAttributeError(self):
-        x = self.codetest(self.reraiseAttributeError)
-        simplify_graph(x)
-        self.show(x)
-        excfound = []
-        for link in x.iterlinks():
-            if link.target is x.exceptblock:
-                excfound.append(link.exitcase)
-        assert len(excfound) == 2
-        excfound.sort()
-        expected = [Exception, AttributeError]
-        expected.sort()
-        assert excfound == expected
-
-    def reraiseTypeError(dic):
-        try:
-            x = dic[5]
-        except TypeError:
-            raise
-
-    def test_reraiseTypeError(self):
-        x = self.codetest(self.reraiseTypeError)
-        simplify_graph(x)
-        self.show(x)
-        excfound = []
-        for link in x.iterlinks():
-            if link.target is x.exceptblock:
-                excfound.append(link.exitcase)
-        assert len(excfound) == 2
-        excfound.sort()
-        expected = [Exception, TypeError]
-        expected.sort()
-        assert excfound == expected
-
-    def test_can_catch_special_exceptions(self):
-        def f():
-            try:
-                f()
-            except NotImplementedError:
-                pass
-        graph = self.codetest(f)
-        # assert did not crash
-
-
 DATA = {'x': 5,
         'y': 6}
 

pypy/translator/goal/targetpypystandalone.py

         filename = os.path.join(this_dir, 'app_main.py')
         app = gateway.applevel(open(filename).read(), 'app_main.py', 'app_main')
         app.hidden_applevel = False
-        app.can_use_geninterp = False
         w_dict = app.getwdict(space)
         entry_point = create_entry_point(space, w_dict)
 

pypy/translator/test/snippet.py

     return result
 
 
-# specifically for geninterp testing
-
-def t_isinstance(x, y):
-    return isinstance(x, (int, long)) and isinstance(y, int)
-
-def t_issubclass(x, y):
-    return issubclass(type(x), (int, long)) and issubclass(type(y), int)
-
-def t_neg_long():
-    return -132L
-
-def t_attrerror(x):
-    try:
-        return x.foobar
-    except AttributeError:
-        return 567
-
-
-class Exc(Exception):
-    def __init__(self, v):
-        Exception.__init__(self, v)    
-
-def exception_subclass_sanity(x):
-    try:
-        raise Exc(x)
-    except Exception, e:
-        return e.args[0]
-
-
-class HaveProp(object):
-
-    def __init__(self, v):
-        self.v = v
-
-    def _hi(self):
-        return self.v
-    hi = property(_hi, doc="HaveProp._hi")
-
-
-def run_prop(v):
-    return HaveProp(v).hi
-
 # --------------------(Currently) Non runnable Functions ---------------------
 
 def _somebug1(n=int):

pypy/translator/test/test_rpystone.py

-from pypy.translator.geninterplevel import translate_as_module, __file__ as __
-from pypy.objspace.std import Space
-import os
-fname = os.path.join(os.path.dirname(__), "test", "rpystone.py")
-src = file(fname).read()
-init, ign = translate_as_module(src)#, tmpname="/tmp/look.py")
-
-LOOPS = 25
-
-def test_rpystone():
-    space = Space()
-    modic = init(space)
-    entry = space.getitem(modic, space.wrap("entrypoint"))
-    # warm-up,to get everything translated
-    space.call(entry, space.newtuple([space.wrap(-1)]))
-    # now this is the real one
-    space.call(entry, space.newtuple([space.wrap(LOOPS)]))
-
-if __name__ == "__main__":
-    test_rpystone()

pypy/translator/translator.py

     FLOWING_FLAGS = {
         'verbose': False,
         'simplifying': True,
-        'builtins_can_raise_exceptions': False,
         'list_comprehension_operations': False,   # True, - not super-tested
         }
 
             config = get_pypy_config(translating=True)
         # ZZZ should go away in the end
         for attr in ['verbose', 'simplifying',
-                     'builtins_can_raise_exceptions',
                      'list_comprehension_operations']:
             if attr in flowing_flags:
                 setattr(config.translation, attr, flowing_flags[attr])
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.