mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-03-10 08:31:29 +00:00
[JS IC] Lot of fixes after rebase
This commit is contained in:
committed by
teamcityserver
parent
8782399ffb
commit
0310f7cb0b
@@ -188,7 +188,7 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
|
||||
messageCollector.report(INFO, "Building cache:")
|
||||
messageCollector.report(INFO, "to: ${outputFilePath}")
|
||||
messageCollector.report(INFO, arguments.cacheDirectories ?: "")
|
||||
messageCollector.report(INFO, resolvedLibraries.getFullList().map { it.libraryName }.toString())
|
||||
messageCollector.report(INFO, libraries.toString())
|
||||
|
||||
val includes = arguments.includes!!
|
||||
|
||||
@@ -197,9 +197,7 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
|
||||
if (sourcesFiles.isNotEmpty()) {
|
||||
messageCollector.report(ERROR, "Source files are not supported when -Xinclude is present")
|
||||
}
|
||||
val allLibraries = resolvedLibraries.getFullList()
|
||||
val mainLib = allLibraries.find { it.libraryFile.absolutePath == File(includes).absolutePath }!!
|
||||
MainModule.Klib(mainLib)
|
||||
MainModule.Klib(includes)
|
||||
}
|
||||
|
||||
val start = System.currentTimeMillis()
|
||||
@@ -209,9 +207,9 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
|
||||
mainModule = mainModule,
|
||||
analyzer = AnalyzerWithCompilerReport(config.configuration),
|
||||
configuration = config.configuration,
|
||||
allDependencies = resolvedLibraries,
|
||||
friendDependencies = friendDependencies,
|
||||
icCache = checkCaches(resolvedLibraries, icCaches, skipLib = mainModule.lib.libraryFile.absolutePath)
|
||||
dependencies = libraries,
|
||||
friendDependencies = friendLibraries,
|
||||
icCache = checkCaches(libraries, icCaches, skipLib = mainModule.libPath)
|
||||
)
|
||||
|
||||
messageCollector.report(INFO, "IC cache building duration: ${System.currentTimeMillis() - start}ms")
|
||||
@@ -316,7 +314,7 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
|
||||
),
|
||||
lowerPerModule = icCaches.isNotEmpty(),
|
||||
useStdlibCache = icCaches.isNotEmpty(),
|
||||
icCache = if (icCaches.isNotEmpty()) checkCaches(resolvedLibraries, icCaches, skipLib = (mainModule as MainModule.Klib).lib.libraryFile.absolutePath).data else emptyMap(),
|
||||
icCache = if (icCaches.isNotEmpty()) checkCaches(libraries, icCaches, skipLib = includes).data else emptyMap(),
|
||||
)
|
||||
|
||||
messageCollector.report(INFO, "Executable production duration: ${System.currentTimeMillis() - start}ms")
|
||||
|
||||
@@ -21,7 +21,8 @@ import org.jetbrains.kotlin.ir.declarations.IrFactory
|
||||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
||||
import org.jetbrains.kotlin.ir.declarations.StageController
|
||||
import org.jetbrains.kotlin.ir.declarations.persistent.PersistentIrFactory
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.ir.util.ExternalDependenciesGenerator
|
||||
import org.jetbrains.kotlin.ir.util.noUnboundLeft
|
||||
import org.jetbrains.kotlin.js.config.RuntimeDiagnostic
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
|
||||
@@ -72,7 +73,7 @@ fun compile(
|
||||
mainModule,
|
||||
analyzer,
|
||||
configuration,
|
||||
allDependencies,
|
||||
dependencies,
|
||||
friendDependencies,
|
||||
mainArguments,
|
||||
exportedDeclarations,
|
||||
|
||||
@@ -10,10 +10,6 @@ import org.jetbrains.kotlin.analyzer.AbstractAnalyzerWithCompilerReport
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.ir.backend.js.MainModule
|
||||
import org.jetbrains.kotlin.ir.backend.js.toByteArray
|
||||
import org.jetbrains.kotlin.library.KotlinLibrary
|
||||
import org.jetbrains.kotlin.library.impl.javaFile
|
||||
import org.jetbrains.kotlin.library.resolver.KotlinLibraryResolveResult
|
||||
import org.jetbrains.kotlin.library.resolver.TopologicalLibraryOrder
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import java.io.File
|
||||
import java.io.PrintWriter
|
||||
@@ -31,18 +27,18 @@ fun buildCache(
|
||||
mainModule: MainModule.Klib,
|
||||
analyzer: AbstractAnalyzerWithCompilerReport,
|
||||
configuration: CompilerConfiguration,
|
||||
allDependencies: KotlinLibraryResolveResult,
|
||||
friendDependencies: List<KotlinLibrary>,
|
||||
dependencies: Collection<String>,
|
||||
friendDependencies: Collection<String>,
|
||||
exportedDeclarations: Set<FqName> = emptySet(),
|
||||
forceClean: Boolean = false,
|
||||
icCache: IcCacheInfo = IcCacheInfo.EMPTY,
|
||||
) {
|
||||
val dependencyHashes = allDependencies.getFullList(TopologicalLibraryOrder).mapNotNull {
|
||||
val path = it.libraryFile.absolutePath
|
||||
val dependencyHashes = dependencies.mapNotNull {
|
||||
val path = File(it).canonicalPath
|
||||
icCache.md5[path]
|
||||
} + compilerVersion
|
||||
|
||||
val md5 = mainModule.lib.libraryFile.javaFile().md5(dependencyHashes)
|
||||
val md5 = File(mainModule.libPath).md5(dependencyHashes)
|
||||
|
||||
if (!forceClean) {
|
||||
val oldCacheInfo = CacheInfo.load(cachePath)
|
||||
@@ -53,11 +49,11 @@ fun buildCache(
|
||||
icDir.deleteRecursively()
|
||||
icDir.mkdirs()
|
||||
|
||||
val icData = prepareSingleLibraryIcCache(project, analyzer, configuration, mainModule.lib, allDependencies, friendDependencies, exportedDeclarations, icCache.data)
|
||||
val icData = prepareSingleLibraryIcCache(project, analyzer, configuration, mainModule.libPath, dependencies, friendDependencies, exportedDeclarations, icCache.data)
|
||||
|
||||
icData.writeTo(File(cachePath))
|
||||
|
||||
CacheInfo(cachePath, mainModule.lib.libraryFile.absolutePath, md5).save()
|
||||
CacheInfo(cachePath, mainModule.libPath, md5).save()
|
||||
}
|
||||
|
||||
private fun File.md5(additional: Iterable<ULong> = emptyList()): ULong {
|
||||
@@ -94,11 +90,12 @@ private fun File.md5(additional: Iterable<ULong> = emptyList()): ULong {
|
||||
}
|
||||
|
||||
fun checkCaches(
|
||||
allDependencies: KotlinLibraryResolveResult,
|
||||
dependencies: Collection<String>,
|
||||
cachePaths: List<String>,
|
||||
skipLib: String? = null,
|
||||
): IcCacheInfo {
|
||||
val allLibs = allDependencies.getFullList().map { it.libraryFile.absolutePath }.toSet() - skipLib
|
||||
val skipLibPath = File(skipLib).canonicalPath
|
||||
val allLibs = dependencies.map { File(it).canonicalPath }.toSet() - skipLibPath
|
||||
|
||||
val caches = cachePaths.map { CacheInfo.load(it) ?: error("Cannot load IC cache from ${it}") }
|
||||
|
||||
|
||||
@@ -14,12 +14,15 @@ import org.jetbrains.kotlin.ir.backend.js.lower.generateTests
|
||||
import org.jetbrains.kotlin.ir.backend.js.lower.moveBodilessDeclarationsToSeparatePlace
|
||||
import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsIrLinker
|
||||
import org.jetbrains.kotlin.ir.backend.js.transformers.irToJs.IrModuleToJsTransformer
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
||||
import org.jetbrains.kotlin.ir.declarations.StageController
|
||||
import org.jetbrains.kotlin.ir.declarations.path
|
||||
import org.jetbrains.kotlin.ir.declarations.persistent.PersistentIrFactory
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.ir.util.ExternalDependenciesGenerator
|
||||
import org.jetbrains.kotlin.ir.util.KotlinLikeDumpOptions
|
||||
import org.jetbrains.kotlin.ir.util.dumpKotlinLike
|
||||
import org.jetbrains.kotlin.ir.util.noUnboundLeft
|
||||
import org.jetbrains.kotlin.js.config.RuntimeDiagnostic
|
||||
import org.jetbrains.kotlin.library.KotlinLibrary
|
||||
import org.jetbrains.kotlin.library.resolver.KotlinLibraryResolveResult
|
||||
import org.jetbrains.kotlin.library.resolver.KotlinResolvedLibrary
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import java.io.PrintWriter
|
||||
@@ -28,9 +31,9 @@ fun prepareSingleLibraryIcCache(
|
||||
project: Project,
|
||||
analyzer: AbstractAnalyzerWithCompilerReport,
|
||||
configuration: CompilerConfiguration,
|
||||
library: KotlinLibrary,
|
||||
dependencies: KotlinLibraryResolveResult,
|
||||
friendDependencies: List<KotlinLibrary> = emptyList(),
|
||||
libPath: String,
|
||||
dependencies: Collection<String>,
|
||||
friendDependencies: Collection<String> = emptyList(),
|
||||
exportedDeclarations: Set<FqName> = emptySet(),
|
||||
icCache: Map<String, SerializedIcData> = emptyMap(),
|
||||
): SerializedIcData {
|
||||
@@ -40,7 +43,7 @@ fun prepareSingleLibraryIcCache(
|
||||
|
||||
val (context, deserializer, allModules) = prepareIr(
|
||||
project,
|
||||
MainModule.Klib(library),
|
||||
MainModule.Klib(libPath),
|
||||
analyzer,
|
||||
configuration,
|
||||
dependencies,
|
||||
@@ -119,8 +122,8 @@ fun icCompile(
|
||||
mainModule: MainModule,
|
||||
analyzer: AbstractAnalyzerWithCompilerReport,
|
||||
configuration: CompilerConfiguration,
|
||||
allDependencies: KotlinLibraryResolveResult,
|
||||
friendDependencies: List<KotlinLibrary>,
|
||||
dependencies: Collection<String>,
|
||||
friendDependencies: Collection<String>,
|
||||
mainArguments: List<String>?,
|
||||
exportedDeclarations: Set<FqName> = emptySet(),
|
||||
generateFullJs: Boolean = true,
|
||||
@@ -143,7 +146,7 @@ fun icCompile(
|
||||
mainModule,
|
||||
analyzer,
|
||||
configuration,
|
||||
allDependencies,
|
||||
dependencies,
|
||||
friendDependencies,
|
||||
exportedDeclarations,
|
||||
dceRuntimeDiagnostic,
|
||||
@@ -212,8 +215,8 @@ private fun prepareIr(
|
||||
mainModule: MainModule,
|
||||
analyzer: AbstractAnalyzerWithCompilerReport,
|
||||
configuration: CompilerConfiguration,
|
||||
allDependencies: KotlinLibraryResolveResult,
|
||||
friendDependencies: List<KotlinLibrary>,
|
||||
dependencies: Collection<String>,
|
||||
friendDependencies: Collection<String>,
|
||||
exportedDeclarations: Set<FqName> = emptySet(),
|
||||
dceRuntimeDiagnostic: RuntimeDiagnostic? = null,
|
||||
es6mode: Boolean = false,
|
||||
@@ -234,7 +237,7 @@ private fun prepareIr(
|
||||
}
|
||||
|
||||
val (moduleFragment: IrModuleFragment, dependencyModules, irBuiltIns, symbolTable, deserializer, moduleToName, loweredIrLoaded) =
|
||||
loadIr(project, mainModule, analyzer, configuration, allDependencies, friendDependencies, irFactory, cacheProvider)
|
||||
loadIr(project, mainModule, analyzer, configuration, dependencies, friendDependencies, irFactory, false, cacheProvider)
|
||||
|
||||
val moduleDescriptor = moduleFragment.descriptor
|
||||
|
||||
|
||||
@@ -171,9 +171,7 @@ sealed class IdSignature {
|
||||
|
||||
override fun isPackageSignature(): Boolean = true
|
||||
|
||||
override fun topLevelSignature(): IdSignature {
|
||||
error("Should not reach here ($this)")
|
||||
}
|
||||
override fun topLevelSignature(): IdSignature = this
|
||||
|
||||
override fun nearestPublicSig(): IdSignature {
|
||||
error("Should not reach here ($this)")
|
||||
|
||||
@@ -19,7 +19,8 @@ package org.jetbrains.kotlin.backend.common.overrides
|
||||
import org.jetbrains.kotlin.backend.common.serialization.CompatibilityMode
|
||||
import org.jetbrains.kotlin.backend.common.serialization.DeclarationTable
|
||||
import org.jetbrains.kotlin.backend.common.serialization.GlobalDeclarationTable
|
||||
import org.jetbrains.kotlin.ir.IrBuiltIns
|
||||
import org.jetbrains.kotlin.backend.common.serialization.signature.IdSignatureSerializer
|
||||
import org.jetbrains.kotlin.backend.common.serialization.signature.PublicIdSignatureComputer
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.overrides.FakeOverrideBuilderStrategy
|
||||
import org.jetbrains.kotlin.ir.overrides.IrOverridingUtil
|
||||
@@ -28,11 +29,7 @@ import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.IrPropertySymbolImpl
|
||||
import org.jetbrains.kotlin.ir.types.IrTypeSystemContext
|
||||
import org.jetbrains.kotlin.ir.types.getClass
|
||||
import org.jetbrains.kotlin.ir.util.IdSignature
|
||||
import org.jetbrains.kotlin.ir.util.KotlinMangler
|
||||
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||
import org.jetbrains.kotlin.ir.util.fileOrNull
|
||||
import org.jetbrains.kotlin.ir.util.parentAsClass
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
|
||||
class FakeOverrideGlobalDeclarationTable(
|
||||
mangler: KotlinMangler.IrMangler
|
||||
@@ -71,16 +68,16 @@ class FakeOverrideBuilder(
|
||||
val symbolTable: SymbolTable,
|
||||
mangler: KotlinMangler.IrMangler,
|
||||
typeSystem: IrTypeSystemContext,
|
||||
irBuiltIns: IrBuiltIns,
|
||||
val platformSpecificClassFilter: FakeOverrideClassFilter = DefaultFakeOverrideClassFilter,
|
||||
val signatureSerializerFactory: (PublicIdSignatureComputer, DeclarationTable) -> IdSignatureSerializer = ::IdSignatureSerializer,
|
||||
private val fakeOverrideDeclarationTable: DeclarationTable = FakeOverrideDeclarationTable(mangler, signatureSerializerFactory),
|
||||
) : FakeOverrideBuilderStrategy() {
|
||||
private val haveFakeOverrides = mutableSetOf<IrClass>()
|
||||
|
||||
private val irOverridingUtil = IrOverridingUtil(typeSystem, this)
|
||||
|
||||
// TODO: The declaration table is needed for the signaturer.
|
||||
private val fakeOverrideDeclarationTable = FakeOverrideDeclarationTable(mangler, signatureSerializerFactory)
|
||||
// private val fakeOverrideDeclarationTable = FakeOverrideDeclarationTable(mangler, signatureSerializerFactory)
|
||||
|
||||
private val fakeOverrideCandidates = mutableMapOf<IrClass, CompatibilityMode>()
|
||||
fun enqueueClass(clazz: IrClass, signature: IdSignature, compatibilityMode: CompatibilityMode) {
|
||||
|
||||
@@ -11,8 +11,9 @@ import org.jetbrains.kotlin.ir.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.ir.declarations.IrSymbolOwner
|
||||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltInsOverDescriptors
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.ir.util.IdSignature
|
||||
import org.jetbrains.kotlin.ir.util.KotlinMangler
|
||||
import org.jetbrains.kotlin.ir.util.render
|
||||
|
||||
|
||||
interface IdSignatureClashTracker {
|
||||
@@ -36,7 +37,7 @@ abstract class GlobalDeclarationTable(
|
||||
constructor(mangler: KotlinMangler.IrMangler) : this(mangler, IdSignatureClashTracker.DEFAULT_TRACKER)
|
||||
|
||||
protected fun loadKnownBuiltins(builtIns: IrBuiltIns) {
|
||||
(builtIns as IrBuiltInsOverDescriptors).knownBuiltins.forEach {
|
||||
builtIns.knownBuiltins.forEach {
|
||||
val symbol = (it as IrSymbolOwner).symbol
|
||||
table[it] = symbol.signature!!.also { id -> clashTracker.commit(it, id) }
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ import org.jetbrains.kotlin.descriptors.PropertyAccessorDescriptor
|
||||
import org.jetbrains.kotlin.ir.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
||||
import org.jetbrains.kotlin.ir.declarations.IrSymbolOwner
|
||||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltInsOverDescriptors
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
||||
import org.jetbrains.kotlin.ir.util.IdSignature
|
||||
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||
@@ -132,7 +131,7 @@ class CurrentModuleWithICDeserializer(
|
||||
}
|
||||
|
||||
override fun init(delegate: IrModuleDeserializer) {
|
||||
val knownBuiltIns = (irBuiltIns as IrBuiltInsOverDescriptors).knownBuiltins.map { (it as IrSymbolOwner).symbol }.toSet()
|
||||
val knownBuiltIns = irBuiltIns.knownBuiltins.map { (it as IrSymbolOwner).symbol }.toSet()
|
||||
symbolTable.forEachPublicSymbol {
|
||||
if (it.descriptor.isDirtyDescriptor()) { // public && non-deserialized should be dirty symbol
|
||||
if (it !in knownBuiltIns) {
|
||||
|
||||
@@ -95,7 +95,7 @@ abstract class IrModuleDeserializer(val moduleDescriptor: ModuleDescriptor, val
|
||||
}
|
||||
|
||||
// Used to resolve built in symbols like `kotlin.ir.internal.*` or `kotlin.FunctionN`
|
||||
class IrModuleDeserializerWithBuiltIns(
|
||||
open class IrModuleDeserializerWithBuiltIns(
|
||||
private val builtIns: IrBuiltIns,
|
||||
private val delegate: IrModuleDeserializer
|
||||
) : IrModuleDeserializer(delegate.moduleDescriptor, delegate.libraryAbiVersion) {
|
||||
|
||||
@@ -8,10 +8,6 @@ package org.jetbrains.kotlin.backend.common.serialization
|
||||
import org.jetbrains.kotlin.backend.common.serialization.encodings.BinarySymbolData
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.Actual
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IdSignature.IdsigCase.*
|
||||
import org.jetbrains.kotlin.ir.symbols.IrFileSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ParameterDescriptor
|
||||
import org.jetbrains.kotlin.ir.declarations.IrAnonymousInitializer
|
||||
@@ -26,11 +22,11 @@ import org.jetbrains.kotlin.backend.common.serialization.proto.AccessorIdSignatu
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.CommonIdSignature as ProtoCommonIdSignature
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.CompositeSignature as ProtoCompositeSignature
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.FileLocalIdSignature as ProtoFileLocalIdSignature
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.ScopeLocalIdSignature as ProtoScopeLocalIdSignature
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.FileSignature as ProtoFileSignature
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IdSignature as ProtoIdSignature
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.LocalSignature as ProtoLocalSignature
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.LoweredIdSignature as ProtoLoweredIdSignature
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.ScopeLocalIdSignature as ProtoScopeLocalIdSignature
|
||||
|
||||
class IrSymbolDeserializer(
|
||||
val symbolTable: ReferenceSymbolTable,
|
||||
|
||||
@@ -18,7 +18,6 @@ import org.jetbrains.kotlin.ir.util.IdSignature
|
||||
import org.jetbrains.kotlin.ir.util.KotlinMangler
|
||||
import org.jetbrains.kotlin.ir.util.isFacadeClass
|
||||
import org.jetbrains.kotlin.ir.util.render
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.acceptVoid
|
||||
|
||||
@@ -283,8 +282,8 @@ open class IdSignatureSerializer(
|
||||
}
|
||||
}
|
||||
|
||||
protected open fun IrDeclaration.createFileLocalSignature(parentSignature: IdSignature, localIndex: Long): IdSignature {
|
||||
return IdSignature.FileLocalSignature(parentSignature, localIndex)
|
||||
protected open fun IrDeclaration.createFileLocalSignature(parentSignature: IdSignature, localIndex: Long, description: String? = null): IdSignature {
|
||||
return IdSignature.FileLocalSignature(parentSignature, localIndex, description)
|
||||
}
|
||||
|
||||
protected open fun IrDeclaration.createScopeLocalSignature(scopeIndex: Int, description: String): IdSignature {
|
||||
|
||||
@@ -75,10 +75,11 @@ class IcFileDeserializer(
|
||||
linker.fakeOverrideBuilder.platformSpecificClassFilter,
|
||||
linker.fakeOverrideBuilder,
|
||||
allowRedeclaration = true,
|
||||
compatibilityMode = CompatibilityMode.CURRENT
|
||||
)
|
||||
|
||||
private fun deserializeOriginalPublicSymbol(idSig: IdSignature, symbolKind: BinarySymbolData.SymbolKind): IrSymbol {
|
||||
assert(idSig.isPublic)
|
||||
assert(idSig.isPubliclyVisible)
|
||||
|
||||
val topLevelSig = idSig.topLevelSignature()
|
||||
|
||||
@@ -172,6 +173,7 @@ class IcFileDeserializer(
|
||||
additionalStatementOriginIndex = additionalStatementOriginIndex,
|
||||
allowErrorStatementOrigins = true,
|
||||
allowRedeclaration = true,
|
||||
compatibilityMode = CompatibilityMode.CURRENT
|
||||
)
|
||||
|
||||
private val protoFile: ProtoIrFile by lazy { ProtoIrFile.parseFrom(icFileData.file.fileData.codedInputStream, ExtensionRegistryLite.newInstance()) }
|
||||
@@ -220,6 +222,7 @@ class IcFileDeserializer(
|
||||
|
||||
private fun deserializePublicSymbol(idSig: IdSignature, kind: BinarySymbolData.SymbolKind) : IrSymbol {
|
||||
// TODO: reference lowered declarations cross-module
|
||||
if (kind == BinarySymbolData.SymbolKind.FILE_SYMBOL) return (idSig as IdSignature.FileSignature).fileSymbol
|
||||
val topLevelSig = idSig.topLevelSignature()
|
||||
val actualModuleDeserializer =
|
||||
moduleDeserializer.findModuleDeserializerForTopLevelId(topLevelSig) ?:
|
||||
@@ -314,4 +317,6 @@ private class FileReaderFromSerializedIrFile(val irFile: SerializedIrFile) : IrL
|
||||
override fun string(index: Int): ByteArray = stringReader.tableItemBytes(index)
|
||||
|
||||
override fun body(index: Int): ByteArray = bodyReader.tableItemBytes(index)
|
||||
|
||||
override fun debugInfo(index: Int): ByteArray? = null
|
||||
}
|
||||
@@ -13,16 +13,15 @@ import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsIrLinker
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrModuleFragmentImpl
|
||||
import org.jetbrains.kotlin.ir.declarations.persistent.PersistentIrFactory
|
||||
import org.jetbrains.kotlin.ir.symbols.IrFileSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
||||
import org.jetbrains.kotlin.ir.util.IdSignature
|
||||
import org.jetbrains.kotlin.ir.util.isEffectivelyExternal
|
||||
import org.jetbrains.kotlin.library.IrLibrary
|
||||
import org.jetbrains.kotlin.library.KotlinAbiVersion
|
||||
import org.jetbrains.kotlin.library.impl.IrLongArrayMemoryReader
|
||||
import org.jetbrains.kotlin.protobuf.ExtensionRegistryLite
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.IrFile as ProtoFile
|
||||
|
||||
class IcModuleDeserializer(
|
||||
@@ -35,7 +34,7 @@ class IcModuleDeserializer(
|
||||
override val strategy: DeserializationStrategy,
|
||||
private val containsErrorCode: Boolean = false,
|
||||
private val useGlobalSignatures: Boolean = false,
|
||||
) : IrModuleDeserializer(moduleDescriptor) {
|
||||
) : IrModuleDeserializer(moduleDescriptor, KotlinAbiVersion.CURRENT) {
|
||||
|
||||
private val fileToDeserializerMap = mutableMapOf<IrFile, IrFileDeserializer>()
|
||||
|
||||
@@ -95,7 +94,7 @@ class IcModuleDeserializer(
|
||||
override fun contains(idSig: IdSignature): Boolean = idSig in moduleReversedFileIndex || idSig in icModuleReversedFileIndex
|
||||
|
||||
override fun deserializeIrSymbol(idSig: IdSignature, symbolKind: BinarySymbolData.SymbolKind): IrSymbol {
|
||||
assert(idSig.isPublic)
|
||||
assert(idSig.isPubliclyVisible)
|
||||
|
||||
if (idSig in icModuleReversedFileIndex) {
|
||||
val icDeserializer = icModuleReversedFileIndex[idSig]!!
|
||||
|
||||
@@ -5,10 +5,11 @@
|
||||
|
||||
package org.jetbrains.kotlin.ir.backend.js.ic
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.serialization.CompatibilityMode
|
||||
import org.jetbrains.kotlin.backend.common.serialization.DeclarationTable
|
||||
import org.jetbrains.kotlin.backend.common.serialization.IdSignatureClashTracker
|
||||
import org.jetbrains.kotlin.backend.common.serialization.signature.IdSignatureSerializer
|
||||
import org.jetbrains.kotlin.backend.common.serialization.signature.PublicIdSignatureComputer
|
||||
import org.jetbrains.kotlin.ir.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.backend.js.JsMapping
|
||||
import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsGlobalDeclarationTable
|
||||
@@ -18,11 +19,13 @@ import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.declarations.persistent.PersistentIrBodyBase
|
||||
import org.jetbrains.kotlin.ir.declarations.persistent.PersistentIrDeclarationBase
|
||||
import org.jetbrains.kotlin.ir.declarations.persistent.PersistentIrFactory
|
||||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
|
||||
import org.jetbrains.kotlin.ir.serialization.serializeCarriers
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.ir.util.IdSignature
|
||||
import org.jetbrains.kotlin.ir.util.file
|
||||
import org.jetbrains.kotlin.ir.util.fileOrNull
|
||||
import org.jetbrains.kotlin.ir.util.isFakeOverride
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.acceptVoid
|
||||
@@ -88,45 +91,48 @@ class IcSerializer(
|
||||
skipExpects = true,
|
||||
icMode = true,
|
||||
allowNullTypes = true,
|
||||
allowErrorStatementOrigins = true
|
||||
allowErrorStatementOrigins = true,
|
||||
compatibilityMode = CompatibilityMode.CURRENT
|
||||
)
|
||||
|
||||
bodies.forEach { body ->
|
||||
if (body is IrExpressionBody) {
|
||||
fileSerializer.serializeIrExpressionBody(body.expression)
|
||||
} else {
|
||||
fileSerializer.serializeIrStatementBody(body)
|
||||
icDeclarationTable.inFile(file) {
|
||||
bodies.forEach { body ->
|
||||
if (body is IrExpressionBody) {
|
||||
fileSerializer.serializeIrExpressionBody(body.expression)
|
||||
} else {
|
||||
fileSerializer.serializeIrStatementBody(body)
|
||||
}
|
||||
}
|
||||
|
||||
// Only save newly created declarations
|
||||
val newDeclarations = fileDeclarations.filter { d ->
|
||||
d is PersistentIrDeclarationBase<*> && (d.createdOn > 0 || /*d.isFakeOverride ||*/ (d is IrValueParameter || d is IrTypeParameter) && (d.parent as IrDeclaration).isFakeOverride)
|
||||
}
|
||||
|
||||
val serializedCarriers = fileSerializer.serializeCarriers(
|
||||
fileDeclarations,
|
||||
bodies,
|
||||
) { declaration ->
|
||||
icDeclarationTable.signatureByDeclaration(declaration, compatibleMode = false)
|
||||
}
|
||||
|
||||
val serializedMappings = mappings.state.serializeMappings(fileDeclarations) { symbol ->
|
||||
fileSerializer.serializeIrSymbol(symbol)
|
||||
}
|
||||
|
||||
val order = storeOrder(file) { symbol ->
|
||||
fileSerializer.serializeIrSymbol(symbol)
|
||||
}
|
||||
|
||||
val serializedIrFile = fileSerializer.serializeDeclarationsForIC(file, newDeclarations)
|
||||
|
||||
icData += SerializedIcDataForFile(
|
||||
serializedIrFile,
|
||||
serializedCarriers,
|
||||
serializedMappings,
|
||||
order,
|
||||
)
|
||||
}
|
||||
|
||||
// Only save newly created declarations
|
||||
val newDeclarations = fileDeclarations.filter { d ->
|
||||
d is PersistentIrDeclarationBase<*> && (d.createdOn > 0 || /*d.isFakeOverride ||*/ (d is IrValueParameter || d is IrTypeParameter) && (d.parent as IrDeclaration).isFakeOverride)
|
||||
}
|
||||
|
||||
val serializedCarriers = fileSerializer.serializeCarriers(
|
||||
fileDeclarations,
|
||||
bodies,
|
||||
) { declaration ->
|
||||
icDeclarationTable.signatureByDeclaration(declaration)
|
||||
}
|
||||
|
||||
val serializedMappings = mappings.state.serializeMappings(fileDeclarations) { symbol ->
|
||||
fileSerializer.serializeIrSymbol(symbol)
|
||||
}
|
||||
|
||||
val order = storeOrder(file) { symbol ->
|
||||
fileSerializer.serializeIrSymbol(symbol)
|
||||
}
|
||||
|
||||
val serializedIrFile = fileSerializer.serializeDeclarationsForIC(file, newDeclarations)
|
||||
|
||||
icData += SerializedIcDataForFile(
|
||||
serializedIrFile,
|
||||
serializedCarriers,
|
||||
serializedMappings,
|
||||
order,
|
||||
)
|
||||
}
|
||||
|
||||
return SerializedIcData(icData)
|
||||
@@ -143,9 +149,9 @@ class IcSerializer(
|
||||
|
||||
override val signaturer: IdSignatureSerializer = IdSignatureSerializerWithForIC(globalDeclarationTable.publicIdSignatureComputer, this, newLocalIndex, newScopeIndex)
|
||||
|
||||
override fun signatureByDeclaration(declaration: IrDeclaration): IdSignature {
|
||||
override fun signatureByDeclaration(declaration: IrDeclaration, compatibleMode: Boolean): IdSignature {
|
||||
return existingMappings.getOrPut(declaration.symbol) {
|
||||
irFactory.declarationSignature(declaration) ?: super.signatureByDeclaration(declaration)
|
||||
irFactory.declarationSignature(declaration) ?: super.signatureByDeclaration(declaration, compatibleMode)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -165,7 +171,7 @@ class IdSignatureSerializerWithForIC(
|
||||
scopeIndex = scopeIndexOffset
|
||||
}
|
||||
|
||||
override fun IrDeclaration.createFileLocalSignature(parentSignature: IdSignature, localIndex: Long): IdSignature {
|
||||
override fun IrDeclaration.createFileLocalSignature(parentSignature: IdSignature, localIndex: Long, description: String?): IdSignature {
|
||||
if (this is IrTypeParameter) {
|
||||
return IdSignature.GlobalFileLocalSignature(parentSignature, 1000_000_000_000L + index, fileOrNull?.path ?: "")
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ import org.jetbrains.kotlin.library.impl.IrArrayMemoryReader
|
||||
import org.jetbrains.kotlin.library.impl.IrMemoryArrayWriter
|
||||
import org.jetbrains.kotlin.library.impl.toArray
|
||||
import java.io.File
|
||||
import java.nio.charset.Charset
|
||||
|
||||
class SerializedIcData(
|
||||
val files: Collection<SerializedIcDataForFile>,
|
||||
@@ -85,7 +84,8 @@ fun File.readIcData(): SerializedIcData {
|
||||
signatures = File(fileDir, "file.signatures").readBytes(),
|
||||
strings = File(fileDir, "file.strings").readBytes(),
|
||||
bodies = File(fileDir, "file.bodies").readBytes(),
|
||||
declarations = File(fileDir, "file.declarations").readBytes()
|
||||
declarations = File(fileDir, "file.declarations").readBytes(),
|
||||
debugInfo = null
|
||||
)
|
||||
|
||||
val carriers = SerializedCarriers(
|
||||
|
||||
@@ -171,7 +171,7 @@ fun generateKLib(
|
||||
val depsDescriptors =
|
||||
ModulesStructure(project, MainModule.SourceFiles(files), analyzer, configuration, dependencies, friendDependencies, EmptyLoweringsCacheProvider)
|
||||
val allDependencies = depsDescriptors.allDependencies
|
||||
val (psi2IrContext, hasErrors) = runAnalysisAndPreparePsi2Ir(depsDescriptors, SymbolTable(IdSignatureDescriptor(JsManglerDesc), irFactory, errorPolicy)
|
||||
val (psi2IrContext, hasErrors) = runAnalysisAndPreparePsi2Ir(depsDescriptors, errorPolicy, SymbolTable(IdSignatureDescriptor(JsManglerDesc), irFactory))
|
||||
val irBuiltIns = psi2IrContext.irBuiltIns
|
||||
|
||||
val expectDescriptorToSymbol = mutableMapOf<DeclarationDescriptor, IrSymbol>()
|
||||
@@ -255,6 +255,7 @@ object EmptyLoweringsCacheProvider : LoweringsCacheProvider {
|
||||
override fun cacheByPath(path: String): SerializedIcData? = null
|
||||
}
|
||||
|
||||
@OptIn(ObsoleteDescriptorBasedAPI::class)
|
||||
fun loadIr(
|
||||
project: Project,
|
||||
mainModule: MainModule,
|
||||
@@ -278,13 +279,11 @@ fun loadIr(
|
||||
is MainModule.SourceFiles -> {
|
||||
val (psi2IrContext, _) = runAnalysisAndPreparePsi2Ir(depsDescriptors, errorPolicy, symbolTable)
|
||||
val irBuiltIns = psi2IrContext.irBuiltIns
|
||||
val symbolTable = psi2IrContext.symbolTable
|
||||
val feContext = psi2IrContext.run {
|
||||
JsIrLinker.JsFePluginContext(moduleDescriptor, symbolTable, typeTranslator, irBuiltIns)
|
||||
}
|
||||
val moduleFragmentToUniqueName = mutableMapOf<IrModuleFragment, String>()
|
||||
val irLinker =
|
||||
JsIrLinker(psi2IrContext.moduleDescriptor, messageLogger, irBuiltIns, symbolTable, feContext, null)
|
||||
JsIrLinker(
|
||||
psi2IrContext.moduleDescriptor,
|
||||
messageLogger,
|
||||
@@ -322,19 +321,18 @@ fun loadIr(
|
||||
}
|
||||
|
||||
if (verifySignatures) {
|
||||
(irBuiltIns as IrBuiltInsOverDescriptors).knownBuiltins.forEach { it.acceptVoid(mangleChecker) }
|
||||
irBuiltIns.knownBuiltins.forEach { it.acceptVoid(mangleChecker) }
|
||||
}
|
||||
|
||||
return IrModuleInfo(moduleFragment, deserializedModuleFragments, irBuiltIns, symbolTable, irLinker, moduleFragmentToUniqueName,
|
||||
depsDescriptors.modulesWithCaches(deserializedModuleFragments))
|
||||
}
|
||||
is MainModule.Klib -> {
|
||||
val mainModuleLib = depsDescriptors.allDependencies.find { it.library.libraryFile.canonicalPath == mainModule.libPath }?.library
|
||||
?: error("No module with ${mainModule.libPath} found")
|
||||
val mainPath = File(mainModule.libPath).canonicalPath
|
||||
val mainModuleLib =
|
||||
depsDescriptors.allDependencies.find { it.library.libraryFile.canonicalPath == mainPath }?.library
|
||||
?: error("No module with ${mainModule.libPath} found")
|
||||
val moduleDescriptor = depsDescriptors.getModuleDescriptor(mainModuleLib)
|
||||
val mangler = JsManglerDesc
|
||||
val signaturer = IdSignatureDescriptor(mangler)
|
||||
val symbolTable = SymbolTable(signaturer, irFactory)
|
||||
val typeTranslator =
|
||||
TypeTranslatorImpl(symbolTable, depsDescriptors.compilerConfiguration.languageVersionSettings, moduleDescriptor)
|
||||
val irBuiltIns = IrBuiltInsOverDescriptors(moduleDescriptor.builtIns, typeTranslator, symbolTable)
|
||||
@@ -346,7 +344,8 @@ fun loadIr(
|
||||
val path = lib.libraryFile.absolutePath
|
||||
val icData = loweringsCacheProvider.cacheByPath(path)
|
||||
if (icData != null) {
|
||||
result[depsDescriptors.getModuleDescriptor(lib)] = icData
|
||||
val desc = depsDescriptors.getModuleDescriptor(lib)
|
||||
result[desc] = icData
|
||||
}
|
||||
}
|
||||
|
||||
@@ -367,7 +366,11 @@ fun loadIr(
|
||||
|
||||
val moduleFragmentToUniqueName = mutableMapOf<IrModuleFragment, String>()
|
||||
|
||||
val deserializedModuleFragments = sortDependencies(allDependencies, depsDescriptors.descriptors).map { klib ->
|
||||
val reachableDependencies = depsDescriptors.allResolvedDependencies.filterRoots {
|
||||
it.library.libraryFile.canonicalPath == mainPath
|
||||
}
|
||||
|
||||
val deserializedModuleFragments = sortDependencies(reachableDependencies.getFullResolvedList(), depsDescriptors.descriptors).map { klib ->
|
||||
val strategy =
|
||||
if (klib == mainModuleLib)
|
||||
DeserializationStrategy.ALL
|
||||
@@ -478,11 +481,13 @@ private class ModulesStructure(
|
||||
friendDependenciesPaths: Collection<String>,
|
||||
private val loweringsCacheProvider: LoweringsCacheProvider
|
||||
) {
|
||||
val allDependencies = jsResolveLibraries(
|
||||
val allResolvedDependencies = jsResolveLibraries(
|
||||
dependencies,
|
||||
compilerConfiguration[JSConfigurationKeys.REPOSITORIES] ?: emptyList(),
|
||||
compilerConfiguration[IrMessageLogger.IR_MESSAGE_LOGGER].toResolverLogger()
|
||||
).getFullResolvedList()
|
||||
)
|
||||
|
||||
val allDependencies = allResolvedDependencies.getFullResolvedList()
|
||||
|
||||
val friendDependencies = allDependencies.run {
|
||||
val friendAbsolutePaths = friendDependenciesPaths.map { File(it).canonicalPath }
|
||||
|
||||
@@ -9,19 +9,17 @@ import org.jetbrains.kotlin.backend.common.serialization.IrModuleDeserializer
|
||||
import org.jetbrains.kotlin.backend.common.serialization.IrModuleDeserializerWithBuiltIns
|
||||
import org.jetbrains.kotlin.backend.common.serialization.encodings.BinarySymbolData
|
||||
import org.jetbrains.kotlin.backend.common.serialization.knownBuiltins
|
||||
import org.jetbrains.kotlin.ir.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
|
||||
import org.jetbrains.kotlin.ir.declarations.IrSymbolOwner
|
||||
import org.jetbrains.kotlin.ir.declarations.IrTypeParametersContainer
|
||||
import org.jetbrains.kotlin.ir.descriptors.IrAbstractFunctionFactory
|
||||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
||||
import org.jetbrains.kotlin.ir.util.IdSignature
|
||||
|
||||
class IrIcModuleDeserializerWithBuiltIns(
|
||||
builtIns: IrBuiltIns,
|
||||
functionFactory: IrAbstractFunctionFactory,
|
||||
delegate: IrModuleDeserializer,
|
||||
) : IrModuleDeserializerWithBuiltIns(builtIns, functionFactory, delegate) {
|
||||
) : IrModuleDeserializerWithBuiltIns(builtIns, delegate) {
|
||||
|
||||
override fun additionalBuiltIns(builtIns: IrBuiltIns): Map<IdSignature, IrSymbol> {
|
||||
val result = mutableMapOf<IdSignature, IrSymbol>()
|
||||
|
||||
@@ -9,16 +9,14 @@ import org.jetbrains.kotlin.backend.common.overrides.FakeOverrideBuilder
|
||||
import org.jetbrains.kotlin.backend.common.serialization.*
|
||||
import org.jetbrains.kotlin.backend.common.serialization.signature.IdSignatureSerializer
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.ir.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.backend.js.JsMapping
|
||||
import org.jetbrains.kotlin.ir.backend.js.ic.IcModuleDeserializer
|
||||
import org.jetbrains.kotlin.ir.backend.js.ic.IdSignatureSerializerWithForIC
|
||||
import org.jetbrains.kotlin.ir.backend.js.ic.SerializedIcData
|
||||
import org.jetbrains.kotlin.ir.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.builders.TranslationPluginContext
|
||||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
||||
import org.jetbrains.kotlin.ir.declarations.persistent.PersistentIrFactory
|
||||
import org.jetbrains.kotlin.ir.descriptors.IrAbstractFunctionFactory
|
||||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.types.IrTypeSystemContextImpl
|
||||
import org.jetbrains.kotlin.ir.util.IrMessageLogger
|
||||
import org.jetbrains.kotlin.ir.util.ReferenceSymbolTable
|
||||
@@ -37,10 +35,14 @@ class JsIrLinker(
|
||||
private val useGlobalSignatures: Boolean = false,
|
||||
) : KotlinIrLinker(currentModule, messageLogger, builtIns, symbolTable, emptyList()) {
|
||||
|
||||
override val fakeOverrideBuilder = FakeOverrideBuilder(this, symbolTable, JsManglerIr, IrTypeSystemContextImpl(builtIns),
|
||||
signatureSerializerFactory = { publicSignatureBuilder, table ->
|
||||
if (useGlobalSignatures) IdSignatureSerializerWithForIC(publicSignatureBuilder, table) else IdSignatureSerializer(publicSignatureBuilder, table)
|
||||
})
|
||||
override val fakeOverrideBuilder = FakeOverrideBuilder(
|
||||
this, symbolTable, JsManglerIr, IrTypeSystemContextImpl(builtIns), signatureSerializerFactory = { publicSignatureBuilder, table ->
|
||||
if (useGlobalSignatures) IdSignatureSerializerWithForIC(publicSignatureBuilder, table) else IdSignatureSerializer(
|
||||
publicSignatureBuilder,
|
||||
table
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
override fun isBuiltInModule(moduleDescriptor: ModuleDescriptor): Boolean =
|
||||
moduleDescriptor === moduleDescriptor.builtIns.builtInsModule
|
||||
@@ -48,7 +50,7 @@ class JsIrLinker(
|
||||
private val IrLibrary.libContainsErrorCode: Boolean
|
||||
get() = this is KotlinLibrary && this.containsErrorCode
|
||||
|
||||
override fun createModuleDeserializer(moduleDescriptor: ModuleDescriptor, klib: IrLibrary?, strategy: DeserializationStrategy): IrModuleDeserializer {
|
||||
override fun createModuleDeserializer(moduleDescriptor: ModuleDescriptor, klib: KotlinLibrary?, strategy: DeserializationStrategy): IrModuleDeserializer {
|
||||
require(klib != null) { "Expecting kotlin library" }
|
||||
loweredIcData[moduleDescriptor]?.let { loweredIcData ->
|
||||
return IcModuleDeserializer(
|
||||
@@ -63,14 +65,12 @@ class JsIrLinker(
|
||||
useGlobalSignatures = useGlobalSignatures
|
||||
)
|
||||
}
|
||||
return klib?.let { lib ->
|
||||
JsModuleDeserializer(moduleDescriptor, lib, strategy, lib.versions.abiVersion ?: KotlinAbiVersion.CURRENT, lib.libContainsErrorCode)
|
||||
} ?: error("Expecting kotlin library")
|
||||
return JsModuleDeserializer(moduleDescriptor, klib, strategy, klib.versions.abiVersion ?: KotlinAbiVersion.CURRENT, klib.libContainsErrorCode)
|
||||
}
|
||||
|
||||
val mapping: JsMapping by lazy { JsMapping(symbolTable.irFactory) }
|
||||
|
||||
private inner class JsModuleDeserializer(moduleDescriptor: ModuleDescriptor, klib: IrLibrary, strategy: DeserializationStrategy, allowErrorCode: Boolean) :
|
||||
private inner class JsModuleDeserializer(moduleDescriptor: ModuleDescriptor, klib: IrLibrary, strategy: DeserializationStrategy, libraryAbiVersion: KotlinAbiVersion, allowErrorCode: Boolean) :
|
||||
BasicIrModuleDeserializer(this, moduleDescriptor, klib, strategy, libraryAbiVersion, allowErrorCode, useGlobalSignatures)
|
||||
|
||||
override fun maybeWrapWithBuiltInAndInit(
|
||||
@@ -79,9 +79,9 @@ class JsIrLinker(
|
||||
): IrModuleDeserializer {
|
||||
return if (isBuiltInModule(moduleDescriptor)) {
|
||||
if (useGlobalSignatures) {
|
||||
IrIcModuleDeserializerWithBuiltIns(builtIns, functionalInterfaceFactory, moduleDeserializer)
|
||||
IrIcModuleDeserializerWithBuiltIns(builtIns, moduleDeserializer)
|
||||
} else {
|
||||
IrModuleDeserializerWithBuiltIns(builtIns, functionalInterfaceFactory, moduleDeserializer)
|
||||
IrModuleDeserializerWithBuiltIns(builtIns, moduleDeserializer)
|
||||
}
|
||||
} else moduleDeserializer
|
||||
}
|
||||
@@ -103,7 +103,7 @@ class JsIrLinker(
|
||||
|
||||
|
||||
fun moduleDeserializer(moduleDescriptor: ModuleDescriptor): IrModuleDeserializer {
|
||||
return deserializersForModules[moduleDescriptor] ?: error("Deserializer for $moduleDescriptor not found")
|
||||
return deserializersForModules[moduleDescriptor.name.asString()] ?: error("Deserializer for $moduleDescriptor not found")
|
||||
}
|
||||
|
||||
fun loadIcIr(preprocess: (IrModuleFragment) -> Unit) {
|
||||
|
||||
@@ -11,15 +11,19 @@ import org.jetbrains.kotlin.backend.common.overrides.FakeOverrideDeclarationTabl
|
||||
import org.jetbrains.kotlin.backend.common.overrides.FileLocalAwareLinker
|
||||
import org.jetbrains.kotlin.backend.common.serialization.*
|
||||
import org.jetbrains.kotlin.backend.common.serialization.encodings.BinarySymbolData
|
||||
import org.jetbrains.kotlin.backend.common.serialization.signature.IdSignatureSerializer
|
||||
import org.jetbrains.kotlin.backend.jvm.serialization.proto.JvmIr
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.backend.jvm.serialization.JvmDescriptorMangler
|
||||
import org.jetbrains.kotlin.ir.backend.jvm.serialization.JvmIrMangler
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFileImpl
|
||||
import org.jetbrains.kotlin.ir.declarations.lazy.LazyIrFactory
|
||||
import org.jetbrains.kotlin.ir.symbols.*
|
||||
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.IrFileSymbolImpl
|
||||
import org.jetbrains.kotlin.ir.types.IrTypeSystemContext
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
@@ -246,7 +250,7 @@ private fun buildFakeOverridesForLocalClasses(
|
||||
|
||||
class PrePopulatedDeclarationTable(
|
||||
sig2symbol: Map<IdSignature, IrSymbol>
|
||||
) : FakeOverrideDeclarationTable(JvmIrMangler) {
|
||||
) : FakeOverrideDeclarationTable(JvmIrMangler, ::IdSignatureSerializer) {
|
||||
private val symbol2Sig = sig2symbol.entries.associate { (x, y) -> y to x }
|
||||
|
||||
override fun tryComputeBackendSpecificSignature(declaration: IrDeclaration): IdSignature? {
|
||||
|
||||
@@ -126,19 +126,17 @@ abstract class BasicIrBoxTest(
|
||||
val klibPath = outputFile.absolutePath.replace("_v5.js", "/")
|
||||
|
||||
if (isMainModule && klibMainModule) {
|
||||
val resolvedLibraries = jsResolveLibraries(allKlibPaths, emptyList(), messageCollectorLogger(MessageCollector.NONE))
|
||||
|
||||
generateKLib(
|
||||
project = config.project,
|
||||
files = filesToCompile,
|
||||
analyzer = AnalyzerWithCompilerReport(config.configuration),
|
||||
configuration = config.configuration,
|
||||
allDependencies = resolvedLibraries,
|
||||
dependencies = allKlibPaths,
|
||||
friendDependencies = emptyList(),
|
||||
irFactory = IrFactoryImpl,
|
||||
outputKlibPath = klibPath,
|
||||
nopack = true,
|
||||
null
|
||||
jsOutputName = null
|
||||
)
|
||||
|
||||
allKlibPaths += File(klibPath).absolutePath
|
||||
@@ -171,29 +169,27 @@ abstract class BasicIrBoxTest(
|
||||
val mainModule = if (!klibMainModule) {
|
||||
MainModule.SourceFiles(filesToCompile)
|
||||
} else {
|
||||
val mainLib = resolvedLibraries.getFullList().find { it.libraryFile.absolutePath == File(klibPath).absolutePath }!!
|
||||
MainModule.Klib(mainLib)
|
||||
MainModule.Klib(klibPath)
|
||||
}
|
||||
|
||||
if (!skipRegularMode) {
|
||||
val icCache: Map<String, SerializedIcData> = if (!runIcMode) emptyMap() else {
|
||||
val map = mutableMapOf<String, SerializedIcData>()
|
||||
for (klibPath in allKlibPaths) {
|
||||
val icData = predefinedKlibHasIcCache[klibPath] ?: prepareSingleLibraryIcCache(
|
||||
for (path in allKlibPaths) {
|
||||
val icData = predefinedKlibHasIcCache[path] ?: prepareSingleLibraryIcCache(
|
||||
project = project,
|
||||
analyzer = AnalyzerWithCompilerReport(config.configuration),
|
||||
configuration = config.configuration,
|
||||
library = resolvedLibraries.getFullList()
|
||||
.single { it.libraryFile.absolutePath == File(klibPath).absolutePath },
|
||||
dependencies = resolvedLibraries.filterRoots { it.library.libraryFile.absolutePath == File(klibPath).absolutePath },
|
||||
libPath = path,
|
||||
dependencies = allKlibPaths,
|
||||
icCache = map
|
||||
)
|
||||
|
||||
if (klibPath in predefinedKlibHasIcCache) {
|
||||
predefinedKlibHasIcCache[klibPath] = icData
|
||||
if (path in predefinedKlibHasIcCache) {
|
||||
predefinedKlibHasIcCache[path] = icData
|
||||
}
|
||||
|
||||
map[klibPath] = icData
|
||||
map[path] = icData
|
||||
}
|
||||
|
||||
map
|
||||
|
||||
Reference in New Issue
Block a user