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

rustc_serialize: make assert more informative. #91655

Closed
wants to merge 1 commit into from

Conversation

matthiaskrgr
Copy link
Member

#91650 (comment)

Make sure it prints the left/right values when it fails.

@rust-highfive
Copy link
Collaborator

r? @oli-obk

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 8, 2021
@klensy
Copy link
Contributor

klensy commented Dec 8, 2021

This code was recently changed in #91407

@oli-obk
Copy link
Contributor

oli-obk commented Dec 8, 2021

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Dec 8, 2021

📌 Commit 90e7f49 has been approved by oli-obk

@bors bors 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 Dec 8, 2021
@Mark-Simulacrum
Copy link
Member

@bors rollup=never - potentially perf sensitive

@the8472
Copy link
Member

the8472 commented Dec 8, 2021

The use of assert instead of assert_eq was requested during review.

@matthiaskrgr
Copy link
Member Author

@bors r-
Hmm, do you think something like adding an assert_eq-like message so that the values are printed still effects perf negatively?
assert!(x==y, "{} vs {}", x, y);

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Dec 8, 2021
@Mark-Simulacrum
Copy link
Member

@bors try @rust-timer queue

I think we should verify (if we haven't yet) whether it's actually a perf hit, first.

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Dec 8, 2021
@bors
Copy link
Contributor

bors commented Dec 8, 2021

⌛ Trying commit 90e7f49 with merge dcf1ec9f0d09e1f0fe4f36e1a0224097753a8ed4...

@the8472
Copy link
Member

the8472 commented Dec 8, 2021

I didn't directly verify the impact of the change, but the post-PR perf run looks ~0.1% better than the perf run before the review changes.

I am a tiny bit annoyed to be told to do one thing to see a PR undoing it.

Hmm, do you think something like adding an assert_eq-like message so that the values are printed still effects perf negatively?
assert!(x==y, "{} vs {}", x, y);

I agree with the original review comment here:

And in this particular case the better error message from assert_eq! doesn't really give additional information. So could you try just putting an assert! here?

To explain: left and right are probably of little use without a lot more context (offsets, raw data of what is being deserialized, what are we trying to deserialize etc.). The assert fires when the serialized data does not match the expected serialization format. Which wrong byte you find at that particular location probably doesn't matter, the fact that it is wrong at all reveals a bigger problem.

I haven't looked at the assert! expansion to figure out what @michaelwoerister meant wrt. codegen impact.

@matthiaskrgr
Copy link
Member Author

Sorry, I did not mean to discredit any of your work.
I did not read through the original PR before making this PR which would have been wise.

I just saw the "assertion failure x == y" on my screen and though "Huh, that does not tell a lot" so I patched it locally to see what was going on, and also made a pr because why not.

About the assert_eq error message; I don't fully agree:
While I don't understand the particular meaning of the number, I think it can still provide some kind of context.
For example "0" instead of "193" may indicate that something is missing.
"194" or "192" might indicate an off-by-one somewhere in the code.
I was also a bit relieved to find out that the error would consistently be 0 vs 192 instead of a different number on every run, so I can at least assume that the error is kind of consistent.

@matthiaskrgr
Copy link
Member Author

Looking at godbolt, it seems that assert indeed generates much less instructions than assert_eq, interesting.
https://rust.godbolt.org/z/57oT1P68z

Still curious about the actual perf result though. :)

@the8472
Copy link
Member

the8472 commented Dec 8, 2021

"194" or "192" might indicate an off-by-one somewhere in the code.

The value is not calculated, it is a constant. It can't be off by one.

For example "0" instead of "193" may indicate that something is missing.

Well, any value other than the expected constant would indicate that the sentinel byte itself is missing. Which value you happen to end up seeing in this place would depend on what comes next after the string in that particular data structure that triggers the assert first.

Sorry, I did not mean to discredit any of your work.

My annoyance only stems from the left hand not knowing what the right hand was doing. Which can happen, doesn't make it not annoying. I'm not seeing it as an attack on my work, just... suboptimal communication, a bit of unnecessary friction, that's all.

@bors
Copy link
Contributor

bors commented Dec 8, 2021

☀️ Try build successful - checks-actions
Build commit: dcf1ec9f0d09e1f0fe4f36e1a0224097753a8ed4 (dcf1ec9f0d09e1f0fe4f36e1a0224097753a8ed4)

@rust-timer
Copy link
Collaborator

Queued dcf1ec9f0d09e1f0fe4f36e1a0224097753a8ed4 with parent 4459e72, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (dcf1ec9f0d09e1f0fe4f36e1a0224097753a8ed4): comparison url.

Summary: This benchmark run did not return any relevant changes.

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR led to changes in compiler perf.

@bors rollup=never
@rustbot label: +S-waiting-on-review -S-waiting-on-perf -perf-regression

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Dec 8, 2021
@apiraino apiraino added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Dec 9, 2021
@matthiaskrgr matthiaskrgr deleted the ser_assert branch January 25, 2025 09:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. 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.

10 participants