79
79
import com .oracle .graal .python .nodes .object .BuiltinClassProfiles .IsBuiltinObjectProfile ;
80
80
import com .oracle .graal .python .nodes .object .GetClassNode ;
81
81
import com .oracle .graal .python .nodes .object .GetClassNode .GetPythonObjectClassNode ;
82
- import com .oracle .graal .python .nodes .object .IsForeignObjectNode ;
83
82
import com .oracle .graal .python .nodes .util .CastBuiltinStringToTruffleStringNode ;
84
- import com .oracle .graal .python .runtime .GilNode ;
85
83
import com .oracle .graal .python .runtime .exception .PException ;
86
84
import com .oracle .graal .python .runtime .sequence .PSequence ;
87
85
import com .oracle .graal .python .runtime .sequence .storage .SequenceStorage ;
98
96
import com .oracle .truffle .api .dsl .ImportStatic ;
99
97
import com .oracle .truffle .api .dsl .Specialization ;
100
98
import com .oracle .truffle .api .frame .VirtualFrame ;
101
- import com .oracle .truffle .api .interop .InteropLibrary ;
102
- import com .oracle .truffle .api .interop .UnsupportedMessageException ;
103
- import com .oracle .truffle .api .library .CachedLibrary ;
104
99
import com .oracle .truffle .api .nodes .Node ;
105
100
import com .oracle .truffle .api .profiles .InlinedConditionProfile ;
106
101
import com .oracle .truffle .api .profiles .InlinedLoopConditionProfile ;
@@ -172,8 +167,6 @@ static int length(@SuppressWarnings("unused") PNone iterable) {
172
167
@ Fallback
173
168
@ InliningCutoff
174
169
static int length (VirtualFrame frame , Node inliningTarget , Object iterable ,
175
- @ Cached IsForeignObjectNode isForeignObjectNode ,
176
- @ Cached (inline = false ) GetLengthForeign getLengthForeign ,
177
170
@ Cached GetClassNode getClassNode ,
178
171
@ Cached GetCachedTpSlotsNode getSlotsNode ,
179
172
@ Cached PyIndexCheckNode indexCheckNode ,
@@ -185,12 +178,6 @@ static int length(VirtualFrame frame, Node inliningTarget, Object iterable,
185
178
@ Cached InlinedConditionProfile hasLenProfile ,
186
179
@ Cached InlinedConditionProfile hasLengthHintProfile ,
187
180
@ Cached PRaiseNode .Lazy raiseNode ) {
188
- if (isForeignObjectNode .execute (inliningTarget , iterable )) {
189
- int foreignLen = getLengthForeign .execute (iterable );
190
- if (foreignLen != -1 ) {
191
- return foreignLen ;
192
- }
193
- }
194
181
Object clazz = getClassNode .execute (inliningTarget , iterable );
195
182
TpSlots slots = getSlotsNode .execute (inliningTarget , clazz );
196
183
if (hasLenProfile .profile (inliningTarget , slots .combined_sq_mp_length () != null )) {
@@ -229,35 +216,6 @@ static int length(VirtualFrame frame, Node inliningTarget, Object iterable,
229
216
}
230
217
}
231
218
232
- /**
233
- * Handles the special case of foreign Strings. If the input is not a string, returns -1.
234
- */
235
- @ GenerateInline (false ) // Intentionally lazy initialized
236
- public abstract static class GetLengthForeign extends PNodeWithContext {
237
- public abstract int execute (Object foreign );
238
-
239
- @ Specialization
240
- static int doIt (Object foreign ,
241
- @ Bind ("this" ) Node inliningTarget ,
242
- @ Cached InlinedConditionProfile isString ,
243
- @ CachedLibrary (limit = "3" ) InteropLibrary iLib ,
244
- @ Cached TruffleString .SwitchEncodingNode switchEncodingNode ,
245
- @ Cached TruffleString .CodePointLengthNode codePointLengthNode ,
246
- @ Cached GilNode gil ) {
247
- if (isString .profile (inliningTarget , iLib .isString (foreign ))) {
248
- gil .release (true );
249
- try {
250
- return codePointLengthNode .execute (switchEncodingNode .execute (iLib .asTruffleString (foreign ), TS_ENCODING ), TS_ENCODING );
251
- } catch (UnsupportedMessageException e ) {
252
- throw CompilerDirectives .shouldNotReachHere ();
253
- } finally {
254
- gil .acquire ();
255
- }
256
- }
257
- return -1 ;
258
- }
259
- }
260
-
261
219
@ ImportStatic (PGuards .class )
262
220
@ GenerateInline
263
221
@ GenerateCached (false )
0 commit comments