[JS IR] Run diagnostics by IR before the klib serialization
Implement an infrastructure for checking IR before JS klib serialization. Implement the EXPORTING_JS_NAME_CLASH and EXPORTING_JS_NAME_CLASH_ES checks. ^KT-61710 Fixed
This commit is contained in:
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||
import org.jetbrains.kotlin.config.*
|
||||
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticReporterFactory
|
||||
import org.jetbrains.kotlin.incremental.ChangedFiles
|
||||
import org.jetbrains.kotlin.incremental.IncrementalJsCompilerRunner
|
||||
import org.jetbrains.kotlin.incremental.multiproject.EmptyModulesApiHistory
|
||||
@@ -36,6 +37,7 @@ import org.jetbrains.kotlin.ir.backend.js.*
|
||||
import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsIrLinker
|
||||
import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsIrModuleSerializer
|
||||
import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsManglerDesc
|
||||
import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.collectExportedNames
|
||||
import org.jetbrains.kotlin.ir.backend.js.transformers.irToJs.IrModuleToJsTransformer
|
||||
import org.jetbrains.kotlin.ir.backend.js.transformers.irToJs.TranslationMode
|
||||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
||||
@@ -490,12 +492,14 @@ class GenerateIrRuntime {
|
||||
files: List<KtFile>,
|
||||
perFile: Boolean = false
|
||||
): String {
|
||||
val diagnosticReporter = DiagnosticReporterFactory.createPendingReporter()
|
||||
val tmpKlibDir = createTempDirectory().also { it.toFile().deleteOnExit() }.toString()
|
||||
val metadataSerializer = KlibMetadataIncrementalSerializer(configuration, project, false)
|
||||
serializeModuleIntoKlib(
|
||||
moduleName,
|
||||
configuration,
|
||||
IrMessageLogger.None,
|
||||
diagnosticReporter,
|
||||
files.map(::KtPsiSourceFile),
|
||||
tmpKlibDir,
|
||||
emptyList(),
|
||||
|
||||
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.incremental
|
||||
import org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport
|
||||
import org.jetbrains.kotlin.cli.js.klib.generateIrForKlibSerialization
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticReporterFactory
|
||||
import org.jetbrains.kotlin.ir.backend.js.*
|
||||
import org.jetbrains.kotlin.ir.backend.js.transformers.irToJs.JsGenerationGranularity
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl
|
||||
@@ -108,13 +109,15 @@ abstract class IrAbstractInvalidationTest(
|
||||
val metadataSerializer =
|
||||
KlibMetadataIncrementalSerializer(configuration, sourceModule.project, sourceModule.jsFrontEndResult.hasErrors)
|
||||
|
||||
val diagnosticReporter = DiagnosticReporterFactory.createPendingReporter()
|
||||
generateKLib(
|
||||
sourceModule,
|
||||
outputKlibFile.canonicalPath,
|
||||
nopack = false,
|
||||
jsOutputName = moduleName,
|
||||
icData = icData,
|
||||
moduleFragment = moduleFragment
|
||||
moduleFragment = moduleFragment,
|
||||
diagnosticReporter = diagnosticReporter
|
||||
) { file ->
|
||||
metadataSerializer.serializeScope(file, sourceModule.jsFrontEndResult.bindingContext, moduleFragment.descriptor)
|
||||
}
|
||||
|
||||
@@ -62,6 +62,7 @@ class FirJsKlibBackendFacade(
|
||||
configuration[CommonConfigurationKeys.MODULE_NAME]!!,
|
||||
configuration,
|
||||
configuration.get(IrMessageLogger.IR_MESSAGE_LOGGER) ?: IrMessageLogger.None,
|
||||
inputArtifact.diagnosticReporter,
|
||||
inputArtifact.sourceFiles,
|
||||
klibPath = outputFile,
|
||||
libraries.map { it.library },
|
||||
|
||||
@@ -51,6 +51,7 @@ class JsKlibBackendFacade(
|
||||
configuration[CommonConfigurationKeys.MODULE_NAME]!!,
|
||||
configuration,
|
||||
configuration.irMessageLogger,
|
||||
inputArtifact.diagnosticReporter,
|
||||
inputArtifact.sourceFiles,
|
||||
klibPath = outputFile,
|
||||
JsEnvironmentConfigurator.getAllRecursiveLibrariesFor(module, testServices).keys.toList(),
|
||||
|
||||
+9
-2
@@ -112,12 +112,19 @@ abstract class AbstractJsPartialLinkageTestCase(private val compilerType: Compil
|
||||
"-Xir-produce-klib-file",
|
||||
"-ir-output-dir", klibFile.parentFile.absolutePath,
|
||||
"-ir-output-name", moduleName,
|
||||
"-Werror" // Halt on any unexpected warning.
|
||||
// Halt on any unexpected warning.
|
||||
"-Werror",
|
||||
// Tests suppress the INVISIBLE_REFERENCE check.
|
||||
// However, JS doesn't produce the INVISIBLE_REFERENCE error;
|
||||
// As result, it triggers a suppression error warning about the redundant suppression.
|
||||
// This flag is used to disable the warning.
|
||||
"-Xdont-warn-on-error-suppression"
|
||||
),
|
||||
dependencies.toCompilerArgs(),
|
||||
listOf(
|
||||
"-language-version", "2.0",
|
||||
"-Xsuppress-version-warnings" // Don't fail on language version warnings.
|
||||
// Don't fail on language version warnings.
|
||||
"-Xsuppress-version-warnings"
|
||||
).takeIf { compilerType.useFir },
|
||||
kotlinSourceFilePaths
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user