Skip to content

Hide comments about constants in MIR dumps if they bring no additional information #74508

Closed
@oli-obk

Description

@oli-obk

cc @lcnr @eddyb

We sometimes have super verbose things in MIR like

         assert(const true, "index out of bounds: the len is {} but the index is {}", const 4_usize, const 2_usize) -> bb1; // scope 0 at $DIR/array_index.rs:5:18: 5:33
                                          // ty::Const
                                          // + ty: bool
                                          // + val: Value(Scalar(0x01))
                                          // mir::Constant
                                          // + span: $DIR/array_index.rs:5:18: 5:33
                                          // + literal: Const { ty: bool, val: Value(Scalar(0x01)) }
                                          // ty::Const
                                          // + ty: usize
                                          // + val: Value(Scalar(0x0000000000000004))
                                          // mir::Constant
                                          // + span: $DIR/array_index.rs:5:18: 5:33
                                          // + literal: Const { ty: usize, val: Value(Scalar(0x0000000000000004)) }
                                          // ty::Const
                                          // + ty: usize
                                          // + val: Value(Scalar(0x0000000000000002))
                                          // mir::Constant
                                          // + span: $DIR/array_index.rs:5:18: 5:33
                                          // + literal: Const { ty: usize, val: Value(Scalar(0x0000000000000002)) }

These constants give no useful additional information, as everything is already contained in the mir terminator. I think we could start out with just not printing these statements if the type is an integer, bool or char, which should cover most use cases. A more complex analysis could later look at constant in more detail and decide whether the verbose printing could be helpful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-mir-optArea: MIR optimizationsC-enhancementCategory: An issue proposing an enhancement or a PR with one.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions