Skip to content

Commit 822da80

Browse files
mcpiromanSpace Team
authored andcommitted
[IR] Extract KlibIrValidationBeforeLoweringPhase
It's cleaner to add checks in the JVM backends rather than remove them.
1 parent 53b0c8b commit 822da80

File tree

5 files changed

+17
-14
lines changed

5 files changed

+17
-14
lines changed

compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/phaser/IrValidationPhase.kt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package org.jetbrains.kotlin.backend.common.phaser
77

88
import org.jetbrains.kotlin.backend.common.*
9+
import org.jetbrains.kotlin.backend.common.checkers.expression.InlineFunctionUseSiteChecker
910
import org.jetbrains.kotlin.config.*
1011
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
1112

@@ -30,19 +31,27 @@ abstract class IrValidationPhase<Context : LoweringContext>(val context: Context
3031
}
3132

3233
@PhaseDescription(name = "ValidateIrBeforeLowering")
33-
open class IrValidationBeforeLoweringPhase<Context : LoweringContext>(context: Context) : IrValidationPhase<Context>(context) {
34+
abstract class IrValidationBeforeLoweringPhase<Context : LoweringContext>(context: Context) : IrValidationPhase<Context>(context) {
3435
override val defaultValidationConfig: IrValidatorConfig
3536
get() = IrValidatorConfig(
3637
checkTypes = false, // TODO: Re-enable checking types (KT-68663)
3738
checkValueScopes = true,
3839
checkTypeParameterScopes = false, // TODO: Re-enable checking out-of-scope type parameter usages (KT-69305)
40+
checkVisibilities = context.configuration.getBoolean(CommonConfigurationKeys.ENABLE_IR_VISIBILITY_CHECKS),
41+
checkVarargTypes = context.configuration.getBoolean(CommonConfigurationKeys.ENABLE_IR_VARARG_TYPES_CHECKS),
42+
checkIrExpressionBodyInFunction = false,
43+
)
44+
}
45+
46+
class KlibIrValidationBeforeLoweringPhase<Context : LoweringContext>(context: Context) : IrValidationBeforeLoweringPhase<Context>(context) {
47+
override val defaultValidationConfig: IrValidatorConfig
48+
get() = super.defaultValidationConfig.copy(
3949
checkCrossFileFieldUsage = context.configuration.getBoolean(CommonConfigurationKeys.ENABLE_IR_VISIBILITY_CHECKS),
4050
// FIXME(KT-71243): This should be true, but currently the ExplicitBackingFields feature de-facto allows specifying
4151
// non-private visibilities for fields.
4252
checkAllKotlinFieldsArePrivate = context.configuration.getBoolean(CommonConfigurationKeys.ENABLE_IR_VISIBILITY_CHECKS) &&
4353
!context.configuration.languageVersionSettings.supportsFeature(LanguageFeature.ExplicitBackingFields),
44-
checkVisibilities = context.configuration.getBoolean(CommonConfigurationKeys.ENABLE_IR_VISIBILITY_CHECKS),
45-
checkVarargTypes = context.configuration.getBoolean(CommonConfigurationKeys.ENABLE_IR_VARARG_TYPES_CHECKS),
54+
checkIrExpressionBodyInFunction = true,
4655
)
4756
}
4857

compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsLoweringPhases.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import org.jetbrains.kotlin.ir.interpreter.IrInterpreterConfiguration
3636
import org.jetbrains.kotlin.platform.js.JsPlatforms
3737

3838
private val validateIrBeforeLowering = makeIrModulePhase(
39-
::IrValidationBeforeLoweringPhase,
39+
::KlibIrValidationBeforeLoweringPhase,
4040
name = "ValidateIrBeforeLowering",
4141
)
4242

compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/irValidation.kt

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,7 @@ import org.jetbrains.kotlin.ir.visitors.acceptVoid
2424
@PhaseDescription(name = "JvmValidateIrBeforeLowering")
2525
internal class JvmIrValidationBeforeLoweringPhase(
2626
context: JvmBackendContext
27-
) : IrValidationBeforeLoweringPhase<JvmBackendContext>(context) {
28-
override val defaultValidationConfig: IrValidatorConfig
29-
get() = super.defaultValidationConfig.copy(
30-
checkCrossFileFieldUsage = false,
31-
checkAllKotlinFieldsArePrivate = false,
32-
checkIrExpressionBodyInFunction = false,
33-
)
34-
}
27+
) : IrValidationBeforeLoweringPhase<JvmBackendContext>(context)
3528

3629
@PhaseDescription(name = "JvmValidateIrAfterLowering")
3730
internal class JvmIrValidationAfterLoweringPhase(

compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/WasmLoweringPhases.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ private fun List<CompilerPhase<WasmBackendContext, IrModuleFragment, IrModuleFra
3434
reduce { acc, lowering -> acc.then(lowering) }
3535

3636
private val validateIrBeforeLowering = makeIrModulePhase(
37-
::IrValidationBeforeLoweringPhase,
37+
::KlibIrValidationBeforeLoweringPhase,
3838
name = "ValidateIrBeforeLowering",
3939
)
4040

kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/driver/phases/NativeLoweringPhases.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.backend.common.lower.inline.LocalClassesInInlineLamb
1515
import org.jetbrains.kotlin.backend.common.lower.optimizations.PropertyAccessorInlineLowering
1616
import org.jetbrains.kotlin.backend.common.lower.optimizations.LivenessAnalysis
1717
import org.jetbrains.kotlin.backend.common.phaser.*
18+
import org.jetbrains.kotlin.backend.common.phaser.KlibIrValidationBeforeLoweringPhase
1819
import org.jetbrains.kotlin.backend.common.runOnFilePostfix
1920
import org.jetbrains.kotlin.backend.common.wrapWithCompilationException
2021
import org.jetbrains.kotlin.backend.konan.*
@@ -72,7 +73,7 @@ internal fun PhaseEngine<NativeGenerationState>.runModuleWisePhase(
7273

7374
internal val validateIrBeforeLowering = createSimpleNamedCompilerPhase<NativeGenerationState, IrModuleFragment>(
7475
name = "ValidateIrBeforeLowering",
75-
op = { context, module -> IrValidationBeforeLoweringPhase(context.context).lower(module) }
76+
op = { context, module -> KlibIrValidationBeforeLoweringPhase(context.context).lower(module) }
7677
)
7778

7879
internal val validateIrAfterInliningOnlyPrivateFunctions = createSimpleNamedCompilerPhase<NativeGenerationState, IrModuleFragment>(

0 commit comments

Comments
 (0)