[pypy-commit] pypy llvm-translation-backend: Fix prebuilt hash preservation.

2015-11-22 Thread mjacob
Author: Manuel Jacob 
Branch: llvm-translation-backend
Changeset: r80824:466d3372c513
Date: 2015-11-19 16:15 +0100
http://bitbucket.org/pypy/pypy/changeset/466d3372c513/

Log:Fix prebuilt hash preservation.

diff --git a/rpython/translator/llvm/genllvm.py 
b/rpython/translator/llvm/genllvm.py
--- a/rpython/translator/llvm/genllvm.py
+++ b/rpython/translator/llvm/genllvm.py
@@ -90,26 +90,34 @@
 else:
 global_attrs += 'internal '
 name = database.unique_name('@global')
-if self.varsize:
-extra_len = self.get_extra_len(obj)
-ptr_type.refs[obj] = 'bitcast({} {} to {})'.format(
-ptr_type.repr_type(extra_len), name,
-ptr_type.repr_type(None))
-else:
-ptr_type.refs[obj] = name
-hash_ = database.genllvm.gcpolicy.get_prebuilt_hash(obj)
 if (hasattr(obj._TYPE, '_hints') and
 obj._TYPE._hints.get('immutable', False) and
 obj._TYPE._gckind != 'gc'):
 global_attrs += 'constant'
 else:
 global_attrs += 'global'
-database.f.write('{} = {} {}\n'.format(
-name, global_attrs, self.repr_type_and_value(obj)))
-if hash_ is not None:
-database.f.write('{}_hash = {} {} {}\n'
-.format(name, global_attrs, SIGNED_TYPE, hash_))
-database.hashes.append(name)
+
+hash_ = database.genllvm.gcpolicy.get_prebuilt_hash(obj)
+if hash_ is None:
+if self.varsize:
+extra_len = self.get_extra_len(obj)
+ptr_type.refs[obj] = 'bitcast({} {} to {})'.format(
+ptr_type.repr_type(extra_len), name,
+ptr_type.repr_type(None))
+else:
+ptr_type.refs[obj] = name
+database.f.write('{} = {} {}\n'.format(
+name, global_attrs, self.repr_type_and_value(obj)))
+else:
+assert not self.varsize
+with_hash_type = '{{ {}, {} }}'.format(
+self.repr_type(), SIGNED_TYPE)
+ptr_type.refs[obj] = \
+'getelementptr({}, {}* {}_with_hash, i64 0, i32 0)'.format(
+with_hash_type, with_hash_type, name)
+database.f.write('{}_with_hash = {} {} {{ {}, {} {} }}\n'.format(
+name, global_attrs, with_hash_type,
+self.repr_type_and_value(obj), SIGNED_TYPE, hash_))
 
 
 class VoidType(Type):
@@ -765,7 +773,6 @@
 self.f = f
 self.names_counter = {}
 self.types = PRIMITIVES.copy()
-self.hashes = []
 self.stack_bottoms = []
 self.tls_getters = set()
 self.tls_addr_wrapper = False
@@ -1875,12 +1882,6 @@
 for export in self.entrypoints:
 get_repr(export._as_ptr()).V
 
-if database.hashes:
-items = ('i8* bitcast({}* {}_hash to i8*)'
-.format(SIGNED_TYPE, name) for name in database.hashes)
-f.write('@llvm.used = appending global [{} x i8*] [ {} ], '
-'section "llvm.metadata"\n'
-.format(len(database.hashes), ', '.join(items)))
 if database.stack_bottoms:
 items = ('i8* bitcast({} to i8*)'
 .format(ref) for ref in database.stack_bottoms)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy llvm-translation-backend: hg merge default

2015-11-22 Thread mjacob
Author: Manuel Jacob 
Branch: llvm-translation-backend
Changeset: r80827:7557812bafd4
Date: 2015-11-20 00:22 +0100
http://bitbucket.org/pypy/pypy/changeset/7557812bafd4/

Log:hg merge default

diff --git a/pypy/goal/targetpypystandalone.py 
b/pypy/goal/targetpypystandalone.py
--- a/pypy/goal/targetpypystandalone.py
+++ b/pypy/goal/targetpypystandalone.py
@@ -302,7 +302,7 @@
 
 def hack_for_cffi_modules(self, driver):
 # HACKHACKHACK
-# ugly hack to modify target goal from compile_c to build_cffi_imports
+# ugly hack to modify target goal from compile_* to build_cffi_imports
 # this should probably get cleaned up and merged with driver.create_exe
 from rpython.translator.driver import taskdef
 import types
@@ -316,7 +316,8 @@
 name = name.new(ext='exe')
 return name
 
-@taskdef(['compile_c'], "Create cffi bindings for modules")
+compile_goal, = driver.backend_select_goals(['compile'])
+@taskdef([compile_goal], "Create cffi bindings for modules")
 def task_build_cffi_imports(self):
 from pypy.tool.build_cffi_imports import 
create_cffi_import_libraries
 ''' Use cffi to compile cffi interfaces to modules'''
@@ -335,7 +336,7 @@
 # if failures, they were already printed
 print  >> sys.stderr, str(exename),'successfully built, but errors 
while building the above modules will be ignored'
 driver.task_build_cffi_imports = 
types.MethodType(task_build_cffi_imports, driver)
-driver.tasks['build_cffi_imports'] = driver.task_build_cffi_imports, 
['compile_c']
+driver.tasks['build_cffi_imports'] = driver.task_build_cffi_imports, 
[compile_goal]
 driver.default_goal = 'build_cffi_imports'
 # HACKHACKHACK end
 
diff --git a/rpython/translator/platform/darwin.py 
b/rpython/translator/platform/darwin.py
--- a/rpython/translator/platform/darwin.py
+++ b/rpython/translator/platform/darwin.py
@@ -28,11 +28,11 @@
 # needed for cross compiling on ARM, needs fixing if relevant for 
darwin
 if len(rel_libdirs) > 0:
 print 'in get_rpath_flags, rel_libdirs is not fixed up',rel_libdirs
-return self.rpath_flags 
+return self.rpath_flags
 
 def _args_for_shared(self, args):
 return (list(self.shared_only)
-+ ['-dynamiclib', '-install_name', '@rpath/$(TARGET)', 
'-undefined', 'dynamic_lookup']
++ ['-dynamiclib', '-install_name', '@rpath/$(TARGET)', 
'-undefined', 'dynamic_lookup', '-flat_namespace']
 + args)
 
 def _include_dirs_for_libffi(self):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy llvm-translation-backend: Implement field offset calculation for FixedSizeArrays.

2015-11-22 Thread mjacob
Author: Manuel Jacob 
Branch: llvm-translation-backend
Changeset: r80829:2980f62bc491
Date: 2015-11-22 11:55 +0100
http://bitbucket.org/pypy/pypy/changeset/2980f62bc491/

Log:Implement field offset calculation for FixedSizeArrays.

diff --git a/rpython/translator/llvm/genllvm.py 
b/rpython/translator/llvm/genllvm.py
--- a/rpython/translator/llvm/genllvm.py
+++ b/rpython/translator/llvm/genllvm.py
@@ -237,9 +237,14 @@
 indices.append('i64 0')
 if isinstance(offset, llmemory.FieldOffset):
 type = database.get_type(offset.TYPE)
-indices.append('i32 {}'.format(
-type.fldnames_wo_voids.index(offset.fldname)))
-return offset.TYPE._flds[offset.fldname]
+if isinstance(type, BareArrayType):
+assert offset.fldname.startswith('item')
+indices.append('i32 {}'.format(int(offset.fldname[4:])))
+return offset.TYPE.OF
+else:
+indices.append('i32 {}'.format(
+type.fldnames_wo_voids.index(offset.fldname)))
+return offset.TYPE._flds[offset.fldname]
 if isinstance(offset, llmemory.ArrayLengthOffset):
 if offset.TYPE._gckind == 'gc':
 indices.append('i32 1')
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy llvm-translation-backend: Add stub for have_debug_prints_for() llop.

