Remove -Xnormalize-constructor-calls

Constructor call normalization is enabled by default since 1.3.
This commit is contained in:
Alexander Udalov
2021-09-02 02:09:18 +02:00
parent cc3ad73436
commit 1864716c83
36 changed files with 83 additions and 400 deletions
@@ -127,7 +127,6 @@ public class FunctionCodegen {
CoroutineCodegenUtilKt.<FunctionDescriptor>unwrapInitialDescriptorForSuspendFunction(functionDescriptor),
function,
v.getThisName(),
state.getConstructorCallNormalizationMode(),
this
);
} else {
@@ -160,8 +160,6 @@ class CoroutineCodegenForLambda private constructor(
) {
private val builtIns = funDescriptor.builtIns
private val constructorCallNormalizationMode = outerExpressionCodegen.state.constructorCallNormalizationMode
private val erasedInvokeFunction by lazy {
getErasedInvokeFunction(funDescriptor).createCustomCopy { setModality(Modality.FINAL) }
}
@@ -524,7 +522,6 @@ class CoroutineCodegenForLambda private constructor(
containingClassInternalName = v.thisName,
obtainClassBuilderForCoroutineState = { v },
isForNamedFunction = false,
shouldPreserveClassInitialization = constructorCallNormalizationMode.shouldPreserveClassInitialization,
disableTailCallOptimizationForFunctionReturningUnit = false,
reportSuspensionPointInsideMonitor = { reportSuspensionPointInsideMonitor(element, state, it) },
lineNumber = CodegenUtil.getLineNumberForElement(element, false) ?: 0,
@@ -12,7 +12,10 @@ import org.jetbrains.kotlin.codegen.optimization.fixStack.FixStackMethodTransfor
import org.jetbrains.kotlin.resolve.jvm.AsmTypes
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin
import org.jetbrains.kotlin.utils.sure
import org.jetbrains.org.objectweb.asm.*
import org.jetbrains.org.objectweb.asm.Label
import org.jetbrains.org.objectweb.asm.MethodVisitor
import org.jetbrains.org.objectweb.asm.Opcodes
import org.jetbrains.org.objectweb.asm.Type
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
import org.jetbrains.org.objectweb.asm.tree.*
import org.jetbrains.org.objectweb.asm.tree.analysis.BasicValue
@@ -43,7 +46,6 @@ class CoroutineTransformerMethodVisitor(
private val containingClassInternalName: String,
obtainClassBuilderForCoroutineState: () -> ClassBuilder,
private val isForNamedFunction: Boolean,
private val shouldPreserveClassInitialization: Boolean,
// Since tail-call optimization of functions with Unit return type relies on ability of call-site to recognize them,
// in order to ignore return value and push Unit, when we cannot ensure this ability, for example, when the function overrides function,
// returning Any, we need to disable tail-call optimization for these functions.
@@ -121,7 +123,7 @@ class CoroutineTransformerMethodVisitor(
// Actual max stack might be increased during the previous phases
methodNode.updateMaxStack()
UninitializedStoresProcessor(methodNode, shouldPreserveClassInitialization).run()
UninitializedStoresProcessor(methodNode).run()
val spilledToVariableMapping = spillVariables(suspensionPoints, methodNode)
@@ -13,7 +13,6 @@ import org.jetbrains.kotlin.codegen.inline.coroutines.FOR_INLINE_SUFFIX
import org.jetbrains.kotlin.codegen.inline.preprocessSuspendMarkers
import org.jetbrains.kotlin.codegen.state.GenerationState
import org.jetbrains.kotlin.config.JVMConfigurationKeys
import org.jetbrains.kotlin.config.JVMConstructorCallNormalizationMode
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.config.languageVersionSettings
import org.jetbrains.kotlin.descriptors.ClassDescriptor
@@ -37,7 +36,6 @@ class SuspendFunctionGenerationStrategy(
private val originalSuspendDescriptor: FunctionDescriptor,
private val declaration: KtFunction,
private val containingClassInternalName: String,
private val constructorCallNormalizationMode: JVMConstructorCallNormalizationMode,
private val functionCodegen: FunctionCodegen
) : FunctionGenerationStrategy.CodegenBased(state) {
@@ -88,7 +86,6 @@ class SuspendFunctionGenerationStrategy(
return CoroutineTransformerMethodVisitor(
mv, access, name, desc, null, null, containingClassInternalName, this::classBuilderForCoroutineState,
isForNamedFunction = true,
shouldPreserveClassInitialization = constructorCallNormalizationMode.shouldPreserveClassInitialization,
disableTailCallOptimizationForFunctionReturningUnit = originalSuspendDescriptor.returnType?.isUnit() == true &&
originalSuspendDescriptor.overriddenDescriptors.isNotEmpty() &&
!originalSuspendDescriptor.allOverriddenFunctionsReturnUnit(),
@@ -72,10 +72,7 @@ import kotlin.math.max
* - generate NEW/DUP
* - restore constructor arguments
*/
class UninitializedStoresProcessor(
private val methodNode: MethodNode,
private val shouldPreserveClassInitialization: Boolean
) {
class UninitializedStoresProcessor(private val methodNode: MethodNode) {
// <init> method is "special", because it will invoke <init> from this class or from a base class for #0
//
// <clinit> method is "special", because <clinit> for singleton objects is generated as:
@@ -107,22 +104,7 @@ class UninitializedStoresProcessor(
methodNode.instructions.run {
removeAll(removableUsages)
if (shouldPreserveClassInitialization) {
// Replace 'NEW C' instruction with "manual" initialization of class 'C':
// LDC [typeName for C]
// INVOKESTATIC java/lang/Class.forName (Ljava/lang/String;)Ljava/lang/Class;
// POP
val typeNameForClass = newInsn.desc.replace('/', '.')
insertBefore(newInsn, LdcInsnNode(typeNameForClass))
insertBefore(
newInsn,
MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/Class", "forName", "(Ljava/lang/String;)Ljava/lang/Class;", false)
)
set(newInsn, InsnNode(Opcodes.POP))
} else {
remove(newInsn)
}
remove(newInsn)
}
val indexOfConstructorArgumentFromTopOfStack = Type.getArgumentTypes((insn as MethodInsnNode).desc).size
@@ -87,7 +87,6 @@ class CoroutineTransformer(
containingClassInternalName = classBuilder.thisName,
obtainClassBuilderForCoroutineState = { classBuilder },
isForNamedFunction = false,
shouldPreserveClassInitialization = state.constructorCallNormalizationMode.shouldPreserveClassInitialization,
disableTailCallOptimizationForFunctionReturningUnit = false,
reportSuspensionPointInsideMonitor = { sourceCompilerForInline.reportSuspensionPointInsideMonitor(it) },
// TODO: this linenumbers might not be correct and since they are used only for step-over, check them.
@@ -121,7 +120,6 @@ class CoroutineTransformer(
containingClassInternalName = classBuilder.thisName,
obtainClassBuilderForCoroutineState = { (inliningContext as RegeneratedClassContext).continuationBuilders[continuationClassName]!! },
isForNamedFunction = true,
shouldPreserveClassInitialization = state.constructorCallNormalizationMode.shouldPreserveClassInitialization,
disableTailCallOptimizationForFunctionReturningUnit = disableTailCallOptimization,
reportSuspensionPointInsideMonitor = { sourceCompilerForInline.reportSuspensionPointInsideMonitor(it) },
lineNumber = inliningContext.callSiteInfo.lineNumber,
@@ -17,6 +17,7 @@
package org.jetbrains.kotlin.codegen.optimization
import org.jetbrains.kotlin.codegen.TransformationMethodVisitor
import org.jetbrains.kotlin.codegen.coroutines.UninitializedStoresProcessor
import org.jetbrains.kotlin.codegen.inline.InplaceArgumentsMethodTransformer
import org.jetbrains.kotlin.codegen.optimization.boxing.PopBackwardPropagationTransformer
import org.jetbrains.kotlin.codegen.optimization.boxing.RedundantBoxingMethodTransformer
@@ -38,9 +39,6 @@ class OptimizationMethodVisitor(
signature: String?,
exceptions: Array<String>?
) : TransformationMethodVisitor(delegate, access, name, desc, signature, exceptions) {
private val constructorCallNormalizationTransformer =
UninitializedStoresMethodTransformer(generationState.constructorCallNormalizationMode)
val normalizationMethodTransformer = CompositeMethodTransformer(
InplaceArgumentsMethodTransformer(),
FixStackWithLabelNormalizationMethodTransformer(),
@@ -65,7 +63,7 @@ class OptimizationMethodVisitor(
override fun performTransformations(methodNode: MethodNode) {
normalizationMethodTransformer.transform("fake", methodNode)
constructorCallNormalizationTransformer.transform("fake", methodNode)
UninitializedStoresProcessor(methodNode).run()
if (canBeOptimized(methodNode) && !generationState.disableOptimization) {
optimizationTransformer.transform("fake", methodNode)
@@ -1,34 +0,0 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.codegen.optimization
import org.jetbrains.kotlin.codegen.coroutines.UninitializedStoresProcessor
import org.jetbrains.kotlin.codegen.optimization.transformer.MethodTransformer
import org.jetbrains.kotlin.config.JVMConstructorCallNormalizationMode
import org.jetbrains.org.objectweb.asm.tree.MethodNode
class UninitializedStoresMethodTransformer(
private val mode: JVMConstructorCallNormalizationMode
) : MethodTransformer() {
override fun transform(internalClassName: String, methodNode: MethodNode) {
if (mode.isEnabled) {
UninitializedStoresProcessor(methodNode, mode.shouldPreserveClassInitialization).run()
}
}
}
@@ -312,14 +312,6 @@ class GenerationState private constructor(
val shouldInlineConstVals = languageVersionSettings.supportsFeature(LanguageFeature.InlineConstVals)
val constructorCallNormalizationMode =
configuration.get(JVMConfigurationKeys.CONSTRUCTOR_CALL_NORMALIZATION_MODE) ?: run {
if (languageVersionSettings.supportsFeature(LanguageFeature.NormalizeConstructorCalls))
JVMConstructorCallNormalizationMode.ENABLE
else
JVMConstructorCallNormalizationMode.DISABLE
}
val jvmDefaultMode = languageVersionSettings.getFlag(JvmAnalysisFlags.jvmDefaultMode)
val disableOptimization = configuration.get(JVMConfigurationKeys.DISABLE_OPTIMIZATION, false)
@@ -23,7 +23,8 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
value = "-classpath",
shortName = "-cp",
valueDescription = "<path>",
description = "List of directories and JAR/ZIP archives to search for user class files")
description = "List of directories and JAR/ZIP archives to search for user class files"
)
var classpath: String? by NullableStringFreezableVar(null)
@DeprecatedOption(removeAfter = "1.5", level = DeprecationLevel.ERROR)
@@ -50,7 +51,10 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
@DeprecatedOption(removeAfter = "1.5", level = DeprecationLevel.ERROR)
@GradleOption(DefaultValues.BooleanTrueDefault::class)
@Argument(value = "-no-stdlib", description = "Don't automatically include the Kotlin/JVM stdlib and Kotlin reflection into the classpath")
@Argument(
value = "-no-stdlib",
description = "Don't automatically include the Kotlin/JVM stdlib and Kotlin reflection into the classpath"
)
var noStdlib: Boolean by FreezableVar(false)
@DeprecatedOption(removeAfter = "1.5", level = DeprecationLevel.ERROR)
@@ -168,15 +172,6 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
@Argument(value = "-Xno-optimize", description = "Disable optimizations")
var noOptimize: Boolean by FreezableVar(false)
@Argument(
value = "-Xnormalize-constructor-calls",
valueDescription = "{disable|enable}",
description = "Normalize constructor calls (disable: don't normalize; enable: normalize),\n" +
"default is 'disable' in language version 1.2 and below,\n" +
"'enable' since language version 1.3"
)
var constructorCallNormalizationMode: String? by NullableStringFreezableVar(null)
@Argument(
value = "-Xassertions", valueDescription = "{always-enable|always-disable|jvm|legacy}",
description = "Assert calls behaviour\n" +
@@ -264,19 +264,6 @@ fun CompilerConfiguration.configureAdvancedJvmOptions(arguments: K2JVMCompilerAr
put(JVMConfigurationKeys.VALIDATE_IR, arguments.validateIr)
put(JVMConfigurationKeys.VALIDATE_BYTECODE, arguments.validateBytecode)
if (!JVMConstructorCallNormalizationMode.isSupportedValue(arguments.constructorCallNormalizationMode)) {
messageCollector.report(
ERROR,
"Unknown constructor call normalization mode: ${arguments.constructorCallNormalizationMode}, " +
"supported modes: ${JVMConstructorCallNormalizationMode.values().map { it.description }}"
)
}
val constructorCallNormalizationMode = JVMConstructorCallNormalizationMode.fromStringOrNull(arguments.constructorCallNormalizationMode)
if (constructorCallNormalizationMode != null) {
put(JVMConfigurationKeys.CONSTRUCTOR_CALL_NORMALIZATION_MODE, constructorCallNormalizationMode)
}
val assertionsMode =
JVMAssertionsMode.fromStringOrNull(arguments.assertionsMode)
if (assertionsMode == null) {
@@ -54,8 +54,6 @@ public class JVMConfigurationKeys {
CompilerConfigurationKey.create("disable not-null parameter assertions");
public static final CompilerConfigurationKey<JVMAssertionsMode> ASSERTIONS_MODE =
CompilerConfigurationKey.create("assertions mode");
public static final CompilerConfigurationKey<JVMConstructorCallNormalizationMode> CONSTRUCTOR_CALL_NORMALIZATION_MODE =
CompilerConfigurationKey.create("constructor call normalization mode");
public static final CompilerConfigurationKey<Boolean> NO_EXCEPTION_ON_EXPLICIT_EQUALS_FOR_BOXED_NULL =
CompilerConfigurationKey.create("do not throw NPE on explicit 'equals' call for null receiver of platform boxed primitive type");
public static final CompilerConfigurationKey<Boolean> DISABLE_OPTIMIZATION =
@@ -1,38 +0,0 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.config
enum class JVMConstructorCallNormalizationMode(
val description: String,
val isEnabled: Boolean,
val shouldPreserveClassInitialization: Boolean
) {
DISABLE("disable", false, false),
ENABLE("enable", true, false),
PRESERVE_CLASS_INITIALIZATION("preserve-class-initialization", true, true)
;
companion object {
@JvmStatic
fun isSupportedValue(string: String?) =
string == null || values().any { it.description == string }
@JvmStatic
fun fromStringOrNull(string: String?) =
values().find { it.description == string }
}
}
@@ -7608,30 +7608,18 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/constructorCall/earlyReturnInConstructorArguments.kt");
}
@Test
@TestMetadata("inlineFunInConstructorCall.kt")
public void testInlineFunInConstructorCall() throws Exception {
runTest("compiler/testData/codegen/box/constructorCall/inlineFunInConstructorCall.kt");
}
@Test
@TestMetadata("inlineFunInConstructorCallEvaluationOrder.kt")
public void testInlineFunInConstructorCallEvaluationOrder() throws Exception {
runTest("compiler/testData/codegen/box/constructorCall/inlineFunInConstructorCallEvaluationOrder.kt");
}
@Test
@TestMetadata("inlineFunInConstructorCallWithDisabledNormalization.kt")
public void testInlineFunInConstructorCallWithDisabledNormalization() throws Exception {
runTest("compiler/testData/codegen/box/constructorCall/inlineFunInConstructorCallWithDisabledNormalization.kt");
}
@Test
@TestMetadata("inlineFunInConstructorCallWithEnabledNormalization.kt")
public void testInlineFunInConstructorCallWithEnabledNormalization() throws Exception {
runTest("compiler/testData/codegen/box/constructorCall/inlineFunInConstructorCallWithEnabledNormalization.kt");
}
@Test
@TestMetadata("inlineFunInConstructorCallWithStrictNormalization.kt")
public void testInlineFunInConstructorCallWithStrictNormalization() throws Exception {
runTest("compiler/testData/codegen/box/constructorCall/inlineFunInConstructorCallWithStrictNormalization.kt");
}
@Test
@TestMetadata("inlineFunInInnerClassConstructorCall.kt")
public void testInlineFunInInnerClassConstructorCall() throws Exception {
@@ -7645,21 +7633,15 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
}
@Test
@TestMetadata("loopInInlineFunInSuperConstructorCallWithEnabledNormalization.kt")
public void testLoopInInlineFunInSuperConstructorCallWithEnabledNormalization() throws Exception {
runTest("compiler/testData/codegen/box/constructorCall/loopInInlineFunInSuperConstructorCallWithEnabledNormalization.kt");
@TestMetadata("loopInInlineFun.kt")
public void testLoopInInlineFun() throws Exception {
runTest("compiler/testData/codegen/box/constructorCall/loopInInlineFun.kt");
}
@Test
@TestMetadata("loopInInlineFunInSuperConstructorCallWithEnabledNormalizationSince13.kt")
public void testLoopInInlineFunInSuperConstructorCallWithEnabledNormalizationSince13() throws Exception {
runTest("compiler/testData/codegen/box/constructorCall/loopInInlineFunInSuperConstructorCallWithEnabledNormalizationSince13.kt");
}
@Test
@TestMetadata("loopInInlineFunWithEnabledNormalization.kt")
public void testLoopInInlineFunWithEnabledNormalization() throws Exception {
runTest("compiler/testData/codegen/box/constructorCall/loopInInlineFunWithEnabledNormalization.kt");
@TestMetadata("loopInInlineFunInSuperConstructorCall.kt")
public void testLoopInInlineFunInSuperConstructorCall() throws Exception {
runTest("compiler/testData/codegen/box/constructorCall/loopInInlineFunInSuperConstructorCall.kt");
}
@Test
@@ -29,7 +29,10 @@ import org.jetbrains.kotlin.ir.expressions.*
import org.jetbrains.kotlin.ir.expressions.impl.IrErrorExpressionImpl
import org.jetbrains.kotlin.ir.types.*
import org.jetbrains.kotlin.ir.types.impl.makeTypeProjection
import org.jetbrains.kotlin.ir.util.*
import org.jetbrains.kotlin.ir.util.file
import org.jetbrains.kotlin.ir.util.functions
import org.jetbrains.kotlin.ir.util.isSuspend
import org.jetbrains.kotlin.ir.util.parentAsClass
import org.jetbrains.kotlin.psi.KtElement
import org.jetbrains.kotlin.types.Variance
import org.jetbrains.org.objectweb.asm.MethodVisitor
@@ -70,7 +73,6 @@ internal fun MethodNode.acceptWithStateMachine(
containingClassInternalName = classCodegen.type.internalName,
obtainClassBuilderForCoroutineState = obtainContinuationClassBuilder,
isForNamedFunction = irFunction.isSuspend,
shouldPreserveClassInitialization = state.constructorCallNormalizationMode.shouldPreserveClassInitialization,
disableTailCallOptimizationForFunctionReturningUnit = irFunction.isSuspend && irFunction.suspendFunctionOriginal().let {
it.returnType.isUnit() && it.anyOfOverriddenFunctionsReturnsNonUnit()
},
-4
View File
@@ -18,10 +18,6 @@ where advanced options include:
default: legacy
-Xbuild-file=<path> Path to the .xml build file to compile
-Xcompile-java Reuse javac analysis and compile Java source files
-Xnormalize-constructor-calls={disable|enable}
Normalize constructor calls (disable: don't normalize; enable: normalize),
default is 'disable' in language version 1.2 and below,
'enable' since language version 1.3
-Xdump-declarations-to=<path> Path to JSON file to dump Java to Kotlin declaration mappings
-Xdefault-script-extension=<script filename extension>
Compile expressions and unrecognized scripts passed with the -script argument as scripts with given filename extension
@@ -1,4 +1,3 @@
// !LANGUAGE: -NormalizeConstructorCalls
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// FILE: test.kt
@@ -13,7 +12,7 @@ fun box(): String {
}
val result = log.toString()
if (result != "<clinit>ij<init>") return "Fail: '$result'"
if (result != "ij<clinit><init>") return "Fail: '$result'"
return "OK"
}
@@ -37,4 +36,4 @@ class Foo(i: Int, j: Int) {
log.append("<clinit>")
}
}
}
}
@@ -1,4 +1,3 @@
// !LANGUAGE: -NormalizeConstructorCalls
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// FILE: test.kt
@@ -14,7 +13,7 @@ fun box(): String {
}
val result = log.toString()
if (result != "<clinit>ij<init>") return "Fail: '$result'"
if (result != "ij<clinit><init>") return "Fail: '$result'"
return "OK"
}
@@ -38,4 +37,4 @@ class Foo(i: Int, j: Int) {
log.append("<clinit>")
}
}
}
}
@@ -1,4 +1,3 @@
// !LANGUAGE: -NormalizeConstructorCalls
// TARGET_BACKEND: JVM
// WITH_RUNTIME
inline fun ok(): String {
@@ -10,7 +9,7 @@ fun box(): String {
if (ok != "OK") return "Fail: $ok"
val r = log.toString()
if (r != "<clinit>;bar;<init>;foo;") return "Fail: '$r'"
if (r != "bar;<clinit>;<init>;foo;") return "Fail: '$r'"
return "OK"
}
@@ -1,6 +1,5 @@
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// CONSTRUCTOR_CALL_NORMALIZATION_MODE: enable
// FILE: test.kt
fun box(): String {
Foo(
@@ -1,4 +1,3 @@
// !LANGUAGE: -NormalizeConstructorCalls
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// FILE: test.kt
@@ -14,7 +13,7 @@ fun box(): String {
)
val result = log.toString()
if (result != "<clinit>ik<init>j<init>") return "Fail: '$result'"
if (result != "ik<clinit><init>j<init>") return "Fail: '$result'"
return "OK"
}
@@ -1,41 +0,0 @@
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// CONSTRUCTOR_CALL_NORMALIZATION_MODE: disable
// FILE: test.kt
fun box(): String {
Foo(
logged("i", 1.let { it }),
logged("j",
Foo(
logged("k", 2.let { it }),
null
)
)
)
val result = log.toString()
if (result != "<clinit>ik<init>j<init>") return "Fail: '$result'"
return "OK"
}
// FILE: util.kt
val log = StringBuilder()
fun <T> logged(msg: String, value: T): T {
log.append(msg)
return value
}
// FILE: Foo.kt
class Foo(i: Int, j: Foo?) {
init {
log.append("<init>")
}
companion object {
init {
log.append("<clinit>")
}
}
}
@@ -1,41 +0,0 @@
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// CONSTRUCTOR_CALL_NORMALIZATION_MODE: preserve-class-initialization
// FILE: test.kt
fun box(): String {
Foo(
logged("i", 1.let { it }),
logged("j",
Foo(
logged("k", 2.let { it }),
null
)
)
)
val result = log.toString()
if (result != "<clinit>ik<init>j<init>") return "Fail: '$result'"
return "OK"
}
// FILE: util.kt
val log = StringBuilder()
fun <T> logged(msg: String, value: T): T {
log.append(msg)
return value
}
// FILE: Foo.kt
class Foo(i: Int, j: Foo?) {
init {
log.append("<init>")
}
companion object {
init {
log.append("<clinit>")
}
}
}
@@ -1,4 +1,3 @@
// !LANGUAGE: -NormalizeConstructorCalls
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// FILE: test.kt
@@ -9,7 +8,7 @@ fun box(): String {
)
val result = log.toString()
if (result != "Foo.<clinit>;i;j;Foo.<init>;Inner.<init>;") return "Fail: '$result'"
if (result != "i;j;Foo.<clinit>;Foo.<init>;Inner.<init>;") return "Fail: '$result'"
return "OK"
}
@@ -41,4 +40,4 @@ class Outer {
log.append("Inner.<init>;")
}
}
}
}
@@ -1,4 +1,3 @@
// !LANGUAGE: -NormalizeConstructorCalls
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// FILE: test.kt
@@ -15,7 +14,7 @@ fun box(): String {
)
val result = log.toString()
if (result != "Foo.<clinit>;i;j;Foo.<init>;Local.<init>;") return "Fail: '$result'"
if (result != "i;j;Foo.<clinit>;Foo.<init>;Local.<init>;") return "Fail: '$result'"
return "OK"
}
@@ -1,6 +1,5 @@
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// CONSTRUCTOR_CALL_NORMALIZATION_MODE: enable
// FILE: test.kt
fun box(): String {
Foo(
@@ -1,4 +1,3 @@
// !LANGUAGE: +NormalizeConstructorCalls
// TARGET_BACKEND: JVM
// WITH_RUNTIME
open class A(val s: String)
@@ -11,4 +10,4 @@ inline fun test(crossinline z: () -> String): String {
fun box(): String {
return test { "OK" }
}
}
@@ -1,14 +0,0 @@
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// CONSTRUCTOR_CALL_NORMALIZATION_MODE: enable
open class A(val s: String)
inline fun test(crossinline z: () -> String): String {
return object : A(listOf(1).map { it.toString() }.joinToString()) {
val value = z()
}.value
}
fun box(): String {
return test { "OK" }
}
@@ -1,4 +1,3 @@
// !LANGUAGE: -NormalizeConstructorCalls
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// FILE: test.kt
@@ -17,7 +16,7 @@ fun box(): String {
}
val result = log.toString()
if (result != "<clinit>ij<init>") return "Fail: '$result'"
if (result != "ij<clinit><init>") return "Fail: '$result'"
return "OK"
}
@@ -41,4 +40,4 @@ class Foo(i: Int, j: Int) {
log.append("<clinit>")
}
}
}
}
@@ -1,4 +1,3 @@
// !LANGUAGE: -NormalizeConstructorCalls
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// FILE: test.kt
@@ -9,7 +8,7 @@ fun box(): String {
)
val result = log.toString()
if (result != "<clinit>ij<init>") return "Fail: '$result'"
if (result != "ij<clinit><init>") return "Fail: '$result'"
return "OK"
}
@@ -7536,30 +7536,18 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/constructorCall/earlyReturnInConstructorArguments.kt");
}
@Test
@TestMetadata("inlineFunInConstructorCall.kt")
public void testInlineFunInConstructorCall() throws Exception {
runTest("compiler/testData/codegen/box/constructorCall/inlineFunInConstructorCall.kt");
}
@Test
@TestMetadata("inlineFunInConstructorCallEvaluationOrder.kt")
public void testInlineFunInConstructorCallEvaluationOrder() throws Exception {
runTest("compiler/testData/codegen/box/constructorCall/inlineFunInConstructorCallEvaluationOrder.kt");
}
@Test
@TestMetadata("inlineFunInConstructorCallWithDisabledNormalization.kt")
public void testInlineFunInConstructorCallWithDisabledNormalization() throws Exception {
runTest("compiler/testData/codegen/box/constructorCall/inlineFunInConstructorCallWithDisabledNormalization.kt");
}
@Test
@TestMetadata("inlineFunInConstructorCallWithEnabledNormalization.kt")
public void testInlineFunInConstructorCallWithEnabledNormalization() throws Exception {
runTest("compiler/testData/codegen/box/constructorCall/inlineFunInConstructorCallWithEnabledNormalization.kt");
}
@Test
@TestMetadata("inlineFunInConstructorCallWithStrictNormalization.kt")
public void testInlineFunInConstructorCallWithStrictNormalization() throws Exception {
runTest("compiler/testData/codegen/box/constructorCall/inlineFunInConstructorCallWithStrictNormalization.kt");
}
@Test
@TestMetadata("inlineFunInInnerClassConstructorCall.kt")
public void testInlineFunInInnerClassConstructorCall() throws Exception {
@@ -7573,21 +7561,15 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
}
@Test
@TestMetadata("loopInInlineFunInSuperConstructorCallWithEnabledNormalization.kt")
public void testLoopInInlineFunInSuperConstructorCallWithEnabledNormalization() throws Exception {
runTest("compiler/testData/codegen/box/constructorCall/loopInInlineFunInSuperConstructorCallWithEnabledNormalization.kt");
@TestMetadata("loopInInlineFun.kt")
public void testLoopInInlineFun() throws Exception {
runTest("compiler/testData/codegen/box/constructorCall/loopInInlineFun.kt");
}
@Test
@TestMetadata("loopInInlineFunInSuperConstructorCallWithEnabledNormalizationSince13.kt")
public void testLoopInInlineFunInSuperConstructorCallWithEnabledNormalizationSince13() throws Exception {
runTest("compiler/testData/codegen/box/constructorCall/loopInInlineFunInSuperConstructorCallWithEnabledNormalizationSince13.kt");
}
@Test
@TestMetadata("loopInInlineFunWithEnabledNormalization.kt")
public void testLoopInInlineFunWithEnabledNormalization() throws Exception {
runTest("compiler/testData/codegen/box/constructorCall/loopInInlineFunWithEnabledNormalization.kt");
@TestMetadata("loopInInlineFunInSuperConstructorCall.kt")
public void testLoopInInlineFunInSuperConstructorCall() throws Exception {
runTest("compiler/testData/codegen/box/constructorCall/loopInInlineFunInSuperConstructorCall.kt");
}
@Test
@@ -7608,30 +7608,18 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/constructorCall/earlyReturnInConstructorArguments.kt");
}
@Test
@TestMetadata("inlineFunInConstructorCall.kt")
public void testInlineFunInConstructorCall() throws Exception {
runTest("compiler/testData/codegen/box/constructorCall/inlineFunInConstructorCall.kt");
}
@Test
@TestMetadata("inlineFunInConstructorCallEvaluationOrder.kt")
public void testInlineFunInConstructorCallEvaluationOrder() throws Exception {
runTest("compiler/testData/codegen/box/constructorCall/inlineFunInConstructorCallEvaluationOrder.kt");
}
@Test
@TestMetadata("inlineFunInConstructorCallWithDisabledNormalization.kt")
public void testInlineFunInConstructorCallWithDisabledNormalization() throws Exception {
runTest("compiler/testData/codegen/box/constructorCall/inlineFunInConstructorCallWithDisabledNormalization.kt");
}
@Test
@TestMetadata("inlineFunInConstructorCallWithEnabledNormalization.kt")
public void testInlineFunInConstructorCallWithEnabledNormalization() throws Exception {
runTest("compiler/testData/codegen/box/constructorCall/inlineFunInConstructorCallWithEnabledNormalization.kt");
}
@Test
@TestMetadata("inlineFunInConstructorCallWithStrictNormalization.kt")
public void testInlineFunInConstructorCallWithStrictNormalization() throws Exception {
runTest("compiler/testData/codegen/box/constructorCall/inlineFunInConstructorCallWithStrictNormalization.kt");
}
@Test
@TestMetadata("inlineFunInInnerClassConstructorCall.kt")
public void testInlineFunInInnerClassConstructorCall() throws Exception {
@@ -7645,21 +7633,15 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
}
@Test
@TestMetadata("loopInInlineFunInSuperConstructorCallWithEnabledNormalization.kt")
public void testLoopInInlineFunInSuperConstructorCallWithEnabledNormalization() throws Exception {
runTest("compiler/testData/codegen/box/constructorCall/loopInInlineFunInSuperConstructorCallWithEnabledNormalization.kt");
@TestMetadata("loopInInlineFun.kt")
public void testLoopInInlineFun() throws Exception {
runTest("compiler/testData/codegen/box/constructorCall/loopInInlineFun.kt");
}
@Test
@TestMetadata("loopInInlineFunInSuperConstructorCallWithEnabledNormalizationSince13.kt")
public void testLoopInInlineFunInSuperConstructorCallWithEnabledNormalizationSince13() throws Exception {
runTest("compiler/testData/codegen/box/constructorCall/loopInInlineFunInSuperConstructorCallWithEnabledNormalizationSince13.kt");
}
@Test
@TestMetadata("loopInInlineFunWithEnabledNormalization.kt")
public void testLoopInInlineFunWithEnabledNormalization() throws Exception {
runTest("compiler/testData/codegen/box/constructorCall/loopInInlineFunWithEnabledNormalization.kt");
@TestMetadata("loopInInlineFunInSuperConstructorCall.kt")
public void testLoopInInlineFunInSuperConstructorCall() throws Exception {
runTest("compiler/testData/codegen/box/constructorCall/loopInInlineFunInSuperConstructorCall.kt");
}
@Test
@@ -5,7 +5,10 @@
package org.jetbrains.kotlin.test.directives
import org.jetbrains.kotlin.config.*
import org.jetbrains.kotlin.config.JVMAssertionsMode
import org.jetbrains.kotlin.config.JvmClosureGenerationScheme
import org.jetbrains.kotlin.config.JvmStringConcat
import org.jetbrains.kotlin.config.JvmTarget
import org.jetbrains.kotlin.test.TestJavacVersion
import org.jetbrains.kotlin.test.TestJdkKind
import org.jetbrains.kotlin.test.directives.model.DirectiveApplicability
@@ -69,12 +72,6 @@ object JvmEnvironmentConfigurationDirectives : SimpleDirectivesContainer() {
additionalParser = JVMAssertionsMode.Companion::fromString
)
@Suppress("RemoveExplicitTypeArguments")
val CONSTRUCTOR_CALL_NORMALIZATION_MODE by enumDirective<JVMConstructorCallNormalizationMode>(
description = "Configure jvm constructor call normalization mode",
additionalParser = JVMConstructorCallNormalizationMode.Companion::fromStringOrNull
)
val SAM_CONVERSIONS by enumDirective(
description = "SAM conversion code generation scheme",
additionalParser = JvmClosureGenerationScheme.Companion::fromString
@@ -31,7 +31,6 @@ import org.jetbrains.kotlin.test.directives.JvmEnvironmentConfigurationDirective
import org.jetbrains.kotlin.test.directives.JvmEnvironmentConfigurationDirectives.ALL_JAVA_AS_BINARY
import org.jetbrains.kotlin.test.directives.JvmEnvironmentConfigurationDirectives.ASSERTIONS_MODE
import org.jetbrains.kotlin.test.directives.JvmEnvironmentConfigurationDirectives.COMPILE_JAVA_USING
import org.jetbrains.kotlin.test.directives.JvmEnvironmentConfigurationDirectives.CONSTRUCTOR_CALL_NORMALIZATION_MODE
import org.jetbrains.kotlin.test.directives.JvmEnvironmentConfigurationDirectives.INCLUDE_JAVA_AS_BINARY
import org.jetbrains.kotlin.test.directives.JvmEnvironmentConfigurationDirectives.JVM_TARGET
import org.jetbrains.kotlin.test.directives.JvmEnvironmentConfigurationDirectives.LAMBDAS
@@ -134,7 +133,6 @@ class JvmEnvironmentConfigurator(testServices: TestServices) : EnvironmentConfig
override fun DirectiveToConfigurationKeyExtractor.provideConfigurationKeys() {
register(STRING_CONCAT, JVMConfigurationKeys.STRING_CONCAT)
register(ASSERTIONS_MODE, JVMConfigurationKeys.ASSERTIONS_MODE)
register(CONSTRUCTOR_CALL_NORMALIZATION_MODE, JVMConfigurationKeys.CONSTRUCTOR_CALL_NORMALIZATION_MODE)
register(SAM_CONVERSIONS, JVMConfigurationKeys.SAM_CONVERSIONS)
register(LAMBDAS, JVMConfigurationKeys.LAMBDAS)
register(USE_OLD_INLINE_CLASSES_MANGLING_SCHEME, JVMConfigurationKeys.USE_OLD_INLINE_CLASSES_MANGLING_SCHEME)
@@ -25,11 +25,6 @@ private val patterns = buildList {
JVMConfigurationKeys.STRING_CONCAT,
JvmStringConcat.Companion::fromString
)
createPattern(
"CONSTRUCTOR_CALL_NORMALIZATION_MODE",
JVMConfigurationKeys.CONSTRUCTOR_CALL_NORMALIZATION_MODE,
JVMConstructorCallNormalizationMode.Companion::fromStringOrNull
)
createPattern(
"SAM_CONVERSIONS",
JVMConfigurationKeys.SAM_CONVERSIONS,
@@ -162,5 +157,3 @@ private fun tryApplyBooleanFlag(
assert(false) { "Expected [+|-][namespace.]configurationKey, got: $flag" }
}
}
@@ -5737,26 +5737,16 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/constructorCall/earlyReturnInConstructorArguments.kt");
}
@TestMetadata("inlineFunInConstructorCall.kt")
public void testInlineFunInConstructorCall() throws Exception {
runTest("compiler/testData/codegen/box/constructorCall/inlineFunInConstructorCall.kt");
}
@TestMetadata("inlineFunInConstructorCallEvaluationOrder.kt")
public void testInlineFunInConstructorCallEvaluationOrder() throws Exception {
runTest("compiler/testData/codegen/box/constructorCall/inlineFunInConstructorCallEvaluationOrder.kt");
}
@TestMetadata("inlineFunInConstructorCallWithDisabledNormalization.kt")
public void testInlineFunInConstructorCallWithDisabledNormalization() throws Exception {
runTest("compiler/testData/codegen/box/constructorCall/inlineFunInConstructorCallWithDisabledNormalization.kt");
}
@TestMetadata("inlineFunInConstructorCallWithEnabledNormalization.kt")
public void testInlineFunInConstructorCallWithEnabledNormalization() throws Exception {
runTest("compiler/testData/codegen/box/constructorCall/inlineFunInConstructorCallWithEnabledNormalization.kt");
}
@TestMetadata("inlineFunInConstructorCallWithStrictNormalization.kt")
public void testInlineFunInConstructorCallWithStrictNormalization() throws Exception {
runTest("compiler/testData/codegen/box/constructorCall/inlineFunInConstructorCallWithStrictNormalization.kt");
}
@TestMetadata("inlineFunInInnerClassConstructorCall.kt")
public void testInlineFunInInnerClassConstructorCall() throws Exception {
runTest("compiler/testData/codegen/box/constructorCall/inlineFunInInnerClassConstructorCall.kt");
@@ -5767,19 +5757,14 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/constructorCall/inlineFunInLocalClassConstructorCall.kt");
}
@TestMetadata("loopInInlineFunInSuperConstructorCallWithEnabledNormalization.kt")
public void testLoopInInlineFunInSuperConstructorCallWithEnabledNormalization() throws Exception {
runTest("compiler/testData/codegen/box/constructorCall/loopInInlineFunInSuperConstructorCallWithEnabledNormalization.kt");
@TestMetadata("loopInInlineFun.kt")
public void testLoopInInlineFun() throws Exception {
runTest("compiler/testData/codegen/box/constructorCall/loopInInlineFun.kt");
}
@TestMetadata("loopInInlineFunInSuperConstructorCallWithEnabledNormalizationSince13.kt")
public void testLoopInInlineFunInSuperConstructorCallWithEnabledNormalizationSince13() throws Exception {
runTest("compiler/testData/codegen/box/constructorCall/loopInInlineFunInSuperConstructorCallWithEnabledNormalizationSince13.kt");
}
@TestMetadata("loopInInlineFunWithEnabledNormalization.kt")
public void testLoopInInlineFunWithEnabledNormalization() throws Exception {
runTest("compiler/testData/codegen/box/constructorCall/loopInInlineFunWithEnabledNormalization.kt");
@TestMetadata("loopInInlineFunInSuperConstructorCall.kt")
public void testLoopInInlineFunInSuperConstructorCall() throws Exception {
runTest("compiler/testData/codegen/box/constructorCall/loopInInlineFunInSuperConstructorCall.kt");
}
@TestMetadata("nestedConstructorCallWithJumpOutInConstructorArguments.kt")