Remove unsafe cast function usages from JVM backend modules
This commit is contained in:
committed by
Space Team
parent
2cd16f055a
commit
1418423423
+3
-4
@@ -57,9 +57,7 @@ import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.resolve.jvm.checkers.JvmSimpleNameBacktickChecker
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.*
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmClassSignature
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.cast
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
import org.jetbrains.org.objectweb.asm.*
|
||||
import org.jetbrains.org.objectweb.asm.commons.Method
|
||||
import java.io.File
|
||||
@@ -247,7 +245,8 @@ class ClassCodegen private constructor(
|
||||
if (supertypeArgument is IrTypeProjection) {
|
||||
val typeArgument = supertypeArgument.type
|
||||
if (typeArgument.isReifiedTypeParameter) {
|
||||
reifiedTypeParametersUsages.addUsedReifiedParameter(typeArgument.classifierOrFail.cast<IrTypeParameterSymbol>().owner.name.asString())
|
||||
val typeParameter = typeArgument.classifierOrFail as IrTypeParameterSymbol
|
||||
reifiedTypeParametersUsages.addUsedReifiedParameter(typeParameter.owner.name.asString())
|
||||
} else {
|
||||
processTypeParameters(typeArgument)
|
||||
}
|
||||
@@ -580,7 +579,7 @@ class ClassCodegen private constructor(
|
||||
// The one exception to this rule are anonymous objects defined as members of a class. These are nested inside of the
|
||||
// class initializer, but can be referred to from anywhere within the scope of the class. That's why we have to ensure
|
||||
// that all references to classes inside of <clinit> have a non-null `parentFunction`.
|
||||
parentFunction: IrFunction? = irClass.parent.safeAs<IrFunction>()?.takeIf {
|
||||
parentFunction: IrFunction? = (irClass.parent as? IrFunction)?.takeIf {
|
||||
it.origin == JvmLoweredDeclarationOrigin.CLASS_STATIC_INITIALIZER
|
||||
},
|
||||
): ClassCodegen =
|
||||
|
||||
+1
-2
@@ -55,7 +55,6 @@ import org.jetbrains.kotlin.types.TypeSystemCommonBackendContext
|
||||
import org.jetbrains.kotlin.types.computeExpandedTypeForInlineClass
|
||||
import org.jetbrains.kotlin.types.model.TypeParameterMarker
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
import org.jetbrains.org.objectweb.asm.Label
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes
|
||||
import org.jetbrains.org.objectweb.asm.Type
|
||||
@@ -1502,7 +1501,7 @@ class ExpressionCodegen(
|
||||
get() = irFunction.isInline || irFunction.origin == JvmLoweredDeclarationOrigin.INLINE_LAMBDA
|
||||
|
||||
val IrType.isReifiedTypeParameter: Boolean
|
||||
get() = this.classifierOrNull?.safeAs<IrTypeParameterSymbol>()?.owner?.isReified == true
|
||||
get() = (classifierOrNull as? IrTypeParameterSymbol)?.owner?.isReified == true
|
||||
|
||||
companion object {
|
||||
internal fun generateClassInstance(v: InstructionAdapter, classType: IrType, typeMapper: IrTypeMapper, wrapPrimitives: Boolean) {
|
||||
|
||||
+8
-10
@@ -21,7 +21,10 @@ import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.descriptors.toIrBasedDescriptor
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.expressions.IrClassReference
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.IrGetValue
|
||||
import org.jetbrains.kotlin.ir.expressions.IrVararg
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.load.java.JavaDescriptorVisibilities
|
||||
import org.jetbrains.kotlin.name.JvmNames.JVM_SYNTHETIC_ANNOTATION_FQ_NAME
|
||||
@@ -30,7 +33,6 @@ import org.jetbrains.kotlin.name.JvmNames.SYNCHRONIZED_ANNOTATION_FQ_NAME
|
||||
import org.jetbrains.kotlin.resolve.annotations.JVM_THROWS_ANNOTATION_FQ_NAME
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterKind
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
import org.jetbrains.org.objectweb.asm.*
|
||||
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
|
||||
import org.jetbrains.org.objectweb.asm.tree.MethodNode
|
||||
@@ -235,14 +237,10 @@ class FunctionCodegen(private val irFunction: IrFunction, private val classCodeg
|
||||
if (!classCodegen.irClass.isAnnotationClass) return null
|
||||
// TODO: any simpler way to get to the value expression?
|
||||
// Are there other valid IR structures that represent the default value?
|
||||
return irFunction.safeAs<IrSimpleFunction>()
|
||||
?.correspondingPropertySymbol?.owner
|
||||
?.backingField
|
||||
?.initializer.safeAs<IrExpressionBody>()
|
||||
?.expression?.safeAs<IrGetValue>()
|
||||
?.symbol?.owner?.safeAs<IrValueParameter>()
|
||||
?.defaultValue?.safeAs<IrExpressionBody>()
|
||||
?.expression
|
||||
val backingField = (irFunction as? IrSimpleFunction)?.correspondingPropertySymbol?.owner?.backingField
|
||||
val getValue = backingField?.initializer?.expression as? IrGetValue
|
||||
val parameter = getValue?.symbol?.owner as? IrValueParameter
|
||||
return parameter?.defaultValue?.expression
|
||||
}
|
||||
|
||||
private fun IrFunction.createFrameMapWithReceivers(): IrFrameMap {
|
||||
|
||||
+3
-5
@@ -29,10 +29,9 @@ import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.expressions.IrCall
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
|
||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
||||
import org.jetbrains.kotlin.ir.types.IrSimpleType
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.classOrNull
|
||||
import org.jetbrains.kotlin.ir.types.getClass
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.load.java.JavaDescriptorVisibilities
|
||||
@@ -40,7 +39,6 @@ import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.resolve.jvm.AsmTypes
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmClassSignature
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes
|
||||
import org.jetbrains.org.objectweb.asm.Type
|
||||
|
||||
@@ -106,7 +104,7 @@ private fun IrDeclaration.getVisibilityAccessFlagForAnonymous(): Int =
|
||||
|
||||
fun IrClass.calculateInnerClassAccessFlags(context: JvmBackendContext): Int {
|
||||
val isLambda = superTypes.any {
|
||||
it.safeAs<IrSimpleType>()?.classifier === context.ir.symbols.lambdaClass
|
||||
it.classOrNull === context.ir.symbols.lambdaClass
|
||||
}
|
||||
val visibility = when {
|
||||
isLambda -> getVisibilityAccessFlagForAnonymous()
|
||||
@@ -245,7 +243,7 @@ internal fun IrTypeMapper.mapClassSignature(irClass: IrClass, type: Type): JvmCl
|
||||
|
||||
val superInterfaces = LinkedHashSet<String>()
|
||||
for (superType in irClass.superTypes) {
|
||||
val superClass = superType.safeAs<IrSimpleType>()?.classifier?.safeAs<IrClassSymbol>()?.owner ?: continue
|
||||
val superClass = superType.classOrNull?.owner ?: continue
|
||||
if (superClass.isJvmInterface) {
|
||||
sw.writeInterface()
|
||||
superInterfaces.add(mapSupertype(superType, sw).internalName)
|
||||
|
||||
+2
-3
@@ -13,7 +13,6 @@ import org.jetbrains.kotlin.backend.jvm.ir.getStringConstArgument
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.util.dump
|
||||
import org.jetbrains.kotlin.ir.util.render
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
import org.jetbrains.org.objectweb.asm.Handle
|
||||
import org.jetbrains.org.objectweb.asm.Type
|
||||
|
||||
@@ -34,8 +33,8 @@ object JvmInvokeDynamic : IntrinsicMethod() {
|
||||
?: fail("'bootstrapMethodHandle' should be a call")
|
||||
val bootstrapMethodHandle = evalMethodHandle(bootstrapMethodHandleArg)
|
||||
|
||||
val bootstrapMethodArgs = (expression.getValueArgument(2)?.safeAs<IrVararg>()
|
||||
?: fail("'bootstrapMethodArgs' is expected to be a vararg"))
|
||||
val bootstrapMethodArgs = expression.getValueArgument(2) as? IrVararg
|
||||
?: fail("'bootstrapMethodArgs' is expected to be a vararg")
|
||||
val asmBootstrapMethodArgs = bootstrapMethodArgs.elements
|
||||
.map { generateBootstrapMethodArg(it, codegen) }
|
||||
.toTypedArray()
|
||||
|
||||
+1
-2
@@ -47,7 +47,6 @@ import org.jetbrains.kotlin.serialization.deserialization.descriptors.Deserializ
|
||||
import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.typeUtil.replaceAnnotations
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
open class JvmGeneratorExtensionsImpl(
|
||||
private val configuration: CompilerConfiguration,
|
||||
@@ -70,7 +69,7 @@ open class JvmGeneratorExtensionsImpl(
|
||||
}
|
||||
|
||||
override fun getContainerSource(descriptor: DeclarationDescriptor): DeserializedContainerSource? {
|
||||
return descriptor.safeAs<DescriptorWithContainerSource>()?.containerSource
|
||||
return (descriptor as? DescriptorWithContainerSource)?.containerSource
|
||||
}
|
||||
|
||||
override fun computeFieldVisibility(descriptor: PropertyDescriptor): DescriptorVisibility? =
|
||||
|
||||
+8
-11
@@ -28,7 +28,6 @@ import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.types.AbstractTypeChecker
|
||||
import org.jetbrains.kotlin.types.TypeCheckerState
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.cast
|
||||
|
||||
internal val collectionStubMethodLowering = makeIrFilePhase(
|
||||
::CollectionStubMethodLowering,
|
||||
@@ -180,17 +179,15 @@ internal class CollectionStubMethodLowering(val context: JvmBackendContext) : Cl
|
||||
}
|
||||
}
|
||||
|
||||
private fun liftStubMethodReturnType(function: IrSimpleFunction) =
|
||||
when (function.name.asString()) {
|
||||
"iterator" ->
|
||||
context.ir.symbols.iterator.typeWithArguments(function.returnType.cast<IrSimpleType>().arguments)
|
||||
"listIterator" ->
|
||||
context.ir.symbols.listIterator.typeWithArguments(function.returnType.cast<IrSimpleType>().arguments)
|
||||
"subList" ->
|
||||
context.ir.symbols.list.typeWithArguments(function.returnType.cast<IrSimpleType>().arguments)
|
||||
else ->
|
||||
function.returnType
|
||||
private fun liftStubMethodReturnType(function: IrSimpleFunction): IrType {
|
||||
val klass = when (function.name.asString()) {
|
||||
"iterator" -> context.ir.symbols.iterator
|
||||
"listIterator" -> context.ir.symbols.listIterator
|
||||
"subList" -> context.ir.symbols.list
|
||||
else -> return function.returnType
|
||||
}
|
||||
return klass.typeWithArguments((function.returnType as IrSimpleType).arguments)
|
||||
}
|
||||
|
||||
private fun isEffectivelyOverriddenBy(superFun: IrSimpleFunction, overridingFun: IrSimpleFunction): Boolean {
|
||||
// Function 'f0' is overridden by function 'f1' if all the following conditions are met,
|
||||
|
||||
+17
-7
@@ -13,25 +13,36 @@ import org.jetbrains.kotlin.backend.common.lower.createIrBuilder
|
||||
import org.jetbrains.kotlin.backend.common.phaser.makeIrFilePhase
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin
|
||||
import org.jetbrains.kotlin.backend.jvm.ir.*
|
||||
import org.jetbrains.kotlin.backend.jvm.ir.createJvmIrBuilder
|
||||
import org.jetbrains.kotlin.backend.jvm.ir.getSingleAbstractMethod
|
||||
import org.jetbrains.kotlin.backend.jvm.ir.irArray
|
||||
import org.jetbrains.kotlin.backend.jvm.ir.javaClassReference
|
||||
import org.jetbrains.kotlin.codegen.ImplementationBodyCodegen
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
|
||||
import org.jetbrains.kotlin.ir.IrStatement
|
||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||
import org.jetbrains.kotlin.ir.builders.*
|
||||
import org.jetbrains.kotlin.ir.builders.declarations.*
|
||||
import org.jetbrains.kotlin.ir.builders.declarations.addField
|
||||
import org.jetbrains.kotlin.ir.builders.declarations.addFunction
|
||||
import org.jetbrains.kotlin.ir.builders.declarations.addValueParameter
|
||||
import org.jetbrains.kotlin.ir.builders.declarations.buildConstructor
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.*
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrExpressionBodyImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrFunctionReferenceImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrGetValueImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrSetValueImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrValueParameterSymbol
|
||||
import org.jetbrains.kotlin.ir.types.*
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.defaultType
|
||||
import org.jetbrains.kotlin.ir.types.getClass
|
||||
import org.jetbrains.kotlin.ir.types.typeWith
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
internal val enumClassPhase = makeIrFilePhase(
|
||||
::EnumClassLowering,
|
||||
@@ -228,8 +239,7 @@ private class EnumClassLowering(private val context: JvmBackendContext) : ClassL
|
||||
}
|
||||
|
||||
override fun visitSimpleFunction(declaration: IrSimpleFunction): IrStatement {
|
||||
val body = declaration.body?.safeAs<IrSyntheticBody>()
|
||||
?: return declaration
|
||||
val body = declaration.body as? IrSyntheticBody ?: return declaration
|
||||
|
||||
declaration.body = context.createJvmIrBuilder(declaration.symbol).run {
|
||||
irExprBody(
|
||||
|
||||
+2
-3
@@ -16,8 +16,8 @@ import org.jetbrains.kotlin.backend.jvm.ir.createJvmIrBuilder
|
||||
import org.jetbrains.kotlin.backend.jvm.ir.irArray
|
||||
import org.jetbrains.kotlin.builtins.StandardNames
|
||||
import org.jetbrains.kotlin.builtins.functions.BuiltInFunctionArity
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.ir.IrStatement
|
||||
import org.jetbrains.kotlin.ir.builders.*
|
||||
import org.jetbrains.kotlin.ir.builders.declarations.addFunction
|
||||
@@ -28,7 +28,6 @@ import org.jetbrains.kotlin.ir.types.*
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
internal val functionNVarargBridgePhase = makeIrFilePhase(
|
||||
::FunctionNVarargBridgeLowering,
|
||||
@@ -150,7 +149,7 @@ private class FunctionNVarargBridgeLowering(val context: JvmBackendContext) :
|
||||
get() {
|
||||
val clazz = classOrNull?.owner ?: return false
|
||||
val name = clazz.name.asString()
|
||||
val fqName = clazz.parent.safeAs<IrPackageFragment>()?.fqName ?: return false
|
||||
val fqName = (clazz.parent as? IrPackageFragment)?.fqName ?: return false
|
||||
return when {
|
||||
name.startsWith("Function") ->
|
||||
fqName == StandardNames.BUILT_INS_PACKAGE_FQ_NAME || fqName == FUNCTIONS_PACKAGE_FQ_NAME
|
||||
|
||||
+1
-2
@@ -35,7 +35,6 @@ import org.jetbrains.kotlin.ir.expressions.impl.IrTypeOperatorCallImpl
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.ir.visitors.*
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
internal val inheritedDefaultMethodsOnClassesPhase = makeIrFilePhase(
|
||||
::InheritedDefaultMethodsOnClassesLowering,
|
||||
@@ -284,7 +283,7 @@ internal fun IrSimpleFunction.isDefinitelyNotDefaultImplsMethod(
|
||||
|
||||
private fun IrSimpleFunction.isCloneableClone(): Boolean =
|
||||
name.asString() == "clone" &&
|
||||
parent.safeAs<IrClass>()?.fqNameWhenAvailable?.asString() == "kotlin.Cloneable" &&
|
||||
(parent as? IrClass)?.fqNameWhenAvailable?.asString() == "kotlin.Cloneable" &&
|
||||
valueParameters.isEmpty()
|
||||
|
||||
internal val interfaceObjectCallsPhase = makeIrFilePhase(
|
||||
|
||||
+2
-3
@@ -6,7 +6,6 @@
|
||||
package org.jetbrains.kotlin.backend.jvm.lower
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.ir.BuiltinSymbolsBase
|
||||
import org.jetbrains.kotlin.ir.deepCopyWithVariables
|
||||
import org.jetbrains.kotlin.backend.common.lower.*
|
||||
import org.jetbrains.kotlin.backend.common.phaser.makeIrFilePhase
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
@@ -20,6 +19,7 @@ import org.jetbrains.kotlin.ir.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.builders.*
|
||||
import org.jetbrains.kotlin.ir.builders.declarations.*
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.deepCopyWithVariables
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrDelegatingConstructorCallImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||
@@ -30,7 +30,6 @@ import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
internal val annotationImplementationPhase = makeIrFilePhase<JvmBackendContext>(
|
||||
{ ctxt -> AnnotationImplementationLowering { JvmAnnotationImplementationTransformer(ctxt, it) } },
|
||||
@@ -44,7 +43,7 @@ class JvmAnnotationImplementationTransformer(val jvmContext: JvmBackendContext,
|
||||
|
||||
// FIXME: Copied from JvmSingleAbstractMethodLowering
|
||||
private val inInlineFunctionScope: Boolean
|
||||
get() = allScopes.any { it.irElement.safeAs<IrDeclaration>()?.isInPublicInlineScope == true }
|
||||
get() = allScopes.any { (it.irElement as? IrDeclaration)?.isInPublicInlineScope == true }
|
||||
|
||||
private val implementor = AnnotationPropertyImplementor(
|
||||
jvmContext.irFactory,
|
||||
|
||||
+2
-3
@@ -12,12 +12,11 @@ import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.backend.jvm.ir.hasPlatformDependent
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.IrStatement
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationBase
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
val jvmArgumentNullabilityAssertions = makeIrFilePhase(
|
||||
::JvmArgumentNullabilityAssertionsLowering,
|
||||
@@ -92,7 +91,7 @@ private class JvmArgumentNullabilityAssertionsLowering(context: JvmBackendContex
|
||||
}
|
||||
|
||||
private fun isCallToMethodWithTypeCheckBarrier(expression: IrMemberAccessExpression<*>): Boolean =
|
||||
expression.symbol.owner.safeAs<IrSimpleFunction>()
|
||||
(expression.symbol.owner as? IrSimpleFunction)
|
||||
?.let {
|
||||
val bridgeInfo = specialBridgeMethods.findSpecialWithOverride(it, includeSelf = true)
|
||||
// The JVM BE adds null checks around platform dependent special bridge methods (Map.getOrDefault and the version of
|
||||
|
||||
+1
-2
@@ -26,7 +26,6 @@ import org.jetbrains.kotlin.ir.expressions.IrTypeOperatorCall
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.getClass
|
||||
import org.jetbrains.kotlin.load.java.JavaDescriptorVisibilities
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
internal val singleAbstractMethodPhase = makeIrFilePhase(
|
||||
::JvmSingleAbstractMethodLowering,
|
||||
@@ -42,7 +41,7 @@ private class JvmSingleAbstractMethodLowering(context: JvmBackendContext) : Sing
|
||||
context.state.languageVersionSettings.supportsFeature(LanguageFeature.JavaSamConversionEqualsHashCode)
|
||||
|
||||
override val inInlineFunctionScope: Boolean
|
||||
get() = allScopes.any { it.irElement.safeAs<IrDeclaration>()?.isInPublicInlineScope == true }
|
||||
get() = allScopes.any { (it.irElement as? IrDeclaration)?.isInPublicInlineScope == true }
|
||||
|
||||
override fun getWrapperVisibility(expression: IrTypeOperatorCall, scopes: List<ScopeWithIr>) =
|
||||
if (inInlineFunctionScope) DescriptorVisibilities.PUBLIC else JavaDescriptorVisibilities.PACKAGE_VISIBILITY
|
||||
|
||||
+1
-2
@@ -27,7 +27,6 @@ import org.jetbrains.kotlin.ir.types.*
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
internal val enumWhenPhase = makeIrFilePhase(
|
||||
::MappedEnumWhenLowering,
|
||||
@@ -114,7 +113,7 @@ private class MappedEnumWhenLowering(override val context: JvmBackendContext) :
|
||||
val mapping = state!!.getMappingForClass(subject.type.getClass()!!)
|
||||
|
||||
mapping.isPublicAbi = mapping.isPublicAbi ||
|
||||
(builder.scope.scopeOwnerSymbol.owner.safeAs<IrDeclaration>()?.isInPublicInlineScope ?: false)
|
||||
(builder.scope.scopeOwnerSymbol.owner as? IrDeclaration)?.isInPublicInlineScope == true
|
||||
|
||||
dispatchReceiver = builder.irGetField(null, mapping.field)
|
||||
putValueArgument(0, super.mapRuntimeEnumEntry(builder, subject))
|
||||
|
||||
+2
-3
@@ -49,7 +49,6 @@ import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmBackendErrors
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
internal val scriptsToClassesPhase = makeCustomPhase<JvmBackendContext, IrModuleFragment>(
|
||||
name = "ScriptsToClasses",
|
||||
@@ -218,7 +217,7 @@ private class ScriptsToClassesLowering(val context: JvmBackendContext, val inner
|
||||
.transform(lambdaPatcher, ScriptFixLambdasTransformerContext())
|
||||
}
|
||||
|
||||
(irScript.constructor?.patchForClass()?.safeAs<IrConstructor>() ?: createConstructor(irScriptClass, irScript)).also { constructor ->
|
||||
(irScript.constructor?.patchForClass() as? IrConstructor ?: createConstructor(irScriptClass, irScript)).also { constructor ->
|
||||
val explicitParamsStartIndex = if (irScript.earlierScriptsParameter == null) 0 else 1
|
||||
val explicitParameters = constructor.valueParameters.subList(
|
||||
explicitParamsStartIndex,
|
||||
@@ -250,7 +249,7 @@ private class ScriptsToClassesLowering(val context: JvmBackendContext, val inner
|
||||
+irSetField(
|
||||
irGet(irScriptClass.thisReceiver!!),
|
||||
field,
|
||||
irGet(correspondingParameter.patchForClass().safeAs<IrValueParameter>()!!)
|
||||
irGet(correspondingParameter.patchForClass() as IrValueParameter)
|
||||
)
|
||||
}
|
||||
+IrInstanceInitializerCallImpl(
|
||||
|
||||
+1
-5
@@ -19,7 +19,6 @@ import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin
|
||||
import org.jetbrains.kotlin.backend.jvm.ir.*
|
||||
import org.jetbrains.kotlin.backend.jvm.unboxInlineClass
|
||||
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
|
||||
import org.jetbrains.kotlin.ir.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.IrStatement
|
||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||
@@ -38,9 +37,6 @@ import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.acceptVoid
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import org.jetbrains.kotlin.types.checker.SimpleClassicTypeSystemContext.getArgument
|
||||
import org.jetbrains.kotlin.types.checker.SimpleClassicTypeSystemContext.isTypeVariableType
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
import org.jetbrains.org.objectweb.asm.Handle
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes
|
||||
import org.jetbrains.org.objectweb.asm.commons.Method
|
||||
@@ -751,7 +747,7 @@ private class TypeOperatorLowering(private val backendContext: JvmBackendContext
|
||||
sourceView.subSequence(startOffset, endOffset).toString()
|
||||
} else {
|
||||
// Fallback for inconsistent line numbers
|
||||
declarationParent.safeAs<IrDeclarationWithName>()?.name?.asString() ?: "Unknown Declaration"
|
||||
(declarationParent as? IrDeclarationWithName)?.name?.asString() ?: "Unknown Declaration"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -19,7 +19,6 @@ import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.InlineClassDescriptorResolver
|
||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
/**
|
||||
@@ -56,7 +55,7 @@ class MemoizedInlineClassReplacements(
|
||||
null
|
||||
|
||||
// Mangle all functions in the body of an inline class
|
||||
it.parent.safeAs<IrClass>()?.isSingleFieldValueClass == true ->
|
||||
(it.parent as? IrClass)?.isSingleFieldValueClass == true ->
|
||||
when {
|
||||
it.isValueClassTypedEquals -> createStaticReplacement(it).also {
|
||||
it.name = InlineClassDescriptorResolver.SPECIALIZED_EQUALS_NAME
|
||||
|
||||
+1
-2
@@ -22,7 +22,6 @@ import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.InlineClassDescriptorResolver
|
||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
/**
|
||||
@@ -235,7 +234,7 @@ class MemoizedMultiFieldValueClassReplacements(
|
||||
function.origin.isSynthetic && function.origin != IrDeclarationOrigin.SYNTHETIC_GENERATED_SAM_IMPLEMENTATION ||
|
||||
function.isMultiFieldValueClassFieldGetter -> null
|
||||
|
||||
function.parent.safeAs<IrClass>()?.isMultiFieldValueClass == true -> when {
|
||||
(function.parent as? IrClass)?.isMultiFieldValueClass == true -> when {
|
||||
function.isValueClassTypedEquals -> createStaticReplacement(function).also {
|
||||
it.name = InlineClassDescriptorResolver.SPECIALIZED_EQUALS_NAME
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ import org.jetbrains.kotlin.ir.expressions.IrFunctionReference
|
||||
import org.jetbrains.kotlin.ir.types.isNullable
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.resolve.inline.INLINE_ONLY_ANNOTATION_FQ_NAME
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
fun IrValueParameter.isInlineParameter(): Boolean =
|
||||
index >= 0 && !isNoinline && (type.isFunction() || type.isSuspendFunction()) &&
|
||||
@@ -48,7 +47,7 @@ val IrDeclaration.inlineScopeVisibility: DescriptorVisibility?
|
||||
owner.visibility
|
||||
}
|
||||
}
|
||||
owner = owner.parent.safeAs<IrDeclaration>()?.original
|
||||
owner = (owner.parent as? IrDeclaration)?.original
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ import org.jetbrains.kotlin.ir.types.impl.IrStarProjectionImpl
|
||||
import org.jetbrains.kotlin.ir.types.impl.makeTypeProjection
|
||||
import org.jetbrains.kotlin.ir.util.isLocal
|
||||
import org.jetbrains.kotlin.ir.util.render
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
/**
|
||||
* Perform as much type erasure as is significant for JVM signature generation.
|
||||
@@ -160,7 +159,7 @@ fun collectVisibleTypeParameters(scopeOwner: IrTypeParametersContainer): Set<IrT
|
||||
.toSet()
|
||||
|
||||
val IrType.isReifiedTypeParameter: Boolean
|
||||
get() = classifierOrNull?.safeAs<IrTypeParameterSymbol>()?.owner?.isReified == true
|
||||
get() = (classifierOrNull as? IrTypeParameterSymbol)?.owner?.isReified == true
|
||||
|
||||
val IrTypeParameter.representativeUpperBound: IrType
|
||||
get() {
|
||||
|
||||
+2
-4
@@ -41,7 +41,6 @@ import org.jetbrains.kotlin.resolve.jvm.JAVA_LANG_RECORD_FQ_NAME
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodGenericSignature
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterKind
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
import org.jetbrains.org.objectweb.asm.Handle
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes
|
||||
import org.jetbrains.org.objectweb.asm.Type
|
||||
@@ -131,8 +130,7 @@ class MethodSignatureMapper(private val context: JvmBackendContext, private val
|
||||
origin != IrDeclarationOrigin.PROPERTY_DELEGATE &&
|
||||
!isPublishedApi()
|
||||
) {
|
||||
return originalFunction.takeIf { it != this }
|
||||
?.safeAs<IrSimpleFunction>()
|
||||
return (originalFunction.takeIf { it != this } as? IrSimpleFunction)
|
||||
?.getInternalFunctionForManglingIfNeeded()
|
||||
?: this
|
||||
}
|
||||
@@ -449,7 +447,7 @@ class MethodSignatureMapper(private val context: JvmBackendContext, private val
|
||||
|
||||
private val IrSimpleFunction.isBuiltIn: Boolean
|
||||
get() = getPackageFragment().fqName == StandardNames.BUILT_INS_PACKAGE_FQ_NAME ||
|
||||
parent.safeAs<IrClass>()?.fqNameWhenAvailable?.toUnsafe()?.let(JavaToKotlinClassMap::mapKotlinToJava) != null
|
||||
(parent as? IrClass)?.fqNameWhenAvailable?.toUnsafe()?.let(JavaToKotlinClassMap::mapKotlinToJava) != null
|
||||
|
||||
// From BuiltinMethodsWithDifferentJvmName.isBuiltinFunctionWithDifferentNameInJvm, BuiltinMethodsWithDifferentJvmName.getJvmName
|
||||
private fun IrSimpleFunction.getDifferentNameForJvmBuiltinFunction(): String? {
|
||||
|
||||
+1
-2
@@ -17,7 +17,6 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.overriddenTreeAsSequence
|
||||
import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor
|
||||
import org.jetbrains.kotlin.types.typeUtil.contains
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.cast
|
||||
|
||||
class JvmIdSignatureDescriptor(mangler: KotlinMangler.DescriptorMangler) : IdSignatureDescriptor(mangler) {
|
||||
|
||||
@@ -86,7 +85,7 @@ class JvmIdSignatureDescriptor(mangler: KotlinMangler.DescriptorMangler) : IdSig
|
||||
}.toList()
|
||||
if (capturingOverrides.isNotEmpty()) {
|
||||
overridden = capturingOverrides.sortedBy {
|
||||
it.containingDeclaration.cast<ClassDescriptor>().fqNameUnsafe.asString()
|
||||
(it.containingDeclaration as ClassDescriptor).fqNameUnsafe.asString()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user