2015-11-22 Thread mjacob
Author: Manuel Jacob 
Branch: llvm-translation-backend
Changeset: r80828:75ba75ce5bee
Date: 2015-11-22 11:51 +0100
http://bitbucket.org/pypy/pypy/changeset/75ba75ce5bee/

Log:Add stub for have_debug_prints_for() llop.

diff --git a/rpython/translator/llvm/genllvm.py 
b/rpython/translator/llvm/genllvm.py
--- a/rpython/translator/llvm/genllvm.py
+++ b/rpython/translator/llvm/genllvm.py
@@ -1113,6 +1113,9 @@
 def op_have_debug_prints(self, result):
 self.w('{result.V} = bitcast i1 false to i1'.format(**locals()))
 
+def op_have_debug_prints_for(self, result, category_prefix):
+self.w('{result.V} = bitcast i1 false to i1'.format(**locals()))
+
 def op_ll_read_timestamp(self, result):
 self.op_direct_call(result, get_repr(llvm_readcyclecounter))
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy llvm-translation-backend: Special-case COMPILER_INFO constant in LLVM backend.

2015-11-22 Thread mjacob
Author: Manuel Jacob 
Branch: llvm-translation-backend
Changeset: r80825:65fa1e610d2f
Date: 2015-11-19 20:05 +0100
http://bitbucket.org/pypy/pypy/changeset/65fa1e610d2f/

Log:Special-case COMPILER_INFO constant in LLVM backend.

diff --git a/rpython/translator/llvm/genllvm.py 
b/rpython/translator/llvm/genllvm.py
--- a/rpython/translator/llvm/genllvm.py
+++ b/rpython/translator/llvm/genllvm.py
@@ -15,6 +15,7 @@
  ShadowStackFrameworkGCTransformer)
 from rpython.memory.gctypelayout import WEAKREF, convert_weakref_to
 from rpython.rlib import exports
+from rpython.rlib.compilerinfo import COMPILER_INFO
 from rpython.rlib.jit import _we_are_jitted
 from rpython.rlib.objectmodel import (Symbolic, ComputedIntSymbolic,
  CDefinedIntSymbolic, malloc_zero_filled, running_on_llinterp)
@@ -412,6 +413,8 @@
 return not value
 
 def repr_value(self, value, extra_len=None):
+if value is COMPILER_INFO:
+return database.compiler_info
 obj = value._obj
 if isinstance(obj, int):
 return 'inttoptr({} {} to {})'.format(SIGNED_TYPE, obj,
@@ -1600,6 +1603,8 @@
 except lltype.DelayedPointer:
 self.delayed_ptrs = True
 return
+except AttributeError:
+return
 if value is None:
 return
 if isinstance(type, lltype.ContainerType):
@@ -1832,6 +1837,13 @@
 self.gcpolicy.finish()
 
 def _write_special_declarations(self, f):
+compiler_info_str = "LLVM " + cmdexec('llvm-config --version').strip()
+cstr_type = '[{} x i8]'.format(len(compiler_info_str) + 1)
+f.write('@compiler_info = private unnamed_addr constant {} c"{}\\00"\n'
+.format(cstr_type, compiler_info_str))
+database.compiler_info = ('bitcast({}* @compiler_info to [0 x i8]*)'
+.format(cstr_type))
+
 f.write('declare void @abort() noreturn nounwind\n')
 f.write('declare void @llvm.gcroot(i8** %ptrloc, i8* %metadata)\n')
 f.write('@__gcmap = external constant i8\n')
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy llvm-translation-backend: Pass HALFWORD instead of Signed to llop.combine_ushort().

2015-11-22 Thread mjacob
Author: Manuel Jacob 
Branch: llvm-translation-backend
Changeset: r80830:0db1c150ce78
Date: 2015-11-22 12:29 +0100
http://bitbucket.org/pypy/pypy/changeset/0db1c150ce78/

Log:Pass HALFWORD instead of Signed to llop.combine_ushort().

The first argument to the combine_ushort() llop is "expected" to be
of type HALFWORD. I say "expected" because e.g. the docstring of
CombinedSymbolic (to which the operation is folded) says it combines
a half-word and a word. The LLVM backend relies on that.

diff --git a/rpython/jit/backend/llsupport/descr.py 
b/rpython/jit/backend/llsupport/descr.py
--- a/rpython/jit/backend/llsupport/descr.py
+++ b/rpython/jit/backend/llsupport/descr.py
@@ -1,5 +1,6 @@
 import py
 from rpython.rtyper.lltypesystem import lltype, rffi, llmemory
+from rpython.rtyper.lltypesystem.llgroup import r_halfword
 from rpython.rtyper.lltypesystem.lloperation import llop
 from rpython.jit.backend.llsupport import symbolic, support
 from rpython.jit.metainterp.history import AbstractDescr, getkind, FLOAT, INT
@@ -34,7 +35,7 @@
 
 class SizeDescr(AbstractDescr):
 size = 0  # help translation
-tid = llop.combine_ushort(lltype.Signed, 0, 0)
+tid = llop.combine_ushort(lltype.Signed, r_halfword(0), 0)
 vtable = lltype.nullptr(rclass.OBJECT_VTABLE)
 immutable_flag = False
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: hg merge

2015-11-22 Thread mjacob
Author: Manuel Jacob 
Branch: 
Changeset: r80832:2bd0965ba1ae
Date: 2015-11-22 13:23 +0100
http://bitbucket.org/pypy/pypy/changeset/2bd0965ba1ae/

Log:hg merge

diff --git a/pypy/goal/targetpypystandalone.py 
b/pypy/goal/targetpypystandalone.py
--- a/pypy/goal/targetpypystandalone.py
+++ b/pypy/goal/targetpypystandalone.py
@@ -302,7 +302,7 @@
 
 def hack_for_cffi_modules(self, driver):
 # HACKHACKHACK
-# ugly hack to modify target goal from compile_c to build_cffi_imports
+# ugly hack to modify target goal from compile_* to build_cffi_imports
 # this should probably get cleaned up and merged with driver.create_exe
 from rpython.translator.driver import taskdef
 import types
@@ -316,7 +316,8 @@
 name = name.new(ext='exe')
 return name
 
-@taskdef(['compile_c'], "Create cffi bindings for modules")
+compile_goal, = driver.backend_select_goals(['compile'])
+@taskdef([compile_goal], "Create cffi bindings for modules")
 def task_build_cffi_imports(self):
 from pypy.tool.build_cffi_imports import 
create_cffi_import_libraries
 ''' Use cffi to compile cffi interfaces to modules'''
@@ -335,7 +336,7 @@
 # if failures, they were already printed
 print  >> sys.stderr, str(exename),'successfully built, but errors 
while building the above modules will be ignored'
 driver.task_build_cffi_imports = 
types.MethodType(task_build_cffi_imports, driver)
-driver.tasks['build_cffi_imports'] = driver.task_build_cffi_imports, 
['compile_c']
+driver.tasks['build_cffi_imports'] = driver.task_build_cffi_imports, 
[compile_goal]
 driver.default_goal = 'build_cffi_imports'
 # HACKHACKHACK end
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Make build_cffi_imports hack work with other backends than GenC.

2015-11-22 Thread mjacob
Author: Manuel Jacob 
Branch: 
Changeset: r80826:e4acc9f54fe0
Date: 2015-11-20 00:22 +0100
http://bitbucket.org/pypy/pypy/changeset/e4acc9f54fe0/

Log:Make build_cffi_imports hack work with other backends than GenC.

diff --git a/pypy/goal/targetpypystandalone.py 
b/pypy/goal/targetpypystandalone.py
--- a/pypy/goal/targetpypystandalone.py
+++ b/pypy/goal/targetpypystandalone.py
@@ -302,7 +302,7 @@
 
 def hack_for_cffi_modules(self, driver):
 # HACKHACKHACK
-# ugly hack to modify target goal from compile_c to build_cffi_imports
+# ugly hack to modify target goal from compile_* to build_cffi_imports
 # this should probably get cleaned up and merged with driver.create_exe
 from rpython.translator.driver import taskdef
 import types
@@ -316,7 +316,8 @@
 name = name.new(ext='exe')
 return name
 
-@taskdef(['compile_c'], "Create cffi bindings for modules")
+compile_goal, = driver.backend_select_goals(['compile'])
+@taskdef([compile_goal], "Create cffi bindings for modules")
 def task_build_cffi_imports(self):
 from pypy.tool.build_cffi_imports import 
create_cffi_import_libraries
 ''' Use cffi to compile cffi interfaces to modules'''
@@ -335,7 +336,7 @@
 # if failures, they were already printed
 print  >> sys.stderr, str(exename),'successfully built, but errors 
while building the above modules will be ignored'
 driver.task_build_cffi_imports = 
types.MethodType(task_build_cffi_imports, driver)
-driver.tasks['build_cffi_imports'] = driver.task_build_cffi_imports, 
['compile_c']
+driver.tasks['build_cffi_imports'] = driver.task_build_cffi_imports, 
[compile_goal]
 driver.default_goal = 'build_cffi_imports'
 # HACKHACKHACK end
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy exc-later: Propagate exception annotations from functions to their callers (work in progress)

2015-11-22 Thread rlamy
Author: Ronan Lamy 
Branch: exc-later
Changeset: r80835:ec9ba2968c66
Date: 2015-11-22 18:00 +
http://bitbucket.org/pypy/pypy/changeset/ec9ba2968c66/

Log:Propagate exception annotations from functions to their callers
(work in progress)

diff --git a/rpython/annotator/annrpython.py b/rpython/annotator/annrpython.py
--- a/rpython/annotator/annrpython.py
+++ b/rpython/annotator/annrpython.py
@@ -7,12 +7,12 @@
 from rpython.tool.pairtype import pair
 from rpython.tool.error import (format_blocked_annotation_error,
  gather_error, source_lines)
-from rpython.flowspace.model import Variable, Constant, checkgraph
+from rpython.flowspace.model import Variable, Constant, checkgraph, 
FunctionGraph
 from rpython.translator import simplify, transform
 from rpython.annotator import model as annmodel, signature
 from rpython.annotator.model import (
-typeof, s_ImpossibleValue, SomeInstance)
-from rpython.annotator.bookkeeper import Bookkeeper
+unionof, typeof, s_ImpossibleValue, SomeInstance, SomePBC)
+from rpython.annotator.bookkeeper import Bookkeeper, simple_args
 from rpython.rtyper.normalizecalls import perform_normalizations
 
 import py
