Author: Ronan Lamy <[email protected]>
Branch: var-in-Some
Changeset: r71560:1b64ec913ad6
Date: 2014-05-17 21:50 +0100
http://bitbucket.org/pypy/pypy/changeset/1b64ec913ad6/
Log: put AnnotatedValues in .is_type_of
diff --git a/rpython/annotator/annrpython.py b/rpython/annotator/annrpython.py
--- a/rpython/annotator/annrpython.py
+++ b/rpython/annotator/annrpython.py
@@ -243,7 +243,12 @@
def annvalue(self, arg):
if isinstance(arg, Variable):
- return self.bindings[arg]
+ try:
+ return self.bindings[arg]
+ except KeyError:
+ value = AnnotatedValue(arg, None)
+ self.bindings[arg] = value
+ return value
else:
return AnnotatedValue(arg,
self.bookkeeper.immutablevalue(arg.value))
@@ -252,8 +257,10 @@
def setbinding(self, arg, s_value):
if arg in self.bindings:
- assert s_value.contains(self.bindings[arg].ann)
- self.bindings[arg].ann = s_value
+ value = self.bindings[arg]
+ if value.ann is not None:
+ assert s_value.contains(value.ann)
+ value.ann = s_value
else:
self.bindings[arg] = AnnotatedValue(arg, s_value)
@@ -517,13 +524,13 @@
last_exception_object = annmodel.SomeType()
if isinstance(last_exception_var, Constant):
last_exception_object.const = last_exception_var.value
- last_exception_object.is_type_of = [last_exc_value_var]
+ last_exception_object.is_type_of = [
+ self.annvalue(last_exc_value_var)]
if isinstance(last_exception_var, Variable):
self.setbinding(last_exception_var, last_exception_object)
if isinstance(last_exc_value_var, Variable):
self.setbinding(last_exc_value_var, last_exc_value_object)
-
last_exception_object = annmodel.SomeType()
if isinstance(last_exception_var, Constant):
last_exception_object.const = last_exception_var.value
@@ -545,7 +552,7 @@
elif a == last_exc_value_var:
assert in_except_block
cells.append(last_exc_value_object)
- last_exc_value_vars.append(v)
+ last_exc_value_vars.append(self.annvalue(v))
else:
cell = self.binding(a)
if (link.exitcase, a) in knowntypedata:
@@ -558,8 +565,8 @@
if hasattr(cell,'is_type_of'):
renamed_is_type_of = []
for v in cell.is_type_of:
- new_vs = renaming.get(v,[])
- renamed_is_type_of += new_vs
+ new_vs = renaming.get(v.value, [])
+ renamed_is_type_of += map(self.annvalue, new_vs)
assert cell.knowntype is type
newcell = annmodel.SomeType()
if cell.is_constant():
diff --git a/rpython/annotator/binaryop.py b/rpython/annotator/binaryop.py
--- a/rpython/annotator/binaryop.py
+++ b/rpython/annotator/binaryop.py
@@ -115,8 +115,10 @@
def bind(src_obj, tgt_obj, tgt_arg):
if hasattr(tgt_obj, 'is_type_of') and src_obj.is_constant():
- add_knowntypedata(knowntypedata, True, tgt_obj.is_type_of,
- bk.valueoftype(src_obj.const))
+ add_knowntypedata(
+ knowntypedata, True,
+ [inst.value for inst in tgt_obj.is_type_of],
+ bk.valueoftype(src_obj.const))
assert annotator.binding(op.args[tgt_arg]) == tgt_obj
add_knowntypedata(knowntypedata, True, [op.args[tgt_arg]],
src_obj)
diff --git a/rpython/annotator/test/test_annrpython.py
b/rpython/annotator/test/test_annrpython.py
--- a/rpython/annotator/test/test_annrpython.py
+++ b/rpython/annotator/test/test_annrpython.py
@@ -1399,7 +1399,7 @@
et, ev = fg.exceptblock.inputargs
t = annmodel.SomeType()
t.const = KeyError
- t.is_type_of = [ev]
+ t.is_type_of = [a.annvalue(ev)]
assert a.binding(et) == t
assert isinstance(a.binding(ev), annmodel.SomeInstance) and
a.binding(ev).classdef == a.bookkeeper.getuniqueclassdef(KeyError)
@@ -1414,7 +1414,7 @@
fg = graphof(a, f)
et, ev = fg.exceptblock.inputargs
t = annmodel.SomeType()
- t.is_type_of = [ev]
+ t.is_type_of = [a.annvalue(ev)]
t.const = KeyError # IndexError ignored because 'dic' is a dict
assert a.binding(et) == t
assert isinstance(a.binding(ev), annmodel.SomeInstance) and
a.binding(ev).classdef == a.bookkeeper.getuniqueclassdef(KeyError)
@@ -1449,7 +1449,7 @@
fg = graphof(a, f)
et, ev = fg.exceptblock.inputargs
t = annmodel.SomeType()
- t.is_type_of = [ev]
+ t.is_type_of = [a.annvalue(ev)]
assert a.binding(et) == t
assert isinstance(a.binding(ev), annmodel.SomeInstance) and
a.binding(ev).classdef == a.bookkeeper.getuniqueclassdef(Exception)
@@ -1471,7 +1471,7 @@
fg = graphof(a, f)
et, ev = fg.exceptblock.inputargs
t = annmodel.SomeType()
- t.is_type_of = [ev]
+ t.is_type_of = [a.annvalue(ev)]
assert a.binding(et) == t
assert isinstance(a.binding(ev), annmodel.SomeInstance) and
a.binding(ev).classdef == a.bookkeeper.getuniqueclassdef(Exception)
diff --git a/rpython/annotator/unaryop.py b/rpython/annotator/unaryop.py
--- a/rpython/annotator/unaryop.py
+++ b/rpython/annotator/unaryop.py
@@ -22,7 +22,7 @@
@op.type.register(SomeObject)
def type_SomeObject(arg):
r = SomeType()
- r.is_type_of = [arg.value]
+ r.is_type_of = [arg]
return r
@op.bool.register(SomeObject)
@@ -41,10 +41,10 @@
def issubtype(self, s_cls):
if hasattr(self, 'is_type_of'):
- vars = self.is_type_of
+ instances = self.is_type_of
annotator = getbookkeeper().annotator
- return builtin.builtin_isinstance(annotator.binding(vars[0]),
- s_cls, vars)
+ return builtin.builtin_isinstance(instances[0].ann, s_cls,
+ [x.value for x in instances])
if self.is_constant() and s_cls.is_constant():
return immutablevalue(issubclass(self.const, s_cls.const))
return s_Bool
diff --git a/rpython/translator/goal/query.py b/rpython/translator/goal/query.py
--- a/rpython/translator/goal/query.py
+++ b/rpython/translator/goal/query.py
@@ -48,11 +48,12 @@
s_ev = annotator.binding(ev, None)
if s_et:
if s_et.knowntype == type:
- if s_et.__class__ == annmodel.SomeType:
- if hasattr(s_et, 'is_type_of') and s_et.is_type_of ==
[ev]:
+ if isinstance(s_et, annmodel.SomeType):
+ if (hasattr(s_et, 'is_type_of') and
+ s_et.is_type_of == [annotator.annvalue(ev)]):
continue
else:
- if s_et.__class__ == annmodel.SomePBC:
+ if isinstance(s_et, annmodel.SomePBC):
continue
yield "%s exceptblock is not completely sane" % graph.name
diff --git a/rpython/translator/transform.py b/rpython/translator/transform.py
--- a/rpython/translator/transform.py
+++ b/rpython/translator/transform.py
@@ -191,7 +191,7 @@
# fix the annotation of the exceptblock.inputargs
etype, evalue = graph.exceptblock.inputargs
s_type = annmodel.SomeType()
- s_type.is_type_of = [evalue]
+ s_type.is_type_of = [self.annvalue(evalue)]
s_value =
annmodel.SomeInstance(self.bookkeeper.getuniqueclassdef(Exception))
self.setbinding(etype, s_type)
self.setbinding(evalue, s_value)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit