Use file symbol instead of a file name string in IrReturnableBlockImpl

This commit is contained in:
Alexander Gorshenev
2019-02-11 16:27:09 +03:00
committed by alexander-gorshenev
parent e2106d4d08
commit 888641e7f1
7 changed files with 32 additions and 25 deletions
@@ -873,13 +873,13 @@ internal class DeepCopyIrTreeWithDescriptors(val targetDescriptor: FunctionDescr
override fun visitBlock(expression: IrBlock): IrBlock {
return if (expression is IrReturnableBlock) {
IrReturnableBlockImpl(
startOffset = expression.startOffset,
endOffset = expression.endOffset,
type = expression.type,
descriptor = expression.descriptor,
origin = mapStatementOrigin(expression.origin),
statements = expression.statements.map { it.transform(this, null) },
sourceFileName = expression.sourceFileName
startOffset = expression.startOffset,
endOffset = expression.endOffset,
type = expression.type,
descriptor = expression.descriptor,
origin = mapStatementOrigin(expression.origin),
statements = expression.statements.map { it.transform(this, null) },
sourceFileSymbol = expression.sourceFileSymbol
)
} else {
IrBlockImpl(
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.ir.expressions.impl.IrReturnableBlockImpl
import org.jetbrains.kotlin.ir.expressions.impl.IrVarargImpl
import org.jetbrains.kotlin.ir.symbols.impl.IrReturnableBlockSymbolImpl
import org.jetbrains.kotlin.ir.types.toKotlinType
import org.jetbrains.kotlin.ir.util.file
import org.jetbrains.kotlin.ir.util.getArguments
import org.jetbrains.kotlin.ir.util.parentAsClass
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
@@ -269,8 +270,6 @@ private class Inliner(val globalSubstituteMap: MutableMap<DeclarationDescriptor,
}
}
val sourceFileName = context.originalModuleIndex.declarationToFile[callee.descriptor.original] ?: ""
copyIrElement.addCurrentSubstituteMap(globalSubstituteMap)
val transformer = ParameterSubstitutor()
@@ -284,7 +283,7 @@ private class Inliner(val globalSubstituteMap: MutableMap<DeclarationDescriptor,
symbol = irReturnableBlockSymbol,
origin = null,
statements = statements,
sourceFileName = sourceFileName
sourceFileSymbol = callee.file.symbol
).apply {
transformChildrenVoid(object: IrElementTransformerVoid() {
override fun visitReturn(expression: IrReturn): IrExpression {
@@ -30,7 +30,6 @@ class ModuleIndex(val module: IrModuleFragment) {
* Contains all functions declared in [module]
*/
val functions = mutableMapOf<FunctionDescriptor, IrFunction>()
val declarationToFile = mutableMapOf<DeclarationDescriptor, String>()
init {
addModule(module)
@@ -63,11 +62,6 @@ class ModuleIndex(val module: IrModuleFragment) {
super.visitFunction(declaration)
functions[declaration.descriptor] = declaration
}
override fun visitDeclaration(declaration: IrDeclaration) {
super.visitDeclaration(declaration)
declarationToFile[declaration.descriptor] = currentFile!!.path
}
})
}
}
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.ir.expressions
import org.jetbrains.kotlin.ir.declarations.IrReturnTarget
import org.jetbrains.kotlin.ir.declarations.IrSymbolOwner
import org.jetbrains.kotlin.ir.symbols.IrFileSymbol
import org.jetbrains.kotlin.ir.symbols.IrReturnableBlockSymbol
interface IrContainerExpression : IrExpression, IrStatementContainer {
@@ -37,5 +38,6 @@ interface IrComposite : IrContainerExpression {
interface IrReturnableBlock : IrBlock, IrSymbolOwner, IrReturnTarget {
override val symbol: IrReturnableBlockSymbol
val sourceFileSymbol: IrFileSymbol?
val sourceFileName: String
}
@@ -18,9 +18,11 @@ package org.jetbrains.kotlin.ir.expressions.impl
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.ir.IrStatement
import org.jetbrains.kotlin.ir.declarations.IrFile
import org.jetbrains.kotlin.ir.expressions.IrBlock
import org.jetbrains.kotlin.ir.expressions.IrReturnableBlock
import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin
import org.jetbrains.kotlin.ir.symbols.IrFileSymbol
import org.jetbrains.kotlin.ir.symbols.IrReturnableBlockSymbol
import org.jetbrains.kotlin.ir.symbols.impl.IrReturnableBlockSymbolImpl
import org.jetbrains.kotlin.ir.types.IrType
@@ -63,14 +65,13 @@ fun IrBlockImpl.inlineStatement(statement: IrStatement) {
}
}
class IrReturnableBlockImpl(
startOffset: Int,
endOffset: Int,
type: IrType,
override val symbol: IrReturnableBlockSymbol,
origin: IrStatementOrigin? = null,
override val sourceFileName: String = "no source file"
override val sourceFileSymbol: IrFileSymbol? = null
) :
IrContainerExpressionBase(startOffset, endOffset, type, origin),
IrReturnableBlock {
@@ -84,8 +85,8 @@ class IrReturnableBlockImpl(
symbol: IrReturnableBlockSymbol,
origin: IrStatementOrigin?,
statements: List<IrStatement>,
sourceFileName: String = "no source file"
) : this(startOffset, endOffset, type, symbol, origin, sourceFileName) {
sourceFileSymbol: IrFileSymbol? = null
) : this(startOffset, endOffset, type, symbol, origin, sourceFileSymbol) {
this.statements.addAll(statements)
}
@@ -95,8 +96,8 @@ class IrReturnableBlockImpl(
type: IrType,
descriptor: FunctionDescriptor,
origin: IrStatementOrigin? = null,
sourceFileName: String = "no source file"
) : this(startOffset, endOffset, type, IrReturnableBlockSymbolImpl(descriptor), origin, sourceFileName)
sourceFileSymbol: IrFileSymbol? = null
) : this(startOffset, endOffset, type, IrReturnableBlockSymbolImpl(descriptor), origin, sourceFileSymbol)
constructor(
startOffset: Int,
@@ -105,8 +106,8 @@ class IrReturnableBlockImpl(
descriptor: FunctionDescriptor,
origin: IrStatementOrigin?,
statements: List<IrStatement>,
sourceFileName: String = "no source file"
) : this(startOffset, endOffset, type, descriptor, origin, sourceFileName) {
sourceFileSymbol: IrFileSymbol? = null
) : this(startOffset, endOffset, type, descriptor, origin, sourceFileSymbol) {
this.statements.addAll(statements)
}
@@ -114,6 +115,8 @@ class IrReturnableBlockImpl(
symbol.bind(this)
}
override val sourceFileName: String = sourceFileSymbol?.owner?.fileEntry?.name ?: "no source file"
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
visitor.visitBlock(this, data)
@@ -383,7 +383,7 @@ open class DeepCopyIrTreeWithSymbols(
symbolRemapper.getReferencedReturnableBlock(expression.symbol),
mapStatementOrigin(expression.origin),
expression.statements.map { it.transform() },
expression.sourceFileName
expression.sourceFileSymbol
)
else
IrBlockImpl(
@@ -569,3 +569,12 @@ private fun IrCall.copyTypeAndValueArgumentsFrom(
putValueArgument(toValueArgumentIndex++, call.getValueArgument(fromValueArgumentIndex++))
}
}
val IrDeclaration.file: IrFile get() = parent.let {
when (it) {
is IrFile -> it
is IrPackageFragment -> TODO("Unknown file")
is IrDeclaration -> it.file
else -> TODO("Unexpected declaration parent")
}
}