[JS IR] Add properties lazy initialization with multiple modules

[JS IR] Move tests into compiler/testData

[JS IR] Add cyclic dependencies with lazy property initialization

[JS IR] Add test on not initialization in case of call non properties (classed, objects, enum classes, const vals)

[JS IR] Add initialization through top level

[JS IR] Ignore enum getInstance function in property lazy initialization

[JS IR] Use let function with useful result instead of pure apply and also

[JS IR] Remove duplicated tests in js.translator
This commit is contained in:
Ilya Goncharov
2020-11-24 17:19:15 +03:00
parent 6cb573cb45
commit 697b2b02f1
19 changed files with 335 additions and 67 deletions
@@ -47,9 +47,11 @@ class PropertyLazyInitLowering(
return
}
if (container !is IrSimpleFunction && container !is IrField && container !is IrProperty)
if (container !is IrField && container !is IrSimpleFunction && container !is IrProperty)
return
if (container.origin !in compatibleOrigins) return
val file = container.parent as? IrFile
?: return
@@ -224,6 +226,8 @@ class RemoveInitializersForLazyProperties(
if (declaration !is IrField) return null
if (!declaration.isCompatibleDeclaration()) return null
val file = declaration.parent as? IrFile ?: return null
if (fileToInitializerPureness[file] == true) return null
@@ -257,6 +261,7 @@ class RemoveInitializersForLazyProperties(
private fun calculateFieldToExpression(declarations: Collection<IrDeclaration>): Map<IrField, IrExpression> =
declarations
.asSequence()
.filter { it.isCompatibleDeclaration() }
.map { it.correspondingProperty }
.filterNotNull()
.filter { it.isForLazyInit() }
@@ -288,4 +293,14 @@ private val IrDeclaration.correspondingProperty: IrProperty?
private fun IrDeclaration.propertyWithPersistentSafe(transform: IrDeclaration.() -> IrProperty?): IrProperty? =
if (((this as? PersistentIrElementBase<*>)?.createdOn ?: 0) <= stageController.currentStage) {
transform()
} else null
} else null
private fun IrDeclaration.isCompatibleDeclaration() =
origin in compatibleOrigins
private val compatibleOrigins = listOf(
IrDeclarationOrigin.DEFINED,
IrDeclarationOrigin.DELEGATED_PROPERTY_ACCESSOR,
IrDeclarationOrigin.DEFAULT_PROPERTY_ACCESSOR,
IrDeclarationOrigin.PROPERTY_BACKING_FIELD,
)