[FIR2IR] Introduce shortcut utilities for unsubstituted and declared scopes
This commit is contained in:
committed by
Space Team
parent
5355f0f705
commit
42dd29aade
@@ -39,8 +39,10 @@ import org.jetbrains.kotlin.fir.resolve.*
|
|||||||
import org.jetbrains.kotlin.fir.resolve.calls.FirSimpleSyntheticPropertySymbol
|
import org.jetbrains.kotlin.fir.resolve.calls.FirSimpleSyntheticPropertySymbol
|
||||||
import org.jetbrains.kotlin.fir.resolve.providers.FirProvider
|
import org.jetbrains.kotlin.fir.resolve.providers.FirProvider
|
||||||
import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
|
import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
|
||||||
|
import org.jetbrains.kotlin.fir.scopes.FirContainingNamesAwareScope
|
||||||
import org.jetbrains.kotlin.fir.scopes.FirTypeScope
|
import org.jetbrains.kotlin.fir.scopes.FirTypeScope
|
||||||
import org.jetbrains.kotlin.fir.scopes.ProcessorAction
|
import org.jetbrains.kotlin.fir.scopes.ProcessorAction
|
||||||
|
import org.jetbrains.kotlin.fir.scopes.impl.declaredMemberScope
|
||||||
import org.jetbrains.kotlin.fir.scopes.unsubstitutedScope
|
import org.jetbrains.kotlin.fir.scopes.unsubstitutedScope
|
||||||
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag
|
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag
|
||||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||||
@@ -407,7 +409,7 @@ internal fun FirSimpleFunction.processOverriddenFunctionSymbols(
|
|||||||
containingClass: FirClass,
|
containingClass: FirClass,
|
||||||
processor: (FirNamedFunctionSymbol) -> Unit
|
processor: (FirNamedFunctionSymbol) -> Unit
|
||||||
) {
|
) {
|
||||||
val scope = containingClass.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = true, memberRequiredPhase = null)
|
val scope = containingClass.unsubstitutedScope()
|
||||||
scope.processFunctionsByName(name) {}
|
scope.processFunctionsByName(name) {}
|
||||||
scope.processOverriddenFunctionsFromSuperClasses(symbol, containingClass) { overriddenSymbol ->
|
scope.processOverriddenFunctionsFromSuperClasses(symbol, containingClass) { overriddenSymbol ->
|
||||||
if (!session.visibilityChecker.isVisibleForOverriding(
|
if (!session.visibilityChecker.isVisibleForOverriding(
|
||||||
@@ -483,7 +485,7 @@ internal fun FirProperty.processOverriddenPropertySymbols(
|
|||||||
containingClass: FirClass,
|
containingClass: FirClass,
|
||||||
processor: (FirPropertySymbol) -> Unit
|
processor: (FirPropertySymbol) -> Unit
|
||||||
): List<IrPropertySymbol> {
|
): List<IrPropertySymbol> {
|
||||||
val scope = containingClass.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = true, memberRequiredPhase = null)
|
val scope = containingClass.unsubstitutedScope()
|
||||||
scope.processPropertiesByName(name) {}
|
scope.processPropertiesByName(name) {}
|
||||||
val overriddenSet = mutableSetOf<IrPropertySymbol>()
|
val overriddenSet = mutableSetOf<IrPropertySymbol>()
|
||||||
scope.processOverriddenPropertiesFromSuperClasses(symbol, containingClass) { overriddenSymbol ->
|
scope.processOverriddenPropertiesFromSuperClasses(symbol, containingClass) { overriddenSymbol ->
|
||||||
@@ -519,7 +521,7 @@ internal fun FirProperty.generateOverriddenPropertySymbols(containingClass: FirC
|
|||||||
context(Fir2IrComponents)
|
context(Fir2IrComponents)
|
||||||
@OptIn(IrSymbolInternals::class)
|
@OptIn(IrSymbolInternals::class)
|
||||||
internal fun FirProperty.generateOverriddenAccessorSymbols(containingClass: FirClass, isGetter: Boolean): List<IrSimpleFunctionSymbol> {
|
internal fun FirProperty.generateOverriddenAccessorSymbols(containingClass: FirClass, isGetter: Boolean): List<IrSimpleFunctionSymbol> {
|
||||||
val scope = containingClass.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = true, memberRequiredPhase = null)
|
val scope = containingClass.unsubstitutedScope()
|
||||||
scope.processPropertiesByName(name) {}
|
scope.processPropertiesByName(name) {}
|
||||||
val overriddenSet = mutableSetOf<IrSimpleFunctionSymbol>()
|
val overriddenSet = mutableSetOf<IrSimpleFunctionSymbol>()
|
||||||
val superClasses = containingClass.getSuperTypesAsIrClasses() ?: return emptyList()
|
val superClasses = containingClass.getSuperTypesAsIrClasses() ?: return emptyList()
|
||||||
@@ -855,3 +857,23 @@ internal val FirValueParameter.varargElementType: ConeKotlinType?
|
|||||||
if (!isVararg) return null
|
if (!isVararg) return null
|
||||||
return returnTypeRef.coneType.arrayElementType()
|
return returnTypeRef.coneType.arrayElementType()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
context(Fir2IrComponents)
|
||||||
|
internal fun FirClassSymbol<*>.unsubstitutedScope(): FirTypeScope {
|
||||||
|
return this.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = true, memberRequiredPhase = null)
|
||||||
|
}
|
||||||
|
|
||||||
|
context(Fir2IrComponents)
|
||||||
|
internal fun FirClass.unsubstitutedScope(): FirTypeScope {
|
||||||
|
return symbol.unsubstitutedScope()
|
||||||
|
}
|
||||||
|
|
||||||
|
context(Fir2IrComponents)
|
||||||
|
internal fun FirClassSymbol<*>.declaredScope(): FirContainingNamesAwareScope {
|
||||||
|
return this.declaredMemberScope(session, memberRequiredPhase = null)
|
||||||
|
}
|
||||||
|
|
||||||
|
context(Fir2IrComponents)
|
||||||
|
internal fun FirClass.declaredScope(): FirContainingNamesAwareScope {
|
||||||
|
return symbol.declaredScope()
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ package org.jetbrains.kotlin.fir.backend
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
|
import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
|
||||||
import org.jetbrains.kotlin.fir.scopes.getDeclaredConstructors
|
import org.jetbrains.kotlin.fir.scopes.getDeclaredConstructors
|
||||||
import org.jetbrains.kotlin.fir.scopes.unsubstitutedScope
|
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrConstructor
|
import org.jetbrains.kotlin.ir.declarations.IrConstructor
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
|
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
|
||||||
@@ -85,12 +84,7 @@ class Fir2IrBuiltIns(
|
|||||||
val constructorSymbol = if (firSymbol == null) {
|
val constructorSymbol = if (firSymbol == null) {
|
||||||
owner.declarations.firstIsInstance<IrConstructor>().symbol
|
owner.declarations.firstIsInstance<IrConstructor>().symbol
|
||||||
} else {
|
} else {
|
||||||
val firConstructorSymbol = firSymbol.unsubstitutedScope(
|
val firConstructorSymbol = firSymbol.unsubstitutedScope().getDeclaredConstructors().singleOrNull() ?: return null
|
||||||
session,
|
|
||||||
scopeSession,
|
|
||||||
withForcedTypeCalculator = true,
|
|
||||||
memberRequiredPhase = null,
|
|
||||||
).getDeclaredConstructors().singleOrNull() ?: return null
|
|
||||||
|
|
||||||
declarationStorage.getIrConstructorSymbol(firConstructorSymbol)
|
declarationStorage.getIrConstructorSymbol(firConstructorSymbol)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import org.jetbrains.kotlin.fir.resolve.providers.firProvider
|
|||||||
import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
|
import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
|
||||||
import org.jetbrains.kotlin.fir.resolve.providers.toSymbol
|
import org.jetbrains.kotlin.fir.resolve.providers.toSymbol
|
||||||
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
||||||
import org.jetbrains.kotlin.fir.scopes.unsubstitutedScope
|
|
||||||
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag
|
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag
|
||||||
import org.jetbrains.kotlin.fir.symbols.Fir2IrClassSymbol
|
import org.jetbrains.kotlin.fir.symbols.Fir2IrClassSymbol
|
||||||
import org.jetbrains.kotlin.fir.symbols.Fir2IrEnumEntrySymbol
|
import org.jetbrains.kotlin.fir.symbols.Fir2IrEnumEntrySymbol
|
||||||
@@ -210,7 +209,7 @@ class Fir2IrClassifierStorage(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun FirRegularClass.hasAbstractMembersInScope(): Boolean {
|
private fun FirRegularClass.hasAbstractMembersInScope(): Boolean {
|
||||||
val scope = unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = false, memberRequiredPhase = null)
|
val scope = unsubstitutedScope()
|
||||||
val names = scope.getCallableNames()
|
val names = scope.getCallableNames()
|
||||||
var hasAbstract = false
|
var hasAbstract = false
|
||||||
for (name in names) {
|
for (name in names) {
|
||||||
|
|||||||
+1
-2
@@ -33,7 +33,6 @@ import org.jetbrains.kotlin.fir.resolve.dfa.cfg.isLocalClassOrAnonymousObject
|
|||||||
import org.jetbrains.kotlin.fir.resolve.isKFunctionInvoke
|
import org.jetbrains.kotlin.fir.resolve.isKFunctionInvoke
|
||||||
import org.jetbrains.kotlin.fir.resolve.providers.firProvider
|
import org.jetbrains.kotlin.fir.resolve.providers.firProvider
|
||||||
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
||||||
import org.jetbrains.kotlin.fir.scopes.unsubstitutedScope
|
|
||||||
import org.jetbrains.kotlin.fir.symbols.*
|
import org.jetbrains.kotlin.fir.symbols.*
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.*
|
import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||||
import org.jetbrains.kotlin.fir.types.*
|
import org.jetbrains.kotlin.fir.types.*
|
||||||
@@ -225,7 +224,7 @@ class Fir2IrDeclarationStorage(
|
|||||||
else -> {}
|
else -> {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val scope = firClass.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = false, memberRequiredPhase = null)
|
val scope = firClass.unsubstitutedScope()
|
||||||
scope.getCallableNames().forEach { callableName ->
|
scope.getCallableNames().forEach { callableName ->
|
||||||
buildList {
|
buildList {
|
||||||
fakeOverrideGenerator.generateFakeOverridesForName(
|
fakeOverrideGenerator.generateFakeOverridesForName(
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import org.jetbrains.kotlin.fir.moduleData
|
|||||||
import org.jetbrains.kotlin.fir.resolve.providers.FirSymbolProvider
|
import org.jetbrains.kotlin.fir.resolve.providers.FirSymbolProvider
|
||||||
import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
|
import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
|
||||||
import org.jetbrains.kotlin.fir.scopes.*
|
import org.jetbrains.kotlin.fir.scopes.*
|
||||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirClassLikeSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirClassLikeSymbol
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
|
||||||
@@ -133,14 +132,9 @@ class Fir2IrPluginContext(
|
|||||||
?.fullyExpandedClass(components.session)
|
?.fullyExpandedClass(components.session)
|
||||||
?: return emptyList()
|
?: return emptyList()
|
||||||
|
|
||||||
expandedClass
|
with(components) {
|
||||||
.unsubstitutedScope(
|
expandedClass.unsubstitutedScope().getCallablesFromScope()
|
||||||
components.session,
|
}
|
||||||
components.scopeSession,
|
|
||||||
withForcedTypeCalculator = true,
|
|
||||||
memberRequiredPhase = null,
|
|
||||||
)
|
|
||||||
.getCallablesFromScope()
|
|
||||||
} else {
|
} else {
|
||||||
symbolProvider.getCallablesFromProvider()
|
symbolProvider.getCallablesFromProvider()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import org.jetbrains.kotlin.fir.declarations.*
|
|||||||
import org.jetbrains.kotlin.fir.declarations.utils.classId
|
import org.jetbrains.kotlin.fir.declarations.utils.classId
|
||||||
import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
|
import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
|
||||||
import org.jetbrains.kotlin.fir.scopes.FirScope
|
import org.jetbrains.kotlin.fir.scopes.FirScope
|
||||||
import org.jetbrains.kotlin.fir.scopes.unsubstitutedScope
|
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol
|
||||||
import org.jetbrains.kotlin.fir.types.ConeClassLikeType
|
import org.jetbrains.kotlin.fir.types.ConeClassLikeType
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
@@ -87,12 +86,7 @@ class FirIrProvider(val fir2IrComponents: Fir2IrComponents) : IrProvider {
|
|||||||
?: return null
|
?: return null
|
||||||
}
|
}
|
||||||
val classId = firClass.classId
|
val classId = firClass.classId
|
||||||
val scope = firClass.unsubstitutedScope(
|
val scope = with(fir2IrComponents) { firClass.unsubstitutedScope() }
|
||||||
fir2IrComponents.session,
|
|
||||||
fir2IrComponents.scopeSession,
|
|
||||||
withForcedTypeCalculator = true,
|
|
||||||
memberRequiredPhase = null,
|
|
||||||
)
|
|
||||||
|
|
||||||
when (kind) {
|
when (kind) {
|
||||||
SymbolKind.CLASS_SYMBOL -> {
|
SymbolKind.CLASS_SYMBOL -> {
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import org.jetbrains.kotlin.fir.descriptors.FirModuleDescriptor
|
|||||||
import org.jetbrains.kotlin.fir.resolve.providers.FirSymbolProvider
|
import org.jetbrains.kotlin.fir.resolve.providers.FirSymbolProvider
|
||||||
import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
|
import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
|
||||||
import org.jetbrains.kotlin.fir.scopes.getFunctions
|
import org.jetbrains.kotlin.fir.scopes.getFunctions
|
||||||
import org.jetbrains.kotlin.fir.scopes.unsubstitutedScope
|
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
|
||||||
@@ -78,9 +77,7 @@ class IrBuiltInsOverFir(
|
|||||||
|
|
||||||
private fun findFirMemberFunctions(classId: ClassId, name: Name): List<FirNamedFunctionSymbol> {
|
private fun findFirMemberFunctions(classId: ClassId, name: Name): List<FirNamedFunctionSymbol> {
|
||||||
val klass = symbolProvider.getClassLikeSymbolByClassId(classId) as FirRegularClassSymbol
|
val klass = symbolProvider.getClassLikeSymbolByClassId(classId) as FirRegularClassSymbol
|
||||||
val scope = klass.unsubstitutedScope(
|
val scope = with(components) { klass.unsubstitutedScope() }
|
||||||
session, components.scopeSession, withForcedTypeCalculator = true, memberRequiredPhase = null
|
|
||||||
)
|
|
||||||
return scope.getFunctions(name)
|
return scope.getFunctions(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+12
-20
@@ -28,7 +28,6 @@ import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor
|
|||||||
import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutorByMap
|
import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutorByMap
|
||||||
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.approximateDeclarationType
|
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.approximateDeclarationType
|
||||||
import org.jetbrains.kotlin.fir.scopes.getDeclaredConstructors
|
import org.jetbrains.kotlin.fir.scopes.getDeclaredConstructors
|
||||||
import org.jetbrains.kotlin.fir.scopes.unsubstitutedScope
|
|
||||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.*
|
import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||||
import org.jetbrains.kotlin.fir.types.*
|
import org.jetbrains.kotlin.fir.types.*
|
||||||
@@ -38,7 +37,7 @@ import org.jetbrains.kotlin.fir.types.builder.buildTypeProjectionWithVariance
|
|||||||
import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl
|
import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl
|
||||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||||
import org.jetbrains.kotlin.ir.builders.declarations.UNDEFINED_PARAMETER_INDEX
|
import org.jetbrains.kotlin.ir.builders.declarations.UNDEFINED_PARAMETER_INDEX
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.name
|
||||||
import org.jetbrains.kotlin.ir.expressions.*
|
import org.jetbrains.kotlin.ir.expressions.*
|
||||||
import org.jetbrains.kotlin.ir.expressions.impl.*
|
import org.jetbrains.kotlin.ir.expressions.impl.*
|
||||||
import org.jetbrains.kotlin.ir.symbols.*
|
import org.jetbrains.kotlin.ir.symbols.*
|
||||||
@@ -53,7 +52,7 @@ import org.jetbrains.kotlin.utils.addToStdlib.runIf
|
|||||||
class CallAndReferenceGenerator(
|
class CallAndReferenceGenerator(
|
||||||
private val components: Fir2IrComponents,
|
private val components: Fir2IrComponents,
|
||||||
private val visitor: Fir2IrVisitor,
|
private val visitor: Fir2IrVisitor,
|
||||||
private val conversionScope: Fir2IrConversionScope
|
private val conversionScope: Fir2IrConversionScope,
|
||||||
) : Fir2IrComponents by components {
|
) : Fir2IrComponents by components {
|
||||||
|
|
||||||
private val adapterGenerator = AdapterGenerator(components, conversionScope)
|
private val adapterGenerator = AdapterGenerator(components, conversionScope)
|
||||||
@@ -67,7 +66,7 @@ class CallAndReferenceGenerator(
|
|||||||
fun convertToIrCallableReference(
|
fun convertToIrCallableReference(
|
||||||
callableReferenceAccess: FirCallableReferenceAccess,
|
callableReferenceAccess: FirCallableReferenceAccess,
|
||||||
explicitReceiverExpression: IrExpression?,
|
explicitReceiverExpression: IrExpression?,
|
||||||
isDelegate: Boolean
|
isDelegate: Boolean,
|
||||||
): IrExpression {
|
): IrExpression {
|
||||||
val type = approximateFunctionReferenceType(callableReferenceAccess.resolvedType).toIrType()
|
val type = approximateFunctionReferenceType(callableReferenceAccess.resolvedType).toIrType()
|
||||||
|
|
||||||
@@ -366,7 +365,7 @@ class CallAndReferenceGenerator(
|
|||||||
explicitReceiverExpression: IrExpression?,
|
explicitReceiverExpression: IrExpression?,
|
||||||
dynamicOperator: IrDynamicOperator? = null,
|
dynamicOperator: IrDynamicOperator? = null,
|
||||||
variableAsFunctionMode: Boolean = false,
|
variableAsFunctionMode: Boolean = false,
|
||||||
noArguments: Boolean = false
|
noArguments: Boolean = false,
|
||||||
): IrExpression {
|
): IrExpression {
|
||||||
try {
|
try {
|
||||||
injectGetValueCall(qualifiedAccess, qualifiedAccess.calleeReference)?.let { return it }
|
injectGetValueCall(qualifiedAccess, qualifiedAccess.calleeReference)?.let { return it }
|
||||||
@@ -721,12 +720,7 @@ class CallAndReferenceGenerator(
|
|||||||
// Fallback for FirReferencePlaceholderForResolvedAnnotations from jar
|
// Fallback for FirReferencePlaceholderForResolvedAnnotations from jar
|
||||||
val fir = coneType.lookupTag.toSymbol(session)?.fir as? FirClass
|
val fir = coneType.lookupTag.toSymbol(session)?.fir as? FirClass
|
||||||
var constructorSymbol: FirConstructorSymbol? = null
|
var constructorSymbol: FirConstructorSymbol? = null
|
||||||
fir?.unsubstitutedScope(
|
fir?.unsubstitutedScope()?.processDeclaredConstructors {
|
||||||
session,
|
|
||||||
scopeSession,
|
|
||||||
withForcedTypeCalculator = true,
|
|
||||||
memberRequiredPhase = null,
|
|
||||||
)?.processDeclaredConstructors {
|
|
||||||
if (it.fir.isPrimary && constructorSymbol == null) {
|
if (it.fir.isPrimary && constructorSymbol == null) {
|
||||||
constructorSymbol = it
|
constructorSymbol = it
|
||||||
}
|
}
|
||||||
@@ -765,9 +759,7 @@ class CallAndReferenceGenerator(
|
|||||||
annotationTypeRef = this@toAnnotationCall.annotationTypeRef
|
annotationTypeRef = this@toAnnotationCall.annotationTypeRef
|
||||||
val symbol = annotationTypeRef.coneType.fullyExpandedType(session).toSymbol(session) as? FirRegularClassSymbol ?: return null
|
val symbol = annotationTypeRef.coneType.fullyExpandedType(session).toSymbol(session) as? FirRegularClassSymbol ?: return null
|
||||||
|
|
||||||
val constructorSymbol =
|
val constructorSymbol = symbol.unsubstitutedScope().getDeclaredConstructors().firstOrNull() ?: return null
|
||||||
symbol.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = false, memberRequiredPhase = null)
|
|
||||||
.getDeclaredConstructors().firstOrNull() ?: return null
|
|
||||||
|
|
||||||
val argumentToParameterToMapping = constructorSymbol.valueParameterSymbols.mapNotNull {
|
val argumentToParameterToMapping = constructorSymbol.valueParameterSymbols.mapNotNull {
|
||||||
val parameter = it.fir
|
val parameter = it.fir
|
||||||
@@ -788,7 +780,7 @@ class CallAndReferenceGenerator(
|
|||||||
|
|
||||||
internal fun convertToGetObject(
|
internal fun convertToGetObject(
|
||||||
qualifier: FirResolvedQualifier,
|
qualifier: FirResolvedQualifier,
|
||||||
callableReferenceAccess: FirCallableReferenceAccess?
|
callableReferenceAccess: FirCallableReferenceAccess?,
|
||||||
): IrExpression? {
|
): IrExpression? {
|
||||||
val classSymbol = (qualifier.resolvedType as? ConeClassLikeType)?.lookupTag?.toSymbol(session)
|
val classSymbol = (qualifier.resolvedType as? ConeClassLikeType)?.lookupTag?.toSymbol(session)
|
||||||
|
|
||||||
@@ -823,7 +815,7 @@ class CallAndReferenceGenerator(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun extractArgumentsMapping(
|
private fun extractArgumentsMapping(
|
||||||
call: FirCall
|
call: FirCall,
|
||||||
): Triple<List<FirValueParameter>?, Map<FirExpression, FirValueParameter>?, ConeSubstitutor> {
|
): Triple<List<FirValueParameter>?, Map<FirExpression, FirValueParameter>?, ConeSubstitutor> {
|
||||||
val calleeReference = when (call) {
|
val calleeReference = when (call) {
|
||||||
is FirFunctionCall -> call.calleeReference
|
is FirFunctionCall -> call.calleeReference
|
||||||
@@ -987,7 +979,7 @@ class CallAndReferenceGenerator(
|
|||||||
|
|
||||||
private fun needArgumentReordering(
|
private fun needArgumentReordering(
|
||||||
parametersInActualOrder: Collection<FirValueParameter>,
|
parametersInActualOrder: Collection<FirValueParameter>,
|
||||||
valueParameters: List<FirValueParameter>
|
valueParameters: List<FirValueParameter>,
|
||||||
): Boolean {
|
): Boolean {
|
||||||
var lastValueParameterIndex = UNDEFINED_PARAMETER_INDEX
|
var lastValueParameterIndex = UNDEFINED_PARAMETER_INDEX
|
||||||
for (parameter in parametersInActualOrder) {
|
for (parameter in parametersInActualOrder) {
|
||||||
@@ -1028,7 +1020,7 @@ class CallAndReferenceGenerator(
|
|||||||
|
|
||||||
private fun IrExpression.applyAssigningArrayElementsToVarargInNamedForm(
|
private fun IrExpression.applyAssigningArrayElementsToVarargInNamedForm(
|
||||||
argument: FirExpression,
|
argument: FirExpression,
|
||||||
parameter: FirValueParameter?
|
parameter: FirValueParameter?,
|
||||||
): IrExpression {
|
): IrExpression {
|
||||||
if (this !is IrVarargImpl ||
|
if (this !is IrVarargImpl ||
|
||||||
parameter?.isVararg != true ||
|
parameter?.isVararg != true ||
|
||||||
@@ -1051,7 +1043,7 @@ class CallAndReferenceGenerator(
|
|||||||
|
|
||||||
private fun IrExpression.applyImplicitIntegerCoercionIfNeeded(
|
private fun IrExpression.applyImplicitIntegerCoercionIfNeeded(
|
||||||
argument: FirExpression,
|
argument: FirExpression,
|
||||||
parameter: FirValueParameter?
|
parameter: FirValueParameter?,
|
||||||
): IrExpression {
|
): IrExpression {
|
||||||
if (!session.languageVersionSettings.supportsFeature(LanguageFeature.ImplicitSignedToUnsignedIntegerConversion)) return this
|
if (!session.languageVersionSettings.supportsFeature(LanguageFeature.ImplicitSignedToUnsignedIntegerConversion)) return this
|
||||||
|
|
||||||
@@ -1291,7 +1283,7 @@ class CallAndReferenceGenerator(
|
|||||||
startOffset: Int,
|
startOffset: Int,
|
||||||
endOffset: Int,
|
endOffset: Int,
|
||||||
calleeReference: FirReference,
|
calleeReference: FirReference,
|
||||||
type: IrType? = null
|
type: IrType? = null,
|
||||||
): IrErrorCallExpression {
|
): IrErrorCallExpression {
|
||||||
return IrErrorCallExpressionImpl(
|
return IrErrorCallExpressionImpl(
|
||||||
startOffset, endOffset, type ?: createErrorType(),
|
startOffset, endOffset, type ?: createErrorType(),
|
||||||
|
|||||||
+5
-14
@@ -10,9 +10,9 @@ import org.jetbrains.kotlin.descriptors.ClassKind
|
|||||||
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
|
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
|
||||||
import org.jetbrains.kotlin.descriptors.Modality
|
import org.jetbrains.kotlin.descriptors.Modality
|
||||||
import org.jetbrains.kotlin.fir.analysis.checkers.toRegularClassSymbol
|
import org.jetbrains.kotlin.fir.analysis.checkers.toRegularClassSymbol
|
||||||
import org.jetbrains.kotlin.fir.backend.Fir2IrComponents
|
import org.jetbrains.kotlin.fir.backend.*
|
||||||
import org.jetbrains.kotlin.fir.backend.FirMetadataSource
|
|
||||||
import org.jetbrains.kotlin.fir.backend.declareThisReceiverParameter
|
import org.jetbrains.kotlin.fir.backend.declareThisReceiverParameter
|
||||||
|
import org.jetbrains.kotlin.fir.backend.unsubstitutedScope
|
||||||
import org.jetbrains.kotlin.fir.containingClassLookupTag
|
import org.jetbrains.kotlin.fir.containingClassLookupTag
|
||||||
import org.jetbrains.kotlin.fir.declarations.*
|
import org.jetbrains.kotlin.fir.declarations.*
|
||||||
import org.jetbrains.kotlin.fir.declarations.utils.classId
|
import org.jetbrains.kotlin.fir.declarations.utils.classId
|
||||||
@@ -21,8 +21,6 @@ import org.jetbrains.kotlin.fir.render
|
|||||||
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
|
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
|
||||||
import org.jetbrains.kotlin.fir.scopes.getFunctions
|
import org.jetbrains.kotlin.fir.scopes.getFunctions
|
||||||
import org.jetbrains.kotlin.fir.scopes.getProperties
|
import org.jetbrains.kotlin.fir.scopes.getProperties
|
||||||
import org.jetbrains.kotlin.fir.scopes.impl.declaredMemberScope
|
|
||||||
import org.jetbrains.kotlin.fir.scopes.unsubstitutedScope
|
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol
|
||||||
import org.jetbrains.kotlin.fir.types.coneType
|
import org.jetbrains.kotlin.fir.types.coneType
|
||||||
@@ -125,9 +123,7 @@ class DataClassMembersGenerator(val components: Fir2IrComponents) : Fir2IrCompon
|
|||||||
// scope of kotlin.Nothing is empty, so we need to search for `hashCode` in scope of kotlin.Any
|
// scope of kotlin.Nothing is empty, so we need to search for `hashCode` in scope of kotlin.Any
|
||||||
return getHashCodeFunction(session.builtinTypes.anyType.type.toRegularClassSymbol(session)!!.fir)
|
return getHashCodeFunction(session.builtinTypes.anyType.type.toRegularClassSymbol(session)!!.fir)
|
||||||
}
|
}
|
||||||
val scope = klass.symbol.unsubstitutedScope(
|
val scope = klass.symbol.unsubstitutedScope()
|
||||||
session, scopeSession, withForcedTypeCalculator = false, memberRequiredPhase = null
|
|
||||||
)
|
|
||||||
return scope.getFunctions(HASHCODE_NAME).first { symbol ->
|
return scope.getFunctions(HASHCODE_NAME).first { symbol ->
|
||||||
val function = symbol.fir
|
val function = symbol.fir
|
||||||
function.valueParameters.isEmpty() && function.receiverParameter == null && function.contextReceivers.isEmpty()
|
function.valueParameters.isEmpty() && function.receiverParameter == null && function.contextReceivers.isEmpty()
|
||||||
@@ -159,7 +155,7 @@ class DataClassMembersGenerator(val components: Fir2IrComponents) : Fir2IrCompon
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun getHashCodeFunctionInfo(property: IrProperty): HashCodeFunctionInfo {
|
override fun getHashCodeFunctionInfo(property: IrProperty): HashCodeFunctionInfo {
|
||||||
val firProperty = klass.symbol.declaredMemberScope(session, memberRequiredPhase = null)
|
val firProperty = klass.symbol.declaredScope()
|
||||||
.getProperties(property.name)
|
.getProperties(property.name)
|
||||||
.first { (it as FirPropertySymbol).fromPrimaryConstructor } as FirPropertySymbol
|
.first { (it as FirPropertySymbol).fromPrimaryConstructor } as FirPropertySymbol
|
||||||
|
|
||||||
@@ -257,12 +253,7 @@ class DataClassMembersGenerator(val components: Fir2IrComponents) : Fir2IrCompon
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun calculateSyntheticFirFunctions(): Map<Name, FirSimpleFunction> {
|
private fun calculateSyntheticFirFunctions(): Map<Name, FirSimpleFunction> {
|
||||||
val scope = klass.unsubstitutedScope(
|
val scope = klass.unsubstitutedScope()
|
||||||
components.session,
|
|
||||||
components.scopeSession,
|
|
||||||
withForcedTypeCalculator = true,
|
|
||||||
memberRequiredPhase = null,
|
|
||||||
)
|
|
||||||
val contributedSyntheticFunctions =
|
val contributedSyntheticFunctions =
|
||||||
buildMap<Name, FirSimpleFunction> {
|
buildMap<Name, FirSimpleFunction> {
|
||||||
for (name in listOf(EQUALS, HASHCODE_NAME, TO_STRING)) {
|
for (name in listOf(EQUALS, HASHCODE_NAME, TO_STRING)) {
|
||||||
|
|||||||
+1
-6
@@ -85,12 +85,7 @@ class DelegatedMemberGenerator(private val components: Fir2IrComponents) : Fir2I
|
|||||||
|
|
||||||
// Generate delegated members for [subClass]. The synthetic field [irField] has the super interface type.
|
// Generate delegated members for [subClass]. The synthetic field [irField] has the super interface type.
|
||||||
fun generate(irField: IrField, firField: FirField, firSubClass: FirClass, subClass: IrClass) {
|
fun generate(irField: IrField, firField: FirField, firSubClass: FirClass, subClass: IrClass) {
|
||||||
val subClassScope = firSubClass.unsubstitutedScope(
|
val subClassScope = firSubClass.unsubstitutedScope()
|
||||||
session,
|
|
||||||
scopeSession,
|
|
||||||
withForcedTypeCalculator = false,
|
|
||||||
memberRequiredPhase = null,
|
|
||||||
)
|
|
||||||
|
|
||||||
val delegateToScope = firField.initializer!!.resolvedType
|
val delegateToScope = firField.initializer!!.resolvedType
|
||||||
.fullyExpandedType(session)
|
.fullyExpandedType(session)
|
||||||
|
|||||||
+3
-13
@@ -61,12 +61,7 @@ class FakeOverrideGenerator(
|
|||||||
|
|
||||||
private fun IrClass.getFakeOverrides(klass: FirClass, realDeclarations: Collection<FirDeclaration>): List<IrDeclaration> {
|
private fun IrClass.getFakeOverrides(klass: FirClass, realDeclarations: Collection<FirDeclaration>): List<IrDeclaration> {
|
||||||
val result = mutableListOf<IrDeclaration>()
|
val result = mutableListOf<IrDeclaration>()
|
||||||
val useSiteMemberScope = klass.unsubstitutedScope(
|
val useSiteMemberScope = klass.unsubstitutedScope()
|
||||||
session,
|
|
||||||
scopeSession,
|
|
||||||
withForcedTypeCalculator = true,
|
|
||||||
memberRequiredPhase = null,
|
|
||||||
)
|
|
||||||
|
|
||||||
val superTypesCallableNames = useSiteMemberScope.getCallableNames()
|
val superTypesCallableNames = useSiteMemberScope.getCallableNames()
|
||||||
val realDeclarationSymbols = realDeclarations.mapTo(mutableSetOf(), FirDeclaration::symbol)
|
val realDeclarationSymbols = realDeclarations.mapTo(mutableSetOf(), FirDeclaration::symbol)
|
||||||
@@ -82,12 +77,7 @@ class FakeOverrideGenerator(
|
|||||||
name: Name,
|
name: Name,
|
||||||
firClass: FirClass
|
firClass: FirClass
|
||||||
): List<IrDeclaration> = buildList {
|
): List<IrDeclaration> = buildList {
|
||||||
val useSiteMemberScope = firClass.unsubstitutedScope(
|
val useSiteMemberScope = firClass.unsubstitutedScope()
|
||||||
session,
|
|
||||||
scopeSession,
|
|
||||||
withForcedTypeCalculator = true,
|
|
||||||
memberRequiredPhase = null,
|
|
||||||
)
|
|
||||||
|
|
||||||
generateFakeOverridesForName(
|
generateFakeOverridesForName(
|
||||||
irClass, useSiteMemberScope, name, firClass, this,
|
irClass, useSiteMemberScope, name, firClass, this,
|
||||||
@@ -220,7 +210,7 @@ class FakeOverrideGenerator(
|
|||||||
fakeOverride: IrSimpleFunction,
|
fakeOverride: IrSimpleFunction,
|
||||||
originalSymbol: FirNamedFunctionSymbol,
|
originalSymbol: FirNamedFunctionSymbol,
|
||||||
) {
|
) {
|
||||||
val scope = klass.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = true, memberRequiredPhase = null)
|
val scope = klass.unsubstitutedScope()
|
||||||
val classLookupTag = klass.symbol.toLookupTag()
|
val classLookupTag = klass.symbol.toLookupTag()
|
||||||
val baseFirSymbolsForFakeOverride =
|
val baseFirSymbolsForFakeOverride =
|
||||||
if (originalSymbol.shouldHaveComputedBaseSymbolsForClass(classLookupTag)) {
|
if (originalSymbol.shouldHaveComputedBaseSymbolsForClass(classLookupTag)) {
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import org.jetbrains.kotlin.fir.isNewPlaceForBodyGeneration
|
|||||||
import org.jetbrains.kotlin.fir.isSubstitutionOrIntersectionOverride
|
import org.jetbrains.kotlin.fir.isSubstitutionOrIntersectionOverride
|
||||||
import org.jetbrains.kotlin.fir.scopes.FirContainingNamesAwareScope
|
import org.jetbrains.kotlin.fir.scopes.FirContainingNamesAwareScope
|
||||||
import org.jetbrains.kotlin.fir.scopes.processClassifiersByName
|
import org.jetbrains.kotlin.fir.scopes.processClassifiersByName
|
||||||
import org.jetbrains.kotlin.fir.scopes.unsubstitutedScope
|
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol
|
||||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||||
@@ -155,7 +154,7 @@ class Fir2IrLazyClass(
|
|||||||
val result = mutableListOf<IrDeclaration>()
|
val result = mutableListOf<IrDeclaration>()
|
||||||
// NB: it's necessary to take all callables from scope,
|
// NB: it's necessary to take all callables from scope,
|
||||||
// e.g. to avoid accessing un-enhanced Java declarations with FirJavaTypeRef etc. inside
|
// e.g. to avoid accessing un-enhanced Java declarations with FirJavaTypeRef etc. inside
|
||||||
val scope = fir.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = true, memberRequiredPhase = null)
|
val scope = fir.unsubstitutedScope()
|
||||||
scope.processDeclaredConstructors {
|
scope.processDeclaredConstructors {
|
||||||
if (shouldBuildStub(it.fir)) {
|
if (shouldBuildStub(it.fir)) {
|
||||||
result += declarationStorage.getIrConstructorSymbol(it).owner
|
result += declarationStorage.getIrConstructorSymbol(it).owner
|
||||||
|
|||||||
Reference in New Issue
Block a user