[K2] Add new resolve phase CONSTANT_EVALUATION

During this phase, the compiler will evaluate initializers of
const properties and defaults of annotation's constructor.
Evaluation results will be stored in corresponding attributes.

#KT-64151
This commit is contained in:
Ivan Kylchik
2024-02-29 13:25:43 +01:00
committed by Space Team
parent b157a8eae5
commit ada47eb110
7 changed files with 74 additions and 0 deletions
@@ -0,0 +1,33 @@
/*
* 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.fir.resolve.transformers
import org.jetbrains.kotlin.fir.FirElement
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.declarations.FirFile
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
import org.jetbrains.kotlin.fir.resolve.ScopeSession
import org.jetbrains.kotlin.fir.visitors.FirTransformer
@OptIn(AdapterForResolveProcessor::class)
class FirConstantEvaluationProcessor(
session: FirSession,
scopeSession: ScopeSession
) : FirTransformerBasedResolveProcessor(session, scopeSession, FirResolvePhase.CONSTANT_EVALUATION) {
override val transformer = FirConstantEvaluationTransformerAdapter(session, scopeSession)
}
@Suppress("UNUSED_PARAMETER")
@AdapterForResolveProcessor
class FirConstantEvaluationTransformerAdapter(session: FirSession, scopeSession: ScopeSession) : FirTransformer<Any?>() {
override fun <E : FirElement> transformElement(element: E, data: Any?): E {
error("Should only be called via transformFile()")
}
override fun transformFile(file: FirFile, data: Any?): FirFile {
return file
}
}
@@ -85,6 +85,7 @@ fun FirResolvePhase.createCompilerProcessorByPhase(
STATUS -> FirStatusResolveProcessor(session, scopeSession)
CONTRACTS -> FirContractResolveProcessor(session, scopeSession)
IMPLICIT_TYPES_BODY_RESOLVE -> FirImplicitTypeBodyResolveProcessor(session, scopeSession)
CONSTANT_EVALUATION -> FirConstantEvaluationProcessor(session, scopeSession)
ANNOTATION_ARGUMENTS -> FirAnnotationArgumentsProcessor(session, scopeSession)
BODY_RESOLVE -> FirBodyResolveProcessor(session, scopeSession)
EXPECT_ACTUAL_MATCHING -> FirExpectActualMatcherProcessor(session, scopeSession)
@@ -178,6 +178,11 @@ enum class FirResolvePhase(val noProcessor: Boolean = false) {
*/
IMPLICIT_TYPES_BODY_RESOLVE,
/**
* The compiler evaluates expressions that are used as initializers for const properties and defaults of annotation's constructor.
*/
CONSTANT_EVALUATION,
/**
* The compiler resolves arguments of annotations in declaration headers.
*/