[pypy-commit] pypy default: cleanups in rpython.annotator
bdkearns
noreply at buildbot.pypy.org
Fri Mar 22 11:00:23 CET 2013
Author: Brian Kearns <bdkearns at gmail.com>
Branch:
Changeset: r62649:c154acb97f6a
Date: 2013-03-22 05:18 -0400
http://bitbucket.org/pypy/pypy/changeset/c154acb97f6a/
Log: cleanups in rpython.annotator
diff --git a/rpython/annotator/annrpython.py b/rpython/annotator/annrpython.py
--- a/rpython/annotator/annrpython.py
+++ b/rpython/annotator/annrpython.py
@@ -1,6 +1,7 @@
from __future__ import absolute_import
import types
+
from rpython.tool.ansi_print import ansi_log
from rpython.tool.pairtype import pair
from rpython.tool.error import (format_blocked_annotation_error,
@@ -10,12 +11,13 @@
from rpython.translator import simplify, transform
from rpython.annotator import model as annmodel, signature, unaryop, binaryop
from rpython.annotator.bookkeeper import Bookkeeper
+
import py
log = py.log.Producer("annrpython")
py.log.setconsumer("annrpython", ansi_log)
+FAIL = object()
-FAIL = object()
class RPythonAnnotator(object):
"""Block annotator for RPython.
diff --git a/rpython/annotator/binaryop.py b/rpython/annotator/binaryop.py
--- a/rpython/annotator/binaryop.py
+++ b/rpython/annotator/binaryop.py
@@ -15,7 +15,6 @@
from rpython.annotator.model import SomeAddress, SomeTypedAddressAccess
from rpython.annotator.model import SomeSingleFloat, SomeLongFloat, SomeType
from rpython.annotator.model import unionof, UnionError, missing_operation
-from rpython.annotator.model import TLS
from rpython.annotator.model import read_can_only_throw
from rpython.annotator.model import add_knowntypedata, merge_knowntypedata
from rpython.annotator.model import SomeGenericCallable
diff --git a/rpython/annotator/bookkeeper.py b/rpython/annotator/bookkeeper.py
--- a/rpython/annotator/bookkeeper.py
+++ b/rpython/annotator/bookkeeper.py
@@ -12,7 +12,7 @@
SomeInteger, SomeOOInstance, SomeOOObject, TLS, SomeAddress, \
SomeUnicodeCodePoint, SomeOOStaticMeth, s_None, s_ImpossibleValue, \
SomeLLADTMeth, SomeBool, SomeTuple, SomeOOClass, SomeImpossibleValue, \
- SomeUnicodeString, SomeList, SomeObject, HarmlesslyBlocked, \
+ SomeUnicodeString, SomeList, HarmlesslyBlocked, \
SomeWeakRef, lltype_to_annotation, SomeType, SomeByteArray
from rpython.annotator.classdef import InstanceSource, ClassDef
from rpython.annotator.listdef import ListDef, ListItem
@@ -25,7 +25,7 @@
from rpython.rtyper.lltypesystem import lltype, llmemory
from rpython.rtyper.ootypesystem import ootype
from rpython.rtyper import extregistry
-from rpython.tool.identity_dict import identity_dict
+
class Stats(object):
@@ -758,9 +758,7 @@
except AttributeError:
return None
-
def delayed_imports():
# import ordering hack
global BUILTIN_ANALYZERS
from rpython.annotator.builtin import BUILTIN_ANALYZERS
-
diff --git a/rpython/annotator/builtin.py b/rpython/annotator/builtin.py
--- a/rpython/annotator/builtin.py
+++ b/rpython/annotator/builtin.py
@@ -1,10 +1,10 @@
"""
Built-in functions.
"""
+import sys
-import sys
from rpython.annotator.model import SomeInteger, SomeObject, SomeChar, SomeBool
-from rpython.annotator.model import SomeString, SomeTuple, s_Bool, SomeBuiltin
+from rpython.annotator.model import SomeString, SomeTuple, s_Bool
from rpython.annotator.model import SomeUnicodeCodePoint, SomeAddress
from rpython.annotator.model import SomeFloat, unionof, SomeUnicodeString
from rpython.annotator.model import SomePBC, SomeInstance, SomeDict, SomeList
diff --git a/rpython/annotator/classdef.py b/rpython/annotator/classdef.py
--- a/rpython/annotator/classdef.py
+++ b/rpython/annotator/classdef.py
@@ -212,7 +212,7 @@
def find_attribute(self, attr):
return self.locate_attribute(attr).attrs[attr]
-
+
def __repr__(self):
return "<ClassDef '%s'>" % (self.name,)
@@ -223,7 +223,6 @@
return True
def commonbase(self, other):
- other1 = other
while other is not None and not self.issubclass(other):
other = other.basedef
return other
@@ -323,14 +322,11 @@
d = []
uplookup = None
updesc = None
- meth = False
- check_for_missing_attrs = False
for desc in pbc.descriptions:
# pick methods but ignore already-bound methods, which can come
# from an instance attribute
if (isinstance(desc, description.MethodDesc)
- and desc.selfclassdef is None):
- meth = True
+ and desc.selfclassdef is None):
methclassdef = desc.originclassdef
if methclassdef is not self and methclassdef.issubclass(self):
pass # subclasses methods are always candidates
@@ -349,7 +345,7 @@
# more precise subclass that it's coming from.
desc = desc.bind_self(methclassdef, flags)
d.append(desc)
- if uplookup is not None:
+ if uplookup is not None:
d.append(updesc.bind_self(self, flags))
if d or pbc.can_be_None:
diff --git a/rpython/annotator/description.py b/rpython/annotator/description.py
--- a/rpython/annotator/description.py
+++ b/rpython/annotator/description.py
@@ -282,7 +282,7 @@
raise Exception("%r: signature and enforceargs cannot both be used" % (self,))
if enforceargs:
if not callable(enforceargs):
- from rpython.annotator.policy import Sig
+ from rpython.annotator.signature import Sig
enforceargs = Sig(*enforceargs)
self.pyobj._annenforceargs_ = enforceargs
enforceargs(self, inputcells) # can modify inputcells in-place
@@ -867,7 +867,6 @@
def consider_call_site(bookkeeper, family, descs, args, s_result, op):
shape = rawshape(args, nextra=1) # account for the extra 'self'
- funcdescs = [methoddesc.funcdesc for methoddesc in descs]
row = FunctionDesc.row_to_consider(descs, args, op)
family.calltable_add_row(shape, row)
consider_call_site = staticmethod(consider_call_site)
@@ -1028,7 +1027,6 @@
def consider_call_site(bookkeeper, family, descs, args, s_result, op):
shape = rawshape(args, nextra=1) # account for the extra 'self'
- funcdescs = [mofdesc.funcdesc for mofdesc in descs]
row = FunctionDesc.row_to_consider(descs, args, op)
family.calltable_add_row(shape, row)
consider_call_site = staticmethod(consider_call_site)
diff --git a/rpython/annotator/dictdef.py b/rpython/annotator/dictdef.py
--- a/rpython/annotator/dictdef.py
+++ b/rpython/annotator/dictdef.py
@@ -1,6 +1,5 @@
-from rpython.annotator.model import SomeObject, s_ImpossibleValue
+from rpython.annotator.model import s_ImpossibleValue
from rpython.annotator.model import SomeInteger, s_Bool, unionof
-from rpython.annotator.model import SomeInstance
from rpython.annotator.listdef import ListItem
from rpython.rlib.objectmodel import compute_hash
diff --git a/rpython/annotator/listdef.py b/rpython/annotator/listdef.py
--- a/rpython/annotator/listdef.py
+++ b/rpython/annotator/listdef.py
@@ -1,4 +1,4 @@
-from rpython.annotator.model import SomeObject, s_ImpossibleValue
+from rpython.annotator.model import s_ImpossibleValue
from rpython.annotator.model import SomeList, SomeString
from rpython.annotator.model import unionof, TLS, UnionError
diff --git a/rpython/annotator/model.py b/rpython/annotator/model.py
--- a/rpython/annotator/model.py
+++ b/rpython/annotator/model.py
@@ -29,11 +29,11 @@
from __future__ import absolute_import
-from types import BuiltinFunctionType, MethodType, FunctionType
+from types import BuiltinFunctionType, MethodType
import rpython
from rpython.tool import descriptor
from rpython.tool.pairtype import pair, extendabletype
-from rpython.rlib.rarithmetic import r_uint, r_ulonglong, base_int
+from rpython.rlib.rarithmetic import r_uint, base_int
from rpython.rlib.rarithmetic import r_singlefloat, r_longfloat
import inspect, weakref
diff --git a/rpython/annotator/policy.py b/rpython/annotator/policy.py
--- a/rpython/annotator/policy.py
+++ b/rpython/annotator/policy.py
@@ -2,11 +2,6 @@
from rpython.annotator.specialize import default_specialize as default
from rpython.annotator.specialize import specialize_argvalue, specialize_argtype, specialize_arglistitemtype, specialize_arg_or_var
from rpython.annotator.specialize import memo, specialize_call_location
-# for some reason, model must be imported first,
-# or we create a cycle.
-from rpython.annotator import model as annmodel
-from rpython.annotator.bookkeeper import getbookkeeper
-from rpython.annotator.signature import Sig
class BasicAnnotatorPolicy(object):
diff --git a/rpython/annotator/specialize.py b/rpython/annotator/specialize.py
--- a/rpython/annotator/specialize.py
+++ b/rpython/annotator/specialize.py
@@ -1,10 +1,10 @@
# specialization support
import py
-from rpython.tool.uid import uid
+
from rpython.tool.sourcetools import func_with_new_name
from rpython.tool.algo.unionfind import UnionFind
from rpython.flowspace.model import Block, Link, Variable, SpaceOperation
-from rpython.flowspace.model import Constant, checkgraph
+from rpython.flowspace.model import checkgraph
from rpython.annotator import model as annmodel
from rpython.flowspace.argument import Signature
@@ -22,7 +22,7 @@
nb_extra_args = s_len.const
flattened_s = list(args_s[:-1])
flattened_s.extend(s_tuple.items)
-
+
def builder(translator, func):
# build a hacked graph that doesn't take a *arg any more, but
# individual extra arguments
@@ -93,7 +93,6 @@
result.append(graph)
assert len(result) == 1
return result[0]
-
# ____________________________________________________________________________
# specializations
@@ -189,8 +188,6 @@
# is the arg a bool?
elif nextargvalues == [False, True]:
- fieldname0 = self.getuniquefieldname()
- fieldname1 = self.getuniquefieldname()
stmt = ['if %s:' % argnames[firstarg]]
if hasattr(nextfns[True], 'constant_result'):
# the True branch has a constant result
diff --git a/rpython/annotator/unaryop.py b/rpython/annotator/unaryop.py
--- a/rpython/annotator/unaryop.py
+++ b/rpython/annotator/unaryop.py
@@ -430,7 +430,7 @@
return dct.dictdef.read_value()
def _can_only_throw(dic, *ignore):
- if dic1.dictdef.dictkey.custom_eq_hash:
+ if dic.dictdef.dictkey.custom_eq_hash:
return None # r_dict: can throw anything
return [] # else: no possible exception
@@ -753,10 +753,8 @@
class __extend__(SomeGenericCallable):
def call(self, args):
- bookkeeper = getbookkeeper()
for arg, expected in zip(args.unpack()[0], self.args_s):
assert expected.contains(arg)
-
return self.s_result
class __extend__(SomeExternalObject):
@@ -769,13 +767,13 @@
else:
return SomeObject()
getattr.can_only_throw = []
-
+
def setattr(p, s_attr, s_value):
assert s_attr.is_constant()
attr = s_attr.const
entry = extregistry.lookup_type(p.knowntype)
entry.set_field_annotation(p.knowntype, attr, s_value)
-
+
def is_true(p):
return s_Bool
More information about the pypy-commit
mailing list