[JPS] Fix incremental build after changing Java constant
InlineConstantTracker implemented for tracking changed java static final constants, that used in kotlin. #KT-46506 Fixed
This commit is contained in:
committed by
TeamCityServer
parent
23420ecf7a
commit
cc5382b37e
+38
-1
@@ -19,6 +19,14 @@ import org.jetbrains.kotlin.ir.expressions.impl.IrGetFieldImpl
|
||||
import org.jetbrains.kotlin.ir.types.isPrimitiveType
|
||||
import org.jetbrains.kotlin.ir.types.isStringClassType
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
||||
import org.jetbrains.kotlin.incremental.components.InlineConstTracker
|
||||
import org.jetbrains.kotlin.incremental.components.ConstantRef
|
||||
import org.jetbrains.kotlin.config.CommonConfigurationKeys
|
||||
import org.jetbrains.kotlin.descriptors.SourceFile
|
||||
import org.jetbrains.kotlin.ir.descriptors.toIrBasedDescriptor
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.ir.util.IdSignature
|
||||
import org.jetbrains.kotlin.load.kotlin.toSourceElement
|
||||
|
||||
internal val constPhase1 = makeIrFilePhase(
|
||||
::ConstLowering,
|
||||
@@ -48,11 +56,16 @@ fun IrField.constantValue(context: JvmBackendContext? = null): IrConst<*>? {
|
||||
}
|
||||
|
||||
class ConstLowering(val context: JvmBackendContext) : IrElementTransformerVoid(), FileLoweringPass {
|
||||
val inlineConstTracker =
|
||||
context.state.configuration[CommonConfigurationKeys.INLINE_CONST_TRACKER] ?: InlineConstTracker.DoNothing
|
||||
|
||||
override fun lower(irFile: IrFile) = irFile.transformChildrenVoid()
|
||||
|
||||
private fun IrExpression.lowerConstRead(receiver: IrExpression?, field: IrField?): IrExpression? {
|
||||
val value = field?.constantValue() ?: return null
|
||||
transformChildrenVoid()
|
||||
reportInlineConst(this@lowerConstRead, field)
|
||||
|
||||
val resultExpression = if (context.state.shouldInlineConstVals)
|
||||
value.copyWithOffsets(startOffset, endOffset)
|
||||
else
|
||||
@@ -66,7 +79,31 @@ class ConstLowering(val context: JvmBackendContext) : IrElementTransformerVoid()
|
||||
listOf(receiver, resultExpression)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
private fun reportInlineConst(irExpression: IrExpression, field: IrField?) {
|
||||
if (inlineConstTracker == InlineConstTracker.DoNothing) return
|
||||
val value = field?.constantValue() ?: return
|
||||
|
||||
if (!field.isFinal || !field.isStatic) return
|
||||
|
||||
val sourceFile = field.toIrBasedDescriptor().containingDeclaration.toSourceElement.containingFile
|
||||
if (sourceFile == SourceFile.NO_SOURCE_FILE || sourceFile.toString().lowercase().endsWith(".kt")) return
|
||||
|
||||
for (file: KtFile in context.state.files) {
|
||||
val fileName = file.virtualFilePath
|
||||
val owner =
|
||||
((irExpression as? IrGetFieldImpl)?.symbol?.signature as? IdSignature.CompositeSignature)?.container?.asPublic()?.firstNameSegment
|
||||
?: continue
|
||||
val name = field.name.asString()
|
||||
val constType = value.kind.toString()
|
||||
|
||||
inlineConstTracker.report(
|
||||
fileName,
|
||||
listOf(ConstantRef(owner, name, constType))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun IrExpression.shouldDropConstReceiver() =
|
||||
this is IrConst<*> || this is IrGetValue ||
|
||||
this is IrGetObjectValue
|
||||
|
||||
Reference in New Issue
Block a user