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.
This commit is contained in:
+1
-7
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -19,4 +19,5 @@ fun box(): String {
|
||||
return "OK"
|
||||
}
|
||||
|
||||
// 0 areEqual
|
||||
// 3 areEqual \(Ljava/lang/Object;Ljava/lang/Object;\)Z
|
||||
// 3 areEqual
|
||||
@@ -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
|
||||
|
||||
@@ -19,4 +19,5 @@ fun box(): String {
|
||||
return "OK"
|
||||
}
|
||||
|
||||
// 0 areEqual
|
||||
// 3 areEqual \(Ljava/lang/Object;Ljava/lang/Object;\)Z
|
||||
// 3 areEqual
|
||||
@@ -1,3 +1,4 @@
|
||||
// !LANGUAGE: +ProperIeee754Comparisons
|
||||
fun box(): String {
|
||||
val plusZero: Any = 0.0
|
||||
val minusZero: Any = -0.0
|
||||
|
||||
@@ -28,4 +28,5 @@ fun box(): String {
|
||||
return "OK"
|
||||
}
|
||||
|
||||
// 0 areEqual
|
||||
// 4 areEqual \(Ljava/lang/Object;Ljava/lang/Object;\)Z
|
||||
// 4 areEqual
|
||||
@@ -1,3 +1,4 @@
|
||||
// !LANGUAGE: +ProperIeee754Comparisons
|
||||
fun box(): String {
|
||||
val nullValue: Any? = null
|
||||
val nullDouble: Double? = null
|
||||
|
||||
@@ -26,4 +26,5 @@ fun box(): String {
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
// 0 areEqual
|
||||
// 4 areEqual \(Ljava/lang/Object;Ljava/lang/Object;\)Z
|
||||
// 4 areEqual
|
||||
|
||||
@@ -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<KtFile>,
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user