[LL FIR] drop unused declarations

This commit is contained in:
Dmitrii Gridin
2024-02-13 20:27:19 +01:00
committed by Space Team
parent 8f83e2ab4d
commit f5f3b7fec0
6 changed files with 1 additions and 89 deletions
@@ -1,11 +0,0 @@
/*
* 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.analysis.low.level.api.fir.api
enum class DeclarationLockType {
READ_LOCK,
WRITE_LOCK,
}
@@ -7,10 +7,8 @@ package org.jetbrains.kotlin.analysis.low.level.api.fir.element.builder
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiErrorElement
import org.jetbrains.annotations.TestOnly
import org.jetbrains.kotlin.analysis.api.impl.barebone.annotations.ThreadSafe
import org.jetbrains.kotlin.analysis.low.level.api.fir.LLFirModuleResolveComponents
import org.jetbrains.kotlin.analysis.low.level.api.fir.file.structure.FileStructureElement
import org.jetbrains.kotlin.analysis.low.level.api.fir.file.structure.FirElementsRecorder
import org.jetbrains.kotlin.analysis.low.level.api.fir.lazy.resolve.declarationCanBeLazilyResolved
import org.jetbrains.kotlin.analysis.low.level.api.fir.util.findSourceNonLocalFirDeclaration
@@ -293,12 +291,6 @@ internal class FirElementBuilder(
private fun FirAnnotationContainer.findAnnotation(
annotationEntry: KtAnnotationEntry,
): FirAnnotation? = annotations.find { it.psi == annotationEntry }
@TestOnly
fun getStructureElementFor(element: KtElement): FileStructureElement {
val fileStructure = moduleComponents.fileStructureCache.getFileStructure(element.containingKtFile)
return fileStructure.getStructureElementFor(element)
}
}
private fun KtDeclaration.isPartOf(callableDeclaration: KtCallableDeclaration): Boolean = when (this) {
@@ -27,8 +27,6 @@ internal sealed class FileStructureElement {
abstract val diagnostics: FileStructureElementDiagnostics
companion object {
val recorder = FirElementsRecorder()
fun recorderFor(fir: FirElement): FirElementsRecorder = when (fir) {
is FirFile -> RootStructureElement.Recorder
is FirScript -> RootScriptStructureElement.Recorder
@@ -66,13 +66,6 @@ internal object FirLazyBodiesCalculator {
firElement.transformSingle(FirTargetLazyAnnotationCalculatorTransformer, FirLazyAnnotationTransformerData(session))
}
fun calculateCompilerAnnotations(firElement: FirElementWithResolveState) {
firElement.transformSingle(
FirTargetLazyAnnotationCalculatorTransformer,
FirLazyAnnotationTransformerData(firElement.moduleData.session, FirLazyAnnotationTransformerScope.COMPILER_ONLY)
)
}
fun calculateLazyArgumentsForAnnotation(annotationCall: FirAnnotationCall, session: FirSession): FirArgumentList {
require(needCalculatingAnnotationCall(annotationCall))
return createArgumentsForAnnotation(annotationCall, session)
@@ -634,7 +627,6 @@ private fun calculateLazyBodyForCodeFragment(designation: FirDesignation) {
private enum class FirLazyAnnotationTransformerScope {
ALL_ANNOTATIONS,
COMPILER_ONLY;
}
private data class FirLazyAnnotationTransformerData(
@@ -1,56 +1,15 @@
/*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2024 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.analysis.low.level.api.fir.lazy.resolve
import org.jetbrains.kotlin.KtFakeSourceElement
import org.jetbrains.kotlin.KtFakeSourceElementKind
import org.jetbrains.kotlin.analysis.utils.printer.parentOfType
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.psi
import org.jetbrains.kotlin.psi
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
import org.jetbrains.kotlin.utils.exceptions.errorWithAttachment
import org.jetbrains.kotlin.utils.exceptions.withPsiEntry
internal fun FirDeclaration.getKtDeclarationForFirElement(): KtDeclaration {
require(this !is FirFile)
val ktDeclaration = (psi as? KtDeclaration) ?: run {
(source as? KtFakeSourceElement).psi?.parentOfType()
}
check(ktDeclaration is KtDeclaration) {
"FirDeclaration should have a PSI of type KtDeclaration"
}
val declaration = when (this) {
is FirPropertyAccessor, is FirTypeParameter, is FirValueParameter -> {
when (ktDeclaration) {
is KtPropertyAccessor -> ktDeclaration.property
is KtProperty -> ktDeclaration
is KtParameter, is KtTypeParameter -> {
val containingDeclaration = ktDeclaration.getParentOfType<KtDeclaration>(true)
if (containingDeclaration !is KtPropertyAccessor) containingDeclaration else containingDeclaration.property
}
is KtCallExpression -> {
check(this.source?.kind == KtFakeSourceElementKind.DefaultAccessor)
((ktDeclaration as? KtCallExpression)?.parent as? KtPropertyDelegate)?.parent as? KtProperty
}
else -> ktDeclaration
}
}
else -> ktDeclaration
}
check(declaration is KtDeclaration) {
"FirDeclaration should have a PSI of type KtDeclaration"
}
return declaration
}
internal fun declarationCanBeLazilyResolved(declaration: KtDeclaration): Boolean = when (declaration) {
is KtDestructuringDeclarationEntry, is KtFunctionLiteral, is KtTypeParameter -> false
is KtPrimaryConstructor -> (declaration.parent as? KtClassOrObject)?.isLocal == false
@@ -1,18 +0,0 @@
/*
* Copyright 2010-2023 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.analysis.low.level.api.fir.util
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
import org.jetbrains.kotlin.fir.declarations.resolvePhase
internal object LLFirResolvePhaseChecker {
fun requireResolvePhase(firDeclaration: FirDeclaration, requiredPhase: FirResolvePhase) {
require(firDeclaration.resolvePhase == FirResolvePhase.BODY_RESOLVE) {
"Required $requiredPhase for $firDeclaration but ${firDeclaration.resolvePhase} found"
}
}
}