Author: Maciej Fijalkowski <[email protected]>
Branch: rdict-experiments-2
Changeset: r59811:bae0ef64aac4
Date: 2013-01-06 18:47 +0200
http://bitbucket.org/pypy/pypy/changeset/bae0ef64aac4/

Log:    hack enough to start passing tests

diff --git a/pypy/annotation/bookkeeper.py b/pypy/annotation/bookkeeper.py
--- a/pypy/annotation/bookkeeper.py
+++ b/pypy/annotation/bookkeeper.py
@@ -298,13 +298,12 @@
             listdef.generalize_range_step(flags['range_step'])
         return SomeList(listdef)
 
-    def getdictdef(self, is_r_dict=False, force_non_null=False):
+    def getdictdef(self, is_r_dict=False):
         """Get the DictDef associated with the current position."""
         try:
             dictdef = self.dictdefs[self.position_key]
         except KeyError:
-            dictdef = DictDef(self, is_r_dict=is_r_dict,
-                              force_non_null=force_non_null)
+            dictdef = DictDef(self, is_r_dict=is_r_dict)
             self.dictdefs[self.position_key] = dictdef
         return dictdef
 
diff --git a/pypy/annotation/builtin.py b/pypy/annotation/builtin.py
--- a/pypy/annotation/builtin.py
+++ b/pypy/annotation/builtin.py
@@ -294,14 +294,8 @@
             clsdef = clsdef.commonbase(cdef)
     return SomeInstance(clsdef)
 
-def robjmodel_r_dict(s_eqfn, s_hashfn, s_force_non_null=None):
-    if s_force_non_null is None:
-        force_non_null = False
-    else:
-        assert s_force_non_null.is_constant()
-        force_non_null = s_force_non_null.const
-    dictdef = getbookkeeper().getdictdef(is_r_dict=True,
-                                         force_non_null=force_non_null)
+def robjmodel_r_dict(s_eqfn, s_hashfn):
+    dictdef = getbookkeeper().getdictdef(is_r_dict=True)
     dictdef.dictkey.update_rdict_annotations(s_eqfn, s_hashfn)
     return SomeDict(dictdef)
 
diff --git a/pypy/annotation/dictdef.py b/pypy/annotation/dictdef.py
--- a/pypy/annotation/dictdef.py
+++ b/pypy/annotation/dictdef.py
@@ -85,14 +85,12 @@
 
     def __init__(self, bookkeeper, s_key = s_ImpossibleValue,
                                  s_value = s_ImpossibleValue,
-                               is_r_dict = False,
-                           force_non_null = False):
+                               is_r_dict = False):
         self.dictkey = DictKey(bookkeeper, s_key, is_r_dict)
         self.dictkey.itemof[self] = True
         self.dictvalue = DictValue(bookkeeper, s_value)
         self.dictvalue.itemof[self] = True
         self.bookkeeper = bookkeeper
-        self.force_non_null = force_non_null
 
     def read_key(self, position_key=None):
         if position_key is None:
diff --git a/pypy/objspace/std/dictmultiobject.py 
b/pypy/objspace/std/dictmultiobject.py
--- a/pypy/objspace/std/dictmultiobject.py
+++ b/pypy/objspace/std/dictmultiobject.py
@@ -9,7 +9,6 @@
 
 from pypy.rlib.objectmodel import r_dict, we_are_translated, specialize,\
      newlist_hint
-from pypy.rlib.debug import mark_dict_non_null
 from pypy.tool.sourcetools import func_with_new_name
 
 from pypy.rlib import rerased
@@ -559,8 +558,7 @@
         return True
 
     def get_empty_storage(self):
-       new_dict = r_dict(self.space.eq_w, self.space.hash_w,
-                         force_non_null=True)
+       new_dict = r_dict(self.space.eq_w, self.space.hash_w)
        return self.erase(new_dict)
 
     def _never_equal_to(self, w_lookup_type):
@@ -589,7 +587,6 @@
 
     def get_empty_storage(self):
         res = {}
-        mark_dict_non_null(res)
         return self.erase(res)
 
     def _never_equal_to(self, w_lookup_type):
@@ -654,7 +651,6 @@
 
     def get_empty_storage(self):
         res = {}
-        mark_dict_non_null(res)
         return self.erase(res)
 
     def _never_equal_to(self, w_lookup_type):
diff --git a/pypy/objspace/std/identitydict.py 
b/pypy/objspace/std/identitydict.py
--- a/pypy/objspace/std/identitydict.py
+++ b/pypy/objspace/std/identitydict.py
@@ -2,7 +2,6 @@
 ## dict strategy (see dictmultiobject.py)
 
 from pypy.rlib import rerased
-from pypy.rlib.debug import mark_dict_non_null
 from pypy.objspace.std.dictmultiobject import (AbstractTypedStrategy,
                                                DictStrategy,
                                                create_iterator_classes)
@@ -66,7 +65,6 @@
 
     def get_empty_storage(self):
         d = {}
-        mark_dict_non_null(d)
         return self.erase(d)
 
     def is_correct_type(self, w_obj):
