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
This commit is contained in:
Alexander Udalov
2016-11-08 16:20:33 +03:00
committed by Nikolay Igotti
parent a354f4b605
commit a7bef2d0ee
2 changed files with 8 additions and 4 deletions
@@ -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) }
)
}
+1
View File
@@ -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'),