diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/Dce.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/Dce.kt index 4a2ec20fbd8..5acb009bc9d 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/Dce.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/Dce.kt @@ -78,6 +78,8 @@ private fun removeUselessDeclarations(module: IrModuleFragment, usefulDeclaratio process(declaration) } + // TODO bring back the primary constructor fix + private fun process(container: IrDeclarationContainer) { container.declarations.transformFlat { member -> if (member !in usefulDeclarations) { @@ -143,6 +145,7 @@ fun usefulDeclarations(roots: Iterable, context: JsIrBackendConte while (queue.isNotEmpty()) { val declaration = queue.pollFirst() + // TODO remove? stageController.lazyLower(declaration) if (declaration is IrClass) { @@ -188,6 +191,7 @@ fun usefulDeclarations(roots: Iterable, context: JsIrBackendConte else -> null } + // TODO remove? (body as? IrBody)?.let { stageController.lazyLower(it) } body?.acceptVoid(object : IrElementVisitorVoid { @@ -285,6 +289,7 @@ fun usefulDeclarations(roots: Iterable, context: JsIrBackendConte } } + // TODO is this needed? for (declaration in ArrayList(klass.declarations)) { // TODO this is a hack. if (declaration is IrProperty) { @@ -293,6 +298,7 @@ fun usefulDeclarations(roots: Iterable, context: JsIrBackendConte } } + // TODO deduplicate // Special hack for `IntrinsicsJs.kt` support if (klass.superTypes.any { it.isSuspendFunctionTypeOrSubtype() }) { ArrayList(klass.declarations).forEach { diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIrBackendContext.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIrBackendContext.kt index 790dc106f53..0f25f6edd64 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIrBackendContext.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIrBackendContext.kt @@ -356,4 +356,5 @@ class JsIrBackendContext( } } +// TODO: investigate if it could be removed fun lazy2(fn: () -> T) = lazy { stageController.withInitialIr(fn) } \ No newline at end of file diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsLoweringPhases.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsLoweringPhases.kt index a70f7ec0a77..ec7864922e7 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsLoweringPhases.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsLoweringPhases.kt @@ -641,8 +641,10 @@ val loweringList = listOf( validateIrAfterLowering ) +// TODO comment? Eliminate MouduleLowering's? Don't filter them here? val pirLowerings = loweringList.filter { it is DeclarationLowering || it is BodyLowering } + staticMembersLoweringPhase +// TODO `fold` -> `reduce` val jsPhases = namedIrModulePhase( name = "IrModuleLowering", description = "IR module lowering", diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/MutableController.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/MutableController.kt index 8322f489746..2c12539d482 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/MutableController.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/MutableController.kt @@ -147,6 +147,7 @@ open class MutableController(val context: JsIrBackendContext, val lowerings: Lis override fun canModify(element: IrElement): Boolean { return true + // TODO fix and enable // return !restricted || restrictedToDeclaration === element || element is IrPersistingElementBase<*> && element.createdOn == currentStage } diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/compiler.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/compiler.kt index 43d81b2fd1a..bff0079cbd9 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/compiler.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/compiler.kt @@ -97,6 +97,7 @@ fun compile( eliminateDeadDeclarations(moduleFragment, context, mainFunction) + // TODO investigate whether this is needed anymore stageController = object : StageController { override val currentStage: Int = controller.currentStage } diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/IrFileToJsTransformer.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/IrFileToJsTransformer.kt index 9b2e305523e..38baf4a814a 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/IrFileToJsTransformer.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/IrFileToJsTransformer.kt @@ -15,7 +15,7 @@ class IrFileToJsTransformer : BaseIrElementToJsNodeTransformer>( override var parentField: IrDeclarationParent? = null + // TODO reduce boilerplate override var parent: IrDeclarationParent get() = getCarrier().parentField ?: throw UninitializedPropertyAccessException("Parent not initialized: $this") set(p) { @@ -84,6 +85,7 @@ abstract class IrPersistingElementBase>( var loweredUpTo = stageController.currentStage + // TODO Array? private var values: Array? = null val createdOn: Int = stageController.currentStage @@ -120,6 +122,7 @@ abstract class IrPersistingElementBase>( } } + // TODO naming? e.g. `mutableCarrier` protected fun setCarrier(): T { val stage = stageController.currentStage @@ -133,6 +136,7 @@ abstract class IrPersistingElementBase>( error("retrospective modification") } + // TODO move up? i.e. fast path if (stage == lastModified) { return this as T } else { diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/carriers/Carrier.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/carriers/Carrier.kt index fe9586dfeb5..4e2457f5e34 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/carriers/Carrier.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/carriers/Carrier.kt @@ -5,6 +5,8 @@ package org.jetbrains.kotlin.ir.declarations.impl.carriers +// TODO degenerify +// TODO degenerify interface Carrier> { val lastModified: Int diff --git a/js/js.translator/testData/typescript-export/visibility/visibility.kt b/js/js.translator/testData/typescript-export/visibility/visibility.kt index bd69c7e224e..6d63b345a2c 100644 --- a/js/js.translator/testData/typescript-export/visibility/visibility.kt +++ b/js/js.translator/testData/typescript-export/visibility/visibility.kt @@ -1,8 +1,10 @@ // TARGET_BACKEND: JS_IR -// SKIP_DCE_DRIVEN // CHECK_TYPESCRIPT_DECLARATIONS // RUN_PLAIN_BOX_FUNCTION +// TODO fix statics export in DCE-driven mode +// SKIP_DCE_DRIVEN + @file:JsExport internal val internalVal = 10