From 7cf6c70fbf71fdff235944a2928b06cebd97e2b8 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Mon, 9 Apr 2018 15:24:46 +0300 Subject: [PATCH] Use NoScopeRecordCliBindingTrace as default trace in GenerationUtils NB we use 'Intrinsics.areEqual(Double, Double)' and 'Intrinsics.areEqual(Float, Float)', because right now we take nullability from the inferred type of the expression (which is 'Any?' in the test cases). We should probably reconsider this in case of more exact information available from the data flow analysis, e.g., in case of fun test(x: Any?) = x is Serializable && x is Double? && x == 0.0 We statically know that 'x' is not null in 'x == 0.0' (although it's neither nullability of it's numeric type 'Double?' nor the nullability of the inferred type 'Any?'). There might be some edge effects in the performance related to byte code size and preventive unboxing and so on. --- .../android/tests/CodegenTestsOnAndroidGenerator.kt | 8 +------- .../codegen/bytecodeText/ieee754/smartCastsForDouble.kt | 5 ++--- .../codegen/bytecodeText/ieee754/smartCastsForDouble10.kt | 3 ++- .../codegen/bytecodeText/ieee754/smartCastsForFloat.kt | 5 ++--- .../codegen/bytecodeText/ieee754/smartCastsForFloat10.kt | 3 ++- compiler/testData/codegen/bytecodeText/ieee754/when.kt | 1 + compiler/testData/codegen/bytecodeText/ieee754/when10.kt | 3 ++- .../codegen/bytecodeText/ieee754/whenNullableSmartCast.kt | 1 + .../bytecodeText/ieee754/whenNullableSmartCast10.kt | 3 ++- .../tests/org/jetbrains/kotlin/codegen/GenerationUtils.kt | 6 +++--- 10 files changed, 18 insertions(+), 20 deletions(-) diff --git a/compiler/android-tests/tests/org/jetbrains/kotlin/android/tests/CodegenTestsOnAndroidGenerator.kt b/compiler/android-tests/tests/org/jetbrains/kotlin/android/tests/CodegenTestsOnAndroidGenerator.kt index 26f0520fa2d..c5491a2c388 100644 --- a/compiler/android-tests/tests/org/jetbrains/kotlin/android/tests/CodegenTestsOnAndroidGenerator.kt +++ b/compiler/android-tests/tests/org/jetbrains/kotlin/android/tests/CodegenTestsOnAndroidGenerator.kt @@ -22,10 +22,8 @@ import com.intellij.openapi.util.io.FileUtil import com.intellij.openapi.util.io.FileUtilRt import com.intellij.openapi.util.text.StringUtil import org.jetbrains.kotlin.cli.common.output.outputUtils.writeAllTo -import org.jetbrains.kotlin.cli.jvm.compiler.CliLightClassGenerationSupport import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment -import org.jetbrains.kotlin.codegen.ClassBuilderFactories import org.jetbrains.kotlin.codegen.CodegenTestCase import org.jetbrains.kotlin.codegen.CodegenTestFiles import org.jetbrains.kotlin.codegen.GenerationUtils @@ -171,11 +169,7 @@ class CodegenTestsOnAndroidGenerator private constructor(private val pathManager println("Generating ${filesToCompile.size} files into ${outputDir.name}, configuration: '${environment.configuration}'...") - val outputFiles = GenerationUtils.compileFiles( - filesToCompile, - environment, - trace = CliLightClassGenerationSupport.NoScopeRecordCliBindingTrace() - ).run { destroy(); factory } + val outputFiles = GenerationUtils.compileFiles(filesToCompile, environment).run { destroy(); factory } if (!outputDir.exists()) { outputDir.mkdirs() diff --git a/compiler/testData/codegen/bytecodeText/ieee754/smartCastsForDouble.kt b/compiler/testData/codegen/bytecodeText/ieee754/smartCastsForDouble.kt index 91a02c0b536..e279293dd8e 100644 --- a/compiler/testData/codegen/bytecodeText/ieee754/smartCastsForDouble.kt +++ b/compiler/testData/codegen/bytecodeText/ieee754/smartCastsForDouble.kt @@ -1,3 +1,4 @@ +// !LANGUAGE: +ProperIeee754Comparisons fun equals5(a: Any?, b: Any?) = if (a is Double && b is Double?) a == b else null!! fun equals6(a: Any?, b: Any?) = if (a is Double? && b is Double) a == b else null!! @@ -17,7 +18,5 @@ fun box(): String { return "OK" } -// 1 areEqual \(Ljava/lang/Double;Ljava/lang/Double;\)Z -// 1 areEqual \(DLjava/lang/Double;\)Z -// 1 areEqual \(Ljava/lang/Double;D\)Z +// 3 areEqual \(Ljava/lang/Double;Ljava/lang/Double;\)Z // 3 areEqual diff --git a/compiler/testData/codegen/bytecodeText/ieee754/smartCastsForDouble10.kt b/compiler/testData/codegen/bytecodeText/ieee754/smartCastsForDouble10.kt index ef22c8e335a..ff96a3d644b 100644 --- a/compiler/testData/codegen/bytecodeText/ieee754/smartCastsForDouble10.kt +++ b/compiler/testData/codegen/bytecodeText/ieee754/smartCastsForDouble10.kt @@ -19,4 +19,5 @@ fun box(): String { return "OK" } -// 0 areEqual \ No newline at end of file +// 3 areEqual \(Ljava/lang/Object;Ljava/lang/Object;\)Z +// 3 areEqual \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeText/ieee754/smartCastsForFloat.kt b/compiler/testData/codegen/bytecodeText/ieee754/smartCastsForFloat.kt index 89832229136..526f626e3f3 100644 --- a/compiler/testData/codegen/bytecodeText/ieee754/smartCastsForFloat.kt +++ b/compiler/testData/codegen/bytecodeText/ieee754/smartCastsForFloat.kt @@ -1,3 +1,4 @@ +// !LANGUAGE: +ProperIeee754Comparisons fun equals5(a: Any?, b: Any?) = if (a is Float && b is Float?) a == b else null!! fun equals6(a: Any?, b: Any?) = if (a is Float? && b is Float) a == b else null!! @@ -17,7 +18,5 @@ fun box(): String { return "OK" } -// 1 areEqual \(Ljava/lang/Float;Ljava/lang/Float;\)Z -// 1 areEqual \(FLjava/lang/Float;\)Z -// 1 areEqual \(Ljava/lang/Float;F\)Z +// 3 areEqual \(Ljava/lang/Float;Ljava/lang/Float;\)Z // 3 areEqual diff --git a/compiler/testData/codegen/bytecodeText/ieee754/smartCastsForFloat10.kt b/compiler/testData/codegen/bytecodeText/ieee754/smartCastsForFloat10.kt index 7758e877b83..7c46cfa3e38 100644 --- a/compiler/testData/codegen/bytecodeText/ieee754/smartCastsForFloat10.kt +++ b/compiler/testData/codegen/bytecodeText/ieee754/smartCastsForFloat10.kt @@ -19,4 +19,5 @@ fun box(): String { return "OK" } -// 0 areEqual \ No newline at end of file +// 3 areEqual \(Ljava/lang/Object;Ljava/lang/Object;\)Z +// 3 areEqual \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeText/ieee754/when.kt b/compiler/testData/codegen/bytecodeText/ieee754/when.kt index 1c1491e4cc6..c71e19d05dc 100644 --- a/compiler/testData/codegen/bytecodeText/ieee754/when.kt +++ b/compiler/testData/codegen/bytecodeText/ieee754/when.kt @@ -1,3 +1,4 @@ +// !LANGUAGE: +ProperIeee754Comparisons fun box(): String { val plusZero: Any = 0.0 val minusZero: Any = -0.0 diff --git a/compiler/testData/codegen/bytecodeText/ieee754/when10.kt b/compiler/testData/codegen/bytecodeText/ieee754/when10.kt index 007dd5dd698..34a589e9fd6 100644 --- a/compiler/testData/codegen/bytecodeText/ieee754/when10.kt +++ b/compiler/testData/codegen/bytecodeText/ieee754/when10.kt @@ -28,4 +28,5 @@ fun box(): String { return "OK" } -// 0 areEqual \ No newline at end of file +// 4 areEqual \(Ljava/lang/Object;Ljava/lang/Object;\)Z +// 4 areEqual \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeText/ieee754/whenNullableSmartCast.kt b/compiler/testData/codegen/bytecodeText/ieee754/whenNullableSmartCast.kt index 7f02248e417..6f9f7c75eea 100644 --- a/compiler/testData/codegen/bytecodeText/ieee754/whenNullableSmartCast.kt +++ b/compiler/testData/codegen/bytecodeText/ieee754/whenNullableSmartCast.kt @@ -1,3 +1,4 @@ +// !LANGUAGE: +ProperIeee754Comparisons fun box(): String { val nullValue: Any? = null val nullDouble: Double? = null diff --git a/compiler/testData/codegen/bytecodeText/ieee754/whenNullableSmartCast10.kt b/compiler/testData/codegen/bytecodeText/ieee754/whenNullableSmartCast10.kt index b1b38fdc643..678021ae10a 100644 --- a/compiler/testData/codegen/bytecodeText/ieee754/whenNullableSmartCast10.kt +++ b/compiler/testData/codegen/bytecodeText/ieee754/whenNullableSmartCast10.kt @@ -26,4 +26,5 @@ fun box(): String { } return "OK" } -// 0 areEqual +// 4 areEqual \(Ljava/lang/Object;Ljava/lang/Object;\)Z +// 4 areEqual diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/GenerationUtils.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/GenerationUtils.kt index adebfa7c20b..9b0de8b49a5 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/GenerationUtils.kt +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/GenerationUtils.kt @@ -19,8 +19,8 @@ package org.jetbrains.kotlin.codegen import com.intellij.psi.search.GlobalSearchScope import org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory import org.jetbrains.kotlin.cli.common.output.outputUtils.writeAllTo -import org.jetbrains.kotlin.cli.jvm.compiler.CliBindingTrace import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment +import org.jetbrains.kotlin.cli.jvm.compiler.NoScopeRecordCliBindingTrace import org.jetbrains.kotlin.codegen.state.GenerationState import org.jetbrains.kotlin.config.CompilerConfiguration import org.jetbrains.kotlin.config.JVMConfigurationKeys @@ -48,7 +48,7 @@ object GenerationUtils { files: List, environment: KotlinCoreEnvironment, classBuilderFactory: ClassBuilderFactory = ClassBuilderFactories.TEST, - trace: BindingTrace = CliBindingTrace() + trace: BindingTrace = NoScopeRecordCliBindingTrace() ): GenerationState = compileFiles(files, environment.configuration, classBuilderFactory, environment::createPackagePartProvider, trace) @@ -59,7 +59,7 @@ object GenerationUtils { configuration: CompilerConfiguration, classBuilderFactory: ClassBuilderFactory, packagePartProvider: (GlobalSearchScope) -> PackagePartProvider, - trace: BindingTrace = CliBindingTrace() + trace: BindingTrace = NoScopeRecordCliBindingTrace() ): GenerationState { val analysisResult = JvmResolveUtil.analyzeAndCheckForErrors(files.first().project, files, configuration, packagePartProvider, trace)