Author: Armin Rigo <ar...@tunes.org> Branch: py3.5 Changeset: r89331:b6b06ee0fb56 Date: 2017-01-03 10:47 +0100 http://bitbucket.org/pypy/pypy/changeset/b6b06ee0fb56/
Log: hg merge default diff --git a/rpython/jit/codewriter/assembler.py b/rpython/jit/codewriter/assembler.py --- a/rpython/jit/codewriter/assembler.py +++ b/rpython/jit/codewriter/assembler.py @@ -5,6 +5,7 @@ from rpython.jit.codewriter.jitcode import SwitchDictDescr, JitCode from rpython.jit.codewriter import heaptracker, longlong from rpython.rlib.objectmodel import ComputedIntSymbolic +from rpython.rlib.rarithmetic import r_int from rpython.flowspace.model import Constant from rpython.rtyper.lltypesystem import lltype, llmemory, rffi from rpython.rtyper import rclass @@ -82,6 +83,8 @@ if not isinstance(value, (llmemory.AddressAsInt, ComputedIntSymbolic)): value = lltype.cast_primitive(lltype.Signed, value) + if type(value) is r_int: + value = int(value) if allow_short: try: short_num = -128 <= value <= 127 diff --git a/rpython/jit/codewriter/jitcode.py b/rpython/jit/codewriter/jitcode.py --- a/rpython/jit/codewriter/jitcode.py +++ b/rpython/jit/codewriter/jitcode.py @@ -1,6 +1,7 @@ from rpython.jit.metainterp.history import AbstractDescr, ConstInt from rpython.jit.codewriter import heaptracker from rpython.rlib.objectmodel import we_are_translated +from rpython.rlib.rarithmetic import base_int class JitCode(AbstractDescr): @@ -21,6 +22,10 @@ liveness=None, startpoints=None, alllabels=None, resulttypes=None): self.code = code + for x in constants_i: + assert not isinstance(x, base_int), ( + "found constant %r of type %r, must not appear in " + "JitCode.constants_i" % (x, type(x))) # if the following lists are empty, use a single shared empty list self.constants_i = constants_i or self._empty_i self.constants_r = constants_r or self._empty_r diff --git a/rpython/jit/codewriter/test/test_assembler.py b/rpython/jit/codewriter/test/test_assembler.py --- a/rpython/jit/codewriter/test/test_assembler.py +++ b/rpython/jit/codewriter/test/test_assembler.py @@ -7,6 +7,7 @@ from rpython.jit.metainterp.history import AbstractDescr from rpython.flowspace.model import Constant from rpython.rtyper.lltypesystem import lltype, llmemory +from rpython.rlib.rarithmetic import r_int, r_uint def test_assemble_simple(): @@ -239,3 +240,17 @@ ] assembler = Assembler() py.test.raises(AssemblerError, assembler.assemble, ssarepr) + +def test_assemble_r_int(): + # r_int is a strange type, which the jit should replace with int. + # r_uint is also replaced with int. + ssarepr = SSARepr("test") + i0, i1, i2 = Register('int', 0), Register('int', 1), Register('int', 2) + ssarepr.insns = [ + ('uint_add', i0, Constant(r_uint(42424242), lltype.Unsigned), '->', i1), + ('int_add', i0, Constant(r_int(42424243), lltype.Signed), '->', i2), + ] + assembler = Assembler() + jitcode = assembler.assemble(ssarepr) + assert jitcode.constants_i == [42424242, 42424243] + assert map(type, jitcode.constants_i) == [int, int] diff --git a/rpython/jit/metainterp/blackhole.py b/rpython/jit/metainterp/blackhole.py --- a/rpython/jit/metainterp/blackhole.py +++ b/rpython/jit/metainterp/blackhole.py @@ -6,6 +6,7 @@ from rpython.jit.metainterp.history import MissingValue from rpython.rlib import longlong2float from rpython.rlib.debug import ll_assert, make_sure_not_resized +from rpython.rlib.debug import check_annotation from rpython.rlib.objectmodel import we_are_translated, specialize from rpython.rlib.rarithmetic import intmask, LONG_BIT, r_uint, ovfcheck from rpython.rlib.unroll import unrolling_iterable @@ -183,7 +184,7 @@ if lltype.typeOf(result) is lltype.Bool: result = int(result) assert lltype.typeOf(result) is lltype.Signed - self.registers_i[ord(code[position])] = result + self.registers_i[ord(code[position])] = plain_int(result) position += 1 elif resulttype == 'r': # argcode should be 'r' too @@ -213,7 +214,7 @@ if lltype.typeOf(result) is lltype.Bool: result = int(result) assert lltype.typeOf(result) is lltype.Signed - self.registers_i[ord(code[position])] = result + self.registers_i[ord(code[position])] = plain_int(result) position += 1 elif resulttype == 'L': assert result >= 0 @@ -251,6 +252,23 @@ if b < 0 or b >= LONG_BIT: raise ValueError("Shift count, %d, not in valid range, 0 .. %d." % (b, LONG_BIT-1)) +def check_list_of_plain_integers(s_arg, bookkeeper): + """Check that 'BlackhopeInterpreter.registers_i' is annotated as a + non-resizable list of plain integers (and not r_int's for example).""" + from rpython.annotator import model as annmodel + assert isinstance(s_arg, annmodel.SomeList) + s_arg.listdef.never_resize() + assert s_arg.listdef.listitem.s_value.knowntype is int + +def _check_int(s_arg, bookkeeper): + assert s_arg.knowntype is int + +def plain_int(x): + """Check that 'x' is annotated as a plain integer (and not r_int)""" + check_annotation(x, _check_int) + return x + + class BlackholeInterpreter(object): def __init__(self, builder, count_interpreter): @@ -277,6 +295,7 @@ self.tmpreg_r = default_r self.tmpreg_f = default_f self.jitcode = None + check_annotation(self.registers_i, check_list_of_plain_integers) def __repr__(self): return '<BHInterp #%d>' % self.count_interpreter @@ -295,7 +314,7 @@ def setarg_i(self, index, value): assert lltype.typeOf(value) is lltype.Signed - self.registers_i[index] = value + self.registers_i[index] = plain_int(value) def setarg_r(self, index, value): assert lltype.typeOf(value) == llmemory.GCREF @@ -1573,7 +1592,8 @@ # 'xxx_call_yyy' instructions from the caller frame def _setup_return_value_i(self, result): assert lltype.typeOf(result) is lltype.Signed - self.registers_i[ord(self.jitcode.code[self.position-1])] = result + self.registers_i[ord(self.jitcode.code[self.position-1])] = plain_int( + result) def _setup_return_value_r(self, result): assert lltype.typeOf(result) == llmemory.GCREF self.registers_r[ord(self.jitcode.code[self.position-1])] = result diff --git a/rpython/rlib/test/test_rawrefcount.py b/rpython/rlib/test/test_rawrefcount.py --- a/rpython/rlib/test/test_rawrefcount.py +++ b/rpython/rlib/test/test_rawrefcount.py @@ -1,7 +1,7 @@ import weakref from rpython.rlib import rawrefcount, objectmodel, rgc from rpython.rlib.rawrefcount import REFCNT_FROM_PYPY, REFCNT_FROM_PYPY_LIGHT -from rpython.rtyper.lltypesystem import lltype, llmemory +from rpython.rtyper.lltypesystem import lltype from rpython.rtyper.annlowlevel import llhelper from rpython.translator.c.test.test_standalone import StandaloneTests from rpython.config.translationoption import get_combined_translation_config @@ -286,55 +286,3 @@ t, cbuilder = self.compile(entry_point) data = cbuilder.cmdexec('hi there') assert data.startswith('OK!\n') - - -class TestBoehmTranslated(StandaloneTests): - - def test_full_translation(self): - - def make_ob(): - p = W_Root(42) - ob = lltype.malloc(PyObjectS, flavor='raw', zero=True) - rawrefcount.create_link_pypy(p, ob) - ob.c_ob_refcnt += REFCNT_FROM_PYPY - assert rawrefcount.from_obj(PyObject, p) == ob - assert rawrefcount.to_obj(W_Root, ob) == p - return ob - - prebuilt_p = W_Root(-42) - prebuilt_ob = lltype.malloc(PyObjectS, flavor='raw', zero=True, - immortal=True) - - def entry_point(argv): - rawrefcount.create_link_pypy(prebuilt_p, prebuilt_ob) - prebuilt_ob.c_ob_refcnt += REFCNT_FROM_PYPY - oblist = [make_ob() for i in range(50)] - rgc.collect() - deadlist = [] - while True: - ob = rawrefcount.next_dead(PyObject) - if not ob: break - if ob.c_ob_refcnt != 1: - print "next_dead().ob_refcnt != 1" - return 1 - deadlist.append(ob) - if len(deadlist) == 0: - print "no dead object" - return 1 - if len(deadlist) < 30: - print "not enough dead objects" - return 1 - for ob in deadlist: - if ob not in oblist: - print "unexpected value for dead pointer" - return 1 - oblist.remove(ob) - print "OK!" - lltype.free(ob, flavor='raw') - return 0 - - self.config = get_combined_translation_config(translating=True) - self.config.translation.gc = "boehm" - t, cbuilder = self.compile(entry_point) - data = cbuilder.cmdexec('hi there') - assert data.startswith('OK!\n') diff --git a/rpython/rlib/test/test_rawrefcount_boehm.py b/rpython/rlib/test/test_rawrefcount_boehm.py --- a/rpython/rlib/test/test_rawrefcount_boehm.py +++ b/rpython/rlib/test/test_rawrefcount_boehm.py @@ -1,19 +1,34 @@ import itertools, os, subprocess, py from hypothesis import given, strategies from rpython.tool.udir import udir +from rpython.rlib import rawrefcount, rgc +from rpython.rlib.rawrefcount import REFCNT_FROM_PYPY +from rpython.rlib.test.test_rawrefcount import W_Root, PyObject, PyObjectS +from rpython.rtyper.lltypesystem import lltype +from rpython.translator.c.test.test_standalone import StandaloneTests +from rpython.config.translationoption import get_combined_translation_config +def compile_test(basename): + srcdir = os.path.dirname(os.path.dirname( + os.path.abspath(os.path.join(__file__)))) + srcdir = os.path.join(srcdir, 'src') + + err = os.system("cd '%s' && gcc -Werror -lgc -I%s -o %s %s.c" + % (udir, srcdir, basename, basename)) + return err + def setup_module(): filename = str(udir.join("test-rawrefcount-boehm-check.c")) with open(filename, "w") as f: print >> f, '#include "gc/gc_mark.h"' - print >> f, 'void *testing(void) {' - print >> f, ' return &GC_set_start_callback;' + print >> f, '#include <stdio.h>' + print >> f, 'int main(void) {' + print >> f, ' printf("%p", &GC_set_start_callback);' + print >> f, ' return 0;' print >> f, '}' - err = os.system("cd '%s' && gcc -c test-rawrefcount-boehm-check.c" - % (udir,)) - if err != 0: + if compile_test("test-rawrefcount-boehm-check") != 0: py.test.skip("Boehm GC not installed or too old version") @@ -180,13 +195,9 @@ print >> f, code print >> f, '}' - srcdir = os.path.dirname(os.path.dirname( - os.path.abspath(os.path.join(__file__)))) - srcdir = os.path.join(srcdir, 'src') - - err = os.system("cd '%s' && gcc -Werror -lgc -I%s -o test-rawrefcount-boehm" - " test-rawrefcount-boehm.c" % (udir, srcdir)) - assert err == 0 + err = compile_test("test-rawrefcount-boehm") + if err != 0: + raise OSError("gcc failed") p = subprocess.Popen("./test-rawrefcount-boehm", stdout=subprocess.PIPE, cwd=str(udir)) stdout, _ = p.communicate() @@ -243,3 +254,55 @@ del links_p2g[p] else: assert False, repr(line) + + +class TestBoehmTranslated(StandaloneTests): + + def test_full_translation(self): + + def make_ob(): + p = W_Root(42) + ob = lltype.malloc(PyObjectS, flavor='raw', zero=True) + rawrefcount.create_link_pypy(p, ob) + ob.c_ob_refcnt += REFCNT_FROM_PYPY + assert rawrefcount.from_obj(PyObject, p) == ob + assert rawrefcount.to_obj(W_Root, ob) == p + return ob + + prebuilt_p = W_Root(-42) + prebuilt_ob = lltype.malloc(PyObjectS, flavor='raw', zero=True, + immortal=True) + + def entry_point(argv): + rawrefcount.create_link_pypy(prebuilt_p, prebuilt_ob) + prebuilt_ob.c_ob_refcnt += REFCNT_FROM_PYPY + oblist = [make_ob() for i in range(50)] + rgc.collect() + deadlist = [] + while True: + ob = rawrefcount.next_dead(PyObject) + if not ob: break + if ob.c_ob_refcnt != 1: + print "next_dead().ob_refcnt != 1" + return 1 + deadlist.append(ob) + if len(deadlist) == 0: + print "no dead object" + return 1 + if len(deadlist) < 30: + print "not enough dead objects" + return 1 + for ob in deadlist: + if ob not in oblist: + print "unexpected value for dead pointer" + return 1 + oblist.remove(ob) + print "OK!" + lltype.free(ob, flavor='raw') + return 0 + + self.config = get_combined_translation_config(translating=True) + self.config.translation.gc = "boehm" + t, cbuilder = self.compile(entry_point) + data = cbuilder.cmdexec('hi there') + assert data.startswith('OK!\n') _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit