IR: minor, remove unused 'isInlined'

This commit is contained in:
Alexander Udalov
2021-08-12 12:34:30 +02:00
parent 8b44b69982
commit 66dbd91851
2 changed files with 0 additions and 61 deletions
@@ -9,60 +9,7 @@ import org.jetbrains.kotlin.ir.declarations.IrClass
import org.jetbrains.kotlin.ir.declarations.IrConstructor
import org.jetbrains.kotlin.ir.declarations.IrField
import org.jetbrains.kotlin.ir.declarations.IrProperty
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
import org.jetbrains.kotlin.ir.symbols.IrScriptSymbol
import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
import org.jetbrains.kotlin.ir.types.IrSimpleType
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.ir.types.classifierOrFail
import org.jetbrains.kotlin.ir.types.isMarkedNullable
/**
* Returns inline class for given class or null of type is not inlined
* TODO: Make this configurable for different backends (currently implements logic of JS BE)
*/
private fun IrType.getInlinedClass(): IrClass? {
if (this is IrSimpleType) {
val erased = erase(this) ?: return null
if (erased.isInline) {
if (this.isMarkedNullable()) {
var fieldType: IrType
var fieldInlinedClass = erased
while (true) {
fieldType = getInlineClassUnderlyingType(fieldInlinedClass)
if (fieldType.isMarkedNullable()) {
return null
}
fieldInlinedClass = fieldType.getInlinedClass() ?: break
}
}
return erased
}
}
return null
}
/**
* Do not use this function in the JVM backend! Use `isInlineClassType` instead.
*
* This function has slightly different semantics for generic type parameters with inline class bounds.
*
* TODO: examine remaining usages in Native and preferably remove this function.
*/
fun IrType.isInlined(): Boolean = this.getInlinedClass() != null
private tailrec fun erase(type: IrType): IrClass? {
val classifier = type.classifierOrFail
return when (classifier) {
is IrClassSymbol -> classifier.owner
is IrScriptSymbol -> null // TODO: check if correct
is IrTypeParameterSymbol -> erase(classifier.owner.superTypes.first())
else -> error(classifier)
}
}
fun getInlineClassUnderlyingType(irClass: IrClass): IrType {
for (declaration in irClass.declarations) {
@@ -33,16 +33,8 @@ import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.isNullable
import org.jetbrains.kotlin.types.typeUtil.makeNullable
/**
* TODO: there is [IrType::getInlinedClass] in [org.jetbrains.kotlin.ir.util] which isn't compatible with
* Native's implementation. Please take a look while commonization.
*/
fun IrType.getInlinedClassNative(): IrClass? = IrTypeInlineClassesSupport.getInlinedClass(this)
/**
* TODO: there is [IrType::isInlined] in [org.jetbrains.kotlin.ir.util] which isn't compatible with
* Native's implementation. Please take a look while commonization.
*/
fun IrType.isInlinedNative(): Boolean = IrTypeInlineClassesSupport.isInlined(this)
fun IrClass.isInlined(): Boolean = IrTypeInlineClassesSupport.isInlined(this)
fun IrClass.isNativePrimitiveType() = IrTypeInlineClassesSupport.isTopLevelClass(this) &&