@@ -265,6 +265,7 @@
 # points to this func which triggers a reflow whenever the
 # return block of this graph has been analysed.
 callpositions = self.notify.setdefault(graph.returnblock, {})
+callpositions2 = self.notify.setdefault(graph.exceptblock, {})
 if whence is not None:
 if callable(whence):
 def callback():
@@ -272,6 +273,7 @@
 else:
 callback = whence
 callpositions[callback] = True
+callpositions2[callback] = True
 
 # generalize the function's input arguments
 self.addpendingblock(graph, graph.startblock, inputcells)
@@ -607,6 +609,24 @@
 """
 Return the annotation for all exceptions that `operation` may raise.
 """
+from rpython.flowspace.operation import SimpleCall
+if isinstance(operation, SimpleCall):
+s_func = self.annotation(operation.args[0])
+if (isinstance(s_func, SomePBC) and
+hasattr(s_func.getKind(), 'get_graph')):  # exclude 
ClassDesc
+args_s = [self.annotation(v) for v in operation.args[1:]]
+argspec = simple_args(args_s)
+exceptions_s = []
+for desc in s_func.descriptions:
+with self.bookkeeper.at_position(None):
+graph = desc.get_graph(argspec, operation)
+if not isinstance(graph, FunctionGraph):
+break
+s_exc = graph.exceptblock.inputargs[1].annotation
+if s_exc is not None:
+exceptions_s.append(s_exc)
+else:
+return unionof(*exceptions_s)
 can_only_throw = operation.get_can_only_throw(self)
 if can_only_throw is None:
 return SomeInstance(self.bookkeeper.getuniqueclassdef(Exception))
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy exc-later: Replace all uses of SomeExceptCase with SomeInstance

2015-11-22 Thread rlamy
Author: Ronan Lamy 
Branch: exc-later
Changeset: r80834:bcf830d9e710
Date: 2015-11-22 05:38 +
http://bitbucket.org/pypy/pypy/changeset/bcf830d9e710/

Log:Replace all uses of SomeExceptCase with SomeInstance

diff --git a/rpython/annotator/annrpython.py b/rpython/annotator/annrpython.py
--- a/rpython/annotator/annrpython.py
+++ b/rpython/annotator/annrpython.py
@@ -11,7 +11,7 @@
 from rpython.translator import simplify, transform
 from rpython.annotator import model as annmodel, signature
 from rpython.annotator.model import (
-typeof, SomeExceptCase, s_ImpossibleValue, SomeInstance)
+typeof, s_ImpossibleValue, SomeInstance)
 from rpython.annotator.bookkeeper import Bookkeeper
 from rpython.rtyper.normalizecalls import perform_normalizations
 
@@ -496,8 +496,7 @@
 continue
 if s_exception == s_ImpossibleValue:
 break
-s_case = SomeExceptCase(
-self.bookkeeper.getuniqueclassdef(case))
+s_case = SomeInstance(self.bookkeeper.getuniqueclassdef(case))
 s_matching_exc = s_exception.intersection(s_case)
 if s_matching_exc != s_ImpossibleValue:
 self.follow_raise_link(graph, link, s_matching_exc)
diff --git a/rpython/annotator/model.py b/rpython/annotator/model.py
--- a/rpython/annotator/model.py
+++ b/rpython/annotator/model.py
@@ -446,17 +446,18 @@
 return None
 
 def intersection(self, other):
-assert isinstance(other, SomeExceptCase)
-if self.classdef.issubclass(other.case):
-return self
-elif other.case.issubclass(self.classdef):
-return SomeInstance(other.case)
+assert isinstance(other, SomeInstance)
+can_be_None = self.can_be_None and other.can_be_None
+if self.classdef.issubclass(other.classdef):
+return SomeInstance(self.classdef, can_be_None=can_be_None)
+elif other.classdef.issubclass(self.classdef):
+return SomeInstance(other.classdef, can_be_None=can_be_None)
 else:
 return s_ImpossibleValue
 
 def difference(self, other):
-assert isinstance(other, SomeExceptCase)
-if self.classdef.issubclass(other.case):
+assert isinstance(other, SomeInstance)
+if self.classdef.issubclass(other.classdef):
 return s_ImpossibleValue
 else:
 return self
@@ -476,16 +477,16 @@
 self.classdefs = classdefs
 
 def intersection(self, other):
-assert isinstance(other, SomeExceptCase)
-classdefs = {c for c in self.classdefs if c.issubclass(other.case)}
+assert isinstance(other, SomeInstance)
+classdefs = {c for c in self.classdefs if c.issubclass(other.classdef)}
 if classdefs:
 return SomeException(classdefs)
 else:
 return s_ImpossibleValue
 
 def difference(self, other):
