61
61
import static com .oracle .graal .python .nodes .SpecialAttributeNames .__SLOTS__ ;
62
62
import static com .oracle .graal .python .nodes .SpecialAttributeNames .__WEAKREF__ ;
63
63
import static com .oracle .graal .python .nodes .SpecialMethodNames .DECODE ;
64
+ import static com .oracle .graal .python .nodes .SpecialMethodNames .__COMPLEX__ ;
64
65
import static com .oracle .graal .python .nodes .SpecialMethodNames .__SETITEM__ ;
65
66
import static com .oracle .graal .python .runtime .exception .PythonErrorType .NotImplementedError ;
66
67
import static com .oracle .graal .python .runtime .exception .PythonErrorType .SystemError ;
95
96
import com .oracle .graal .python .builtins .objects .code .CodeNodes ;
96
97
import com .oracle .graal .python .builtins .objects .code .PCode ;
97
98
import com .oracle .graal .python .builtins .objects .common .HashingCollectionNodes ;
98
- import com .oracle .graal .python .builtins .objects .common .HashingStorageLibrary ;
99
+ import com .oracle .graal .python .builtins .objects .common .HashingStorage ;
99
100
import com .oracle .graal .python .builtins .objects .common .HashingStorage .DictEntry ;
100
- import com .oracle .graal .python .builtins .objects .common .HashingStorageNodes ;
101
+ import com .oracle .graal .python .builtins .objects .common .HashingStorageLibrary ;
101
102
import com .oracle .graal .python .builtins .objects .common .PHashingCollection ;
102
103
import com .oracle .graal .python .builtins .objects .common .SequenceNodes .GetObjectArrayNode ;
103
104
import com .oracle .graal .python .builtins .objects .common .SequenceNodesFactory .GetObjectArrayNodeGen ;
143
144
import com .oracle .graal .python .nodes .PGuards ;
144
145
import com .oracle .graal .python .nodes .PRaiseNode ;
145
146
import com .oracle .graal .python .nodes .SpecialMethodNames ;
146
- import static com .oracle .graal .python .nodes .SpecialMethodNames .__COMPLEX__ ;
147
147
import com .oracle .graal .python .nodes .attributes .GetAttributeNode ;
148
148
import com .oracle .graal .python .nodes .attributes .GetAttributeNode .GetAnyAttributeNode ;
149
149
import com .oracle .graal .python .nodes .attributes .LookupAttributeInMRONode ;
@@ -2267,7 +2267,6 @@ public abstract static class TypeNode extends PythonBuiltinNode {
2267
2267
@ Child private SequenceStorageNodes .LenNode slotLenNode ;
2268
2268
@ Child private SequenceStorageNodes .GetItemNode getItemNode ;
2269
2269
@ Child private SequenceStorageNodes .AppendNode appendNode ;
2270
- @ Child private HashingStorageNodes .ContainsKeyNode containsKeyNode ;
2271
2270
@ Child private CExtNodes .PCallCapiFunction callAddNativeSlotsNode ;
2272
2271
@ Child private CExtNodes .ToSulongNode toSulongNode ;
2273
2272
@ Child private ReadCallerFrameNode readCallerFrameNode ;
@@ -2287,11 +2286,11 @@ Object type(Object cls, Object obj, PNone bases, PNone dict, PKeyword[] kwds,
2287
2286
@ Specialization
2288
2287
Object type (VirtualFrame frame , LazyPythonClass cls , String name , PTuple bases , PDict namespace , PKeyword [] kwds ,
2289
2288
@ Cached GetLazyClassNode getMetaclassNode ,
2290
- @ CachedLibrary (limit = "1" ) HashingStorageLibrary hlib ,
2289
+ @ CachedLibrary (limit = "1" ) HashingStorageLibrary nslib ,
2290
+ @ CachedLibrary (limit = "1" ) HashingStorageLibrary glib ,
2291
+ @ Cached BranchProfile updatedStorage ,
2291
2292
@ Cached ("create(__NEW__)" ) LookupInheritedAttributeNode getNewFuncNode ,
2292
2293
@ Cached ("create(__INIT_SUBCLASS__)" ) GetAttributeNode getInitSubclassNode ,
2293
- @ Cached HashingStorageNodes .GetItemNode getClasscellNode ,
2294
- @ Cached HashingStorageNodes .DelItemNode delClasscellNode ,
2295
2294
@ Cached CallNode callInitSubclassNode ,
2296
2295
@ Cached CallNode callNewFuncNode ) {
2297
2296
@@ -2308,7 +2307,7 @@ Object type(VirtualFrame frame, LazyPythonClass cls, String name, PTuple bases,
2308
2307
}
2309
2308
2310
2309
try {
2311
- PythonClass newType = typeMetaclass (frame , name , bases , namespace , metaclass );
2310
+ PythonClass newType = typeMetaclass (frame , name , bases , namespace , metaclass , nslib );
2312
2311
2313
2312
// TODO: Call __set_name__ on all descriptors in a newly generated type
2314
2313
@@ -2323,22 +2322,28 @@ Object type(VirtualFrame frame, LazyPythonClass cls, String name, PTuple bases,
2323
2322
PFrame callerFrame = getReadCallerFrameNode ().executeWith (frame , 0 );
2324
2323
PythonObject globals = callerFrame .getGlobals ();
2325
2324
if (globals != null ) {
2326
- String moduleName = getModuleNameFromGlobals (frame , globals , hlib );
2325
+ String moduleName = getModuleNameFromGlobals (globals , glib );
2327
2326
if (moduleName != null ) {
2328
2327
ensureWriteAttrNode ().execute (frame , newType , __MODULE__ , moduleName );
2329
2328
}
2330
2329
}
2331
2330
}
2332
2331
2333
2332
// set __class__ cell contents
2334
- Object classcell = getClasscellNode . execute ( frame , namespace .getDictStorage (), __CLASSCELL__ );
2333
+ Object classcell = nslib . getItem ( namespace .getDictStorage (), __CLASSCELL__ );
2335
2334
if (classcell != null ) {
2336
2335
if (classcell instanceof PCell ) {
2337
2336
((PCell ) classcell ).setRef (newType );
2338
2337
} else {
2339
2338
raise (TypeError , "__classcell__ must be a cell" );
2340
2339
}
2341
- delClasscellNode .execute (frame , namespace , namespace .getDictStorage (), __CLASSCELL__ );
2340
+ if (nslib .hasKey (namespace .getDictStorage (), __CLASSCELL__ )) {
2341
+ HashingStorage newStore = nslib .delItem (namespace .getDictStorage (), __CLASSCELL__ );
2342
+ if (newStore != namespace .getDictStorage ()) {
2343
+ updatedStorage .enter ();
2344
+ namespace .setDictStorage (newStore );
2345
+ }
2346
+ }
2342
2347
}
2343
2348
2344
2349
return newType ;
@@ -2347,7 +2352,7 @@ Object type(VirtualFrame frame, LazyPythonClass cls, String name, PTuple bases,
2347
2352
}
2348
2353
}
2349
2354
2350
- private String getModuleNameFromGlobals (VirtualFrame frame , PythonObject globals , HashingStorageLibrary hlib ) {
2355
+ private String getModuleNameFromGlobals (PythonObject globals , HashingStorageLibrary hlib ) {
2351
2356
Object nameAttr ;
2352
2357
if (globals instanceof PythonModule ) {
2353
2358
nameAttr = ensureReadAttrNode ().execute (globals , __NAME__ );
@@ -2361,7 +2366,7 @@ private String getModuleNameFromGlobals(VirtualFrame frame, PythonObject globals
2361
2366
}
2362
2367
2363
2368
@ SuppressWarnings ("try" )
2364
- private PythonClass typeMetaclass (VirtualFrame frame , String name , PTuple bases , PDict namespace , LazyPythonClass metaclass ) {
2369
+ private PythonClass typeMetaclass (VirtualFrame frame , String name , PTuple bases , PDict namespace , LazyPythonClass metaclass , HashingStorageLibrary nslib ) {
2365
2370
2366
2371
Object [] array = ensureGetObjectArrayNode ().execute (bases );
2367
2372
@@ -2463,7 +2468,7 @@ private PythonClass typeMetaclass(VirtualFrame frame, String name, PTuple bases,
2463
2468
PythonContext context = getContextRef ().get ();
2464
2469
Object state = ForeignCallContext .enter (frame , context , this );
2465
2470
try {
2466
- PTuple newSlots = copySlots (name , slotList , slotlen , addDict , false , namespace );
2471
+ PTuple newSlots = copySlots (name , slotList , slotlen , addDict , false , namespace , nslib );
2467
2472
pythonClass .setAttribute (__SLOTS__ , newSlots );
2468
2473
if (basesArray .length > 1 ) {
2469
2474
// TODO: tfel - check if secondary bases provide weakref or dict when we
@@ -2483,7 +2488,7 @@ private PythonClass typeMetaclass(VirtualFrame frame, String name, PTuple bases,
2483
2488
}
2484
2489
2485
2490
@ TruffleBoundary
2486
- private PTuple copySlots (String className , SequenceStorage slotList , int slotlen , boolean add_dict , boolean add_weak , PDict namespace ) {
2491
+ private PTuple copySlots (String className , SequenceStorage slotList , int slotlen , boolean add_dict , boolean add_weak , PDict namespace , HashingStorageLibrary nslib ) {
2487
2492
SequenceStorage newSlots = new ObjectSequenceStorage (slotlen - PInt .intValue (add_dict ) - PInt .intValue (add_weak ));
2488
2493
int j = 0 ;
2489
2494
for (int i = 0 ; i < slotlen ; i ++) {
@@ -2503,7 +2508,7 @@ private PTuple copySlots(String className, SequenceStorage slotList, int slotlen
2503
2508
setSlotItemNode ().execute (newSlots , slotName , NoGeneralizationNode .DEFAULT );
2504
2509
// Passing 'null' frame is fine because the caller already transfers the exception
2505
2510
// state to the context.
2506
- if (getContainsKeyNode (). execute ( null , namespace .getDictStorage (), slotName )) {
2511
+ if (nslib . hasKey ( namespace .getDictStorage (), slotName )) {
2507
2512
throw raise (PythonBuiltinClassType .ValueError , "%s in __slots__ conflicts with class variable" , slotName );
2508
2513
}
2509
2514
j ++;
@@ -2552,14 +2557,6 @@ private String mangle(String privateobj, String ident) {
2552
2557
return "_" + privateobj .substring (ipriv ) + ident ;
2553
2558
}
2554
2559
2555
- private HashingStorageNodes .ContainsKeyNode getContainsKeyNode () {
2556
- if (containsKeyNode == null ) {
2557
- CompilerDirectives .transferToInterpreterAndInvalidate ();
2558
- containsKeyNode = insert (HashingStorageNodes .ContainsKeyNode .create ());
2559
- }
2560
- return containsKeyNode ;
2561
- }
2562
-
2563
2560
private SequenceStorageNodes .GetItemNode getSlotItemNode () {
2564
2561
if (getItemNode == null ) {
2565
2562
CompilerDirectives .transferToInterpreterAndInvalidate ();
@@ -2986,7 +2983,8 @@ Object call(VirtualFrame frame, LazyPythonClass cls, int argcount, int kwonlyarg
2986
2983
@ CachedLibrary ("codestring" ) PythonObjectLibrary codestringBufferLib ,
2987
2984
@ CachedLibrary ("lnotab" ) PythonObjectLibrary lnotabBufferLib ,
2988
2985
@ Cached CodeNodes .CreateCodeNode createCodeNode ,
2989
- @ Cached GetObjectArrayNode getObjectArrayNode ) throws UnsupportedMessageException {
2986
+ @ Cached GetObjectArrayNode getObjectArrayNode ,
2987
+ @ CachedLibrary (limit = "1" ) HashingStorageLibrary lib ) throws UnsupportedMessageException {
2990
2988
byte [] codeBytes = codestringBufferLib .getBufferBytes (codestring );
2991
2989
byte [] lnotabBytes = lnotabBufferLib .getBufferBytes (lnotab );
2992
2990
@@ -3001,7 +2999,7 @@ Object call(VirtualFrame frame, LazyPythonClass cls, int argcount, int kwonlyarg
3001
2999
codeBytes , constantsArr , namesArr ,
3002
3000
varnamesArr , freevarsArr , cellcarsArr ,
3003
3001
getStringArg (filename ), getStringArg (name ), firstlineno ,
3004
- lnotabBytes );
3002
+ lnotabBytes , lib );
3005
3003
}
3006
3004
3007
3005
@ Specialization (guards = {"codestringBufferLib.isBuffer(codestring)" , "lnotabBufferLib.isBuffer(lnotab)" }, limit = "2" , rewriteOn = UnsupportedMessageException .class )
@@ -3089,7 +3087,7 @@ Object doMapping(LazyPythonClass klass, PHashingCollection obj) {
3089
3087
3090
3088
@ Specialization (guards = {"isSequence(frame, obj, lib)" , "!isBuiltinMapping(obj)" })
3091
3089
Object doMapping (VirtualFrame frame , LazyPythonClass klass , PythonObject obj ,
3092
- @ Cached ("create()" ) HashingStorageNodes .InitNode initNode ,
3090
+ @ Cached ("create()" ) HashingStorage .InitNode initNode ,
3093
3091
@ SuppressWarnings ("unused" ) @ CachedLibrary (limit = "1" ) PythonObjectLibrary lib ) {
3094
3092
return factory ().createMappingproxy (klass , initNode .execute (frame , obj , PKeyword .EMPTY_KEYWORDS ));
3095
3093
}
0 commit comments