6
6
package org.jetbrains.kotlin.backend.common.phaser
7
7
8
8
import org.jetbrains.kotlin.backend.common.*
9
+ import org.jetbrains.kotlin.backend.common.checkers.declaration.IrFieldVisibilityChecker
10
+ import org.jetbrains.kotlin.backend.common.checkers.declaration.IrExpressionBodyInFunctionChecker
11
+ import org.jetbrains.kotlin.backend.common.checkers.declaration.IrPrivateDeclarationOverrideChecker
12
+ import org.jetbrains.kotlin.backend.common.checkers.expression.IrCrossFileFieldUsageChecker
13
+ import org.jetbrains.kotlin.backend.common.checkers.expression.IrValueAccessScopeChecker
9
14
import org.jetbrains.kotlin.backend.common.checkers.expression.InlineFunctionUseSiteChecker
15
+ import org.jetbrains.kotlin.backend.common.checkers.symbol.IrVisibilityChecker
16
+ import org.jetbrains.kotlin.backend.common.withBasicChecks
17
+ import org.jetbrains.kotlin.backend.common.withInlineFunctionCallsiteCheck
18
+ import org.jetbrains.kotlin.backend.common.withVarargChecks
10
19
import org.jetbrains.kotlin.config.*
11
20
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
21
+ import org.jetbrains.kotlin.utils.addToStdlib.applyIf
12
22
13
23
abstract class IrValidationPhase <Context : LoweringContext >(val context : Context ) : ModuleLoweringPass {
14
24
protected abstract val defaultValidationConfig: IrValidatorConfig
@@ -30,73 +40,79 @@ abstract class IrValidationPhase<Context : LoweringContext>(val context: Context
30
40
protected open fun IrValidationContext.additionalValidation (irModule : IrModuleFragment , phaseName : String ) {}
31
41
}
32
42
33
- @PhaseDescription(name = " ValidateIrBeforeLowering" )
34
43
abstract class IrValidationBeforeLoweringPhase <Context : LoweringContext >(context : Context ) : IrValidationPhase<Context>(context) {
35
44
override val defaultValidationConfig: IrValidatorConfig
36
- get() = IrValidatorConfig (
37
- checkTypes = false , // TODO: Re-enable checking types (KT-68663)
38
- checkValueScopes = true ,
39
- 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
- )
45
+ get() = IrValidatorConfig (checkTreeConsistency = true , checkUnboundSymbols = true )
46
+ .withBasicChecks()
47
+ .withCheckers(IrValueAccessScopeChecker )
48
+ // .withTypeChecks() // TODO: Re-enable checking types (KT-68663)
49
+ // .withCheckers(IrTypeParameterScopeChecker) // TODO: Re-enable checking out-of-scope type parameter usages (KT-69305)
50
+ .applyIf(context.configuration.enableIrVisibilityChecks) {
51
+ withCheckers(IrVisibilityChecker )
52
+ }
53
+ .applyIf(context.configuration.enableIrVarargTypesChecks) {
54
+ withVarargChecks()
55
+ }
44
56
}
45
57
46
58
class KlibIrValidationBeforeLoweringPhase <Context : LoweringContext >(context : Context ) : IrValidationBeforeLoweringPhase<Context>(context) {
47
59
override val defaultValidationConfig: IrValidatorConfig
48
- get() = super .defaultValidationConfig.copy(
49
- checkCrossFileFieldUsage = context.configuration.getBoolean(CommonConfigurationKeys .ENABLE_IR_VISIBILITY_CHECKS ),
50
- // FIXME(KT-71243): This should be true, but currently the ExplicitBackingFields feature de-facto allows specifying
51
- // non-private visibilities for fields.
52
- checkAllKotlinFieldsArePrivate = context.configuration.getBoolean(CommonConfigurationKeys .ENABLE_IR_VISIBILITY_CHECKS ) &&
53
- ! context.configuration.languageVersionSettings.supportsFeature(LanguageFeature .ExplicitBackingFields ),
54
- checkIrExpressionBodyInFunction = true ,
55
- )
60
+ get() = super .defaultValidationConfig
61
+ .applyIf(context.configuration.enableIrVisibilityChecks) {
62
+ withCheckers(IrCrossFileFieldUsageChecker )
63
+ // FIXME(KT-71243): This checker should be added unconditionally, but currently the ExplicitBackingFields feature de-facto allows specifying
64
+ // non-private visibilities for fields.
65
+ .applyIf(! context.configuration.languageVersionSettings.supportsFeature(LanguageFeature .ExplicitBackingFields )) {
66
+ withCheckers(IrFieldVisibilityChecker )
67
+ }
68
+ }
69
+ .withCheckers(IrExpressionBodyInFunctionChecker )
56
70
}
57
71
72
+
58
73
@PhaseDescription(name = " IrValidationAfterInliningOnlyPrivateFunctionsPhase" )
59
74
class IrValidationAfterInliningOnlyPrivateFunctionsPhase <Context : LoweringContext >(
60
75
context : Context ,
61
- private val checkInlineFunctionCallSites : InlineFunctionUseSiteChecker
76
+ private val checkInlineFunctionCallSites : InlineFunctionUseSiteChecker ,
62
77
) : IrValidationPhase<Context>(context) {
63
78
override val defaultValidationConfig: IrValidatorConfig
64
- get() = IrValidatorConfig (
65
- checkTypes = false , // TODO: Re-enable checking types (KT-68663)
66
- checkVisibilities = false , // TODO: Enable checking visibilities (KT-69516)
67
- checkInlineFunctionUseSites = checkInlineFunctionCallSites,
68
- checkVarargTypes = context.configuration.getBoolean(CommonConfigurationKeys .ENABLE_IR_VARARG_TYPES_CHECKS ),
69
- )
79
+ get() = IrValidatorConfig (checkTreeConsistency = true )
80
+ .withBasicChecks()
81
+ // .withVisibilityChecks() // TODO: Enable checking visibilities (KT-69516)
82
+ // .withTypeChecks() // TODO: Re-enable checking types (KT-68663)
83
+ .applyIf(context.configuration.enableIrVarargTypesChecks) {
84
+ withVarargChecks()
85
+ }
86
+ .withInlineFunctionCallsiteCheck(checkInlineFunctionCallSites)
70
87
}
71
88
72
89
class IrValidationAfterInliningAllFunctionsOnTheSecondStagePhase <Context : LoweringContext >(
73
90
context : Context ,
74
- private val checkInlineFunctionCallSites : InlineFunctionUseSiteChecker ? = null
91
+ private val checkInlineFunctionCallSites : InlineFunctionUseSiteChecker ? = null ,
75
92
) : IrValidationPhase<Context>(context) {
76
93
override val defaultValidationConfig: IrValidatorConfig
77
- get() = IrValidatorConfig (
78
- checkTypes = false , // TODO: Re-enable checking types (KT-68663)
79
- checkValueScopes = context.configuration.enableIrVisibilityChecks,
80
- checkCrossFileFieldUsage = context.configuration.enableIrVisibilityChecks,
81
- checkTypeParameterScopes = false ,
82
- checkVisibilities = context.configuration.enableIrVisibilityChecks,
83
- checkInlineFunctionUseSites = checkInlineFunctionCallSites,
84
- checkVarargTypes = context.configuration.enableIrVarargTypesChecks,
85
- )
94
+ get() = IrValidatorConfig (checkTreeConsistency = true )
95
+ // .withTypeChecks() // TODO: Re-enable checking types (KT-68663)
96
+ .applyIf( context.configuration.enableIrVisibilityChecks) {
97
+ withCheckers( IrVisibilityChecker , IrCrossFileFieldUsageChecker , IrValueAccessScopeChecker )
98
+ }
99
+ .applyIf( context.configuration.enableIrVarargTypesChecks) {
100
+ withVarargChecks()
101
+ }
102
+ .withInlineFunctionCallsiteCheck(checkInlineFunctionCallSites )
86
103
}
87
104
88
105
class IrValidationAfterInliningAllFunctionsOnTheFirstStagePhase <Context : LoweringContext >(
89
106
context : Context ,
90
107
private val checkInlineFunctionCallSites : InlineFunctionUseSiteChecker ? = null
91
108
) : IrValidationPhase<Context>(context) {
92
109
override val defaultValidationConfig: IrValidatorConfig
93
- get() = IrValidatorConfig (
94
- checkInlineFunctionUseSites = checkInlineFunctionCallSites,
95
- checkOverridePrivateDeclaration = false ,
96
- )
110
+ get() = IrValidatorConfig ()
111
+ .withBasicChecks().withoutCheckers(IrPrivateDeclarationOverrideChecker )
112
+ .withInlineFunctionCallsiteCheck(checkInlineFunctionCallSites)
97
113
}
98
114
99
115
open class IrValidationAfterLoweringPhase <Context : LoweringContext >(context : Context ) : IrValidationPhase<Context>(context) {
100
116
override val defaultValidationConfig: IrValidatorConfig
101
- get() = IrValidatorConfig ()
117
+ get() = IrValidatorConfig (checkTreeConsistency = true )
102
118
}
0 commit comments