JVM: refactor JvmDefaultMode, remove/rename some entries
- remove ENABLE/COMPATIBILITY because they can no longer be used - remove forAllMethodsWithBody because its behavior is now equivalent to isEnabled - inline isCompatibility - inline DEFAULT - rename ALL_INCOMPATIBLE -> ALL
This commit is contained in:
committed by
Space Team
parent
6219806ab9
commit
28797a31b4
+8
-6
@@ -19,7 +19,10 @@ import org.jetbrains.kotlin.ir.expressions.IrCall
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.IrFunctionReference
|
||||
import org.jetbrains.kotlin.ir.expressions.IrReturn
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.*
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrFunctionReferenceImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrGetValueImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrReturnImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.types.defaultType
|
||||
import org.jetbrains.kotlin.ir.util.functions
|
||||
@@ -65,8 +68,8 @@ internal class InterfaceLowering(val context: JvmBackendContext) : IrElementTran
|
||||
private fun handleInterface(irClass: IrClass) {
|
||||
val jvmDefaultMode = context.config.jvmDefaultMode
|
||||
val isCompatibilityMode =
|
||||
(jvmDefaultMode.isCompatibility && !irClass.hasJvmDefaultNoCompatibilityAnnotation()) ||
|
||||
(jvmDefaultMode == JvmDefaultMode.ALL_INCOMPATIBLE && irClass.hasJvmDefaultWithCompatibilityAnnotation())
|
||||
(jvmDefaultMode == JvmDefaultMode.ALL_COMPATIBILITY && !irClass.hasJvmDefaultNoCompatibilityAnnotation()) ||
|
||||
(jvmDefaultMode == JvmDefaultMode.ALL && irClass.hasJvmDefaultWithCompatibilityAnnotation())
|
||||
// There are 6 cases for functions on interfaces:
|
||||
for (function in irClass.functions) {
|
||||
when {
|
||||
@@ -130,8 +133,7 @@ internal class InterfaceLowering(val context: JvmBackendContext) : IrElementTran
|
||||
|| function.origin == IrDeclarationOrigin.FUNCTION_FOR_DEFAULT_PARAMETER
|
||||
|| function.origin == JvmLoweredDeclarationOrigin.SYNTHETIC_METHOD_FOR_PROPERTY_OR_TYPEALIAS_ANNOTATIONS)) ||
|
||||
(function.origin == JvmLoweredDeclarationOrigin.SYNTHETIC_METHOD_FOR_PROPERTY_OR_TYPEALIAS_ANNOTATIONS &&
|
||||
(isCompatibilityMode || jvmDefaultMode == JvmDefaultMode.ENABLE) &&
|
||||
function.isCompiledToJvmDefault(jvmDefaultMode)) -> {
|
||||
isCompatibilityMode && function.isCompiledToJvmDefault(jvmDefaultMode)) -> {
|
||||
if (function.origin == JvmLoweredDeclarationOrigin.INLINE_LAMBDA) {
|
||||
//move as is
|
||||
val defaultImplsClass = context.cachedDeclarations.getDefaultImplsClass(irClass)
|
||||
@@ -177,7 +179,7 @@ internal class InterfaceLowering(val context: JvmBackendContext) : IrElementTran
|
||||
|
||||
// Move $$delegatedProperties array and $assertionsDisabled field
|
||||
for (field in irClass.declarations.filterIsInstance<IrField>()) {
|
||||
if ((jvmDefaultMode.forAllMethodsWithBody || field.origin != JvmLoweredDeclarationOrigin.GENERATED_PROPERTY_REFERENCE) &&
|
||||
if ((jvmDefaultMode.isEnabled || field.origin != JvmLoweredDeclarationOrigin.GENERATED_PROPERTY_REFERENCE) &&
|
||||
field.origin != JvmLoweredDeclarationOrigin.GENERATED_ASSERTION_ENABLED_FIELD
|
||||
)
|
||||
continue
|
||||
|
||||
+2
-1
@@ -218,7 +218,8 @@ internal class PropertyReferenceLowering(val context: JvmBackendContext) : IrEle
|
||||
isFinal = true
|
||||
isStatic = true
|
||||
visibility =
|
||||
if (irClass.isInterface && context.config.jvmDefaultMode.forAllMethodsWithBody) DescriptorVisibilities.PUBLIC else JavaDescriptorVisibilities.PACKAGE_VISIBILITY
|
||||
if (irClass.isInterface && context.config.jvmDefaultMode.isEnabled) DescriptorVisibilities.PUBLIC
|
||||
else JavaDescriptorVisibilities.PACKAGE_VISIBILITY
|
||||
}
|
||||
|
||||
val localProperties = mutableListOf<IrLocalDelegatedPropertySymbol>()
|
||||
|
||||
@@ -98,7 +98,7 @@ fun IrSimpleFunction.isCompiledToJvmDefault(jvmDefaultMode: JvmDefaultMode): Boo
|
||||
}
|
||||
is IrMaybeDeserializedClass -> return klass.isNewPlaceForBodyGeneration
|
||||
}
|
||||
return jvmDefaultMode.forAllMethodsWithBody
|
||||
return jvmDefaultMode.isEnabled
|
||||
}
|
||||
|
||||
fun IrFunction.hasJvmDefault(): Boolean = propertyIfAccessor.hasAnnotation(JVM_DEFAULT_FQ_NAME)
|
||||
|
||||
+2
-5
@@ -12,7 +12,6 @@ import org.jetbrains.kotlin.codegen.binding.CodegenBinding
|
||||
import org.jetbrains.kotlin.codegen.createFreeFakeLambdaDescriptor
|
||||
import org.jetbrains.kotlin.codegen.serialization.JvmSerializationBindings
|
||||
import org.jetbrains.kotlin.codegen.serialization.JvmSerializerExtension
|
||||
import org.jetbrains.kotlin.config.languageVersionSettings
|
||||
import org.jetbrains.kotlin.ir.declarations.DescriptorMetadataSource
|
||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
|
||||
@@ -59,10 +58,8 @@ class DescriptorMetadataSerializer(
|
||||
context.state.bindingTrace.record(
|
||||
CodegenBinding.DELEGATED_PROPERTIES_WITH_METADATA,
|
||||
// key for local delegated properties metadata in interfaces depends on jvmDefaultMode
|
||||
if (irClass.isInterface && !context.config.jvmDefaultMode.forAllMethodsWithBody) context.defaultTypeMapper.mapClass(
|
||||
context.cachedDeclarations.getDefaultImplsClass(
|
||||
irClass
|
||||
)
|
||||
if (irClass.isInterface && !context.config.jvmDefaultMode.isEnabled) context.defaultTypeMapper.mapClass(
|
||||
context.cachedDeclarations.getDefaultImplsClass(irClass)
|
||||
) else type,
|
||||
localDelegatedProperties.mapNotNull { (it.owner.metadata as? DescriptorMetadataSource.LocalDelegatedProperty)?.descriptor }
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user