Skip to content
This repository has been archived by the owner on Aug 10, 2021. It is now read-only.

Commit

Permalink
[lowering][debug info] corrections in offsets processing
Browse files Browse the repository at this point in the history
  • Loading branch information
vvlevchenko committed Jul 1, 2019
1 parent c8af53e commit 91868e7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import org.jetbrains.kotlin.backend.konan.Context
import org.jetbrains.kotlin.backend.konan.descriptors.resolveFakeOverride
import org.jetbrains.kotlin.backend.konan.ir.*
import org.jetbrains.kotlin.config.languageVersionSettings
import org.jetbrains.kotlin.descriptors.ValueDescriptor
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.IrStatement
import org.jetbrains.kotlin.ir.builders.irGet
Expand All @@ -25,9 +26,12 @@ import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.expressions.*
import org.jetbrains.kotlin.ir.expressions.impl.*
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
import org.jetbrains.kotlin.ir.symbols.IrValueSymbol
import org.jetbrains.kotlin.ir.symbols.impl.IrReturnableBlockSymbolImpl
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.ir.util.*
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.util.OperatorNameConventions
Expand Down Expand Up @@ -101,7 +105,7 @@ internal class FunctionInlining(val context: Context) : IrElementTransformerVoid
DeepCopyIrTreeWithSymbolsForInliner(context, typeArguments, parent)
}

val substituteMap = mutableMapOf<IrValueParameter, IrExpression>()
val substituteMap = mutableMapOf<IrValueParameter, IrElement>()

fun inline() = inlineFunction(callSite, callee)

Expand All @@ -125,7 +129,10 @@ internal class FunctionInlining(val context: Context) : IrElementTransformerVoid
val irReturnableBlockSymbol = IrReturnableBlockSymbolImpl(copiedCallee.descriptor.original)
val startOffset = callee.startOffset
val endOffset = callee.endOffset
val irBuilder = context.createIrBuilder(irReturnableBlockSymbol, startOffset, endOffset)
/* creates irBuilder appending to the end of the given returnable block: thus why we initialize
* irBuilder with (..., endOffset, endOffset).
*/
val irBuilder = context.createIrBuilder(irReturnableBlockSymbol, endOffset, endOffset)

if (callee.isInlineConstructor) {
// Copier sets parent to be the current function but
Expand Down Expand Up @@ -197,9 +204,13 @@ internal class FunctionInlining(val context: Context) : IrElementTransformerVoid
override fun visitGetValue(expression: IrGetValue): IrExpression {
val newExpression = super.visitGetValue(expression) as IrGetValue
val argument = substituteMap[newExpression.symbol.owner] ?: return newExpression

argument.transformChildrenVoid(this) // Default argument can contain subjects for substitution.
return copyIrElement.copy(argument) as IrExpression
return if (argument is IrVariable) {
IrGetValueImpl(startOffset = newExpression.startOffset,
endOffset = newExpression.endOffset,
symbol = argument.symbol)

} else (copyIrElement.copy(argument) as IrExpression)
}

//-----------------------------------------------------------------//
Expand Down Expand Up @@ -403,13 +414,7 @@ internal class FunctionInlining(val context: Context) : IrElementTransformerVoid
isMutable = false)

evaluationStatements.add(newVariable)
val getVal = IrGetValueImpl(
startOffset = currentScope.irElement.startOffset,
endOffset = currentScope.irElement.endOffset,
type = newVariable.type,
symbol = newVariable.symbol
)
substituteMap[it.parameter] = getVal
substituteMap[it.parameter] = newVariable
}
return evaluationStatements
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ internal class ReturnsInsertionLowering(val context: Context) : FileLoweringPass

val body = declaration.body
if ((declaration is IrConstructor || declaration.returnType.classifierOrNull == symbols.unit) && body != null) {
val irBuilder = context.createIrBuilder(declaration.symbol, declaration.startOffset, declaration.endOffset)
val irBuilder = context.createIrBuilder(declaration.symbol, declaration.endOffset, declaration.endOffset)
irBuilder.run {
(body as IrBlockBody).statements += irReturn(irGetObject(symbols.unit))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1413,12 +1413,13 @@ internal object Devirtualization {
val newSymbol = IrReturnableBlockSymbolImpl(expression.descriptor)
val transformedReturnableBlock = with(expression) {
IrReturnableBlockImpl(
startOffset = startOffset,
endOffset = endOffset,
type = coercion.type,
symbol = newSymbol,
origin = origin,
statements = statements)
startOffset = startOffset,
endOffset = endOffset,
type = coercion.type,
symbol = newSymbol,
origin = origin,
statements = statements,
inlineFunctionSymbol = inlineFunctionSymbol)
}
transformedReturnableBlock.transformChildrenVoid(object: IrElementTransformerVoid() {
override fun visitExpression(expression: IrExpression): IrExpression {
Expand Down

0 comments on commit 91868e7

Please sign in to comment.