[JS IR] Use a backing field initializer for js() code folding
During a translation of the code from js() call to statement list, the compiler folds the code string. For that it uses property bodies. However the bodies can not be loaded in an incremental rebuild. The patch uses the backing field initializers of constant properties. The initializers are always loaded. ^KT-57002 Fixed
This commit is contained in:
committed by
Space Team
parent
c91ef606f7
commit
f82d3e63a2
+6
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.ir.backend.js.transformers.irToJs.CrossModuleReferen
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.declarations.IrAnnotationContainer
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||
import org.jetbrains.kotlin.ir.declarations.IrProperty
|
||||
import org.jetbrains.kotlin.ir.declarations.IrTypeParametersContainer
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
||||
import org.jetbrains.kotlin.ir.util.DumpIrTreeVisitor
|
||||
@@ -131,6 +132,11 @@ internal class ICHasher {
|
||||
}
|
||||
}
|
||||
(symbol.owner as? IrAnnotationContainer)?.let(hashCalculator::updateAnnotationContainer)
|
||||
(symbol.owner as? IrProperty)?.let { irProperty ->
|
||||
if (irProperty.isConst) {
|
||||
irProperty.backingField?.initializer?.let(hashCalculator::update)
|
||||
}
|
||||
}
|
||||
return hashCalculator.finalize()
|
||||
}
|
||||
}
|
||||
|
||||
+13
-3
@@ -63,7 +63,7 @@ private fun translateJsCodeIntoStatementList(
|
||||
return parseExpressionOrStatement(jsCode, ThrowExceptionOnErrorReporter, currentScope, CodePosition(startLine, offset), fileName)
|
||||
}
|
||||
|
||||
fun foldString(expression: IrExpression, context: JsIrBackendContext?): String? {
|
||||
private fun foldString(expression: IrExpression, context: JsIrBackendContext?): String? {
|
||||
val builder = StringBuilder()
|
||||
var foldingFailed = false
|
||||
expression.acceptVoid(object : IrElementVisitorVoid {
|
||||
@@ -92,6 +92,7 @@ fun foldString(expression: IrExpression, context: JsIrBackendContext?): String?
|
||||
|
||||
override fun visitCall(expression: IrCall) {
|
||||
val owner = expression.symbol.owner
|
||||
val propertySymbol = owner.correspondingPropertySymbol
|
||||
return when {
|
||||
expression.origin == IrStatementOrigin.PLUS ->
|
||||
expression.acceptChildrenVoid(this)
|
||||
@@ -99,8 +100,17 @@ fun foldString(expression: IrExpression, context: JsIrBackendContext?): String?
|
||||
owner.body?.acceptChildrenVoid(InitFunVisitor(context))
|
||||
expression.acceptChildrenVoid(this)
|
||||
}
|
||||
owner == owner.correspondingPropertySymbol?.owner?.getter -> {
|
||||
owner.body?.acceptChildrenVoid(this)
|
||||
propertySymbol != null && owner == propertySymbol.owner.getter -> {
|
||||
if (propertySymbol.owner.isConst) {
|
||||
val initializer = propertySymbol.owner.backingField?.initializer
|
||||
if (initializer != null) {
|
||||
initializer.acceptChildrenVoid(this)
|
||||
} else {
|
||||
foldingFailed = true
|
||||
}
|
||||
} else {
|
||||
owner.body?.acceptChildrenVoid(this)
|
||||
}
|
||||
expression.acceptChildrenVoid(this)
|
||||
}
|
||||
else -> super.visitCall(expression)
|
||||
|
||||
Reference in New Issue
Block a user