[FIR] Add FirSession as parameter for FirTotalResolveTransformer
This commit is contained in:
@@ -164,7 +164,7 @@ abstract class AbstractSimpleFileBenchmark {
|
|||||||
val firProvider = session.firProvider as FirProviderImpl
|
val firProvider = session.firProvider as FirProviderImpl
|
||||||
val builder = RawFirBuilder(session, firProvider.kotlinScopeProvider, stubMode = false)
|
val builder = RawFirBuilder(session, firProvider.kotlinScopeProvider, stubMode = false)
|
||||||
|
|
||||||
val totalTransformer = FirTotalResolveTransformer()
|
val totalTransformer = FirTotalResolveTransformer(session)
|
||||||
val firFile = builder.buildFirFile(file).also(firProvider::recordFile)
|
val firFile = builder.buildFirFile(file).also(firProvider::recordFile)
|
||||||
|
|
||||||
for (transformer in totalTransformer.transformers) {
|
for (transformer in totalTransformer.transformers) {
|
||||||
|
|||||||
+1
-1
@@ -331,7 +331,7 @@ object KotlinToJVMBytecodeCompiler {
|
|||||||
}
|
}
|
||||||
val firProvider = (session.firProvider as FirProviderImpl)
|
val firProvider = (session.firProvider as FirProviderImpl)
|
||||||
val builder = RawFirBuilder(session, firProvider.kotlinScopeProvider, stubMode = false)
|
val builder = RawFirBuilder(session, firProvider.kotlinScopeProvider, stubMode = false)
|
||||||
val resolveTransformer = FirTotalResolveTransformer()
|
val resolveTransformer = FirTotalResolveTransformer(session)
|
||||||
val firFiles = ktFiles.map {
|
val firFiles = ktFiles.map {
|
||||||
val firFile = builder.buildFirFile(it)
|
val firFile = builder.buildFirFile(it)
|
||||||
firProvider.recordFile(firFile)
|
firProvider.recordFile(firFile)
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ abstract class AbstractFir2IrTextTest : AbstractIrTextTestCase() {
|
|||||||
val firProvider = (session.firProvider as FirProviderImpl)
|
val firProvider = (session.firProvider as FirProviderImpl)
|
||||||
val builder = RawFirBuilder(session, firProvider.kotlinScopeProvider, stubMode = false)
|
val builder = RawFirBuilder(session, firProvider.kotlinScopeProvider, stubMode = false)
|
||||||
|
|
||||||
val resolveTransformer = FirTotalResolveTransformer()
|
val resolveTransformer = FirTotalResolveTransformer(session)
|
||||||
val firFiles = psiFiles.map {
|
val firFiles = psiFiles.map {
|
||||||
val firFile = builder.buildFirFile(it)
|
val firFile = builder.buildFirFile(it)
|
||||||
firProvider.recordFile(firFile)
|
firProvider.recordFile(firFile)
|
||||||
|
|||||||
+1
-1
@@ -55,7 +55,7 @@ class FirResolveModularizedTotalKotlinTest : AbstractModularizedTest() {
|
|||||||
.uniteWith(TopDownAnalyzerFacadeForJVM.AllJavaSourcesInProjectScope(project))
|
.uniteWith(TopDownAnalyzerFacadeForJVM.AllJavaSourcesInProjectScope(project))
|
||||||
val librariesScope = ProjectScope.getLibrariesScope(project)
|
val librariesScope = ProjectScope.getLibrariesScope(project)
|
||||||
val session = createSession(environment, scope, librariesScope, moduleData.qualifiedName)
|
val session = createSession(environment, scope, librariesScope, moduleData.qualifiedName)
|
||||||
val totalTransformer = FirTotalResolveTransformer()
|
val totalTransformer = FirTotalResolveTransformer(session)
|
||||||
|
|
||||||
val firProvider = session.firProvider as FirProviderImpl
|
val firProvider = session.firProvider as FirProviderImpl
|
||||||
val firFiles = if (useLightTree) {
|
val firFiles = if (useLightTree) {
|
||||||
|
|||||||
+1
-1
@@ -52,7 +52,7 @@ fun FirFile.runResolve(toPhase: FirResolvePhase, fromPhase: FirResolvePhase = Fi
|
|||||||
var currentPhase = fromPhase
|
var currentPhase = fromPhase
|
||||||
while (currentPhase < toPhase) {
|
while (currentPhase < toPhase) {
|
||||||
currentPhase = currentPhase.next
|
currentPhase = currentPhase.next
|
||||||
val phaseTransformer = currentPhase.createTransformerByPhase(scopeSession)
|
val phaseTransformer = currentPhase.createTransformerByPhase(session, scopeSession)
|
||||||
transform<FirFile, Nothing?>(phaseTransformer, null)
|
transform<FirFile, Nothing?>(phaseTransformer, null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-4
@@ -5,20 +5,19 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.fir.resolve.transformers
|
package org.jetbrains.kotlin.fir.resolve.transformers
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.fir.FirSession
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirFile
|
import org.jetbrains.kotlin.fir.declarations.FirFile
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||||
import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
||||||
import org.jetbrains.kotlin.fir.visitors.FirTransformer
|
import org.jetbrains.kotlin.fir.visitors.FirTransformer
|
||||||
|
|
||||||
// TODO: rework, see rr/FIR/semoro-dev FirStagesTransformerFactory
|
class FirTotalResolveTransformer(session: FirSession) {
|
||||||
class FirTotalResolveTransformer {
|
|
||||||
|
|
||||||
val scopeSession = ScopeSession()
|
val scopeSession = ScopeSession()
|
||||||
|
|
||||||
val transformers: List<FirTransformer<Nothing?>> =
|
val transformers: List<FirTransformer<Nothing?>> =
|
||||||
FirResolvePhase.values()
|
FirResolvePhase.values()
|
||||||
.drop(1) // to remove RAW_FIR phase
|
.drop(1) // to remove RAW_FIR phase
|
||||||
.map { it.createTransformerByPhase(scopeSession) }
|
.map { it.createTransformerByPhase(session, scopeSession) }
|
||||||
|
|
||||||
fun processFiles(files: List<FirFile>) {
|
fun processFiles(files: List<FirFile>) {
|
||||||
for (transformer in transformers) {
|
for (transformer in transformers) {
|
||||||
|
|||||||
+2
-1
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.fir.resolve.transformers
|
package org.jetbrains.kotlin.fir.resolve.transformers
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.fir.FirSession
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase.*
|
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase.*
|
||||||
import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
||||||
@@ -17,7 +18,7 @@ import org.jetbrains.kotlin.fir.visitors.FirTransformer
|
|||||||
|
|
||||||
// TODO: add FirSession parameter
|
// TODO: add FirSession parameter
|
||||||
@OptIn(AdapterForResolvePhase::class)
|
@OptIn(AdapterForResolvePhase::class)
|
||||||
fun FirResolvePhase.createTransformerByPhase(scopeSession: ScopeSession): FirTransformer<Nothing?> {
|
fun FirResolvePhase.createTransformerByPhase(session: FirSession, scopeSession: ScopeSession): FirTransformer<Nothing?> {
|
||||||
return when (this) {
|
return when (this) {
|
||||||
RAW_FIR -> throw AssertionError("Raw FIR building phase does not have a transformer")
|
RAW_FIR -> throw AssertionError("Raw FIR building phase does not have a transformer")
|
||||||
ANNOTATIONS_FOR_PLUGINS -> FirPluginAnnotationsResolveTransformer(scopeSession)
|
ANNOTATIONS_FOR_PLUGINS -> FirPluginAnnotationsResolveTransformer(scopeSession)
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ object GenerationUtils {
|
|||||||
|
|
||||||
val firProvider = (session.firProvider as FirProviderImpl)
|
val firProvider = (session.firProvider as FirProviderImpl)
|
||||||
val builder = RawFirBuilder(session, firProvider.kotlinScopeProvider, stubMode = false)
|
val builder = RawFirBuilder(session, firProvider.kotlinScopeProvider, stubMode = false)
|
||||||
val resolveTransformer = FirTotalResolveTransformer()
|
val resolveTransformer = FirTotalResolveTransformer(session)
|
||||||
val firFiles = files.map {
|
val firFiles = files.map {
|
||||||
val firFile = builder.buildFirFile(it)
|
val firFile = builder.buildFirFile(it)
|
||||||
firProvider.recordFile(firFile)
|
firProvider.recordFile(firFile)
|
||||||
|
|||||||
@@ -73,10 +73,10 @@ abstract class AbstractFirDiagnosticsTest : AbstractFirBaseDiagnosticsTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun runAnalysis(testDataFile: File, testFiles: List<TestFile>, firFilesPerSession: Map<FirSession, List<FirFile>>) {
|
override fun runAnalysis(testDataFile: File, testFiles: List<TestFile>, firFilesPerSession: Map<FirSession, List<FirFile>>) {
|
||||||
for ((_, firFiles) in firFilesPerSession) {
|
for ((session, firFiles) in firFilesPerSession) {
|
||||||
doFirResolveTestBench(
|
doFirResolveTestBench(
|
||||||
firFiles,
|
firFiles,
|
||||||
FirTotalResolveTransformer().transformers,
|
FirTotalResolveTransformer(session).transformers,
|
||||||
gc = false
|
gc = false
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -31,8 +31,8 @@ abstract class AbstractFirOldFrontendDiagnosticsTest : AbstractFirDiagnosticsTes
|
|||||||
|
|
||||||
override fun runAnalysis(testDataFile: File, testFiles: List<TestFile>, firFilesPerSession: Map<FirSession, List<FirFile>>) {
|
override fun runAnalysis(testDataFile: File, testFiles: List<TestFile>, firFilesPerSession: Map<FirSession, List<FirFile>>) {
|
||||||
val failure: FirRuntimeException? = try {
|
val failure: FirRuntimeException? = try {
|
||||||
for ((_, firFiles) in firFilesPerSession) {
|
for ((session, firFiles) in firFilesPerSession) {
|
||||||
doFirResolveTestBench(firFiles, FirTotalResolveTransformer().transformers, gc = false)
|
doFirResolveTestBench(firFiles, FirTotalResolveTransformer(session).transformers, gc = false)
|
||||||
}
|
}
|
||||||
null
|
null
|
||||||
} catch (e: FirRuntimeException) {
|
} catch (e: FirRuntimeException) {
|
||||||
|
|||||||
+1
-1
@@ -37,7 +37,7 @@ abstract class AbstractFirVisualizer : AbstractVisualizer() {
|
|||||||
val firProvider = (session.firProvider as FirProviderImpl)
|
val firProvider = (session.firProvider as FirProviderImpl)
|
||||||
val builder = RawFirBuilder(session, firProvider.kotlinScopeProvider, stubMode = false)
|
val builder = RawFirBuilder(session, firProvider.kotlinScopeProvider, stubMode = false)
|
||||||
|
|
||||||
val transformer = FirTotalResolveTransformer()
|
val transformer = FirTotalResolveTransformer(session)
|
||||||
val firFiles = ktFiles.map {
|
val firFiles = ktFiles.map {
|
||||||
val firFile = builder.buildFirFile(it)
|
val firFile = builder.buildFirFile(it)
|
||||||
firProvider.recordFile(firFile)
|
firProvider.recordFile(firFile)
|
||||||
|
|||||||
+1
-1
@@ -115,7 +115,7 @@ abstract class AbstractFirMultiModuleResolveTest : AbstractMultiModuleTest() {
|
|||||||
firFiles += firFile
|
firFiles += firFile
|
||||||
}
|
}
|
||||||
firFilesPerSession[session] = firFiles
|
firFilesPerSession[session] = firFiles
|
||||||
totalTransformerPerSession[session] = FirTotalResolveTransformer()
|
totalTransformerPerSession[session] = FirTotalResolveTransformer(session)
|
||||||
}
|
}
|
||||||
println("Raw fir up, files: ${firFilesPerSession.values.flatten().size}")
|
println("Raw fir up, files: ${firFilesPerSession.values.flatten().size}")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user