You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
mir::Constant::span is a footgun for mir optimizations #77608
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
The issue also applies to implicit const () at the end of block. Replacing it with an empty tuple aggregate in a MIR builder triggers a few extra optimizations in mir-opt test suite.
So are we going to use the "trivial" fix – adding a custom impl of PartialEq that ignores span – or some kind of more complex one – I think you mentioned a "multispan"?
Only adding a new method that ignores span equality does not remove the footgun though. Other code would still use the PartialEq which still compares unintuitively because of the span.
If someone wants to work on this, feel free to reuse my code. I don't remember how useful it is anymore since it has more than 1 year :). Anyway, feel free to contact me on a Zulip topic.
Activity
tmiasko commentedon Nov 3, 2020
The issue also applies to implicit
const ()at the end of block. Replacing it with an empty tuple aggregate in a MIR builder triggers a few extra optimizations in mir-opt test suite.camelid commentedon Nov 15, 2020
So are we going to use the "trivial" fix – adding a custom impl of
PartialEqthat ignoresspan– or some kind of more complex one – I think you mentioned a "multispan"?oli-obk commentedon Nov 16, 2020
Ideally we'd remove the
PartialEqimpl and leave a comment that it can't have that impl, but I'm not sure what the fallout of that is.camelid commentedon Nov 16, 2020
Perhaps we could add a method on
Constantthat checks equality while ignoringspan?simonvandel commentedon Nov 16, 2020
Only adding a new method that ignores span equality does not remove the footgun though. Other code would still use the PartialEq which still compares unintuitively because of the span.
camelid commentedon Nov 16, 2020
I meant that we should remove
PartialEqas Oli suggested and then add a new method that explicitly ignoresspan.camelid commentedon Nov 16, 2020
@spastorino Is it okay if I work on this a bit?
spastorino commentedon Jun 8, 2022
If someone wants to work on this, feel free to reuse my code. I don't remember how useful it is anymore since it has more than 1 year :). Anyway, feel free to contact me on a Zulip topic.