Compare commits

...

2 Commits

Author SHA1 Message Date
Roman Artemev
6737364eec wip ZZ ~~ 2021-06-17 16:51:11 +03:00
Roman Artemev
2928823306 [JS IR] Disable ts export check in PIR mode in box tests
Since that feature is not declared as working yet
2021-06-17 09:50:55 +03:00
9 changed files with 67 additions and 39 deletions

View File

@@ -187,11 +187,6 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
messageCollectorLogger(configuration[CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY] ?: error("Could not find message collector"))
)
val friendAbsolutePaths = friendLibraries.map { File(it).absolutePath }
val friendDependencies = resolvedLibraries.getFullList().filter {
it.libraryFile.absolutePath in friendAbsolutePaths
}
if (arguments.irProduceKlibDir || arguments.irProduceKlibFile) {
if (arguments.irProduceKlibFile) {
require(outputFile.extension == KLIB_FILE_EXTENSION) { "Please set up .klib file as output" }
@@ -202,8 +197,8 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
files = sourcesFiles,
analyzer = AnalyzerWithCompilerReport(config.configuration),
configuration = config.configuration,
allDependencies = resolvedLibraries,
friendDependencies = friendDependencies,
dependencies = libraries,
friendDependencies = friendLibraries,
irFactory = PersistentIrFactory(), // TODO IrFactoryImpl?
outputKlibPath = outputFile.path,
nopack = arguments.irProduceKlibDir,
@@ -235,8 +230,8 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
config.configuration,
PhaseConfig(wasmPhases),
IrFactoryImpl,
allDependencies = resolvedLibraries,
friendDependencies = friendDependencies,
dependencies = libraries,
friendDependencies = friendLibraries,
exportedDeclarations = setOf(FqName("main"))
)
val outputWasmFile = outputFile.withReplacedExtensionOrNull(outputFile.extension, "wasm")!!
@@ -262,8 +257,8 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
config.configuration,
phaseConfig,
if (arguments.irDceDriven) PersistentIrFactory() else IrFactoryImpl,
allDependencies = resolvedLibraries,
friendDependencies = friendDependencies,
dependencies = libraries,
friendDependencies = friendLibraries,
mainArguments = mainCallArguments,
generateFullJs = !arguments.irDce,
generateDceJs = arguments.irDce,

View File

@@ -21,8 +21,6 @@ import org.jetbrains.kotlin.ir.declarations.persistent.PersistentIrFactory
import org.jetbrains.kotlin.ir.util.ExternalDependenciesGenerator
import org.jetbrains.kotlin.ir.util.noUnboundLeft
import org.jetbrains.kotlin.js.config.DceRuntimeDiagnostic
import org.jetbrains.kotlin.library.KotlinLibrary
import org.jetbrains.kotlin.library.resolver.KotlinLibraryResolveResult
import org.jetbrains.kotlin.name.FqName
class CompilerResult(
@@ -40,8 +38,8 @@ fun compile(
configuration: CompilerConfiguration,
phaseConfig: PhaseConfig,
irFactory: IrFactory,
allDependencies: KotlinLibraryResolveResult,
friendDependencies: List<KotlinLibrary>,
dependencies: Collection<String>,
friendDependencies: Collection<String>,
mainArguments: List<String>?,
exportedDeclarations: Set<FqName> = emptySet(),
generateFullJs: Boolean = true,
@@ -56,7 +54,7 @@ fun compile(
baseClassIntoMetadata: Boolean = false,
): CompilerResult {
val (moduleFragment: IrModuleFragment, dependencyModules, irBuiltIns, symbolTable, deserializer, moduleToName) =
loadIr(project, mainModule, analyzer, configuration, allDependencies, friendDependencies, irFactory)
loadIr(project, mainModule, analyzer, configuration, dependencies, friendDependencies, irFactory)
val moduleDescriptor = moduleFragment.descriptor

View File

@@ -18,8 +18,6 @@ import org.jetbrains.kotlin.ir.backend.js.loadIr
import org.jetbrains.kotlin.ir.declarations.IrFactory
import org.jetbrains.kotlin.ir.util.ExternalDependenciesGenerator
import org.jetbrains.kotlin.ir.util.patchDeclarationParents
import org.jetbrains.kotlin.library.KotlinLibrary
import org.jetbrains.kotlin.library.resolver.KotlinLibraryResolveResult
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi2ir.generators.generateTypicalIrProviderList
import org.jetbrains.kotlin.wasm.ir.convertors.WasmIrToBinary
@@ -35,12 +33,12 @@ fun compileWasm(
configuration: CompilerConfiguration,
phaseConfig: PhaseConfig,
irFactory: IrFactory,
allDependencies: KotlinLibraryResolveResult,
friendDependencies: List<KotlinLibrary>,
dependencies: Collection<String>,
friendDependencies: Collection<String>,
exportedDeclarations: Set<FqName> = emptySet()
): WasmCompilerResult {
val (moduleFragment, dependencyModules, irBuiltIns, symbolTable, deserializer) =
loadIr(project, mainModule, analyzer, configuration, allDependencies, friendDependencies, irFactory)
loadIr(project, mainModule, analyzer, configuration, dependencies, friendDependencies, irFactory)
val allModules = when (mainModule) {
is MainModule.SourceFiles -> dependencyModules + listOf(moduleFragment)

View File

@@ -37,7 +37,7 @@ class JsLibraryResolver(
}
// TODO: This is a temporary set of library resolver policies for js compiler.
fun jsResolveLibraries(libraries: List<String>, repositories: Collection<String>, logger: Logger): KotlinLibraryResolveResult {
fun jsResolveLibraries(libraries: Collection<String>, repositories: Collection<String>, logger: Logger): KotlinLibraryResolveResult {
val unresolvedLibraries = libraries.map { UnresolvedLibrary(it, null) }
val libraryAbsolutePaths = libraries.map { File(it).absolutePath }
// Configure the resolver to only work with absolute paths for now.

View File

@@ -68,6 +68,8 @@ import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.BindingContextUtils
import org.jetbrains.kotlin.storage.LockBasedStorageManager
import org.jetbrains.kotlin.storage.StorageManager
import org.jetbrains.kotlin.util.DummyLogger
import org.jetbrains.kotlin.util.Logger
import org.jetbrains.kotlin.utils.DFS
import java.io.File
import org.jetbrains.kotlin.konan.file.File as KFile
@@ -95,13 +97,36 @@ private val CompilerConfiguration.expectActualLinker: Boolean
class KotlinFileSerializedData(val metadata: ByteArray, val irData: SerializedIrFile)
private fun IrMessageLogger?.toResolverLogger(): Logger {
if (this == null) return DummyLogger
return object : Logger {
override fun log(message: String) {
report(IrMessageLogger.Severity.INFO, message, null)
}
override fun error(message: String) {
report(IrMessageLogger.Severity.ERROR, message, null)
}
override fun warning(message: String) {
report(IrMessageLogger.Severity.WARNING, message, null)
}
override fun fatal(message: String): Nothing {
report(IrMessageLogger.Severity.ERROR, message, null)
kotlin.error("FATAL ERROR: $message")
}
}
}
fun generateKLib(
project: Project,
files: List<KtFile>,
analyzer: AbstractAnalyzerWithCompilerReport,
configuration: CompilerConfiguration,
allDependencies: KotlinLibraryResolveResult,
friendDependencies: List<KotlinLibrary>,
dependencies: Collection<String>,
friendDependencies: Collection<String>,
irFactory: IrFactory,
outputKlibPath: String,
nopack: Boolean,
@@ -142,8 +167,8 @@ fun generateKLib(
}
val depsDescriptors =
ModulesStructure(project, MainModule.SourceFiles(files), analyzer, configuration, allDependencies, friendDependencies)
ModulesStructure(project, MainModule.SourceFiles(files), analyzer, configuration, dependencies, friendDependencies)
val allDependencies = depsDescriptors.allDependencies
val (psi2IrContext, hasErrors) = runAnalysisAndPreparePsi2Ir(depsDescriptors, irFactory, errorPolicy)
val irBuiltIns = psi2IrContext.irBuiltIns
val functionFactory = IrFunctionFactory(irBuiltIns, psi2IrContext.symbolTable)
@@ -223,13 +248,14 @@ fun loadIr(
mainModule: MainModule,
analyzer: AbstractAnalyzerWithCompilerReport,
configuration: CompilerConfiguration,
allDependencies: KotlinLibraryResolveResult,
friendDependencies: List<KotlinLibrary>,
dependencies: Collection<String>,
friendDependencies: Collection<String>,
irFactory: IrFactory,
): IrModuleInfo {
val depsDescriptors = ModulesStructure(project, mainModule, analyzer, configuration, allDependencies, friendDependencies)
val depsDescriptors = ModulesStructure(project, mainModule, analyzer, configuration, dependencies, friendDependencies)
val errorPolicy = configuration.get(JSConfigurationKeys.ERROR_TOLERANCE_POLICY) ?: ErrorTolerancePolicy.DEFAULT
val messageLogger = configuration.get(IrMessageLogger.IR_MESSAGE_LOGGER) ?: IrMessageLogger.None
val allDependencies = depsDescriptors.allDependencies
when (mainModule) {
is MainModule.SourceFiles -> {
@@ -390,9 +416,21 @@ private class ModulesStructure(
private val mainModule: MainModule,
private val analyzer: AbstractAnalyzerWithCompilerReport,
val compilerConfiguration: CompilerConfiguration,
val allDependencies: KotlinLibraryResolveResult,
private val friendDependencies: List<KotlinLibrary>
val dependencies: Collection<String>,
friendDependenciesPaths: Collection<String>
) {
val allDependencies = jsResolveLibraries(
dependencies,
compilerConfiguration[JSConfigurationKeys.REPOSITORIES] ?: emptyList(),
compilerConfiguration[IrMessageLogger.IR_MESSAGE_LOGGER].toResolverLogger()
)
private val friendAbsolutePaths = friendDependenciesPaths.map { File(it).absolutePath }
val friendDependencies = allDependencies.getFullList().filter {
it.libraryFile.absolutePath in friendAbsolutePaths
}
val moduleDependencies: Map<KotlinLibrary, List<KotlinLibrary>> = run {
val transitives = allDependencies.getFullResolvedList()
transitives.associate { klib ->

View File

@@ -83,8 +83,8 @@ class ApiTest : KotlinTestWithEnvironment() {
MainModule.Klib(resolvedLibraries.getFullList().single()),
AnalyzerWithCompilerReport(configuration),
configuration,
resolvedLibraries,
listOf(),
listOf(fullRuntimeKlib),
emptyList(),
IrFactoryImpl,
).module.descriptor.packagesSerialized()
}

View File

@@ -138,7 +138,7 @@ abstract class BasicIrBoxTest(
configuration = config.configuration,
phaseConfig = phaseConfig,
irFactory = IrFactoryImpl,
allDependencies = resolvedLibraries,
dependencies = allKlibPaths,
friendDependencies = emptyList(),
mainArguments = mainCallParameters.run { if (shouldBeGenerated()) arguments() else null },
exportedDeclarations = setOf(FqName.fromSegments(listOfNotNull(testPackage, testFunction))),
@@ -168,7 +168,7 @@ abstract class BasicIrBoxTest(
configuration = config.configuration,
phaseConfig = phaseConfig,
irFactory = PersistentIrFactory(),
allDependencies = resolvedLibraries,
dependencies = allKlibPaths,
friendDependencies = emptyList(),
mainArguments = mainCallParameters.run { if (shouldBeGenerated()) arguments() else null },
exportedDeclarations = setOf(FqName.fromSegments(listOfNotNull(testPackage, testFunction))),
@@ -184,7 +184,7 @@ abstract class BasicIrBoxTest(
files = filesToCompile,
analyzer = AnalyzerWithCompilerReport(config.configuration),
configuration = config.configuration,
allDependencies = resolvedLibraries,
dependencies = allKlibPaths,
friendDependencies = emptyList(),
irFactory = IrFactoryImpl,
outputKlibPath = actualOutputFile,

View File

@@ -22,8 +22,6 @@ import org.jetbrains.kotlin.js.config.JsConfig
import org.jetbrains.kotlin.js.facade.TranslationUnit
import org.jetbrains.kotlin.js.test.engines.ExternalTool
import org.jetbrains.kotlin.js.test.engines.SpiderMonkeyEngine
import org.jetbrains.kotlin.library.resolver.impl.KotlinLibraryResolverResultImpl
import org.jetbrains.kotlin.library.resolver.impl.KotlinResolvedLibraryImpl
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.KtNamedFunction
import org.jetbrains.kotlin.psi.KtPsiFactory
@@ -140,7 +138,7 @@ abstract class BasicWasmBoxTest(
phaseConfig = phaseConfig,
irFactory = IrFactoryImpl,
// TODO: Bypass the resolver fow wasm.
allDependencies = KotlinLibraryResolverResultImpl(listOf(KotlinResolvedLibraryImpl(wasmRuntimeKlib))),
dependencies = listOf(System.getProperty("kotlin.wasm.stdlib.path")!!),
friendDependencies = emptyList(),
exportedDeclarations = setOf(FqName.fromSegments(listOfNotNull(testPackage, testFunction)))
)

View File

@@ -24,6 +24,7 @@ abstract class AbstractIrJsTypeScriptExportTest(
private val updateReferenceDtsFiles = getBoolean("kotlin.js.updateReferenceDtsFiles")
override fun performAdditionalChecks(inputFile: File, outputFile: File) {
if (skipRegularMode) return
val referenceDtsFile = inputFile.withReplacedExtensionOrNull(".kt", ".d.ts")
?: error("Can't find reference .d.ts file")
val generatedDtsFile = outputFile.withReplacedExtensionOrNull("_v5", ".d.ts")