Skip to content

compiler: Print valid -Zmir-enable-passes names if invalid name is used#156059

Open
Enselic wants to merge 1 commit intorust-lang:mainfrom
Enselic:print-mir-passes
Open

compiler: Print valid -Zmir-enable-passes names if invalid name is used#156059
Enselic wants to merge 1 commit intorust-lang:mainfrom
Enselic:print-mir-passes

Conversation

@Enselic
Copy link
Copy Markdown
Member

@Enselic Enselic commented May 1, 2026

If a user passes an invalid name to -Zmir-enable-passes, print the valid names as a note.

To avoid the annoyance of having to keep blessing test output, completely normalize away the list of names in the test.

The diagnostic is duplicated, but that is not introduced by this commit. In other words, we don't make matters worse. The existing "is unknown and will be ignored" diagnostic is already duplicated, as can be seen in the existing test stderr.

The output is on one long line, but that makes normalization in tests easier, and I don't think we have to overdo this. We can let terminals wrap the line.

Click to expand current output

note: valid MIR pass names are: AbortUnwindingCalls, AddCallGuards, AddMovesForPackedDrops, AddRetag, CheckAlignment, CheckCallRecursion, CheckConstItemMutation, CheckDropRecursion, CheckEnums, CheckForceInline, CheckInlineAlwaysTargetFeature, CheckLiveDrops, CheckNull, CheckPackedRef, CleanupPostBorrowck, CopyProp, CtfeLimit, DataflowConstProp, DeadStoreElimination-final, DeadStoreElimination-initial, Derefer, DestinationPropagation, EarlyOtherwiseBranch, ElaborateBoxDerefs, ElaborateDrops, EnumSizeOpt, EraseDerefTemps, ForceInline, FunctionItemReferences, GVN, ImpossiblePredicates, Inline, InstSimplify-after-simplifycfg, InstSimplify-before-inline, InstrumentCoverage, JumpThreading, KnownPanicsLint, LowerIntrinsics, LowerSliceLenCalls, Marker, MatchBranchSimplification, MentionedItems, MultipleReturnTerminators, PostAnalysisNormalize, PreCodegen, PromoteTemps, ReferencePropagation, RemoveNoopLandingPads, RemovePlaceMention, RemoveStorageMarkers, RemoveUninitDrops, RemoveUnneededDrops, RemoveZsts, ReorderBasicBlocks, ReorderLocals, RequiredConstsVisitor, SanityCheck, ScalarReplacementOfAggregates, SimplifyCfg-after-unreachable-enum-branching, SimplifyCfg-final, SimplifyCfg-initial, SimplifyCfg-make_shim, SimplifyCfg-post-analysis, SimplifyCfg-pre-optimizations, SimplifyCfg-promote-consts, SimplifyCfg-remove-false-edges, SimplifyComparisonIntegral, SimplifyConstCondition-after-const-prop, SimplifyConstCondition-after-inst-simplify, SimplifyConstCondition-final, SimplifyLocals-after-value-numbering, SimplifyLocals-before-const-prop, SimplifyLocals-final, SingleUseConsts, SsaRangePropagation, StateTransform, StripDebugInfo, Subtyper, UnreachableEnumBranching, UnreachablePropagation, Validator

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 1, 2026
@Enselic Enselic marked this pull request as ready for review May 1, 2026 20:44
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 1, 2026

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 1, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 1, 2026

r? @mu001999

rustbot has assigned @mu001999.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 73 candidates
  • Random selection from 21 candidates

#[derive(Diagnostic)]
#[diag("valid MIR pass names are: {$valid_passes}")]
pub(crate) struct ValidPassNames {
pub(crate) valid_passes: String,
Copy link
Copy Markdown
Member

@mu001999 mu001999 May 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use &str here?

View changes since the review

Copy link
Copy Markdown
Member Author

@Enselic Enselic May 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could maybe create a complicated macro to generate the string we want at compile time, but IMHO that would be unnecessarily complicated, because we only need to allocate this string on error code paths (when the user passes an invalid MIR pass name). And doing it at runtime is simpler by probably two orders of magnitude.

Copy link
Copy Markdown
Member

@mu001999 mu001999 May 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about Vec<&'a str>

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. What do you think about using DiagSymbolList<&'a str>? We'd have

pub(crate) struct ValidPassNames<'a> {
    pub(crate) valid_passes: DiagSymbolList<&'a str>,
}

which would give diagnostics like this:

