[FIR] Remove unused declarations

This commit is contained in:
Ivan Kochurkin
2023-07-05 11:33:50 +02:00
committed by Space Team
parent 6156609617
commit 43b76f3c24
40 changed files with 14 additions and 397 deletions
@@ -66,18 +66,3 @@ fun generateTemporaryVariable(
}
}
fun generateTemporaryVariable(
moduleData: FirModuleData,
source: KtSourceElement?,
specialName: String,
initializer: FirExpression,
extractedAnnotations: Collection<FirAnnotation>? = null,
): FirProperty =
generateTemporaryVariable(
moduleData,
source,
Name.special("<$specialName>"),
initializer,
null,
extractedAnnotations,
)
@@ -12,10 +12,6 @@ class FirLanguageSettingsComponent(val languageVersionSettings: LanguageVersionS
private val FirSession.languageSettingsComponent: FirLanguageSettingsComponent by FirSession.sessionComponentAccessor()
private val FirSession.safeLanguageSettingsComponent: FirLanguageSettingsComponent? by FirSession.nullableSessionComponentAccessor()
val FirSession.languageVersionSettings: LanguageVersionSettings
get() = languageSettingsComponent.languageVersionSettings
val FirSession.safeLanguageVersionSettings: LanguageVersionSettings?
get() = safeLanguageSettingsComponent?.languageVersionSettings
@@ -77,7 +77,6 @@ class BuiltinTypes {
val floatType: FirImplicitBuiltinTypeRef = FirImplicitFloatTypeRef(null)
val uIntType: FirImplicitUIntTypeRef = FirImplicitUIntTypeRef(null)
val uLongType: FirImplicitULongTypeRef = FirImplicitULongTypeRef(null)
val nothingType: FirImplicitBuiltinTypeRef = FirImplicitNothingTypeRef(null)
val nullableNothingType: FirImplicitBuiltinTypeRef = FirImplicitNullableNothingTypeRef(null)
@@ -70,28 +70,4 @@ inline fun <K : Any, V> FirCachesFactory.createCache(
createValue = { key, _ -> createValue(key) },
)
inline fun <K : Any, V, CONTEXT> FirCachesFactory.createCacheWithPostCompute(
crossinline createValue: (K, CONTEXT) -> V,
crossinline postCompute: (K, V) -> Unit
): FirCache<K, V, CONTEXT> = createCacheWithPostCompute(
createValue = { key, context -> createValue(key, context) to null },
postCompute = { key, value, _ -> postCompute(key, value) }
)
inline fun <K : Any, V> FirCachesFactory.createCacheWithPostCompute(
crossinline createValue: (K) -> V,
crossinline postCompute: (K, V) -> Unit
): FirCache<K, V, Nothing?> = createCacheWithPostCompute(
createValue = { key, _ -> createValue(key) to null },
postCompute = { key, value, _ -> postCompute(key, value) }
)
inline fun <K : Any, V, DATA> FirCachesFactory.createCacheWithPostCompute(
crossinline createValue: (K) -> Pair<V, DATA>,
crossinline postCompute: (K, V, DATA) -> Unit
): FirCache<K, V, Nothing?> = createCacheWithPostCompute(
createValue = { key, _ -> createValue(key) },
postCompute = { key, value, data -> postCompute(key, value, data) }
)
@@ -21,15 +21,6 @@ enum class FirResolvePhase(val noProcessor: Boolean = false) {
ANNOTATIONS_ARGUMENTS_MAPPING,
BODY_RESOLVE;
val requiredToLaunch: FirResolvePhase
get() = when (this) {
RAW_FIR -> RAW_FIR
IMPORTS -> RAW_FIR
STATUS -> TYPES
IMPLICIT_TYPES_BODY_RESOLVE, BODY_RESOLVE -> STATUS
else -> values()[ordinal - 1]
}
val next: FirResolvePhase get() = values()[ordinal + 1]
val previous: FirResolvePhase get() = values()[ordinal - 1]
@@ -1,10 +0,0 @@
/*
* Copyright 2010-2019 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.fir.declarations
enum class SupertypesComputationStatus {
NOT_COMPUTED, COMPUTING, COMPUTED
}
@@ -1,9 +1,7 @@
package org.jetbrains.kotlin.fir.declarations
import org.jetbrains.kotlin.resolve.deprecation.DeprecationInfo
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
import org.jetbrains.kotlin.utils.keysToMap
import org.jetbrains.kotlin.utils.keysToMapExceptNulls
import org.jetbrains.kotlin.resolve.deprecation.DeprecationInfo
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
@@ -27,59 +25,9 @@ class DeprecationsPerUseSite(
fun isEmpty(): Boolean = all == null && bySpecificSite == null
fun isNotEmpty(): Boolean = !isEmpty()
fun combineMin(other: DeprecationsPerUseSite): DeprecationsPerUseSite {
if (isEmpty() || isEmpty()) return EmptyDeprecationsPerUseSite
return DeprecationsPerUseSite(
if (all == null || other.all == null) null else minOf(all, other.all),
if (bySpecificSite == null || other.bySpecificSite == null) {
null
} else {
bySpecificSite.keys.intersect(other.bySpecificSite.keys).keysToMap { target ->
minOf(bySpecificSite[target]!!, other.bySpecificSite[target]!!)
}
}
)
}
fun combinePreferLeft(other: DeprecationsPerUseSite): DeprecationsPerUseSite {
return DeprecationsPerUseSite(
all ?: other.all,
if (bySpecificSite == null || other.bySpecificSite == null) {
bySpecificSite ?: other.bySpecificSite
} else {
bySpecificSite.keys.union(other.bySpecificSite.keys).keysToMapExceptNulls { target ->
bySpecificSite[target] ?: other.bySpecificSite[target]
}
}
)
}
fun inheritableOnly(): DeprecationsPerUseSite =
DeprecationsPerUseSite(
all?.takeIf { it.propagatesToOverrides },
bySpecificSite?.filterValues { it.propagatesToOverrides }
)
override fun toString(): String =
if (isEmpty()) "NoDeprecation"
else "org.jetbrains.kotlin.fir.declarations.DeprecationInfoForUseSites(all=$all, bySpecificSite=$bySpecificSite)"
companion object {
fun fromMap(perUseSite: Map<AnnotationUseSiteTarget?, DeprecationInfo>): DeprecationsPerUseSite {
if (perUseSite.isEmpty()) return EmptyDeprecationsPerUseSite
@Suppress("UNCHECKED_CAST")
val specificCallSite = perUseSite.filterKeys { it != null } as Map<AnnotationUseSiteTarget, DeprecationInfo>
return DeprecationsPerUseSite(
perUseSite[null],
specificCallSite.takeIf { it.isNotEmpty() }
)
}
}
}
val EmptyDeprecationsPerUseSite = DeprecationsPerUseSite(null, null)
@@ -29,8 +29,6 @@ val FirClass.delegateFields: List<FirField>
inline val FirDeclaration.isJava: Boolean
get() = origin is FirDeclarationOrigin.Java
inline val FirDeclaration.isJavaSource: Boolean
get() = origin == FirDeclarationOrigin.Java.Source
inline val FirDeclaration.isFromLibrary: Boolean
get() = origin == FirDeclarationOrigin.Library || origin == FirDeclarationOrigin.Java.Library
inline val FirDeclaration.isPrecompiled: Boolean
@@ -97,8 +97,4 @@ inline val FirClassSymbol<*>.isEnumEntry: Boolean
// ---------------------- specific callables ----------------------
inline val FirPropertyAccessorSymbol.allowsToHaveFakeOverride: Boolean get() = visibility.allowsToHaveFakeOverride
inline val FirPropertySymbol.allowsToHaveFakeOverride: Boolean get() = visibility.allowsToHaveFakeOverride
inline val FirNamedFunctionSymbol.isLocal: Boolean get() = rawStatus.visibility == Visibilities.Local
@@ -8,7 +8,6 @@ package org.jetbrains.kotlin.fir.expressions
import org.jetbrains.kotlin.KtSourceElement
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
import org.jetbrains.kotlin.fir.expressions.builder.buildArgumentList
import org.jetbrains.kotlin.fir.expressions.impl.FirArraySetArgumentList
import org.jetbrains.kotlin.fir.expressions.impl.FirResolvedArgumentList
import org.jetbrains.kotlin.fir.expressions.impl.FirResolvedArgumentListForErrorCall
import org.jetbrains.kotlin.fir.expressions.impl.FirResolvedArgumentListImpl
@@ -22,9 +21,6 @@ fun buildBinaryArgumentList(left: FirExpression, right: FirExpression): FirArgum
arguments += right
}
fun buildArraySetArgumentList(rValue: FirExpression, indexes: List<FirExpression>): FirArgumentList =
FirArraySetArgumentList(rValue, indexes)
fun buildResolvedArgumentList(
mapping: LinkedHashMap<FirExpression, FirValueParameter>,
source: KtSourceElement? = null
@@ -27,8 +27,6 @@ enum class FirOperation(val operator: String = "???") {
DIV_ASSIGN("/="),
REM_ASSIGN("%="),
// Unary
EXCL("!"),
// Type
IS("is"),
NOT_IS("!is"),
@@ -40,12 +38,6 @@ enum class FirOperation(val operator: String = "???") {
companion object {
val ASSIGNMENTS: Set<FirOperation> = EnumSet.of(ASSIGN, PLUS_ASSIGN, MINUS_ASSIGN, TIMES_ASSIGN, DIV_ASSIGN, REM_ASSIGN)
val BOOLEANS: Set<FirOperation> = EnumSet.of(
EQ, NOT_EQ, IDENTITY, NOT_IDENTITY, LT, GT, LT_EQ, GT_EQ, IS, NOT_IS
)
val COMPARISONS: Set<FirOperation> = EnumSet.of(LT, GT, LT_EQ, GT_EQ)
val TYPES: Set<FirOperation> = EnumSet.of(IS, NOT_IS, AS, SAFE_AS)
}
}
@@ -8,11 +8,9 @@ package org.jetbrains.kotlin.fir.expressions.builder
import org.jetbrains.kotlin.KtSourceElement
import org.jetbrains.kotlin.fir.builder.FirBuilderDsl
import org.jetbrains.kotlin.fir.expressions.FirAnnotationArgumentMapping
import org.jetbrains.kotlin.fir.expressions.FirArgumentList
import org.jetbrains.kotlin.fir.expressions.FirExpression
import org.jetbrains.kotlin.fir.expressions.impl.FirAnnotationArgumentMappingImpl
import org.jetbrains.kotlin.fir.expressions.impl.FirEmptyAnnotationArgumentMapping
import org.jetbrains.kotlin.fir.expressions.impl.FirResolvedArgumentList
import org.jetbrains.kotlin.name.Name
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind
@@ -36,14 +34,3 @@ inline fun buildAnnotationArgumentMapping(init: FirAnnotationArgumentMappingBuil
}
return FirAnnotationArgumentMappingBuilder().apply(init).build()
}
fun FirArgumentList.toAnnotationArgumentMapping(): FirAnnotationArgumentMapping {
return buildAnnotationArgumentMapping {
source = this@toAnnotationArgumentMapping.source
if (this@toAnnotationArgumentMapping is FirResolvedArgumentList) {
this@toAnnotationArgumentMapping.mapping
.map { (argument, parameter) -> parameter.name to argument }
.toMap(mapping)
}
}
}
@@ -1,21 +0,0 @@
/*
* Copyright 2010-2020 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.fir.expressions.impl
import org.jetbrains.kotlin.KtSourceElement
import org.jetbrains.kotlin.fir.expressions.FirAbstractArgumentList
import org.jetbrains.kotlin.fir.expressions.FirExpression
class FirArraySetArgumentList internal constructor(
private val rValue: FirExpression,
private val indexes: List<FirExpression>
) : FirAbstractArgumentList() {
override val arguments: List<FirExpression>
get() = indexes + rValue
override val source: KtSourceElement?
get() = null
}
@@ -54,6 +54,3 @@ class FirExtensionService(val session: FirSession) : ComponentArrayOwner<FirExte
}
val FirSession.extensionService: FirExtensionService by FirSession.sessionComponentAccessor()
val FirExtensionService.hasExtensions: Boolean
get() = registeredExtensionsSize > 0
@@ -71,9 +71,3 @@ fun FirReference.isError(): Boolean {
}
}
fun FirReference.toNameString(): String? = when (this) {
is FirNamedReference -> name.asString()
is FirThisReference -> "this"
is FirSuperReference -> "super"
else -> null
}
@@ -63,15 +63,6 @@ fun FirTypeScope.processOverriddenFunctionsAndSelf(
return processOverriddenFunctions(functionSymbol, processor = processor)
}
fun FirTypeScope.processOverriddenPropertiesAndSelf(
propertySymbol: FirPropertySymbol,
processor: (FirPropertySymbol) -> ProcessorAction
): ProcessorAction {
if (!processor(propertySymbol)) return ProcessorAction.STOP
return processOverriddenProperties(propertySymbol, processor = processor)
}
fun List<FirTypeScope>.processOverriddenPropertiesAndSelf(
propertySymbol: FirPropertySymbol,
processor: (FirPropertySymbol) -> ProcessorAction
@@ -70,8 +70,6 @@ class FirConstructorSymbol(callableId: CallableId) : FirFunctionSymbol<FirConstr
val delegatedConstructorCallIsThis: Boolean
get() = fir.delegatedConstructor?.isThis == true
val delegatedConstructorCallIsSuper: Boolean
get() = fir.delegatedConstructor?.isSuper == true
}
/**
@@ -122,17 +122,6 @@ fun FirTypeProjection.toConeTypeProjection(): ConeTypeProjection =
else -> error("!")
}
private fun ConeTypeParameterType.hasNotNullUpperBound(): Boolean {
return lookupTag.typeParameterSymbol.resolvedBounds.any {
val boundType = it.coneType
if (boundType is ConeTypeParameterType) {
boundType.hasNotNullUpperBound()
} else {
boundType.nullability == ConeNullability.NOT_NULL
}
}
}
val FirTypeRef.canBeNull: Boolean
get() = coneType.canBeNull
@@ -60,8 +60,6 @@ object FieldSets {
val typeRefField = field(typeRef, withReplace = true)
val valueParameters by lazy { fieldList(valueParameter) }
val typeParameters by lazy { fieldList("typeParameters", typeParameter) }
val typeParameterRefs by lazy { fieldList("typeParameters", typeParameterRef) }
@@ -71,7 +71,6 @@ val firBasedSymbolType = type("fir.symbols", "FirBasedSymbol")
val functionSymbolType = type("fir.symbols.impl", "FirFunctionSymbol")
val backingFieldSymbolType = type("fir.symbols.impl", "FirBackingFieldSymbol")
val delegateFieldSymbolType = type("fir.symbols.impl", "FirDelegateFieldSymbol")
val classSymbolType = type("fir.symbols.impl", "FirClassSymbol")
val classLikeSymbolType = type("fir.symbols.impl", "FirClassLikeSymbol<*>")
val regularClassSymbolType = type("fir.symbols.impl", "FirRegularClassSymbol")
val typeParameterSymbolType = type("fir.symbols.impl", "FirTypeParameterSymbol")
@@ -85,7 +84,6 @@ val emptyContractDescriptionType = generatedType("contracts.impl", "FirEmptyCont
val coneDiagnosticType = generatedType("diagnostics", "ConeDiagnostic")
val coneStubDiagnosticType = generatedType("diagnostics", "ConeStubDiagnostic")
val dslBuilderAnnotationType = generatedType("builder", "FirBuilderDsl")
val firImplementationDetailType = generatedType("FirImplementationDetail")
val declarationOriginType = generatedType("declarations", "FirDeclarationOrigin")
val declarationAttributesType = generatedType("declarations", "FirDeclarationAttributes")
@@ -90,16 +90,6 @@ abstract class AbstractBuilderConfigurator<T : AbstractFirTreeBuilder>(val firTr
builder.materializedElement = element
return ExceptConfigurator()
}
inner class Helper(val fieldName: String) {
infix fun from(element: Element) {
val field = element[fieldName] ?: throw IllegalArgumentException("Element $element doesn't have field $fieldName")
builder.fields += FieldWithDefault(field)
}
}
// fields has <field> from <element>
infix fun has(name: String): Helper = Helper(name)
}
inner class ExceptConfigurator {
@@ -115,12 +105,6 @@ abstract class AbstractBuilderConfigurator<T : AbstractFirTreeBuilder>(val firTr
val fields = Fields()
val parents: MutableList<IntermediateBuilder> get() = builder.parents
var materializedElement: Element
get() = throw IllegalArgumentException()
set(value) {
builder.materializedElement = value
}
}
inner class IntermediateBuilderDelegateProvider(
@@ -42,10 +42,6 @@ abstract class AbstractFieldConfigurator<T : AbstractFirTreeBuilder>(private val
}
}
fun parentArg(parent: Element, argument: String, type: String) {
parentArg(parent, Type(null, argument), Type(null, type))
}
fun parentArg(parent: Element, argument: String, type: Importable) {
parentArg(parent, Type(null, argument), type)
}
@@ -61,10 +57,6 @@ abstract class AbstractFieldConfigurator<T : AbstractFirTreeBuilder>(private val
argMap[argument] = type
}
fun Type.withArgs(vararg args: Importable): Pair<Type, List<Importable>> {
return this to args.toList()
}
fun Type.withArgs(vararg args: String): Pair<Type, List<Importable>> {
return this to args.map { Type(null, it) }
}
@@ -87,8 +87,6 @@ abstract class AbstractFirTreeImplementationConfigurator {
val parents = ParentsHolder()
fun Implementation.withArg(argument: Importable): ImplementationWithArg = ImplementationWithArg(this, argument)
fun optInToInternals() {
implementation.requiresOptIn = true
}
@@ -94,6 +94,4 @@ fun Field.withTransform(needTransformInOtherChildren: Boolean = false): Field =
fun Field.withReplace(): Field = copy().apply {
withReplace = true
}
fun FieldSet.withTransform(): FieldSet = this.map { it.withTransform() }
}
@@ -130,7 +130,6 @@ private fun SmartPrinter.printBuilder(builder: Builder) {
internal val Field.invisibleField: Boolean get() = customInitializationCall != null
private val String.nullable: String get() = if (endsWith("?")) this else "$this?"
private fun FieldWithDefault.needBackingField(fieldIsUseless: Boolean) =
(!nullable || notNull) && origin !is FieldList && if (fieldIsUseless) {
defaultValueInImplementation == null
@@ -1,43 +0,0 @@
/*
* Copyright 2010-2020 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.fir.tree.generator.util
import org.jetbrains.kotlin.fir.tree.generator.context.AbstractFirTreeBuilder
import org.jetbrains.kotlin.fir.tree.generator.model.Element
import org.jetbrains.kotlin.fir.tree.generator.model.Field
import java.io.File
fun printFieldUsageTable(builder: AbstractFirTreeBuilder) {
val elements = builder.elements.filter { it.allImplementations.isNotEmpty() }
val fields = elements.flatMapTo(mutableSetOf()) { it.allFields }
val mapping = mutableMapOf<Element, Set<Field>>()
val fieldsCount = mutableMapOf<Field, Int>()
for (element in elements) {
val containingFields = mutableSetOf<Field>()
for (field in fields) {
if (field in element.allFields) {
containingFields += field
fieldsCount[field] = fieldsCount.getOrDefault(field, 0) + 1
}
}
mapping[element] = containingFields
}
val sortedFields = fields.sortedByDescending { fieldsCount[it] }
File("compiler/fir/tree/table.csv").printWriter().use { printer ->
with(printer) {
val delim = ","
print(delim)
println(sortedFields.joinToString(delim) { "${it.name}:${fieldsCount.getValue(it)}" })
for (element in elements) {
print(element.name + delim)
val containingFields = mapping.getValue(element)
println(sortedFields.joinToString(delim) { if (it in containingFields) "+" else "-" })
}
}
}
}