[JS IR] Extract adding of function call to another function
[JS IR] Add option for dce mode [JS IR] Add logging to non useful declarations if appropriate dce mode [JS IR] Add mode with throwing exception [JS IR] unreachableDeclaration method is in rootDeclarations [JS IR] Add js extra help arg with dce mode and include debug.kt to compile unreachableMethod [JS IR] unreachableDeclaration as internal to not reproduce stdlib api [JS IR] Fix description of dce mode argument - Use console.error instead of console.log - Use JsError instead Kotlin exception for lightweight [JS IR] Remove body for throwing exception [JS IR] Remove default parameter in unreachableDeclaration [JS IR] Process without removing fields and declaration containers [JS IR] Rename dce mode on dce runtime diagnostic [JS IR] Use console.trace instead of console.error [JS IR] Extract JsError - Fix naming in prependFunctionCall - Fix description on runtime diagnostic argument - Using message collector instead of throwing exception [JS IR] Distinguish unreachableMethods for log and exception [JS IR] Extract checking of Kotlin packages of IrField ^KT-45059 fixed
This commit is contained in:
+8
-2
@@ -5,8 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.cli.common.arguments
|
||||
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JsArgumentConstants.CALL
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JsArgumentConstants.NO_CALL
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JsArgumentConstants.*
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
||||
import org.jetbrains.kotlin.config.ApiVersion
|
||||
@@ -126,6 +125,13 @@ class K2JSCompilerArguments : CommonCompilerArguments() {
|
||||
@Argument(value = "-Xir-dce", description = "Perform experimental dead code elimination")
|
||||
var irDce: Boolean by FreezableVar(false)
|
||||
|
||||
@Argument(
|
||||
value = "-Xir-dce-runtime-diagnostic",
|
||||
valueDescription = "{$DCE_RUNTIME_DIAGNOSTIC_LOG|$DCE_RUNTIME_DIAGNOSTIC_EXCEPTION}",
|
||||
description = "Enable runtime diagnostics when performing DCE instead of removing declarations"
|
||||
)
|
||||
var irDceRuntimeDiagnostic: String? by NullableStringFreezableVar(null)
|
||||
|
||||
@Argument(value = "-Xir-dce-driven", description = "Perform a more experimental faster dead code elimination")
|
||||
var irDceDriven: Boolean by FreezableVar(false)
|
||||
|
||||
|
||||
+3
@@ -28,4 +28,7 @@ public interface K2JsArgumentConstants {
|
||||
String SOURCE_MAP_SOURCE_CONTENT_ALWAYS = "always";
|
||||
String SOURCE_MAP_SOURCE_CONTENT_NEVER = "never";
|
||||
String SOURCE_MAP_SOURCE_CONTENT_INLINING = "inlining";
|
||||
|
||||
String DCE_RUNTIME_DIAGNOSTIC_LOG = "log";
|
||||
String DCE_RUNTIME_DIAGNOSTIC_EXCEPTION = "exception";
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import org.jetbrains.kotlin.cli.common.ExitCode.COMPILATION_ERROR
|
||||
import org.jetbrains.kotlin.cli.common.ExitCode.OK
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JsArgumentConstants
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JsArgumentConstants.*
|
||||
import org.jetbrains.kotlin.cli.common.config.addKotlinSourceRoot
|
||||
import org.jetbrains.kotlin.cli.common.extensions.ScriptEvaluationExtension
|
||||
import org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport
|
||||
@@ -259,12 +260,17 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
|
||||
mainArguments = mainCallArguments,
|
||||
generateFullJs = !arguments.irDce,
|
||||
generateDceJs = arguments.irDce,
|
||||
dceRuntimeDiagnostic = DceRuntimeDiagnostic.resolve(
|
||||
arguments.irDceRuntimeDiagnostic,
|
||||
messageCollector
|
||||
),
|
||||
dceDriven = arguments.irDceDriven,
|
||||
multiModule = arguments.irPerModule,
|
||||
relativeRequirePath = true,
|
||||
propertyLazyInitialization = arguments.irPropertyLazyInitialization,
|
||||
)
|
||||
|
||||
|
||||
val jsCode = if (arguments.irDce && !arguments.irDceDriven) compiledModule.dceJsCode!! else compiledModule.jsCode!!
|
||||
outputFile.writeText(jsCode.mainModule)
|
||||
jsCode.dependencies.forEach { (name, content) ->
|
||||
@@ -422,6 +428,19 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
|
||||
}
|
||||
}
|
||||
|
||||
fun DceRuntimeDiagnostic.Companion.resolve(
|
||||
value: String?,
|
||||
messageCollector: MessageCollector
|
||||
): DceRuntimeDiagnostic? = when (value?.toLowerCase()) {
|
||||
DCE_RUNTIME_DIAGNOSTIC_LOG -> DceRuntimeDiagnostic.LOG
|
||||
DCE_RUNTIME_DIAGNOSTIC_EXCEPTION -> DceRuntimeDiagnostic.EXCEPTION
|
||||
null -> null
|
||||
else -> {
|
||||
messageCollector.report(STRONG_WARNING, "Unknown DCE runtime diagnostic '$value'")
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
fun messageCollectorLogger(collector: MessageCollector) = object : Logger {
|
||||
override fun warning(message: String) = collector.report(STRONG_WARNING, message)
|
||||
override fun error(message: String) = collector.report(ERROR, message)
|
||||
|
||||
Reference in New Issue
Block a user