note: valid MIR pass names are: `AbortUnwindingCalls`, ..., `UnreachablePropagation`, and `Validator`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

…used

If a user passes an invalid name to `-Zmir-enable-passes`, print the
valid names as a note.

The diagnostic is duplicated, but that is not introduced by this commit.
In other words, we don't make matters worse. The existing "is unknown
and will be ignored" diagnostic is already duplicated.

To avoid the annoyance of having to keep blessing test output,
completely normalize away the list of names in the test.
@Enselic Enselic force-pushed the print-mir-passes branch from 36b7394 to e906d1f Compare May 2, 2026 06:32
Copy link
Copy Markdown
Member

@mu001999 mu001999 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 2, 2026

📌 Commit e906d1f has been approved by mu001999

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 2, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request May 2, 2026
compiler: Print valid `-Zmir-enable-passes` names if invalid name is used

If a user passes an invalid name to `-Zmir-enable-passes`, print the valid names as a note.

To avoid the annoyance of having to keep blessing test output, completely normalize away the list of names in the test.

The diagnostic is duplicated, but that is not introduced by this commit. In other words, we don't make matters worse. The existing "is unknown and will be ignored" diagnostic is already duplicated, as can be seen in the existing test stderr.

The output is on one long line, but that makes normalization in tests easier, and I don't think we have to overdo this. We can let terminals wrap the line.

<details>

<summary>Click to expand current output</summary>

`note: valid MIR pass names are: AbortUnwindingCalls, AddCallGuards, AddMovesForPackedDrops, AddRetag, CheckAlignment, CheckCallRecursion, CheckConstItemMutation, CheckDropRecursion, CheckEnums, CheckForceInline, CheckInlineAlwaysTargetFeature, CheckLiveDrops, CheckNull, CheckPackedRef, CleanupPostBorrowck, CopyProp, CtfeLimit, DataflowConstProp, DeadStoreElimination-final, DeadStoreElimination-initial, Derefer, DestinationPropagation, EarlyOtherwiseBranch, ElaborateBoxDerefs, ElaborateDrops, EnumSizeOpt, EraseDerefTemps, ForceInline, FunctionItemReferences, GVN, ImpossiblePredicates, Inline, InstSimplify-after-simplifycfg, InstSimplify-before-inline, InstrumentCoverage, JumpThreading, KnownPanicsLint, LowerIntrinsics, LowerSliceLenCalls, Marker, MatchBranchSimplification, MentionedItems, MultipleReturnTerminators, PostAnalysisNormalize, PreCodegen, PromoteTemps, ReferencePropagation, RemoveNoopLandingPads, RemovePlaceMention, RemoveStorageMarkers, RemoveUninitDrops, RemoveUnneededDrops, RemoveZsts, ReorderBasicBlocks, ReorderLocals, RequiredConstsVisitor, SanityCheck, ScalarReplacementOfAggregates, SimplifyCfg-after-unreachable-enum-branching, SimplifyCfg-final, SimplifyCfg-initial, SimplifyCfg-make_shim, SimplifyCfg-post-analysis, SimplifyCfg-pre-optimizations, SimplifyCfg-promote-consts, SimplifyCfg-remove-false-edges, SimplifyComparisonIntegral, SimplifyConstCondition-after-const-prop, SimplifyConstCondition-after-inst-simplify, SimplifyConstCondition-final, SimplifyLocals-after-value-numbering, SimplifyLocals-before-const-prop, SimplifyLocals-final, SingleUseConsts, SsaRangePropagation, StateTransform, StripDebugInfo, Subtyper, UnreachableEnumBranching, UnreachablePropagation, Validator`

</details>
rust-bors Bot pushed a commit that referenced this pull request May 2, 2026
…uwer

Rollup of 9 pull requests

Successful merges:

 - #156030 (Make stable hashing names consistent (part 1))
 - #156020 (Improve source code for `librustdoc/visit_ast.rs`)
 - #156021 (Clean up some traits)
 - #156028 (Add a `Local::arg(i)` helper constructor)
 - #156037 (Add AcceptContext::expect_no_args)
 - #156040 (Add missing alias to mailmap)
 - #156048 (Make `diverging_type_vars` a vec of `TyVid`)
 - #156053 (Reuse CTFE MIR for constructors.)
 - #156059 (compiler: Print valid `-Zmir-enable-passes` names if invalid name is used)

Failed merges:

 - #155940 (refactor rustc_on_unimplemented's filtering)
 - #156065 (Remove unused spans from AttributeKind)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants