Author: Armin Rigo <ar...@tunes.org> Branch: Changeset: r68957:76462f1c604c Date: 2014-01-26 22:29 +0100 http://bitbucket.org/pypy/pypy/changeset/76462f1c604c/
Log: merge heads diff --git a/pypy/doc/faq.rst b/pypy/doc/faq.rst --- a/pypy/doc/faq.rst +++ b/pypy/doc/faq.rst @@ -426,25 +426,12 @@ Could we use LLVM? ------------------ -In theory yes. But we tried to use it 5 or 6 times already, as a -translation backend or as a JIT backend --- and failed each time. +There is a (static) translation backend using LLVM in the branch +``llvm-translation-backend``. It can translate PyPy with or without the JIT on +Linux. -In more details: using LLVM as a (static) translation backend is -pointless nowadays because you can generate C code and compile it with -clang. (Note that compiling PyPy with clang gives a result that is not -faster than compiling it with gcc.) We might in theory get extra -benefits from LLVM's GC integration, but this requires more work on the -LLVM side before it would be remotely useful. Anyway, it could be -interfaced via a custom primitive in the C code. - -On the other hand, using LLVM as our JIT backend looks interesting as -well --- but again we made an attempt, and it failed: LLVM has no way to -patch the generated machine code. - -So the position of the core PyPy developers is that if anyone wants to -make an N+1'th attempt with LLVM, they are welcome, and will be happy to -provide help in the IRC channel, but they are left with the burden of proof -that (a) it works and (b) it gives important benefits. +Using LLVM as our JIT backend looks interesting as well -- we made an attempt, +but it failed: LLVM has no way to patch the generated machine code. ---------------------- How do I compile PyPy? diff --git a/pypy/module/cpyext/include/pyconfig.h b/pypy/module/cpyext/include/pyconfig.h --- a/pypy/module/cpyext/include/pyconfig.h +++ b/pypy/module/cpyext/include/pyconfig.h @@ -15,6 +15,8 @@ #define HAVE_UNICODE #define WITHOUT_COMPLEX #define HAVE_WCHAR_H 1 +#define HAVE_SYS_TYPES_H 1 +#define HAVE_SYS_STAT_H 1 /* PyPy supposes Py_UNICODE == wchar_t */ #define HAVE_USABLE_WCHAR_T 1 diff --git a/pypy/module/cpyext/include/pyport.h b/pypy/module/cpyext/include/pyport.h --- a/pypy/module/cpyext/include/pyport.h +++ b/pypy/module/cpyext/include/pyport.h @@ -64,4 +64,45 @@ # error "Python needs a typedef for Py_uintptr_t in pyport.h." #endif /* HAVE_UINTPTR_T */ +/******************************* + * stat() and fstat() fiddling * + *******************************/ + +/* We expect that stat and fstat exist on most systems. + * It's confirmed on Unix, Mac and Windows. + * If you don't have them, add + * #define DONT_HAVE_STAT + * and/or + * #define DONT_HAVE_FSTAT + * to your pyconfig.h. Python code beyond this should check HAVE_STAT and + * HAVE_FSTAT instead. + * Also + * #define HAVE_SYS_STAT_H + * if <sys/stat.h> exists on your platform, and + * #define HAVE_STAT_H + * if <stat.h> does. + */ +#ifndef DONT_HAVE_STAT +#define HAVE_STAT +#endif + +#ifndef DONT_HAVE_FSTAT +#define HAVE_FSTAT +#endif + +#ifdef RISCOS +#include <sys/types.h> +#include "unixstuff.h" +#endif + +#ifdef HAVE_SYS_STAT_H +#if defined(PYOS_OS2) && defined(PYCC_GCC) +#include <sys/types.h> +#endif +#include <sys/stat.h> +#elif defined(HAVE_STAT_H) +#include <stat.h> +#else +#endif + #endif /* Py_PYPORT_H */ diff --git a/rpython/annotator/binaryop.py b/rpython/annotator/binaryop.py --- a/rpython/annotator/binaryop.py +++ b/rpython/annotator/binaryop.py @@ -10,10 +10,11 @@ SomeDict, SomeOrderedDict, SomeUnicodeCodePoint, SomeUnicodeString, SomeTuple, SomeImpossibleValue, s_ImpossibleValue, SomeInstance, SomeBuiltin, SomeIterator, SomePBC, SomeFloat, s_None, SomeByteArray, - SomeWeakRef, SomeAddress, SomeTypedAddressAccess, SomeSingleFloat, + SomeWeakRef, SomeSingleFloat, SomeLongFloat, SomeType, SomeConstantType, unionof, UnionError, read_can_only_throw, add_knowntypedata, merge_knowntypedata,) +from rpython.rtyper.llannotation import SomeAddress, SomeTypedAddressAccess from rpython.annotator.bookkeeper import getbookkeeper from rpython.flowspace.model import Variable, Constant from rpython.flowspace.operation import op diff --git a/rpython/annotator/bookkeeper.py b/rpython/annotator/bookkeeper.py --- a/rpython/annotator/bookkeeper.py +++ b/rpython/annotator/bookkeeper.py @@ -9,10 +9,11 @@ from rpython.flowspace.model import Constant from rpython.annotator.model import (SomeOrderedDict, SomeString, SomeChar, SomeFloat, SomePtr, unionof, SomeInstance, SomeDict, - SomeBuiltin, SomePBC, SomeInteger, TLS, SomeAddress, SomeUnicodeCodePoint, + SomeBuiltin, SomePBC, SomeInteger, TLS, SomeUnicodeCodePoint, s_None, s_ImpossibleValue, SomeLLADTMeth, SomeBool, SomeTuple, SomeImpossibleValue, SomeUnicodeString, SomeList, HarmlesslyBlocked, SomeWeakRef, lltype_to_annotation, SomeType, SomeByteArray, SomeConstantType) +from rpython.rtyper.llannotation import SomeAddress from rpython.annotator.classdef import InstanceSource, ClassDef from rpython.annotator.listdef import ListDef, ListItem from rpython.annotator.dictdef import DictDef diff --git a/rpython/annotator/builtin.py b/rpython/annotator/builtin.py --- a/rpython/annotator/builtin.py +++ b/rpython/annotator/builtin.py @@ -5,11 +5,12 @@ from rpython.annotator.model import ( SomeInteger, SomeObject, SomeChar, SomeBool, SomeString, SomeTuple, s_Bool, - SomeUnicodeCodePoint, SomeAddress, SomeFloat, unionof, SomeUnicodeString, + SomeUnicodeCodePoint, SomeFloat, unionof, SomeUnicodeString, SomePBC, SomeInstance, SomeDict, SomeList, SomeWeakRef, SomeIterator, SomeOrderedDict, SomeByteArray, annotation_to_lltype, lltype_to_annotation, ll_to_annotation, add_knowntypedata, s_ImpossibleValue,) +from rpython.rtyper.llannotation import SomeAddress from rpython.annotator.bookkeeper import getbookkeeper from rpython.annotator import description from rpython.flowspace.model import Constant diff --git a/rpython/annotator/model.py b/rpython/annotator/model.py --- a/rpython/annotator/model.py +++ b/rpython/annotator/model.py @@ -568,33 +568,6 @@ # 'classdef' is None for known-to-be-dead weakrefs. self.classdef = classdef -# ____________________________________________________________ -# memory addresses - -from rpython.rtyper.lltypesystem import llmemory - - -class SomeAddress(SomeObject): - immutable = True - - def can_be_none(self): - return False - - def is_null_address(self): - return self.is_immutable_constant() and not self.const - - -# The following class is used to annotate the intermediate value that -# appears in expressions of the form: -# addr.signed[offset] and addr.signed[offset] = value - -class SomeTypedAddressAccess(SomeObject): - def __init__(self, type): - self.type = type - - def can_be_none(self): - return False - #____________________________________________________________ # annotation of low-level types @@ -630,6 +603,8 @@ return False +from rpython.rtyper.llannotation import SomeAddress +from rpython.rtyper.lltypesystem import llmemory annotation_to_ll_map = [ (SomeSingleFloat(), lltype.SingleFloat), diff --git a/rpython/annotator/unaryop.py b/rpython/annotator/unaryop.py --- a/rpython/annotator/unaryop.py +++ b/rpython/annotator/unaryop.py @@ -9,9 +9,10 @@ from rpython.annotator.model import (SomeObject, SomeInteger, SomeBool, SomeString, SomeChar, SomeList, SomeDict, SomeTuple, SomeImpossibleValue, SomeUnicodeCodePoint, SomeInstance, SomeBuiltin, SomeFloat, SomeIterator, - SomePBC, SomeTypedAddressAccess, SomeAddress, SomeType, s_ImpossibleValue, + SomePBC, SomeType, s_ImpossibleValue, s_Bool, s_None, unionof, add_knowntypedata, HarmlesslyBlocked, SomeWeakRef, SomeUnicodeString, SomeByteArray) +from rpython.rtyper.llannotation import SomeAddress, SomeTypedAddressAccess from rpython.annotator.bookkeeper import getbookkeeper from rpython.annotator import builtin from rpython.annotator.binaryop import _clone ## XXX where to put this? diff --git a/rpython/memory/gctransform/asmgcroot.py b/rpython/memory/gctransform/asmgcroot.py --- a/rpython/memory/gctransform/asmgcroot.py +++ b/rpython/memory/gctransform/asmgcroot.py @@ -7,6 +7,7 @@ from rpython.rtyper.lltypesystem.lloperation import llop from rpython.memory.gctransform.framework import ( BaseFrameworkGCTransformer, BaseRootWalker) +from rpython.rtyper.llannotation import SomeAddress from rpython.rtyper.rbuiltin import gen_cast from rpython.translator.unsimplify import copyvar, varoftype from rpython.translator.tool.cbuild import ExternalCompilationInfo @@ -215,7 +216,7 @@ # update the global stack counter rffi.stackcounter.stacks_counter += 1 # - s_addr = annmodel.SomeAddress() + s_addr = SomeAddress() s_None = annmodel.s_None self.gc_detach_callback_pieces_ptr = getfn(gc_detach_callback_pieces, [], s_addr) @@ -327,10 +328,10 @@ inline=True) self.thread_die_ptr = getfn(thread_die, [], annmodel.s_None) self.thread_before_fork_ptr = getfn(thread_before_fork, [], - annmodel.SomeAddress()) + SomeAddress()) self.thread_after_fork_ptr = getfn(thread_after_fork, [annmodel.SomeInteger(), - annmodel.SomeAddress()], + SomeAddress()], annmodel.s_None) # # check that the order of the need_*() is correct for us: if we @@ -496,7 +497,7 @@ # location -- but we check for consistency that ebp points # to a JITFRAME object. from rpython.jit.backend.llsupport.jitframe import STACK_DEPTH_OFS - + tid = self.gc.get_possibly_forwarded_type_id(ebp_in_caller) ll_assert(rffi.cast(lltype.Signed, tid) == rffi.cast(lltype.Signed, self.frame_tid), diff --git a/rpython/memory/gctransform/framework.py b/rpython/memory/gctransform/framework.py --- a/rpython/memory/gctransform/framework.py +++ b/rpython/memory/gctransform/framework.py @@ -1,4 +1,5 @@ from rpython.annotator import model as annmodel +from rpython.rtyper.llannotation import SomeAddress from rpython.rlib import rgc from rpython.rtyper import rmodel, annlowlevel from rpython.rtyper.lltypesystem import lltype, llmemory, rffi, llgroup @@ -195,21 +196,11 @@ # the point of this little dance is to not annotate # self.gcdata.static_root_xyz as constants. XXX is it still needed?? data_classdef = bk.getuniqueclassdef(gctypelayout.GCData) - data_classdef.generalize_attr( - 'static_root_start', - annmodel.SomeAddress()) - data_classdef.generalize_attr( - 'static_root_nongcend', - annmodel.SomeAddress()) - data_classdef.generalize_attr( - 'static_root_end', - annmodel.SomeAddress()) - data_classdef.generalize_attr( - 'max_type_id', - annmodel.SomeInteger()) - data_classdef.generalize_attr( - 'typeids_z', - annmodel.SomeAddress()) + data_classdef.generalize_attr('static_root_start', SomeAddress()) + data_classdef.generalize_attr('static_root_nongcend', SomeAddress()) + data_classdef.generalize_attr('static_root_end', SomeAddress()) + data_classdef.generalize_attr('max_type_id', annmodel.SomeInteger()) + data_classdef.generalize_attr('typeids_z', SomeAddress()) annhelper = annlowlevel.MixLevelHelperAnnotator(self.translator.rtyper) @@ -310,13 +301,13 @@ self.collect_ptr = getfn(GCClass.collect.im_func, [s_gc, annmodel.SomeInteger()], annmodel.s_None) self.can_move_ptr = getfn(GCClass.can_move.im_func, - [s_gc, annmodel.SomeAddress()], + [s_gc, SomeAddress()], annmodel.SomeBool()) if hasattr(GCClass, 'shrink_array'): self.shrink_array_ptr = getfn( GCClass.shrink_array.im_func, - [s_gc, annmodel.SomeAddress(), + [s_gc, SomeAddress(), annmodel.SomeInteger(nonneg=True)], annmodel.s_Bool) else: self.shrink_array_ptr = None @@ -333,7 +324,7 @@ if hasattr(GCClass, 'writebarrier_before_copy'): self.wb_before_copy_ptr = \ getfn(GCClass.writebarrier_before_copy.im_func, - [s_gc] + [annmodel.SomeAddress()] * 2 + + [s_gc] + [SomeAddress()] * 2 + [annmodel.SomeInteger()] * 3, annmodel.SomeBool()) elif GCClass.needs_write_barrier: raise NotImplementedError("GC needs write barrier, but does not provide writebarrier_before_copy functionality") @@ -421,7 +412,7 @@ if getattr(GCClass, 'obtain_free_space', False): self.obtainfreespace_ptr = getfn(GCClass.obtain_free_space.im_func, [s_gc, annmodel.SomeInteger()], - annmodel.SomeAddress()) + SomeAddress()) if GCClass.moving_gc: self.id_ptr = getfn(GCClass.id.im_func, @@ -470,8 +461,7 @@ self.write_barrier_from_array_ptr = None if GCClass.needs_write_barrier: self.write_barrier_ptr = getfn(GCClass.write_barrier.im_func, - [s_gc, - annmodel.SomeAddress()], + [s_gc, SomeAddress()], annmodel.s_None, inline=True) func = getattr(gcdata.gc, 'remember_young_pointer', None) @@ -479,13 +469,12 @@ # func should not be a bound method, but a real function assert isinstance(func, types.FunctionType) self.write_barrier_failing_case_ptr = getfn(func, - [annmodel.SomeAddress()], + [SomeAddress()], annmodel.s_None) func = getattr(GCClass, 'write_barrier_from_array', None) if func is not None: self.write_barrier_from_array_ptr = getfn(func.im_func, - [s_gc, - annmodel.SomeAddress(), + [s_gc, SomeAddress(), annmodel.SomeInteger()], annmodel.s_None, inline=True) @@ -497,7 +486,7 @@ assert isinstance(func, types.FunctionType) self.write_barrier_from_array_failing_case_ptr = \ getfn(func, - [annmodel.SomeAddress()], + [SomeAddress()], annmodel.s_None) diff --git a/rpython/memory/gctransform/shadowstack.py b/rpython/memory/gctransform/shadowstack.py --- a/rpython/memory/gctransform/shadowstack.py +++ b/rpython/memory/gctransform/shadowstack.py @@ -5,6 +5,7 @@ from rpython.rtyper import rmodel from rpython.rtyper.annlowlevel import llhelper from rpython.rtyper.lltypesystem import lltype, llmemory +from rpython.rtyper.llannotation import SomeAddress from rpython.memory.gctransform.framework import ( BaseFrameworkGCTransformer, BaseRootWalker, sizeofaddr) from rpython.rtyper.rbuiltin import gen_cast @@ -14,11 +15,11 @@ def annotate_walker_functions(self, getfn): self.incr_stack_ptr = getfn(self.root_walker.incr_stack, [annmodel.SomeInteger()], - annmodel.SomeAddress(), + SomeAddress(), inline = True) self.decr_stack_ptr = getfn(self.root_walker.decr_stack, [annmodel.SomeInteger()], - annmodel.SomeAddress(), + SomeAddress(), inline = True) def build_root_walker(self): @@ -211,7 +212,7 @@ # no thread_before_fork_ptr here self.thread_after_fork_ptr = getfn(thread_after_fork, [annmodel.SomeInteger(), - annmodel.SomeAddress()], + SomeAddress()], annmodel.s_None, minimal_transform=False) @@ -242,7 +243,7 @@ shadow_stack_pool.start_fresh_new_state() s_gcref = annmodel.SomePtr(llmemory.GCREF) - s_addr = annmodel.SomeAddress() + s_addr = SomeAddress() self.gc_shadowstackref_new_ptr = getfn(gc_shadowstackref_new, [], s_gcref, minimal_transform=False) diff --git a/rpython/rtyper/llannotation.py b/rpython/rtyper/llannotation.py new file mode 100644 --- /dev/null +++ b/rpython/rtyper/llannotation.py @@ -0,0 +1,26 @@ +""" +Code for annotating low-level thingies. +""" +from rpython.annotator.model import SomeObject + +class SomeAddress(SomeObject): + immutable = True + + def can_be_none(self): + return False + + def is_null_address(self): + return self.is_immutable_constant() and not self.const + +class SomeTypedAddressAccess(SomeObject): + """This class is used to annotate the intermediate value that + appears in expressions of the form: + addr.signed[offset] and addr.signed[offset] = value + """ + + def __init__(self, type): + self.type = type + + def can_be_none(self): + return False + diff --git a/rpython/rtyper/lltypesystem/llmemory.py b/rpython/rtyper/lltypesystem/llmemory.py --- a/rpython/rtyper/lltypesystem/llmemory.py +++ b/rpython/rtyper/lltypesystem/llmemory.py @@ -905,11 +905,12 @@ _about_ = raw_memmove def compute_result_annotation(self, s_from, s_to, s_size): - from rpython.annotator.model import SomeAddress, SomeInteger + from rpython.annotator.model import SomeInteger + from rpython.rtyper.llannotation import SomeAddress assert isinstance(s_from, SomeAddress) assert isinstance(s_to, SomeAddress) assert isinstance(s_size, SomeInteger) - + def specialize_call(self, hop): hop.exception_cannot_occur() v_list = hop.inputargs(Address, Address, lltype.Signed) diff --git a/rpython/rtyper/raddress.py b/rpython/rtyper/raddress.py --- a/rpython/rtyper/raddress.py +++ b/rpython/rtyper/raddress.py @@ -1,5 +1,5 @@ # rtyping of memory address operations -from rpython.annotator import model as annmodel +from rpython.rtyper.llannotation import SomeAddress, SomeTypedAddressAccess from rpython.rlib.rarithmetic import r_uint from rpython.rtyper.lltypesystem import lltype from rpython.rtyper.lltypesystem.llmemory import (NULL, Address, @@ -9,14 +9,14 @@ from rpython.tool.pairtype import pairtype -class __extend__(annmodel.SomeAddress): +class __extend__(SomeAddress): def rtyper_makerepr(self, rtyper): return address_repr def rtyper_makekey(self): return self.__class__, -class __extend__(annmodel.SomeTypedAddressAccess): +class __extend__(SomeTypedAddressAccess): def rtyper_makerepr(self, rtyper): return TypedAddressAccessRepr(self.type) diff --git a/rpython/rtyper/test/test_nongc.py b/rpython/rtyper/test/test_nongc.py --- a/rpython/rtyper/test/test_nongc.py +++ b/rpython/rtyper/test/test_nongc.py @@ -1,6 +1,7 @@ import py from rpython.annotator import model as annmodel +from rpython.rtyper.llannotation import SomeAddress from rpython.annotator.annrpython import RPythonAnnotator from rpython.rtyper.rtyper import RPythonTyper from rpython.rlib.objectmodel import free_non_gc_object @@ -25,7 +26,7 @@ assert t.method2() == 42 free_non_gc_object(t) py.test.raises(RuntimeError, "t.method1()") - py.test.raises(RuntimeError, "t.method2()") + py.test.raises(RuntimeError, "t.method2()") py.test.raises(RuntimeError, "t.a") py.test.raises(RuntimeError, "t.a = 1") py.test.raises(AssertionError, "free_non_gc_object(TestClass2())") @@ -43,8 +44,8 @@ rtyper = RPythonTyper(a) rtyper.specialize() assert (Adef, 'raw') in rtyper.instance_reprs - assert (Adef, 'gc') not in rtyper.instance_reprs - + assert (Adef, 'gc') not in rtyper.instance_reprs + def test_alloc_flavor_subclassing(): class A: _alloc_flavor_ = "raw" @@ -64,7 +65,7 @@ assert (Adef, 'raw') in rtyper.instance_reprs assert (Adef, 'gc') not in rtyper.instance_reprs assert (Bdef, 'raw') in rtyper.instance_reprs - assert (Bdef, 'gc') not in rtyper.instance_reprs + assert (Bdef, 'gc') not in rtyper.instance_reprs def test_unsupported(): class A: @@ -85,7 +86,7 @@ pass class C(B): pass - + def f(i): if i == 0: o = None @@ -226,7 +227,7 @@ return b a = RPythonAnnotator() #does not raise: - s = a.build_types(malloc_and_free, [annmodel.SomeAddress()]) - assert isinstance(s, annmodel.SomeAddress) + s = a.build_types(malloc_and_free, [SomeAddress()]) + assert isinstance(s, SomeAddress) rtyper = RPythonTyper(a) rtyper.specialize() _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit