Author: Ronan Lamy <[email protected]>
Branch:
Changeset: r71737:857289bf8ff9
Date: 2014-05-26 21:11 +0100
http://bitbucket.org/pypy/pypy/changeset/857289bf8ff9/
Log: start splitting SomePBC and SomeNone
diff --git a/rpython/annotator/binaryop.py b/rpython/annotator/binaryop.py
--- a/rpython/annotator/binaryop.py
+++ b/rpython/annotator/binaryop.py
@@ -9,8 +9,8 @@
SomeObject, SomeInteger, SomeBool, s_Bool, SomeString, SomeChar, SomeList,
SomeDict, SomeOrderedDict, SomeUnicodeCodePoint, SomeUnicodeString,
SomeTuple, SomeImpossibleValue, s_ImpossibleValue, SomeInstance,
- SomeBuiltinMethod, SomeIterator, SomePBC, SomeFloat, s_None, SomeByteArray,
- SomeWeakRef, SomeSingleFloat,
+ SomeBuiltinMethod, SomeIterator, SomePBC, SomeNone, SomeFloat, s_None,
+ SomeByteArray, SomeWeakRef, SomeSingleFloat,
SomeLongFloat, SomeType, SomeConstantType, unionof, UnionError,
read_can_only_throw, add_knowntypedata,
merge_knowntypedata,)
@@ -773,19 +773,13 @@
glob = globals()
loc = locals()
source = py.code.Source("""
- class __extend__(pairtype(%(classname)s, SomePBC)):
- def union((obj, pbc)):
- if pbc.isNone():
- return %(classname)s(%(constructor_args)s)
- else:
- raise UnionError(pbc, obj)
+ class __extend__(pairtype(%(classname)s, SomeNone)):
+ def union((obj, none)):
+ return %(classname)s(%(constructor_args)s)
- class __extend__(pairtype(SomePBC, %(classname)s)):
- def union((pbc, obj)):
- if pbc.isNone():
- return %(classname)s(%(constructor_args)s)
- else:
- raise UnionError(pbc, obj)
+ class __extend__(pairtype(SomeNone, %(classname)s)):
+ def union((none, obj)):
+ return %(classname)s(%(constructor_args)s)
""" % loc)
exec source.compile() in glob
diff --git a/rpython/annotator/classdef.py b/rpython/annotator/classdef.py
--- a/rpython/annotator/classdef.py
+++ b/rpython/annotator/classdef.py
@@ -1,8 +1,9 @@
"""
Type inference for user-defined classes.
"""
-from rpython.annotator.model import SomePBC, s_ImpossibleValue, unionof
-from rpython.annotator.model import SomeInteger, SomeTuple, SomeString,
AnnotatorError
+from rpython.annotator.model import (
+ SomePBC, s_ImpossibleValue, unionof, s_None, SomeInteger, SomeTuple,
+ SomeString, AnnotatorError)
from rpython.annotator import description
@@ -351,8 +352,10 @@
if uplookup is not None:
d.append(updesc.bind_self(self, flags))
- if d or pbc.can_be_None:
+ if d:
return SomePBC(d, can_be_None=pbc.can_be_None)
+ elif pbc.can_be_None:
+ return s_None
else:
return s_ImpossibleValue
diff --git a/rpython/annotator/model.py b/rpython/annotator/model.py
--- a/rpython/annotator/model.py
+++ b/rpython/annotator/model.py
@@ -424,36 +424,32 @@
immutable = True
def __init__(self, descriptions, can_be_None=False, subset_of=None):
+ assert descriptions
# descriptions is a set of Desc instances
descriptions = set(descriptions)
self.descriptions = descriptions
self.can_be_None = can_be_None
self.subset_of = subset_of
self.simplify()
- if self.isNone():
- self.knowntype = type(None)
- self.const = None
- else:
- knowntype = reduce(commonbase,
- [x.knowntype for x in descriptions])
- if knowntype == type(Exception):
- knowntype = type
- if knowntype != object:
- self.knowntype = knowntype
- if len(descriptions) == 1 and not can_be_None:
- # hack for the convenience of direct callers to SomePBC():
- # only if there is a single object in descriptions
- desc, = descriptions
- if desc.pyobj is not None:
- self.const = desc.pyobj
- elif len(descriptions) > 1:
- from rpython.annotator.description import ClassDesc
- if self.getKind() is ClassDesc:
- # a PBC of several classes: enforce them all to be
- # built, without support for specialization. See
- # rpython/test/test_rpbc.test_pbc_of_classes_not_all_used
- for desc in descriptions:
- desc.getuniqueclassdef()
+ knowntype = reduce(commonbase, [x.knowntype for x in descriptions])
+ if knowntype == type(Exception):
+ knowntype = type
+ if knowntype != object:
+ self.knowntype = knowntype
+ if len(descriptions) == 1 and not can_be_None:
+ # hack for the convenience of direct callers to SomePBC():
+ # only if there is a single object in descriptions
+ desc, = descriptions
+ if desc.pyobj is not None:
+ self.const = desc.pyobj
+ elif len(descriptions) > 1:
+ from rpython.annotator.description import ClassDesc
+ if self.getKind() is ClassDesc:
+ # a PBC of several classes: enforce them all to be
+ # built, without support for specialization. See
+ # rpython/test/test_rpbc.test_pbc_of_classes_not_all_used
+ for desc in descriptions:
+ desc.getuniqueclassdef()
def any_description(self):
return iter(self.descriptions).next()
@@ -466,32 +462,24 @@
kinds.add(x.__class__)
if len(kinds) > 1:
raise AnnotatorError("mixing several kinds of PBCs: %r" % kinds)
- if not kinds:
- raise ValueError("no 'kind' on the 'None' PBC")
return kinds.pop()
def simplify(self):
- if self.descriptions:
- # We check that the set only contains a single kind of Desc
instance
- kind = self.getKind()
- # then we remove unnecessary entries in self.descriptions:
- # some MethodDescs can be 'shadowed' by others
- if len(self.descriptions) > 1:
- kind.simplify_desc_set(self.descriptions)
- else:
- assert self.can_be_None, "use s_ImpossibleValue"
+ # We check that the set only contains a single kind of Desc instance
+ kind = self.getKind()
+ # then we remove unnecessary entries in self.descriptions:
+ # some MethodDescs can be 'shadowed' by others
+ if len(self.descriptions) > 1:
+ kind.simplify_desc_set(self.descriptions)
def isNone(self):
- return len(self.descriptions) == 0
+ return False
def can_be_none(self):
return self.can_be_None
def nonnoneify(self):
- if self.isNone():
- return s_ImpossibleValue
- else:
- return SomePBC(self.descriptions, can_be_None=False)
+ return SomePBC(self.descriptions, can_be_None=False)
def fmt_descriptions(self, pbis):
if hasattr(self, 'const'):
@@ -527,6 +515,10 @@
def is_immutable_constant(self):
return True
+ def nonnoneify(self):
+ return s_ImpossibleValue
+
+
class SomeConstantType(SomePBC):
can_be_None = False
subset_of = None
diff --git a/rpython/annotator/unaryop.py b/rpython/annotator/unaryop.py
--- a/rpython/annotator/unaryop.py
+++ b/rpython/annotator/unaryop.py
@@ -8,7 +8,7 @@
from rpython.annotator.model import (SomeObject, SomeInteger, SomeBool,
SomeString, SomeChar, SomeList, SomeDict, SomeTuple, SomeImpossibleValue,
SomeUnicodeCodePoint, SomeInstance, SomeBuiltin, SomeBuiltinMethod,
- SomeFloat, SomeIterator, SomePBC, SomeType, s_ImpossibleValue,
+ SomeFloat, SomeIterator, SomePBC, SomeNone, SomeType, s_ImpossibleValue,
s_Bool, s_None, unionof, add_knowntypedata,
HarmlesslyBlocked, SomeWeakRef, SomeUnicodeString, SomeByteArray)
from rpython.annotator.bookkeeper import getbookkeeper, immutablevalue
@@ -765,6 +765,10 @@
# This should probably never happen
raise AnnotatorError("Cannot call len on a pbc")
+class __extend__(SomeNone):
+ def bind_callables_under(self, classdef, name):
+ return self
+
#_________________________________________
# weakrefs
diff --git a/rpython/rtyper/controllerentry.py
b/rpython/rtyper/controllerentry.py
--- a/rpython/rtyper/controllerentry.py
+++ b/rpython/rtyper/controllerentry.py
@@ -1,6 +1,6 @@
from rpython.annotator import model as annmodel
from rpython.tool.pairtype import pairtype
-from rpython.annotator.binaryop import _make_none_union, SomePBC # SomePBC
needed by _make_none_union
+from rpython.annotator.binaryop import _make_none_union, SomeNone # SomeNone
needed by _make_none_union
from rpython.annotator.bookkeeper import getbookkeeper
from rpython.rtyper.extregistry import ExtRegistryEntry
from rpython.rtyper.annlowlevel import cachedtype
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit