[Native] Drop constantInliningPhase
We don't need this lowering anymore because corresponding work is done by `constEvaluationPhase`
This commit is contained in:
-49
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2022 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.backend.common.lower
|
||||
|
||||
import org.jetbrains.kotlin.ir.declarations.IrField
|
||||
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrCompositeImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrGetFieldImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.copyWithOffsets
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
||||
|
||||
abstract class InlineConstTransformer : IrElementTransformerVoid() {
|
||||
abstract val IrField.constantInitializer: IrConst<*>?
|
||||
private fun IrExpression.lowerConstRead(receiver: IrExpression?, field: IrField?): IrExpression? {
|
||||
val value = field?.constantInitializer ?: return null
|
||||
transformChildrenVoid()
|
||||
reportInlineConst(field, value)
|
||||
|
||||
val resultExpression = value.copyWithOffsets(startOffset, endOffset)
|
||||
|
||||
return if (receiver == null || receiver.shouldDropConstReceiver())
|
||||
resultExpression
|
||||
else
|
||||
IrCompositeImpl(
|
||||
startOffset, endOffset, resultExpression.type, null,
|
||||
listOf(receiver, resultExpression)
|
||||
)
|
||||
}
|
||||
|
||||
abstract fun reportInlineConst(field: IrField, value: IrConst<*>)
|
||||
|
||||
fun IrExpression.shouldDropConstReceiver(): Boolean {
|
||||
return this is IrConst<*> || this is IrGetValue || this is IrGetObjectValue
|
||||
}
|
||||
|
||||
override fun visitCall(expression: IrCall): IrExpression {
|
||||
val function = (expression.symbol.owner as? IrSimpleFunction) ?: return super.visitCall(expression)
|
||||
val property = function.correspondingPropertySymbol?.owner ?: return super.visitCall(expression)
|
||||
// If `constantValue` is not null, `function` can only be the getter because the property is immutable.
|
||||
return expression.lowerConstRead(expression.dispatchReceiver, property.backingField) ?: super.visitCall(expression)
|
||||
}
|
||||
|
||||
override fun visitGetField(expression: IrGetField): IrExpression =
|
||||
expression.lowerConstRead(expression.receiver, expression.symbol.owner) ?: super.visitGetField(expression)
|
||||
}
|
||||
-7
@@ -415,12 +415,6 @@ private val expressionBodyTransformPhase = createFileLoweringPhase(
|
||||
description = "Replace IrExpressionBody with IrBlockBody"
|
||||
)
|
||||
|
||||
private val constantInliningPhase = createFileLoweringPhase(
|
||||
::ConstLowering,
|
||||
name = "ConstantInlining",
|
||||
description = "Inline const fields reads",
|
||||
)
|
||||
|
||||
private val staticInitializersPhase = createFileLoweringPhase(
|
||||
::StaticInitializersLowering,
|
||||
name = "StaticInitializers",
|
||||
@@ -550,7 +544,6 @@ private fun PhaseEngine<NativeGenerationState>.getAllLowerings() = listOfNotNull
|
||||
coroutinesPhase,
|
||||
typeOperatorPhase,
|
||||
expressionBodyTransformPhase,
|
||||
constantInliningPhase,
|
||||
objectClassesPhase,
|
||||
staticInitializersPhase,
|
||||
builtinOperatorPhase,
|
||||
|
||||
-35
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2022 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.backend.konan.lower
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.FileLoweringPass
|
||||
import org.jetbrains.kotlin.backend.common.lower.InlineConstTransformer
|
||||
import org.jetbrains.kotlin.backend.konan.Context
|
||||
import org.jetbrains.kotlin.ir.declarations.IrField
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.ir.expressions.IrConst
|
||||
import org.jetbrains.kotlin.ir.expressions.IrConstKind
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.IrGetValue
|
||||
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
||||
|
||||
internal class ConstLowering(val context: Context) : FileLoweringPass {
|
||||
override fun lower(irFile: IrFile) {
|
||||
irFile.transformChildrenVoid(NativeInlineConstTransformer())
|
||||
}
|
||||
}
|
||||
|
||||
private class NativeInlineConstTransformer : InlineConstTransformer() {
|
||||
override val IrField.constantInitializer get() =
|
||||
(initializer?.expression as? IrConst<*>)
|
||||
?.takeIf { correspondingPropertySymbol?.owner?.isConst == true }
|
||||
// NaN constants has inconsistencies between IR and metadata representation,
|
||||
// so inlining them can lead to incorrect behaviour. Check KT-53258 for details.
|
||||
?.takeUnless { it.kind == IrConstKind.Double && IrConstKind.Double.valueOf(it).isNaN() }
|
||||
?.takeUnless { it.kind == IrConstKind.Float && IrConstKind.Float.valueOf(it).isNaN() }
|
||||
|
||||
override fun reportInlineConst(field: IrField, value: IrConst<*>) {}
|
||||
}
|
||||
Reference in New Issue
Block a user