From 195ecad004c5a122cd70de105341b47203f7aa7f Mon Sep 17 00:00:00 2001 From: Egor Kulikov Date: Fri, 23 Dec 2022 01:26:52 +0100 Subject: [PATCH] [FIR] Make annotations arguments lazy in RawFirBuilder Sixth step for ^KT-52615 --- .../lazy/resolve/FirLazyBodiesCalculator.kt | 123 +++++++++++++++++- ...edAnnotationArgumentsMappingTransformer.kt | 2 + ...edAnnotationArgumentsResolveTransformer.kt | 2 + ...DesignatedAnnotationsResolveTransformed.kt | 2 + .../LLFirDesignatedTypeResolverTransformer.kt | 8 ++ .../lazyResolve/annotationParameters.txt | 34 ++--- .../testdata/lazyResolve/annotations.txt | 34 ++--- .../kotlin/fir/builder/RawFirBuilder.kt | 14 +- .../declarations/annotation.lazyBodies.txt | 2 +- ...nNullableParenthesizedTypes.lazyBodies.txt | 2 +- ...tationsOnParenthesizedTypes.lazyBodies.txt | 2 +- ...nglingAnnotationsClassLevel.lazyBodies.txt | 6 +- ...anglingAnnotationsFileLevel.lazyBodies.txt | 2 +- .../splitModifierList.lazyBodies.txt | 4 +- .../expressions/annotated.lazyBodies.txt | 2 +- .../collectionLiterals.lazyBodies.txt | 8 +- 16 files changed, 190 insertions(+), 57 deletions(-) diff --git a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/lazy/resolve/FirLazyBodiesCalculator.kt b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/lazy/resolve/FirLazyBodiesCalculator.kt index 1a703c7b9cb..15e670a1a30 100644 --- a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/lazy/resolve/FirLazyBodiesCalculator.kt +++ b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/lazy/resolve/FirLazyBodiesCalculator.kt @@ -9,23 +9,30 @@ import kotlinx.collections.immutable.PersistentList import kotlinx.collections.immutable.persistentListOf import kotlinx.collections.immutable.toPersistentList import org.jetbrains.kotlin.analysis.low.level.api.fir.api.FirDesignation -import org.jetbrains.kotlin.fir.FirElement +import org.jetbrains.kotlin.fir.* +import org.jetbrains.kotlin.fir.builder.RawFirBuilder import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.fir.declarations.utils.getExplicitBackingField -import org.jetbrains.kotlin.fir.expressions.FirFunctionCall -import org.jetbrains.kotlin.fir.expressions.FirStatement -import org.jetbrains.kotlin.fir.expressions.FirWrappedDelegateExpression +import org.jetbrains.kotlin.fir.expressions.* import org.jetbrains.kotlin.fir.expressions.impl.FirLazyBlock import org.jetbrains.kotlin.fir.expressions.impl.FirLazyDelegatedConstructorCall import org.jetbrains.kotlin.fir.expressions.impl.FirLazyExpression -import org.jetbrains.kotlin.fir.psi +import org.jetbrains.kotlin.fir.extensions.registeredPluginAnnotations import org.jetbrains.kotlin.fir.scopes.kotlinScopeProvider +import org.jetbrains.kotlin.fir.types.FirUserTypeRef import org.jetbrains.kotlin.fir.visitors.FirTransformer import org.jetbrains.kotlin.fir.visitors.transformSingle +import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.* +import org.jetbrains.kotlin.name.StandardClassIds.Annotations.Deprecated +import org.jetbrains.kotlin.name.StandardClassIds.Annotations.DeprecatedSinceKotlin +import org.jetbrains.kotlin.name.StandardClassIds.Annotations.JvmRecord +import org.jetbrains.kotlin.name.StandardClassIds.Annotations.WasExperimental +import org.jetbrains.kotlin.name.StandardClassIds.Annotations.SinceKotlin internal object FirLazyBodiesCalculator { fun calculateLazyBodiesInside(designation: FirDesignation) { + calculateAnnotations(designation.target) designation.target.transform>( FirLazyBodiesCalculatorTransformer, designation.path.toPersistentList(), @@ -33,9 +40,28 @@ internal object FirLazyBodiesCalculator { } fun calculateLazyBodies(firFile: FirFile) { + calculateAnnotations(firFile) firFile.transform>(FirLazyBodiesCalculatorTransformer, persistentListOf()) } + fun calculateAnnotations(firElement: FirElementWithResolvePhase) { + calculateAnnotations(firElement, firElement.moduleData.session) + } + + fun calculateAnnotations(firElement: FirElement, session: FirSession) { + firElement.transform( + FirLazyAnnotationTransformer, + FirLazyAnnotationTransformerData(session) + ) + } + + fun calculateCompilerAnnotations(firElement: FirElementWithResolvePhase) { + firElement.transform( + FirLazyAnnotationTransformer, + FirLazyAnnotationTransformerData(firElement.moduleData.session, FirLazyAnnotationTransformerScope.COMPILER_ONLY) + ) + } + private fun replaceValueParameterDefaultValues(valueParameters: List, newValueParameters: List) { require(valueParameters.size == newValueParameters.size) for ((valueParameter, newValueParameter) in valueParameters.zip(newValueParameters)) { @@ -45,6 +71,13 @@ internal object FirLazyBodiesCalculator { } } + fun calculateLazyArgumentsForAnnotation(annotationCall: FirAnnotationCall, session: FirSession) { + require(needCalculatingAnnotationCall(annotationCall)) + val builder = RawFirBuilder(session, baseScopeProvider = session.kotlinScopeProvider) + val newAnnotationCall = builder.buildAnnotationCall(annotationCall.psi as KtAnnotationEntry) + annotationCall.replaceArgumentList(newAnnotationCall.argumentList) + } + fun calculateLazyBodiesForFunction(designation: FirDesignation) { val simpleFunction = designation.target as FirSimpleFunction require(needCalculatingLazyBodyForFunction(simpleFunction)) @@ -169,6 +202,86 @@ internal object FirLazyBodiesCalculator { || firProperty.initializer is FirLazyExpression || (firProperty.delegate as? FirWrappedDelegateExpression)?.expression is FirLazyExpression || firProperty.getExplicitBackingField()?.initializer is FirLazyExpression + + fun needCalculatingAnnotationCall(firAnnotationCall: FirAnnotationCall): Boolean = + firAnnotationCall.argumentList.arguments.any { it is FirLazyExpression } +} + +private enum class FirLazyAnnotationTransformerScope { + ALL_ANNOTATIONS, + COMPILER_ONLY; +} + +private data class FirLazyAnnotationTransformerData( + val session: FirSession, + val compilerAnnotationsOnly: FirLazyAnnotationTransformerScope = FirLazyAnnotationTransformerScope.ALL_ANNOTATIONS +) + +private object FirLazyAnnotationTransformer : FirTransformer() { + private val COMPILATOR_ANNOTATION_NAMES: Set = setOf( + Deprecated, + DeprecatedSinceKotlin, + WasExperimental, + JvmRecord, + SinceKotlin, + ).mapTo(mutableSetOf()) { it.shortClassName } + + private fun canBeCompilerAnnotation(annotationCall: FirAnnotationCall, session: FirSession): Boolean { + val annotationTypeRef = annotationCall.annotationTypeRef + if (annotationTypeRef !is FirUserTypeRef) return false + if (session.registeredPluginAnnotations.annotations.isNotEmpty()) return true + val name = annotationTypeRef.qualifier.last().name + return name in COMPILATOR_ANNOTATION_NAMES + } + + override fun transformElement(element: E, data: FirLazyAnnotationTransformerData): E { + element.transformChildren(this, data) + return element + } + + override fun transformAnnotationCall(annotationCall: FirAnnotationCall, data: FirLazyAnnotationTransformerData): FirStatement { + if ((data.compilerAnnotationsOnly == FirLazyAnnotationTransformerScope.ALL_ANNOTATIONS || canBeCompilerAnnotation( + annotationCall, + data.session, + )) && FirLazyBodiesCalculator.needCalculatingAnnotationCall(annotationCall) + ) { + FirLazyBodiesCalculator.calculateLazyArgumentsForAnnotation(annotationCall, data.session) + } + super.transformAnnotationCall(annotationCall, data) + return annotationCall + } + + override fun transformErrorAnnotationCall( + errorAnnotationCall: FirErrorAnnotationCall, + data: FirLazyAnnotationTransformerData + ): FirStatement { + transformAnnotationCall(errorAnnotationCall, data) + return errorAnnotationCall + } + + override fun transformExpression(expression: FirExpression, data: FirLazyAnnotationTransformerData): FirStatement { + if (expression is FirLazyExpression) { + return expression + } + return super.transformExpression(expression, data) + } + + override fun transformBlock(block: FirBlock, data: FirLazyAnnotationTransformerData): FirStatement { + if (block is FirLazyBlock) { + return block + } + return super.transformBlock(block, data) + } + + override fun transformDelegatedConstructorCall( + delegatedConstructorCall: FirDelegatedConstructorCall, + data: FirLazyAnnotationTransformerData + ): FirStatement { + if (delegatedConstructorCall is FirLazyDelegatedConstructorCall) { + return delegatedConstructorCall + } + return super.transformDelegatedConstructorCall(delegatedConstructorCall, data) + } } private object FirLazyBodiesCalculatorTransformer : FirTransformer>() { diff --git a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirDesignatedAnnotationArgumentsMappingTransformer.kt b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirDesignatedAnnotationArgumentsMappingTransformer.kt index 106ff7016ce..eda112fc977 100644 --- a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirDesignatedAnnotationArgumentsMappingTransformer.kt +++ b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirDesignatedAnnotationArgumentsMappingTransformer.kt @@ -7,6 +7,7 @@ package org.jetbrains.kotlin.analysis.low.level.api.fir.transformers import org.jetbrains.kotlin.analysis.low.level.api.fir.LLFirPhaseRunner import org.jetbrains.kotlin.analysis.low.level.api.fir.api.FirDesignationWithFile +import org.jetbrains.kotlin.analysis.low.level.api.fir.lazy.resolve.FirLazyBodiesCalculator import org.jetbrains.kotlin.analysis.low.level.api.fir.transformers.LLFirLazyTransformer.Companion.updatePhaseDeep import org.jetbrains.kotlin.analysis.low.level.api.fir.util.checkAnnotationArgumentsMappingIsResolved import org.jetbrains.kotlin.analysis.low.level.api.fir.util.checkPhase @@ -41,6 +42,7 @@ internal class LLFirDesignatedAnnotationArgumentsMappingTransformer( designation.target.checkPhase(FirResolvePhase.IMPLICIT_TYPES_BODY_RESOLVE) phaseRunner.runPhaseWithCustomResolve(FirResolvePhase.ANNOTATIONS_ARGUMENTS_MAPPING) { + FirLazyBodiesCalculator.calculateAnnotations(designation.firFile) designation.firFile.transform(this, ResolutionMode.ContextIndependent) } diff --git a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirDesignatedAnnotationArgumentsResolveTransformer.kt b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirDesignatedAnnotationArgumentsResolveTransformer.kt index 3c2954f8231..d2ccfdd5d49 100644 --- a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirDesignatedAnnotationArgumentsResolveTransformer.kt +++ b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirDesignatedAnnotationArgumentsResolveTransformer.kt @@ -7,6 +7,7 @@ package org.jetbrains.kotlin.analysis.low.level.api.fir.transformers import org.jetbrains.kotlin.analysis.low.level.api.fir.LLFirPhaseRunner import org.jetbrains.kotlin.analysis.low.level.api.fir.api.FirDesignationWithFile +import org.jetbrains.kotlin.analysis.low.level.api.fir.lazy.resolve.FirLazyBodiesCalculator import org.jetbrains.kotlin.analysis.low.level.api.fir.util.checkPhase import org.jetbrains.kotlin.analysis.low.level.api.fir.util.checkTypeRefIsResolved import org.jetbrains.kotlin.analysis.low.level.api.fir.util.withFirEntry @@ -27,6 +28,7 @@ internal class LLFirDesignatedAnnotationArgumentsResolveTransformer( private fun moveNextDeclaration(designationIterator: Iterator) { if (!designationIterator.hasNext()) { + FirLazyBodiesCalculator.calculateAnnotations(designation.target) designation.target.transform(declarationsTransformer, ResolutionMode.ContextIndependent) return } diff --git a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirDesignatedAnnotationsResolveTransformed.kt b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirDesignatedAnnotationsResolveTransformed.kt index ccebadfff13..1cebb25266b 100644 --- a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirDesignatedAnnotationsResolveTransformed.kt +++ b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirDesignatedAnnotationsResolveTransformed.kt @@ -7,6 +7,7 @@ package org.jetbrains.kotlin.analysis.low.level.api.fir.transformers import org.jetbrains.kotlin.analysis.low.level.api.fir.LLFirPhaseRunner import org.jetbrains.kotlin.analysis.low.level.api.fir.api.FirDesignationWithFile +import org.jetbrains.kotlin.analysis.low.level.api.fir.lazy.resolve.FirLazyBodiesCalculator import org.jetbrains.kotlin.analysis.low.level.api.fir.util.checkPhase import org.jetbrains.kotlin.fir.FirElementWithResolvePhase import org.jetbrains.kotlin.fir.FirSession @@ -25,6 +26,7 @@ internal class LLFirDesignatedAnnotationsResolveTransformed( if (!designationIterator.hasNext()) { val declaration = designation.target if (declaration is FirRegularClass || declaration is FirTypeAlias) { + FirLazyBodiesCalculator.calculateCompilerAnnotations(declaration) declaration.transform(this, null) } return diff --git a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirDesignatedTypeResolverTransformer.kt b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirDesignatedTypeResolverTransformer.kt index c6549da3223..5e331789e72 100644 --- a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirDesignatedTypeResolverTransformer.kt +++ b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirDesignatedTypeResolverTransformer.kt @@ -7,6 +7,7 @@ package org.jetbrains.kotlin.analysis.low.level.api.fir.transformers import org.jetbrains.kotlin.analysis.low.level.api.fir.LLFirPhaseRunner import org.jetbrains.kotlin.analysis.low.level.api.fir.api.FirDesignationWithFile +import org.jetbrains.kotlin.analysis.low.level.api.fir.lazy.resolve.FirLazyBodiesCalculator import org.jetbrains.kotlin.analysis.low.level.api.fir.transformers.LLFirLazyTransformer.Companion.updatePhaseDeep import org.jetbrains.kotlin.analysis.low.level.api.fir.util.* import org.jetbrains.kotlin.fir.FirElement @@ -15,6 +16,8 @@ import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.fir.resolve.ScopeSession import org.jetbrains.kotlin.fir.resolve.transformers.FirTypeResolveTransformer +import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef +import org.jetbrains.kotlin.fir.types.FirTypeRef /** * Transform designation into TYPES phase. Affects only for designation, target declaration and it's children @@ -53,6 +56,11 @@ internal class LLFirDesignatedTypeResolverTransformer( (designation.target as? FirDeclaration)?.let { checkClassMembersAreResolved(it) } } + override fun transformTypeRef(typeRef: FirTypeRef, data: Any?): FirResolvedTypeRef { + FirLazyBodiesCalculator.calculateAnnotations(typeRef, session) + return super.transformTypeRef(typeRef, data) + } + override fun checkIsResolved(target: FirElementWithResolvePhase) { target.checkPhase(FirResolvePhase.TYPES) when (target) { diff --git a/analysis/low-level-api-fir/testdata/lazyResolve/annotationParameters.txt b/analysis/low-level-api-fir/testdata/lazyResolve/annotationParameters.txt index ba816b269ad..90616523787 100644 --- a/analysis/low-level-api-fir/testdata/lazyResolve/annotationParameters.txt +++ b/analysis/low-level-api-fir/testdata/lazyResolve/annotationParameters.txt @@ -31,9 +31,9 @@ FILE: annotationParameters.kt super() } - @Anno(X#.A#) public? final? [RAW_FIR] fun resolveMe(): R|kotlin/Unit| { LAZY_BLOCK } + @Anno(LAZY_EXPRESSION) public? final? [RAW_FIR] fun resolveMe(): R|kotlin/Unit| { LAZY_BLOCK } - @Anno(X#.A#) public? final? [RAW_FIR] fun foo(): R|kotlin/Unit| { LAZY_BLOCK } + @Anno(LAZY_EXPRESSION) public? final? [RAW_FIR] fun foo(): R|kotlin/Unit| { LAZY_BLOCK } } @@ -69,9 +69,9 @@ FILE: annotationParameters.kt super() } - @Anno(X#.A#) public? final? [RAW_FIR] fun resolveMe(): R|kotlin/Unit| { LAZY_BLOCK } + @Anno(LAZY_EXPRESSION) public? final? [RAW_FIR] fun resolveMe(): R|kotlin/Unit| { LAZY_BLOCK } - @Anno(X#.A#) public? final? [RAW_FIR] fun foo(): R|kotlin/Unit| { LAZY_BLOCK } + @Anno(LAZY_EXPRESSION) public? final? [RAW_FIR] fun foo(): R|kotlin/Unit| { LAZY_BLOCK } } @@ -107,9 +107,9 @@ FILE: annotationParameters.kt super() } - @Anno(X#.A#) public? final? [COMPILER_REQUIRED_ANNOTATIONS] fun resolveMe(): R|kotlin/Unit| { LAZY_BLOCK } + @Anno(LAZY_EXPRESSION) public? final? [COMPILER_REQUIRED_ANNOTATIONS] fun resolveMe(): R|kotlin/Unit| { LAZY_BLOCK } - @Anno(X#.A#) public? final? [RAW_FIR] fun foo(): R|kotlin/Unit| { LAZY_BLOCK } + @Anno(LAZY_EXPRESSION) public? final? [RAW_FIR] fun foo(): R|kotlin/Unit| { LAZY_BLOCK } } @@ -145,9 +145,9 @@ FILE: annotationParameters.kt super() } - @Anno(X#.A#) public? final? [COMPANION_GENERATION] fun resolveMe(): R|kotlin/Unit| { LAZY_BLOCK } + @Anno(LAZY_EXPRESSION) public? final? [COMPANION_GENERATION] fun resolveMe(): R|kotlin/Unit| { LAZY_BLOCK } - @Anno(X#.A#) public? final? [RAW_FIR] fun foo(): R|kotlin/Unit| { LAZY_BLOCK } + @Anno(LAZY_EXPRESSION) public? final? [RAW_FIR] fun foo(): R|kotlin/Unit| { LAZY_BLOCK } } @@ -183,9 +183,9 @@ FILE: annotationParameters.kt super() } - @Anno(X#.A#) public? final? [SUPER_TYPES] fun resolveMe(): R|kotlin/Unit| { LAZY_BLOCK } + @Anno(LAZY_EXPRESSION) public? final? [SUPER_TYPES] fun resolveMe(): R|kotlin/Unit| { LAZY_BLOCK } - @Anno(X#.A#) public? final? [RAW_FIR] fun foo(): R|kotlin/Unit| { LAZY_BLOCK } + @Anno(LAZY_EXPRESSION) public? final? [RAW_FIR] fun foo(): R|kotlin/Unit| { LAZY_BLOCK } } @@ -221,9 +221,9 @@ FILE: annotationParameters.kt super() } - @R|Anno|(X#.A#) public? final? [TYPES] fun resolveMe(): R|kotlin/Unit| { LAZY_BLOCK } + @R|Anno|(LAZY_EXPRESSION) public? final? [TYPES] fun resolveMe(): R|kotlin/Unit| { LAZY_BLOCK } - @Anno(X#.A#) public? final? [SUPER_TYPES] fun foo(): R|kotlin/Unit| { LAZY_BLOCK } + @Anno(LAZY_EXPRESSION) public? final? [SUPER_TYPES] fun foo(): R|kotlin/Unit| { LAZY_BLOCK } } @@ -259,9 +259,9 @@ FILE: annotationParameters.kt super() } - @R|Anno|(X#.A#) public final [STATUS] fun resolveMe(): R|kotlin/Unit| { LAZY_BLOCK } + @R|Anno|(LAZY_EXPRESSION) public final [STATUS] fun resolveMe(): R|kotlin/Unit| { LAZY_BLOCK } - @R|Anno|(X#.A#) public final [TYPES] fun foo(): R|kotlin/Unit| { LAZY_BLOCK } + @R|Anno|(LAZY_EXPRESSION) public final [TYPES] fun foo(): R|kotlin/Unit| { LAZY_BLOCK } } @@ -299,7 +299,7 @@ FILE: annotationParameters.kt @R|Anno|(Q|X|.R|/X.A|) public final [ARGUMENTS_OF_ANNOTATIONS] fun resolveMe(): R|kotlin/Unit| { LAZY_BLOCK } - @R|Anno|(X#.A#) public final [STATUS] fun foo(): R|kotlin/Unit| { LAZY_BLOCK } + @R|Anno|(LAZY_EXPRESSION) public final [STATUS] fun foo(): R|kotlin/Unit| { LAZY_BLOCK } } @@ -338,7 +338,7 @@ FILE: annotationParameters.kt @R|Anno|(Q|X|.R|/X.A|) public final [CONTRACTS] fun resolveMe(): R|kotlin/Unit| { } - @R|Anno|(X#.A#) public final [STATUS] fun foo(): R|kotlin/Unit| { LAZY_BLOCK } + @R|Anno|(LAZY_EXPRESSION) public final [STATUS] fun foo(): R|kotlin/Unit| { LAZY_BLOCK } } @@ -377,7 +377,7 @@ FILE: annotationParameters.kt @R|Anno|(Q|X|.R|/X.A|) public final [IMPLICIT_TYPES_BODY_RESOLVE] fun resolveMe(): R|kotlin/Unit| { } - @R|Anno|(X#.A#) public final [STATUS] fun foo(): R|kotlin/Unit| { LAZY_BLOCK } + @R|Anno|(LAZY_EXPRESSION) public final [STATUS] fun foo(): R|kotlin/Unit| { LAZY_BLOCK } } diff --git a/analysis/low-level-api-fir/testdata/lazyResolve/annotations.txt b/analysis/low-level-api-fir/testdata/lazyResolve/annotations.txt index 21146218ee2..69d442b9a5e 100644 --- a/analysis/low-level-api-fir/testdata/lazyResolve/annotations.txt +++ b/analysis/low-level-api-fir/testdata/lazyResolve/annotations.txt @@ -1,53 +1,53 @@ RAW_FIR: FILE: annotations.kt - @FILE:Suppress(String(1)) - @Suppress(String(2)) public? final? [RAW_FIR] fun resolveMe(): R|kotlin/Unit| { LAZY_BLOCK } + @FILE:Suppress(LAZY_EXPRESSION) + @Suppress(LAZY_EXPRESSION) public? final? [RAW_FIR] fun resolveMe(): R|kotlin/Unit| { LAZY_BLOCK } IMPORTS: FILE: annotations.kt - @FILE:Suppress(String(1)) - @Suppress(String(2)) public? final? [RAW_FIR] fun resolveMe(): R|kotlin/Unit| { LAZY_BLOCK } + @FILE:Suppress(LAZY_EXPRESSION) + @Suppress(LAZY_EXPRESSION) public? final? [RAW_FIR] fun resolveMe(): R|kotlin/Unit| { LAZY_BLOCK } COMPILER_REQUIRED_ANNOTATIONS: FILE: annotations.kt - @FILE:Suppress(String(1)) - @Suppress(String(2)) public? final? [COMPILER_REQUIRED_ANNOTATIONS] fun resolveMe(): R|kotlin/Unit| { LAZY_BLOCK } + @FILE:Suppress(LAZY_EXPRESSION) + @Suppress(LAZY_EXPRESSION) public? final? [COMPILER_REQUIRED_ANNOTATIONS] fun resolveMe(): R|kotlin/Unit| { LAZY_BLOCK } COMPANION_GENERATION: FILE: annotations.kt - @FILE:Suppress(String(1)) - @Suppress(String(2)) public? final? [COMPANION_GENERATION] fun resolveMe(): R|kotlin/Unit| { LAZY_BLOCK } + @FILE:Suppress(LAZY_EXPRESSION) + @Suppress(LAZY_EXPRESSION) public? final? [COMPANION_GENERATION] fun resolveMe(): R|kotlin/Unit| { LAZY_BLOCK } SUPER_TYPES: FILE: annotations.kt - @FILE:Suppress(String(1)) - @Suppress(String(2)) public? final? [SUPER_TYPES] fun resolveMe(): R|kotlin/Unit| { LAZY_BLOCK } + @FILE:Suppress(LAZY_EXPRESSION) + @Suppress(LAZY_EXPRESSION) public? final? [SUPER_TYPES] fun resolveMe(): R|kotlin/Unit| { LAZY_BLOCK } TYPES: FILE: annotations.kt - @FILE:Suppress(String(1)) - @R|kotlin/Suppress|(String(2)) public? final? [TYPES] fun resolveMe(): R|kotlin/Unit| { LAZY_BLOCK } + @FILE:Suppress(LAZY_EXPRESSION) + @R|kotlin/Suppress|(LAZY_EXPRESSION) public? final? [TYPES] fun resolveMe(): R|kotlin/Unit| { LAZY_BLOCK } STATUS: FILE: annotations.kt - @FILE:Suppress(String(1)) - @R|kotlin/Suppress|(String(2)) public final [STATUS] fun resolveMe(): R|kotlin/Unit| { LAZY_BLOCK } + @FILE:Suppress(LAZY_EXPRESSION) + @R|kotlin/Suppress|(LAZY_EXPRESSION) public final [STATUS] fun resolveMe(): R|kotlin/Unit| { LAZY_BLOCK } ARGUMENTS_OF_ANNOTATIONS: FILE: annotations.kt - @FILE:Suppress(String(1)) + @FILE:Suppress(LAZY_EXPRESSION) @R|kotlin/Suppress|(String(2)) public final [ARGUMENTS_OF_ANNOTATIONS] fun resolveMe(): R|kotlin/Unit| { LAZY_BLOCK } CONTRACTS: FILE: annotations.kt - @FILE:Suppress(String(1)) + @FILE:Suppress(LAZY_EXPRESSION) @R|kotlin/Suppress|(String(2)) public final [CONTRACTS] fun resolveMe(): R|kotlin/Unit| { } IMPLICIT_TYPES_BODY_RESOLVE: FILE: annotations.kt - @FILE:Suppress(String(1)) + @FILE:Suppress(LAZY_EXPRESSION) @R|kotlin/Suppress|(String(2)) public final [IMPLICIT_TYPES_BODY_RESOLVE] fun resolveMe(): R|kotlin/Unit| { } diff --git a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt index 4ed44fb6cf8..c407fac4cf3 100644 --- a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt +++ b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt @@ -82,6 +82,10 @@ open class RawFirBuilder( return file.accept(Visitor(), Unit) as FirFile } + fun buildAnnotationCall(annotation: KtAnnotationEntry): FirAnnotationCall { + return Visitor().visitAnnotationEntry(annotation, Unit) as FirAnnotationCall + } + fun buildTypeReference(reference: KtTypeReference): FirTypeRef { return reference.accept(Visitor(), Unit) as FirTypeRef } @@ -817,7 +821,8 @@ open class RawFirBuilder( val argumentList = buildArgumentList { source = valueArgumentList?.toFirSourceElement() for (argument in valueArguments) { - val argumentExpression = disabledLazyMode { argument.toFirExpression() } + val argumentExpression = + buildOrLazyExpression((argument as? PsiElement)?.toFirSourceElement()) { argument.toFirExpression() } arguments += when (argument) { is KtLambdaArgument -> buildLambdaArgumentExpression { source = argument.toFirSourceElement() @@ -853,7 +858,8 @@ open class RawFirBuilder( } is KtDelegatedSuperTypeEntry -> { val type = superTypeListEntry.typeReference.toFirOrErrorType() - val delegateExpression = { superTypeListEntry.delegateExpression }.toFirExpression("Should have delegate") + val delegateExpression = + disabledLazyMode { { superTypeListEntry.delegateExpression }.toFirExpression("Should have delegate") } container.superTypeRefs += type val delegateSource = superTypeListEntry.delegateExpression?.toFirSourceElement(KtFakeSourceElementKind.ClassDelegationField) @@ -964,7 +970,7 @@ open class RawFirBuilder( ?: this@buildDelegatedConstructorCall.source?.fakeElement(KtFakeSourceElementKind.DelegatingConstructorCall) superTypeRef = this@buildDelegatedConstructorCall.constructedTypeRef } - superTypeCallEntry?.extractArgumentsTo(this) + disabledLazyMode { superTypeCallEntry?.extractArgumentsTo(this) } } } if (this == null && owner !is KtEnumEntry) { @@ -1693,7 +1699,7 @@ open class RawFirBuilder( this.superTypeRef = this@buildDelegatedConstructorCall.constructedTypeRef } } - extractArgumentsTo(this) + disabledLazyMode { extractArgumentsTo(this) } } } diff --git a/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/annotation.lazyBodies.txt b/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/annotation.lazyBodies.txt index c0c487e46ec..b4d072d51f5 100644 --- a/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/annotation.lazyBodies.txt +++ b/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/annotation.lazyBodies.txt @@ -1,5 +1,5 @@ FILE: annotation.kt - @Target(AnnotationTarget#.CLASS#, AnnotationTarget#.PROPERTY#, AnnotationTarget#.LOCAL_VARIABLE#, AnnotationTarget#.VALUE_PARAMETER#, AnnotationTarget#.CONSTRUCTOR#, AnnotationTarget#.FUNCTION#, AnnotationTarget#.TYPE#) public? final? annotation class base : R|kotlin/Annotation| { + @Target(LAZY_EXPRESSION, LAZY_EXPRESSION, LAZY_EXPRESSION, LAZY_EXPRESSION, LAZY_EXPRESSION, LAZY_EXPRESSION, LAZY_EXPRESSION) public? final? annotation class base : R|kotlin/Annotation| { public? constructor(): R|base| { super() } diff --git a/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/annotationsOnNullableParenthesizedTypes.lazyBodies.txt b/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/annotationsOnNullableParenthesizedTypes.lazyBodies.txt index 0c2921469c0..3ceaba69952 100644 --- a/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/annotationsOnNullableParenthesizedTypes.lazyBodies.txt +++ b/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/annotationsOnNullableParenthesizedTypes.lazyBodies.txt @@ -25,7 +25,7 @@ FILE: annotationsOnNullableParenthesizedTypes.kt public? get(): ( @A() C?.() -> C ) } - @Target(AnnotationTarget#.TYPE#, AnnotationTarget#.TYPE_PARAMETER#) public? final? annotation class A : R|kotlin/Annotation| { + @Target(LAZY_EXPRESSION, LAZY_EXPRESSION) public? final? annotation class A : R|kotlin/Annotation| { public? constructor(): R|A| { super() } diff --git a/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/annotationsOnParenthesizedTypes.lazyBodies.txt b/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/annotationsOnParenthesizedTypes.lazyBodies.txt index 5c88652d134..95f84ee72a2 100644 --- a/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/annotationsOnParenthesizedTypes.lazyBodies.txt +++ b/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/annotationsOnParenthesizedTypes.lazyBodies.txt @@ -28,7 +28,7 @@ FILE: annotationsOnParenthesizedTypes.kt public? get(): ( (@A() C) -> C ) } - @Target(AnnotationTarget#.TYPE#, AnnotationTarget#.TYPE_PARAMETER#) public? final? annotation class A : R|kotlin/Annotation| { + @Target(LAZY_EXPRESSION, LAZY_EXPRESSION) public? final? annotation class A : R|kotlin/Annotation| { public? constructor(): R|A| { super() } diff --git a/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/danglingAnnotationsClassLevel.lazyBodies.txt b/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/danglingAnnotationsClassLevel.lazyBodies.txt index 2c1c255872d..0c35ed5dc75 100644 --- a/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/danglingAnnotationsClassLevel.lazyBodies.txt +++ b/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/danglingAnnotationsClassLevel.lazyBodies.txt @@ -4,14 +4,14 @@ FILE: danglingAnnotationsClassLevel.kt super() } - @Suppress(String()) @MustBeDocumented() + @Suppress(LAZY_EXPRESSION) @MustBeDocumented() } public? final? class B : R|kotlin/Any| { public? constructor(): R|B| { super() } - @Suppress(String()) @MustBeDocumented() + @Suppress(LAZY_EXPRESSION) @MustBeDocumented() } public? final? class Outer : R|kotlin/Any| { public? constructor(): R|Outer| { @@ -23,7 +23,7 @@ FILE: danglingAnnotationsClassLevel.kt super() } - @Suppress(String()) @MustBeDocumented() + @Suppress(LAZY_EXPRESSION) @MustBeDocumented() } public? final? fun withLocal(): R|kotlin/Unit| { LAZY_BLOCK } diff --git a/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/danglingAnnotationsFileLevel.lazyBodies.txt b/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/danglingAnnotationsFileLevel.lazyBodies.txt index fb90000b5be..d29e77d35ff 100644 --- a/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/danglingAnnotationsFileLevel.lazyBodies.txt +++ b/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/danglingAnnotationsFileLevel.lazyBodies.txt @@ -1,2 +1,2 @@ FILE: danglingAnnotationsFileLevel.kt - @Suppress(String()) @MustBeDocumented() \ No newline at end of file + @Suppress(LAZY_EXPRESSION) @MustBeDocumented() \ No newline at end of file diff --git a/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/splitModifierList.lazyBodies.txt b/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/splitModifierList.lazyBodies.txt index 9660b9389f4..f26317035c9 100644 --- a/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/splitModifierList.lazyBodies.txt +++ b/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/splitModifierList.lazyBodies.txt @@ -1,11 +1,11 @@ FILE: splitModifierList.kt - @Target(AnnotationTarget#.TYPE#, AnnotationTarget#.TYPE_PARAMETER#) public? final? annotation class A : R|kotlin/Annotation| { + @Target(LAZY_EXPRESSION, LAZY_EXPRESSION) public? final? annotation class A : R|kotlin/Annotation| { public? constructor(): R|A| { super() } } - @Target(AnnotationTarget#.TYPE#, AnnotationTarget#.TYPE_PARAMETER#) public? final? annotation class B : R|kotlin/Annotation| { + @Target(LAZY_EXPRESSION, LAZY_EXPRESSION) public? final? annotation class B : R|kotlin/Annotation| { public? constructor(): R|B| { super() } diff --git a/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/expressions/annotated.lazyBodies.txt b/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/expressions/annotated.lazyBodies.txt index 027f59869a1..76095407a38 100644 --- a/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/expressions/annotated.lazyBodies.txt +++ b/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/expressions/annotated.lazyBodies.txt @@ -1,5 +1,5 @@ FILE: annotated.kt - @Target(AnnotationTarget#.EXPRESSION#, AnnotationTarget#.LOCAL_VARIABLE#) @Retention(AnnotationRetention#.SOURCE#) public? final? annotation class Ann : R|kotlin/Annotation| { + @Target(LAZY_EXPRESSION, LAZY_EXPRESSION) @Retention(LAZY_EXPRESSION) public? final? annotation class Ann : R|kotlin/Annotation| { public? constructor(): R|Ann| { super() } diff --git a/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/expressions/collectionLiterals.lazyBodies.txt b/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/expressions/collectionLiterals.lazyBodies.txt index 28b30fcbf46..eb03c90ced1 100644 --- a/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/expressions/collectionLiterals.lazyBodies.txt +++ b/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/expressions/collectionLiterals.lazyBodies.txt @@ -26,25 +26,25 @@ FILE: collectionLiterals.kt public? get(): Array } - @Ann1(()) @Ann2(()) @Ann3(()) public? final? class Zero : R|kotlin/Any| { + @Ann1(LAZY_EXPRESSION) @Ann2(LAZY_EXPRESSION) @Ann3(LAZY_EXPRESSION) public? final? class Zero : R|kotlin/Any| { public? constructor(): R|Zero| { super() } } - @Ann1((IntegerLiteral(1), IntegerLiteral(2))) public? final? class First : R|kotlin/Any| { + @Ann1(LAZY_EXPRESSION) public? final? class First : R|kotlin/Any| { public? constructor(): R|First| { super() } } - @Ann2((Double(3.14))) public? final? class Second : R|kotlin/Any| { + @Ann2(LAZY_EXPRESSION) public? final? class Second : R|kotlin/Any| { public? constructor(): R|Second| { super() } } - @Ann3((String(Alpha), String(Omega))) public? final? class Third : R|kotlin/Any| { + @Ann3(LAZY_EXPRESSION) public? final? class Third : R|kotlin/Any| { public? constructor(): R|Third| { super() }