-assert isinstance(other, SomeExceptCase)
-classdefs = {c for c in self.classdefs if not c.issubclass(other.case)}
+assert isinstance(other, SomeInstance)
+classdefs = {c for c in self.classdefs if not 
c.issubclass(other.classdef)}
 if classdefs:
 return SomeException(classdefs)
 else:
@@ -495,15 +496,6 @@
 return unionof(*[SomeInstance(cdef) for cdef in self.classdefs])
 
 
-class SomeExceptCase(SomeObject):
-"""The set of exceptions that match a given except clause.
-
-IOW, the set of exceptions that verify isinstance(exc, self.case).
-"""
-def __init__(self, case):
-self.case = case
-
-
 class SomePBC(SomeObject):
 """Stands for a global user instance, built prior to the analysis,
 or a set of such instances."""
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy exc-later: Use annotations to represent the exception behaviour of operations

2015-11-22 Thread rlamy
Author: Ronan Lamy 
Branch: exc-later
Changeset: r80833:9c9c044a9aff
Date: 2015-11-22 01:50 +
http://bitbucket.org/pypy/pypy/changeset/9c9c044a9aff/

Log:Use annotations to represent the exception behaviour of operations

diff --git a/rpython/annotator/annrpython.py b/rpython/annotator/annrpython.py
--- a/rpython/annotator/annrpython.py
+++ b/rpython/annotator/annrpython.py
@@ -11,7 +11,7 @@
 from rpython.translator import simplify, transform
 from rpython.annotator import model as annmodel, signature
 from rpython.annotator.model import (
-typeof, SomeExceptCase, s_ImpossibleValue)
+typeof, SomeExceptCase, s_ImpossibleValue, SomeInstance)
 from rpython.annotator.bookkeeper import Bookkeeper
 from rpython.rtyper.normalizecalls import perform_normalizations
 
@@ -488,31 +488,20 @@
 
 if block.canraise:
 op = block.raising_op
-can_only_throw = op.get_can_only_throw(self)
-if can_only_throw is not None:
-# filter out those exceptions which cannot
-# occur for this specific, typed operation.
-s_exception = self.bookkeeper.new_exception(can_only_throw)
-for link in exits:
-case = link.exitcase
-if case is None:
-self.follow_link(graph, link, {})
-continue
-if s_exception == s_ImpossibleValue:
-break
-s_case = SomeExceptCase(
-self.bookkeeper.getuniqueclassdef(case))
-s_matching_exc = s_exception.intersection(s_case)
-if s_matching_exc != s_ImpossibleValue:
-self.follow_raise_link(graph, link, s_matching_exc)
-s_exception = s_exception.difference(s_case)
-else:
-for link in exits:
-if link.exitcase is None:
-self.follow_link(graph, link, {})
-else:
-s_exception = 
self.bookkeeper.valueoftype(link.exitcase)
-self.follow_raise_link(graph, link, s_exception)
+s_exception = self.get_exception(op)
+for link in exits:
+case = link.exitcase
+if case is None:
+self.follow_link(graph, link, {})
+continue
+if s_exception == s_ImpossibleValue:
+break
+s_case = SomeExceptCase(
+self.bookkeeper.getuniqueclassdef(case))
+s_matching_exc = s_exception.intersection(s_case)
+if s_matching_exc != s_ImpossibleValue:
+self.follow_raise_link(graph, link, s_matching_exc)
+s_exception = s_exception.difference(s_case)
 else:
 if isinstance(block.exitswitch, Variable):
 knowntypedata = getattr(block.exitswitch.annotation,
@@ -615,6 +604,16 @@
 assert isinstance(op.result, Variable)
 self.setbinding(op.result, resultcell)  # bind resultcell to op.result
 
+def get_exception(self, operation):
+"""
+Return the annotation for all exceptions that `operation` may raise.
+"""
+can_only_throw = operation.get_can_only_throw(self)
+if can_only_throw is None:
+return SomeInstance(self.bookkeeper.getuniqueclassdef(Exception))
+else:
+return self.bookkeeper.new_exception(can_only_throw)
+
 
 class BlockedInference(Exception):
 """This exception signals the type inference engine that the situation
diff --git a/rpython/annotator/model.py b/rpython/annotator/model.py
--- a/rpython/annotator/model.py
+++ b/rpython/annotator/model.py
@@ -445,6 +445,22 @@
 else:
 return None
 
+def intersection(self, other):
+assert isinstance(other, SomeExceptCase)
+if self.classdef.issubclass(other.case):
+return self
+elif other.case.issubclass(self.classdef):
+return SomeInstance(other.case)
+else:
+return s_ImpossibleValue
+
+def difference(self, other):
+assert isinstance(other, SomeExceptCase)
+if self.classdef.issubclass(other.case):
+return s_ImpossibleValue
+else:
+return self
+
 def can_be_none(self):
 return self.can_be_None
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy anntype2: Use annotations to represent the exception behaviour of operations

2015-11-22 Thread rlamy
Author: Ronan Lamy 
Branch: anntype2
Changeset: r80837:5b6b723dac8f
Date: 2015-11-22 01:50 +
http://bitbucket.org/pypy/pypy/changeset/5b6b723dac8f/

Log:Use annotations to represent the exception behaviour of operations

diff --git a/rpython/annotator/annrpython.py b/rpython/annotator/annrpython.py
--- a/rpython/annotator/annrpython.py
+++ b/rpython/annotator/annrpython.py
@@ -11,7 +11,7 @@
 from rpython.translator import simplify, transform
 from rpython.annotator import model as annmodel, signature
 from rpython.annotator.model import (
-typeof, SomeExceptCase, s_ImpossibleValue)
+typeof, SomeExceptCase, s_ImpossibleValue, SomeInstance)
 from rpython.annotator.bookkeeper import Bookkeeper
 from rpython.rtyper.normalizecalls import perform_normalizations
 
@@ -488,31 +488,20 @@
 
 if block.canraise:
 op = block.raising_op
-can_only_throw = op.get_can_only_throw(self)
-if can_only_throw is not None:
-# filter out those exceptions which cannot
-# occur for this specific, typed operation.
-s_exception = self.bookkeeper.new_exception(can_only_throw)
-for link in exits:
-case = link.exitcase
-if case is None:
-self.follow_link(graph, link, {})
-continue
-if s_exception == s_ImpossibleValue:
-break
-s_case = SomeExceptCase(
-self.bookkeeper.getuniqueclassdef(case))
-s_matching_exc = s_exception.intersection(s_case)
-if s_matching_exc != s_ImpossibleValue:
-self.follow_raise_link(graph, link, s_matching_exc)
-s_exception = s_exception.difference(s_case)
-else:
-for link in exits:
-if link.exitcase is None:
-self.follow_link(graph, link, {})
-else:
-s_exception = 
self.bookkeeper.valueoftype(link.exitcase)
-self.follow_raise_link(graph, link, s_exception)
+s_exception = self.get_exception(op)
+for link in exits:
+case = link.exitcase
+if case is None:
+self.follow_link(graph, link, {})
+continue
+if s_exception == s_ImpossibleValue:
+break
+s_case = SomeExceptCase(
+self.bookkeeper.getuniqueclassdef(case))
+s_matching_exc = s_exception.intersection(s_case)
+if s_matching_exc != s_ImpossibleValue:
+self.follow_raise_link(graph, link, s_matching_exc)
+s_exception = s_exception.difference(s_case)
 else:
 if isinstance(block.exitswitch, Variable):
 knowntypedata = getattr(block.exitswitch.annotation,
@@ -615,6 +604,16 @@
 assert isinstance(op.result, Variable)
 self.setbinding(op.result, resultcell)  # bind resultcell to op.result
 
+def get_exception(self, operation):
+"""
+Return the annotation for all exceptions that `operation` may raise.
+"""
+can_only_throw = operation.get_can_only_throw(self)
+if can_only_throw is None:
+return SomeInstance(self.bookkeeper.getuniqueclassdef(Exception))
+else:
+return self.bookkeeper.new_exception(can_only_throw)
+
 
 class BlockedInference(Exception):
 """This exception signals the type inference engine that the situation
diff --git a/rpython/annotator/model.py b/rpython/annotator/model.py
--- a/rpython/annotator/model.py
+++ b/rpython/annotator/model.py
@@ -445,6 +445,22 @@
 else:
 return None
 
+def intersection(self, other):
+assert isinstance(other, SomeExceptCase)
+if self.classdef.issubclass(other.case):
+return self
+elif other.case.issubclass(self.classdef):
+return SomeInstance(other.case)
+else:
+return s_ImpossibleValue
+
+def difference(self, other):
+assert isinstance(other, SomeExceptCase)
+if self.classdef.issubclass(other.case):
+return s_ImpossibleValue
+else:
+return self
+
 def can_be_none(self):
 return self.can_be_None
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy anntype2: Replace all uses of SomeExceptCase with SomeInstance

2015-11-22 Thread rlamy
Author: Ronan Lamy 
Branch: anntype2
Changeset: r80838:fd73e9433923
Date: 2015-11-22 05:38 +
http://bitbucket.org/pypy/pypy/changeset/fd73e9433923/

Log:Replace all uses of SomeExceptCase with SomeInstance

diff --git a/rpython/annotator/annrpython.py b/rpython/annotator/annrpython.py
--- a/rpython/annotator/annrpython.py
+++ b/rpython/annotator/annrpython.py
@@ -11,7 +11,7 @@
 from rpython.translator import simplify, transform
 from rpython.annotator import model as annmodel, signature
 from rpython.annotator.model import (
-typeof, SomeExceptCase, s_ImpossibleValue, SomeInstance)
+typeof, s_ImpossibleValue, SomeInstance)
 from rpython.annotator.bookkeeper import Bookkeeper
 from rpython.rtyper.normalizecalls import perform_normalizations
 
