Skip to content

Commit 50cf771

Browse files
ddolovovSpace Team
authored andcommitted
[CLI] New CLI parameter to enable nested IR element offsets checks
^KT-81475
1 parent 0db2509 commit 50cf771

File tree

10 files changed

+83
-0
lines changed

10 files changed

+83
-0
lines changed

compiler/arguments/resources/kotlin-compiler-arguments.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3672,6 +3672,37 @@
36723672
"removedVersion": null
36733673
}
36743674
},
3675+
{
3676+
"name": "Xverify-ir-nested-offsets",
3677+
"shortName": null,
3678+
"deprecatedName": null,
3679+
"description": {
3680+
"current": "Check that offsets of nested IR elements conform to offsets of their containers. Only has effect if '-Xverify-ir' is not 'none'.",
3681+
"valueInVersions": []
3682+
},
3683+
"delimiter": null,
3684+
"valueType": {
3685+
"type": "org.jetbrains.kotlin.arguments.dsl.types.BooleanType",
3686+
"isNullable": {
3687+
"current": false,
3688+
"valueInVersions": []
3689+
},
3690+
"defaultValue": {
3691+
"current": false,
3692+
"valueInVersions": []
3693+
}
3694+
},
3695+
"valueDescription": {
3696+
"current": null,
3697+
"valueInVersions": []
3698+
},
3699+
"releaseVersionsMetadata": {
3700+
"introducedVersion": "2.3.20",
3701+
"stabilizedVersion": null,
3702+
"deprecatedVersion": null,
3703+
"removedVersion": null
3704+
}
3705+
},
36753706
{
36763707
"name": "Xverify-ir-visibility",
36773708
"shortName": null,

compiler/arguments/src/org/jetbrains/kotlin/arguments/description/CommonCompilerArguments.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,18 @@ val actualCommonCompilerArguments by compilerArgumentsLevel(CompilerArgumentsLev
511511
}
512512

513513

514+
compilerArgument {
515+
name = "Xverify-ir-nested-offsets"
516+
description =
517+
"Check that offsets of nested IR elements conform to offsets of their containers. Only has effect if '-Xverify-ir' is not 'none'.".asReleaseDependent()
518+
valueType = BooleanType.defaultFalse
519+
520+
lifecycle(
521+
introducedVersion = KotlinReleaseVersion.v2_3_20,
522+
)
523+
}
524+
525+
514526
compilerArgument {
515527
name = "Xprofile-phases"
516528
description = "Profile backend phases.".asReleaseDependent()

compiler/build-tools/kotlin-build-tools-api/api/kotlin-build-tools-api.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ public abstract interface class org/jetbrains/kotlin/buildtools/api/arguments/Co
237237
public static final field X_USE_FIR_LT Lorg/jetbrains/kotlin/buildtools/api/arguments/CommonCompilerArguments$CommonCompilerArgument;
238238
public static final field X_VERBOSE_PHASES Lorg/jetbrains/kotlin/buildtools/api/arguments/CommonCompilerArguments$CommonCompilerArgument;
239239
public static final field X_VERIFY_IR Lorg/jetbrains/kotlin/buildtools/api/arguments/CommonCompilerArguments$CommonCompilerArgument;
240+
public static final field X_VERIFY_IR_NESTED_OFFSETS Lorg/jetbrains/kotlin/buildtools/api/arguments/CommonCompilerArguments$CommonCompilerArgument;
240241
public static final field X_VERIFY_IR_VISIBILITY Lorg/jetbrains/kotlin/buildtools/api/arguments/CommonCompilerArguments$CommonCompilerArgument;
241242
public static final field X_WARNING_LEVEL Lorg/jetbrains/kotlin/buildtools/api/arguments/CommonCompilerArguments$CommonCompilerArgument;
242243
public static final field X_WHEN_GUARDS Lorg/jetbrains/kotlin/buildtools/api/arguments/CommonCompilerArguments$CommonCompilerArgument;

compiler/build-tools/kotlin-build-tools-api/gen/org/jetbrains/kotlin/buildtools/api/arguments/CommonCompilerArguments.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,16 @@ public interface CommonCompilerArguments : CommonToolArguments {
701701
public val X_VERIFY_IR: CommonCompilerArgument<String?> =
702702
CommonCompilerArgument("X_VERIFY_IR", KotlinReleaseVersion(2, 0, 20))
703703

704+
/**
705+
* Check that offsets of nested IR elements conform to offsets of their containers. Only has effect if '-Xverify-ir' is not 'none'.
706+
*
707+
* WARNING: this option is EXPERIMENTAL and it may be changed in the future without notice or may be removed entirely.
708+
*/
709+
@JvmField
710+
@ExperimentalCompilerArgument
711+
public val X_VERIFY_IR_NESTED_OFFSETS: CommonCompilerArgument<Boolean> =
712+
CommonCompilerArgument("X_VERIFY_IR_NESTED_OFFSETS", KotlinReleaseVersion(2, 3, 20))
713+
704714
/**
705715
* Check for visibility violations in IR when validating it before running any lowerings. Only has effect if '-Xverify-ir' is not 'none'.
706716
*

compiler/build-tools/kotlin-build-tools-impl/gen/org/jetbrains/kotlin/buildtools/internal/arguments/CommonCompilerArgumentsImpl.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ import org.jetbrains.kotlin.buildtools.`internal`.arguments.CommonCompilerArgume
108108
import org.jetbrains.kotlin.buildtools.`internal`.arguments.CommonCompilerArgumentsImpl.Companion.X_USE_K2
109109
import org.jetbrains.kotlin.buildtools.`internal`.arguments.CommonCompilerArgumentsImpl.Companion.X_VERBOSE_PHASES
110110
import org.jetbrains.kotlin.buildtools.`internal`.arguments.CommonCompilerArgumentsImpl.Companion.X_VERIFY_IR
111+
import org.jetbrains.kotlin.buildtools.`internal`.arguments.CommonCompilerArgumentsImpl.Companion.X_VERIFY_IR_NESTED_OFFSETS
111112
import org.jetbrains.kotlin.buildtools.`internal`.arguments.CommonCompilerArgumentsImpl.Companion.X_VERIFY_IR_VISIBILITY
112113
import org.jetbrains.kotlin.buildtools.`internal`.arguments.CommonCompilerArgumentsImpl.Companion.X_WARNING_LEVEL
113114
import org.jetbrains.kotlin.buildtools.`internal`.arguments.CommonCompilerArgumentsImpl.Companion.X_WHEN_GUARDS
@@ -241,6 +242,7 @@ internal abstract class CommonCompilerArgumentsImpl : CommonToolArgumentsImpl(),
241242
try { if (X_USE_K2 in this) { arguments.setUsingReflection("useK2", get(X_USE_K2))} } catch (e: NoSuchMethodError) { throw IllegalStateException("""Compiler parameter not recognized: X_USE_K2. Current compiler version is: $KC_VERSION, but the argument was removed in 2.2.0""").initCause(e) }
242243
if (X_VERBOSE_PHASES in this) { arguments.verbosePhases = get(X_VERBOSE_PHASES)}
243244
if (X_VERIFY_IR in this) { arguments.verifyIr = get(X_VERIFY_IR)}
245+
if (X_VERIFY_IR_NESTED_OFFSETS in this) { arguments.verifyIrNestedOffsets = get(X_VERIFY_IR_NESTED_OFFSETS)}
244246
if (X_VERIFY_IR_VISIBILITY in this) { arguments.verifyIrVisibility = get(X_VERIFY_IR_VISIBILITY)}
245247
if (X_WARNING_LEVEL in this) { arguments.warningLevels = get(X_WARNING_LEVEL)}
246248
if (X_WHEN_GUARDS in this) { arguments.whenGuards = get(X_WHEN_GUARDS)}
@@ -341,6 +343,7 @@ internal abstract class CommonCompilerArgumentsImpl : CommonToolArgumentsImpl(),
341343
try { this[X_USE_K2] = arguments.getUsingReflection("useK2") } catch (_: NoSuchMethodError) { }
342344
try { this[X_VERBOSE_PHASES] = arguments.verbosePhases } catch (_: NoSuchMethodError) { }
343345
try { this[X_VERIFY_IR] = arguments.verifyIr } catch (_: NoSuchMethodError) { }
346+
try { this[X_VERIFY_IR_NESTED_OFFSETS] = arguments.verifyIrNestedOffsets } catch (_: NoSuchMethodError) { }
344347
try { this[X_VERIFY_IR_VISIBILITY] = arguments.verifyIrVisibility } catch (_: NoSuchMethodError) { }
345348
try { this[X_WARNING_LEVEL] = arguments.warningLevels } catch (_: NoSuchMethodError) { }
346349
try { this[X_WHEN_GUARDS] = arguments.whenGuards } catch (_: NoSuchMethodError) { }
@@ -612,6 +615,9 @@ internal abstract class CommonCompilerArgumentsImpl : CommonToolArgumentsImpl(),
612615

613616
public val X_VERIFY_IR: CommonCompilerArgument<String?> = CommonCompilerArgument("X_VERIFY_IR")
614617

618+
public val X_VERIFY_IR_NESTED_OFFSETS: CommonCompilerArgument<Boolean> =
619+
CommonCompilerArgument("X_VERIFY_IR_NESTED_OFFSETS")
620+
615621
public val X_VERIFY_IR_VISIBILITY: CommonCompilerArgument<Boolean> =
616622
CommonCompilerArgument("X_VERIFY_IR_VISIBILITY")
617623

compiler/cli/cli-common/gen/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,16 @@ Warning: This feature is not yet production-ready.""",
976976
field = if (value.isNullOrEmpty()) null else value
977977
}
978978

979+
@Argument(
980+
value = "-Xverify-ir-nested-offsets",
981+
description = "Check that offsets of nested IR elements conform to offsets of their containers. Only has effect if '-Xverify-ir' is not 'none'.",
982+
)
983+
var verifyIrNestedOffsets: Boolean = false
984+
set(value) {
985+
checkFrozen()
986+
field = value
987+
}
988+
979989
@Argument(
980990
value = "-Xverify-ir-visibility",
981991
description = "Check for visibility violations in IR when validating it before running any lowerings. Only has effect if '-Xverify-ir' is not 'none'.",

compiler/cli/cli-common/gen/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArgumentsCopyGenerated.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ fun copyCommonCompilerArguments(from: CommonCompilerArguments, to: CommonCompile
104104
to.useK2 = from.useK2
105105
to.verbosePhases = from.verbosePhases?.copyOf()
106106
to.verifyIr = from.verifyIr
107+
to.verifyIrNestedOffsets = from.verifyIrNestedOffsets
107108
to.verifyIrVisibility = from.verifyIrVisibility
108109
to.warningLevels = from.warningLevels?.copyOf()
109110
to.whenGuards = from.whenGuards

compiler/cli/src/org/jetbrains/kotlin/cli/common/arguments.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ fun CompilerConfiguration.setupCommonArguments(
6363
}
6464
}
6565

66+
if (arguments.verifyIrNestedOffsets) {
67+
put(CommonConfigurationKeys.ENABLE_IR_NESTED_OFFSETS_CHECKS, true)
68+
if (irVerificationMode == IrVerificationMode.NONE) {
69+
messageCollector.report(
70+
CompilerMessageSeverity.WARNING,
71+
"'-Xverify-ir-nested-offsets' has no effect unless '-Xverify-ir=warning' or '-Xverify-ir=error' is specified"
72+
)
73+
}
74+
}
75+
6676
@Suppress("DEPRECATION")
6777
if (arguments.useFirExperimentalCheckers) {
6878
put(CommonConfigurationKeys.USE_FIR_EXPERIMENTAL_CHECKERS, true)

compiler/testData/cli/js/jsExtraHelp.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ where advanced options include:
221221
-Xverbose-phases Be verbose while performing the given backend phases.
222222
-Xverify-ir={none|warning|error}
223223
IR verification mode (no verification by default).
224+
-Xverify-ir-nested-offsets Check that offsets of nested IR elements conform to offsets of their containers. Only has effect if '-Xverify-ir' is not 'none'.
224225
-Xverify-ir-visibility Check for visibility violations in IR when validating it before running any lowerings. Only has effect if '-Xverify-ir' is not 'none'.
225226
-Xwarning-level=<WARNING_NAME>:(error|warning|disabled)
226227
Set the severity of the given warning.

compiler/testData/cli/jvm/extraHelp.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ where advanced options include:
278278
-Xverbose-phases Be verbose while performing the given backend phases.
279279
-Xverify-ir={none|warning|error}
280280
IR verification mode (no verification by default).
281+
-Xverify-ir-nested-offsets Check that offsets of nested IR elements conform to offsets of their containers. Only has effect if '-Xverify-ir' is not 'none'.
281282
-Xverify-ir-visibility Check for visibility violations in IR when validating it before running any lowerings. Only has effect if '-Xverify-ir' is not 'none'.
282283
-Xwarning-level=<WARNING_NAME>:(error|warning|disabled)
283284
Set the severity of the given warning.

0 commit comments

Comments
 (0)