IR: remove SourceManager, make PsiSourceManager a singleton
This commit is contained in:
+6
-7
@@ -354,7 +354,7 @@ object KotlinToJVMBytecodeCompiler {
|
||||
|
||||
performanceManager?.notifyIRTranslationStarted()
|
||||
val extensions = JvmGeneratorExtensions()
|
||||
val (moduleFragment, symbolTable, sourceManager, components) = firAnalyzerFacade.convertToIr(extensions)
|
||||
val (moduleFragment, symbolTable, components) = firAnalyzerFacade.convertToIr(extensions)
|
||||
|
||||
performanceManager?.notifyIRTranslationFinished()
|
||||
|
||||
@@ -390,12 +390,11 @@ object KotlinToJVMBytecodeCompiler {
|
||||
performanceManager?.notifyIRLoweringStarted()
|
||||
generationState.beforeCompile()
|
||||
codegenFactory.generateModuleInFrontendIRMode(
|
||||
generationState, moduleFragment, symbolTable, sourceManager, extensions, FirJvmBackendExtension(session, components),
|
||||
{
|
||||
performanceManager?.notifyIRLoweringFinished()
|
||||
performanceManager?.notifyIRGenerationStarted()
|
||||
}
|
||||
)
|
||||
generationState, moduleFragment, symbolTable, extensions, FirJvmBackendExtension(session, components)
|
||||
) {
|
||||
performanceManager?.notifyIRLoweringFinished()
|
||||
performanceManager?.notifyIRGenerationStarted()
|
||||
}
|
||||
CodegenFactory.doCheckCancelled(generationState)
|
||||
generationState.factory.done()
|
||||
|
||||
|
||||
@@ -36,7 +36,6 @@ import org.jetbrains.kotlin.psi2ir.generators.generateTypicalIrProviderList
|
||||
|
||||
class Fir2IrConverter(
|
||||
private val moduleDescriptor: FirModuleDescriptor,
|
||||
private val sourceManager: PsiSourceManager,
|
||||
private val components: Fir2IrComponents
|
||||
) : Fir2IrComponents by components {
|
||||
|
||||
@@ -58,7 +57,7 @@ class Fir2IrConverter(
|
||||
|
||||
fun registerFileAndClasses(file: FirFile): IrFile {
|
||||
val irFile = IrFileImpl(
|
||||
sourceManager.getOrCreateFileEntry(file.psi as KtFile),
|
||||
PsiSourceManager.PsiFileEntry(file.psi as KtFile),
|
||||
moduleDescriptor.getPackage(file.packageFqName).fragments.first()
|
||||
)
|
||||
declarationStorage.registerFile(file, irFile)
|
||||
@@ -265,11 +264,10 @@ class Fir2IrConverter(
|
||||
TypeTranslatorImpl(symbolTable, languageVersionSettings, moduleDescriptor, extensions = generatorExtensions)
|
||||
val irBuiltIns = IrBuiltIns(moduleDescriptor.builtIns, typeTranslator, symbolTable)
|
||||
FirBuiltinSymbols(irBuiltIns, moduleDescriptor.builtIns, symbolTable)
|
||||
val sourceManager = PsiSourceManager()
|
||||
val components = Fir2IrComponentsStorage(session, scopeSession, symbolTable, irBuiltIns, irFactory, mangler)
|
||||
val conversionScope = Fir2IrConversionScope()
|
||||
val classifierStorage = Fir2IrClassifierStorage(components)
|
||||
val converter = Fir2IrConverter(moduleDescriptor, sourceManager, components)
|
||||
val converter = Fir2IrConverter(moduleDescriptor, components)
|
||||
val fir2irVisitor = Fir2IrVisitor(converter, components, conversionScope)
|
||||
val declarationStorage = Fir2IrDeclarationStorage(components, moduleDescriptor)
|
||||
val typeConverter = Fir2IrTypeConverter(components)
|
||||
@@ -308,9 +306,7 @@ class Fir2IrConverter(
|
||||
}
|
||||
|
||||
for (firFile in firFiles) {
|
||||
val irFile = firFile.accept(fir2irVisitor, null) as IrFile
|
||||
val fileEntry = sourceManager.getOrCreateFileEntry(firFile.psi as KtFile)
|
||||
sourceManager.putFileEntry(irFile, fileEntry)
|
||||
firFile.accept(fir2irVisitor, null)
|
||||
}
|
||||
|
||||
externalDependenciesGenerator.generateUnboundSymbolsAsDependencies()
|
||||
@@ -319,7 +315,7 @@ class Fir2IrConverter(
|
||||
|
||||
evaluateConstants(irModuleFragment)
|
||||
|
||||
return Fir2IrResult(irModuleFragment, symbolTable, sourceManager, components)
|
||||
return Fir2IrResult(irModuleFragment, symbolTable, components)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,5 @@ package org.jetbrains.kotlin.fir.backend
|
||||
|
||||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
||||
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||
import org.jetbrains.kotlin.psi2ir.PsiSourceManager
|
||||
|
||||
data class Fir2IrResult(val irModuleFragment: IrModuleFragment, val symbolTable: SymbolTable, val sourceManager: PsiSourceManager, val components: Fir2IrComponents)
|
||||
data class Fir2IrResult(val irModuleFragment: IrModuleFragment, val symbolTable: SymbolTable, val components: Fir2IrComponents)
|
||||
|
||||
@@ -77,7 +77,7 @@ class JsIrBackendContext(
|
||||
private val internalPackageFragmentDescriptor = EmptyPackageFragmentDescriptor(builtIns.builtInsModule, FqName("kotlin.js.internal"))
|
||||
|
||||
private fun syntheticFile(name: String, module: IrModuleFragment): IrFile {
|
||||
return IrFileImpl(object : SourceManager.FileEntry {
|
||||
return IrFileImpl(object : IrFileEntry {
|
||||
override val name = "<$name>"
|
||||
override val maxOffset = UNDEFINED_OFFSET
|
||||
|
||||
|
||||
@@ -11,7 +11,10 @@ import org.jetbrains.kotlin.backend.common.Mapping
|
||||
import org.jetbrains.kotlin.backend.common.ir.Ir
|
||||
import org.jetbrains.kotlin.backend.common.lower.irThrow
|
||||
import org.jetbrains.kotlin.backend.common.phaser.PhaseConfig
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.*
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.ClassCodegen
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.IrTypeMapper
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.MethodSignatureMapper
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.createFakeContinuation
|
||||
import org.jetbrains.kotlin.backend.jvm.descriptors.JvmSharedVariablesManager
|
||||
import org.jetbrains.kotlin.backend.jvm.intrinsics.IrIntrinsicMethods
|
||||
import org.jetbrains.kotlin.backend.jvm.lower.BridgeLowering
|
||||
@@ -36,14 +39,12 @@ import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.psi2ir.PsiErrorBuilder
|
||||
import org.jetbrains.kotlin.psi2ir.PsiSourceManager
|
||||
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
|
||||
import org.jetbrains.org.objectweb.asm.Type
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
class JvmBackendContext(
|
||||
val state: GenerationState,
|
||||
val psiSourceManager: PsiSourceManager,
|
||||
override val irBuiltIns: IrBuiltIns,
|
||||
irModuleFragment: IrModuleFragment,
|
||||
private val symbolTable: SymbolTable,
|
||||
@@ -69,7 +70,7 @@ class JvmBackendContext(
|
||||
|
||||
override val mapping: Mapping = DefaultMapping()
|
||||
|
||||
val psiErrorBuilder = PsiErrorBuilder(psiSourceManager, state.diagnostics)
|
||||
val psiErrorBuilder = PsiErrorBuilder(state.diagnostics)
|
||||
|
||||
override val ir = JvmIr(irModuleFragment, this.symbolTable)
|
||||
|
||||
@@ -158,14 +159,6 @@ class JvmBackendContext(
|
||||
classSymbolMap: MutableMap<IrClassSymbol, IrClassSymbol>,
|
||||
functionSymbolMap: MutableMap<IrSimpleFunctionSymbol, IrSimpleFunctionSymbol>
|
||||
) {
|
||||
for ((oldFileSymbol, newFileSymbol) in fileSymbolMap) {
|
||||
val psiFileEntry = psiSourceManager.getFileEntry(oldFileSymbol.owner) as? PsiSourceManager.PsiFileEntry ?: continue
|
||||
psiSourceManager.putFileEntry(
|
||||
newFileSymbol.owner,
|
||||
psiFileEntry
|
||||
)
|
||||
}
|
||||
|
||||
val oldClassesWithNameOverride = classNameOverride.keys.toList()
|
||||
for (klass in oldClassesWithNameOverride) {
|
||||
classSymbolMap[klass.symbol]?.let { newSymbol ->
|
||||
|
||||
+9
-11
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.backend.common.extensions.IrPluginContextImpl
|
||||
import org.jetbrains.kotlin.backend.common.ir.BuiltinSymbolsBase
|
||||
import org.jetbrains.kotlin.backend.common.phaser.PhaseConfig
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.ClassCodegen
|
||||
import org.jetbrains.kotlin.backend.jvm.ir.getKtFile
|
||||
import org.jetbrains.kotlin.backend.jvm.lower.MultifileFacadeFileEntry
|
||||
import org.jetbrains.kotlin.backend.jvm.serialization.JvmIdSignatureDescriptor
|
||||
import org.jetbrains.kotlin.codegen.CodegenFactory
|
||||
@@ -25,6 +26,7 @@ import org.jetbrains.kotlin.ir.backend.jvm.serialization.JvmIrLinker
|
||||
import org.jetbrains.kotlin.ir.backend.jvm.serialization.JvmManglerDesc
|
||||
import org.jetbrains.kotlin.ir.builders.TranslationPluginContext
|
||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl
|
||||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
||||
@@ -35,7 +37,6 @@ import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi2ir.Psi2IrConfiguration
|
||||
import org.jetbrains.kotlin.psi2ir.Psi2IrTranslator
|
||||
import org.jetbrains.kotlin.psi2ir.PsiSourceManager
|
||||
import org.jetbrains.kotlin.psi2ir.generators.DeclarationStubGeneratorImpl
|
||||
import org.jetbrains.kotlin.psi2ir.generators.generateTypicalIrProviderList
|
||||
import org.jetbrains.kotlin.resolve.CleanableBindingContext
|
||||
@@ -45,7 +46,6 @@ class JvmIrCodegenFactory(private val phaseConfig: PhaseConfig) : CodegenFactory
|
||||
val state: GenerationState,
|
||||
val irModuleFragment: IrModuleFragment,
|
||||
val symbolTable: SymbolTable,
|
||||
val sourceManager: PsiSourceManager,
|
||||
val phaseConfig: PhaseConfig,
|
||||
val irProviders: List<IrProvider>,
|
||||
val extensions: JvmGeneratorExtensions,
|
||||
@@ -152,13 +152,11 @@ class JvmIrCodegenFactory(private val phaseConfig: PhaseConfig) : CodegenFactory
|
||||
state,
|
||||
irModuleFragment,
|
||||
symbolTable,
|
||||
psi2irContext.sourceManager,
|
||||
phaseConfig,
|
||||
irProviders,
|
||||
extensions,
|
||||
JvmBackendExtension.Default,
|
||||
{},
|
||||
)
|
||||
) {}
|
||||
}
|
||||
|
||||
private fun ModuleDescriptor.collectAllDependencyModulesTransitively(): List<ModuleDescriptor> {
|
||||
@@ -173,10 +171,9 @@ class JvmIrCodegenFactory(private val phaseConfig: PhaseConfig) : CodegenFactory
|
||||
}
|
||||
|
||||
fun doGenerateFilesInternal(input: JvmIrBackendInput) {
|
||||
val (state, irModuleFragment, symbolTable, sourceManager, phaseConfig, irProviders, extensions, backendExtension, notifyCodegenStart) = input
|
||||
val (state, irModuleFragment, symbolTable, phaseConfig, irProviders, extensions, backendExtension, notifyCodegenStart) = input
|
||||
val context = JvmBackendContext(
|
||||
state, sourceManager, irModuleFragment.irBuiltins, irModuleFragment,
|
||||
symbolTable, phaseConfig, extensions, backendExtension
|
||||
state, irModuleFragment.irBuiltins, irModuleFragment, symbolTable, phaseConfig, extensions, backendExtension
|
||||
)
|
||||
/* JvmBackendContext creates new unbound symbols, have to resolve them. */
|
||||
ExternalDependenciesGenerator(symbolTable, irProviders).generateUnboundSymbolsAsDependencies()
|
||||
@@ -185,7 +182,7 @@ class JvmIrCodegenFactory(private val phaseConfig: PhaseConfig) : CodegenFactory
|
||||
context.typeMapper.mapType(context.referenceClass(descriptor).defaultType)
|
||||
}
|
||||
|
||||
context.state.factory.registerSourceFiles(irModuleFragment.files.map(context.psiSourceManager::getKtFile))
|
||||
context.state.factory.registerSourceFiles(irModuleFragment.files.map(IrFile::getKtFile))
|
||||
|
||||
JvmLower(context).lower(irModuleFragment)
|
||||
|
||||
@@ -220,14 +217,15 @@ class JvmIrCodegenFactory(private val phaseConfig: PhaseConfig) : CodegenFactory
|
||||
state: GenerationState,
|
||||
irModuleFragment: IrModuleFragment,
|
||||
symbolTable: SymbolTable,
|
||||
sourceManager: PsiSourceManager,
|
||||
extensions: JvmGeneratorExtensions,
|
||||
backendExtension: JvmBackendExtension,
|
||||
notifyCodegenStart: () -> Unit
|
||||
) {
|
||||
val irProviders = configureBuiltInsAndGenerateIrProvidersInFrontendIRMode(irModuleFragment, symbolTable, extensions)
|
||||
doGenerateFilesInternal(
|
||||
JvmIrBackendInput(state, irModuleFragment, symbolTable, sourceManager, phaseConfig, irProviders, extensions, backendExtension, notifyCodegenStart)
|
||||
JvmIrBackendInput(
|
||||
state, irModuleFragment, symbolTable, phaseConfig, irProviders, extensions, backendExtension, notifyCodegenStart
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+3
-2
@@ -36,6 +36,7 @@ import org.jetbrains.kotlin.load.kotlin.header.KotlinClassHeader
|
||||
import org.jetbrains.kotlin.metadata.jvm.serialization.JvmStringTable
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.protobuf.MessageLite
|
||||
import org.jetbrains.kotlin.psi2ir.PsiSourceManager
|
||||
import org.jetbrains.kotlin.resolve.jvm.annotations.JVM_RECORD_ANNOTATION_FQ_NAME
|
||||
import org.jetbrains.kotlin.resolve.jvm.annotations.JVM_SYNTHETIC_ANNOTATION_FQ_NAME
|
||||
import org.jetbrains.kotlin.resolve.jvm.annotations.TRANSIENT_ANNOTATION_FQ_NAME
|
||||
@@ -250,7 +251,7 @@ class ClassCodegen private constructor(
|
||||
if (entry is MultifileFacadeFileEntry) {
|
||||
return entry.partFiles.flatMap { it.loadSourceFilesInfo() }
|
||||
}
|
||||
return listOfNotNull(context.psiSourceManager.getFileEntry(this)?.let { File(it.name) })
|
||||
return listOf(File(entry.name))
|
||||
}
|
||||
|
||||
companion object {
|
||||
@@ -462,7 +463,7 @@ class ClassCodegen private constructor(
|
||||
|
||||
private val IrDeclaration.descriptorOrigin: JvmDeclarationOrigin
|
||||
get() {
|
||||
val psiElement = context.psiSourceManager.findPsiElement(this)
|
||||
val psiElement = PsiSourceManager.findPsiElement(this)
|
||||
// For declarations inside lambdas, produce a descriptor which refers back to the original function.
|
||||
// This is needed for plugins which check for lambdas inside of inline functions using the descriptor
|
||||
// contained in JvmDeclarationOrigin. This matches the behavior of the JVM backend.
|
||||
|
||||
+9
-12
@@ -128,7 +128,7 @@ class ExpressionCodegen(
|
||||
|
||||
val state = context.state
|
||||
|
||||
private val fileEntry = classCodegen.context.psiSourceManager.getFileEntry(irFunction.fileParent)
|
||||
private val fileEntry = irFunction.fileParent.fileEntry
|
||||
|
||||
override val visitor: InstructionAdapter
|
||||
get() = mv
|
||||
@@ -163,21 +163,18 @@ class ExpressionCodegen(
|
||||
|
||||
private fun markNewLinkedLabel() = linkedLabel().apply { mv.visitLabel(this) }
|
||||
|
||||
private fun getLineNumberForOffset(offset: Int): Int = fileEntry?.getLineNumber(offset)?.plus(1) ?: -1
|
||||
private fun getLineNumberForOffset(offset: Int): Int = fileEntry.getLineNumber(offset) + 1
|
||||
|
||||
private fun IrElement.markLineNumber(startOffset: Boolean) {
|
||||
if (noLineNumberScope) return
|
||||
val offset = if (startOffset) this.startOffset else endOffset
|
||||
if (offset < 0) {
|
||||
return
|
||||
}
|
||||
if (fileEntry != null) {
|
||||
val lineNumber = getLineNumberForOffset(offset)
|
||||
assert(lineNumber > 0)
|
||||
if (lastLineNumber != lineNumber) {
|
||||
lastLineNumber = lineNumber
|
||||
mv.visitLineNumber(lineNumber, markNewLabel())
|
||||
}
|
||||
if (offset < 0) return
|
||||
|
||||
val lineNumber = getLineNumberForOffset(offset)
|
||||
assert(lineNumber > 0)
|
||||
if (lastLineNumber != lineNumber) {
|
||||
lastLineNumber = lineNumber
|
||||
mv.visitLineNumber(lineNumber, markNewLabel())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-2
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.codegen.AsmUtil
|
||||
import org.jetbrains.kotlin.ir.descriptors.toIrBasedDescriptor
|
||||
import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression
|
||||
import org.jetbrains.kotlin.ir.util.render
|
||||
import org.jetbrains.kotlin.psi2ir.PsiSourceManager
|
||||
|
||||
interface IrInlineCallGenerator : IrCallGenerator {
|
||||
override fun genCall(
|
||||
@@ -18,8 +19,8 @@ interface IrInlineCallGenerator : IrCallGenerator {
|
||||
expression: IrFunctionAccessExpression,
|
||||
isInsideIfCondition: Boolean,
|
||||
) {
|
||||
val element = codegen.context.psiSourceManager.findPsiElement(expression, codegen.irFunction)
|
||||
?: codegen.context.psiSourceManager.findPsiElement(codegen.irFunction)
|
||||
val element = PsiSourceManager.findPsiElement(expression, codegen.irFunction)
|
||||
?: PsiSourceManager.findPsiElement(codegen.irFunction)
|
||||
if (!codegen.state.globalInlineContext.enterIntoInlining(
|
||||
expression.symbol.owner.suspendFunctionOriginal().toIrBasedDescriptor(), element)
|
||||
) {
|
||||
|
||||
+5
-3
@@ -9,6 +9,7 @@ import com.intellij.openapi.util.TextRange
|
||||
import com.intellij.psi.PsiFile
|
||||
import org.jetbrains.kotlin.backend.common.CodegenUtil
|
||||
import org.jetbrains.kotlin.backend.common.ir.ir2string
|
||||
import org.jetbrains.kotlin.backend.jvm.ir.getKtFile
|
||||
import org.jetbrains.kotlin.codegen.BaseExpressionCodegen
|
||||
import org.jetbrains.kotlin.codegen.OwnerKind
|
||||
import org.jetbrains.kotlin.codegen.inline.*
|
||||
@@ -32,7 +33,8 @@ import org.jetbrains.kotlin.psi.KtElement
|
||||
import org.jetbrains.kotlin.psi.doNotAnalyze
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm.SUSPENSION_POINT_INSIDE_MONITOR
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
|
||||
import org.jetbrains.org.objectweb.asm.*
|
||||
import org.jetbrains.org.objectweb.asm.Label
|
||||
import org.jetbrains.org.objectweb.asm.Type
|
||||
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
|
||||
import org.jetbrains.org.objectweb.asm.commons.Method
|
||||
import org.jetbrains.org.objectweb.asm.tree.MethodNode
|
||||
@@ -49,7 +51,7 @@ class IrSourceCompilerForInline(
|
||||
get() = object : LookupLocation {
|
||||
override val location: LocationInfo?
|
||||
get() {
|
||||
val ktFile = codegen.classCodegen.context.psiSourceManager.getKtFile(codegen.irFunction.fileParent)
|
||||
val ktFile = codegen.irFunction.fileParent.getKtFile()
|
||||
?.takeUnless { it.doNotAnalyze != null } ?: return null
|
||||
|
||||
return object : LocationInfo {
|
||||
@@ -68,7 +70,7 @@ class IrSourceCompilerForInline(
|
||||
get() = ir2string(callElement)
|
||||
|
||||
override val callsiteFile: PsiFile?
|
||||
get() = codegen.context.psiSourceManager.getKtFile(codegen.irFunction.fileParent)
|
||||
get() = codegen.irFunction.fileParent.getKtFile()
|
||||
|
||||
override val contextKind: OwnerKind
|
||||
get() = when (val parent = callElement.symbol.owner.parent) {
|
||||
|
||||
+3
-2
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.diagnostics.DiagnosticFactory1
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.descriptors.toIrBasedDescriptor
|
||||
import org.jetbrains.kotlin.ir.util.isFakeOverride
|
||||
import org.jetbrains.kotlin.psi2ir.PsiSourceManager
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.*
|
||||
import org.jetbrains.kotlin.utils.SmartSet
|
||||
import org.jetbrains.org.objectweb.asm.Type
|
||||
@@ -153,7 +154,7 @@ class JvmSignatureClashDetector(
|
||||
}
|
||||
}
|
||||
|
||||
private fun IrDeclaration.findPsiElement() = context.psiSourceManager.findPsiElement(this)
|
||||
private fun IrDeclaration.findPsiElement(): PsiElement? = PsiSourceManager.findPsiElement(this)
|
||||
|
||||
private fun IrDeclaration.getElementForDiagnostics(): PsiElement? =
|
||||
findPsiElement()
|
||||
@@ -176,7 +177,7 @@ class JvmSignatureClashDetector(
|
||||
// However, if needed, we can provide more meaningful information regarding function origin.
|
||||
return JvmDeclarationOrigin(
|
||||
JvmDeclarationOriginKind.OTHER,
|
||||
context.psiSourceManager.findPsiElement(this),
|
||||
PsiSourceManager.findPsiElement(this),
|
||||
toIrBasedDescriptor()
|
||||
)
|
||||
}
|
||||
|
||||
+2
-3
@@ -89,13 +89,12 @@ internal val DeclarationDescriptorWithSource.psiElement: PsiElement?
|
||||
get() = (source as? PsiSourceElement)?.psi
|
||||
|
||||
fun JvmBackendContext.getSourceMapper(declaration: IrClass): SourceMapper {
|
||||
val sourceManager = this.psiSourceManager
|
||||
val fileEntry = sourceManager.getFileEntry(declaration.fileParent)
|
||||
val fileEntry = declaration.fileParent.fileEntry
|
||||
// NOTE: apparently inliner requires the source range to cover the
|
||||
// whole file the class is declared in rather than the class only.
|
||||
val endLineNumber = when (fileEntry) {
|
||||
is MultifileFacadeFileEntry -> 0
|
||||
else -> fileEntry?.getSourceRangeInfo(0, fileEntry.maxOffset)?.endLineNumber ?: 0
|
||||
else -> fileEntry.getSourceRangeInfo(0, fileEntry.maxOffset).endLineNumber
|
||||
}
|
||||
val sourceFileName = when (fileEntry) {
|
||||
is MultifileFacadeFileEntry -> fileEntry.partFiles.singleOrNull()?.name
|
||||
|
||||
@@ -44,6 +44,8 @@ import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
||||
import org.jetbrains.kotlin.load.java.JavaDescriptorVisibilities
|
||||
import org.jetbrains.kotlin.load.java.JvmAbi
|
||||
import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmProtoBufUtil
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi2ir.PsiSourceManager
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.jvm.annotations.JVM_DEFAULT_FQ_NAME
|
||||
import org.jetbrains.kotlin.resolve.jvm.annotations.JVM_DEFAULT_NO_COMPATIBILITY_FQ_NAME
|
||||
@@ -394,4 +396,7 @@ fun IrType.getSingleAbstractMethod(): IrSimpleFunction? =
|
||||
getClass()?.getSingleAbstractMethod()
|
||||
|
||||
fun IrClass.getSingleAbstractMethod(): IrSimpleFunction? =
|
||||
functions.singleOrNull { it.modality == Modality.ABSTRACT }
|
||||
functions.singleOrNull { it.modality == Modality.ABSTRACT }
|
||||
|
||||
fun IrFile.getKtFile(): KtFile? =
|
||||
(fileEntry as? PsiSourceManager.PsiFileEntry)?.psiFile as KtFile?
|
||||
|
||||
+4
-7
@@ -34,6 +34,7 @@ import org.jetbrains.kotlin.ir.symbols.impl.IrClassSymbolImpl
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.load.java.JavaDescriptorVisibilities
|
||||
import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi2ir.PsiSourceManager
|
||||
import org.jetbrains.kotlin.resolve.inline.INLINE_ONLY_ANNOTATION_FQ_NAME
|
||||
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
|
||||
@@ -79,14 +80,10 @@ private class FileClassLowering(val context: JvmBackendContext) : FileLoweringPa
|
||||
private fun createFileClass(irFile: IrFile, fileClassMembers: List<IrDeclaration>): IrClass {
|
||||
val fileEntry = irFile.fileEntry
|
||||
val fileClassInfo = when (fileEntry) {
|
||||
is PsiSourceManager.PsiFileEntry -> {
|
||||
val ktFile = context.psiSourceManager.getKtFile(fileEntry)
|
||||
?: throw AssertionError("Unexpected file entry: $fileEntry")
|
||||
JvmFileClassUtil.getFileClassInfoNoResolve(ktFile)
|
||||
}
|
||||
is NaiveSourceBasedFileEntryImpl -> {
|
||||
is PsiSourceManager.PsiFileEntry ->
|
||||
JvmFileClassUtil.getFileClassInfoNoResolve(fileEntry.psiFile as KtFile)
|
||||
is NaiveSourceBasedFileEntryImpl ->
|
||||
JvmSimpleFileClassInfo(PackagePartClassUtils.getPackagePartFqName(irFile.fqName, fileEntry.name), false)
|
||||
}
|
||||
else -> error("unknown kind of file entry: $fileEntry")
|
||||
}
|
||||
val isMultifilePart = fileClassInfo.withJvmMultifileClass
|
||||
|
||||
+1
-1
@@ -69,7 +69,7 @@ internal val generateMultifileFacadesPhase = makeCustomPhase<JvmBackendContext,
|
||||
class MultifileFacadeFileEntry(
|
||||
private val className: JvmClassName,
|
||||
val partFiles: List<IrFile>
|
||||
) : SourceManager.FileEntry {
|
||||
) : IrFileEntry {
|
||||
override val name: String
|
||||
get() = "<multi-file facade $className>"
|
||||
|
||||
|
||||
+3
-2
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.fileParent
|
||||
import org.jetbrains.kotlin.backend.jvm.ir.createJvmIrBuilder
|
||||
import org.jetbrains.kotlin.backend.jvm.ir.erasedUpperBound
|
||||
import org.jetbrains.kotlin.backend.jvm.ir.getKtFile
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||
import org.jetbrains.kotlin.ir.builders.*
|
||||
@@ -447,8 +448,8 @@ private class TypeOperatorLowering(private val context: JvmBackendContext) : Fil
|
||||
return startOffset to endOffset
|
||||
}
|
||||
|
||||
private fun sourceViewFor(declaration: IrDeclaration) =
|
||||
context.psiSourceManager.getKtFile(declaration.fileParent)!!.viewProvider.contents
|
||||
private fun sourceViewFor(declaration: IrDeclaration): CharSequence =
|
||||
declaration.fileParent.getKtFile()!!.viewProvider.contents
|
||||
|
||||
private val throwTypeCastException: IrSimpleFunctionSymbol =
|
||||
if (context.state.unifiedNullChecks)
|
||||
|
||||
+2
-5
@@ -13,10 +13,7 @@ import org.jetbrains.kotlin.backend.wasm.utils.WasmInlineClassesUtils
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.impl.EmptyPackageFragmentDescriptor
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.SourceManager
|
||||
import org.jetbrains.kotlin.ir.SourceRangeInfo
|
||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||
import org.jetbrains.kotlin.ir.*
|
||||
import org.jetbrains.kotlin.ir.backend.js.JsCommonBackendContext
|
||||
import org.jetbrains.kotlin.ir.backend.js.JsMapping
|
||||
import org.jetbrains.kotlin.ir.backend.js.lower.JsInnerClassesSupport
|
||||
@@ -63,7 +60,7 @@ class WasmBackendContext(
|
||||
private val internalPackageFragmentDescriptor = EmptyPackageFragmentDescriptor(builtIns.builtInsModule, FqName("kotlin.wasm.internal"))
|
||||
// TODO: Merge with JS IR Backend context lazy file
|
||||
val internalPackageFragment by lazy {
|
||||
IrFileImpl(object : SourceManager.FileEntry {
|
||||
IrFileImpl(object : IrFileEntry {
|
||||
override val name = "<implicitDeclarations>"
|
||||
override val maxOffset = UNDEFINED_OFFSET
|
||||
|
||||
|
||||
@@ -13,20 +13,16 @@ import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.ir.util.render
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
class PsiErrorBuilder(
|
||||
private val psiSourceManager: PsiSourceManager,
|
||||
private val diagnosticSink: DiagnosticSink
|
||||
) {
|
||||
|
||||
class PsiErrorBuilder(private val diagnosticSink: DiagnosticSink) {
|
||||
fun <E : PsiElement> at(irDeclaration: IrDeclaration, psiElementClass: KClass<E>): Location<E> =
|
||||
Location(
|
||||
psiSourceManager.findPsiElement(irDeclaration, psiElementClass)
|
||||
PsiSourceManager.findPsiElement(irDeclaration, psiElementClass)
|
||||
?: throw AssertionError("No ${psiElementClass.simpleName} found for '${irDeclaration.render()}'")
|
||||
)
|
||||
|
||||
fun at(irDeclaration: IrDeclaration): Location<PsiElement> =
|
||||
Location(
|
||||
psiSourceManager.findPsiElement(irDeclaration)
|
||||
PsiSourceManager.findPsiElement(irDeclaration)
|
||||
?: throw AssertionError("No PsiElement found for '${irDeclaration.render()}'")
|
||||
)
|
||||
|
||||
@@ -34,30 +30,29 @@ class PsiErrorBuilder(
|
||||
|
||||
fun <E : PsiElement> at(irElement: IrElement, irDeclaration: IrDeclaration, psiElementClass: KClass<E>): Location<E> =
|
||||
Location(
|
||||
psiSourceManager.findPsiElement(irElement, irDeclaration, psiElementClass)
|
||||
PsiSourceManager.findPsiElement(irElement, irDeclaration, psiElementClass)
|
||||
?: throw AssertionError("No ${psiElementClass.simpleName} found for '${irElement.render()}'")
|
||||
)
|
||||
|
||||
fun at(irElement: IrElement, irDeclaration: IrDeclaration): Location<PsiElement> =
|
||||
Location(
|
||||
psiSourceManager.findPsiElement(irElement, irDeclaration)
|
||||
PsiSourceManager.findPsiElement(irElement, irDeclaration)
|
||||
?: throw AssertionError("No PsiElement found for '${irElement.render()}'")
|
||||
)
|
||||
|
||||
fun <E : PsiElement> at(irElement: IrElement, irFile: IrFile, psiElementClass: KClass<E>): Location<E> =
|
||||
Location(
|
||||
psiSourceManager.findPsiElement(irElement, irFile, psiElementClass)
|
||||
PsiSourceManager.findPsiElement(irElement, irFile, psiElementClass)
|
||||
?: throw AssertionError("No ${psiElementClass.simpleName} found for '${irElement.render()}'")
|
||||
)
|
||||
|
||||
fun at(irElement: IrElement, irFile: IrFile): Location<PsiElement> =
|
||||
Location(
|
||||
psiSourceManager.findPsiElement(irElement, irFile)
|
||||
PsiSourceManager.findPsiElement(irElement, irFile)
|
||||
?: throw AssertionError("No PsiElement found for '${irElement.render()}'")
|
||||
)
|
||||
|
||||
inner class Location<E : PsiElement>(private val psiElement: E) {
|
||||
|
||||
fun report(diagnosticFactory: DiagnosticFactory0<E>) {
|
||||
diagnosticSink.report(diagnosticFactory.on(psiElement))
|
||||
}
|
||||
|
||||
@@ -20,17 +20,15 @@ import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiFile
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.SourceManager
|
||||
import org.jetbrains.kotlin.ir.IrFileEntry
|
||||
import org.jetbrains.kotlin.ir.SourceRangeInfo
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.ir.util.fileOrNull
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import java.util.*
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
class PsiSourceManager : SourceManager {
|
||||
class PsiFileEntry(psiFile: PsiFile) : SourceManager.FileEntry {
|
||||
object PsiSourceManager {
|
||||
class PsiFileEntry(val psiFile: PsiFile) : IrFileEntry {
|
||||
private val psiFileName = psiFile.virtualFile?.path ?: psiFile.name
|
||||
|
||||
override val maxOffset: Int
|
||||
@@ -87,41 +85,13 @@ class PsiSourceManager : SourceManager {
|
||||
}
|
||||
}
|
||||
|
||||
private val fileEntriesByKtFile = HashMap<KtFile, PsiFileEntry>()
|
||||
private val fileEntriesByIrFile = HashMap<IrFile, PsiFileEntry>()
|
||||
private val ktFileByFileEntry = HashMap<PsiFileEntry, KtFile>()
|
||||
|
||||
private fun createFileEntry(ktFile: KtFile): PsiFileEntry {
|
||||
if (ktFile in fileEntriesByKtFile) error("PsiFileEntry is already created for $ktFile")
|
||||
val newEntry = PsiFileEntry(ktFile)
|
||||
fileEntriesByKtFile[ktFile] = newEntry
|
||||
ktFileByFileEntry[newEntry] = ktFile
|
||||
return newEntry
|
||||
}
|
||||
|
||||
fun putFileEntry(irFile: IrFile, fileEntry: PsiFileEntry) {
|
||||
fileEntriesByIrFile[irFile] = fileEntry
|
||||
}
|
||||
|
||||
fun getOrCreateFileEntry(ktFile: KtFile): PsiFileEntry =
|
||||
fileEntriesByKtFile.getOrElse(ktFile) { createFileEntry(ktFile) }
|
||||
|
||||
fun getKtFile(fileEntry: PsiFileEntry): KtFile? =
|
||||
ktFileByFileEntry[fileEntry]
|
||||
|
||||
fun getKtFile(irFile: IrFile): KtFile? =
|
||||
(irFile.fileEntry as? PsiFileEntry)?.let { ktFileByFileEntry[it] }
|
||||
|
||||
override fun getFileEntry(irFile: IrFile): SourceManager.FileEntry? =
|
||||
fileEntriesByIrFile[irFile] ?: irFile.fileEntry
|
||||
|
||||
fun <E : PsiElement> findPsiElement(irElement: IrElement, irFile: IrFile, psiElementClass: KClass<E>): E? {
|
||||
val psiFileEntry = fileEntriesByIrFile[irFile] ?: return null
|
||||
val psiFileEntry = irFile.fileEntry as? PsiFileEntry ?: return null
|
||||
return psiFileEntry.findPsiElement(irElement, psiElementClass)
|
||||
}
|
||||
|
||||
fun findPsiElement(irElement: IrElement, irFile: IrFile): PsiElement? {
|
||||
val psiFileEntry = fileEntriesByIrFile[irFile] ?: return null
|
||||
val psiFileEntry = irFile.fileEntry as? PsiFileEntry ?: return null
|
||||
return psiFileEntry.findPsiElement(irElement)
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@ import org.jetbrains.kotlin.ir.util.ConstantValueGenerator
|
||||
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||
import org.jetbrains.kotlin.ir.util.TypeTranslator
|
||||
import org.jetbrains.kotlin.psi2ir.Psi2IrConfiguration
|
||||
import org.jetbrains.kotlin.psi2ir.PsiSourceManager
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
||||
|
||||
@@ -34,8 +33,6 @@ class GeneratorContext(
|
||||
) : IrGeneratorContext {
|
||||
internal val callToSubstitutedDescriptorMap = mutableMapOf<IrDeclarationReference, CallableDescriptor>()
|
||||
|
||||
val sourceManager = PsiSourceManager()
|
||||
|
||||
// TODO: inject a correct StorageManager instance, or store NotFoundClasses inside ModuleDescriptor
|
||||
val reflectionTypes = ReflectionTypes(moduleDescriptor, NotFoundClasses(LockBasedStorageManager.NO_LOCKS, moduleDescriptor))
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.jetbrains.kotlin.ir.util.patchDeclarationParents
|
||||
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.acceptVoid
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi2ir.PsiSourceManager
|
||||
import org.jetbrains.kotlin.psi2ir.transformations.insertImplicitCasts
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.lazy.descriptors.findPackageFragmentForFile
|
||||
@@ -101,12 +102,10 @@ class ModuleGenerator(
|
||||
}
|
||||
|
||||
private fun createEmptyIrFile(ktFile: KtFile): IrFileImpl {
|
||||
val fileEntry = context.sourceManager.getOrCreateFileEntry(ktFile)
|
||||
val fileEntry = PsiSourceManager.PsiFileEntry(ktFile)
|
||||
val packageFragmentDescriptor = context.moduleDescriptor.findPackageFragmentForFile(ktFile)!!
|
||||
val irFile = IrFileImpl(fileEntry, packageFragmentDescriptor).apply {
|
||||
return IrFileImpl(fileEntry, packageFragmentDescriptor).apply {
|
||||
metadata = DescriptorMetadataSource.File(CodegenUtil.getMemberDescriptorsToGenerate(ktFile, context.bindingContext))
|
||||
}
|
||||
context.sourceManager.putFileEntry(irFile, fileEntry)
|
||||
return irFile
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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.ir
|
||||
|
||||
const val UNDEFINED_OFFSET: Int = -1
|
||||
|
||||
data class SourceRangeInfo(
|
||||
val filePath: String,
|
||||
val startOffset: Int,
|
||||
val startLineNumber: Int,
|
||||
val startColumnNumber: Int,
|
||||
val endOffset: Int,
|
||||
val endLineNumber: Int,
|
||||
val endColumnNumber: Int
|
||||
)
|
||||
|
||||
interface IrFileEntry {
|
||||
val name: String
|
||||
val maxOffset: Int
|
||||
fun getSourceRangeInfo(beginOffset: Int, endOffset: Int): SourceRangeInfo
|
||||
fun getLineNumber(offset: Int): Int
|
||||
fun getColumnNumber(offset: Int): Int
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.ir
|
||||
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
|
||||
const val UNDEFINED_OFFSET: Int = -1
|
||||
|
||||
data class SourceRangeInfo(
|
||||
val filePath: String,
|
||||
val startOffset: Int,
|
||||
val startLineNumber: Int,
|
||||
val startColumnNumber: Int,
|
||||
val endOffset: Int,
|
||||
val endLineNumber: Int,
|
||||
val endColumnNumber: Int
|
||||
)
|
||||
|
||||
interface SourceManager {
|
||||
interface FileEntry {
|
||||
val name: String
|
||||
val maxOffset: Int
|
||||
fun getSourceRangeInfo(beginOffset: Int, endOffset: Int): SourceRangeInfo
|
||||
fun getLineNumber(offset: Int): Int
|
||||
fun getColumnNumber(offset: Int): Int
|
||||
}
|
||||
|
||||
fun getFileEntry(irFile: IrFile): FileEntry?
|
||||
}
|
||||
@@ -18,7 +18,7 @@ package org.jetbrains.kotlin.ir.declarations
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
||||
import org.jetbrains.kotlin.ir.IrElementBase
|
||||
import org.jetbrains.kotlin.ir.SourceManager
|
||||
import org.jetbrains.kotlin.ir.IrFileEntry
|
||||
import org.jetbrains.kotlin.ir.symbols.IrExternalPackageFragmentSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrFileSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrPackageFragmentSymbol
|
||||
@@ -42,7 +42,7 @@ abstract class IrExternalPackageFragment : IrPackageFragment() {
|
||||
abstract class IrFile : IrPackageFragment(), IrMutableAnnotationContainer, IrMetadataSourceOwner {
|
||||
abstract override val symbol: IrFileSymbol
|
||||
|
||||
abstract val fileEntry: SourceManager.FileEntry
|
||||
abstract val fileEntry: IrFileEntry
|
||||
|
||||
override fun <D> transform(transformer: IrElementTransformer<D>, data: D): IrFile =
|
||||
accept(transformer, data) as IrFile
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
package org.jetbrains.kotlin.ir.declarations.impl
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
||||
import org.jetbrains.kotlin.ir.IrFileEntry
|
||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||
import org.jetbrains.kotlin.ir.SourceManager
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.ir.declarations.MetadataSource
|
||||
@@ -30,12 +30,12 @@ import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
|
||||
class IrFileImpl(
|
||||
override val fileEntry: SourceManager.FileEntry,
|
||||
override val fileEntry: IrFileEntry,
|
||||
override val symbol: IrFileSymbol,
|
||||
override val fqName: FqName
|
||||
) : IrFile() {
|
||||
constructor(
|
||||
fileEntry: SourceManager.FileEntry,
|
||||
fileEntry: IrFileEntry,
|
||||
packageFragmentDescriptor: PackageFragmentDescriptor
|
||||
) : this(fileEntry, IrFileSymbolImpl(packageFragmentDescriptor), packageFragmentDescriptor.fqName)
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ fun List<IrConstructorCall>.hasAnnotation(fqName: FqName): Boolean =
|
||||
fun List<IrConstructorCall>.findAnnotation(fqName: FqName): IrConstructorCall? =
|
||||
firstOrNull { it.annotationClass.hasEqualFqName(fqName) }
|
||||
|
||||
val IrDeclaration.fileEntry: SourceManager.FileEntry
|
||||
val IrDeclaration.fileEntry: IrFileEntry
|
||||
get() = parent.let {
|
||||
when (it) {
|
||||
is IrFile -> it.fileEntry
|
||||
@@ -172,7 +172,7 @@ val File.lineStartOffsets: IntArray
|
||||
return buffer.toIntArray()
|
||||
}
|
||||
|
||||
val SourceManager.FileEntry.lineStartOffsets
|
||||
val IrFileEntry.lineStartOffsets
|
||||
get() = File(name).let {
|
||||
if (it.exists() && it.isFile) it.lineStartOffsets else IntArray(0)
|
||||
}
|
||||
@@ -180,7 +180,7 @@ val SourceManager.FileEntry.lineStartOffsets
|
||||
class NaiveSourceBasedFileEntryImpl(
|
||||
override val name: String,
|
||||
private val lineStartOffsets: IntArray = intArrayOf()
|
||||
) : SourceManager.FileEntry {
|
||||
) : IrFileEntry {
|
||||
|
||||
private val MAX_SAVED_LINE_NUMBERS = 50
|
||||
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
|
||||
package org.jetbrains.kotlin.ir.util
|
||||
|
||||
import org.jetbrains.kotlin.ir.IrFileEntry
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.SourceManager
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
||||
@@ -355,7 +355,7 @@ class DumpIrTreeVisitor(
|
||||
}
|
||||
|
||||
class DumpTreeFromSourceLineVisitor(
|
||||
val fileEntry: SourceManager.FileEntry,
|
||||
val fileEntry: IrFileEntry,
|
||||
private val lineNumber: Int,
|
||||
out: Appendable,
|
||||
normalizeNames: Boolean = false
|
||||
|
||||
+2
-2
@@ -8,8 +8,8 @@ package org.jetbrains.kotlin.backend.common.serialization
|
||||
import org.jetbrains.kotlin.backend.common.ir.ir2string
|
||||
import org.jetbrains.kotlin.backend.common.serialization.encodings.*
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.ir.IrFileEntry
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.SourceManager
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.symbols.*
|
||||
@@ -1224,7 +1224,7 @@ open class IrFileSerializer(
|
||||
|
||||
// ---------- Top level ------------------------------------------------------
|
||||
|
||||
private fun serializeFileEntry(entry: SourceManager.FileEntry): ProtoFileEntry = ProtoFileEntry.newBuilder()
|
||||
private fun serializeFileEntry(entry: IrFileEntry): ProtoFileEntry = ProtoFileEntry.newBuilder()
|
||||
.setName(entry.name)
|
||||
.addAllLineStartOffsets(entry.lineStartOffsets.asIterable())
|
||||
.build()
|
||||
|
||||
+3
-9
@@ -42,7 +42,7 @@ class Fir2IrResultsConverter(
|
||||
inputArtifact: FirOutputArtifact
|
||||
): IrBackendInput {
|
||||
val extensions = JvmGeneratorExtensions()
|
||||
val (irModuleFragment, symbolTable, sourceManager, components) = inputArtifact.firAnalyzerFacade.convertToIr(extensions)
|
||||
val (irModuleFragment, symbolTable, components) = inputArtifact.firAnalyzerFacade.convertToIr(extensions)
|
||||
val dummyBindingContext = NoScopeRecordCliBindingTrace().bindingContext
|
||||
|
||||
val compilerConfigurationProvider = testServices.compilerConfigurationProvider
|
||||
@@ -76,24 +76,18 @@ class Fir2IrResultsConverter(
|
||||
).build()
|
||||
|
||||
irModuleFragment.irBuiltins.functionFactory = IrFunctionFactory(irModuleFragment.irBuiltins, symbolTable)
|
||||
val irProviders = codegenFactory.configureBuiltInsAndGenerateIrProvidersInFrontendIRMode(
|
||||
irModuleFragment,
|
||||
symbolTable,
|
||||
extensions
|
||||
)
|
||||
val irProviders = codegenFactory.configureBuiltInsAndGenerateIrProvidersInFrontendIRMode(irModuleFragment, symbolTable, extensions)
|
||||
|
||||
return IrBackendInput(
|
||||
JvmIrCodegenFactory.JvmIrBackendInput(
|
||||
generationState,
|
||||
irModuleFragment,
|
||||
symbolTable,
|
||||
sourceManager,
|
||||
phaseConfig,
|
||||
irProviders,
|
||||
extensions,
|
||||
FirJvmBackendExtension(inputArtifact.session, components),
|
||||
{},
|
||||
)
|
||||
) {}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -35,14 +35,14 @@ abstract class AbstractIrSourceRangesTestCase : AbstractIrGeneratorTestCase() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun IrElement.dumpWithSourceLocations(fileEntry: SourceManager.FileEntry): String =
|
||||
private fun IrElement.dumpWithSourceLocations(fileEntry: IrFileEntry): String =
|
||||
StringBuilder().also {
|
||||
acceptVoid(DumpSourceLocations(it, fileEntry))
|
||||
}.toString()
|
||||
|
||||
private class DumpSourceLocations(
|
||||
out: Appendable,
|
||||
val fileEntry: SourceManager.FileEntry
|
||||
val fileEntry: IrFileEntry
|
||||
) : IrElementVisitorVoid {
|
||||
val printer = Printer(out, " ")
|
||||
val elementRenderer = RenderIrElementVisitor()
|
||||
|
||||
@@ -109,7 +109,7 @@ object GenerationUtils {
|
||||
// TODO: add running checkers and check that it's safe to compile
|
||||
val firAnalyzerFacade = FirAnalyzerFacade(session, configuration.languageVersionSettings, files)
|
||||
val extensions = JvmGeneratorExtensions()
|
||||
val (moduleFragment, symbolTable, sourceManager, components) = firAnalyzerFacade.convertToIr(extensions)
|
||||
val (moduleFragment, symbolTable, components) = firAnalyzerFacade.convertToIr(extensions)
|
||||
val dummyBindingContext = NoScopeRecordCliBindingTrace().bindingContext
|
||||
|
||||
val codegenFactory = JvmIrCodegenFactory(configuration.get(CLIConfigurationKeys.PHASE_CONFIG) ?: PhaseConfig(jvmPhases))
|
||||
@@ -131,8 +131,8 @@ object GenerationUtils {
|
||||
|
||||
generationState.beforeCompile()
|
||||
codegenFactory.generateModuleInFrontendIRMode(
|
||||
generationState, moduleFragment, symbolTable, sourceManager, extensions, FirJvmBackendExtension(session, components), {},
|
||||
)
|
||||
generationState, moduleFragment, symbolTable, extensions, FirJvmBackendExtension(session, components),
|
||||
) {}
|
||||
|
||||
generationState.factory.done()
|
||||
return generationState
|
||||
|
||||
+4
-4
@@ -10,7 +10,7 @@ import kotlinx.cinterop.memScoped
|
||||
import kotlinx.cinterop.reinterpret
|
||||
import llvm.*
|
||||
import org.jetbrains.kotlin.backend.konan.*
|
||||
import org.jetbrains.kotlin.ir.SourceManager.FileEntry
|
||||
import org.jetbrains.kotlin.ir.IrFileEntry
|
||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
@@ -95,7 +95,7 @@ internal class DebugInfo internal constructor(override val context: Context):Con
|
||||
* File entry starts offsets from zero while dwarf number lines/column starting from 1.
|
||||
*/
|
||||
private val NO_SOURCE_FILE = "no source file"
|
||||
private fun FileEntry.location(offset: Int, offsetToNumber: (Int) -> Int): Int {
|
||||
private fun IrFileEntry.location(offset: Int, offsetToNumber: (Int) -> Int): Int {
|
||||
assert(offset != UNDEFINED_OFFSET)
|
||||
// Part "name.isEmpty() || name == NO_SOURCE_FILE" is an awful hack, @minamoto, please fix properly.
|
||||
if (offset == SYNTHETIC_OFFSET || name.isEmpty() || name == NO_SOURCE_FILE) return 1
|
||||
@@ -105,9 +105,9 @@ private fun FileEntry.location(offset: Int, offsetToNumber: (Int) -> Int): Int {
|
||||
return result
|
||||
}
|
||||
|
||||
internal fun FileEntry.line(offset: Int) = location(offset, this::getLineNumber)
|
||||
internal fun IrFileEntry.line(offset: Int) = location(offset, this::getLineNumber)
|
||||
|
||||
internal fun FileEntry.column(offset: Int) = location(offset, this::getColumnNumber)
|
||||
internal fun IrFileEntry.column(offset: Int) = location(offset, this::getColumnNumber)
|
||||
|
||||
internal data class FileAndFolder(val file: String, val folder: String) {
|
||||
companion object {
|
||||
|
||||
+3
-4
@@ -10,13 +10,12 @@ import org.jetbrains.kotlin.backend.konan.KonanBackendContext
|
||||
import org.jetbrains.kotlin.backend.konan.KonanCompilationException
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.synthesizedName
|
||||
import org.jetbrains.kotlin.backend.konan.ir.buildSimpleAnnotation
|
||||
import org.jetbrains.kotlin.builtins.StandardNames
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.descriptors.ParameterDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
|
||||
import org.jetbrains.kotlin.descriptors.ParameterDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.impl.PackageFragmentDescriptorImpl
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.SourceManager
|
||||
import org.jetbrains.kotlin.ir.IrFileEntry
|
||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||
import org.jetbrains.kotlin.ir.builders.*
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
@@ -88,7 +87,7 @@ internal fun IrFile.addTopLevelInitializer(expression: IrExpression, context: Ko
|
||||
addChild(irField)
|
||||
}
|
||||
|
||||
fun IrModuleFragment.addFile(fileEntry: SourceManager.FileEntry, packageFqName: FqName): IrFile {
|
||||
fun IrModuleFragment.addFile(fileEntry: IrFileEntry, packageFqName: FqName): IrFile {
|
||||
val packageFragmentDescriptor = object : PackageFragmentDescriptorImpl(this.descriptor, packageFqName) {
|
||||
override fun getMemberScope(): MemberScope = MemberScope.Empty
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user