@@ -496,8 +496,7 @@
 continue
 if s_exception == s_ImpossibleValue:
 break
-s_case = SomeExceptCase(
-self.bookkeeper.getuniqueclassdef(case))
+s_case = SomeInstance(self.bookkeeper.getuniqueclassdef(case))
 s_matching_exc = s_exception.intersection(s_case)
 if s_matching_exc != s_ImpossibleValue:
 self.follow_raise_link(graph, link, s_matching_exc)
diff --git a/rpython/annotator/model.py b/rpython/annotator/model.py
--- a/rpython/annotator/model.py
+++ b/rpython/annotator/model.py
@@ -446,17 +446,18 @@
 return None
 
 def intersection(self, other):
-assert isinstance(other, SomeExceptCase)
-if self.classdef.issubclass(other.case):
-return self
-elif other.case.issubclass(self.classdef):
-return SomeInstance(other.case)
+assert isinstance(other, SomeInstance)
+can_be_None = self.can_be_None and other.can_be_None
+if self.classdef.issubclass(other.classdef):
+return SomeInstance(self.classdef, can_be_None=can_be_None)
+elif other.classdef.issubclass(self.classdef):
+return SomeInstance(other.classdef, can_be_None=can_be_None)
 else:
 return s_ImpossibleValue
 
 def difference(self, other):
-assert isinstance(other, SomeExceptCase)
-if self.classdef.issubclass(other.case):
+assert isinstance(other, SomeInstance)
+if self.classdef.issubclass(other.classdef):
 return s_ImpossibleValue
 else:
 return self
@@ -476,16 +477,16 @@
 self.classdefs = classdefs
 
 def intersection(self, other):
-assert isinstance(other, SomeExceptCase)
-classdefs = {c for c in self.classdefs if c.issubclass(other.case)}
+assert isinstance(other, SomeInstance)
+classdefs = {c for c in self.classdefs if c.issubclass(other.classdef)}
 if classdefs:
 return SomeException(classdefs)
 else:
 return s_ImpossibleValue
 
 def difference(self, other):
-assert isinstance(other, SomeExceptCase)
-classdefs = {c for c in self.classdefs if not c.issubclass(other.case)}
+assert isinstance(other, SomeInstance)
+classdefs = {c for c in self.classdefs if not 
c.issubclass(other.classdef)}
 if classdefs:
 return SomeException(classdefs)
 else:
@@ -495,15 +496,6 @@
 return unionof(*[SomeInstance(cdef) for cdef in self.classdefs])
 
 
-class SomeExceptCase(SomeObject):
-"""The set of exceptions that match a given except clause.
-
-IOW, the set of exceptions that verify isinstance(exc, self.case).
-"""
-def __init__(self, case):
-self.case = case
-
-
 class SomePBC(SomeObject):
 """Stands for a global user instance, built prior to the analysis,
 or a set of such instances."""
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy anntype2: Following up on branch 'anntype'

2015-11-22 Thread rlamy
Author: Ronan Lamy 
Branch: anntype2
Changeset: r80836:f84f99b5bf95
Date: 2015-11-22 20:05 +
http://bitbucket.org/pypy/pypy/changeset/f84f99b5bf95/

Log:Following up on branch 'anntype'

___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: fix translated tests by partially recreating app level functions called by appbridge in rpython

2015-11-22 Thread mattip
Author: mattip 
Branch: 
Changeset: r80839:a50cf6604948
Date: 2015-11-22 22:44 +0200
http://bitbucket.org/pypy/pypy/changeset/a50cf6604948/

Log:fix translated tests by partially recreating app level functions
called by appbridge in rpython

diff --git a/pypy/module/micronumpy/descriptor.py 
b/pypy/module/micronumpy/descriptor.py
--- a/pypy/module/micronumpy/descriptor.py
+++ b/pypy/module/micronumpy/descriptor.py
@@ -816,8 +816,8 @@
 def _usefields(space, w_dict, align):
 # Only for testing, a shortened version of the real _usefields
 allfields = []
-for fname in w_dict.iterkeys().iterator:
-obj = _get_list_or_none(space, w_dict, fname)
+for fname_w in space.unpackiterable(w_dict):
+obj = _get_list_or_none(space, w_dict, space.str_w(fname_w))
 num = space.int_w(obj[1])
 if align:
 alignment = 0
@@ -828,8 +828,8 @@
 title = space.wrap(obj[2])
 else:
 title = space.w_None
-allfields.append((space.wrap(fname), format, num, title))
-allfields.sort(key=lambda x: x[2])
+allfields.append((fname_w, format, num, title))
+#allfields.sort(key=lambda x: x[2])
 names   = [space.newtuple([x[0], x[3]]) for x in allfields]
 formats = [x[1] for x in allfields]
 offsets = [x[2] for x in allfields]
@@ -853,12 +853,14 @@
 aligned_w = _get_val_or_none(space, w_dict, 'aligned')
 itemsize_w = _get_val_or_none(space, w_dict, 'itemsize')
 if names_w is None or formats_w is None:
-if we_are_translated():
+try:
 return get_appbridge_cache(space).call_method(space,
 'numpy.core._internal', '_usefields', Arguments(space, 
 [w_dict, space.wrap(alignment >= 0)]))
