[pypy-commit] pypy fix-broken-types: Hack around to make the flag do something (disallowing int-float unions)
rlamy
pypy.commits at gmail.com
Tue Nov 22 14:02:57 EST 2016
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: fix-broken-types
Changeset: r88550:98f1bef80edd
Date: 2016-11-22 18:44 +0000
http://bitbucket.org/pypy/pypy/changeset/98f1bef80edd/
Log: Hack around to make the flag do something (disallowing int-float
unions)
diff --git a/rpython/annotator/annrpython.py b/rpython/annotator/annrpython.py
--- a/rpython/annotator/annrpython.py
+++ b/rpython/annotator/annrpython.py
@@ -50,7 +50,9 @@
if bookkeeper is None:
bookkeeper = Bookkeeper(self)
self.bookkeeper = bookkeeper
- self.allow_bad_unions = True # temporary feature flag, see config.translation.brokentypes
+ # temporary feature flag, see config.translation.brokentypes
+ # defaults to True in real translations
+ self.allow_bad_unions = False
def __getstate__(self):
attrs = """translator pendingblocks annotated links_followed
@@ -76,9 +78,7 @@
# make input arguments and set their type
args_s = [self.typeannotation(t) for t in input_arg_types]
- # XXX hack
- annmodel.TLS.check_str_without_nul = (
- self.translator.config.translation.check_str_without_nul)
+ self._setup_union_hacks() # XXX
flowgraph, inputs_s = self.get_call_parameters(function, args_s, policy)
@@ -86,6 +86,11 @@
self.translator.entry_point_graph = flowgraph
return self.build_graph_types(flowgraph, inputs_s, complete_now=complete_now)
+ def _setup_union_hacks(self):
+ annmodel.TLS.check_str_without_nul = (
+ self.translator.config.translation.check_str_without_nul)
+ annmodel.TLS.allow_bad_unions = self.allow_bad_unions
+
def get_call_parameters(self, function, args_s, policy):
desc = self.bookkeeper.getdesc(function)
prevpolicy = self.policy
@@ -101,9 +106,7 @@
if policy is None:
from rpython.annotator.policy import AnnotatorPolicy
policy = AnnotatorPolicy()
- # XXX hack
- annmodel.TLS.check_str_without_nul = (
- self.translator.config.translation.check_str_without_nul)
+ self._setup_union_hacks() # XXX
graph, inputcells = self.get_call_parameters(function, args_s, policy)
self.build_graph_types(graph, inputcells, complete_now=False)
self.complete_helpers(policy)
diff --git a/rpython/annotator/binaryop.py b/rpython/annotator/binaryop.py
--- a/rpython/annotator/binaryop.py
+++ b/rpython/annotator/binaryop.py
@@ -436,14 +436,16 @@
class __extend__(pairtype(SomeFloat, SomeFloat)):
def union((flt1, flt2)):
- if not TLS.allow_int_to_float:
+ if not TLS.allow_bad_unions or not TLS.allow_int_to_float:
# in this mode, if one of the two is actually the
# subclass SomeInteger, complain
if isinstance(flt1, SomeInteger) or isinstance(flt2, SomeInteger):
raise UnionError(flt1, flt2)
return SomeFloat()
- add = sub = mul = union
+ def add((flt1, flt2)):
+ return SomeFloat()
+ sub = mul = add
def div((flt1, flt2)):
return SomeFloat()
diff --git a/rpython/annotator/model.py b/rpython/annotator/model.py
--- a/rpython/annotator/model.py
+++ b/rpython/annotator/model.py
@@ -45,6 +45,7 @@
# the no_nul attribute...
check_str_without_nul = False
allow_int_to_float = True
+ allow_bad_unions = False
TLS = State()
class SomeObject(object):
diff --git a/rpython/annotator/test/test_model.py b/rpython/annotator/test/test_model.py
--- a/rpython/annotator/test/test_model.py
+++ b/rpython/annotator/test/test_model.py
@@ -14,7 +14,10 @@
@pytest.fixture()
def annotator():
t = TranslationContext()
- return t.buildannotator()
+ t.config.translation.brokentypes = False
+ ann = t.buildannotator()
+ ann._setup_union_hacks()
+ return ann
listdef1 = ListDef(None, SomeTuple([SomeInteger(nonneg=True), SomeString()]))
More information about the pypy-commit
mailing list