40
40
*/
41
41
package com .oracle .graal .python .nodes .frame ;
42
42
43
- import com .oracle .graal .python .builtins .PythonBuiltinClassType ;
44
43
import com .oracle .graal .python .builtins .objects .cell .PCell ;
45
44
import com .oracle .graal .python .builtins .objects .common .HashingCollectionNodes ;
46
45
import com .oracle .graal .python .builtins .objects .common .HashingStorage ;
50
49
import com .oracle .graal .python .builtins .objects .frame .PFrame ;
51
50
import com .oracle .graal .python .builtins .objects .function .PArguments ;
52
51
import com .oracle .graal .python .nodes .ModuleRootNode ;
52
+ import com .oracle .graal .python .nodes .PGuards ;
53
53
import com .oracle .graal .python .nodes .PRootNode ;
54
54
import com .oracle .graal .python .nodes .SpecialMethodNames ;
55
55
import com .oracle .graal .python .nodes .bytecode .FrameInfo ;
56
56
import com .oracle .graal .python .nodes .frame .MaterializeFrameNodeGen .SyncFrameValuesNodeGen ;
57
57
import com .oracle .graal .python .nodes .function .ClassBodyRootNode ;
58
- import com .oracle .graal .python .nodes .object .GetClassNode ;
59
58
import com .oracle .graal .python .runtime .object .PythonObjectFactory ;
60
59
import com .oracle .graal .python .util .PythonUtils ;
61
60
import com .oracle .truffle .api .CompilerDirectives ;
@@ -432,13 +431,6 @@ static void doGenericDictAST(VirtualFrame frame, PFrame pyFrame, Frame frameToSy
432
431
}
433
432
}
434
433
435
- @ Specialization (guards = {"isCustomLocalsObject(pyFrame, frameToSync, frameProfile)" }, limit = "1" )
436
- @ SuppressWarnings ("unused" )
437
- static void doCustomLocalsObject (PFrame pyFrame , Frame frameToSync , @ SuppressWarnings ("unused" ) Node location ,
438
- @ Cached ("createClassProfile()" ) ValueProfile frameProfile ) {
439
- // nothing to do; we already worked on the custom object
440
- }
441
-
442
434
@ Specialization (guards = {"isBytecodeFrame(frameToSync)" , "hasLocalsStorage(pyFrame, frameToSync, frameProfile)" , "frameToSync.getFrameDescriptor() == cachedFd" ,
443
435
"variableSlotCount(cachedFd) < 32" }, limit = "1" )
444
436
@ ExplodeLoop
@@ -550,6 +542,12 @@ static void doGenericDict(VirtualFrame frame, PFrame pyFrame, Frame frameToSync,
550
542
}
551
543
}
552
544
545
+ @ Specialization (guards = "!isDictWithCustomStorage(pyFrame)" )
546
+ @ SuppressWarnings ("unused" )
547
+ static void doCustomLocalsObject (PFrame pyFrame , Frame frameToSync , Node location ) {
548
+ // nothing to do; we already worked on the custom object
549
+ }
550
+
553
551
private static void syncDict (VirtualFrame frame , int slot , FrameInfo info , Frame frameToSync , PDict localsDict , HashingStorageLibrary lib ,
554
552
ConditionProfile hasFrame , BranchProfile updatedStorage , ConditionProfile profile ) {
555
553
HashingStorage storage = localsDict .getDictStorage ();
@@ -558,21 +556,25 @@ private static void syncDict(VirtualFrame frame, int slot, FrameInfo info, Frame
558
556
if (value != null && profile .profile (value instanceof PCell )) {
559
557
value = ((PCell ) value ).getRef ();
560
558
}
561
- HashingStorage newStore = null ;
559
+ HashingStorage newStore ;
562
560
if (value != null ) {
563
561
newStore = lib .setItemWithFrame (storage , identifier , value , hasFrame , frame );
562
+ if (newStore != storage ) {
563
+ updatedStorage .enter ();
564
+ localsDict .setDictStorage (newStore );
565
+ }
564
566
} else {
565
567
// delete variable
566
568
// TODO: FIXME: this might call __hash__ twice
567
569
boolean hasKey = lib .hasKeyWithFrame (storage , identifier , hasFrame , frame );
568
570
if (hasKey ) {
569
571
newStore = lib .delItemWithFrame (storage , identifier , hasFrame , frame );
572
+ if (newStore != storage ) {
573
+ updatedStorage .enter ();
574
+ localsDict .setDictStorage (newStore );
575
+ }
570
576
}
571
577
}
572
- if (newStore != storage ) {
573
- updatedStorage .enter ();
574
- localsDict .setDictStorage (newStore );
575
- }
576
578
}
577
579
578
580
// @ImportStatic doesn't work on this for some reason
@@ -606,11 +608,7 @@ protected static boolean hasLocalsStorage(PFrame pyFrame, Frame frameToSync, Val
606
608
protected static boolean isDictWithCustomStorage (PFrame pyFrame ) {
607
609
Object localsObject = pyFrame .getLocalsDict ();
608
610
// do not allow subclasses of 'dict'
609
- return GetClassNode .getUncached ().execute (localsObject ) == PythonBuiltinClassType .PDict ;
610
- }
611
-
612
- protected static boolean isCustomLocalsObject (PFrame pyFrame , Frame frameToSync , ValueProfile frameProfile ) {
613
- return !hasLocalsStorage (pyFrame , frameToSync , frameProfile );
611
+ return localsObject instanceof PDict && PGuards .isBuiltinDict ((PDict ) localsObject );
614
612
}
615
613
616
614
protected static LocalsStorage getLocalsStorage (PFrame pyFrame ) {
0 commit comments