diff options
author | 2021-01-21 20:31:40 +0100 | |
---|---|---|
committer | 2021-01-21 20:31:40 +0100 | |
commit | c95ee8f01f4d5d199ffed1a1c43afa0efc9d8c3d (patch) | |
tree | d48c4f9acb83f553d3e050c85ae5ed0aabee7a2c /pypy/objspace | |
parent | fix interaction of reordering and unboxing (diff) | |
download | pypy-c95ee8f01f4d5d199ffed1a1c43afa0efc9d8c3d.tar.gz pypy-c95ee8f01f4d5d199ffed1a1c43afa0efc9d8c3d.tar.bz2 pypy-c95ee8f01f4d5d199ffed1a1c43afa0efc9d8c3d.zip |
another reordering bug
Diffstat (limited to 'pypy/objspace')
-rw-r--r-- | pypy/objspace/std/mapdict.py | 18 | ||||
-rw-r--r-- | pypy/objspace/std/test/test_mapdict.py | 15 |
2 files changed, 23 insertions, 10 deletions
diff --git a/pypy/objspace/std/mapdict.py b/pypy/objspace/std/mapdict.py index cd36c331c1..4c94551394 100644 --- a/pypy/objspace/std/mapdict.py +++ b/pypy/objspace/std/mapdict.py @@ -155,13 +155,7 @@ class AbstractAttribute(object): def add_attr(self, obj, name, attrkind, w_value): space = self.space - unbox_type = None - if self.terminator.allow_unboxing: - if type(w_value) is space.IntObjectCls: - unbox_type = space.IntObjectCls - elif type(w_value) is space.FloatObjectCls: - unbox_type = space.FloatObjectCls - self._reorder_and_add(obj, name, attrkind, w_value, unbox_type) + self._reorder_and_add(obj, name, attrkind, w_value) if not jit.we_are_jitted(): oldattr = self attr = obj._get_mapdict_map() @@ -196,11 +190,11 @@ class AbstractAttribute(object): current_order = current.order current = current.back - @jit.look_inside_iff(lambda self, obj, name, attrkind, w_value, unbox_type: + @jit.look_inside_iff(lambda self, obj, name, attrkind, w_value: jit.isconstant(self) and jit.isconstant(name) and jit.isconstant(attrkind)) - def _reorder_and_add(self, obj, name, attrkind, w_value, unbox_type): + def _reorder_and_add(self, obj, name, attrkind, w_value): # the idea is as follows: the subtrees of any map are ordered by # insertion. the invariant is that subtrees that are inserted later # must not contain the name of the attribute of any earlier inserted @@ -224,6 +218,12 @@ class AbstractAttribute(object): stack_index = 0 while True: current = self + unbox_type = None + if self.terminator.allow_unboxing: + if type(w_value) is self.space.IntObjectCls: + unbox_type = self.space.IntObjectCls + elif type(w_value) is self.space.FloatObjectCls: + unbox_type = self.space.FloatObjectCls number_to_readd, attr = self._find_branch_to_move_into(name, attrkind, unbox_type) # we found the attributes further up, need to save the # previous values of the attributes we passed diff --git a/pypy/objspace/std/test/test_mapdict.py b/pypy/objspace/std/test/test_mapdict.py index 7cd582e612..9780f7767f 100644 --- a/pypy/objspace/std/test/test_mapdict.py +++ b/pypy/objspace/std/test/test_mapdict.py @@ -721,10 +721,23 @@ def test_unboxed_reorder_add_bug(): assert obj.map is obj2.map +def test_unboxed_reorder_add_bug2(): + cls = Class(allow_unboxing=True) + obj = cls.instantiate() + obj.setdictvalue(space, "a", 10) + obj.setdictvalue(space, "b", "20") + obj.setdictvalue(space, "c", "20") + + obj2 = cls.instantiate() + obj2.setdictvalue(space, "b", "30") + obj2.setdictvalue(space, "c", "40") + obj2.setdictvalue(space, "a", 23) + + assert obj.map is obj2.map def test_unboxed_insert_different_orders_perm(): from itertools import permutations - cls = Class() + cls = Class(allow_unboxing=True) seen_maps = {} for preexisting in ['', 'x', 'xy']: for i, attributes in enumerate(permutations("abcdef")): |