-else:
-return _usefields(space, w_dict, alignment >= 0)
+except OperationError as e:
+if e.match(space, space.w_ImportError):
+return _usefields(space, w_dict, alignment >= 0)
+raise
 n = len(names_w)
 if (n != len(formats_w) or 
 (offsets_w is not None and n != len(offsets_w)) or
@@ -898,16 +900,17 @@
 
 def dtype_from_spec(space, w_spec, alignment):
 
-if we_are_translated():
+w_lst = w_spec
+try:
 w_lst = get_appbridge_cache(space).call_method(space,
 'numpy.core._internal', '_commastring', Arguments(space, [w_spec]))
-else:
+except OperationError as e:
+if not e.match(space, space.w_ImportError):
+raise
 # handle only simple cases for testing
 if space.isinstance_w(w_spec, space.w_str):
 spec = [s.strip() for s in space.str_w(w_spec).split(',')]
 w_lst = space.newlist([space.wrap(s) for s in spec]) 
-elif space.isinstance_w(w_spec, space.w_list):
-w_lst = w_spec
 if not space.isinstance_w(w_lst, space.w_list) or space.len_w(w_lst) < 1:
 raise oefmt(space.w_RuntimeError,
 "_commastring is not returning a list with len >= 1")
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy anntype2: Use @doubledispatch for intersection() and difference()

2015-11-22 Thread rlamy
Author: Ronan Lamy 
Branch: anntype2
Changeset: r80841:5acb90f641dd
Date: 2015-11-23 04:51 +
http://bitbucket.org/pypy/pypy/changeset/5acb90f641dd/

Log:Use @doubledispatch for intersection() and difference()

diff --git a/rpython/annotator/annrpython.py b/rpython/annotator/annrpython.py
--- a/rpython/annotator/annrpython.py
+++ b/rpython/annotator/annrpython.py
@@ -11,7 +11,7 @@
 from rpython.translator import simplify, transform
 from rpython.annotator import model as annmodel, signature
 from rpython.annotator.model import (
-typeof, s_ImpossibleValue, SomeInstance)
+typeof, s_ImpossibleValue, SomeInstance, intersection, difference)
 from rpython.annotator.bookkeeper import Bookkeeper
 from rpython.rtyper.normalizecalls import perform_normalizations
 
@@ -497,14 +497,14 @@
 if s_exception == s_ImpossibleValue:
 break
 s_case = SomeInstance(self.bookkeeper.getuniqueclassdef(case))
-s_matching_exc = s_exception.intersection(s_case)
+s_matching_exc = intersection(s_exception, s_case)
 if s_matching_exc != s_ImpossibleValue:
 self.follow_raise_link(graph, link, s_matching_exc)
-s_exception = s_exception.difference(s_case)
+s_exception = difference(s_exception, s_case)
 else:
 if isinstance(block.exitswitch, Variable):
-knowntypedata = getattr(block.exitswitch.annotation,
-"knowntypedata", {})
+knowntypedata = getattr(
+block.exitswitch.annotation, "knowntypedata", {})
 else:
 knowntypedata = {}
 for link in exits:
diff --git a/rpython/annotator/model.py b/rpython/annotator/model.py
--- a/rpython/annotator/model.py
+++ b/rpython/annotator/model.py
@@ -36,7 +36,7 @@
 
 import rpython
 from rpython.tool import descriptor
-from rpython.tool.pairtype import pair, extendabletype
+from rpython.tool.pairtype import pair, extendabletype, doubledispatch
 from rpython.rlib.rarithmetic import r_uint, base_int, r_singlefloat, 
r_longfloat
 
 
@@ -129,6 +129,16 @@
 def nonnoneify(self):
 return self
 
+@doubledispatch
+def intersection(s_obj1, s_obj2):
+"""Return the intersection of two annotations, or an over-approximation 
thereof"""
+raise NotImplementedError
+
+@doubledispatch
+def difference(s_obj1, s_obj2):
+"""Return the set difference of two annotations, or an over-approximation 
thereof"""
+raise NotImplementedError
+
 
 class SomeType(SomeObject):
 "Stands for a type.  We might not be sure which one it is."
@@ -445,23 +455,6 @@
 else:
 return None
 
-def intersection(self, other):
-assert isinstance(other, SomeInstance)
-can_be_None = self.can_be_None and other.can_be_None
-if self.classdef.issubclass(other.classdef):
-return SomeInstance(self.classdef, can_be_None=can_be_None)
-elif other.classdef.issubclass(self.classdef):
-return SomeInstance(other.classdef, can_be_None=can_be_None)
-else:
-return s_ImpossibleValue
-
-def difference(self, other):
-assert isinstance(other, SomeInstance)
-if self.classdef.issubclass(other.classdef):
-return s_ImpossibleValue
-else:
-return self
-
 def can_be_none(self):
 return self.can_be_None
 
@@ -471,30 +464,52 @@
 def noneify(self):
 return SomeInstance(self.classdef, can_be_None=True)
 
+@intersection.register(SomeInstance, SomeInstance)
+def intersection_Instance(s_inst1, s_inst2):
+can_be_None = s_inst1.can_be_None and s_inst2.can_be_None
+if s_inst1.classdef.issubclass(s_inst2.classdef):
+return SomeInstance(s_inst1.classdef, can_be_None=can_be_None)
+elif s_inst2.classdef.issubclass(s_inst1.classdef):
+return SomeInstance(s_inst2.classdef, can_be_None=can_be_None)
+else:
+return s_ImpossibleValue
+
+@difference.register(SomeInstance, SomeInstance)
+def difference_Instance_Instance(s_inst1, s_inst2):
+if s_inst1.classdef.issubclass(s_inst2.classdef):
+return s_ImpossibleValue
+else:
+return s_inst1
+
+
 class SomeException(SomeObject):
 """The set of exceptions obeying type(exc) in self.classes"""
 def __init__(self, classdefs):
 self.classdefs = classdefs
 
-def intersection(self, other):
-assert isinstance(other, SomeInstance)
-classdefs = {c for c in self.classdefs if c.issubclass(other.classdef)}
-if classdefs:
-return SomeException(classdefs)
-else:
-return s_ImpossibleValue
-
-def difference(self, other):
-assert isinstance(other, SomeInstance)
-classdefs = {c for c in self.classdefs if not 
c.issubclass(other.classdef)}
-if classdefs:
-return SomeException(cl

[pypy-commit] pypy anntype2: Implement @doubledispatch decorator

2015-11-22 Thread rlamy
Author: Ronan Lamy 
Branch: anntype2
Changeset: r80840:d8221802192d
Date: 2015-11-23 02:13 +
http://bitbucket.org/pypy/pypy/changeset/d8221802192d/

Log:Implement @doubledispatch decorator

diff --git a/rpython/tool/pairtype.py b/rpython/tool/pairtype.py
--- a/rpython/tool/pairtype.py
+++ b/rpython/tool/pairtype.py
@@ -94,3 +94,40 @@
 def __setitem__(self, clspair, value):
 self._registry[clspair] = value
 self._cache = self._registry.copy()
+
+def doubledispatch(func):
+"""
+Decorator returning a double-dispatch function
+
+Usage
+-
+>>> @doubledispatch
+... def func(x, y):
+... return 0
+>>> @func.register(basestring, basestring)
+... def func_string_string(x, y):
+... return 42
+>>> func(1, 2)
+0
+>>> func('x', u'y')
+42
+"""
+return DoubleDispatchFunction(func)
+
+class DoubleDispatchFunction(object):
+def __init__(self, func):
+self._registry = DoubleDispatchRegistry()
+self._default = func
+
+def __call__(self, arg1, arg2, *args, **kwargs):
+try:
+func = self._registry[type(arg1), type(arg2)]
+except KeyError:
+func = self._default
+return func(arg1, arg2, *args, **kwargs)
+
+def register(self, cls1, cls2):
+def decorator(func):
+self._registry[cls1, cls2] = func
+return func
+return decorator
diff --git a/rpython/tool/test/test_pairtype.py 
b/rpython/tool/test/test_pairtype.py
--- a/rpython/tool/test/test_pairtype.py
+++ b/rpython/tool/test/test_pairtype.py
@@ -1,5 +1,6 @@
 from rpython.tool.pairtype import (
-pairtype, pair, extendabletype, pairmro, DoubleDispatchRegistry)
+pairtype, pair, extendabletype, pairmro, DoubleDispatchRegistry,
+doubledispatch)
 
 def test_binop():
 ### Binary operation example
