IR: use DescriptorBySignatureFinder in DeclarationStubGenerator
Duplicating code that was used for the same purpose in DeclarationStubGenerator is removed.
This commit is contained in:
committed by
TeamCityServer
parent
162dcef73a
commit
3cc883cf7b
@@ -103,7 +103,8 @@ class FirAnalyzerFacade(
|
|||||||
|
|
||||||
override fun convertToIr(extensions: GeneratorExtensions): Fir2IrResult {
|
override fun convertToIr(extensions: GeneratorExtensions): Fir2IrResult {
|
||||||
if (_scopeSession == null) runResolution()
|
if (_scopeSession == null) runResolution()
|
||||||
val signaturer = JvmIdSignatureDescriptor(JvmDescriptorMangler(null))
|
val mangler = JvmDescriptorMangler(null)
|
||||||
|
val signaturer = JvmIdSignatureDescriptor(mangler)
|
||||||
|
|
||||||
val commonFirFiles = session.moduleData.dependsOnDependencies
|
val commonFirFiles = session.moduleData.dependsOnDependencies
|
||||||
.map { it.session }
|
.map { it.session }
|
||||||
@@ -112,7 +113,7 @@ class FirAnalyzerFacade(
|
|||||||
|
|
||||||
return Fir2IrConverter.createModuleFragment(
|
return Fir2IrConverter.createModuleFragment(
|
||||||
session, _scopeSession!!, firFiles!! + commonFirFiles,
|
session, _scopeSession!!, firFiles!! + commonFirFiles,
|
||||||
languageVersionSettings, signaturer,
|
languageVersionSettings, mangler, signaturer,
|
||||||
extensions, FirJvmKotlinMangler(session), IrFactoryImpl,
|
extensions, FirJvmKotlinMangler(session), IrFactoryImpl,
|
||||||
FirJvmVisibilityConverter,
|
FirJvmVisibilityConverter,
|
||||||
Fir2IrJvmSpecialAnnotationSymbolProvider(),
|
Fir2IrJvmSpecialAnnotationSymbolProvider(),
|
||||||
|
|||||||
@@ -29,7 +29,8 @@ fun FirSession.convertToIr(
|
|||||||
extensions: GeneratorExtensions,
|
extensions: GeneratorExtensions,
|
||||||
irGeneratorExtensions: Collection<IrGenerationExtension>
|
irGeneratorExtensions: Collection<IrGenerationExtension>
|
||||||
): Fir2IrResult {
|
): Fir2IrResult {
|
||||||
val signaturer = JvmIdSignatureDescriptor(JvmDescriptorMangler(null))
|
val mangler = JvmDescriptorMangler(null)
|
||||||
|
val signaturer = JvmIdSignatureDescriptor(mangler)
|
||||||
|
|
||||||
val commonFirFiles = moduleData.dependsOnDependencies
|
val commonFirFiles = moduleData.dependsOnDependencies
|
||||||
.map { it.session }
|
.map { it.session }
|
||||||
@@ -38,7 +39,7 @@ fun FirSession.convertToIr(
|
|||||||
|
|
||||||
return Fir2IrConverter.createModuleFragment(
|
return Fir2IrConverter.createModuleFragment(
|
||||||
this, scopeSession, firFiles + commonFirFiles,
|
this, scopeSession, firFiles + commonFirFiles,
|
||||||
languageVersionSettings, signaturer,
|
languageVersionSettings, mangler, signaturer,
|
||||||
extensions, FirJvmKotlinMangler(this), IrFactoryImpl,
|
extensions, FirJvmKotlinMangler(this), IrFactoryImpl,
|
||||||
FirJvmVisibilityConverter,
|
FirJvmVisibilityConverter,
|
||||||
Fir2IrJvmSpecialAnnotationSymbolProvider(),
|
Fir2IrJvmSpecialAnnotationSymbolProvider(),
|
||||||
|
|||||||
@@ -410,6 +410,7 @@ class Fir2IrConverter(
|
|||||||
scopeSession: ScopeSession,
|
scopeSession: ScopeSession,
|
||||||
firFiles: List<FirFile>,
|
firFiles: List<FirFile>,
|
||||||
languageVersionSettings: LanguageVersionSettings,
|
languageVersionSettings: LanguageVersionSettings,
|
||||||
|
descriptorMangler: KotlinMangler.DescriptorMangler,
|
||||||
signaturer: IdSignatureComposer,
|
signaturer: IdSignatureComposer,
|
||||||
generatorExtensions: GeneratorExtensions,
|
generatorExtensions: GeneratorExtensions,
|
||||||
mangler: FirMangler,
|
mangler: FirMangler,
|
||||||
|
|||||||
+6
-2
@@ -94,7 +94,9 @@ open class JvmIrCodegenFactory(
|
|||||||
val pluginExtensions = IrGenerationExtension.getInstances(input.project)
|
val pluginExtensions = IrGenerationExtension.getInstances(input.project)
|
||||||
|
|
||||||
val stubGenerator =
|
val stubGenerator =
|
||||||
DeclarationStubGeneratorImpl(psi2irContext.moduleDescriptor, symbolTable, psi2irContext.irBuiltIns, jvmGeneratorExtensions)
|
DeclarationStubGeneratorImpl(
|
||||||
|
psi2irContext.moduleDescriptor, symbolTable, psi2irContext.irBuiltIns, mangler, jvmGeneratorExtensions
|
||||||
|
)
|
||||||
val frontEndContext = object : TranslationPluginContext {
|
val frontEndContext = object : TranslationPluginContext {
|
||||||
override val moduleDescriptor: ModuleDescriptor
|
override val moduleDescriptor: ModuleDescriptor
|
||||||
get() = psi2irContext.moduleDescriptor
|
get() = psi2irContext.moduleDescriptor
|
||||||
@@ -287,7 +289,9 @@ open class JvmIrCodegenFactory(
|
|||||||
extensions: JvmGeneratorExtensionsImpl,
|
extensions: JvmGeneratorExtensionsImpl,
|
||||||
): List<IrProvider> {
|
): List<IrProvider> {
|
||||||
return generateTypicalIrProviderList(
|
return generateTypicalIrProviderList(
|
||||||
irModuleFragment.descriptor, irModuleFragment.irBuiltins, symbolTable, extensions = extensions
|
irModuleFragment.descriptor, irModuleFragment.irBuiltins, symbolTable,
|
||||||
|
JvmDescriptorMangler(null),
|
||||||
|
extensions = extensions
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ dependencies {
|
|||||||
api(project(":compiler:frontend"))
|
api(project(":compiler:frontend"))
|
||||||
api(project(":compiler:backend-common"))
|
api(project(":compiler:backend-common"))
|
||||||
api(project(":compiler:ir.tree"))
|
api(project(":compiler:ir.tree"))
|
||||||
|
api(project(":compiler:ir.serialization.common"))
|
||||||
compileOnly(intellijCore())
|
compileOnly(intellijCore())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+10
-1
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.psi2ir.generators
|
package org.jetbrains.kotlin.psi2ir.generators
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.backend.common.serialization.DescriptorByIdSignatureFinderImpl
|
||||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.NotFoundClasses
|
import org.jetbrains.kotlin.descriptors.NotFoundClasses
|
||||||
import org.jetbrains.kotlin.ir.IrBuiltIns
|
import org.jetbrains.kotlin.ir.IrBuiltIns
|
||||||
@@ -20,6 +21,7 @@ class DeclarationStubGeneratorImpl(
|
|||||||
moduleDescriptor: ModuleDescriptor,
|
moduleDescriptor: ModuleDescriptor,
|
||||||
symbolTable: SymbolTable,
|
symbolTable: SymbolTable,
|
||||||
irBuiltins: IrBuiltIns,
|
irBuiltins: IrBuiltIns,
|
||||||
|
mangler: KotlinMangler.DescriptorMangler,
|
||||||
extensions: StubGeneratorExtensions = StubGeneratorExtensions.EMPTY,
|
extensions: StubGeneratorExtensions = StubGeneratorExtensions.EMPTY,
|
||||||
) : DeclarationStubGenerator(moduleDescriptor, symbolTable, irBuiltins, extensions) {
|
) : DeclarationStubGenerator(moduleDescriptor, symbolTable, irBuiltins, extensions) {
|
||||||
override val typeTranslator: TypeTranslator =
|
override val typeTranslator: TypeTranslator =
|
||||||
@@ -31,6 +33,12 @@ class DeclarationStubGeneratorImpl(
|
|||||||
true,
|
true,
|
||||||
extensions
|
extensions
|
||||||
)
|
)
|
||||||
|
|
||||||
|
override val descriptorFinder: DescriptorByIdSignatureFinder = DescriptorByIdSignatureFinderImpl(
|
||||||
|
moduleDescriptor,
|
||||||
|
mangler,
|
||||||
|
DescriptorByIdSignatureFinderImpl.LookupMode.MODULE_WITH_DEPENDENCIES
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// In most cases, IrProviders list consist of an optional deserializer and a DeclarationStubGenerator.
|
// In most cases, IrProviders list consist of an optional deserializer and a DeclarationStubGenerator.
|
||||||
@@ -38,11 +46,12 @@ fun generateTypicalIrProviderList(
|
|||||||
moduleDescriptor: ModuleDescriptor,
|
moduleDescriptor: ModuleDescriptor,
|
||||||
irBuiltins: IrBuiltIns,
|
irBuiltins: IrBuiltIns,
|
||||||
symbolTable: SymbolTable,
|
symbolTable: SymbolTable,
|
||||||
|
mangler: KotlinMangler.DescriptorMangler,
|
||||||
deserializer: IrDeserializer? = null,
|
deserializer: IrDeserializer? = null,
|
||||||
extensions: StubGeneratorExtensions = StubGeneratorExtensions.EMPTY
|
extensions: StubGeneratorExtensions = StubGeneratorExtensions.EMPTY
|
||||||
): List<IrProvider> {
|
): List<IrProvider> {
|
||||||
val stubGenerator = DeclarationStubGeneratorImpl(
|
val stubGenerator = DeclarationStubGeneratorImpl(
|
||||||
moduleDescriptor, symbolTable, irBuiltins, extensions
|
moduleDescriptor, symbolTable, irBuiltins, mangler, extensions
|
||||||
)
|
)
|
||||||
return listOfNotNull(deserializer, stubGenerator)
|
return listOfNotNull(deserializer, stubGenerator)
|
||||||
}
|
}
|
||||||
|
|||||||
-1
@@ -40,7 +40,6 @@ class IrLazyTypeParameter(
|
|||||||
|
|
||||||
override var superTypes: List<IrType> by lazyVar(stubGenerator.lock) {
|
override var superTypes: List<IrType> by lazyVar(stubGenerator.lock) {
|
||||||
typeTranslator.buildWithScope(this.parent as IrTypeParametersContainer) {
|
typeTranslator.buildWithScope(this.parent as IrTypeParametersContainer) {
|
||||||
val descriptor = symbol.descriptor
|
|
||||||
descriptor.upperBounds.mapTo(arrayListOf()) { it.toIrType() }
|
descriptor.upperBounds.mapTo(arrayListOf()) { it.toIrType() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ abstract class DeclarationStubGenerator(
|
|||||||
}
|
}
|
||||||
|
|
||||||
abstract val typeTranslator: TypeTranslator
|
abstract val typeTranslator: TypeTranslator
|
||||||
|
abstract val descriptorFinder: DescriptorByIdSignatureFinder
|
||||||
|
|
||||||
private val facadeClassMap = mutableMapOf<DeserializedContainerSource, IrClass?>()
|
private val facadeClassMap = mutableMapOf<DeserializedContainerSource, IrClass?>()
|
||||||
|
|
||||||
@@ -70,7 +71,7 @@ abstract class DeclarationStubGenerator(
|
|||||||
// return generateStubBySymbol(symbol, symbol.descriptor)
|
// return generateStubBySymbol(symbol, symbol.descriptor)
|
||||||
// }
|
// }
|
||||||
val descriptor = if (!symbol.hasDescriptor)
|
val descriptor = if (!symbol.hasDescriptor)
|
||||||
findDescriptorBySignature(
|
descriptorFinder.findDescriptorBySignature(
|
||||||
symbol.signature
|
symbol.signature
|
||||||
?: error("Symbol is not public API. Expected signature for symbol: ${symbol.descriptor}")
|
?: error("Symbol is not public API. Expected signature for symbol: ${symbol.descriptor}")
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.ir.util
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||||
|
|
||||||
|
interface DescriptorByIdSignatureFinder {
|
||||||
|
fun findDescriptorBySignature(signature: IdSignature): DeclarationDescriptor?
|
||||||
|
}
|
||||||
@@ -24,35 +24,43 @@ import org.jetbrains.kotlin.utils.threadLocal
|
|||||||
|
|
||||||
interface ReferenceSymbolTable {
|
interface ReferenceSymbolTable {
|
||||||
fun referenceClass(descriptor: ClassDescriptor): IrClassSymbol
|
fun referenceClass(descriptor: ClassDescriptor): IrClassSymbol
|
||||||
|
fun referenceClass(sig: IdSignature, reg: Boolean = true): IrClassSymbol
|
||||||
|
|
||||||
fun referenceScript(descriptor: ScriptDescriptor): IrScriptSymbol
|
fun referenceScript(descriptor: ScriptDescriptor): IrScriptSymbol
|
||||||
|
|
||||||
fun referenceConstructor(descriptor: ClassConstructorDescriptor): IrConstructorSymbol
|
fun referenceConstructor(descriptor: ClassConstructorDescriptor): IrConstructorSymbol
|
||||||
|
fun referenceConstructor(sig: IdSignature, reg: Boolean = true): IrConstructorSymbol
|
||||||
|
|
||||||
fun referenceEnumEntry(descriptor: ClassDescriptor): IrEnumEntrySymbol
|
fun referenceEnumEntry(descriptor: ClassDescriptor): IrEnumEntrySymbol
|
||||||
|
fun referenceEnumEntry(sig: IdSignature, reg: Boolean = true): IrEnumEntrySymbol
|
||||||
fun referenceField(descriptor: PropertyDescriptor): IrFieldSymbol
|
fun referenceField(descriptor: PropertyDescriptor): IrFieldSymbol
|
||||||
|
fun referenceField(sig: IdSignature, reg: Boolean = true): IrFieldSymbol
|
||||||
fun referenceProperty(descriptor: PropertyDescriptor): IrPropertySymbol
|
fun referenceProperty(descriptor: PropertyDescriptor): IrPropertySymbol
|
||||||
|
fun referenceProperty(sig: IdSignature, reg: Boolean = true): IrPropertySymbol
|
||||||
|
|
||||||
fun referenceProperty(descriptor: PropertyDescriptor, generate: () -> IrProperty): IrProperty
|
fun referenceProperty(descriptor: PropertyDescriptor, generate: () -> IrProperty): IrProperty
|
||||||
|
|
||||||
fun referenceSimpleFunction(descriptor: FunctionDescriptor): IrSimpleFunctionSymbol
|
fun referenceSimpleFunction(descriptor: FunctionDescriptor): IrSimpleFunctionSymbol
|
||||||
|
fun referenceSimpleFunction(sig: IdSignature, reg: Boolean = true): IrSimpleFunctionSymbol
|
||||||
fun referenceDeclaredFunction(descriptor: FunctionDescriptor): IrSimpleFunctionSymbol
|
fun referenceDeclaredFunction(descriptor: FunctionDescriptor): IrSimpleFunctionSymbol
|
||||||
fun referenceValueParameter(descriptor: ParameterDescriptor): IrValueParameterSymbol
|
fun referenceValueParameter(descriptor: ParameterDescriptor): IrValueParameterSymbol
|
||||||
|
|
||||||
fun referenceTypeParameter(classifier: TypeParameterDescriptor): IrTypeParameterSymbol
|
fun referenceTypeParameter(classifier: TypeParameterDescriptor): IrTypeParameterSymbol
|
||||||
|
fun referenceTypeParameter(sig: IdSignature, reg: Boolean = true): IrTypeParameterSymbol
|
||||||
fun referenceScopedTypeParameter(classifier: TypeParameterDescriptor): IrTypeParameterSymbol
|
fun referenceScopedTypeParameter(classifier: TypeParameterDescriptor): IrTypeParameterSymbol
|
||||||
fun referenceVariable(descriptor: VariableDescriptor): IrVariableSymbol
|
fun referenceVariable(descriptor: VariableDescriptor): IrVariableSymbol
|
||||||
|
|
||||||
fun referenceTypeAlias(descriptor: TypeAliasDescriptor): IrTypeAliasSymbol
|
fun referenceTypeAlias(descriptor: TypeAliasDescriptor): IrTypeAliasSymbol
|
||||||
|
fun referenceTypeAlias(sig: IdSignature, reg: Boolean = true): IrTypeAliasSymbol
|
||||||
|
|
||||||
fun referenceClassFromLinker(sig: IdSignature): IrClassSymbol
|
fun referenceClassFromLinker(sig: IdSignature) = referenceClass(sig, false)
|
||||||
fun referenceConstructorFromLinker(sig: IdSignature): IrConstructorSymbol
|
fun referenceConstructorFromLinker(sig: IdSignature) = referenceConstructor(sig, false)
|
||||||
fun referenceEnumEntryFromLinker(sig: IdSignature): IrEnumEntrySymbol
|
fun referenceEnumEntryFromLinker(sig: IdSignature) = referenceEnumEntry(sig, false)
|
||||||
fun referenceFieldFromLinker(sig: IdSignature): IrFieldSymbol
|
fun referenceFieldFromLinker(sig: IdSignature) = referenceField(sig, false)
|
||||||
fun referencePropertyFromLinker(sig: IdSignature): IrPropertySymbol
|
fun referencePropertyFromLinker(sig: IdSignature) = referenceProperty(sig, false)
|
||||||
fun referenceSimpleFunctionFromLinker(sig: IdSignature): IrSimpleFunctionSymbol
|
fun referenceSimpleFunctionFromLinker(sig: IdSignature) = referenceSimpleFunction(sig, false)
|
||||||
fun referenceGlobalTypeParameterFromLinker(sig: IdSignature): IrTypeParameterSymbol
|
fun referenceGlobalTypeParameterFromLinker(sig: IdSignature) = referenceTypeParameter(sig, false)
|
||||||
fun referenceTypeAliasFromLinker(sig: IdSignature): IrTypeAliasSymbol
|
fun referenceTypeAliasFromLinker(sig: IdSignature) = referenceTypeAlias(sig, false)
|
||||||
|
|
||||||
fun enterScope(owner: IrSymbol)
|
fun enterScope(owner: IrSymbol)
|
||||||
fun enterScope(owner: IrDeclaration)
|
fun enterScope(owner: IrDeclaration)
|
||||||
@@ -485,9 +493,9 @@ open class SymbolTable(
|
|||||||
fun referenceClassIfAny(sig: IdSignature): IrClassSymbol? =
|
fun referenceClassIfAny(sig: IdSignature): IrClassSymbol? =
|
||||||
classSymbolTable.get(sig)
|
classSymbolTable.get(sig)
|
||||||
|
|
||||||
override fun referenceClassFromLinker(sig: IdSignature): IrClassSymbol =
|
override fun referenceClass(sig: IdSignature, reg: Boolean): IrClassSymbol =
|
||||||
classSymbolTable.run {
|
classSymbolTable.run {
|
||||||
if (sig.isPubliclyVisible) referenced(sig, false) { IrClassPublicSymbolImpl(sig) }
|
if (sig.isPubliclyVisible) referenced(sig, reg) { IrClassPublicSymbolImpl(sig) }
|
||||||
else IrClassSymbolImpl().also {
|
else IrClassSymbolImpl().also {
|
||||||
it.privateSignature = sig
|
it.privateSignature = sig
|
||||||
}
|
}
|
||||||
@@ -554,9 +562,9 @@ open class SymbolTable(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun referenceConstructorFromLinker(sig: IdSignature): IrConstructorSymbol =
|
override fun referenceConstructor(sig: IdSignature, reg: Boolean): IrConstructorSymbol =
|
||||||
constructorSymbolTable.run {
|
constructorSymbolTable.run {
|
||||||
if (sig.isPubliclyVisible) referenced(sig, false) { IrConstructorPublicSymbolImpl(sig) }
|
if (sig.isPubliclyVisible) referenced(sig, reg) { IrConstructorPublicSymbolImpl(sig) }
|
||||||
else IrConstructorSymbolImpl()
|
else IrConstructorSymbolImpl()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -603,9 +611,9 @@ open class SymbolTable(
|
|||||||
override fun referenceEnumEntry(descriptor: ClassDescriptor): IrEnumEntrySymbol =
|
override fun referenceEnumEntry(descriptor: ClassDescriptor): IrEnumEntrySymbol =
|
||||||
enumEntrySymbolTable.referenced(descriptor) { signature -> createEnumEntrySymbol(descriptor, signature) }
|
enumEntrySymbolTable.referenced(descriptor) { signature -> createEnumEntrySymbol(descriptor, signature) }
|
||||||
|
|
||||||
override fun referenceEnumEntryFromLinker(sig: IdSignature) =
|
override fun referenceEnumEntry(sig: IdSignature, reg: Boolean) =
|
||||||
enumEntrySymbolTable.run {
|
enumEntrySymbolTable.run {
|
||||||
if (sig.isPubliclyVisible) referenced(sig, false) { IrEnumEntryPublicSymbolImpl(sig) }
|
if (sig.isPubliclyVisible) referenced(sig, reg) { IrEnumEntryPublicSymbolImpl(sig) }
|
||||||
else IrEnumEntrySymbolImpl()
|
else IrEnumEntrySymbolImpl()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -672,9 +680,11 @@ open class SymbolTable(
|
|||||||
override fun referenceField(descriptor: PropertyDescriptor): IrFieldSymbol =
|
override fun referenceField(descriptor: PropertyDescriptor): IrFieldSymbol =
|
||||||
fieldSymbolTable.referenced(descriptor) { signature -> createFieldSymbol(descriptor, signature) }
|
fieldSymbolTable.referenced(descriptor) { signature -> createFieldSymbol(descriptor, signature) }
|
||||||
|
|
||||||
override fun referenceFieldFromLinker(sig: IdSignature): IrFieldSymbol =
|
override fun referenceField(sig: IdSignature, reg: Boolean): IrFieldSymbol =
|
||||||
fieldSymbolTable.run {
|
fieldSymbolTable.run {
|
||||||
if (sig.isPubliclyVisible) IrFieldPublicSymbolImpl(sig) else IrFieldSymbolImpl()
|
if (sig.isPubliclyVisible) {
|
||||||
|
referenced(sig) { IrFieldPublicSymbolImpl(sig) }
|
||||||
|
} else IrFieldSymbolImpl()
|
||||||
}
|
}
|
||||||
|
|
||||||
val unboundFields: Set<IrFieldSymbol> get() = fieldSymbolTable.unboundSymbols
|
val unboundFields: Set<IrFieldSymbol> get() = fieldSymbolTable.unboundSymbols
|
||||||
@@ -750,9 +760,9 @@ open class SymbolTable(
|
|||||||
fun referencePropertyIfAny(sig: IdSignature): IrPropertySymbol? =
|
fun referencePropertyIfAny(sig: IdSignature): IrPropertySymbol? =
|
||||||
propertySymbolTable.get(sig)
|
propertySymbolTable.get(sig)
|
||||||
|
|
||||||
override fun referencePropertyFromLinker(sig: IdSignature): IrPropertySymbol =
|
override fun referenceProperty(sig: IdSignature, reg: Boolean): IrPropertySymbol =
|
||||||
propertySymbolTable.run {
|
propertySymbolTable.run {
|
||||||
if (sig.isPubliclyVisible) referenced(sig, false) { IrPropertyPublicSymbolImpl(sig) }
|
if (sig.isPubliclyVisible) referenced(sig, reg) { IrPropertyPublicSymbolImpl(sig) }
|
||||||
else IrPropertySymbolImpl()
|
else IrPropertySymbolImpl()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -764,9 +774,9 @@ open class SymbolTable(
|
|||||||
override fun referenceTypeAlias(descriptor: TypeAliasDescriptor): IrTypeAliasSymbol =
|
override fun referenceTypeAlias(descriptor: TypeAliasDescriptor): IrTypeAliasSymbol =
|
||||||
typeAliasSymbolTable.referenced(descriptor) { signature -> createTypeAliasSymbol(descriptor, signature) }
|
typeAliasSymbolTable.referenced(descriptor) { signature -> createTypeAliasSymbol(descriptor, signature) }
|
||||||
|
|
||||||
override fun referenceTypeAliasFromLinker(sig: IdSignature) =
|
override fun referenceTypeAlias(sig: IdSignature, reg: Boolean) =
|
||||||
typeAliasSymbolTable.run {
|
typeAliasSymbolTable.run {
|
||||||
if (sig.isPubliclyVisible) referenced(sig, false) { IrTypeAliasPublicSymbolImpl(sig) }
|
if (sig.isPubliclyVisible) referenced(sig, reg) { IrTypeAliasPublicSymbolImpl(sig) }
|
||||||
else IrTypeAliasSymbolImpl()
|
else IrTypeAliasSymbolImpl()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -840,9 +850,9 @@ open class SymbolTable(
|
|||||||
fun referenceSimpleFunctionIfAny(sig: IdSignature): IrSimpleFunctionSymbol? =
|
fun referenceSimpleFunctionIfAny(sig: IdSignature): IrSimpleFunctionSymbol? =
|
||||||
simpleFunctionSymbolTable.get(sig)
|
simpleFunctionSymbolTable.get(sig)
|
||||||
|
|
||||||
override fun referenceSimpleFunctionFromLinker(sig: IdSignature): IrSimpleFunctionSymbol {
|
override fun referenceSimpleFunction(sig: IdSignature, reg: Boolean): IrSimpleFunctionSymbol {
|
||||||
return simpleFunctionSymbolTable.run {
|
return simpleFunctionSymbolTable.run {
|
||||||
if (sig.isPubliclyVisible) referenced(sig, false) { IrSimpleFunctionPublicSymbolImpl(sig) }
|
if (sig.isPubliclyVisible) referenced(sig, reg) { IrSimpleFunctionPublicSymbolImpl(sig) }
|
||||||
else IrSimpleFunctionSymbolImpl().also {
|
else IrSimpleFunctionSymbolImpl().also {
|
||||||
it.privateSignature = sig
|
it.privateSignature = sig
|
||||||
}
|
}
|
||||||
@@ -970,8 +980,8 @@ open class SymbolTable(
|
|||||||
override fun referenceScopedTypeParameter(classifier: TypeParameterDescriptor): IrTypeParameterSymbol =
|
override fun referenceScopedTypeParameter(classifier: TypeParameterDescriptor): IrTypeParameterSymbol =
|
||||||
scopedTypeParameterSymbolTable.referenced(classifier) { signature -> createTypeParameterSymbol(classifier, signature) }
|
scopedTypeParameterSymbolTable.referenced(classifier) { signature -> createTypeParameterSymbol(classifier, signature) }
|
||||||
|
|
||||||
override fun referenceGlobalTypeParameterFromLinker(sig: IdSignature): IrTypeParameterSymbol =
|
override fun referenceTypeParameter(sig: IdSignature, reg: Boolean): IrTypeParameterSymbol =
|
||||||
globalTypeParameterSymbolTable.referenced(sig, false) {
|
globalTypeParameterSymbolTable.referenced(sig, reg) {
|
||||||
if (sig.isPubliclyVisible) IrTypeParameterPublicSymbolImpl(sig) else IrTypeParameterSymbolImpl()
|
if (sig.isPubliclyVisible) IrTypeParameterPublicSymbolImpl(sig) else IrTypeParameterSymbolImpl()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-3
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.backend.common.serialization.mangle.MangleConstant
|
|||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
|
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
|
||||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||||
|
import org.jetbrains.kotlin.ir.util.DescriptorByIdSignatureFinder
|
||||||
import org.jetbrains.kotlin.ir.util.IdSignature
|
import org.jetbrains.kotlin.ir.util.IdSignature
|
||||||
import org.jetbrains.kotlin.ir.util.KotlinMangler
|
import org.jetbrains.kotlin.ir.util.KotlinMangler
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
@@ -16,11 +17,11 @@ import org.jetbrains.kotlin.name.Name
|
|||||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||||
|
|
||||||
class DescriptorByIdSignatureFinder(
|
class DescriptorByIdSignatureFinderImpl(
|
||||||
private val moduleDescriptor: ModuleDescriptor,
|
private val moduleDescriptor: ModuleDescriptor,
|
||||||
private val mangler: KotlinMangler.DescriptorMangler,
|
private val mangler: KotlinMangler.DescriptorMangler,
|
||||||
private val lookupMode: LookupMode
|
private val lookupMode: LookupMode
|
||||||
) {
|
) : DescriptorByIdSignatureFinder {
|
||||||
init {
|
init {
|
||||||
assert(lookupMode != LookupMode.MODULE_ONLY || moduleDescriptor is ModuleDescriptorImpl) {
|
assert(lookupMode != LookupMode.MODULE_ONLY || moduleDescriptor is ModuleDescriptorImpl) {
|
||||||
"Incorrect lookup mode $lookupMode for $moduleDescriptor"
|
"Incorrect lookup mode $lookupMode for $moduleDescriptor"
|
||||||
@@ -42,7 +43,7 @@ class DescriptorByIdSignatureFinder(
|
|||||||
MODULE_ONLY
|
MODULE_ONLY
|
||||||
}
|
}
|
||||||
|
|
||||||
fun findDescriptorBySignature(signature: IdSignature): DeclarationDescriptor? =
|
override fun findDescriptorBySignature(signature: IdSignature): DeclarationDescriptor? =
|
||||||
when (signature) {
|
when (signature) {
|
||||||
is IdSignature.AccessorSignature -> findDescriptorForAccessorSignature(signature)
|
is IdSignature.AccessorSignature -> findDescriptorForAccessorSignature(signature)
|
||||||
is IdSignature.CommonSignature -> findDescriptorForPublicSignature(signature)
|
is IdSignature.CommonSignature -> findDescriptorForPublicSignature(signature)
|
||||||
+12
-11
@@ -54,10 +54,10 @@ fun deserializeFromByteArray(
|
|||||||
irProto.debugInfoList
|
irProto.debugInfoList
|
||||||
)
|
)
|
||||||
val descriptorFinder =
|
val descriptorFinder =
|
||||||
DescriptorByIdSignatureFinder(
|
DescriptorByIdSignatureFinderImpl(
|
||||||
stubGenerator.moduleDescriptor,
|
stubGenerator.moduleDescriptor,
|
||||||
JvmDescriptorMangler(null),
|
JvmDescriptorMangler(null),
|
||||||
DescriptorByIdSignatureFinder.LookupMode.MODULE_WITH_DEPENDENCIES
|
DescriptorByIdSignatureFinderImpl.LookupMode.MODULE_WITH_DEPENDENCIES
|
||||||
)
|
)
|
||||||
|
|
||||||
// Only needed for local signature computation.
|
// Only needed for local signature computation.
|
||||||
@@ -129,13 +129,13 @@ private class IrLibraryFileFromAnnotation(
|
|||||||
|
|
||||||
private fun referencePublicSymbol(
|
private fun referencePublicSymbol(
|
||||||
symbolTable: SymbolTable,
|
symbolTable: SymbolTable,
|
||||||
descriptorFinder: DescriptorByIdSignatureFinder,
|
descriptorFinder: DescriptorByIdSignatureFinderImpl,
|
||||||
idSig: IdSignature,
|
idSig: IdSignature,
|
||||||
symbolKind: BinarySymbolData.SymbolKind
|
symbolKind: BinarySymbolData.SymbolKind
|
||||||
): IrSymbol {
|
): IrSymbol {
|
||||||
with(symbolTable) {
|
with(symbolTable) {
|
||||||
val descriptor = descriptorFinder.findDescriptorBySignature(idSig)
|
val descriptor = descriptorFinder.findDescriptorBySignature(idSig)
|
||||||
return if (descriptor != null) {
|
return if (descriptor != null && false) {
|
||||||
when (symbolKind) {
|
when (symbolKind) {
|
||||||
BinarySymbolData.SymbolKind.CLASS_SYMBOL -> referenceClass(descriptor as ClassDescriptor)
|
BinarySymbolData.SymbolKind.CLASS_SYMBOL -> referenceClass(descriptor as ClassDescriptor)
|
||||||
BinarySymbolData.SymbolKind.CONSTRUCTOR_SYMBOL -> referenceConstructor(descriptor as ClassConstructorDescriptor)
|
BinarySymbolData.SymbolKind.CONSTRUCTOR_SYMBOL -> referenceConstructor(descriptor as ClassConstructorDescriptor)
|
||||||
@@ -150,14 +150,15 @@ private fun referencePublicSymbol(
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
when (symbolKind) {
|
when (symbolKind) {
|
||||||
BinarySymbolData.SymbolKind.CLASS_SYMBOL -> referenceClassFromLinker(idSig)
|
BinarySymbolData.SymbolKind.CLASS_SYMBOL -> referenceClass(idSig)
|
||||||
BinarySymbolData.SymbolKind.CONSTRUCTOR_SYMBOL -> referenceConstructorFromLinker(idSig)
|
BinarySymbolData.SymbolKind.CONSTRUCTOR_SYMBOL -> referenceConstructor(idSig)
|
||||||
BinarySymbolData.SymbolKind.ENUM_ENTRY_SYMBOL -> referenceEnumEntryFromLinker(idSig)
|
BinarySymbolData.SymbolKind.ENUM_ENTRY_SYMBOL -> referenceEnumEntry(idSig)
|
||||||
BinarySymbolData.SymbolKind.STANDALONE_FIELD_SYMBOL, BinarySymbolData.SymbolKind.FIELD_SYMBOL
|
BinarySymbolData.SymbolKind.STANDALONE_FIELD_SYMBOL, BinarySymbolData.SymbolKind.FIELD_SYMBOL
|
||||||
-> referenceFieldFromLinker(idSig)
|
-> referenceField(idSig)
|
||||||
BinarySymbolData.SymbolKind.FUNCTION_SYMBOL -> referenceSimpleFunctionFromLinker(idSig)
|
BinarySymbolData.SymbolKind.FUNCTION_SYMBOL -> referenceSimpleFunction(idSig)
|
||||||
BinarySymbolData.SymbolKind.TYPEALIAS_SYMBOL -> referenceTypeAliasFromLinker(idSig)
|
BinarySymbolData.SymbolKind.TYPEALIAS_SYMBOL -> referenceTypeAlias(idSig)
|
||||||
BinarySymbolData.SymbolKind.PROPERTY_SYMBOL -> referencePropertyFromLinker(idSig)
|
BinarySymbolData.SymbolKind.PROPERTY_SYMBOL -> referenceProperty(idSig)
|
||||||
|
BinarySymbolData.SymbolKind.TYPE_PARAMETER_SYMBOL -> referenceTypeParameter(idSig)
|
||||||
else -> error("Unexpected classifier symbol kind: $symbolKind for signature $idSig")
|
else -> error("Unexpected classifier symbol kind: $symbolKind for signature $idSig")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -125,9 +125,9 @@ class JvmIrLinker(
|
|||||||
// TODO: implement proper check whether `idSig` belongs to this module
|
// TODO: implement proper check whether `idSig` belongs to this module
|
||||||
override fun contains(idSig: IdSignature): Boolean = true
|
override fun contains(idSig: IdSignature): Boolean = true
|
||||||
|
|
||||||
private val descriptorFinder = DescriptorByIdSignatureFinder(
|
private val descriptorFinder = DescriptorByIdSignatureFinderImpl(
|
||||||
moduleDescriptor, manglerDesc,
|
moduleDescriptor, manglerDesc,
|
||||||
DescriptorByIdSignatureFinder.LookupMode.MODULE_ONLY
|
DescriptorByIdSignatureFinderImpl.LookupMode.MODULE_ONLY
|
||||||
)
|
)
|
||||||
|
|
||||||
private fun resolveDescriptor(idSig: IdSignature): DeclarationDescriptor {
|
private fun resolveDescriptor(idSig: IdSignature): DeclarationDescriptor {
|
||||||
|
|||||||
+2
-1
@@ -88,7 +88,8 @@ class IrTextDumpHandler(testServices: TestServices) : AbstractIrHandler(testServ
|
|||||||
val stubGenerator = DeclarationStubGeneratorImpl(
|
val stubGenerator = DeclarationStubGeneratorImpl(
|
||||||
irModule.descriptor,
|
irModule.descriptor,
|
||||||
SymbolTable(signaturer, IrFactoryImpl), // TODO
|
SymbolTable(signaturer, IrFactoryImpl), // TODO
|
||||||
irModule.irBuiltins
|
irModule.irBuiltins,
|
||||||
|
mangler,
|
||||||
)
|
)
|
||||||
|
|
||||||
val baseFile = testServices.moduleStructure.originalTestDataFiles.first()
|
val baseFile = testServices.moduleStructure.originalTestDataFiles.first()
|
||||||
|
|||||||
@@ -168,7 +168,9 @@ abstract class AbstractIrGeneratorTestCase : CodegenTestCase() {
|
|||||||
generatorExtensions
|
generatorExtensions
|
||||||
)
|
)
|
||||||
val irProviders = generateTypicalIrProviderList(
|
val irProviders = generateTypicalIrProviderList(
|
||||||
moduleDescriptor, context.irBuiltIns, context.symbolTable, extensions = generatorExtensions
|
moduleDescriptor, context.irBuiltIns, context.symbolTable,
|
||||||
|
extensions = generatorExtensions,
|
||||||
|
mangler = JsManglerDesc,
|
||||||
)
|
)
|
||||||
return psi2ir.generateModuleFragment(context, ktFilesToAnalyze, irProviders, emptyList())
|
return psi2ir.generateModuleFragment(context, ktFilesToAnalyze, irProviders, emptyList())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,8 @@ abstract class AbstractIrTextTestCase : AbstractIrGeneratorTestCase() {
|
|||||||
val stubGenerator = DeclarationStubGeneratorImpl(
|
val stubGenerator = DeclarationStubGeneratorImpl(
|
||||||
irModule.descriptor,
|
irModule.descriptor,
|
||||||
SymbolTable(signaturer, IrFactoryImpl), // TODO
|
SymbolTable(signaturer, IrFactoryImpl), // TODO
|
||||||
irModule.irBuiltins
|
irModule.irBuiltins,
|
||||||
|
mangler,
|
||||||
)
|
)
|
||||||
|
|
||||||
val path = wholeFile.path
|
val path = wholeFile.path
|
||||||
|
|||||||
+2
-2
@@ -567,7 +567,7 @@ internal class KonanIrLinker(
|
|||||||
require(klib.isInteropLibrary())
|
require(klib.isInteropLibrary())
|
||||||
}
|
}
|
||||||
|
|
||||||
private val descriptorByIdSignatureFinder = DescriptorByIdSignatureFinder(
|
private val descriptorByIdSignatureFinder = DescriptorByIdSignatureFinderImpl(
|
||||||
moduleDescriptor, KonanManglerDesc,
|
moduleDescriptor, KonanManglerDesc,
|
||||||
DescriptorByIdSignatureFinder.LookupMode.MODULE_ONLY
|
DescriptorByIdSignatureFinder.LookupMode.MODULE_ONLY
|
||||||
)
|
)
|
||||||
@@ -621,7 +621,7 @@ internal class KonanIrLinker(
|
|||||||
override val klib: KotlinLibrary
|
override val klib: KotlinLibrary
|
||||||
) : IrModuleDeserializer(moduleDescriptor, klib.versions.abiVersion ?: KotlinAbiVersion.CURRENT) {
|
) : IrModuleDeserializer(moduleDescriptor, klib.versions.abiVersion ?: KotlinAbiVersion.CURRENT) {
|
||||||
|
|
||||||
private val descriptorByIdSignatureFinder = DescriptorByIdSignatureFinder(
|
private val descriptorByIdSignatureFinder = DescriptorByIdSignatureFinderImpl(
|
||||||
moduleDescriptor, KonanManglerDesc,
|
moduleDescriptor, KonanManglerDesc,
|
||||||
DescriptorByIdSignatureFinder.LookupMode.MODULE_ONLY
|
DescriptorByIdSignatureFinder.LookupMode.MODULE_ONLY
|
||||||
)
|
)
|
||||||
|
|||||||
+5
-2
@@ -18,6 +18,7 @@ import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
|||||||
import org.jetbrains.kotlin.ir.backend.js.JsIrBackendContext
|
import org.jetbrains.kotlin.ir.backend.js.JsIrBackendContext
|
||||||
import org.jetbrains.kotlin.ir.backend.js.generateJsCode
|
import org.jetbrains.kotlin.ir.backend.js.generateJsCode
|
||||||
import org.jetbrains.kotlin.ir.backend.js.utils.NameTables
|
import org.jetbrains.kotlin.ir.backend.js.utils.NameTables
|
||||||
|
import org.jetbrains.kotlin.ir.backend.jvm.serialization.JvmDescriptorMangler
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrScript
|
import org.jetbrains.kotlin.ir.declarations.IrScript
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrScriptSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrScriptSymbol
|
||||||
@@ -73,8 +74,9 @@ class JsCoreScriptingCompiler(
|
|||||||
override fun getPreviousScripts() = replCompilerState.history.map { it.item.scriptSymbol }
|
override fun getPreviousScripts() = replCompilerState.history.map { it.item.scriptSymbol }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val mangler = JvmDescriptorMangler(null)
|
||||||
val psi2irContext = psi2ir.createGeneratorContext(module, bindingContext, symbolTable, generatorExtensions)
|
val psi2irContext = psi2ir.createGeneratorContext(module, bindingContext, symbolTable, generatorExtensions)
|
||||||
val providers = generateTypicalIrProviderList(module, psi2irContext.irBuiltIns, psi2irContext.symbolTable)
|
val providers = generateTypicalIrProviderList(module, psi2irContext.irBuiltIns, psi2irContext.symbolTable, mangler)
|
||||||
val irModuleFragment = psi2ir.generateModuleFragment(psi2irContext, files, providers, emptyList(), null) // TODO: deserializer
|
val irModuleFragment = psi2ir.generateModuleFragment(psi2irContext, files, providers, emptyList(), null) // TODO: deserializer
|
||||||
|
|
||||||
val context = JsIrBackendContext(
|
val context = JsIrBackendContext(
|
||||||
@@ -92,7 +94,8 @@ class JsCoreScriptingCompiler(
|
|||||||
generateTypicalIrProviderList(
|
generateTypicalIrProviderList(
|
||||||
irModuleFragment.descriptor,
|
irModuleFragment.descriptor,
|
||||||
psi2irContext.irBuiltIns,
|
psi2irContext.irBuiltIns,
|
||||||
psi2irContext.symbolTable
|
psi2irContext.symbolTable,
|
||||||
|
mangler
|
||||||
)
|
)
|
||||||
).generateUnboundSymbolsAsDependencies()
|
).generateUnboundSymbolsAsDependencies()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user