156
156
import com .oracle .truffle .api .CompilerDirectives ;
157
157
import com .oracle .truffle .api .CompilerDirectives .CompilationFinal ;
158
158
import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
159
+ import com .oracle .truffle .api .HostCompilerDirectives .InliningCutoff ;
159
160
import com .oracle .truffle .api .dsl .Bind ;
160
161
import com .oracle .truffle .api .dsl .Cached ;
161
162
import com .oracle .truffle .api .dsl .Cached .Exclusive ;
@@ -278,6 +279,7 @@ abstract static class SequenceStorageBaseNode extends PNodeWithContext {
278
279
protected static final int MAX_SEQUENCE_STORAGES = 9 ;
279
280
protected static final int MAX_ARRAY_STORAGES = 7 ;
280
281
282
+ @ InliningCutoff
281
283
protected static boolean isByteStorage (NativeSequenceStorage store ) {
282
284
return store .getElementType () == ListStorageType .Byte ;
283
285
}
@@ -312,30 +314,37 @@ protected static boolean isEmpty(LenNode lenNode, SequenceStorage left) {
312
314
return lenNode .execute (left ) == 0 ;
313
315
}
314
316
317
+ @ InliningCutoff
315
318
protected static boolean isBoolean (GetElementType getElementTypeNode , SequenceStorage s ) {
316
319
return getElementTypeNode .execute (s ) == ListStorageType .Boolean ;
317
320
}
318
321
322
+ @ InliningCutoff
319
323
protected static boolean isByte (GetElementType getElementTypeNode , SequenceStorage s ) {
320
324
return getElementTypeNode .execute (s ) == ListStorageType .Byte ;
321
325
}
322
326
327
+ @ InliningCutoff
323
328
protected static boolean isByteLike (GetElementType getElementTypeNode , SequenceStorage s ) {
324
329
return isByte (getElementTypeNode , s ) || isInt (getElementTypeNode , s ) || isLong (getElementTypeNode , s );
325
330
}
326
331
332
+ @ InliningCutoff
327
333
protected static boolean isInt (GetElementType getElementTypeNode , SequenceStorage s ) {
328
334
return getElementTypeNode .execute (s ) == ListStorageType .Int ;
329
335
}
330
336
337
+ @ InliningCutoff
331
338
protected static boolean isLong (GetElementType getElementTypeNode , SequenceStorage s ) {
332
339
return getElementTypeNode .execute (s ) == ListStorageType .Long ;
333
340
}
334
341
342
+ @ InliningCutoff
335
343
protected static boolean isDouble (GetElementType getElementTypeNode , SequenceStorage s ) {
336
344
return getElementTypeNode .execute (s ) == ListStorageType .Double ;
337
345
}
338
346
347
+ @ InliningCutoff
339
348
protected static boolean isObject (GetElementType getElementTypeNode , SequenceStorage s ) {
340
349
return getElementTypeNode .execute (s ) == ListStorageType .Generic ;
341
350
}
@@ -432,13 +441,10 @@ public abstract static class GetItemNode extends NormalizingNode {
432
441
433
442
@ Child private GetItemScalarNode getItemScalarNode ;
434
443
@ Child private GetItemSliceNode getItemSliceNode ;
435
- @ Child private PRaiseNode raiseNode ;
436
- private final TruffleString keyTypeErrorMessage ;
437
444
private final BiFunction <SequenceStorage , PythonObjectFactory , Object > factoryMethod ;
438
445
439
- public GetItemNode (NormalizeIndexNode normalizeIndexNode , TruffleString keyTypeErrorMessage , BiFunction <SequenceStorage , PythonObjectFactory , Object > factoryMethod ) {
446
+ public GetItemNode (NormalizeIndexNode normalizeIndexNode , BiFunction <SequenceStorage , PythonObjectFactory , Object > factoryMethod ) {
440
447
super (normalizeIndexNode );
441
- this .keyTypeErrorMessage = keyTypeErrorMessage ;
442
448
this .factoryMethod = factoryMethod ;
443
449
}
444
450
@@ -462,16 +468,19 @@ protected Object doScalarLong(VirtualFrame frame, SequenceStorage storage, long
462
468
return getGetItemScalarNode ().execute (storage , normalizeIndex (frame , idx , storage ));
463
469
}
464
470
471
+ @ InliningCutoff
465
472
@ Specialization
466
473
protected Object doScalarPInt (VirtualFrame frame , SequenceStorage storage , PInt idx ) {
467
474
return getGetItemScalarNode ().execute (storage , normalizeIndex (frame , idx , storage ));
468
475
}
469
476
477
+ @ InliningCutoff
470
478
@ Specialization (guards = "!isPSlice(idx)" )
471
479
protected Object doScalarGeneric (VirtualFrame frame , SequenceStorage storage , Object idx ) {
472
480
return getGetItemScalarNode ().execute (storage , normalizeIndex (frame , idx , storage ));
473
481
}
474
482
483
+ @ InliningCutoff
475
484
@ Specialization
476
485
protected Object doSlice (VirtualFrame frame , SequenceStorage storage , PSlice slice ,
477
486
@ Cached LenNode lenNode ,
@@ -487,11 +496,6 @@ protected Object doSlice(VirtualFrame frame, SequenceStorage storage, PSlice sli
487
496
throw new IllegalStateException ();
488
497
}
489
498
490
- @ Fallback
491
- protected Object doInvalidKey (@ SuppressWarnings ("unused" ) SequenceStorage storage , Object key ) {
492
- throw ensureRaiseNode ().raise (TypeError , keyTypeErrorMessage , key );
493
- }
494
-
495
499
private GetItemScalarNode getGetItemScalarNode () {
496
500
if (getItemScalarNode == null ) {
497
501
CompilerDirectives .transferToInterpreterAndInvalidate ();
@@ -508,44 +512,20 @@ private GetItemSliceNode getGetItemSliceNode() {
508
512
return getItemSliceNode ;
509
513
}
510
514
511
- private PRaiseNode ensureRaiseNode () {
512
- if (raiseNode == null ) {
513
- CompilerDirectives .transferToInterpreterAndInvalidate ();
514
- raiseNode = insert (PRaiseNode .create ());
515
- }
516
- return raiseNode ;
517
- }
518
-
519
515
public static GetItemNode createNotNormalized () {
520
- return GetItemNodeGen .create (null , ErrorMessages . OBJ_INDEX_MUST_BE_INT_OR_SLICES , null );
516
+ return GetItemNodeGen .create (null , null );
521
517
}
522
518
523
519
public static GetItemNode create (NormalizeIndexNode normalizeIndexNode ) {
524
- return GetItemNodeGen .create (normalizeIndexNode , ErrorMessages . OBJ_INDEX_MUST_BE_INT_OR_SLICES , null );
520
+ return GetItemNodeGen .create (normalizeIndexNode , null );
525
521
}
526
522
527
523
public static GetItemNode create () {
528
- return GetItemNodeGen .create (NormalizeIndexNode .create (), ErrorMessages .OBJ_INDEX_MUST_BE_INT_OR_SLICES , null );
529
- }
530
-
531
- public static GetItemNode createNotNormalized (TruffleString keyTypeErrorMessage ) {
532
- return GetItemNodeGen .create (null , keyTypeErrorMessage , null );
533
- }
534
-
535
- public static GetItemNode create (NormalizeIndexNode normalizeIndexNode , TruffleString keyTypeErrorMessage ) {
536
- return GetItemNodeGen .create (normalizeIndexNode , keyTypeErrorMessage , null );
537
- }
538
-
539
- public static GetItemNode create (TruffleString keyTypeErrorMessage ) {
540
- return GetItemNodeGen .create (NormalizeIndexNode .create (), keyTypeErrorMessage , null );
541
- }
542
-
543
- public static GetItemNode create (NormalizeIndexNode normalizeIndexNode , TruffleString keyTypeErrorMessage , BiFunction <SequenceStorage , PythonObjectFactory , Object > factoryMethod ) {
544
- return GetItemNodeGen .create (normalizeIndexNode , keyTypeErrorMessage , factoryMethod );
524
+ return GetItemNodeGen .create (NormalizeIndexNode .create (), null );
545
525
}
546
526
547
527
public static GetItemNode create (NormalizeIndexNode normalizeIndexNode , BiFunction <SequenceStorage , PythonObjectFactory , Object > factoryMethod ) {
548
- return GetItemNodeGen .create (normalizeIndexNode , ErrorMessages . OBJ_INDEX_MUST_BE_INT_OR_SLICES , factoryMethod );
528
+ return GetItemNodeGen .create (normalizeIndexNode , factoryMethod );
549
529
}
550
530
551
531
}
@@ -682,6 +662,19 @@ protected static Object doMro(MroSequenceStorage storage, int idx) {
682
662
return storage .getItemNormalized (idx );
683
663
}
684
664
665
+ @ InliningCutoff
666
+ @ Specialization
667
+ protected static Object doNative (NativeSequenceStorage storage , int idx ,
668
+ @ Cached GetNativeItemScalarNode getItem ) {
669
+ return getItem .execute (storage , idx );
670
+ }
671
+ }
672
+
673
+ @ GenerateUncached
674
+ @ ImportStatic (SequenceStorageBaseNode .class )
675
+ protected abstract static class GetNativeItemScalarNode extends Node {
676
+ public abstract Object execute (NativeSequenceStorage s , int idx );
677
+
685
678
@ Specialization (guards = "isObject(getElementType, storage)" , limit = "1" )
686
679
protected static Object doNativeObject (NativeSequenceStorage storage , int idx ,
687
680
@ CachedLibrary ("storage.getPtr()" ) InteropLibrary lib ,
@@ -1134,7 +1127,7 @@ public static SetItemNode create(TruffleString invalidItemErrorMessage) {
1134
1127
}
1135
1128
1136
1129
@ GenerateUncached
1137
- @ ImportStatic (SequenceStorageBaseNode .class )
1130
+ @ ImportStatic ({ SequenceStorageBaseNode .class , PGuards . class } )
1138
1131
public abstract static class SetItemScalarNode extends Node {
1139
1132
1140
1133
public abstract void execute (SequenceStorage s , int idx , Object value );
@@ -1151,9 +1144,10 @@ protected static void doByteSimple(ByteSequenceStorage storage, int idx, byte va
1151
1144
storage .setByteItemNormalized (idx , value );
1152
1145
}
1153
1146
1147
+ @ InliningCutoff
1154
1148
@ Specialization (replaces = "doByteSimple" )
1155
1149
protected static void doByte (ByteSequenceStorage storage , int idx , Object value ,
1156
- @ Shared ( "castToByteNode" ) @ Cached CastToByteNode castToByteNode ) {
1150
+ @ Cached CastToByteNode castToByteNode ) {
1157
1151
// TODO: clean this up, we really might need a frame
1158
1152
storage .setByteItemNormalized (idx , castToByteNode .execute (null , value ));
1159
1153
}
@@ -1168,6 +1162,7 @@ protected static void doIntL(IntSequenceStorage storage, int idx, long value) th
1168
1162
storage .setIntItemNormalized (idx , PInt .intValueExact (value ));
1169
1163
}
1170
1164
1165
+ @ InliningCutoff
1171
1166
@ Specialization (replaces = "doIntL" )
1172
1167
protected static void doIntLOvf (IntSequenceStorage storage , int idx , long value ) {
1173
1168
try {
@@ -1177,7 +1172,8 @@ protected static void doIntLOvf(IntSequenceStorage storage, int idx, long value)
1177
1172
}
1178
1173
}
1179
1174
1180
- @ Specialization (guards = "!value.isNative()" )
1175
+ @ InliningCutoff
1176
+ @ Specialization (guards = "!isNativeWrapper(value)" )
1181
1177
protected static void doInt (IntSequenceStorage storage , int idx , PInt value ) {
1182
1178
try {
1183
1179
storage .setIntItemNormalized (idx , value .intValueExact ());
@@ -1196,7 +1192,8 @@ protected static void doLong(LongSequenceStorage storage, int idx, int value) {
1196
1192
storage .setLongItemNormalized (idx , value );
1197
1193
}
1198
1194
1199
- @ Specialization (guards = "!value.isNative()" )
1195
+ @ InliningCutoff
1196
+ @ Specialization (guards = "!isNativeWrapper(value)" )
1200
1197
protected static void doLong (LongSequenceStorage storage , int idx , PInt value ) {
1201
1198
try {
1202
1199
storage .setLongItemNormalized (idx , value .longValueExact ());
@@ -1215,11 +1212,34 @@ protected static void doObject(ObjectSequenceStorage storage, int idx, Object va
1215
1212
storage .setItemNormalized (idx , value );
1216
1213
}
1217
1214
1215
+ @ InliningCutoff
1216
+ @ Specialization
1217
+ protected static void doNative (NativeSequenceStorage storage , int idx , Object value ,
1218
+ @ Cached SetNativeItemScalarNode setItem ) {
1219
+ setItem .execute (storage , idx , value );
1220
+ }
1221
+
1222
+ @ Fallback
1223
+ @ SuppressWarnings ("unused" )
1224
+ static void doError (SequenceStorage s , int idx , Object item ) {
1225
+ throw new SequenceStoreException (item );
1226
+ }
1227
+
1228
+ public static SetItemScalarNode create () {
1229
+ return SetItemScalarNodeGen .create ();
1230
+ }
1231
+ }
1232
+
1233
+ @ GenerateUncached
1234
+ @ ImportStatic (SequenceStorageBaseNode .class )
1235
+ protected abstract static class SetNativeItemScalarNode extends Node {
1236
+ public abstract void execute (NativeSequenceStorage s , int idx , Object value );
1237
+
1218
1238
@ Specialization (guards = "isByteStorage(storage)" )
1219
1239
protected static void doNativeByte (NativeSequenceStorage storage , int idx , Object value ,
1220
1240
@ Shared ("raiseNode" ) @ Cached PRaiseNode raiseNode ,
1221
1241
@ Shared ("lib" ) @ CachedLibrary (limit = "1" ) InteropLibrary lib ,
1222
- @ Shared ( "castToByteNode" ) @ Cached CastToByteNode castToByteNode ) {
1242
+ @ Cached CastToByteNode castToByteNode ) {
1223
1243
try {
1224
1244
lib .writeArrayElement (storage .getPtr (), idx , castToByteNode .execute (null , value ));
1225
1245
} catch (UnsupportedMessageException | UnsupportedTypeException | InvalidArrayIndexException e ) {
@@ -1239,22 +1259,12 @@ protected static void doNative(NativeSequenceStorage storage, int idx, Object va
1239
1259
}
1240
1260
}
1241
1261
1242
- @ Fallback
1243
- @ SuppressWarnings ("unused" )
1244
- static void doError (SequenceStorage s , int idx , Object item ) {
1245
- throw new SequenceStoreException (item );
1246
- }
1247
-
1248
1262
private static Object verifyValue (NativeSequenceStorage storage , Object item , VerifyNativeItemNode verifyNativeItemNode ) {
1249
1263
if (verifyNativeItemNode .execute (storage .getElementType (), item )) {
1250
1264
return item ;
1251
1265
}
1252
1266
throw new SequenceStoreException (item );
1253
1267
}
1254
-
1255
- public static SetItemScalarNode create () {
1256
- return SetItemScalarNodeGen .create ();
1257
- }
1258
1268
}
1259
1269
1260
1270
@ GenerateUncached
0 commit comments