[Psi2Ir] Move to new linkage scheme based on IdSignature
Now SymbolTable operates with two types of symbols (public and private) In case of Public symbol IdSignature is used as table key Private one uses descriptor as the key in similar scheme as before
This commit is contained in:
+6
-1
@@ -31,8 +31,10 @@ import org.jetbrains.kotlin.asJava.finder.JavaElementFinder
|
||||
import org.jetbrains.kotlin.backend.common.output.OutputFileCollection
|
||||
import org.jetbrains.kotlin.backend.common.output.SimpleOutputFileCollection
|
||||
import org.jetbrains.kotlin.backend.common.phaser.PhaseConfig
|
||||
import org.jetbrains.kotlin.backend.common.serialization.signature.IdSignatureDescriptor
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory
|
||||
import org.jetbrains.kotlin.backend.jvm.jvmPhases
|
||||
import org.jetbrains.kotlin.backend.jvm.serialization.JvmManglerDesc
|
||||
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
|
||||
import org.jetbrains.kotlin.cli.common.ExitCode
|
||||
import org.jetbrains.kotlin.cli.common.checkKotlinPackageUsage
|
||||
@@ -339,8 +341,11 @@ object KotlinToJVMBytecodeCompiler {
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
val signaturer = IdSignatureDescriptor(JvmManglerDesc())
|
||||
|
||||
val (moduleFragment, symbolTable, sourceManager) =
|
||||
Fir2IrConverter.createModuleFragment(session, firFiles, moduleConfiguration.languageVersionSettings)
|
||||
Fir2IrConverter.createModuleFragment(session, firFiles, moduleConfiguration.languageVersionSettings, signaturer = signaturer)
|
||||
val dummyBindingContext = NoScopeRecordCliBindingTrace().bindingContext
|
||||
|
||||
val codegenFactory = JvmIrCodegenFactory(moduleConfiguration.get(CLIConfigurationKeys.PHASE_CONFIG) ?: PhaseConfig(jvmPhases))
|
||||
|
||||
@@ -24,15 +24,16 @@ object Fir2IrConverter {
|
||||
session: FirSession,
|
||||
firFiles: List<FirFile>,
|
||||
languageVersionSettings: LanguageVersionSettings,
|
||||
fakeOverrideMode: FakeOverrideMode = FakeOverrideMode.NORMAL
|
||||
fakeOverrideMode: FakeOverrideMode = FakeOverrideMode.NORMAL,
|
||||
signaturer: IdSignatureComposer
|
||||
): Fir2IrResult {
|
||||
val moduleDescriptor = FirModuleDescriptor(session)
|
||||
val symbolTable = SymbolTable()
|
||||
val symbolTable = SymbolTable(signaturer)
|
||||
val constantValueGenerator = ConstantValueGenerator(moduleDescriptor, symbolTable)
|
||||
val typeTranslator = TypeTranslator(symbolTable, languageVersionSettings, moduleDescriptor.builtIns)
|
||||
constantValueGenerator.typeTranslator = typeTranslator
|
||||
typeTranslator.constantValueGenerator = constantValueGenerator
|
||||
val builtIns = IrBuiltIns(moduleDescriptor.builtIns, typeTranslator, symbolTable)
|
||||
val builtIns = IrBuiltIns(moduleDescriptor.builtIns, typeTranslator, signaturer, symbolTable)
|
||||
val sourceManager = PsiSourceManager()
|
||||
val fir2irTransformer = Fir2IrVisitor(session, moduleDescriptor, symbolTable, sourceManager, builtIns, fakeOverrideMode)
|
||||
val irFiles = mutableListOf<IrFile>()
|
||||
|
||||
@@ -11,6 +11,8 @@ import com.intellij.psi.PsiElementFinder
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import junit.framework.TestCase
|
||||
import org.jetbrains.kotlin.asJava.finder.JavaElementFinder
|
||||
import org.jetbrains.kotlin.backend.common.serialization.signature.IdSignatureDescriptor
|
||||
import org.jetbrains.kotlin.backend.jvm.serialization.JvmManglerDesc
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM
|
||||
import org.jetbrains.kotlin.config.languageVersionSettings
|
||||
import org.jetbrains.kotlin.fir.backend.Fir2IrConverter
|
||||
@@ -92,8 +94,10 @@ abstract class AbstractFir2IrTextTest : AbstractIrTextTestCase() {
|
||||
}
|
||||
}
|
||||
|
||||
val signaturer = IdSignatureDescriptor(JvmManglerDesc())
|
||||
|
||||
return Fir2IrConverter.createModuleFragment(
|
||||
session, firFiles, myEnvironment.configuration.languageVersionSettings
|
||||
session, firFiles, myEnvironment.configuration.languageVersionSettings, signaturer = signaturer
|
||||
).irModuleFragment
|
||||
}
|
||||
}
|
||||
@@ -11,11 +11,13 @@ import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
|
||||
import org.jetbrains.kotlin.backend.common.phaser.PhaseConfig
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.ClassCodegen
|
||||
import org.jetbrains.kotlin.backend.jvm.lower.MultifileFacadeFileEntry
|
||||
import org.jetbrains.kotlin.backend.jvm.serialization.JvmIdSignatureDescriptor
|
||||
import org.jetbrains.kotlin.backend.jvm.serialization.JvmManglerDesc
|
||||
import org.jetbrains.kotlin.codegen.state.GenerationState
|
||||
import org.jetbrains.kotlin.idea.MainFunctionDetector
|
||||
import org.jetbrains.kotlin.descriptors.konan.KlibModuleOrigin
|
||||
import org.jetbrains.kotlin.ir.backend.jvm.serialization.EmptyLoggingContext
|
||||
import org.jetbrains.kotlin.ir.backend.jvm.serialization.JvmIrLinker
|
||||
import org.jetbrains.kotlin.ir.backend.jvm.serialization.JvmMangler
|
||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
||||
import org.jetbrains.kotlin.ir.types.defaultType
|
||||
@@ -27,7 +29,9 @@ import org.jetbrains.kotlin.psi2ir.PsiSourceManager
|
||||
object JvmBackendFacade {
|
||||
fun doGenerateFiles(files: Collection<KtFile>, state: GenerationState, phaseConfig: PhaseConfig) {
|
||||
val extensions = JvmGeneratorExtensions()
|
||||
val psi2ir = Psi2IrTranslator(state.languageVersionSettings, mangler = JvmMangler)
|
||||
val mangler = JvmManglerDesc(MainFunctionDetector(state.bindingContext, state.languageVersionSettings))
|
||||
val signaturer = JvmIdSignatureDescriptor(mangler)
|
||||
val psi2ir = Psi2IrTranslator(state.languageVersionSettings, signaturer = signaturer)
|
||||
val psi2irContext = psi2ir.createGeneratorContext(state.module, state.bindingContext, extensions = extensions)
|
||||
|
||||
for (extension in IrGenerationExtension.getInstances(state.project)) {
|
||||
|
||||
@@ -35,7 +35,7 @@ typealias Psi2IrPostprocessingStep = (IrModuleFragment) -> Unit
|
||||
class Psi2IrTranslator(
|
||||
val languageVersionSettings: LanguageVersionSettings,
|
||||
val configuration: Psi2IrConfiguration = Psi2IrConfiguration(),
|
||||
val mangler: KotlinMangler? = null
|
||||
val signaturer: IdSignatureComposer
|
||||
) {
|
||||
private val postprocessingSteps = SmartList<Psi2IrPostprocessingStep>()
|
||||
|
||||
@@ -59,10 +59,10 @@ class Psi2IrTranslator(
|
||||
fun createGeneratorContext(
|
||||
moduleDescriptor: ModuleDescriptor,
|
||||
bindingContext: BindingContext,
|
||||
symbolTable: SymbolTable = SymbolTable(mangler),
|
||||
symbolTable: SymbolTable = SymbolTable(signaturer),
|
||||
extensions: GeneratorExtensions = GeneratorExtensions()
|
||||
): GeneratorContext =
|
||||
GeneratorContext(configuration, moduleDescriptor, bindingContext, languageVersionSettings, symbolTable, extensions)
|
||||
GeneratorContext(configuration, moduleDescriptor, bindingContext, languageVersionSettings, symbolTable, extensions, signaturer)
|
||||
|
||||
fun generateModuleFragment(
|
||||
context: GeneratorContext,
|
||||
@@ -73,13 +73,12 @@ class Psi2IrTranslator(
|
||||
val moduleGenerator = ModuleGenerator(context)
|
||||
val irModule = moduleGenerator.generateModuleFragmentWithoutDependencies(ktFiles)
|
||||
|
||||
expectDescriptorToSymbol ?. let { referenceExpectsForUsedActuals(it, context.symbolTable, irModule) }
|
||||
expectDescriptorToSymbol?.let { referenceExpectsForUsedActuals(it, context.symbolTable, irModule) }
|
||||
irModule.patchDeclarationParents()
|
||||
postprocess(context, irModule)
|
||||
// do not generate unbound symbols before postprocessing,
|
||||
// since plugins must work with non-lazy IR
|
||||
moduleGenerator.generateUnboundSymbolsAsDependencies(irProviders)
|
||||
irModule.computeUniqIdForDeclarations(context.symbolTable)
|
||||
|
||||
return irModule
|
||||
}
|
||||
|
||||
+11
-7
@@ -27,6 +27,8 @@ import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrGetValueImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.mapTypeParameters
|
||||
import org.jetbrains.kotlin.ir.expressions.mapValueParameters
|
||||
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.util.declareSimpleFunctionWithOverrides
|
||||
import org.jetbrains.kotlin.ir.util.properties
|
||||
import org.jetbrains.kotlin.ir.util.referenceFunction
|
||||
@@ -200,16 +202,16 @@ class DataClassMembersGenerator(
|
||||
.let { context.symbolTable.referenceFunction(it) }
|
||||
|
||||
|
||||
private fun getHashCodeFunction(type: KotlinType): FunctionDescriptor =
|
||||
private fun getHashCodeFunction(type: KotlinType, symbolResolve: (FunctionDescriptor) -> IrSimpleFunctionSymbol): IrSimpleFunctionSymbol =
|
||||
when (val typeConstructorDescriptor = type.constructor.declarationDescriptor) {
|
||||
is ClassDescriptor ->
|
||||
if (KotlinBuiltIns.isArrayOrPrimitiveArray(typeConstructorDescriptor))
|
||||
context.irBuiltIns.dataClassArrayMemberHashCode
|
||||
context.irBuiltIns.dataClassArrayMemberHashCodeSymbol
|
||||
else
|
||||
type.memberScope.findFirstFunction("hashCode") { it.valueParameters.isEmpty() }
|
||||
symbolResolve(type.memberScope.findFirstFunction("hashCode") { it.valueParameters.isEmpty() })
|
||||
|
||||
is TypeParameterDescriptor ->
|
||||
getHashCodeFunction(typeConstructorDescriptor.representativeUpperBound)
|
||||
getHashCodeFunction(typeConstructorDescriptor.representativeUpperBound, symbolResolve)
|
||||
|
||||
else ->
|
||||
throw AssertionError("Unexpected type: $type")
|
||||
@@ -255,10 +257,12 @@ class DataClassMembersGenerator(
|
||||
}
|
||||
|
||||
private fun MemberFunctionBuilder.getHashCodeOf(kotlinType: KotlinType, irValue: IrExpression): IrExpression {
|
||||
val hashCodeFunctionDescriptor = getHashCodeFunction(kotlinType)
|
||||
val hashCodeFunctionSymbol = declarationGenerator.context.symbolTable.referenceFunction(hashCodeFunctionDescriptor.original)
|
||||
val hashCodeFunctionSymbol = getHashCodeFunction(kotlinType) {
|
||||
declarationGenerator.context.symbolTable.referenceSimpleFunction(it.original)
|
||||
}
|
||||
|
||||
return irCall(hashCodeFunctionSymbol, context.irBuiltIns.intType).apply {
|
||||
if (hashCodeFunctionDescriptor.dispatchReceiverParameter != null) {
|
||||
if (hashCodeFunctionSymbol.descriptor.dispatchReceiverParameter != null) {
|
||||
dispatchReceiver = irValue
|
||||
} else {
|
||||
putValueArgument(0, irValue)
|
||||
|
||||
+4
-5
@@ -24,9 +24,7 @@ import org.jetbrains.kotlin.descriptors.NotFoundClasses
|
||||
import org.jetbrains.kotlin.ir.builders.IrGeneratorContext
|
||||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
|
||||
import org.jetbrains.kotlin.ir.util.ConstantValueGenerator
|
||||
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||
import org.jetbrains.kotlin.ir.util.TypeTranslator
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.psi2ir.Psi2IrConfiguration
|
||||
import org.jetbrains.kotlin.psi2ir.PsiSourceManager
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
@@ -38,7 +36,8 @@ class GeneratorContext(
|
||||
val bindingContext: BindingContext,
|
||||
val languageVersionSettings: LanguageVersionSettings,
|
||||
val symbolTable: SymbolTable,
|
||||
val extensions: GeneratorExtensions
|
||||
val extensions: GeneratorExtensions,
|
||||
signaturer: IdSignatureComposer
|
||||
) : IrGeneratorContext() {
|
||||
|
||||
val constantValueGenerator: ConstantValueGenerator = ConstantValueGenerator(moduleDescriptor, symbolTable)
|
||||
@@ -50,7 +49,7 @@ class GeneratorContext(
|
||||
constantValueGenerator.typeTranslator = typeTranslator
|
||||
}
|
||||
|
||||
override val irBuiltIns: IrBuiltIns = IrBuiltIns(moduleDescriptor.builtIns, typeTranslator, symbolTable)
|
||||
override val irBuiltIns: IrBuiltIns = IrBuiltIns(moduleDescriptor.builtIns, typeTranslator, signaturer, symbolTable)
|
||||
|
||||
val sourceManager = PsiSourceManager()
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl
|
||||
import org.jetbrains.kotlin.descriptors.impl.TypeParameterDescriptorImpl
|
||||
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOriginImpl
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrExternalPackageFragmentImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||
@@ -27,8 +26,7 @@ import org.jetbrains.kotlin.ir.types.impl.buildSimpleType
|
||||
import org.jetbrains.kotlin.ir.types.impl.originalKotlinType
|
||||
import org.jetbrains.kotlin.ir.types.makeNullable
|
||||
import org.jetbrains.kotlin.ir.types.withHasQuestionMark
|
||||
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||
import org.jetbrains.kotlin.ir.util.TypeTranslator
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
||||
@@ -37,6 +35,7 @@ import org.jetbrains.kotlin.types.*
|
||||
class IrBuiltIns(
|
||||
val builtIns: KotlinBuiltIns,
|
||||
private val typeTranslator: TypeTranslator,
|
||||
signaturer: IdSignatureComposer,
|
||||
outerSymbolTable: SymbolTable? = null
|
||||
) {
|
||||
val languageVersionSettings = typeTranslator.languageVersionSettings
|
||||
@@ -45,7 +44,7 @@ class IrBuiltIns(
|
||||
|
||||
val irBuiltInsSymbols = mutableListOf<IrBuiltinWithMangle>()
|
||||
|
||||
private val symbolTable = outerSymbolTable ?: SymbolTable()
|
||||
private val symbolTable = outerSymbolTable ?: SymbolTable(signaturer)
|
||||
|
||||
private val packageFragmentDescriptor = IrBuiltinsPackageFragmentDescriptorImpl(builtInsModule, KOTLIN_INTERNAL_IR_FQN)
|
||||
private val packageFragment =
|
||||
@@ -56,8 +55,9 @@ class IrBuiltIns(
|
||||
|
||||
fun defineOperator(name: String, returnType: IrType, valueParameterTypes: List<IrType>): IrSimpleFunctionSymbol {
|
||||
val descriptor = WrappedSimpleFunctionDescriptor()
|
||||
val symbol = symbolTable.declareSimpleFunction(UNDEFINED_OFFSET, UNDEFINED_OFFSET, BUILTIN_OPERATOR, descriptor) {
|
||||
val suffix = valueParameterTypes.joinToString(":", "[", "]") { t -> t.originalKotlinType?.toString() ?: "T" }
|
||||
val suffix = valueParameterTypes.joinToString(":", "[", "]") { t -> t.originalKotlinType?.toString() ?: "T" }
|
||||
val mangle = "operator#$name@$suffix"
|
||||
val symbol = symbolTable.declareBuiltInOperator(descriptor, mangle) {
|
||||
val operator = IrBuiltInOperator(it, Name.identifier(name), returnType, suffix)
|
||||
operator.parent = packageFragment
|
||||
packageFragment.declarations += operator
|
||||
@@ -135,7 +135,8 @@ class IrBuiltIns(
|
||||
buildSimpleType()
|
||||
}
|
||||
|
||||
return symbolTable.declareSimpleFunction(UNDEFINED_OFFSET, UNDEFINED_OFFSET, BUILTIN_OPERATOR, descriptor) {
|
||||
val mangle = "operator#$name@:!!"
|
||||
return symbolTable.declareBuiltInOperator(descriptor, mangle) {
|
||||
val operator = IrBuiltInOperator(it, name, returnIrType, ":!!")
|
||||
operator.parent = packageFragment
|
||||
packageFragment.declarations += operator
|
||||
|
||||
@@ -19,20 +19,17 @@
|
||||
package org.jetbrains.kotlin.ir.util
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.*
|
||||
import org.jetbrains.kotlin.ir.declarations.lazy.IrLazyDeclarationBase
|
||||
import org.jetbrains.kotlin.ir.declarations.lazy.IrLazySymbolTable
|
||||
import org.jetbrains.kotlin.ir.descriptors.*
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
|
||||
import org.jetbrains.kotlin.ir.symbols.*
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.*
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.impl.IrUninitializedType
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.acceptVoid
|
||||
|
||||
interface IrProvider {
|
||||
fun getDeclaration(symbol: IrSymbol): IrDeclaration?
|
||||
@@ -42,7 +39,7 @@ interface IrProvider {
|
||||
* Extension of [IrProvider] which always produces inheritors of [IrLazyDeclarationBase].
|
||||
* Thus, it needs [declarationStubGenerator] to be able to produce IR declarations.
|
||||
*/
|
||||
interface LazyIrProvider: IrProvider {
|
||||
interface LazyIrProvider : IrProvider {
|
||||
var declarationStubGenerator: DeclarationStubGenerator
|
||||
|
||||
override fun getDeclaration(symbol: IrSymbol): IrLazyDeclarationBase?
|
||||
@@ -70,51 +67,31 @@ interface ReferenceSymbolTable {
|
||||
|
||||
fun referenceTypeAlias(descriptor: TypeAliasDescriptor): IrTypeAliasSymbol
|
||||
|
||||
fun referenceClassFromLinker(descriptor: ClassDescriptor, sig: IdSignature): IrClassSymbol
|
||||
fun referenceConstructorFromLinker(descriptor: ClassConstructorDescriptor, sig: IdSignature): IrConstructorSymbol
|
||||
fun referenceEnumEntryFromLinker(descriptor: ClassDescriptor, sig: IdSignature): IrEnumEntrySymbol
|
||||
fun referenceFieldFromLinker(descriptor: PropertyDescriptor, sig: IdSignature): IrFieldSymbol
|
||||
fun referencePropertyFromLinker(descriptor: PropertyDescriptor, sig: IdSignature): IrPropertySymbol
|
||||
fun referenceSimpleFunctionFromLinker(descriptor: FunctionDescriptor, sig: IdSignature): IrSimpleFunctionSymbol
|
||||
fun referenceTypeParameterFromLinker(classifier: TypeParameterDescriptor, sig: IdSignature): IrTypeParameterSymbol
|
||||
fun referenceTypeAliasFromLinker(descriptor: TypeAliasDescriptor, sig: IdSignature): IrTypeAliasSymbol
|
||||
|
||||
fun enterScope(owner: DeclarationDescriptor)
|
||||
|
||||
fun leaveScope(owner: DeclarationDescriptor)
|
||||
|
||||
// Referencing by UniqId produces symbols with WrappedDescriptor
|
||||
fun referenceClass(uniqId: UniqId): IrClassSymbol
|
||||
fun referenceConstructor(uniqId: UniqId): IrConstructorSymbol
|
||||
fun referenceEnumEntry(uniqId: UniqId): IrEnumEntrySymbol
|
||||
fun referenceField(uniqId: UniqId): IrFieldSymbol
|
||||
fun referenceProperty(uniqId: UniqId): IrPropertySymbol
|
||||
fun referenceSimpleFunction(uniqId: UniqId): IrSimpleFunctionSymbol
|
||||
fun referenceTypeParameter(uniqId: UniqId): IrTypeParameterSymbol
|
||||
fun referenceTypeAlias(uniqId: UniqId): IrTypeAliasSymbol
|
||||
|
||||
// Should only be called when the declaration is in a `ready` state -- with a full chain of parents,
|
||||
// type and value parameters etc.
|
||||
fun computeUniqId(declaration: IrDeclaration)
|
||||
}
|
||||
|
||||
open class SymbolTable(val mangler: KotlinMangler? = null) : ReferenceSymbolTable {
|
||||
open class SymbolTable(private val signaturer: IdSignatureComposer) : ReferenceSymbolTable {
|
||||
|
||||
@Suppress("LeakingThis")
|
||||
val lazyWrapper = IrLazySymbolTable(this)
|
||||
|
||||
private fun IrSymbolOwner.getUniqId() = mangler?.run {
|
||||
(this@getUniqId as? IrDeclaration)?.hashedMangle?.let { UniqId(it) } ?: UniqId.NONE
|
||||
} ?: UniqId.NONE
|
||||
|
||||
fun IrSymbol.setUniqId() {
|
||||
if (isBound) {
|
||||
val oldUid = uniqId
|
||||
val newUid = owner.getUniqId()
|
||||
assert(oldUid == UniqId.NONE || oldUid == newUid)
|
||||
uniqId = newUid
|
||||
}
|
||||
}
|
||||
|
||||
private abstract inner class SymbolTableBase<D : DeclarationDescriptor, B : IrSymbolOwner, S : IrBindableSymbol<D, B>> {
|
||||
val unboundSymbols = linkedSetOf<S>()
|
||||
val unboundUniqIds = linkedSetOf<UniqId>()
|
||||
|
||||
abstract fun get(d: D): S?
|
||||
abstract fun set(d: D, s: S)
|
||||
abstract fun get(uid: UniqId): S?
|
||||
abstract fun set(uid: UniqId, s: S)
|
||||
abstract fun get(sig: IdSignature): S?
|
||||
|
||||
inline fun declare(d: D, createSymbol: () -> S, createOwner: (S) -> B): B {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@@ -134,12 +111,22 @@ open class SymbolTable(val mangler: KotlinMangler? = null) : ReferenceSymbolTabl
|
||||
return createOwner(symbol)
|
||||
}
|
||||
|
||||
fun computeUniqId(b: B) {
|
||||
if (b !is IrDeclaration) return
|
||||
val symbol = b.symbol as S
|
||||
symbol.setUniqId()
|
||||
set(symbol.uniqId, symbol)
|
||||
unboundSymbols.remove(symbol)
|
||||
inline fun declare(sig: IdSignature, d: D, createSymbol: () -> S, createOwner: (S) -> B): B {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val d0 = d.original as D
|
||||
assert(d0 === d) {
|
||||
"Non-original descriptor in declaration: $d\n\tExpected: $d0"
|
||||
}
|
||||
val existing = get(sig)
|
||||
val symbol = if (existing == null) {
|
||||
val new = createSymbol()
|
||||
set(d0, new)
|
||||
new
|
||||
} else {
|
||||
unboundSymbols.remove(existing)
|
||||
existing
|
||||
}
|
||||
return createOwner(symbol)
|
||||
}
|
||||
|
||||
inline fun referenced(d: D, orElse: () -> S): S {
|
||||
@@ -160,62 +147,96 @@ open class SymbolTable(val mangler: KotlinMangler? = null) : ReferenceSymbolTabl
|
||||
return s
|
||||
}
|
||||
|
||||
inline fun referenced(uid: UniqId, orElse: () -> S): S {
|
||||
return get(uid) ?: run {
|
||||
inline fun referenced(sig: IdSignature, orElse: () -> S): S {
|
||||
return get(sig) ?: run {
|
||||
val new = orElse()
|
||||
assert(unboundSymbols.add(new)) {
|
||||
"Symbol for ${new.uniqId} was already referenced"
|
||||
"Symbol for ${new.signature} was already referenced"
|
||||
}
|
||||
set(uid, new)
|
||||
set(new.descriptor, new)
|
||||
new
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private inner class FlatSymbolTable<D : DeclarationDescriptor, B : IrSymbolOwner, S : IrBindableSymbol<D, B>>
|
||||
: SymbolTableBase<D, B, S>() {
|
||||
private open inner class FlatSymbolTable<D : DeclarationDescriptor, B : IrSymbolOwner, S : IrBindableSymbol<D, B>> : SymbolTableBase<D, B, S>() {
|
||||
val descriptorToSymbol = linkedMapOf<D, S>()
|
||||
val uniqIdToSymbol = linkedMapOf<UniqId, S>()
|
||||
val idSigToSymbol = linkedMapOf<IdSignature, S>()
|
||||
|
||||
override fun get(d: D): S? = descriptorToSymbol[d]
|
||||
protected open fun signature(descriptor: D): IdSignature? = signaturer.composeSignature(descriptor)
|
||||
|
||||
override fun set(d: D, s: S) {
|
||||
descriptorToSymbol[d] = s
|
||||
}
|
||||
|
||||
override fun get(uid: UniqId): S? = uniqIdToSymbol[uid]
|
||||
override fun set(uid: UniqId, s: S) {
|
||||
if (uid != UniqId.NONE) {
|
||||
uniqIdToSymbol[uid] = s
|
||||
override fun get(d: D): S? {
|
||||
return if (d !is WrappedDeclarationDescriptor<*>) {
|
||||
val sig = signature(d)
|
||||
if (sig != null) {
|
||||
idSigToSymbol[sig]
|
||||
} else {
|
||||
descriptorToSymbol[d]
|
||||
}
|
||||
} else {
|
||||
descriptorToSymbol[d]
|
||||
}
|
||||
}
|
||||
|
||||
override fun set(d: D, s: S) {
|
||||
if (s.isPublicApi) {
|
||||
idSigToSymbol[s.signature] = s
|
||||
} else {
|
||||
descriptorToSymbol[d] = s
|
||||
}
|
||||
}
|
||||
|
||||
override fun get(sig: IdSignature): S? = idSigToSymbol[sig]
|
||||
}
|
||||
|
||||
private inner class EnumEntrySymbolTable : FlatSymbolTable<ClassDescriptor, IrEnumEntry, IrEnumEntrySymbol>() {
|
||||
override fun signature(descriptor: ClassDescriptor): IdSignature? = signaturer.composeEnumEntrySignature(descriptor)
|
||||
}
|
||||
|
||||
private inner class FieldSymbolTable : FlatSymbolTable<PropertyDescriptor, IrField, IrFieldSymbol>() {
|
||||
override fun signature(descriptor: PropertyDescriptor): IdSignature? = null
|
||||
}
|
||||
|
||||
private inner class ScopedSymbolTable<D : DeclarationDescriptor, B : IrSymbolOwner, S : IrBindableSymbol<D, B>>
|
||||
: SymbolTableBase<D, B, S>() {
|
||||
inner class Scope(val owner: DeclarationDescriptor, val parent: Scope?) {
|
||||
private val descriptorToSymbol = linkedMapOf<D, S>()
|
||||
private val uniqIdToSymbol = linkedMapOf<UniqId, S>()
|
||||
private val idSigToSymbol = linkedMapOf<IdSignature, S>()
|
||||
|
||||
operator fun get(d: D): S? =
|
||||
descriptorToSymbol[d] ?: parent?.get(d)
|
||||
private fun getByDescriptor(d: D): S? {
|
||||
return descriptorToSymbol[d] ?: parent?.getByDescriptor(d)
|
||||
}
|
||||
|
||||
private fun getByIdSignature(sig: IdSignature): S? {
|
||||
return idSigToSymbol[sig] ?: parent?.getByIdSignature(sig)
|
||||
}
|
||||
|
||||
operator fun get(d: D): S? {
|
||||
return if (d !is WrappedDeclarationDescriptor<*>) {
|
||||
val sig = signaturer.composeSignature(d)
|
||||
if (sig != null) {
|
||||
getByIdSignature(sig)
|
||||
} else {
|
||||
getByDescriptor(d)
|
||||
}
|
||||
} else {
|
||||
getByDescriptor(d)
|
||||
}
|
||||
}
|
||||
|
||||
fun getLocal(d: D) = descriptorToSymbol[d]
|
||||
|
||||
operator fun set(d: D, s: S) {
|
||||
descriptorToSymbol[d] = s
|
||||
}
|
||||
|
||||
operator fun get(uid: UniqId): S? =
|
||||
uniqIdToSymbol[uid] ?: parent?.get(uid)
|
||||
|
||||
operator fun set(uid: UniqId, s: S) {
|
||||
if (uid != UniqId.NONE) {
|
||||
uniqIdToSymbol[uid] = s
|
||||
if (s.isPublicApi) {
|
||||
require(d is TypeParameterDescriptor)
|
||||
idSigToSymbol[s.signature] = s
|
||||
} else {
|
||||
descriptorToSymbol[d] = s
|
||||
}
|
||||
}
|
||||
|
||||
operator fun get(sig: IdSignature): S? = idSigToSymbol[sig] ?: parent?.get(sig)
|
||||
|
||||
fun dumpTo(stringBuilder: StringBuilder): StringBuilder =
|
||||
stringBuilder.also {
|
||||
it.append("owner=")
|
||||
@@ -241,14 +262,9 @@ open class SymbolTable(val mangler: KotlinMangler? = null) : ReferenceSymbolTabl
|
||||
scope[d] = s
|
||||
}
|
||||
|
||||
override fun get(uid: UniqId): S? {
|
||||
override fun get(sig: IdSignature): S? {
|
||||
val scope = currentScope ?: return null
|
||||
return scope[uid]
|
||||
}
|
||||
|
||||
override fun set(uid: UniqId, s: S) {
|
||||
val scope = currentScope ?: throw AssertionError("No active scope")
|
||||
scope[uid] = s
|
||||
return scope[sig]
|
||||
}
|
||||
|
||||
inline fun declareLocal(d: D, createSymbol: () -> S, createOwner: (S) -> B): B {
|
||||
@@ -290,8 +306,8 @@ open class SymbolTable(val mangler: KotlinMangler? = null) : ReferenceSymbolTabl
|
||||
private val scriptSymbolTable = FlatSymbolTable<ScriptDescriptor, IrScript, IrScriptSymbol>()
|
||||
private val classSymbolTable = FlatSymbolTable<ClassDescriptor, IrClass, IrClassSymbol>()
|
||||
private val constructorSymbolTable = FlatSymbolTable<ClassConstructorDescriptor, IrConstructor, IrConstructorSymbol>()
|
||||
private val enumEntrySymbolTable = FlatSymbolTable<ClassDescriptor, IrEnumEntry, IrEnumEntrySymbol>()
|
||||
private val fieldSymbolTable = FlatSymbolTable<PropertyDescriptor, IrField, IrFieldSymbol>()
|
||||
private val enumEntrySymbolTable = EnumEntrySymbolTable()
|
||||
private val fieldSymbolTable = FieldSymbolTable()
|
||||
private val simpleFunctionSymbolTable = FlatSymbolTable<FunctionDescriptor, IrSimpleFunction, IrSimpleFunctionSymbol>()
|
||||
private val propertySymbolTable = FlatSymbolTable<PropertyDescriptor, IrProperty, IrPropertySymbol>()
|
||||
private val typeAliasSymbolTable = FlatSymbolTable<TypeAliasDescriptor, IrTypeAlias, IrTypeAliasSymbol>()
|
||||
@@ -342,6 +358,10 @@ open class SymbolTable(val mangler: KotlinMangler? = null) : ReferenceSymbolTabl
|
||||
)
|
||||
}
|
||||
|
||||
private fun createClassSymbol(descriptor: ClassDescriptor): IrClassSymbol {
|
||||
return signaturer.composeSignature(descriptor)?.let { IrClassPublicSymbolImpl(descriptor, it) } ?: IrClassSymbolImpl(descriptor)
|
||||
}
|
||||
|
||||
fun declareClass(
|
||||
startOffset: Int, endOffset: Int, origin: IrDeclarationOrigin, descriptor: ClassDescriptor,
|
||||
modality: Modality = descriptor.modality, visibility: Visibility = descriptor.visibility,
|
||||
@@ -351,19 +371,51 @@ open class SymbolTable(val mangler: KotlinMangler? = null) : ReferenceSymbolTabl
|
||||
): IrClass {
|
||||
return classSymbolTable.declare(
|
||||
descriptor,
|
||||
{ IrClassSymbolImpl(descriptor) },
|
||||
{ createClassSymbol(descriptor) },
|
||||
classFactory
|
||||
)
|
||||
}
|
||||
|
||||
override fun referenceClass(descriptor: ClassDescriptor) =
|
||||
classSymbolTable.referenced(descriptor) { IrClassSymbolImpl(descriptor) }
|
||||
fun declareClassFromLinker(descriptor: ClassDescriptor, sig: IdSignature, factory: (IrClassSymbol) -> IrClass): IrClass {
|
||||
return classSymbolTable.run {
|
||||
if (sig.isPublic) {
|
||||
declare(sig, descriptor, { IrClassPublicSymbolImpl(descriptor, sig) }, factory)
|
||||
} else {
|
||||
declare(descriptor, { IrClassSymbolImpl(descriptor) }, factory)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun referenceClass(uniqId: UniqId): IrClassSymbol =
|
||||
classSymbolTable.referenced(uniqId) { IrClassSymbolImpl(uniqId) }
|
||||
override fun referenceClass(descriptor: ClassDescriptor) =
|
||||
classSymbolTable.referenced(descriptor) { createClassSymbol(descriptor) }
|
||||
|
||||
private fun createBuiltInClassSymbol(descriptor: ClassDescriptor, sig: IdSignature): IrClassSymbol {
|
||||
return IrClassPublicSymbolImpl(descriptor, sig)
|
||||
}
|
||||
|
||||
fun declareBuiltInClass(
|
||||
descriptor: ClassDescriptor,
|
||||
mangle: String,
|
||||
classFactory: (IrClassSymbol) -> IrClass
|
||||
): IrClass {
|
||||
val sig = IdSignature.BuiltInSignature(mangle, signaturer.string2Hash(mangle))
|
||||
return classSymbolTable.declare(sig, descriptor, { createBuiltInClassSymbol(descriptor, sig) }, classFactory)
|
||||
}
|
||||
|
||||
override fun referenceClassFromLinker(descriptor: ClassDescriptor, sig: IdSignature): IrClassSymbol =
|
||||
classSymbolTable.run {
|
||||
if (sig.isPublic) referenced(sig) { IrClassPublicSymbolImpl(descriptor, sig) }
|
||||
else referenced(descriptor) { IrClassSymbolImpl(descriptor) }
|
||||
}
|
||||
|
||||
val unboundClasses: Set<IrClassSymbol> get() = classSymbolTable.unboundSymbols
|
||||
|
||||
private fun createConstructorSymbol(descriptor: ClassConstructorDescriptor): IrConstructorSymbol {
|
||||
return signaturer.composeSignature(descriptor)?.let { IrConstructorPublicSymbolImpl(descriptor, it) } ?: IrConstructorSymbolImpl(
|
||||
descriptor
|
||||
)
|
||||
}
|
||||
|
||||
fun declareConstructor(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
@@ -377,36 +429,79 @@ open class SymbolTable(val mangler: KotlinMangler? = null) : ReferenceSymbolTabl
|
||||
): IrConstructor =
|
||||
constructorSymbolTable.declare(
|
||||
descriptor,
|
||||
{ IrConstructorSymbolImpl(descriptor) },
|
||||
{ createConstructorSymbol(descriptor) },
|
||||
constructorFactory
|
||||
)
|
||||
|
||||
override fun referenceConstructor(descriptor: ClassConstructorDescriptor) =
|
||||
constructorSymbolTable.referenced(descriptor) { IrConstructorSymbolImpl(descriptor) }
|
||||
constructorSymbolTable.referenced(descriptor) { createConstructorSymbol(descriptor) }
|
||||
|
||||
override fun referenceConstructor(uniqId: UniqId): IrConstructorSymbol =
|
||||
constructorSymbolTable.referenced(uniqId) { IrConstructorSymbolImpl(uniqId) }
|
||||
fun declareConstructorFromLinker(
|
||||
descriptor: ClassConstructorDescriptor,
|
||||
sig: IdSignature,
|
||||
constructorFactory: (IrConstructorSymbol) -> IrConstructor
|
||||
): IrConstructor {
|
||||
return constructorSymbolTable.run {
|
||||
if (sig.isPublic) {
|
||||
declare(sig, descriptor, { IrConstructorPublicSymbolImpl(descriptor, sig) }, constructorFactory)
|
||||
} else {
|
||||
declare(descriptor, { IrConstructorSymbolImpl(descriptor) }, constructorFactory)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun referenceConstructorFromLinker(descriptor: ClassConstructorDescriptor, sig: IdSignature): IrConstructorSymbol =
|
||||
constructorSymbolTable.run {
|
||||
if (sig.isPublic) referenced(sig) { IrConstructorPublicSymbolImpl(descriptor, sig) }
|
||||
else referenced(descriptor) { IrConstructorSymbolImpl(descriptor) }
|
||||
}
|
||||
|
||||
val unboundConstructors: Set<IrConstructorSymbol> get() = constructorSymbolTable.unboundSymbols
|
||||
|
||||
private fun createEnumEntrySymbol(descriptor: ClassDescriptor): IrEnumEntrySymbol {
|
||||
return signaturer.composeEnumEntrySignature(descriptor)?.let { IrEnumEntryPublicSymbolImpl(descriptor, it) }
|
||||
?: IrEnumEntrySymbolImpl(descriptor)
|
||||
}
|
||||
|
||||
fun declareEnumEntry(
|
||||
startOffset: Int, endOffset: Int, origin: IrDeclarationOrigin, descriptor: ClassDescriptor,
|
||||
factory: (IrEnumEntrySymbol) -> IrEnumEntry = { IrEnumEntryImpl(startOffset, endOffset, origin, it) }
|
||||
): IrEnumEntry =
|
||||
enumEntrySymbolTable.declare(
|
||||
descriptor,
|
||||
{ IrEnumEntrySymbolImpl(descriptor) },
|
||||
{ createEnumEntrySymbol(descriptor) },
|
||||
factory
|
||||
)
|
||||
|
||||
override fun referenceEnumEntry(descriptor: ClassDescriptor) =
|
||||
enumEntrySymbolTable.referenced(descriptor) { IrEnumEntrySymbolImpl(descriptor) }
|
||||
fun declareEnumEntryFromLinker(
|
||||
descriptor: ClassDescriptor,
|
||||
sig: IdSignature,
|
||||
factory: (IrEnumEntrySymbol) -> IrEnumEntry
|
||||
): IrEnumEntry {
|
||||
return enumEntrySymbolTable.run {
|
||||
if (sig.isPublic) {
|
||||
declare(sig, descriptor, { IrEnumEntryPublicSymbolImpl(descriptor, sig) }, factory)
|
||||
} else {
|
||||
declare(descriptor, { IrEnumEntrySymbolImpl(descriptor) }, factory)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun referenceEnumEntry(uniqId: UniqId): IrEnumEntrySymbol =
|
||||
enumEntrySymbolTable.referenced(uniqId) { IrEnumEntrySymbolImpl(uniqId) }
|
||||
override fun referenceEnumEntry(descriptor: ClassDescriptor) =
|
||||
enumEntrySymbolTable.referenced(descriptor) { createEnumEntrySymbol(descriptor) }
|
||||
|
||||
override fun referenceEnumEntryFromLinker(descriptor: ClassDescriptor, sig: IdSignature) =
|
||||
enumEntrySymbolTable.run {
|
||||
if (sig.isPublic) referenced(sig) { IrEnumEntryPublicSymbolImpl(descriptor, sig) } else
|
||||
referenced(descriptor) { IrEnumEntrySymbolImpl(descriptor) }
|
||||
}
|
||||
|
||||
val unboundEnumEntries: Set<IrEnumEntrySymbol> get() = enumEntrySymbolTable.unboundSymbols
|
||||
|
||||
private fun createFieldSymbol(descriptor: PropertyDescriptor): IrFieldSymbol {
|
||||
return IrFieldSymbolImpl(descriptor)
|
||||
}
|
||||
|
||||
fun declareField(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
@@ -422,7 +517,7 @@ open class SymbolTable(val mangler: KotlinMangler? = null) : ReferenceSymbolTabl
|
||||
): IrField =
|
||||
fieldSymbolTable.declare(
|
||||
descriptor,
|
||||
{ IrFieldSymbolImpl(descriptor) },
|
||||
{ createFieldSymbol(descriptor) },
|
||||
fieldFactory
|
||||
)
|
||||
|
||||
@@ -438,11 +533,21 @@ open class SymbolTable(val mangler: KotlinMangler? = null) : ReferenceSymbolTabl
|
||||
initializer = irInitializer
|
||||
}
|
||||
|
||||
override fun referenceField(descriptor: PropertyDescriptor) =
|
||||
fieldSymbolTable.referenced(descriptor) { IrFieldSymbolImpl(descriptor) }
|
||||
fun declareFieldFromLinker(descriptor: PropertyDescriptor, sig: IdSignature, factory: (IrFieldSymbol) -> IrField): IrField {
|
||||
return fieldSymbolTable.run {
|
||||
require(sig.isLocal)
|
||||
declare(descriptor, { IrFieldSymbolImpl(descriptor) }, factory)
|
||||
}
|
||||
}
|
||||
|
||||
override fun referenceField(uniqId: UniqId) =
|
||||
fieldSymbolTable.referenced(uniqId) { IrFieldSymbolImpl(uniqId) }
|
||||
override fun referenceField(descriptor: PropertyDescriptor) =
|
||||
fieldSymbolTable.referenced(descriptor) { createFieldSymbol(descriptor) }
|
||||
|
||||
override fun referenceFieldFromLinker(descriptor: PropertyDescriptor, sig: IdSignature) =
|
||||
fieldSymbolTable.run {
|
||||
require(sig.isLocal)
|
||||
referenced(descriptor) { IrFieldSymbolImpl(descriptor) }
|
||||
}
|
||||
|
||||
val unboundFields: Set<IrFieldSymbol> get() = fieldSymbolTable.unboundSymbols
|
||||
|
||||
@@ -452,6 +557,13 @@ open class SymbolTable(val mangler: KotlinMangler? = null) : ReferenceSymbolTabl
|
||||
override fun referenceProperty(descriptor: PropertyDescriptor, generate: () -> IrProperty): IrProperty =
|
||||
propertyTable.getOrPut(descriptor, generate)
|
||||
|
||||
private fun createPropertySymbol(descriptor: PropertyDescriptor): IrPropertySymbol {
|
||||
return signaturer.composeSignature(descriptor)?.let { IrPropertyPublicSymbolImpl(descriptor, it) } ?: IrPropertySymbolImpl(
|
||||
descriptor
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
fun declareProperty(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
@@ -466,29 +578,70 @@ open class SymbolTable(val mangler: KotlinMangler? = null) : ReferenceSymbolTabl
|
||||
): IrProperty =
|
||||
propertySymbolTable.declare(
|
||||
descriptor,
|
||||
{ IrPropertySymbolImpl(descriptor) },
|
||||
{ createPropertySymbol(descriptor) },
|
||||
propertyFactory
|
||||
)
|
||||
|
||||
fun referenceProperty(descriptor: PropertyDescriptor): IrPropertySymbol =
|
||||
propertySymbolTable.referenced(descriptor) { IrPropertySymbolImpl(descriptor) }
|
||||
fun declarePropertyFromLinker(descriptor: PropertyDescriptor, sig: IdSignature, factory: (IrPropertySymbol) -> IrProperty): IrProperty {
|
||||
return propertySymbolTable.run {
|
||||
if (sig.isPublic) {
|
||||
declare(sig, descriptor, { IrPropertyPublicSymbolImpl(descriptor, sig) }, factory)
|
||||
} else {
|
||||
declare(descriptor, { IrPropertySymbolImpl(descriptor) }, factory)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun referenceProperty(uniqId: UniqId): IrPropertySymbol =
|
||||
propertySymbolTable.referenced(uniqId) { IrPropertySymbolImpl(uniqId) }
|
||||
fun referenceProperty(descriptor: PropertyDescriptor): IrPropertySymbol =
|
||||
propertySymbolTable.referenced(descriptor) { createPropertySymbol(descriptor) }
|
||||
|
||||
override fun referencePropertyFromLinker(descriptor: PropertyDescriptor, sig: IdSignature): IrPropertySymbol =
|
||||
propertySymbolTable.run {
|
||||
if (sig.isPublic) referenced(sig) { IrPropertyPublicSymbolImpl(descriptor, sig) }
|
||||
else referenced(descriptor) { IrPropertySymbolImpl(descriptor) }
|
||||
}
|
||||
|
||||
val unboundProperties: Set<IrPropertySymbol> get() = propertySymbolTable.unboundSymbols
|
||||
|
||||
override fun referenceTypeAlias(descriptor: TypeAliasDescriptor): IrTypeAliasSymbol =
|
||||
typeAliasSymbolTable.referenced(descriptor) { IrTypeAliasSymbolImpl(descriptor) }
|
||||
private fun createTypeAliasSymbol(descriptor: TypeAliasDescriptor): IrTypeAliasSymbol {
|
||||
return signaturer.composeSignature(descriptor)?.let { IrTypeAliasPublicSymbolImpl(descriptor, it) } ?: IrTypeAliasSymbolImpl(
|
||||
descriptor
|
||||
)
|
||||
}
|
||||
|
||||
override fun referenceTypeAlias(uniqId: UniqId): IrTypeAliasSymbol =
|
||||
typeAliasSymbolTable.referenced(uniqId) { IrTypeAliasSymbolImpl(uniqId) }
|
||||
override fun referenceTypeAlias(descriptor: TypeAliasDescriptor): IrTypeAliasSymbol =
|
||||
typeAliasSymbolTable.referenced(descriptor) { createTypeAliasSymbol(descriptor) }
|
||||
|
||||
fun declareTypeAliasFromLinker(
|
||||
descriptor: TypeAliasDescriptor,
|
||||
sig: IdSignature,
|
||||
factory: (IrTypeAliasSymbol) -> IrTypeAlias
|
||||
): IrTypeAlias {
|
||||
return typeAliasSymbolTable.run {
|
||||
if (sig.isPublic) {
|
||||
declare(sig, descriptor, { IrTypeAliasPublicSymbolImpl(descriptor, sig) }, factory)
|
||||
} else {
|
||||
declare(descriptor, { IrTypeAliasSymbolImpl(descriptor) }, factory)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun referenceTypeAliasFromLinker(descriptor: TypeAliasDescriptor, sig: IdSignature) =
|
||||
typeAliasSymbolTable.run {
|
||||
if (sig.isPublic) referenced(sig) { IrTypeAliasPublicSymbolImpl(descriptor, sig) } else
|
||||
referenced(descriptor) { IrTypeAliasSymbolImpl(descriptor) }
|
||||
}
|
||||
|
||||
fun declareTypeAlias(descriptor: TypeAliasDescriptor, factory: (IrTypeAliasSymbol) -> IrTypeAlias): IrTypeAlias =
|
||||
typeAliasSymbolTable.declare(descriptor, { IrTypeAliasSymbolImpl(descriptor) }, factory)
|
||||
typeAliasSymbolTable.declare(descriptor, { createTypeAliasSymbol(descriptor) }, factory)
|
||||
|
||||
val unboundTypeAliases: Set<IrTypeAliasSymbol> get() = typeAliasSymbolTable.unboundSymbols
|
||||
|
||||
private fun createSimpleFunctionSymbol(descriptor: FunctionDescriptor): IrSimpleFunctionSymbol {
|
||||
return signaturer.composeSignature(descriptor)?.let { IrSimpleFunctionPublicSymbolImpl(descriptor, it) }
|
||||
?: IrSimpleFunctionSymbolImpl(descriptor)
|
||||
}
|
||||
|
||||
fun declareSimpleFunction(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
@@ -502,22 +655,67 @@ open class SymbolTable(val mangler: KotlinMangler? = null) : ReferenceSymbolTabl
|
||||
): IrSimpleFunction {
|
||||
return simpleFunctionSymbolTable.declare(
|
||||
descriptor,
|
||||
{ IrSimpleFunctionSymbolImpl(descriptor) },
|
||||
{ createSimpleFunctionSymbol(descriptor) },
|
||||
functionFactory
|
||||
)
|
||||
}
|
||||
|
||||
override fun referenceSimpleFunction(descriptor: FunctionDescriptor) =
|
||||
simpleFunctionSymbolTable.referenced(descriptor) { IrSimpleFunctionSymbolImpl(descriptor) }
|
||||
fun declareSimpleFunctionFromLinker(
|
||||
descriptor: FunctionDescriptor,
|
||||
sig: IdSignature,
|
||||
functionFactory: (IrSimpleFunctionSymbol) -> IrSimpleFunction
|
||||
): IrSimpleFunction {
|
||||
return simpleFunctionSymbolTable.run {
|
||||
if (sig.isPublic) {
|
||||
declare(sig, descriptor, { IrSimpleFunctionPublicSymbolImpl(descriptor, sig) }, functionFactory)
|
||||
} else {
|
||||
declare(descriptor, { IrSimpleFunctionSymbolImpl(descriptor) }, functionFactory)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun referenceSimpleFunction(uniqId: UniqId): IrSimpleFunctionSymbol =
|
||||
simpleFunctionSymbolTable.referenced(uniqId) { IrSimpleFunctionSymbolImpl(uniqId) }
|
||||
private fun createBuiltInOperatorSymbol(descriptor: FunctionDescriptor, sig: IdSignature): IrSimpleFunctionSymbol {
|
||||
return IrSimpleFunctionPublicSymbolImpl(descriptor, sig)
|
||||
}
|
||||
|
||||
fun declareBuiltInOperator(
|
||||
descriptor: FunctionDescriptor,
|
||||
mangle: String,
|
||||
functionFactory: (IrSimpleFunctionSymbol) -> IrSimpleFunction
|
||||
): IrSimpleFunction {
|
||||
val sig = IdSignature.BuiltInSignature(mangle, signaturer.string2Hash(mangle))
|
||||
return simpleFunctionSymbolTable.declare(
|
||||
sig,
|
||||
descriptor,
|
||||
{ createBuiltInOperatorSymbol(descriptor, sig) },
|
||||
functionFactory
|
||||
)
|
||||
}
|
||||
|
||||
fun referenceBuiltInOperator(descriptor: FunctionDescriptor, mangle: String): IrSimpleFunctionSymbol {
|
||||
val sig = IdSignature.BuiltInSignature(mangle, signaturer.string2Hash(mangle))
|
||||
return simpleFunctionSymbolTable.referenced(sig) { createBuiltInOperatorSymbol(descriptor, sig) }
|
||||
}
|
||||
|
||||
override fun referenceSimpleFunction(descriptor: FunctionDescriptor) =
|
||||
simpleFunctionSymbolTable.referenced(descriptor) { createSimpleFunctionSymbol(descriptor) }
|
||||
|
||||
override fun referenceSimpleFunctionFromLinker(descriptor: FunctionDescriptor, sig: IdSignature): IrSimpleFunctionSymbol {
|
||||
return simpleFunctionSymbolTable.run {
|
||||
if (sig.isPublic) referenced(sig) { IrSimpleFunctionPublicSymbolImpl(descriptor, sig) } else
|
||||
referenced(descriptor) { IrSimpleFunctionSymbolImpl(descriptor) }
|
||||
}
|
||||
}
|
||||
|
||||
override fun referenceDeclaredFunction(descriptor: FunctionDescriptor) =
|
||||
simpleFunctionSymbolTable.referenced(descriptor) { throw AssertionError("Function is not declared: $descriptor") }
|
||||
|
||||
val unboundSimpleFunctions: Set<IrSimpleFunctionSymbol> get() = simpleFunctionSymbolTable.unboundSymbols
|
||||
|
||||
private fun createTypeParameterSymbol(descriptor: TypeParameterDescriptor): IrTypeParameterSymbol {
|
||||
return IrTypeParameterSymbolImpl(descriptor)
|
||||
}
|
||||
|
||||
fun declareGlobalTypeParameter(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
@@ -527,10 +725,19 @@ open class SymbolTable(val mangler: KotlinMangler? = null) : ReferenceSymbolTabl
|
||||
): IrTypeParameter =
|
||||
globalTypeParameterSymbolTable.declare(
|
||||
descriptor,
|
||||
{ IrTypeParameterSymbolImpl(descriptor) },
|
||||
{ createTypeParameterSymbol(descriptor) },
|
||||
typeParameterFactory
|
||||
)
|
||||
|
||||
fun declareGlobalTypeParameterFromLinker(
|
||||
descriptor: TypeParameterDescriptor,
|
||||
sig: IdSignature,
|
||||
typeParameterFactory: (IrTypeParameterSymbol) -> IrTypeParameter
|
||||
): IrTypeParameter {
|
||||
require(sig.isLocal)
|
||||
return globalTypeParameterSymbolTable.declare(descriptor, { IrTypeParameterSymbolImpl(descriptor) }, typeParameterFactory)
|
||||
}
|
||||
|
||||
fun declareScopedTypeParameter(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
@@ -540,10 +747,18 @@ open class SymbolTable(val mangler: KotlinMangler? = null) : ReferenceSymbolTabl
|
||||
): IrTypeParameter =
|
||||
scopedTypeParameterSymbolTable.declare(
|
||||
descriptor,
|
||||
{ IrTypeParameterSymbolImpl(descriptor) },
|
||||
{ createTypeParameterSymbol(descriptor) },
|
||||
typeParameterFactory
|
||||
)
|
||||
|
||||
fun declareScopedTypeParameterFromLinker(
|
||||
descriptor: TypeParameterDescriptor,
|
||||
sig: IdSignature,
|
||||
typeParameterFactory: (IrTypeParameterSymbol) -> IrTypeParameter
|
||||
): IrTypeParameter {
|
||||
require(sig.isLocal)
|
||||
return scopedTypeParameterSymbolTable.declare(descriptor, { IrTypeParameterSymbolImpl(descriptor) }, typeParameterFactory)
|
||||
}
|
||||
|
||||
val unboundTypeParameters: Set<IrTypeParameterSymbol> get() = globalTypeParameterSymbolTable.unboundSymbols
|
||||
|
||||
@@ -575,13 +790,14 @@ open class SymbolTable(val mangler: KotlinMangler? = null) : ReferenceSymbolTabl
|
||||
|
||||
override fun referenceTypeParameter(classifier: TypeParameterDescriptor): IrTypeParameterSymbol =
|
||||
scopedTypeParameterSymbolTable.get(classifier) ?: globalTypeParameterSymbolTable.referenced(classifier) {
|
||||
IrTypeParameterSymbolImpl(classifier)
|
||||
createTypeParameterSymbol(classifier)
|
||||
}
|
||||
|
||||
override fun referenceTypeParameter(uniqId: UniqId): IrTypeParameterSymbol =
|
||||
scopedTypeParameterSymbolTable.get(uniqId) ?: globalTypeParameterSymbolTable.referenced(uniqId) {
|
||||
IrTypeParameterSymbolImpl(uniqId)
|
||||
}
|
||||
override fun referenceTypeParameterFromLinker(classifier: TypeParameterDescriptor, sig: IdSignature): IrTypeParameterSymbol {
|
||||
require(sig.isLocal)
|
||||
return scopedTypeParameterSymbolTable.get(classifier)
|
||||
?: globalTypeParameterSymbolTable.referenced(classifier) { IrTypeParameterSymbolImpl(classifier) }
|
||||
}
|
||||
|
||||
fun declareVariable(
|
||||
startOffset: Int,
|
||||
@@ -650,44 +866,11 @@ open class SymbolTable(val mangler: KotlinMangler? = null) : ReferenceSymbolTabl
|
||||
else ->
|
||||
throw IllegalArgumentException("Unexpected value descriptor: $value")
|
||||
}
|
||||
|
||||
override fun computeUniqId(declaration: IrDeclaration) {
|
||||
if (mangler == null) return
|
||||
with(mangler) {
|
||||
if (!declaration.isExported()) return
|
||||
}
|
||||
when(declaration) {
|
||||
is IrConstructor -> constructorSymbolTable.computeUniqId(declaration)
|
||||
is IrClass -> classSymbolTable.computeUniqId(declaration)
|
||||
is IrEnumEntry -> enumEntrySymbolTable.computeUniqId(declaration)
|
||||
is IrField -> fieldSymbolTable.computeUniqId(declaration)
|
||||
is IrProperty -> propertySymbolTable.computeUniqId(declaration)
|
||||
is IrSimpleFunction -> simpleFunctionSymbolTable.computeUniqId(declaration)
|
||||
is IrTypeAlias -> typeAliasSymbolTable.computeUniqId(declaration)
|
||||
is IrTypeParameter -> globalTypeParameterSymbolTable.computeUniqId(declaration)
|
||||
else -> { /* do nothing */ }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <T, D: DeclarationDescriptor> SymbolTable.withScope(owner: D, block: SymbolTable.(D) -> T): T {
|
||||
inline fun <T, D : DeclarationDescriptor> SymbolTable.withScope(owner: D, block: SymbolTable.(D) -> T): T {
|
||||
enterScope(owner)
|
||||
val result = block(owner)
|
||||
leaveScope(owner)
|
||||
return result
|
||||
}
|
||||
|
||||
fun IrElement.computeUniqIdForDeclarations(symbolTable: SymbolTable) {
|
||||
acceptVoid(ComputeUniqIdVisitor(symbolTable))
|
||||
}
|
||||
|
||||
private class ComputeUniqIdVisitor(val symbolTable: SymbolTable) : IrElementVisitorVoid {
|
||||
override fun visitElement(element: IrElement) {
|
||||
element.acceptChildrenVoid(this)
|
||||
}
|
||||
|
||||
override fun visitDeclaration(declaration: IrDeclaration) {
|
||||
symbolTable.computeUniqId(declaration)
|
||||
super.visitDeclaration(declaration)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -200,7 +200,9 @@ fun loadIr(
|
||||
}
|
||||
is MainModule.Klib -> {
|
||||
val moduleDescriptor = depsDescriptors.getModuleDescriptor(mainModule.lib)
|
||||
val symbolTable = SymbolTable()
|
||||
val mangler = JsManglerDesc
|
||||
val signaturer = IdSignatureDescriptor(mangler)
|
||||
val symbolTable = SymbolTable(signaturer)
|
||||
val constantValueGenerator = ConstantValueGenerator(moduleDescriptor, symbolTable)
|
||||
val typeTranslator = TypeTranslator(
|
||||
symbolTable,
|
||||
@@ -209,8 +211,8 @@ fun loadIr(
|
||||
)
|
||||
typeTranslator.constantValueGenerator = constantValueGenerator
|
||||
constantValueGenerator.typeTranslator = typeTranslator
|
||||
val irBuiltIns = IrBuiltIns(moduleDescriptor.builtIns, typeTranslator, symbolTable)
|
||||
val deserializer = JsIrLinker(moduleDescriptor, JsMangler, emptyLoggingContext, irBuiltIns, symbolTable)
|
||||
val irBuiltIns = IrBuiltIns(moduleDescriptor.builtIns, typeTranslator, signaturer, symbolTable)
|
||||
val deserializer = JsIrLinker(emptyLoggingContext, irBuiltIns, symbolTable)
|
||||
|
||||
val deserializedModuleFragments = sortDependencies(allDependencies.getFullList(), depsDescriptors.descriptors).map {
|
||||
val strategy =
|
||||
@@ -234,14 +236,17 @@ fun loadIr(
|
||||
|
||||
private fun runAnalysisAndPreparePsi2Ir(depsDescriptors: ModulesStructure): GeneratorContext {
|
||||
val analysisResult = depsDescriptors.runAnalysis()
|
||||
val mangler = JsManglerDesc
|
||||
val signaturer = IdSignatureDescriptor(mangler)
|
||||
|
||||
return GeneratorContext(
|
||||
Psi2IrConfiguration(),
|
||||
analysisResult.moduleDescriptor,
|
||||
analysisResult.bindingContext,
|
||||
depsDescriptors.compilerConfiguration.languageVersionSettings,
|
||||
SymbolTable(),
|
||||
JsGeneratorExtensions()
|
||||
SymbolTable(signaturer),
|
||||
GeneratorExtensions(),
|
||||
signaturer
|
||||
)
|
||||
}
|
||||
|
||||
@@ -252,7 +257,8 @@ fun GeneratorContext.generateModuleFragmentWithPlugins(
|
||||
expectDescriptorToSymbol: MutableMap<DeclarationDescriptor, IrSymbol>? = null
|
||||
): IrModuleFragment {
|
||||
val irProviders = generateTypicalIrProviderList(moduleDescriptor, irBuiltIns, symbolTable, deserializer)
|
||||
val psi2Ir = Psi2IrTranslator(languageVersionSettings, configuration, mangler = JsMangler)
|
||||
val signaturer = IdSignatureDescriptor(JsManglerDesc)
|
||||
val psi2Ir = Psi2IrTranslator(languageVersionSettings, configuration, signaturer)
|
||||
|
||||
for (extension in IrGenerationExtension.getInstances(project)) {
|
||||
psi2Ir.addPostprocessingStep { module ->
|
||||
@@ -282,8 +288,10 @@ fun GeneratorContext.generateModuleFragmentWithPlugins(
|
||||
|
||||
fun GeneratorContext.generateModuleFragment(files: List<KtFile>, deserializer: IrDeserializer? = null, expectDescriptorToSymbol: MutableMap<DeclarationDescriptor, IrSymbol>? = null): IrModuleFragment {
|
||||
val irProviders = generateTypicalIrProviderList(moduleDescriptor, irBuiltIns, symbolTable, deserializer)
|
||||
val mangler = JsManglerDesc
|
||||
val signaturer = IdSignatureDescriptor(mangler)
|
||||
return Psi2IrTranslator(
|
||||
languageVersionSettings, configuration, mangler = JsMangler
|
||||
languageVersionSettings, configuration, signaturer
|
||||
).generateModuleFragment(this, files, irProviders, expectDescriptorToSymbol)
|
||||
}
|
||||
|
||||
|
||||
@@ -24,8 +24,10 @@ import com.intellij.psi.search.ProjectScope
|
||||
import org.jetbrains.kotlin.TestsCompiletimeError
|
||||
import org.jetbrains.kotlin.asJava.finder.JavaElementFinder
|
||||
import org.jetbrains.kotlin.backend.common.phaser.PhaseConfig
|
||||
import org.jetbrains.kotlin.backend.common.serialization.signature.IdSignatureDescriptor
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory
|
||||
import org.jetbrains.kotlin.backend.jvm.jvmPhases
|
||||
import org.jetbrains.kotlin.backend.jvm.serialization.JvmManglerDesc
|
||||
import org.jetbrains.kotlin.builtins.jvm.JvmBuiltIns
|
||||
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
|
||||
import org.jetbrains.kotlin.cli.common.output.writeAllTo
|
||||
@@ -136,7 +138,7 @@ object GenerationUtils {
|
||||
}
|
||||
}
|
||||
val (moduleFragment, symbolTable, sourceManager) =
|
||||
Fir2IrConverter.createModuleFragment(session, firFiles, configuration.languageVersionSettings)
|
||||
Fir2IrConverter.createModuleFragment(session, firFiles, configuration.languageVersionSettings, signaturer = IdSignatureDescriptor(JvmManglerDesc()))
|
||||
val dummyBindingContext = NoScopeRecordCliBindingTrace().bindingContext
|
||||
|
||||
val codegenFactory = JvmIrCodegenFactory(configuration.get(CLIConfigurationKeys.PHASE_CONFIG) ?: PhaseConfig(jvmPhases))
|
||||
|
||||
@@ -17,12 +17,13 @@
|
||||
package org.jetbrains.kotlin.ir
|
||||
|
||||
import org.jetbrains.kotlin.analyzer.AnalysisResult
|
||||
import org.jetbrains.kotlin.backend.common.serialization.signature.IdSignatureDescriptor
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmGeneratorExtensions
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||
import org.jetbrains.kotlin.codegen.CodegenTestCase
|
||||
import org.jetbrains.kotlin.config.languageVersionSettings
|
||||
import org.jetbrains.kotlin.ir.backend.js.JsGeneratorExtensions
|
||||
import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsManglerDesc
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
||||
import org.jetbrains.kotlin.js.analyze.TopDownAnalyzerFacadeForJS
|
||||
@@ -84,7 +85,11 @@ abstract class AbstractIrGeneratorTestCase : CodegenTestCase() {
|
||||
protected open fun generateIrModule(ignoreErrors: Boolean = false): IrModuleFragment {
|
||||
assert(myFiles != null) { "myFiles not initialized" }
|
||||
assert(myEnvironment != null) { "myEnvironment not initialized" }
|
||||
return doGenerateIrModule(Psi2IrTranslator(myEnvironment.configuration.languageVersionSettings, Psi2IrConfiguration(ignoreErrors)))
|
||||
val mangler = JsManglerDesc
|
||||
val signaturer = IdSignatureDescriptor(mangler)
|
||||
return doGenerateIrModule(Psi2IrTranslator(myEnvironment.configuration.languageVersionSettings,
|
||||
Psi2IrConfiguration(ignoreErrors),
|
||||
signaturer))
|
||||
}
|
||||
|
||||
protected open fun doGenerateIrModule(psi2IrTranslator: Psi2IrTranslator): IrModuleFragment =
|
||||
@@ -111,7 +116,7 @@ abstract class AbstractIrGeneratorTestCase : CodegenTestCase() {
|
||||
moduleDescriptors = emptyList(),
|
||||
friendModuleDescriptors = emptyList()
|
||||
),
|
||||
psi2ir, ktFilesToAnalyze, JsGeneratorExtensions()
|
||||
psi2ir, ktFilesToAnalyze, GeneratorExtensions()
|
||||
)
|
||||
|
||||
fun generateIrModuleWithJvmResolve(
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.ir
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import junit.framework.TestCase
|
||||
import org.jetbrains.kotlin.backend.common.serialization.signature.IdSignatureDescriptor
|
||||
import org.jetbrains.kotlin.cli.js.loadPluginsForTests
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.config.languageVersionSettings
|
||||
@@ -25,6 +26,7 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.findClassAcrossModuleDependencies
|
||||
import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsManglerDesc
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
||||
@@ -61,10 +63,12 @@ abstract class AbstractIrTextTestCase : AbstractIrGeneratorTestCase() {
|
||||
|
||||
private fun doTestIrModuleDependencies(wholeFile: File, irModule: IrModuleFragment) {
|
||||
val wholeText = wholeFile.readText()
|
||||
val mangler = JsManglerDesc
|
||||
val signaturer = IdSignatureDescriptor(mangler)
|
||||
|
||||
val stubGenerator = DeclarationStubGenerator(
|
||||
irModule.descriptor,
|
||||
SymbolTable(), // TODO
|
||||
SymbolTable(signaturer), // TODO
|
||||
myEnvironment.configuration.languageVersionSettings
|
||||
)
|
||||
|
||||
|
||||
+3
-1
@@ -5,10 +5,12 @@
|
||||
|
||||
package org.jetbrains.kotlin.scripting.compiler.plugin.impl
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.serialization.signature.IdSignatureDescriptor
|
||||
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
|
||||
import org.jetbrains.kotlin.cli.common.repl.ReplCompileResult
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsManglerDesc
|
||||
import org.jetbrains.kotlin.ir.backend.js.utils.NameTables
|
||||
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||
import org.jetbrains.kotlin.scripting.compiler.plugin.ScriptCompilerProxy
|
||||
@@ -20,7 +22,7 @@ import kotlin.script.experimental.api.*
|
||||
|
||||
class JsScriptCompilerWithDependenciesProxy(private val environment: KotlinCoreEnvironment) : ScriptCompilerProxy {
|
||||
private val nameTables = NameTables(emptyList())
|
||||
private val symbolTable = SymbolTable()
|
||||
private val symbolTable = SymbolTable(IdSignatureDescriptor(JsManglerDesc))
|
||||
private val dependencies: List<ModuleDescriptor> = readLibrariesFromConfiguration(environment.configuration)
|
||||
private val compiler = JsCoreScriptingCompiler(environment, nameTables, symbolTable, dependencies)
|
||||
private var scriptDependencyCompiler: JsScriptDependencyCompiler? =
|
||||
|
||||
+5
-3
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.scripting.repl.js
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.serialization.signature.IdSignatureDescriptor
|
||||
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
|
||||
import org.jetbrains.kotlin.cli.common.environment.setIdeaIoUseFallback
|
||||
import org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport
|
||||
@@ -18,7 +19,7 @@ import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.ir.backend.js.JsIrBackendContext
|
||||
import org.jetbrains.kotlin.ir.backend.js.generateJsCode
|
||||
import org.jetbrains.kotlin.ir.backend.js.generateModuleFragment
|
||||
import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsMangler
|
||||
import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsManglerDesc
|
||||
import org.jetbrains.kotlin.ir.backend.js.utils.NameTables
|
||||
import org.jetbrains.kotlin.ir.util.ExternalDependenciesGenerator
|
||||
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||
@@ -59,8 +60,9 @@ class JsCoreScriptingCompiler(
|
||||
|
||||
val module = analysisResult.moduleDescriptor
|
||||
val bindingContext = analysisResult.bindingContext
|
||||
|
||||
val psi2ir = Psi2IrTranslator(environment.configuration.languageVersionSettings, mangler = JsMangler)
|
||||
val mangler = JsManglerDesc
|
||||
val signaturer = IdSignatureDescriptor(mangler)
|
||||
val psi2ir = Psi2IrTranslator(environment.configuration.languageVersionSettings, signaturer = signaturer)
|
||||
val psi2irContext = psi2ir.createGeneratorContext(module, bindingContext, symbolTable)
|
||||
|
||||
val irModuleFragment = psi2irContext.generateModuleFragment(listOf(snippetKtFile))
|
||||
|
||||
+3
-1
@@ -5,8 +5,10 @@
|
||||
|
||||
package org.jetbrains.kotlin.scripting.repl.js
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.serialization.signature.IdSignatureDescriptor
|
||||
import org.jetbrains.kotlin.cli.common.repl.*
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||
import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsManglerDesc
|
||||
import org.jetbrains.kotlin.ir.backend.js.utils.NameTables
|
||||
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||
import org.jetbrains.kotlin.scripting.compiler.plugin.repl.ReplCodeAnalyzer
|
||||
@@ -21,7 +23,7 @@ class JsReplCompiler(private val environment: KotlinCoreEnvironment) : ReplCompi
|
||||
NameTables(emptyList()),
|
||||
readLibrariesFromConfiguration(environment.configuration),
|
||||
ReplCodeAnalyzer.ResettableAnalyzerState(),
|
||||
SymbolTable()
|
||||
SymbolTable(IdSignatureDescriptor(JsManglerDesc))
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+5
-3
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.scripting.repl.js
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.serialization.signature.IdSignatureDescriptor
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettingsImpl
|
||||
@@ -15,7 +16,7 @@ import org.jetbrains.kotlin.ir.backend.js.JsIrBackendContext
|
||||
import org.jetbrains.kotlin.ir.backend.js.emptyLoggingContext
|
||||
import org.jetbrains.kotlin.ir.backend.js.generateJsCode
|
||||
import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsIrLinker
|
||||
import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsMangler
|
||||
import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsManglerDesc
|
||||
import org.jetbrains.kotlin.ir.backend.js.utils.NameTables
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrModuleFragmentImpl
|
||||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
||||
@@ -45,8 +46,9 @@ class JsScriptDependencyCompiler(
|
||||
it.constantValueGenerator = ConstantValueGenerator(moduleDescriptor, symbolTable)
|
||||
}
|
||||
|
||||
val irBuiltIns = IrBuiltIns(builtIns, typeTranslator, symbolTable)
|
||||
val jsLinker = JsIrLinker(moduleDescriptor, JsMangler, emptyLoggingContext, irBuiltIns, symbolTable)
|
||||
val signaturer = IdSignatureDescriptor(JsManglerDesc)
|
||||
val irBuiltIns = IrBuiltIns(builtIns, typeTranslator, signaturer, symbolTable)
|
||||
val jsLinker = JsIrLinker(emptyLoggingContext, irBuiltIns, symbolTable)
|
||||
|
||||
val moduleFragment = IrModuleFragmentImpl(moduleDescriptor, irBuiltIns)
|
||||
val irDependencies = dependencies.map { jsLinker.deserializeFullModule(it) }
|
||||
|
||||
Reference in New Issue
Block a user