[pypy-commit] pypy var-in-Some: kill 3rd argument of RPythonAnnotator.binding()

rlamy noreply at buildbot.pypy.org
Sun Oct 5 19:14:55 CEST 2014


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: var-in-Some
Changeset: r73791:61604ad10046
Date: 2014-10-05 18:14 +0100
http://bitbucket.org/pypy/pypy/changeset/61604ad10046/

Log:	kill 3rd argument of RPythonAnnotator.binding()

	Create RPythonAnnotator.annotation()

diff --git a/rpython/annotator/annrpython.py b/rpython/annotator/annrpython.py
--- a/rpython/annotator/annrpython.py
+++ b/rpython/annotator/annrpython.py
@@ -18,7 +18,6 @@
 log = py.log.Producer("annrpython")
 py.log.setconsumer("annrpython", ansi_log)
 
-FAIL = object()
 
 class RPythonAnnotator(object):
     """Block annotator for RPython.
@@ -143,7 +142,7 @@
         # recursively proceed until no more pending block is left
         if complete_now:
             self.complete()
-        return self.binding(flowgraph.getreturnvar(), None)
+        return self.annotation(flowgraph.getreturnvar())
 
     def gettype(self, variable):
         """Return the known type of a control flow graph variable,
@@ -226,21 +225,25 @@
         # policy-dependent computation
         self.bookkeeper.compute_at_fixpoint()
 
-    def binding(self, arg, default=FAIL):
+    def annotation(self, arg):
         "Gives the SomeValue corresponding to the given Variable or Constant."
         if isinstance(arg, Variable):
             annvalue = arg.binding
-            if annvalue is not None:
-                return annvalue.ann
-            if default is not FAIL:
-                return default
-            else:
-                raise KeyError
+            if annvalue is None:
+                return None
+            return annvalue.ann
         elif isinstance(arg, Constant):
             return self.bookkeeper.immutablevalue(arg.value)
         else:
             raise TypeError('Variable or Constant expected, got %r' % (arg,))
 
+    def binding(self, arg):
+        "Gives the SomeValue corresponding to the given Variable or Constant."
+        s_arg = self.annotation(arg)
+        if s_arg is None:
+            raise KeyError
+        return s_arg
+
     def annvalue(self, arg):
         if isinstance(arg, Variable):
             return arg.binding
diff --git a/rpython/annotator/bookkeeper.py b/rpython/annotator/bookkeeper.py
--- a/rpython/annotator/bookkeeper.py
+++ b/rpython/annotator/bookkeeper.py
@@ -89,14 +89,14 @@
                 newblocks = self.annotator.added_blocks
                 if newblocks is None:
                     newblocks = self.annotator.annotated  # all of them
-                binding = self.annotator.binding
+                annotation = self.annotator.annotation
                 for block in newblocks:
                     for op in block.operations:
                         if op.opname in ('simple_call', 'call_args'):
                             yield op
 
                         # some blocks are partially annotated
-                        if binding(op.result, None) is None:
+                        if annotation(op.result) is None:
                             break   # ignore the unannotated part
 
             for call_op in call_sites():
@@ -144,15 +144,17 @@
 
     def consider_call_site(self, call_op):
         from rpython.rtyper.llannotation import SomeLLADTMeth, lltype_to_annotation
-        binding = self.annotator.binding
-        s_callable = binding(call_op.args[0])
-        args_s = [binding(arg) for arg in call_op.args[1:]]
+        annotation = self.annotator.annotation
+        s_callable = annotation(call_op.args[0])
+        args_s = [annotation(arg) for arg in call_op.args[1:]]
         if isinstance(s_callable, SomeLLADTMeth):
             adtmeth = s_callable
             s_callable = self.immutablevalue(adtmeth.func)
             args_s = [lltype_to_annotation(adtmeth.ll_ptrtype)] + args_s
         if isinstance(s_callable, SomePBC):
-            s_result = binding(call_op.result, s_ImpossibleValue)
+            s_result = annotation(call_op.result)
+            if s_result is None:
+                s_result = s_ImpossibleValue
             args = call_op.build_args(args_s)
             self.consider_call_site_for_pbc(s_callable, args,
                                             s_result, call_op)
