[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:
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user