195
195
import com .oracle .truffle .api .profiles .BranchProfile ;
196
196
import com .oracle .truffle .api .profiles .ConditionProfile ;
197
197
import com .oracle .truffle .api .source .Source ;
198
+ import com .oracle .truffle .api .utilities .TriState ;
198
199
199
200
@ CoreFunctions (defineModule = BuiltinNames .BUILTINS )
200
201
public final class BuiltinFunctions extends PythonBuiltins {
@@ -1142,9 +1143,12 @@ public static IsInstanceNode create() {
1142
1143
return BuiltinFunctionsFactory .IsInstanceNodeFactory .create ();
1143
1144
}
1144
1145
1145
- private boolean isInstanceCheckInternal (VirtualFrame frame , Object instance , Object cls ) {
1146
+ private TriState isInstanceCheckInternal (VirtualFrame frame , Object instance , Object cls ) {
1146
1147
Object instanceCheckResult = instanceCheckNode .executeObject (frame , cls , instance );
1147
- return instanceCheckResult != NOT_IMPLEMENTED && castToBooleanNode .executeBoolean (frame , instanceCheckResult );
1148
+ if (instanceCheckResult == NOT_IMPLEMENTED ) {
1149
+ return TriState .UNDEFINED ;
1150
+ }
1151
+ return TriState .valueOf (castToBooleanNode .executeBoolean (frame , instanceCheckResult ));
1148
1152
}
1149
1153
1150
1154
public abstract boolean executeWith (VirtualFrame frame , Object instance , Object cls );
@@ -1154,7 +1158,7 @@ boolean isInstance(VirtualFrame frame, Object instance, Object cls,
1154
1158
@ Cached TypeNodes .IsSameTypeNode isSameTypeNode ,
1155
1159
@ Cached IsSubtypeNode isSubtypeNode ) {
1156
1160
Object instanceClass = getClassNode .execute (instance );
1157
- return isSameTypeNode .execute (instanceClass , cls ) || isSubtypeNode .execute (frame , instanceClass , cls ) || isInstanceCheckInternal (frame , instance , cls );
1161
+ return isSameTypeNode .execute (instanceClass , cls ) || isSubtypeNode .execute (frame , instanceClass , cls ) || isInstanceCheckInternal (frame , instance , cls ) == TriState . TRUE ;
1158
1162
}
1159
1163
1160
1164
@ Specialization (guards = "getLength(clsTuple) == cachedLen" , limit = "getVariableArgumentInlineCacheLimit()" )
@@ -1193,7 +1197,11 @@ boolean isInstance(VirtualFrame frame, Object instance, Object cls) {
1193
1197
return hostCls instanceof Class && ((Class <?>) hostCls ).isAssignableFrom (hostInstance .getClass ());
1194
1198
}
1195
1199
}
1196
- return isInstanceCheckInternal (frame , instance , cls ) || typeInstanceCheckNode .executeWith (frame , cls , instance );
1200
+ TriState check = isInstanceCheckInternal (frame , instance , cls );
1201
+ if (check == TriState .UNDEFINED ) {
1202
+ return typeInstanceCheckNode .executeWith (frame , cls , instance );
1203
+ }
1204
+ return check == TriState .TRUE ;
1197
1205
}
1198
1206
1199
1207
protected int getLength (PTuple t ) {
0 commit comments