[K/N][IR][codegen] Preliminary support of per-file caches

This commit is contained in:
Igor Chevdar
2022-04-04 18:27:15 +05:00
committed by Space
parent 4d2a8f852e
commit 7e79b2b500
35 changed files with 615 additions and 332 deletions
@@ -117,7 +117,7 @@ class K2Native : CLICompiler<K2NativeCompilerArguments>() {
val K2NativeCompilerArguments.isUsefulWithoutFreeArgs: Boolean
get() = listTargets || listPhases || checkDependencies || !includes.isNullOrEmpty() ||
!librariesToCache.isNullOrEmpty() || libraryToAddToCache != null || !exportedLibraries.isNullOrEmpty()
libraryToAddToCache != null || !exportedLibraries.isNullOrEmpty()
fun Array<String>?.toNonNullList(): List<String> {
return this?.asList<String>() ?: listOf<String>()
@@ -297,7 +297,6 @@ class K2Native : CLICompiler<K2NativeCompilerArguments>() {
put(OBJC_GENERICS, !arguments.noObjcGenerics)
put(DEBUG_PREFIX_MAP, parseDebugPrefixMap(arguments, configuration))
put(LIBRARIES_TO_CACHE, parseLibrariesToCache(arguments, configuration, outputKind))
val libraryToAddToCache = parseLibraryToAddToCache(arguments, configuration, outputKind)
if (libraryToAddToCache != null && !arguments.outputName.isNullOrEmpty())
configuration.report(ERROR, "${K2NativeCompilerArguments.ADD_CACHE} already implicitly sets output file name")
@@ -305,6 +304,10 @@ class K2Native : CLICompiler<K2NativeCompilerArguments>() {
libraryToAddToCache?.let { put(LIBRARY_TO_ADD_TO_CACHE, it) }
put(CACHE_DIRECTORIES, cacheDirectories)
put(CACHED_LIBRARIES, parseCachedLibraries(arguments, configuration))
val fileToCache = arguments.fileToCache
if (outputKind == CompilerOutputKind.PRELIMINARY_CACHE && fileToCache == null)
configuration.report(ERROR, "preliminary_cache only supported for per-file caches")
fileToCache?.let { put(FILE_TO_CACHE, it) }
parseShortModuleName(arguments, configuration, outputKind)?.let {
put(SHORT_MODULE_NAME, it)
@@ -521,27 +524,6 @@ private fun parseCachedLibraries(
}
}.toMap()
private fun parseLibrariesToCache(
arguments: K2NativeCompilerArguments,
configuration: CompilerConfiguration,
outputKind: CompilerOutputKind
): List<String> {
val input = arguments.librariesToCache?.asList().orEmpty()
return if (input.isNotEmpty() && !outputKind.isCache) {
configuration.report(ERROR, "${K2NativeCompilerArguments.MAKE_CACHE} can't be used when not producing cache")
emptyList()
} else if (input.isNotEmpty() && !arguments.libraryToAddToCache.isNullOrEmpty()) {
configuration.report(
ERROR,
"supplied both ${K2NativeCompilerArguments.MAKE_CACHE} and ${K2NativeCompilerArguments.ADD_CACHE} options"
)
emptyList()
} else {
input
}
}
private fun parseLibraryToAddToCache(
arguments: K2NativeCompilerArguments,
configuration: CompilerConfiguration,
@@ -43,12 +43,6 @@ const val INCLUDE_ARG = MovedK2NativeCompilerArguments.INCLUDE_ARG
)
const val CACHED_LIBRARY = MovedK2NativeCompilerArguments.CACHED_LIBRARY
@Deprecated(
"Moved to new 'org.jetbrains.kotlin.cli.common.arguments' package",
ReplaceWith("MAKE_CACHE", "org.jetbrains.kotlin.cli.common.arguments.MAKE_CACHE")
)
const val MAKE_CACHE = MovedK2NativeCompilerArguments.MAKE_CACHE
@Deprecated(
"Moved to new 'org.jetbrains.kotlin.cli.common.arguments' package",
ReplaceWith("ADD_CACHE", "org.jetbrains.kotlin.cli.common.arguments.ADD_CACHE")