[K/N] Move calls checker into separate module ^KT-62091

This commit is contained in:
Alexander Shabalin
2024-01-03 14:02:36 +01:00
committed by Space Team
parent 8cd87059c8
commit 3f2584bb02
15 changed files with 112 additions and 64 deletions
@@ -15,6 +15,8 @@ import kotlin.properties.ReadOnlyProperty
object BinaryOptions : BinaryOptionRegistry() {
val runtimeAssertionsMode by option<RuntimeAssertsMode>()
val checkStateAtExternalCalls by booleanOption()
val memoryModel by option<MemoryModel>()
val freezing by option<Freezing>()
@@ -95,6 +95,7 @@ class KonanConfig(val project: Project, val configuration: CompilerConfiguration
private val defaultGC get() = GC.PARALLEL_MARK_CONCURRENT_SWEEP
val gc: GC get() = configuration.get(BinaryOptions.gc) ?: defaultGC
val runtimeAssertsMode: RuntimeAssertsMode get() = configuration.get(BinaryOptions.runtimeAssertionsMode) ?: RuntimeAssertsMode.IGNORE
val checkStateAtExternalCalls: Boolean get() = configuration.get(BinaryOptions.checkStateAtExternalCalls) ?: false
private val defaultDisableMmap get() = target.family == Family.MINGW
val disableMmap: Boolean by lazy {
when (configuration.get(BinaryOptions.disableMmap)) {
@@ -400,6 +401,10 @@ class KonanConfig(val project: Project, val configuration: CompilerConfiguration
add("custom_alloc.bc")
}
}
when (checkStateAtExternalCalls) {
true -> add("impl_externalCallsChecker.bc")
false -> add("noop_externalCallsChecker.bc")
}
}.map {
File(distribution.defaultNatives(target)).child(it).absolutePath
}
@@ -523,6 +528,7 @@ class KonanConfig(val project: Project, val configuration: CompilerConfiguration
optimizationsEnabled -> "for optimized compilation"
sanitizer != null -> "with sanitizers enabled"
runtimeLogsEnabled -> "with runtime logs"
checkStateAtExternalCalls -> "with external calls state checker"
else -> null
}
@@ -101,8 +101,6 @@ class KonanConfigKeys {
= CompilerConfigurationKey.create("export KDoc into klib and framework")
val PRINT_BITCODE: CompilerConfigurationKey<Boolean>
= CompilerConfigurationKey.create("print bitcode")
val CHECK_EXTERNAL_CALLS: CompilerConfigurationKey<Boolean>
= CompilerConfigurationKey.create("check external calls")
val PRINT_IR: CompilerConfigurationKey<Boolean>
= CompilerConfigurationKey.create("print ir")
val PRINT_FILES: CompilerConfigurationKey<Boolean>
@@ -108,7 +108,6 @@ fun CompilerConfiguration.setupFromArguments(arguments: K2NativeCompilerArgument
put(PRINT_IR, arguments.printIr)
put(PRINT_BITCODE, arguments.printBitCode)
put(CHECK_EXTERNAL_CALLS, arguments.checkExternalCalls)
put(PRINT_FILES, arguments.printFiles)
put(PURGE_USER_LIBS, arguments.purgeUserLibs)
@@ -242,6 +241,14 @@ fun CompilerConfiguration.setupFromArguments(arguments: K2NativeCompilerArgument
putIfNotNull(BinaryOptions.gc, gcFromArgument)
}
if (arguments.checkExternalCalls != null) {
report(WARNING, "-Xcheck-state-at-external-calls compiler argument is deprecated. Use -Xbinary=checkStateAtExternalCalls=true instead")
}
// TODO: revise priority and/or report conflicting values.
if (get(BinaryOptions.checkStateAtExternalCalls) == null) {
putIfNotNull(BinaryOptions.checkStateAtExternalCalls, arguments.checkExternalCalls)
}
putIfNotNull(PROPERTY_LAZY_INITIALIZATION, when (arguments.propertyLazyInitialization) {
null -> null
"enable" -> true
@@ -249,7 +249,7 @@ internal data class ModuleCompilationOutput(
*/
internal fun PhaseEngine<NativeGenerationState>.compileModule(module: IrModuleFragment, bitcodeFile: java.io.File, cExportFiles: CExportFiles?) {
runBackendCodegen(module, cExportFiles)
val checkExternalCalls = context.config.configuration.getBoolean(KonanConfigKeys.CHECK_EXTERNAL_CALLS)
val checkExternalCalls = context.config.checkStateAtExternalCalls
if (checkExternalCalls) {
runPhase(CheckExternalCallsPhase)
}