75
75
import com .oracle .graal .python .builtins .objects .common .SequenceNodes ;
76
76
import com .oracle .graal .python .builtins .objects .common .SequenceStorageNodes ;
77
77
import com .oracle .graal .python .builtins .objects .exception .OSErrorEnum ;
78
+ import com .oracle .graal .python .builtins .objects .function .PArguments ;
78
79
import com .oracle .graal .python .builtins .objects .ints .PInt ;
79
80
import com .oracle .graal .python .builtins .objects .memoryview .PMemoryView ;
80
81
import com .oracle .graal .python .builtins .objects .mmap .MMapBuiltinsFactory .InternalLenNodeGen ;
82
+ import com .oracle .graal .python .builtins .objects .object .PythonObjectLibrary ;
81
83
import com .oracle .graal .python .builtins .objects .slice .PSlice ;
82
84
import com .oracle .graal .python .builtins .objects .slice .PSlice .SliceInfo ;
83
85
import com .oracle .graal .python .nodes .PNodeWithContext ;
91
93
import com .oracle .graal .python .nodes .function .builtins .PythonUnaryBuiltinNode ;
92
94
import com .oracle .graal .python .nodes .truffle .PythonArithmeticTypes ;
93
95
import com .oracle .graal .python .nodes .util .CastToByteNode ;
94
- import com .oracle .graal .python .nodes .util .CastToIndexNode ;
95
96
import com .oracle .graal .python .nodes .util .ChannelNodes ;
96
97
import com .oracle .graal .python .nodes .util .ChannelNodes .ReadByteFromChannelNode ;
97
98
import com .oracle .graal .python .nodes .util .ChannelNodes .ReadFromChannelNode ;
103
104
import com .oracle .truffle .api .CompilerDirectives ;
104
105
import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
105
106
import com .oracle .truffle .api .dsl .Cached ;
107
+ import com .oracle .truffle .api .dsl .Cached .Shared ;
106
108
import com .oracle .truffle .api .dsl .GenerateNodeFactory ;
107
109
import com .oracle .truffle .api .dsl .GenerateUncached ;
108
110
import com .oracle .truffle .api .dsl .NodeFactory ;
109
111
import com .oracle .truffle .api .dsl .Specialization ;
110
112
import com .oracle .truffle .api .dsl .TypeSystemReference ;
111
113
import com .oracle .truffle .api .frame .VirtualFrame ;
114
+ import com .oracle .truffle .api .library .CachedLibrary ;
112
115
import com .oracle .truffle .api .profiles .BranchProfile ;
113
116
import com .oracle .truffle .api .profiles .ConditionProfile ;
114
117
@@ -489,12 +492,12 @@ PBytes readUnlimited(PMMap self, @SuppressWarnings("unused") PNone n,
489
492
return factory ().createBytes (res );
490
493
}
491
494
492
- @ Specialization (guards = "!isNoValue(n)" )
495
+ @ Specialization (guards = "!isNoValue(n)" , limit = "getCallSiteInlineCacheMaxDepth()" )
493
496
PBytes read (VirtualFrame frame , PMMap self , Object n ,
494
497
@ Cached ("create()" ) ReadFromChannelNode readChannelNode ,
495
- @ Cached ( "create() " ) CastToIndexNode castToIndexNode ,
498
+ @ CachedLibrary ( "n " ) PythonObjectLibrary lib ,
496
499
@ Cached ("createBinaryProfile()" ) ConditionProfile negativeProfile ) {
497
- int nread = castToIndexNode . execute ( frame , n );
500
+ int nread = lib . asIndexWithState ( n , PArguments . getThreadState ( frame ) );
498
501
if (negativeProfile .profile (nread < 0 )) {
499
502
return readUnlimited (self , PNone .NO_VALUE , readChannelNode );
500
503
}
@@ -569,17 +572,17 @@ int writeMemoryview(VirtualFrame frame, PMMap self, PMemoryView memoryView,
569
572
@ GenerateNodeFactory
570
573
@ TypeSystemReference (PythonArithmeticTypes .class )
571
574
abstract static class SeekNode extends PythonBuiltinNode implements MMapBaseNode {
572
- @ Child private CastToIndexNode castToLongNode ;
573
-
574
- private final BranchProfile errorProfile = BranchProfile .create ();
575
-
576
575
@ Specialization (guards = "isNoValue(how)" )
577
- Object seek (VirtualFrame frame , PMMap self , long dist , @ SuppressWarnings ("unused" ) PNone how ) {
578
- return seek (frame , self , dist , 0 );
576
+ Object seek (VirtualFrame frame , PMMap self , long dist , @ SuppressWarnings ("unused" ) PNone how ,
577
+ @ Shared ("errorProfile" ) @ Cached BranchProfile errorProfile ,
578
+ @ Shared ("library" ) @ CachedLibrary (limit = "getCallSiteInlineCacheMaxDepth()" ) PythonObjectLibrary lib ) {
579
+ return seek (frame , self , dist , 0 , errorProfile , lib );
579
580
}
580
581
581
- @ Specialization
582
- Object seek (VirtualFrame frame , PMMap self , long dist , Object how ) {
582
+ @ Specialization (guards = "!isNoValue(how)" )
583
+ Object seek (VirtualFrame frame , PMMap self , long dist , Object how ,
584
+ @ Shared ("errorProfile" ) @ Cached BranchProfile errorProfile ,
585
+ @ Shared ("library" ) @ CachedLibrary (limit = "getCallSiteInlineCacheMaxDepth()" ) PythonObjectLibrary lib ) {
583
586
try {
584
587
SeekableByteChannel channel = self .getChannel ();
585
588
long size ;
@@ -589,7 +592,7 @@ Object seek(VirtualFrame frame, PMMap self, long dist, Object how) {
589
592
size = self .getLength ();
590
593
}
591
594
long where ;
592
- int ihow = castToInt ( frame , how );
595
+ int ihow = lib . asIndexWithState ( how , PArguments . getThreadState ( frame ) );
593
596
switch (ihow ) {
594
597
case 0 : /* relative to start */
595
598
where = dist ;
@@ -615,14 +618,6 @@ Object seek(VirtualFrame frame, PMMap self, long dist, Object how) {
615
618
throw raiseOSError (frame , OSErrorEnum .EIO , e );
616
619
}
617
620
}
618
-
619
- private int castToInt (VirtualFrame frame , Object val ) {
620
- if (castToLongNode == null ) {
621
- CompilerDirectives .transferToInterpreterAndInvalidate ();
622
- castToLongNode = insert (CastToIndexNode .create (PythonBuiltinClassType .TypeError , (obj ) -> 0 ));
623
- }
624
- return castToLongNode .execute (frame , val );
625
- }
626
621
}
627
622
628
623
@ Builtin (name = "find" , minNumOfPositionalArgs = 2 , maxNumOfPositionalArgs = 4 )
0 commit comments