|
40 | 40 | */
|
41 | 41 | package com.oracle.graal.python.builtins.objects.common;
|
42 | 42 |
|
43 |
| -import static com.oracle.graal.python.nodes.SpecialMethodNames.__DEL__; |
44 | 43 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__EQ__;
|
45 | 44 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__HASH__;
|
46 | 45 |
|
47 | 46 | import java.util.Iterator;
|
48 | 47 |
|
49 | 48 | import org.graalvm.collections.MapCursor;
|
50 | 49 |
|
51 |
| -import com.oracle.graal.python.builtins.objects.PNone; |
52 | 50 | import com.oracle.graal.python.builtins.objects.common.HashingStorageLibrary.ForEachNode;
|
53 | 51 | import com.oracle.graal.python.builtins.objects.common.HashingStorageLibrary.HashingStorageIterable;
|
54 | 52 | import com.oracle.graal.python.builtins.objects.function.PArguments;
|
|
60 | 58 | import com.oracle.graal.python.lib.PyObjectHashNode;
|
61 | 59 | import com.oracle.graal.python.nodes.PGuards;
|
62 | 60 | import com.oracle.graal.python.nodes.attributes.LookupInheritedAttributeNode;
|
63 |
| -import com.oracle.graal.python.nodes.call.special.CallUnaryMethodNode; |
64 | 61 | import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
|
65 | 62 | import com.oracle.truffle.api.CompilerAsserts;
|
66 | 63 | import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
|
@@ -176,10 +173,7 @@ static boolean isBuiltin(PythonObject o, IsBuiltinClassProfile p) {
|
176 | 173 | }
|
177 | 174 |
|
178 | 175 | 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__)); |
183 | 177 | }
|
184 | 178 |
|
185 | 179 | @Specialization
|
@@ -322,78 +316,21 @@ static HashingStorage generic(EconomicMapStorage self, HashingStorage other,
|
322 | 316 | }
|
323 | 317 | }
|
324 | 318 |
|
325 |
| - private static boolean hasDELSideEffect(Object o, LookupInheritedAttributeNode.Dynamic lookup) { |
326 |
| - return o instanceof PythonObject && lookup.execute(o, __DEL__) != PNone.NO_VALUE; |
327 |
| - } |
328 |
| - |
329 | 319 | @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; |
361 | 328 | }
|
362 | 329 |
|
363 | 330 | @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; |
397 | 334 | }
|
398 | 335 |
|
399 | 336 | @ExportMessage
|
|
0 commit comments