Rework how built-in types are loaded in compiler for JVM
In TopDownAnalyzerFacadeForJVM, we now always use the "load built-ins from module dependencies" behavior that was previously only enabled with the dedicated CLI argument -Xload-builtins-from-dependencies. However, sometimes we compile code without kotlin-stdlib in the classpath, and we don't want everything to crash because some standard type like kotlin.Unit hasn't been found. To mitigate this, we add another module at the end of the dependencies list, namely a "fallback built-ins" module. This module loads all built-in declarations from the compiler's class loader, as was done by default previously. This prevents the compiler from crashing if any built-in declaration is not found, but compiling the code against built-ins found in the compiler is still discouraged, so we report an error if anything is resolved to a declaration from this module, via a new checker MissingBuiltInDeclarationChecker. Also introduce a new CLI argument -Xsuppress-missing-builtins-error specifically to suppress this error and to allow compiling code against compiler's own built-ins. #KT-19227 Fixed #KT-28198 Fixed
This commit is contained in:
@@ -22,6 +22,10 @@ sourceSets {
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile(project(":core:builtins"))
|
||||
}
|
||||
|
||||
publish()
|
||||
|
||||
sourcesJar()
|
||||
|
||||
@@ -19,6 +19,10 @@ sourceSets {
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile project(':core:builtins')
|
||||
}
|
||||
|
||||
artifacts {
|
||||
archives sourcesJar
|
||||
}
|
||||
|
||||
+7
-20
@@ -6,7 +6,6 @@
|
||||
package org.jetbrains.kotlin.gradle.tasks
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.Task
|
||||
import org.gradle.api.file.FileCollection
|
||||
import org.gradle.api.plugins.BasePluginConvention
|
||||
import org.gradle.api.tasks.*
|
||||
@@ -29,9 +28,14 @@ import org.jetbrains.kotlin.gradle.internal.prepareCompilerArguments
|
||||
import org.jetbrains.kotlin.gradle.internal.tasks.TaskWithLocalState
|
||||
import org.jetbrains.kotlin.gradle.internal.tasks.allOutputFiles
|
||||
import org.jetbrains.kotlin.gradle.logging.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.COMPILER_CLASSPATH_CONFIGURATION_NAME
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinMultiplatformPluginWrapper
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformPluginBase
|
||||
import org.jetbrains.kotlin.gradle.plugin.PLUGIN_CLASSPATH_CONFIGURATION_NAME
|
||||
import org.jetbrains.kotlin.gradle.report.BuildReportMode
|
||||
import org.jetbrains.kotlin.gradle.utils.*
|
||||
import org.jetbrains.kotlin.gradle.utils.isParentOf
|
||||
import org.jetbrains.kotlin.gradle.utils.pathsAsStringRelativeTo
|
||||
import org.jetbrains.kotlin.gradle.utils.toSortedPathsArray
|
||||
import org.jetbrains.kotlin.incremental.ChangedFiles
|
||||
import org.jetbrains.kotlin.incremental.classpathAsList
|
||||
import org.jetbrains.kotlin.incremental.destinationAsFile
|
||||
@@ -393,13 +397,6 @@ open class KotlinCompile : AbstractKotlinCompile<K2JVMCompilerArguments>(), Kotl
|
||||
args.apply { fillDefaultValues() }
|
||||
super.setupCompilerArgs(args, defaultsOnly)
|
||||
|
||||
args.addCompilerBuiltIns = true
|
||||
|
||||
val gradleVersion = getGradleVersion()
|
||||
if (gradleVersion == null || gradleVersion >= ParsedGradleVersion(3, 2)) {
|
||||
args.loadBuiltInsFromDependencies = true
|
||||
}
|
||||
|
||||
args.moduleName = friendTask?.moduleName ?: moduleName
|
||||
logger.kotlinDebug { "args.moduleName = ${args.moduleName}" }
|
||||
|
||||
@@ -614,13 +611,3 @@ private val invalidModuleNameCharactersRegex = """[\\/\r\n\t]""".toRegex()
|
||||
|
||||
private fun filterModuleName(moduleName: String): String =
|
||||
moduleName.replace(invalidModuleNameCharactersRegex, "_")
|
||||
|
||||
private fun Task.getGradleVersion(): ParsedGradleVersion? {
|
||||
val gradleVersion = project.gradle.gradleVersion
|
||||
val result = ParsedGradleVersion.parse(gradleVersion)
|
||||
if (result == null) {
|
||||
logger.kotlinDebug("Could not parse gradle version: $gradleVersion")
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
</goals>
|
||||
<configuration>
|
||||
<args combine.children="append">
|
||||
<arg>-Xadd-compiler-builtins</arg>
|
||||
<arg>-Xsuppress-missing-builtins-error</arg>
|
||||
</args>
|
||||
</configuration>
|
||||
</execution>
|
||||
|
||||
Reference in New Issue
Block a user