[K/N] Added isSubtype intrinsic

This commit is contained in:
Igor Chevdar
2023-05-10 10:03:42 +03:00
committed by Space Team
parent 67b65ec56a
commit 2f24c6df80
11 changed files with 56 additions and 43 deletions
@@ -53,8 +53,8 @@ touchFunction(FreezeSubgraph)
touchFunction(CheckGlobalsAccessible)
touchFunction(LookupInterfaceTableRecord)
touchFunction(IsInstance)
touchFunction(IsInstanceOfClassFast)
touchFunction(IsSubtype)
touchFunction(IsSubclassFast)
touchFunction(ThrowException)
touchFunction(Kotlin_getExceptionObject)
+5 -4
View File
@@ -12,6 +12,10 @@ KBoolean IsInstance(const ObjHeader* obj, const TypeInfo* type_info) {
// We assume null check is handled by caller.
RuntimeAssert(obj != nullptr, "must not be null");
const TypeInfo* obj_type_info = obj->type_info();
return IsSubtype(obj_type_info, type_info);
}
KBoolean IsSubtype(const TypeInfo* obj_type_info, const TypeInfo* type_info) {
// If it is an interface - check in list of implemented interfaces.
if ((type_info->flags_ & TF_INTERFACE) != 0) {
for (int i = 0; i < obj_type_info->implementedInterfacesCount_; ++i) {
@@ -27,10 +31,7 @@ KBoolean IsInstance(const ObjHeader* obj, const TypeInfo* type_info) {
return obj_type_info != nullptr;
}
KBoolean IsInstanceOfClassFast(const ObjHeader* obj, int32_t lo, int32_t hi) {
// We assume null check is handled by caller.
RuntimeAssert(obj != nullptr, "must not be null");
const TypeInfo* obj_type_info = obj->type_info();
KBoolean IsSubclassFast(const TypeInfo* obj_type_info, int32_t lo, int32_t hi) {
// Super type's interval should contain our interval.
return obj_type_info->classId_ >= lo && obj_type_info->classId_ <= hi;
}
+2 -1
View File
@@ -73,7 +73,8 @@ extern const TypeInfo* theCleanerImplTypeInfo;
extern const TypeInfo* theRegularWeakReferenceImplTypeInfo;
KBoolean IsInstance(const ObjHeader* obj, const TypeInfo* type_info) RUNTIME_PURE;
KBoolean IsInstanceOfClassFast(const ObjHeader* obj, int32_t lo, int32_t hi) RUNTIME_PURE;
KBoolean IsSubtype(const TypeInfo* obj_type_info, const TypeInfo* type_info) RUNTIME_PURE;
KBoolean IsSubclassFast(const TypeInfo* obj_type_info, int32_t lo, int32_t hi) RUNTIME_PURE;
void CheckCast(const ObjHeader* obj, const TypeInfo* type_info);
KBoolean IsArray(KConstRef obj) RUNTIME_PURE;
bool IsSubInterface(const TypeInfo* thiz, const TypeInfo* other) RUNTIME_PURE;
@@ -52,6 +52,7 @@ internal class IntrinsicType {
const val IDENTITY = "IDENTITY"
const val IMMUTABLE_BLOB = "IMMUTABLE_BLOB"
const val INIT_INSTANCE = "INIT_INSTANCE"
const val IS_SUBTYPE = "IS_SUBTYPE"
const val IS_EXPERIMENTAL_MM = "IS_EXPERIMENTAL_MM"
const val THE_UNIT_INSTANCE = "THE_UNIT_INSTANCE"
@@ -226,6 +226,10 @@ internal external fun <T> createUninitializedInstance(): T
@TypedIntrinsic(IntrinsicType.INIT_INSTANCE)
internal external fun initInstance(thiz: Any, constructorCall: Any): Unit
@PublishedApi
@TypedIntrinsic(IntrinsicType.IS_SUBTYPE)
internal external fun <T> isSubtype(objTypeInfo: NativePtr): Boolean
@PublishedApi
internal fun checkProgressionStep(step: Int) =
if (step > 0) step else throw IllegalArgumentException("Step must be positive, was: $step.")