IR: IrTypeAlias: Strip 'typealias' declarations in back-ends
This commit is contained in:
+44
@@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.backend.common.lower
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.backend.common.FileLoweringPass
|
||||||
|
import org.jetbrains.kotlin.ir.IrElement
|
||||||
|
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||||
|
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||||
|
import org.jetbrains.kotlin.ir.declarations.IrTypeAlias
|
||||||
|
import org.jetbrains.kotlin.ir.expressions.IrContainerExpression
|
||||||
|
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
|
||||||
|
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
|
||||||
|
import org.jetbrains.kotlin.ir.visitors.acceptVoid
|
||||||
|
|
||||||
|
class StripTypeAliasDeclarationsLowering :
|
||||||
|
IrElementVisitorVoid,
|
||||||
|
FileLoweringPass {
|
||||||
|
|
||||||
|
override fun lower(irFile: IrFile) {
|
||||||
|
irFile.acceptVoid(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun visitElement(element: IrElement) {
|
||||||
|
element.acceptChildrenVoid(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun visitFile(declaration: IrFile) {
|
||||||
|
declaration.acceptChildrenVoid(this)
|
||||||
|
declaration.declarations.removeAll { it is IrTypeAlias }
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun visitClass(declaration: IrClass) {
|
||||||
|
declaration.acceptChildrenVoid(this)
|
||||||
|
declaration.declarations.removeAll { it is IrTypeAlias }
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun visitContainerExpression(expression: IrContainerExpression) {
|
||||||
|
expression.acceptChildrenVoid(this)
|
||||||
|
expression.statements.removeAll { it is IrTypeAlias }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -98,6 +98,12 @@ private val lateinitLoweringPhase = makeJsModulePhase(
|
|||||||
description = "Insert checks for lateinit field references"
|
description = "Insert checks for lateinit field references"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
private val stripTypeAliasDeclarationsPhase = makeJsModulePhase(
|
||||||
|
{ StripTypeAliasDeclarationsLowering() },
|
||||||
|
name = "StripTypeAliasDeclarations",
|
||||||
|
description = "Strip typealias declarations"
|
||||||
|
)
|
||||||
|
|
||||||
// TODO make all lambda-related stuff work with IrFunctionExpression and drop this phase
|
// TODO make all lambda-related stuff work with IrFunctionExpression and drop this phase
|
||||||
private val provisionalFunctionExpressionPhase = makeJsModulePhase(
|
private val provisionalFunctionExpressionPhase = makeJsModulePhase(
|
||||||
{ ProvisionalFunctionExpressionLowering() },
|
{ ProvisionalFunctionExpressionLowering() },
|
||||||
@@ -396,6 +402,7 @@ val jsPhases = namedIrModulePhase(
|
|||||||
lower = validateIrBeforeLowering then
|
lower = validateIrBeforeLowering then
|
||||||
testGenerationPhase then
|
testGenerationPhase then
|
||||||
expectDeclarationsRemovingPhase then
|
expectDeclarationsRemovingPhase then
|
||||||
|
stripTypeAliasDeclarationsPhase then
|
||||||
provisionalFunctionExpressionPhase then
|
provisionalFunctionExpressionPhase then
|
||||||
arrayConstructorPhase then
|
arrayConstructorPhase then
|
||||||
functionInliningPhase then
|
functionInliningPhase then
|
||||||
|
|||||||
@@ -36,6 +36,12 @@ private fun makePatchParentsPhase(number: Int) = namedIrFilePhase(
|
|||||||
nlevels = 0
|
nlevels = 0
|
||||||
)
|
)
|
||||||
|
|
||||||
|
private val stripTypeAliasDeclarationsPhase = makeIrFilePhase<CommonBackendContext>(
|
||||||
|
{ StripTypeAliasDeclarationsLowering() },
|
||||||
|
name = "StripTypeAliasDeclarations",
|
||||||
|
description = "Strip typealias declarations"
|
||||||
|
)
|
||||||
|
|
||||||
// TODO make all lambda-related stuff work with IrFunctionExpression and drop this phase
|
// TODO make all lambda-related stuff work with IrFunctionExpression and drop this phase
|
||||||
private val provisionalFunctionExpressionPhase = makeIrFilePhase<CommonBackendContext>(
|
private val provisionalFunctionExpressionPhase = makeIrFilePhase<CommonBackendContext>(
|
||||||
{ ProvisionalFunctionExpressionLowering() },
|
{ ProvisionalFunctionExpressionLowering() },
|
||||||
@@ -106,6 +112,7 @@ private val innerClassesPhase = makeIrFilePhase(
|
|||||||
)
|
)
|
||||||
|
|
||||||
private val jvmFilePhases =
|
private val jvmFilePhases =
|
||||||
|
stripTypeAliasDeclarationsPhase then
|
||||||
provisionalFunctionExpressionPhase then
|
provisionalFunctionExpressionPhase then
|
||||||
inventNamesForLocalClassesPhase then
|
inventNamesForLocalClassesPhase then
|
||||||
kCallableNamePropertyPhase then
|
kCallableNamePropertyPhase then
|
||||||
|
|||||||
Reference in New Issue
Block a user