IR: add BackendContext.typeSystem and JvmIrTypeSystemContext
To be able to override JVM-specific behavior of IrTypeSystemContext in JVM IR, for things like JVM flexible types.
This commit is contained in:
+11
-2
@@ -13,16 +13,24 @@ import org.jetbrains.kotlin.backend.wasm.utils.WasmInlineClassesUtils
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.impl.EmptyPackageFragmentDescriptor
|
||||
import org.jetbrains.kotlin.ir.*
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.IrFileEntry
|
||||
import org.jetbrains.kotlin.ir.SourceRangeInfo
|
||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||
import org.jetbrains.kotlin.ir.backend.js.JsCommonBackendContext
|
||||
import org.jetbrains.kotlin.ir.backend.js.JsMapping
|
||||
import org.jetbrains.kotlin.ir.backend.js.lower.JsInnerClassesSupport
|
||||
import org.jetbrains.kotlin.ir.builders.declarations.buildFun
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFactory
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
||||
import org.jetbrains.kotlin.ir.declarations.IrPackageFragment
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrExternalPackageFragmentImpl
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFileImpl
|
||||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.DescriptorlessExternalPackageFragmentSymbol
|
||||
import org.jetbrains.kotlin.ir.types.IrTypeSystemContext
|
||||
import org.jetbrains.kotlin.ir.types.IrTypeSystemContextImpl
|
||||
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
@@ -36,6 +44,7 @@ class WasmBackendContext(
|
||||
override val configuration: CompilerConfiguration,
|
||||
) : JsCommonBackendContext {
|
||||
override val builtIns = module.builtIns
|
||||
override val typeSystem: IrTypeSystemContext = IrTypeSystemContextImpl(irBuiltIns)
|
||||
override var inVerbosePhase: Boolean = false
|
||||
override val scriptMode = false
|
||||
override val irFactory: IrFactory = symbolTable.irFactory
|
||||
|
||||
+2
-3
@@ -15,7 +15,6 @@ import org.jetbrains.kotlin.ir.backend.js.utils.realOverrideTarget
|
||||
import org.jetbrains.kotlin.ir.builders.irImplicitCast
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
|
||||
import org.jetbrains.kotlin.ir.declarations.IrTypeParameter
|
||||
import org.jetbrains.kotlin.ir.expressions.IrCall
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
||||
@@ -62,7 +61,7 @@ class GenericReturnTypeLowering(val context: WasmBackendContext) : FileLoweringP
|
||||
|
||||
if (erasedReturnType != call.type) {
|
||||
if (callType.isNothing()) return call
|
||||
if (erasedReturnType.isSubtypeOf(callType, context.irBuiltIns)) return call
|
||||
if (erasedReturnType.isSubtypeOf(callType, context.typeSystem)) return call
|
||||
|
||||
// Erase type parameter from call return type
|
||||
val newCall = irCall(
|
||||
@@ -83,4 +82,4 @@ class GenericReturnTypeLowering(val context: WasmBackendContext) : FileLoweringP
|
||||
}
|
||||
return call
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+7
-4
@@ -17,7 +17,10 @@ import org.jetbrains.kotlin.backend.wasm.ir2wasm.erasedUpperBound
|
||||
import org.jetbrains.kotlin.ir.builders.*
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.ir.declarations.IrTypeParameter
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.expressions.IrConst
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.IrTypeOperator
|
||||
import org.jetbrains.kotlin.ir.expressions.IrTypeOperatorCall
|
||||
import org.jetbrains.kotlin.ir.types.*
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
||||
@@ -94,7 +97,7 @@ class WasmBaseTypeOperatorTransformer(val context: WasmBackendContext) : IrEleme
|
||||
// Inlined values have no type information on runtime.
|
||||
// But since they are final we can compute type checks on compile time.
|
||||
if (fromType.isInlined()) {
|
||||
val result = fromType.erasedType.isSubtypeOf(toType.erasedType, builtIns)
|
||||
val result = fromType.erasedType.isSubtypeOf(toType.erasedType, context.typeSystem)
|
||||
return builder.irBoolean(result)
|
||||
}
|
||||
|
||||
@@ -173,7 +176,7 @@ class WasmBaseTypeOperatorTransformer(val context: WasmBackendContext) : IrEleme
|
||||
}
|
||||
}
|
||||
|
||||
if (fromType.erasedType.isSubtypeOf(toType.erasedType, context.irBuiltIns)) {
|
||||
if (fromType.erasedType.isSubtypeOf(toType.erasedType, context.typeSystem)) {
|
||||
return value
|
||||
}
|
||||
if (toType.isNothing()) {
|
||||
@@ -213,7 +216,7 @@ class WasmBaseTypeOperatorTransformer(val context: WasmBackendContext) : IrEleme
|
||||
val toType = expression.typeOperand
|
||||
val fromType = expression.argument.type
|
||||
|
||||
if (fromType.erasedType.isSubtypeOf(expression.type.erasedType, context.irBuiltIns)) {
|
||||
if (fromType.erasedType.isSubtypeOf(expression.type.erasedType, context.typeSystem)) {
|
||||
return narrowType(fromType, expression.type, expression.argument)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user