52
52
import com .oracle .graal .python .builtins .objects .ints .PInt ;
53
53
import com .oracle .graal .python .builtins .objects .list .PList ;
54
54
import com .oracle .graal .python .builtins .objects .module .PythonModule ;
55
- import com .oracle .graal .python .builtins .objects .object .PythonObjectLibrary ;
56
55
import com .oracle .graal .python .builtins .objects .range .RangeNodes .LenOfRangeNode ;
57
56
import com .oracle .graal .python .builtins .objects .tuple .PTuple ;
58
57
import com .oracle .graal .python .lib .PyNumberAsSizeNode ;
58
+ import com .oracle .graal .python .lib .PyObjectLookupAttr ;
59
59
import com .oracle .graal .python .lib .PyObjectSizeNode ;
60
60
import com .oracle .graal .python .nodes .ErrorMessages ;
61
61
import com .oracle .graal .python .nodes .call .special .LookupAndCallBinaryNode ;
@@ -359,126 +359,118 @@ public static int lengthHint(VirtualFrame frame, PSequenceIterator self,
359
359
@ Builtin (name = __REDUCE__ , minNumOfPositionalArgs = 1 )
360
360
@ GenerateNodeFactory
361
361
public abstract static class ReduceNode extends PythonUnaryBuiltinNode {
362
+ @ Child PyObjectLookupAttr lookupAttrNode ;
363
+
362
364
@ Specialization
363
365
public Object reduce (VirtualFrame frame , PArrayIterator self ,
364
- @ Cached ConditionProfile exhaustedProfile ,
365
- @ Cached .Shared ("pol" ) @ CachedLibrary (limit = "1" ) PythonObjectLibrary pol ) {
366
+ @ Cached ConditionProfile exhaustedProfile ) {
366
367
PythonContext context = PythonContext .get (this );
367
368
if (!exhaustedProfile .profile (self .isExhausted ())) {
368
- return reduceInternal (frame , self .array , self .getIndex (), context , pol );
369
+ return reduceInternal (frame , self .array , self .getIndex (), context );
369
370
} else {
370
- return reduceInternal (frame , factory ().createEmptyTuple (), context , pol );
371
+ return reduceInternal (frame , factory ().createEmptyTuple (), context );
371
372
}
372
373
}
373
374
374
375
@ Specialization
375
376
public Object reduce (VirtualFrame frame , PBaseSetIterator self ,
376
- @ Cached SequenceStorageNodes .CreateStorageFromIteratorNode storageNode ,
377
- @ Cached .Shared ("pol" ) @ CachedLibrary (limit = "1" ) PythonObjectLibrary pol ) {
377
+ @ Cached SequenceStorageNodes .CreateStorageFromIteratorNode storageNode ) {
378
378
int index = self .index ;
379
379
boolean isExhausted = self .isExhausted ();
380
380
PList list = factory ().createList (storageNode .execute (frame , self ));
381
381
self .setExhausted (isExhausted );
382
382
self .index = index ;
383
- return reduceInternal (frame , list , self .getIndex (), PythonContext .get (this ), pol );
383
+ return reduceInternal (frame , list , self .getIndex (), PythonContext .get (this ));
384
384
}
385
385
386
386
@ Specialization
387
387
public Object reduce (VirtualFrame frame , PDictView .PBaseDictIterator <?> self ,
388
388
@ Cached SequenceStorageNodes .CreateStorageFromIteratorNode storageNode ,
389
389
@ Cached MapNodes .GetIteratorState getState ,
390
- @ Cached MapNodes .SetIteratorState setState ,
391
- @ CachedLibrary (limit = "2" ) PythonObjectLibrary pol ) {
390
+ @ Cached MapNodes .SetIteratorState setState ) {
392
391
int index = self .index ;
393
392
boolean isExhausted = self .isExhausted ();
394
393
int state = getState .execute (self .getIterator ());
395
394
PList list = factory ().createList (storageNode .execute (frame , self ));
396
395
setState .execute (self .getIterator (), state );
397
396
self .setExhausted (isExhausted );
398
397
self .index = index ;
399
- return reduceInternal (frame , list , PythonContext .get (this ), pol );
398
+ return reduceInternal (frame , list , PythonContext .get (this ));
400
399
}
401
400
402
401
@ Specialization
403
- public Object reduce (VirtualFrame frame , PIntegerSequenceIterator self ,
404
- @ Cached .Shared ("pol" ) @ CachedLibrary (limit = "1" ) PythonObjectLibrary pol ) {
402
+ public Object reduce (VirtualFrame frame , PIntegerSequenceIterator self ) {
405
403
PythonContext context = PythonContext .get (this );
406
404
if (self .isExhausted ()) {
407
- return reduceInternal (frame , factory ().createList (), null , context , pol );
405
+ return reduceInternal (frame , factory ().createList (), null , context );
408
406
}
409
- return reduceInternal (frame , self .getObject (), self .getIndex (), context , pol );
407
+ return reduceInternal (frame , self .getObject (), self .getIndex (), context );
410
408
}
411
409
412
410
@ Specialization
413
- public Object reduce (VirtualFrame frame , PPrimitiveIterator self ,
414
- @ Cached .Shared ("pol" ) @ CachedLibrary (limit = "1" ) PythonObjectLibrary pol ) {
411
+ public Object reduce (VirtualFrame frame , PPrimitiveIterator self ) {
415
412
PythonContext context = PythonContext .get (this );
416
413
if (self .isExhausted ()) {
417
- return reduceInternal (frame , factory ().createList (), null , context , pol );
414
+ return reduceInternal (frame , factory ().createList (), null , context );
418
415
}
419
- return reduceInternal (frame , self .getObject (), self .getIndex (), context , pol );
416
+ return reduceInternal (frame , self .getObject (), self .getIndex (), context );
420
417
}
421
418
422
419
@ Specialization
423
- public Object reduce (VirtualFrame frame , PStringIterator self ,
424
- @ Cached .Shared ("pol" ) @ CachedLibrary (limit = "1" ) PythonObjectLibrary pol ) {
420
+ public Object reduce (VirtualFrame frame , PStringIterator self ) {
425
421
PythonContext context = PythonContext .get (this );
426
422
if (self .isExhausted ()) {
427
- return reduceInternal (frame , "" , null , context , pol );
423
+ return reduceInternal (frame , "" , null , context );
428
424
}
429
- return reduceInternal (frame , self .value , self .getIndex (), context , pol );
425
+ return reduceInternal (frame , self .value , self .getIndex (), context );
430
426
}
431
427
432
428
@ Specialization
433
429
public Object reduce (VirtualFrame frame , PIntRangeIterator self ,
434
- @ Cached LenOfRangeNode length ,
435
- @ Cached .Shared ("pol" ) @ CachedLibrary (limit = "1" ) PythonObjectLibrary pol ) {
430
+ @ Cached LenOfRangeNode length ) {
436
431
int start = self .getReduceStart ();
437
432
int stop = self .getReduceStop ();
438
433
int step = self .getReduceStep ();
439
434
int len = length .executeInt (start , stop , step );
440
- return reduceInternal (frame , factory ().createIntRange (start , stop , step , len ), self .getIndex (), PythonContext .get (this ), pol );
435
+ return reduceInternal (frame , factory ().createIntRange (start , stop , step , len ), self .getIndex (), PythonContext .get (this ));
441
436
}
442
437
443
438
@ Specialization
444
439
public Object reduce (VirtualFrame frame , PBigRangeIterator self ,
445
- @ Cached LenOfRangeNode length ,
446
- @ Cached .Shared ("pol" ) @ CachedLibrary (limit = "1" ) PythonObjectLibrary pol ) {
440
+ @ Cached LenOfRangeNode length ) {
447
441
PInt start = self .getReduceStart ();
448
442
PInt stop = self .getReduceStop (factory ());
449
443
PInt step = self .getReduceStep ();
450
444
PInt len = factory ().createInt (length .execute (start .getValue (), stop .getValue (), step .getValue ()));
451
- return reduceInternal (frame , factory ().createBigRange (start , stop , step , len ), self .getLongIndex (factory ()), PythonContext .get (this ), pol );
445
+ return reduceInternal (frame , factory ().createBigRange (start , stop , step , len ), self .getLongIndex (factory ()), PythonContext .get (this ));
452
446
}
453
447
454
448
@ Specialization (guards = "self.isPSequence()" )
455
- public Object reduce (VirtualFrame frame , PSequenceIterator self ,
456
- @ Cached .Shared ("pol" ) @ CachedLibrary (limit = "1" ) PythonObjectLibrary pol ) {
449
+ public Object reduce (VirtualFrame frame , PSequenceIterator self ) {
457
450
PythonContext context = PythonContext .get (this );
458
451
if (self .isExhausted ()) {
459
- return reduceInternal (frame , factory ().createTuple (new Object [0 ]), null , context , pol );
452
+ return reduceInternal (frame , factory ().createTuple (new Object [0 ]), null , context );
460
453
}
461
- return reduceInternal (frame , self .getPSequence (), self .getIndex (), context , pol );
454
+ return reduceInternal (frame , self .getPSequence (), self .getIndex (), context );
462
455
}
463
456
464
457
@ Specialization (guards = "!self.isPSequence()" )
465
- public Object reduceNonSeq (@ SuppressWarnings ({"unused" }) VirtualFrame frame , PSequenceIterator self ,
466
- @ Cached .Shared ("pol" ) @ CachedLibrary (limit = "1" ) PythonObjectLibrary pol ) {
458
+ public Object reduceNonSeq (@ SuppressWarnings ({"unused" }) VirtualFrame frame , PSequenceIterator self ) {
467
459
PythonContext context = PythonContext .get (this );
468
460
if (!self .isExhausted ()) {
469
- return reduceInternal (frame , self .getObject (), self .getIndex (), context , pol );
461
+ return reduceInternal (frame , self .getObject (), self .getIndex (), context );
470
462
} else {
471
- return reduceInternal (frame , factory ().createTuple (new Object [0 ]), null , context , pol );
463
+ return reduceInternal (frame , factory ().createTuple (new Object [0 ]), null , context );
472
464
}
473
465
}
474
466
475
- private PTuple reduceInternal (VirtualFrame frame , Object arg , PythonContext context , PythonObjectLibrary pol ) {
476
- return reduceInternal (frame , arg , null , context , pol );
467
+ private PTuple reduceInternal (VirtualFrame frame , Object arg , PythonContext context ) {
468
+ return reduceInternal (frame , arg , null , context );
477
469
}
478
470
479
- private PTuple reduceInternal (VirtualFrame frame , Object arg , Object state , PythonContext context , PythonObjectLibrary pol ) {
471
+ private PTuple reduceInternal (VirtualFrame frame , Object arg , Object state , PythonContext context ) {
480
472
PythonModule builtins = context .getCore ().getBuiltins ();
481
- Object iter = pol . lookupAttributeStrict ( builtins , frame , ITER );
473
+ Object iter = getLookupAttrNode (). executeStrict ( frame , this , builtins , ITER );
482
474
PTuple args = factory ().createTuple (new Object []{arg });
483
475
// callable, args, state (optional)
484
476
if (state != null ) {
@@ -487,6 +479,14 @@ private PTuple reduceInternal(VirtualFrame frame, Object arg, Object state, Pyth
487
479
return factory ().createTuple (new Object []{iter , args });
488
480
}
489
481
}
482
+
483
+ private PyObjectLookupAttr getLookupAttrNode () {
484
+ if (lookupAttrNode == null ) {
485
+ CompilerDirectives .transferToInterpreterAndInvalidate ();
486
+ lookupAttrNode = insert (PyObjectLookupAttr .create ());
487
+ }
488
+ return lookupAttrNode ;
489
+ }
490
490
}
491
491
492
492
@ Builtin (name = __SETSTATE__ , minNumOfPositionalArgs = 2 )
0 commit comments