Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constant::eq skips spans #85208

Closed

Conversation

spastorino
Copy link
Member

Opening this to start discussion and see what CI says about different approaches we can try for #77608.
For now I've just skipped span on eq implementation.

r? @oli-obk

From what I've seen locally it passes all tests, which surprises me given the comments made on #77608. Although I'm not really sure how well this plays with incremental compilation, but my guess is that it doesn't play well.

Closes #77608

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 12, 2021
@oli-obk
Copy link
Contributor

oli-obk commented May 12, 2021

If you change PartialEq, you also need to adjust Hash and HashStable to reflect these changes, otherwise hashmaps behave badly

@Aaron1011
Copy link
Member

I think this is going to cause problems with incremental compilation. As @oli-obk said, this change would require ignoring the span in the HashStable impl. This means that a change in the span of a constant will not invalidate the result of a query, which could lead to stale diagnostics/debuginfo being produced (or even weirder issues if the SyntaxContext changes.

@spastorino
Copy link
Member Author

spastorino commented May 12, 2021

yeah you both are right, I need to adjust that but I meant, wouldn't this cause incr. comp. issues regardless of the Hash and HashStable related changes?.

Edit: ohh, sorry my english understanding skills are a bit poor :), I think that @Aaron1011 is exactly saying that indeed regardless of Hash and HashStable changes this will cause problems. Please confirm that to me because that was my assumption and I'm not sure if I understood correctly.

In that case, would removing PartialEq impl avoid this problem?

@spastorino spastorino force-pushed the constant-span-footgun-miropt branch from b6cb245 to fa9e3d8 Compare May 13, 2021 18:01
@@ -683,14 +683,13 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
self.stack_mut().push(frame);

// Make sure all the constants required by this frame evaluate successfully (post-monomorphization check).
for const_ in &body.required_consts {
let span = const_.span;
for (span, const_) in &body.required_consts {
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh right! we have required_consts. Perfect. I think we may be able to remove the span from Operand::Const after all

Copy link
Member Author

Choose a reason for hiding this comment

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

Should we do this in a follow up PR? or do you want me to take some kind of action here?

if let mir::Operand::Constant(box constant) = func {
if constant.span.lo() > span.lo() {
span = span.with_lo(constant.span.lo());
if let mir::Operand::Constant(box (c_span, _)) = func {
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure why this special cased to constants. we can do the same thing for other operands by looking up their local's span. But this is essentially what I was talking about for pulling the span even outside the Operand and using (Operand, Span) tuples where necessary

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure I follow your comment, are you referring to something pre-existing? in that case, should we address it in a follow up PR? or are you asking me to change how I'm handling spans further?

Copy link
Contributor

Choose a reason for hiding this comment

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

yea, I'm just musing on the pre-existing thing

func: Operand::Constant(box Constant {
span: source_info.span,

func: Operand::Constant(box (source_info.span, Constant {
Copy link
Contributor

Choose a reason for hiding this comment

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

here we could pull the span into a field on TerminatorKind::Call

@oli-obk
Copy link
Contributor

oli-obk commented May 13, 2021

the current changes should always stay their own commit, this is really clean

@bstrie bstrie added S-experimental Status: Ongoing experiment that does not require reviewing and won't be merged in its current state. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 2, 2021
@bstrie
Copy link
Contributor

bstrie commented Jun 2, 2021

Triage, marking as experimental.

@crlf0710 crlf0710 added S-experimental Status: Ongoing experiment that does not require reviewing and won't be merged in its current state. and removed S-experimental Status: Ongoing experiment that does not require reviewing and won't be merged in its current state. labels Jun 25, 2021
@crlf0710 crlf0710 added S-experimental Status: Ongoing experiment that does not require reviewing and won't be merged in its current state. and removed S-experimental Status: Ongoing experiment that does not require reviewing and won't be merged in its current state. labels Jul 17, 2021
@crlf0710 crlf0710 added S-experimental Status: Ongoing experiment that does not require reviewing and won't be merged in its current state. and removed S-experimental Status: Ongoing experiment that does not require reviewing and won't be merged in its current state. labels Sep 10, 2021
@apiraino apiraino added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Oct 14, 2021
@Dylan-DPC
Copy link
Member

closing this as it has bitrotted

@Dylan-DPC Dylan-DPC closed this Jun 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-experimental Status: Ongoing experiment that does not require reviewing and won't be merged in its current state. 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.

mir::Constant::span is a footgun for mir optimizations
8 participants