[pypy-commit] pypy space-newtext: gave up finding the root cause of this translation problem, and instead enforce
cfbolz
pypy.commits at gmail.com
Fri Dec 16 10:53:59 EST 2016
Author: Carl Friedrich Bolz <cfbolz at gmx.de>
Branch: space-newtext
Changeset: r89101:4d6b02c8898d
Date: 2016-12-16 16:53 +0100
http://bitbucket.org/pypy/pypy/changeset/4d6b02c8898d/
Log: gave up finding the root cause of this translation problem, and
instead enforce some W_Root types in gateway.py. (why things have to
be None is another sad story)
diff --git a/pypy/interpreter/gateway.py b/pypy/interpreter/gateway.py
--- a/pypy/interpreter/gateway.py
+++ b/pypy/interpreter/gateway.py
@@ -27,6 +27,9 @@
from rpython.rlib.rarithmetic import r_longlong, r_int, r_ulonglong, r_uint
from rpython.tool.sourcetools import func_with_new_name, compile2
+from rpython.rlib.signature import signature, finishsigs
+from rpython.rlib import types as sigtypes
+
# internal non-translatable parts:
class SignatureBuilder(object):
@@ -795,11 +798,17 @@
w_result = space.w_None
return w_result
+w_root_or_none = sigtypes.instance(W_Root, can_be_None=True)
+ at finishsigs
class BuiltinCode1(BuiltinCode):
_immutable_ = True
fast_natural_arity = 1
+ @signature(sigtypes.self(), sigtypes.any(),
+ w_root_or_none,
+ w_root_or_none,
+ returns=w_root_or_none)
def fastcall_1(self, space, w_func, w1):
try:
w_result = self.fastfunc_1(space, w1)
@@ -816,10 +825,16 @@
return w_result
+ at finishsigs
class BuiltinCode2(BuiltinCode):
_immutable_ = True
fast_natural_arity = 2
+ @signature(sigtypes.self(), sigtypes.any(),
+ w_root_or_none,
+ w_root_or_none,
+ w_root_or_none,
+ returns=w_root_or_none)
def fastcall_2(self, space, w_func, w1, w2):
try:
w_result = self.fastfunc_2(space, w1, w2)
@@ -836,10 +851,17 @@
return w_result
+ at finishsigs
class BuiltinCode3(BuiltinCode):
_immutable_ = True
fast_natural_arity = 3
+ @signature(sigtypes.self(), sigtypes.any(),
+ w_root_or_none,
+ w_root_or_none,
+ w_root_or_none,
+ w_root_or_none,
+ returns=w_root_or_none)
def fastcall_3(self, space, func, w1, w2, w3):
try:
w_result = self.fastfunc_3(space, w1, w2, w3)
@@ -855,12 +877,20 @@
w_result = space.w_None
return w_result
-
+ at finishsigs
class BuiltinCode4(BuiltinCode):
_immutable_ = True
fast_natural_arity = 4
+ @signature(sigtypes.self(), sigtypes.any(),
+ w_root_or_none,
+ w_root_or_none,
+ w_root_or_none,
+ w_root_or_none,
+ w_root_or_none,
+ returns=w_root_or_none)
def fastcall_4(self, space, func, w1, w2, w3, w4):
+ from rpython.rlib.debug import check_annotation
try:
w_result = self.fastfunc_4(space, w1, w2, w3, w4)
except DescrMismatch:
diff --git a/rpython/rlib/test/test_signature.py b/rpython/rlib/test/test_signature.py
--- a/rpython/rlib/test/test_signature.py
+++ b/rpython/rlib/test/test_signature.py
@@ -221,6 +221,36 @@
@check_annotator_fails
def bad_for_body():
f(C1())
+ @check_annotator_fails
+ def ok_for_body():
+ f(None)
+
+def test_instance_or_none():
+ class C1(object):
+ pass
+ class C2(C1):
+ pass
+ class C3(C2):
+ pass
+ @signature(types.instance(C3, can_be_None=True), returns=types.instance(C2, can_be_None=True))
+ def f(x):
+ assert isinstance(x, C2) or x is None
+ return x
+ argtype, rettype = getsig(f)
+ assert isinstance(argtype, model.SomeInstance)
+ assert argtype.classdef.classdesc.pyobj == C3
+ assert argtype.can_be_None
+ assert isinstance(rettype, model.SomeInstance)
+ assert rettype.classdef.classdesc.pyobj == C2
+ assert rettype.can_be_None
+
+ @check_annotator_fails
+ def ok_for_body():
+ f(C2())
+ @check_annotator_fails
+ def bad_for_body():
+ f(C1())
+
def test_self():
@finishsigs
diff --git a/rpython/rlib/types.py b/rpython/rlib/types.py
--- a/rpython/rlib/types.py
+++ b/rpython/rlib/types.py
@@ -76,8 +76,8 @@
return model.SomeDict(dictdef)
-def instance(cls):
- return lambda bookkeeper: model.SomeInstance(bookkeeper.getuniqueclassdef(cls))
+def instance(cls, can_be_None=False):
+ return lambda bookkeeper: model.SomeInstance(bookkeeper.getuniqueclassdef(cls), can_be_None=can_be_None)
class SelfTypeMarker(object):
More information about the pypy-commit
mailing list