@@ -115,7 +116,7 @@
 parent_pairtypes = pairtype(A3, B2).__mro__[:-2]
 assert (tuple(pairtype(a, b) for a, b in pairmro(A3, B2)) == 
parent_pairtypes)
 
-def test_doubledispatch():
+def test_doubledispatch_registry():
 class A(object): pass
 class A2(A): pass
 class A3(A2): pass
@@ -129,3 +130,15 @@
 assert reg[A3, B2] == "A2-B2"
 reg[A3, B] = "A3-B"
 assert reg[A3, B2] == "A2-B2"  # note that A2,B2 wins over A3,B
+
+def test_doubledispatch_function():
+@doubledispatch
+def f(x, y, z):
+return z
+
+@f.register(int, int)
+def f_int(x, y, z):
+return 42
+
+assert f(1., 1., 0) == 0
+assert f(1, 1, 0) == 42
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy s390x-backend: merged default

2015-11-22 Thread plan_rich
Author: Richard Plangger 
Branch: s390x-backend
Changeset: r80842:7372febfd770
Date: 2015-11-23 08:17 +0100
http://bitbucket.org/pypy/pypy/changeset/7372febfd770/

Log:merged default

diff too long, truncating to 2000 out of 2102 lines

diff --git a/lib_pypy/greenlet.py b/lib_pypy/greenlet.py
--- a/lib_pypy/greenlet.py
+++ b/lib_pypy/greenlet.py
@@ -88,9 +88,19 @@
 #
 try:
 unbound_method = getattr(_continulet, methodname)
+_tls.leaving = current
 args, kwds = unbound_method(current, *baseargs, to=target)
-finally:
 _tls.current = current
+except:
+_tls.current = current
+if hasattr(_tls, 'trace'):
+_run_trace_callback('throw')
+_tls.leaving = None
+raise
+else:
+if hasattr(_tls, 'trace'):
+_run_trace_callback('switch')
+_tls.leaving = None
 #
 if kwds:
 if args:
@@ -122,6 +132,34 @@
 return f.f_back.f_back.f_back   # go past start(), __switch(), switch()
 
 # 
+# Recent additions
+
+GREENLET_USE_GC = True
+GREENLET_USE_TRACING = True
+
+def gettrace():
+return getattr(_tls, 'trace', None)
+
+def settrace(callback):
+try:
+prev = _tls.trace
+del _tls.trace
+except AttributeError:
+prev = None
+if callback is not None:
+_tls.trace = callback
+return prev
+
+def _run_trace_callback(event):
+try:
+_tls.trace(event, (_tls.leaving, _tls.current))
+except:
+# In case of exceptions trace function is removed
+if hasattr(_tls, 'trace'):
+del _tls.trace
+raise
+
+# 
 # Internal stuff
 
 try:
@@ -143,22 +181,32 @@
 _tls.current = gmain
 
 def _greenlet_start(greenlet, args):
-args, kwds = args
-_tls.current = greenlet
 try:
-res = greenlet.run(*args, **kwds)
-except GreenletExit, e:
-res = e
+args, kwds = args
+_tls.current = greenlet
+try:
+if hasattr(_tls, 'trace'):
+_run_trace_callback('switch')
+res = greenlet.run(*args, **kwds)
+except GreenletExit, e:
+res = e
+finally:
+_continuation.permute(greenlet, greenlet.parent)
+return ((res,), None)
 finally:
-_continuation.permute(greenlet, greenlet.parent)
-return ((res,), None)
+_tls.leaving = greenlet
 
 def _greenlet_throw(greenlet, exc, value, tb):
-_tls.current = greenlet
 try:
-raise exc, value, tb
-except GreenletExit, e:
-res = e
+_tls.current = greenlet
+try:
+if hasattr(_tls, 'trace'):
+_run_trace_callback('throw')
+raise exc, value, tb
+except GreenletExit, e:
+res = e
+finally:
+_continuation.permute(greenlet, greenlet.parent)
+return ((res,), None)
 finally:
-_continuation.permute(greenlet, greenlet.parent)
-return ((res,), None)
+_tls.leaving = greenlet
diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst
--- a/pypy/doc/whatsnew-head.rst
+++ b/pypy/doc/whatsnew-head.rst
@@ -1,7 +1,18 @@
 =
-What's new in PyPy 4.0.+
+What's new in PyPy 4.1.+
 =
 
 .. this is a revision shortly after release-4.0.1
 .. startrev: 4b5c840d0da2
 
+.. branch: numpy-1.10
+
+Fix tests to run cleanly with -A and start to fix micronumpy for upstream numpy
+which is now 1.10.2
+
+.. branch: osx-flat-namespace
+
+Fix the cpyext tests on OSX by linking with -flat_namespace
+
+.. branch: anntype
+Refactor and improve exception analysis in the annotator.
diff --git a/pypy/goal/targetpypystandalone.py 
b/pypy/goal/targetpypystandalone.py
--- a/pypy/goal/targetpypystandalone.py
+++ b/pypy/goal/targetpypystandalone.py
@@ -302,7 +302,7 @@
 
 def hack_for_cffi_modules(self, driver):
 # HACKHACKHACK
-# ugly hack to modify target goal from compile_c to build_cffi_imports
+# ugly hack to modify target goal from compile_* to build_cffi_imports
 # this should probably get cleaned up and merged with driver.create_exe
 from rpython.translator.driver import taskdef
 import types
@@ -316,7 +316,8 @@
 name = name.new(ext='exe')
 return name
 
-@taskdef(['compile_c'], "Create cffi bindings for modules")
+compile_goal, = driver.backend_select_goals(['compile'])
+@taskdef([compile_goal], "Create cffi bindings for modules")
 def task_build_cffi_imports(self):
 from pypy.tool.build_cffi_imports import 
create_cffi_import_libraries
 ''' Use cffi to compile cffi interfaces to modules'''
@@ -335,7 +336,7 @@
 # if failures, they

[pypy-commit] pypy s390x-backend: reverted change

2015-11-22 Thread plan_rich
Author: Richard Plangger 
Branch: s390x-backend
Changeset: r80843:f7d1843208b9
Date: 2015-11-23 08:17 +0100
http://bitbucket.org/pypy/pypy/changeset/f7d1843208b9/

Log:reverted change

diff --git a/rpython/annotator/model.py b/rpython/annotator/model.py
--- a/rpython/annotator/model.py
+++ b/rpython/annotator/model.py
@@ -461,7 +461,7 @@
 
 def intersection(self, other):
 assert isinstance(other, SomeExceptCase)
-classdefs = {c:None for c in self.classdefs if 
c.issubclass(other.case)}
+classdefs = {c for c in self.classdefs if c.issubclass(other.case)}
 if classdefs:
 return SomeException(classdefs)
 else:
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: reverted 2.7 {k for k ...} set syntax to an explicit for loop + set init. (s390x machine only has cpython 2.6 installed)

2015-11-22 Thread plan_rich
Author: Richard Plangger 
Branch: 
Changeset: r80844:95fa20db8791
Date: 2015-11-23 08:22 +0100
http://bitbucket.org/pypy/pypy/changeset/95fa20db8791/

Log:reverted 2.7 {k for k ...} set syntax to an explicit for loop + set
init. (s390x machine only has cpython 2.6 installed)

diff --git a/rpython/annotator/model.py b/rpython/annotator/model.py
--- a/rpython/annotator/model.py
+++ b/rpython/annotator/model.py
@@ -461,7 +461,10 @@
 
 def intersection(self, other):
 assert isinstance(other, SomeExceptCase)
-classdefs = {c for c in self.classdefs if c.issubclass(other.case)}
+classdefs = set()
+for c in self.classdefs:
+if c.issubclass(other.case):
+classdefs.add(c)
 if classdefs:
 return SomeException(classdefs)
 else:
@@ -469,7 +472,10 @@
 
 def difference(self, other):
 assert isinstance(other, SomeExceptCase)
-classdefs = {c for c in self.classdefs if not c.issubclass(other.case)}
+classdefs = set()
+for c in self.classdefs:
+if not c.issubclass(other.case):
+classdefs.add(c)
 if classdefs:
 return SomeException(classdefs)
 else:
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: yet another {k for k ...} set syntax converted to an explicit for loop

2015-11-22 Thread plan_rich
Author: Richard Plangger 
Branch: 
Changeset: r80846:856bc46f9525
Date: 2015-11-23 08:25 +0100
http://bitbucket.org/pypy/pypy/changeset/856bc46f9525/

Log:yet another {k for k ...} set syntax converted to an explicit for
loop

diff --git a/rpython/annotator/bookkeeper.py b/rpython/annotator/bookkeeper.py
--- a/rpython/annotator/bookkeeper.py
+++ b/rpython/annotator/bookkeeper.py
@@ -168,7 +168,9 @@
 return desc.getuniqueclassdef()
 
 def new_exception(self, exc_classes):
-clsdefs = {self.getuniqueclassdef(cls) for cls in exc_classes}
+clsdefs = set()
+for cls in exc_classes:
+clsdefs.add(self.getuniqueclassdef(cls))
 return SomeException(clsdefs)
 
 def getlistdef(self, **flags_if_new):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy s390x-backend: merged default

2015-11-22 Thread plan_rich
Author: Richard Plangger 
Branch: s390x-backend
Changeset: r80845:ec399b39378a
Date: 2015-11-23 08:22 +0100
http://bitbucket.org/pypy/pypy/changeset/ec399b39378a/

Log:merged default

diff --git a/rpython/annotator/model.py b/rpython/annotator/model.py
--- a/rpython/annotator/model.py
+++ b/rpython/annotator/model.py
@@ -461,7 +461,10 @@
 
 def intersection(self, other):
 assert isinstance(other, SomeExceptCase)
-classdefs = {c for c in self.classdefs if c.issubclass(other.case)}
+classdefs = set()
+for c in self.classdefs:
+if c.issubclass(other.case):
+classdefs.add(c)
 if classdefs:
 return SomeException(classdefs)
 else:
@@ -469,7 +472,10 @@
 
 def difference(self, other):
 assert isinstance(other, SomeExceptCase)
-classdefs = {c for c in self.classdefs if not c.issubclass(other.case)}
+classdefs = set()
+for c in self.classdefs:
+if not c.issubclass(other.case):
+classdefs.add(c)
 if classdefs:
 return SomeException(classdefs)
 else:
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy s390x-backend: merged default

2015-11-22 Thread plan_rich
Author: Richard Plangger 
Branch: s390x-backend
Changeset: r80847:4dcc42d4c820
Date: 2015-11-23 08:28 +0100
http://bitbucket.org/pypy/pypy/changeset/4dcc42d4c820/

Log:merged default

diff --git a/rpython/annotator/bookkeeper.py b/rpython/annotator/bookkeeper.py
--- a/rpython/annotator/bookkeeper.py
+++ b/rpython/annotator/bookkeeper.py
@@ -168,7 +168,9 @@
 return desc.getuniqueclassdef()
 
 def new_exception(self, exc_classes):
-clsdefs = {self.getuniqueclassdef(cls) for cls in exc_classes}
+clsdefs = set()
+for cls in exc_classes:
+clsdefs.add(self.getuniqueclassdef(cls))
 return SomeException(clsdefs)
 
 def getlistdef(self, **flags_if_new):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: reverted previous changes (did not know we do not support 2.6 anymore)

2015-11-22 Thread plan_rich
Author: Richard Plangger 
Branch: 
Changeset: r80848:ed910c5221d9
Date: 2015-11-23 08:48 +0100
http://bitbucket.org/pypy/pypy/changeset/ed910c5221d9/

Log:reverted previous changes (did not know we do not support 2.6
anymore)

diff --git a/rpython/annotator/bookkeeper.py b/rpython/annotator/bookkeeper.py
--- a/rpython/annotator/bookkeeper.py
+++ b/rpython/annotator/bookkeeper.py
@@ -168,9 +168,7 @@
 return desc.getuniqueclassdef()
 
 def new_exception(self, exc_classes):
-clsdefs = set()
-for cls in exc_classes:
-clsdefs.add(self.getuniqueclassdef(cls))
+clsdefs = {self.getuniqueclassdef(cls) for cls in exc_classes}
 return SomeException(clsdefs)
 
 def getlistdef(self, **flags_if_new):
diff --git a/rpython/annotator/model.py b/rpython/annotator/model.py
--- a/rpython/annotator/model.py
+++ b/rpython/annotator/model.py
@@ -461,10 +461,7 @@
 
 def intersection(self, other):
 assert isinstance(other, SomeExceptCase)
-classdefs = set()
-for c in self.classdefs:
-if c.issubclass(other.case):
-classdefs.add(c)
+classdefs = {c for c in self.classdefs if c.issubclass(other.case)}
 if classdefs:
 return SomeException(classdefs)
 else:
@@ -472,10 +469,7 @@
 
 def difference(self, other):
 assert isinstance(other, SomeExceptCase)
-classdefs = set()
-for c in self.classdefs:
-if not c.issubclass(other.case):
-classdefs.add(c)
+classdefs = {c for c in self.classdefs if not c.issubclass(other.case)}
 if classdefs:
 return SomeException(classdefs)
 else:
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy s390x-backend: merged default

2015-11-22 Thread plan_rich
Author: Richard Plangger 
Branch: s390x-backend
Changeset: r80849:d454a5a7d9cd
Date: 2015-11-23 08:48 +0100
http://bitbucket.org/pypy/pypy/changeset/d454a5a7d9cd/

Log:merged default

diff --git a/rpython/annotator/bookkeeper.py b/rpython/annotator/bookkeeper.py
--- a/rpython/annotator/bookkeeper.py
+++ b/rpython/annotator/bookkeeper.py
@@ -168,9 +168,7 @@
 return desc.getuniqueclassdef()
 
 def new_exception(self, exc_classes):
-clsdefs = set()
-for cls in exc_classes:
-clsdefs.add(self.getuniqueclassdef(cls))
+clsdefs = {self.getuniqueclassdef(cls) for cls in exc_classes}
 return SomeException(clsdefs)
 
 def getlistdef(self, **flags_if_new):
diff --git a/rpython/annotator/model.py b/rpython/annotator/model.py
--- a/rpython/annotator/model.py
+++ b/rpython/annotator/model.py
@@ -461,10 +461,7 @@
 
 def intersection(self, other):
 assert isinstance(other, SomeExceptCase)
-classdefs = set()
-for c in self.classdefs:
-if c.issubclass(other.case):
-classdefs.add(c)
+classdefs = {c for c in self.classdefs if c.issubclass(other.case)}
 if classdefs:
 return SomeException(classdefs)
 else:
@@ -472,10 +469,7 @@
 
 def difference(self, other):
 assert isinstance(other, SomeExceptCase)
-classdefs = set()
-for c in self.classdefs:
-if not c.issubclass(other.case):
-classdefs.add(c)
+classdefs = {c for c in self.classdefs if not c.issubclass(other.case)}
 if classdefs:
 return SomeException(classdefs)
 else:
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit