71
71
import com .oracle .graal .python .builtins .objects .tuple .StructSequenceFactory .NewNodeGen ;
72
72
import com .oracle .graal .python .builtins .objects .tuple .StructSequenceFactory .ReduceNodeGen ;
73
73
import com .oracle .graal .python .builtins .objects .tuple .StructSequenceFactory .ReprNodeGen ;
74
+ import com .oracle .graal .python .builtins .objects .type .PythonBuiltinClass ;
74
75
import com .oracle .graal .python .builtins .objects .type .TypeNodes .GetNameNode ;
75
76
import com .oracle .graal .python .nodes .ErrorMessages ;
76
77
import com .oracle .graal .python .nodes .PRootNode ;
98
99
import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
99
100
import com .oracle .truffle .api .RootCallTarget ;
100
101
import com .oracle .truffle .api .dsl .Cached ;
101
- import com .oracle .truffle .api .dsl .Cached .Shared ;
102
102
import com .oracle .truffle .api .dsl .NodeFactory ;
103
103
import com .oracle .truffle .api .dsl .Specialization ;
104
104
import com .oracle .truffle .api .frame .VirtualFrame ;
@@ -272,11 +272,9 @@ private static void createConstructor(PythonLanguage language, Object klass, Des
272
272
@ Builtin (name = __NEW__ , minNumOfPositionalArgs = 1 , takesVarArgs = true , takesVarKeywordArgs = true )
273
273
public abstract static class DisabledNewNode extends PythonVarargsBuiltinNode {
274
274
275
- @ Child private GetNameNode getNameNode ;
276
-
277
275
@ Override
278
276
@ SuppressWarnings ("unused" )
279
- public Object varArgExecute (VirtualFrame frame , Object self , Object [] arguments , PKeyword [] keywords ) throws VarargsBuiltinDirectInvocationNotSupported {
277
+ public final Object varArgExecute (VirtualFrame frame , Object self , Object [] arguments , PKeyword [] keywords ) throws VarargsBuiltinDirectInvocationNotSupported {
280
278
if (arguments .length > 0 ) {
281
279
return error (arguments [0 ], PythonUtils .EMPTY_OBJECT_ARRAY , PKeyword .EMPTY_KEYWORDS );
282
280
}
@@ -287,11 +285,7 @@ public Object varArgExecute(VirtualFrame frame, Object self, Object[] arguments,
287
285
@ Specialization
288
286
@ SuppressWarnings ("unused" )
289
287
Object error (Object cls , Object [] arguments , PKeyword [] keywords ) {
290
- if (getNameNode == null ) {
291
- CompilerDirectives .transferToInterpreterAndInvalidate ();
292
- getNameNode = insert (GetNameNode .create ());
293
- }
294
- throw raise (TypeError , ErrorMessages .CANNOT_CREATE_INSTANCES , getNameNode .execute (cls ));
288
+ throw raise (TypeError , ErrorMessages .CANNOT_CREATE_INSTANCES , StructSequence .getTpName (cls ));
295
289
}
296
290
}
297
291
@@ -316,10 +310,9 @@ PTuple withoutDict(VirtualFrame frame, Object cls, Object sequence, @SuppressWar
316
310
@ Cached ToArrayNode toArrayNode ,
317
311
@ Cached IsBuiltinClassProfile notASequenceProfile ,
318
312
@ Cached BranchProfile wrongLenProfile ,
319
- @ Cached BranchProfile needsReallocProfile ,
320
- @ Shared ("getNameNode" ) @ Cached GetNameNode getNameNode ) {
313
+ @ Cached BranchProfile needsReallocProfile ) {
321
314
Object [] src = sequenceToArray (frame , sequence , fastConstructListNode , toArrayNode , notASequenceProfile );
322
- Object [] dst = processSequence (cls , src , wrongLenProfile , needsReallocProfile , getNameNode );
315
+ Object [] dst = processSequence (cls , src , wrongLenProfile , needsReallocProfile );
323
316
for (int i = src .length ; i < dst .length ; ++i ) {
324
317
dst [i ] = PNone .NONE ;
325
318
}
@@ -333,10 +326,9 @@ PTuple withDict(VirtualFrame frame, Object cls, Object sequence, PDict dict,
333
326
@ Cached IsBuiltinClassProfile notASequenceProfile ,
334
327
@ Cached BranchProfile wrongLenProfile ,
335
328
@ Cached BranchProfile needsReallocProfile ,
336
- @ Shared ("getNameNode" ) @ Cached GetNameNode getNameNode ,
337
329
@ CachedLibrary (limit = "1" ) HashingStorageLibrary dictLib ) {
338
330
Object [] src = sequenceToArray (frame , sequence , fastConstructListNode , toArrayNode , notASequenceProfile );
339
- Object [] dst = processSequence (cls , src , wrongLenProfile , needsReallocProfile , getNameNode );
331
+ Object [] dst = processSequence (cls , src , wrongLenProfile , needsReallocProfile );
340
332
HashingStorage hs = dict .getDictStorage ();
341
333
ThreadState threadState = PArguments .getThreadState (frame );
342
334
for (int i = src .length ; i < dst .length ; ++i ) {
@@ -348,9 +340,8 @@ PTuple withDict(VirtualFrame frame, Object cls, Object sequence, PDict dict,
348
340
349
341
@ Specialization (guards = {"!isNoValue(dict)" , "!isDict(dict)" })
350
342
@ SuppressWarnings ("unused" )
351
- PTuple doDictError (VirtualFrame frame , Object cls , Object sequence , Object dict ,
352
- @ Shared ("getNameNode" ) @ Cached GetNameNode getNameNode ) {
353
- throw raise (TypeError , ErrorMessages .TAKES_A_DICT_AS_SECOND_ARG_IF_ANY , getNameNode .execute (cls ));
343
+ PTuple doDictError (VirtualFrame frame , Object cls , Object sequence , Object dict ) {
344
+ throw raise (TypeError , ErrorMessages .TAKES_A_DICT_AS_SECOND_ARG_IF_ANY , StructSequence .getTpName (cls ));
354
345
}
355
346
356
347
private Object [] sequenceToArray (VirtualFrame frame , Object sequence , FastConstructListNode fastConstructListNode , ToArrayNode toArrayNode , IsBuiltinClassProfile notASequenceProfile ) {
@@ -364,20 +355,20 @@ private Object[] sequenceToArray(VirtualFrame frame, Object sequence, FastConstr
364
355
return toArrayNode .execute (seq .getSequenceStorage ());
365
356
}
366
357
367
- private Object [] processSequence (Object cls , Object [] src , BranchProfile wrongLenProfile , BranchProfile needsReallocProfile , GetNameNode getNameNode ) {
358
+ private Object [] processSequence (Object cls , Object [] src , BranchProfile wrongLenProfile , BranchProfile needsReallocProfile ) {
368
359
int len = src .length ;
369
360
int minLen = inSequence ;
370
361
int maxLen = fieldNames .length ;
371
362
372
363
if (len < minLen || len > maxLen ) {
373
364
wrongLenProfile .enter ();
374
365
if (minLen == maxLen ) {
375
- throw raise (TypeError , ErrorMessages .TAKES_A_D_SEQUENCE , getNameNode . execute (cls ), minLen , len );
366
+ throw raise (TypeError , ErrorMessages .TAKES_A_D_SEQUENCE , StructSequence . getTpName (cls ), minLen , len );
376
367
}
377
368
if (len < minLen ) {
378
- throw raise (TypeError , ErrorMessages .TAKES_AN_AT_LEAST_D_SEQUENCE , getNameNode . execute (cls ), minLen , len );
369
+ throw raise (TypeError , ErrorMessages .TAKES_AN_AT_LEAST_D_SEQUENCE , StructSequence . getTpName (cls ), minLen , len );
379
370
} else { // len > maxLen
380
- throw raise (TypeError , ErrorMessages .TAKES_AN_AT_MOST_D_SEQUENCE , getNameNode . execute (cls ), maxLen , len );
371
+ throw raise (TypeError , ErrorMessages .TAKES_AN_AT_MOST_D_SEQUENCE , StructSequence . getTpName (cls ), maxLen , len );
381
372
}
382
373
}
383
374
@@ -491,4 +482,13 @@ public boolean isPythonInternal() {
491
482
return true ;
492
483
}
493
484
}
485
+
486
+ static String getTpName (Object cls ) {
487
+ if (cls instanceof PythonBuiltinClassType ) {
488
+ return ((PythonBuiltinClassType ) cls ).getPrintName ();
489
+ } else if (cls instanceof PythonBuiltinClass ) {
490
+ return ((PythonBuiltinClass ) cls ).getType ().getPrintName ();
491
+ }
492
+ return GetNameNode .getUncached ().execute (cls );
493
+ }
494
494
}
0 commit comments