Skip to content

Commit 5fea4bf

Browse files
msimacektimfel
authored andcommitted
Don't call __del__ from EconomicMapStorage
1 parent 3864ad0 commit 5fea4bf

File tree

2 files changed

+12
-85
lines changed

2 files changed

+12
-85
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/EconomicMapStorage.java

Lines changed: 12 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,13 @@
4040
*/
4141
package com.oracle.graal.python.builtins.objects.common;
4242

43-
import static com.oracle.graal.python.nodes.SpecialMethodNames.__DEL__;
4443
import static com.oracle.graal.python.nodes.SpecialMethodNames.__EQ__;
4544
import static com.oracle.graal.python.nodes.SpecialMethodNames.__HASH__;
4645

4746
import java.util.Iterator;
4847

4948
import org.graalvm.collections.MapCursor;
5049

51-
import com.oracle.graal.python.builtins.objects.PNone;
5250
import com.oracle.graal.python.builtins.objects.common.HashingStorageLibrary.ForEachNode;
5351
import com.oracle.graal.python.builtins.objects.common.HashingStorageLibrary.HashingStorageIterable;
5452
import com.oracle.graal.python.builtins.objects.function.PArguments;
@@ -60,7 +58,6 @@
6058
import com.oracle.graal.python.lib.PyObjectHashNode;
6159
import com.oracle.graal.python.nodes.PGuards;
6260
import com.oracle.graal.python.nodes.attributes.LookupInheritedAttributeNode;
63-
import com.oracle.graal.python.nodes.call.special.CallUnaryMethodNode;
6461
import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
6562
import com.oracle.truffle.api.CompilerAsserts;
6663
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
@@ -176,10 +173,7 @@ static boolean isBuiltin(PythonObject o, IsBuiltinClassProfile p) {
176173
}
177174

178175
static boolean maySideEffect(PythonObject o, LookupInheritedAttributeNode.Dynamic lookup) {
179-
boolean se = lookup.execute(o, __DEL__) != PNone.NO_VALUE;
180-
se = se || !PGuards.isBuiltinFunction(lookup.execute(o, __EQ__));
181-
se = se || !PGuards.isBuiltinFunction(lookup.execute(o, __HASH__));
182-
return se;
176+
return !PGuards.isBuiltinFunction(lookup.execute(o, __EQ__)) || !PGuards.isBuiltinFunction(lookup.execute(o, __HASH__));
183177
}
184178

185179
@Specialization
@@ -322,78 +316,21 @@ static HashingStorage generic(EconomicMapStorage self, HashingStorage other,
322316
}
323317
}
324318

