[JS IR]Add check on pureness to not calculate fields to expression twice
^KT-43222 fixed
This commit is contained in:
@@ -8,8 +8,6 @@ package org.jetbrains.kotlin.ir.backend.js
|
||||
import org.jetbrains.kotlin.backend.common.DefaultMapping
|
||||
import org.jetbrains.kotlin.backend.common.Mapping
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
|
||||
|
||||
class JsMapping : DefaultMapping() {
|
||||
val outerThisFieldSymbols = newMapping<IrClass, IrField>()
|
||||
@@ -32,8 +30,6 @@ class JsMapping : DefaultMapping() {
|
||||
val enumEntryToCorrespondingField = newMapping<IrEnumEntry, IrField>()
|
||||
val enumClassToInitEntryInstancesFun = newMapping<IrClass, IrSimpleFunction>()
|
||||
|
||||
val lazyInitialisedFields = newMapping<IrField, IrExpression>()
|
||||
|
||||
// Triggers `StageController.lazyLower` on access
|
||||
override fun <K : IrDeclaration, V> newMapping(): Mapping.Delegate<K, V> = object : Mapping.Delegate<K, V>() {
|
||||
private val map: MutableMap<K, V> = mutableMapOf()
|
||||
|
||||
+8
-5
@@ -51,11 +51,13 @@ class PropertyLazyInitLowering(
|
||||
val file = container.parent as? IrFile
|
||||
?: return
|
||||
|
||||
val initFun = (if (file in fileToInitialisationFuns) {
|
||||
fileToInitialisationFuns[file]
|
||||
} else {
|
||||
createInitialisationFunction(file).also {
|
||||
fileToInitialisationFuns[file] = it
|
||||
val initFun = (when {
|
||||
file in fileToInitialisationFuns -> fileToInitialisationFuns[file]
|
||||
fileToPurenessInitializers[file] == true -> null
|
||||
else -> {
|
||||
createInitialisationFunction(file).also {
|
||||
fileToInitialisationFuns[file] = it
|
||||
}
|
||||
}
|
||||
}) ?: return
|
||||
|
||||
@@ -95,6 +97,7 @@ class PropertyLazyInitLowering(
|
||||
if (fieldToInitializer.isEmpty()) return null
|
||||
|
||||
val allFieldsInFilePure = allFieldsInFilePure(fieldToInitializer.values)
|
||||
fileToPurenessInitializers[file] = allFieldsInFilePure
|
||||
if (allFieldsInFilePure) {
|
||||
return null
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user