Author: Ronan Lamy <[email protected]>
Branch: less-stringly-ops
Changeset: r66774:2c9d5c1c85d7
Date: 2013-09-02 20:33 +0100
http://bitbucket.org/pypy/pypy/changeset/2c9d5c1c85d7/
Log: Add annotation SomeConstantType:
this is a SomePBC subclass that can be unified with SomeTypes.
diff --git a/rpython/annotator/binaryop.py b/rpython/annotator/binaryop.py
--- a/rpython/annotator/binaryop.py
+++ b/rpython/annotator/binaryop.py
@@ -5,18 +5,14 @@
import py
import operator
from rpython.tool.pairtype import pair, pairtype
-from rpython.annotator.model import SomeObject, SomeInteger, SomeBool, s_Bool
-from rpython.annotator.model import SomeString, SomeChar, SomeList, SomeDict
-from rpython.annotator.model import SomeUnicodeCodePoint, SomeUnicodeString
-from rpython.annotator.model import SomeTuple, SomeImpossibleValue,
s_ImpossibleValue
-from rpython.annotator.model import SomeInstance, SomeBuiltin, SomeIterator
-from rpython.annotator.model import SomePBC, SomeFloat, s_None, SomeByteArray
-from rpython.annotator.model import SomeWeakRef
-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 read_can_only_throw
-from rpython.annotator.model import add_knowntypedata, merge_knowntypedata
+from rpython.annotator.model import (
+ SomeObject, SomeInteger, SomeBool, s_Bool, SomeString, SomeChar, SomeList,
+ SomeDict, SomeUnicodeCodePoint, SomeUnicodeString, SomeTuple,
+ SomeImpossibleValue, s_ImpossibleValue, SomeInstance, SomeBuiltin,
+ SomeIterator, SomePBC, SomeFloat, s_None, SomeByteArray, SomeWeakRef,
+ SomeAddress, SomeTypedAddressAccess, SomeSingleFloat, SomeLongFloat,
+ SomeType, SomeConstantType, unionof, UnionError, missing_operation,
+ read_can_only_throw, add_knowntypedata, merge_knowntypedata,)
from rpython.annotator.bookkeeper import getbookkeeper
from rpython.flowspace.model import Variable, Constant
from rpython.rlib import rarithmetic
@@ -196,7 +192,9 @@
getitem_key = getitem_idx_key
-class __extend__(pairtype(SomeType, SomeType)):
+class __extend__(pairtype(SomeType, SomeType),
+ pairtype(SomeType, SomeConstantType),
+ pairtype(SomeConstantType, SomeType),):
def union((obj1, obj2)):
result = SomeType()
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 @@
SomeBuiltin, SomePBC, SomeInteger, TLS, SomeAddress, SomeUnicodeCodePoint,
s_None, s_ImpossibleValue, SomeLLADTMeth, SomeBool, SomeTuple,
SomeImpossibleValue, SomeUnicodeString, SomeList, HarmlesslyBlocked,
- SomeWeakRef, lltype_to_annotation, SomeType, SomeByteArray)
+ SomeWeakRef, lltype_to_annotation, SomeType, SomeByteArray,
SomeConstantType)
from rpython.annotator.classdef import InstanceSource, ClassDef
from rpython.annotator.listdef import ListDef, ListItem
from rpython.annotator.dictdef import DictDef
@@ -432,11 +432,7 @@
elif isinstance(x, llmemory.fakeaddress):
result = SomeAddress()
elif tp is type:
- if (x is type(None) or # add cases here if needed
- x.__module__ == 'rpython.rtyper.lltypesystem.lltype'):
- result = SomeType()
- else:
- result = SomePBC([self.getdesc(x)])
+ result = SomeConstantType(x, self)
elif callable(x):
if hasattr(x, 'im_self') and hasattr(x, 'im_func'):
# on top of PyPy, for cases like 'l.append' where 'l' is a
diff --git a/rpython/annotator/model.py b/rpython/annotator/model.py
--- a/rpython/annotator/model.py
+++ b/rpython/annotator/model.py
@@ -486,6 +486,14 @@
else:
return kt.__name__
+class SomeConstantType(SomePBC):
+ can_be_None = False
+ subset_of = None
+ def __init__(self, x, bk):
+ self.descriptions = set([bk.getdesc(x)])
+ self.knowntype = type(x)
+ self.const = x
+
class SomeBuiltin(SomeObject):
"Stands for a built-in function or method with special-cased analysis."
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit