[pypy-commit] pypy desc-specialize: Initialize funcdesc.specializer in FunctionDesc.__init__ and ensure the right annotator policy is active at the time
rlamy
pypy.commits at gmail.com
Sat Feb 20 05:20:05 EST 2016
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: desc-specialize
Changeset: r82339:cf1b6e045f41
Date: 2016-02-20 10:19 +0000
http://bitbucket.org/pypy/pypy/changeset/cf1b6e045f41/
Log: Initialize funcdesc.specializer in FunctionDesc.__init__ and ensure
the right annotator policy is active at the time
diff --git a/rpython/annotator/annrpython.py b/rpython/annotator/annrpython.py
--- a/rpython/annotator/annrpython.py
+++ b/rpython/annotator/annrpython.py
@@ -82,17 +82,17 @@
annmodel.TLS.check_str_without_nul = (
self.translator.config.translation.check_str_without_nul)
- flowgraph, inputs_s = self.get_call_parameters(function, args_s, policy)
+ with self.using_policy(policy):
+ flowgraph, inputs_s = self.get_call_parameters(function, args_s)
if main_entry_point:
self.translator.entry_point_graph = flowgraph
return self.build_graph_types(flowgraph, inputs_s, complete_now=complete_now)
- def get_call_parameters(self, function, args_s, policy):
- desc = self.bookkeeper.getdesc(function)
- with self.using_policy(policy):
- with self.bookkeeper.at_position(None):
- return desc.get_call_parameters(args_s)
+ def get_call_parameters(self, function, args_s):
+ with self.bookkeeper.at_position(None):
+ desc = self.bookkeeper.getdesc(function)
+ return desc.get_call_parameters(args_s)
def annotate_helper(self, function, args_s, policy=None):
if policy is None:
@@ -101,21 +101,21 @@
# XXX hack
annmodel.TLS.check_str_without_nul = (
self.translator.config.translation.check_str_without_nul)
- graph, inputcells = self.get_call_parameters(function, args_s, policy)
- self.build_graph_types(graph, inputcells, complete_now=False)
- self.complete_helpers(policy)
+ with self.using_policy(policy):
+ graph, inputcells = self.get_call_parameters(function, args_s)
+ self.build_graph_types(graph, inputcells, complete_now=False)
+ self.complete_helpers()
return graph
- def complete_helpers(self, policy):
+ def complete_helpers(self):
saved = self.added_blocks
self.added_blocks = {}
- with self.using_policy(policy):
- try:
- self.complete()
- # invoke annotation simplifications for the new blocks
- self.simplify(block_subset=self.added_blocks)
- finally:
- self.added_blocks = saved
+ try:
+ self.complete()
+ # invoke annotation simplifications for the new blocks
+ self.simplify(block_subset=self.added_blocks)
+ finally:
+ self.added_blocks = saved
@contextmanager
def using_policy(self, policy):
diff --git a/rpython/annotator/description.py b/rpython/annotator/description.py
--- a/rpython/annotator/description.py
+++ b/rpython/annotator/description.py
@@ -214,6 +214,7 @@
# specializer(funcdesc, args_s) => graph
# or => s_result (overridden/memo cases)
self.specializer = specializer
+ self.init_specializer()
self._cache = {} # convenience for the specializer
def buildgraph(self, alt_name=None, builder=None):
@@ -296,7 +297,6 @@
getattr(self.bookkeeper, "position_key", None) is not None):
_, block, i = self.bookkeeper.position_key
op = block.operations[i]
- self.init_specializer()
enforceargs = getattr(self.pyobj, '_annenforceargs_', None)
signature = getattr(self.pyobj, '_signature_', None)
if enforceargs and signature:
diff --git a/rpython/rtyper/annlowlevel.py b/rpython/rtyper/annlowlevel.py
--- a/rpython/rtyper/annlowlevel.py
+++ b/rpython/rtyper/annlowlevel.py
@@ -138,11 +138,12 @@
# get the graph of the mix-level helper ll_function and prepare it for
# being annotated. Annotation and RTyping should be done in a single shot
# at the end with finish().
- graph, args_s = self.rtyper.annotator.get_call_parameters(
- ll_function, args_s, policy = self.policy)
+ ann = self.rtyper.annotator
+ with ann.using_policy(self.policy):
+ graph, args_s = ann.get_call_parameters(ll_function, args_s)
for v_arg, s_arg in zip(graph.getargs(), args_s):
- self.rtyper.annotator.setbinding(v_arg, s_arg)
- self.rtyper.annotator.setbinding(graph.getreturnvar(), s_result)
+ ann.setbinding(v_arg, s_arg)
+ ann.setbinding(graph.getreturnvar(), s_result)
#self.rtyper.annotator.annotated[graph.returnblock] = graph
self.pending.append((ll_function, graph, args_s, s_result))
return graph
@@ -224,16 +225,17 @@
bk = ann.bookkeeper
translator = ann.translator
original_graph_count = len(translator.graphs)
- for ll_function, graph, args_s, s_result in self.pending:
- # mark the return block as already annotated, because the return var
- # annotation was forced in getgraph() above. This prevents temporary
- # less general values reaching the return block from crashing the
- # annotator (on the assert-that-new-binding-is-not-less-general).
- ann.annotated[graph.returnblock] = graph
- s_function = bk.immutablevalue(ll_function)
- bk.emulate_pbc_call(graph, s_function, args_s)
- self.newgraphs.add(graph)
- ann.complete_helpers(self.policy)
+ with ann.using_policy(self.policy):
+ for ll_function, graph, args_s, s_result in self.pending:
+ # mark the return block as already annotated, because the return var
+ # annotation was forced in getgraph() above. This prevents temporary
+ # less general values reaching the return block from crashing the
+ # annotator (on the assert-that-new-binding-is-not-less-general).
+ ann.annotated[graph.returnblock] = graph
+ s_function = bk.immutablevalue(ll_function)
+ bk.emulate_pbc_call(graph, s_function, args_s)
+ self.newgraphs.add(graph)
+ ann.complete_helpers()
for ll_function, graph, args_s, s_result in self.pending:
s_real_result = ann.binding(graph.getreturnvar())
if s_real_result != s_result:
diff --git a/rpython/rtyper/rtyper.py b/rpython/rtyper/rtyper.py
--- a/rpython/rtyper/rtyper.py
+++ b/rpython/rtyper/rtyper.py
@@ -852,28 +852,29 @@
rtyper = self.rtyper
args_s = []
newargs_v = []
- for v in args_v:
- if v.concretetype is Void:
- 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)):
- raise TyperError("non-PBC Void argument: %r", (s_value,))
- args_s.append(s_value)
- else:
- args_s.append(lltype_to_annotation(v.concretetype))
- newargs_v.append(v)
+ with rtyper.annotator.using_policy(rtyper.lowlevel_ann_policy):
+ for v in args_v:
+ if v.concretetype is Void:
+ 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)):
+ raise TyperError("non-PBC Void argument: %r", (s_value,))
+ args_s.append(s_value)
+ else:
+ args_s.append(lltype_to_annotation(v.concretetype))
+ newargs_v.append(v)
- self.rtyper.call_all_setups() # compute ForwardReferences now
+ self.rtyper.call_all_setups() # compute ForwardReferences now
- # hack for bound methods
- if hasattr(ll_function, 'im_func'):
- bk = rtyper.annotator.bookkeeper
- args_s.insert(0, bk.immutablevalue(ll_function.im_self))
- newargs_v.insert(0, inputconst(Void, ll_function.im_self))
- ll_function = ll_function.im_func
+ # hack for bound methods
+ if hasattr(ll_function, 'im_func'):
+ bk = rtyper.annotator.bookkeeper
+ args_s.insert(0, bk.immutablevalue(ll_function.im_self))
+ newargs_v.insert(0, inputconst(Void, ll_function.im_self))
+ ll_function = ll_function.im_func
graph = annotate_lowlevel_helper(rtyper.annotator, ll_function, args_s,
rtyper.lowlevel_ann_policy)
More information about the pypy-commit
mailing list