[pypy-svn] r59075 - in pypy/dist/pypy/translator: goal tool tool/test

xoraxax at codespeak.net xoraxax at codespeak.net
Mon Oct 13 23:32:51 CEST 2008


Author: xoraxax
Date: Mon Oct 13 23:32:49 2008
New Revision: 59075

Modified:
   pypy/dist/pypy/translator/goal/targettestdicts.py
   pypy/dist/pypy/translator/goal/targettestlistvsdict.py
   pypy/dist/pypy/translator/tool/staticsizereport.py
   pypy/dist/pypy/translator/tool/test/test_staticsizereport.py
Log:
Modify test targets to provide info that is more easy to compare, fix a bug in the staticsizereport code that resulted in incorrect accounting of inlined structures.

Modified: pypy/dist/pypy/translator/goal/targettestdicts.py
==============================================================================
--- pypy/dist/pypy/translator/goal/targettestdicts.py	(original)
+++ pypy/dist/pypy/translator/goal/targettestdicts.py	Mon Oct 13 23:32:49 2008
@@ -14,7 +14,7 @@
 
 # __________  Entry point  __________
 
-test_dict = dict(map(lambda x: (x, hex(x)), range(5000)))
+test_dict = dict(map(lambda x: (x, hex(x)), range(256, 4096)))
 reverse_dict = dict(map(lambda (x,y): (y,x), test_dict.items()))
 
 def entry_point(argv):

Modified: pypy/dist/pypy/translator/goal/targettestlistvsdict.py
==============================================================================
--- pypy/dist/pypy/translator/goal/targettestlistvsdict.py	(original)
+++ pypy/dist/pypy/translator/goal/targettestlistvsdict.py	Mon Oct 13 23:32:49 2008
@@ -14,8 +14,9 @@
 
 # __________  Entry point  __________
 
-test_list = map(hex, range(5000))
-test_dict = dict(map(lambda x: (x, hex(x)), range(5000)))
+numbers = range(1000, 5000)
+test_list = map(str, numbers)
+test_dict = dict(map(lambda x: (x, str(x)), numbers))
 
 def entry_point(argv):
     if argv[1] == 'd':

Modified: pypy/dist/pypy/translator/tool/staticsizereport.py
==============================================================================
--- pypy/dist/pypy/translator/tool/staticsizereport.py	(original)
+++ pypy/dist/pypy/translator/tool/staticsizereport.py	Mon Oct 13 23:32:49 2008
@@ -51,10 +51,14 @@
 def values_to_nodes(database, values):
     nodes = []
     for value in values:
-        if isinstance(typeOf(value), Ptr) and isinstance(typeOf(value._obj), ContainerType):
-            node = database.getcontainernode(value._obj)
-            if node.nodekind != 'func':
-                nodes.append(node)
+        if isinstance(typeOf(value), Ptr):
+            container = value._obj
+            if isinstance(typeOf(container), ContainerType):
+                node = database.getcontainernode(container)
+                if node.nodekind != 'func':
+                    nodes.append(node)
+        elif isinstance(typeOf(value), ContainerType): # inlined container
+            nodes.extend(values_to_nodes(database, database.getcontainernode(value).enum_dependencies()))
     return nodes
 
 

Modified: pypy/dist/pypy/translator/tool/test/test_staticsizereport.py
==============================================================================
--- pypy/dist/pypy/translator/tool/test/test_staticsizereport.py	(original)
+++ pypy/dist/pypy/translator/tool/test/test_staticsizereport.py	Mon Oct 13 23:32:49 2008
@@ -1,5 +1,6 @@
 from pypy.translator.c.test.test_typed import CompilationTestCase
 from pypy.translator.tool.staticsizereport import group_static_size, guess_size
+from pypy.rpython.lltypesystem import llmemory, lltype, rffi
 
 class TestStaticSizeReport(CompilationTestCase):
     def test_simple(self):
@@ -23,6 +24,11 @@
 
     def test_large_dict(self):
         d = {}
+        d_small = {1:2}
+        fixlist = [x for x in range(100)]
+        dynlist = [x for x in range(100)]
+        test_dict = dict(map(lambda x: (x, hex(x)), range(256, 4096)))
+        reverse_dict = dict(map(lambda (x,y): (y,x), test_dict.items()))
         class wrap:
             pass
         for x in xrange(100):
@@ -30,9 +36,30 @@
             i.x = x
             d[x] = i
         def f(x):
-            return d[x].x
+            if x > 42:
+                dynlist.append(x)
+            return d[x].x + fixlist[x] + d_small[x] + reverse_dict[test_dict[x]]
         func = self.getcompiled(f, [int])
-        gcontainers = self.builder.db.globalcontainers()
-        dictvalnode = [node for node in gcontainers if "struct dicttable" in repr(node.obj)][0]
+        db = self.builder.db
+        gcontainers = list(db.globalcontainers())
+        t = db.translator
+        rtyper = t.rtyper
+        get_container = lambda x: rtyper.getrepr(t.annotator.bookkeeper.immutablevalue(x)).convert_const(x)._obj
+        dictvalnode = db.getcontainernode(get_container(d))
+        dictvalnode2 = db.getcontainernode(get_container(d_small))
+        fixarrayvalnode = db.getcontainernode(get_container(fixlist))
+        dynarrayvalnode = db.getcontainernode(get_container(dynlist))
+        test_dictnode = db.getcontainernode(get_container(test_dict))
+        reverse_dictnode = db.getcontainernode(get_container(reverse_dict))
+
+        S = rffi.sizeof(lltype.Signed)
+        P = rffi.sizeof(rffi.VOIDP)
+        B = 1 # bool
         assert guess_size(self.builder.db, dictvalnode, set()) > 100
-        #size, num = group_static_size(self.builder.db, gcontainers)
+        assert guess_size(self.builder.db, dictvalnode2, set()) == 2 * S + 1 * P + 1 * S + 8 * (2*S + 1 * B)
+        r_set = set()
+        dictnode_size = guess_size(db, test_dictnode, r_set)
+        assert dictnode_size == 2 * S + 1 * P + 1 * S + (4096-256) * (1*S+1*P + (1 * S + 1*P + 5)) + (8192-4096+256) * (1*S+1*P)
+        assert guess_size(self.builder.db, fixarrayvalnode, set()) == 100 * rffi.sizeof(lltype.Signed) + 1 * rffi.sizeof(lltype.Signed)
+        assert guess_size(self.builder.db, dynarrayvalnode, set()) == 100 * rffi.sizeof(lltype.Signed) + 2 * rffi.sizeof(lltype.Signed) + 1 * rffi.sizeof(rffi.VOIDP)
+



More information about the Pypy-commit mailing list