@@ -500,8 +502,9 @@
             # needed by some kinds of specialization.
             fn, block, i = self.position_key
             op = block.operations[i]
-            s_previous_result = self.annotator.binding(op.result,
-                                                       s_ImpossibleValue)
+            s_previous_result = self.annotator.annotation(op.result)
+            if s_previous_result is None:
+                s_previous_result = s_ImpossibleValue
         else:
             if emulated is True:
                 whence = None
diff --git a/rpython/rtyper/rtyper.py b/rpython/rtyper/rtyper.py
--- a/rpython/rtyper/rtyper.py
+++ b/rpython/rtyper/rtyper.py
@@ -17,7 +17,6 @@
 
 from rpython.annotator import model as annmodel, unaryop, binaryop
 from rpython.rtyper.llannotation import SomePtr, lltype_to_annotation
-from rpython.annotator.annrpython import FAIL
 from rpython.flowspace.model import Variable, Constant, SpaceOperation, c_last_exception
 from rpython.rtyper.annlowlevel import annotate_lowlevel_helper, LowLevelAnnotatorPolicy
 from rpython.rtyper.error import TyperError
@@ -152,8 +151,12 @@
         assert result is not None     # recursive getrepr()!
         return result
 
-    def binding(self, var, default=FAIL):
-        s_obj = self.annotator.binding(var, default)
+    def annotation(self, var):
+        s_obj = self.annotator.annotation(var)
+        return s_obj
+
+    def binding(self, var):
+        s_obj = self.annotator.binding(var)
         return s_obj
 
     def bindingrepr(self, var):
@@ -635,7 +638,7 @@
             ARG_GCSTRUCT = GCSTRUCT
         args_s = [SomePtr(Ptr(ARG_GCSTRUCT))]
         graph = self.annotate_helper(func, args_s)
-        s = self.annotator.binding(graph.getreturnvar())
+        s = self.annotation(graph.getreturnvar())
         if (not isinstance(s, SomePtr) or
             s.ll_ptrtype != Ptr(RuntimeTypeInfo)):
             raise TyperError("runtime type info function %r returns %r, "
@@ -882,7 +885,9 @@
         newargs_v = []
         for v in args_v:
             if v.concretetype is Void:
-                s_value = rtyper.binding(v, default=annmodel.s_None)
+                s_value = rtyper.annotation(v)
+                if s_value is None:
+                    s_value = annmodel.s_None
                 if not s_value.is_constant():
                     raise TyperError("non-constant variable of type Void")
                 if not isinstance(s_value, (annmodel.SomePBC, annmodel.SomeNone)):
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
@@ -33,7 +33,7 @@
         try:
             for block in g.iterblocks():
                 for v in block.getvariables():
-                    s = annotator.binding(v, None)
+                    s = annotator.annotation(v)
                     if s and s.__class__ == annmodel.SomeObject and s.knowntype != type:
                         raise Found
         except Found:
@@ -44,8 +44,8 @@
     annotator = translator.annotator
     for graph in translator.graphs:
         et, ev = graph.exceptblock.inputargs
-        s_et = annotator.binding(et, None)
-        s_ev = annotator.binding(ev, None)
+        s_et = annotator.annotation(et)
+        s_ev = annotator.annotation(ev)
         if s_et:
             if s_et.knowntype == type:
                 if s_et.__class__ == annmodel.SomeType:
diff --git a/rpython/translator/transform.py b/rpython/translator/transform.py
--- a/rpython/translator/transform.py
+++ b/rpython/translator/transform.py
@@ -89,8 +89,8 @@
         for i in range(len(block.operations)):
             op = block.operations[i]
             if op.opname == 'mul':
-                s0 = self.binding(op.args[0], None)
-                s1 = self.binding(op.args[1], None)
+                s0 = self.annotation(op.args[0])
+                s1 = self.annotation(op.args[1])
                 if (isinstance(s0, annmodel.SomeChar) and
                     isinstance(s1, annmodel.SomeInteger)):
                     mul_sources[op.result] = op.args[0], op.args[1]


More information about the pypy-commit mailing list