From a7bef2d0eef468581153ce10b33d9310126dbd9e Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Tue, 8 Nov 2016 16:20:33 +0300 Subject: [PATCH] Lower priority of compiler built-ins in resolution (#43) * Remove unneeded module context creation in K2Native Calling this method is useful only when its result is used * Use JvmAbi from compiler instead of reflection implementation Package "kotlin.reflect.jvm.internal.impl" is internal implementation detail of kotlin-reflect and should not be used * Run native back-end with "-ea" This allows to get more detailed messages in case something fails * Lower priority of compiler built-ins in resolution CREATE_BUILT_INS_FROM_MODULE_DEPENDENCIES makes sure that the "built-ins" that the compiler front-end uses during the resolution are loaded from the module being resolved itself, i.e. from its sources and/or dependencies. E.g. if there's a class named kotlin.Any in module sources, it'll become the default supertype for any class without an explicit supertype. ADD_BUILT_INS_FROM_COMPILER_TO_DEPENDENCIES adds the built-ins from the compiler jar to the end of the dependencies list of the module being resolved. This option makes sure that if there's no built-in class in module sources/dependencies and it is required by the front-end, the class definition from the compiler jar will be taken instead of failing with an exception. If both of these options are turned on, the effect is basically that compiler built-ins are still there in the classpath, but have a lower priority than classes explicitly declared in sources --- .../src/org/jetbrains/kotlin/cli/bc/K2Native.kt | 11 +++++++---- backend.native/tests/build.gradle | 1 + 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt b/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt index 249b9897e1a..19a17e6c5c4 100644 --- a/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt +++ b/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt @@ -12,15 +12,17 @@ import org.jetbrains.kotlin.cli.jvm.compiler.JvmPackagePartProvider import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment import org.jetbrains.kotlin.config.CommonConfigurationKeys import org.jetbrains.kotlin.config.CompilerConfiguration +import org.jetbrains.kotlin.config.JVMConfigurationKeys.ADD_BUILT_INS_FROM_COMPILER_TO_DEPENDENCIES +import org.jetbrains.kotlin.config.JVMConfigurationKeys.CREATE_BUILT_INS_FROM_MODULE_DEPENDENCIES import org.jetbrains.kotlin.config.Services import org.jetbrains.kotlin.config.addKotlinSourceRoots import org.jetbrains.kotlin.ir.util.DumpIrTreeVisitor +import org.jetbrains.kotlin.load.java.JvmAbi import org.jetbrains.kotlin.psi2ir.Psi2IrConfiguration import org.jetbrains.kotlin.psi2ir.Psi2IrTranslator import org.jetbrains.kotlin.resolve.jvm.TopDownAnalyzerFacadeForJVM import java.lang.System.out import java.util.* -import kotlin.reflect.jvm.internal.impl.load.java.JvmAbi class NativeAnalyzer(val environment: KotlinCoreEnvironment) : AnalyzerWithCompilerReport.Analyzer { @@ -28,13 +30,14 @@ class NativeAnalyzer(val environment: KotlinCoreEnvironment) : val sharedTrace = CliLightClassGenerationSupport.NoScopeRecordCliBindingTrace() - TopDownAnalyzerFacadeForJVM.createContextWithSealedModule( - environment.project, environment.configuration) return TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration( environment.project, environment.getSourceFiles(), sharedTrace, - environment.configuration, + environment.configuration.apply { + put(ADD_BUILT_INS_FROM_COMPILER_TO_DEPENDENCIES, true) + put(CREATE_BUILT_INS_FROM_MODULE_DEPENDENCIES, true) + }, { scope -> JvmPackagePartProvider(environment, scope) } ) } diff --git a/backend.native/tests/build.gradle b/backend.native/tests/build.gradle index 4a4eb9ebb7b..dce9c14d502 100644 --- a/backend.native/tests/build.gradle +++ b/backend.native/tests/build.gradle @@ -33,6 +33,7 @@ abstract class KonanTest extends DefaultTask { project.javaexec { main = 'org.jetbrains.kotlin.cli.bc.K2NativeKt' classpath = project.configurations.cli_bc + jvmArgs "-ea" args "-output", "${sourceBc.absolutePath}", "-runtime", "${runtimeBc.absolutePath}", "-headers", project.project(':runtime').file('src/main/kotlin'),