325-
private static boolean hasDELSideEffect(Object o, LookupInheritedAttributeNode.Dynamic lookup) {
326-
return o instanceof PythonObject && lookup.execute(o, __DEL__) != PNone.NO_VALUE;
327-
}
328-
329319
@ExportMessage
330-
static class DelItemWithState {
331-
332-
@Specialization(guards = "!hasSideEffect(self)")
333-
static HashingStorage delItemWithState(EconomicMapStorage self, Object key, ThreadState state,
334-
@Shared("plib") @CachedLibrary(limit = "3") PythonObjectLibrary lib,
335-
@Shared("hashNode") @Cached PyObjectHashNode hashNode,
336-
@Shared("gotState") @Cached ConditionProfile gotState) {
337-
VirtualFrame frame = gotState.profile(state == null) ? null : PArguments.frameForCall(state);
338-
DictKey newKey = new DictKey(key, hashNode.execute(frame, key));
339-
self.map.removeKey(newKey, lib, lib, gotState, state);
340-
return self;
341-
}
342-
343-
@Specialization
344-
static HashingStorage delItemWithStateWithSideEffect(EconomicMapStorage self, Object key, ThreadState state,
345-
@Shared("plib") @CachedLibrary(limit = "3") PythonObjectLibrary lib,
346-
@Shared("hashNode") @Cached PyObjectHashNode hashNode,
347-
@Shared("lookupDel") @Cached LookupInheritedAttributeNode.Dynamic lookup,
348-
@Shared("callDel") @Cached CallUnaryMethodNode callNode,
349-
@Shared("gotState") @Cached ConditionProfile gotState) {
350-
VirtualFrame frame = gotState.profile(state == null) ? null : PArguments.frameForCall(state);
351-
DictKey newKey = new DictKey(key, hashNode.execute(frame, key));
352-
Object value = self.map.removeKey(newKey, lib, lib, gotState, state);
353-
if (hasDELSideEffect(key, lookup)) {
354-
callNode.executeObject(frame, lookup.execute(key, __DEL__), key);
355-
}
356-
if (hasDELSideEffect(value, lookup)) {
357-
callNode.executeObject(frame, lookup.execute(value, __DEL__), value);
358-
}
359-
return self;
360-
}
320+
HashingStorage delItemWithState(Object key, ThreadState state,
321+
@Shared("plib") @CachedLibrary(limit = "3") PythonObjectLibrary lib,
322+
@Shared("hashNode") @Cached PyObjectHashNode hashNode,
323+
@Shared("gotState") @Cached ConditionProfile gotState) {
324+
VirtualFrame frame = gotState.profile(state == null) ? null : PArguments.frameForCall(state);
325+
DictKey newKey = new DictKey(key, hashNode.execute(frame, key));
326+
map.removeKey(newKey, lib, lib, gotState, state);
327+
return this;
361328
}
362329

363330
@ExportMessage
364-
static class Clear {
365-
366-
@Specialization(guards = "!hasSideEffect(self)")
367-
static HashingStorage clear(EconomicMapStorage self) {
368-
self.map.clear();
369-
return self;
370-
}
371-
372-
@Specialization
373-
static HashingStorage clearWithSideEffect(EconomicMapStorage self,
374-
@Shared("lookupDel") @Cached LookupInheritedAttributeNode.Dynamic lookup,
375-
@Shared("callDel") @Cached CallUnaryMethodNode callNode) {
376-
if (self.map.size() == 0) {
377-
return self;
378-
}
379-
Object[] entries = new Object[self.map.size() * 2];
380-
MapCursor<DictKey, Object> cursor = self.map.getEntries();
381-
int i = 0;
382-
while (advance(cursor)) {
383-
Object key = getKey(cursor);
384-
Object value = getValue(cursor);
385-
entries[i++] = hasDELSideEffect(key, lookup) ? key : null;
386-
entries[i++] = hasDELSideEffect(value, lookup) ? value : null;
387-
}
388-
self.map.clear();
389-
for (Object o : entries) {
390-
if (o != null) {
391-
callNode.executeObject(lookup.execute(o, __DEL__), o);
392-
}
393-
}
394-
return self;
395-
}
396-
331+
HashingStorage clear() {
332+
map.clear();
333+
return this;
397334
}
398335

399336
@ExportMessage

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/range/RangeBuiltins.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.ValueError;
3131
import static com.oracle.graal.python.nodes.SpecialMethodNames.__BOOL__;
3232
import static com.oracle.graal.python.nodes.SpecialMethodNames.__CONTAINS__;
33-
import static com.oracle.graal.python.nodes.SpecialMethodNames.__DEL__;
3433
import static com.oracle.graal.python.nodes.SpecialMethodNames.__EQ__;
3534
import static com.oracle.graal.python.nodes.SpecialMethodNames.__GETITEM__;
3635
import static com.oracle.graal.python.nodes.SpecialMethodNames.__HASH__;
@@ -54,7 +53,6 @@
5453
import com.oracle.graal.python.builtins.objects.function.PArguments;
5554
import com.oracle.graal.python.builtins.objects.function.PArguments.ThreadState;
5655
import com.oracle.graal.python.builtins.objects.ints.PInt;
57-
import com.oracle.graal.python.builtins.objects.object.PythonObject;
5856
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
5957
import com.oracle.graal.python.builtins.objects.range.RangeNodes.CoerceToBigRange;
6058
import com.oracle.graal.python.builtins.objects.range.RangeNodes.LenOfIntRangeNodeExact;
@@ -73,7 +71,6 @@
7371
import com.oracle.graal.python.lib.PyObjectReprAsJavaStringNode;
7472
import com.oracle.graal.python.nodes.ErrorMessages;
7573
import com.oracle.graal.python.nodes.PGuards;
76-
import com.oracle.graal.python.nodes.attributes.LookupInheritedAttributeNode;
7774
import com.oracle.graal.python.nodes.control.GetNextNode;
7875
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
7976
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
@@ -758,13 +755,6 @@ Object doLongRange(VirtualFrame frame, PBigRange self, Object elem,
758755
throw raise(ValueError, ErrorMessages.D_IS_NOT_IN_RANGE, elem);
759756
}
760757

761-
static boolean maySideEffect(PythonObject o, LookupInheritedAttributeNode.Dynamic lookup) {
762-
boolean se = lookup.execute(o, __DEL__) != PNone.NO_VALUE;
763-
se = se || !PGuards.isBuiltinFunction(lookup.execute(o, __EQ__));
764-
se = se || !PGuards.isBuiltinFunction(lookup.execute(o, __HASH__));
765-
return se;
766-
}
767-
768758
/**
769759
* XXX: (mq) currently sys.maxsize in {@link SysModuleBuiltins#MAXSIZE} is
770760
* {@link Integer#MAX_VALUE}.

0 commit comments

Comments
 (0)