Skip to content

mir::Constant::span is a footgun for mir optimizations #77608

Description

@oli-obk

The field is part of the PartialEq impl, and thus two constants that are equal except in their span will compare inequal. This causes problems in #77551 (comment) and #77549 (comment) and possibly in other places.

The "trivial" way to resolve this is to manually implement PartialEq and make it skip the Span field.
Downside: now we may cause weird diagnostics after such an optimization has been applied, because if one of the constants is eliminated, all diagnostics are reported on the other diagnostic's site. We'd need a multispan and properly combine it. That will be hard to ensure to happen if we just silently change PartialEq

cc @rust-lang/wg-mir-opt

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlA-diagnosticsArea: Messages for errors, warnings, and lintsA-mir-optArea: MIR optimizationsE-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.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