diff --git a/pypy/objspace/std/setobject.py b/pypy/objspace/std/setobject.py
--- a/pypy/objspace/std/setobject.py
+++ b/pypy/objspace/std/setobject.py
@@ -982,7 +982,7 @@
 # some helper functions
 
 def newset(space):
-    return r_dict(space.eq_w, space.hash_w, force_non_null=True)
+    return r_dict(space.eq_w, space.hash_w)
 
 def set_strategy_and_setdata(space, w_set, w_iterable):
     from pypy.objspace.std.intobject import W_IntObject
diff --git a/pypy/rlib/debug.py b/pypy/rlib/debug.py
--- a/pypy/rlib/debug.py
+++ b/pypy/rlib/debug.py
@@ -284,28 +284,6 @@
         return hop.inputarg(hop.args_r[0], arg=0)
 
 
-def mark_dict_non_null(d):
-    """ Mark dictionary as having non-null keys and values. A warning would
-    be emitted (not an error!) in case annotation disagrees.
-    """
-    assert isinstance(d, dict)
-    return d
-
-
-class DictMarkEntry(ExtRegistryEntry):
-    _about_ = mark_dict_non_null
-    
-    def compute_result_annotation(self, s_dict):
-        from pypy.annotation.model import SomeDict, s_None
-
-        assert isinstance(s_dict, SomeDict)
-        s_dict.dictdef.force_non_null = True
-        return s_dict
-
-    def specialize_call(self, hop):
-        hop.exception_cannot_occur()
-        return hop.inputarg(hop.args_r[0], arg=0)
-
 class IntegerCanBeNegative(Exception):
     pass
 
diff --git a/pypy/rlib/objectmodel.py b/pypy/rlib/objectmodel.py
--- a/pypy/rlib/objectmodel.py
+++ b/pypy/rlib/objectmodel.py
@@ -650,11 +650,10 @@
     The functions key_eq() and key_hash() are used by the key comparison
     algorithm."""
 
-    def __init__(self, key_eq, key_hash, force_non_null=False):
+    def __init__(self, key_eq, key_hash):
         self._dict = {}
         self.key_eq = key_eq
         self.key_hash = key_hash
-        self.force_non_null = force_non_null
 
     def __getitem__(self, key):
         return self._dict[_r_dictkey(self, key)]
diff --git a/pypy/rlib/test/test_debug.py b/pypy/rlib/test/test_debug.py
--- a/pypy/rlib/test/test_debug.py
+++ b/pypy/rlib/test/test_debug.py
@@ -3,8 +3,8 @@
 from pypy.rlib.debug import (check_annotation, make_sure_not_resized,
                              debug_print, debug_start, debug_stop,
                              have_debug_prints, debug_offset, debug_flush,
-                             check_nonneg, IntegerCanBeNegative,
-                             mark_dict_non_null)
+                             check_nonneg, IntegerCanBeNegative)
+
 from pypy.rlib import debug
 from pypy.rpython.test.test_llinterp import interpret, gengraph
 
@@ -53,15 +53,6 @@
     py.test.raises(ListChangeUnallowed, interpret, f, [], 
                    list_comprehension_operations=True)
 
-def test_mark_dict_non_null():
-    def f():
-        d = {"ac": "bx"}
-        mark_dict_non_null(d)
-        return d
-
-    t, typer, graph = gengraph(f, [])
-    assert 
sorted(graph.returnblock.inputargs[0].concretetype.TO.entries.TO.OF._flds.keys())
 == ['key', 'value']
-
 
 class DebugTests(object):
 
diff --git a/pypy/rpython/lltypesystem/rdict.py 
b/pypy/rpython/lltypesystem/rdict.py
--- a/pypy/rpython/lltypesystem/rdict.py
+++ b/pypy/rpython/lltypesystem/rdict.py
@@ -147,7 +147,11 @@
         if isinstance(self.DICT, lltype.GcForwardReference):
             DICTKEY = self.key_repr.lowleveltype
             DICTVALUE = self.value_repr.lowleveltype
-            xxx
+            get_ll_dict(DICTKEY, DICTVALUE, DICT=self.DICT,
+                 ll_fasthash_function=self.key_repr.get_ll_fasthash_function(),
+                 ll_hash_function=self.key_repr.get_ll_hash_function(),
+                 ll_eq_function=self.key_repr.get_ll_eq_function(),
+                 get_custom_eq_hash=self.custom_eq_hash)
 
     def convert_const(self, dictobj):
         from pypy.rpython.lltypesystem import llmemory
@@ -372,8 +376,9 @@
     i = i & MASK
     ENTRY = lltype.typeOf(d.entries).TO.OF
     index = d.indexes[i]
-    entry = d.entries[index]
     if index == FREE:
+        index = d.num_items
+        entry = d.entries[index]
         # a new entry that was never used before
         ll_assert(not valid, "valid but not everused")
         rc = d.resize_counter - 3
@@ -385,16 +390,21 @@
             rc = d.resize_counter - 3
             ll_assert(rc > 0, "ll_dict_resize failed?")
         d.resize_counter = rc
-        if hasattr(ENTRY, 'f_everused'): entry.f_everused = True
+        d.indexes[i] = index
+        entry.value = value
+    elif index == DELETED:
+        index = d.num_items
+        entry = d.entries[index]        
+        d.indexes[i] = index
         entry.value = value
     else:
         # override an existing or deleted entry
+        entry = d.entries[index]
         entry.value = value
         if valid:
             return
     entry.key = key
     if hasattr(ENTRY, 'f_hash'):  entry.f_hash = hash
-    if hasattr(ENTRY, 'f_valid'): entry.f_valid = True
     d.num_items += 1
 
 def ll_dict_insertclean(d, key, value, hash):
@@ -482,15 +492,13 @@
 def ll_dict_lookup(d, key, hash):
     entries = d.entries
     indexes = d.indexes
-    ENTRIES = lltype.typeOf(entries).TO
-    direct_compare = not hasattr(ENTRIES, 'no_direct_compare')
     mask = len(entries) - 1
     i = hash & mask
     # do the first try before any looping
     index = indexes[i]
     if index >= 0:
         checkingkey = entries[index].key
-        if direct_compare and checkingkey == key:
+        if checkingkey == key:
             return index   # found the entry
         if d.keyeq is not None and entries.hash(index) == hash:
             # correct hash, maybe the key is e.g. a different pointer to
@@ -526,7 +534,7 @@
             return freeslot | HIGHEST_BIT
         elif index >= 0:
             checkingkey = entries[index].key
-            if direct_compare and checkingkey == key:
+            if checkingkey == key:
                 return index
             if d.keyeq is not None and entries.hash(index) == hash:
                 # correct hash, maybe the key is e.g. a different pointer to
@@ -713,8 +721,6 @@
         entry = dict.entries[i]
         ENTRY = lltype.typeOf(d.entries).TO.OF
         d_entry.key = entry.key
-        if hasattr(ENTRY, 'f_valid'):    d_entry.f_valid    = entry.f_valid
-        if hasattr(ENTRY, 'f_everused'): d_entry.f_everused = entry.f_everused
         d_entry.value = entry.value
         if hasattr(ENTRY, 'f_hash'):     d_entry.f_hash     = entry.f_hash
         i += 1
diff --git a/pypy/rpython/ootypesystem/rdict.py 
b/pypy/rpython/ootypesystem/rdict.py
--- a/pypy/rpython/ootypesystem/rdict.py
+++ b/pypy/rpython/ootypesystem/rdict.py
@@ -13,7 +13,7 @@
 
 class DictRepr(AbstractDictRepr):
     def __init__(self, rtyper, key_repr, value_repr, dictkey, dictvalue,
-                 custom_eq_hash=None, force_non_null=False):
+                 custom_eq_hash=None):
         self.rtyper = rtyper
         self.custom_eq_hash = custom_eq_hash is not None
 
@@ -260,7 +260,7 @@
         methodname = None
     return fn, v_obj, methodname
 
-def rtype_r_dict(hop, i_force_non_null=None):
+def rtype_r_dict(hop):
     from pypy.rlib import jit
 
     r_dict = hop.r_result
diff --git a/pypy/rpython/rdict.py b/pypy/rpython/rdict.py
--- a/pypy/rpython/rdict.py
+++ b/pypy/rpython/rdict.py
@@ -9,7 +9,6 @@
         dictvalue = self.dictdef.dictvalue
         s_key     = dictkey  .s_value
         s_value   = dictvalue.s_value
-        force_non_null = self.dictdef.force_non_null
         if dictkey.custom_eq_hash:
             custom_eq_hash = lambda: (rtyper.getrepr(dictkey.s_rdict_eqfn),
                                       rtyper.getrepr(dictkey.s_rdict_hashfn))
@@ -20,8 +19,7 @@
                                                  lambda: 
rtyper.getrepr(s_value),
                                                  dictkey,
                                                  dictvalue,
-                                                 custom_eq_hash,
-                                                 force_non_null)
+                                                 custom_eq_hash)
 
     def rtyper_makekey(self):
         self.dictdef.dictkey  .dont_change_any_more = True
diff --git a/pypy/rpython/test/test_rdict.py b/pypy/rpython/test/test_rdict.py
--- a/pypy/rpython/test/test_rdict.py
+++ b/pypy/rpython/test/test_rdict.py
@@ -32,6 +32,10 @@
                                  ll_eq_function=rstr.LLHelpers.ll_streq)
         ll_d = rdict.ll_newdict(DICT)
         rdict.ll_dict_setitem(ll_d, llstr("abc"), 13)
+        assert (len([i for i in ll_d.indexes if i == rdict.FREE]) ==
+                rdict.DICT_INITSIZE - 1)
+        assert rdict.ll_dict_getitem(ll_d, llstr("abc")) == 13
+
 
 class BaseTestRdict(BaseRtypingTest):
 
@@ -969,7 +973,7 @@
             return 3
 
         def func(i):
-            d = r_dict(eq, rhash, force_non_null=True)
+            d = r_dict(eq, rhash)
             if not i:
                 d[None] = i
             else:
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to