Skip to content

atomic: remove 'Atomic*' from Debug output - #48553

Merged
bors merged 1 commit into
rust-lang:masterfrom
seanmonstar:atomic-debug
Apr 20, 2018
Merged

atomic: remove 'Atomic*' from Debug output#48553
bors merged 1 commit into
rust-lang:masterfrom
seanmonstar:atomic-debug

Conversation

@seanmonstar

Copy link
Copy Markdown
Contributor

For the same reason that we don't show Vec { data: [0, 1, 2, 3] }, but just the array, the AtomicUsize(1000) is noisy, and seeing just 1000 is likely better.

@rust-highfive

Copy link
Copy Markdown
Contributor

r? @aidanhs

(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 Feb 26, 2018
@Mark-Simulacrum

Copy link
Copy Markdown
Member

There are some stability concerns here (see the thread in #47619) for a similar change that caused somewhat widespread breakage.

However, I feel that it is warranted to make this change -- with a note for the compatibility notes.

@Mark-Simulacrum Mark-Simulacrum added the relnotes Marks issues that should be documented in the release notes of the next release. label Feb 26, 2018
@hanna-kruppe

hanna-kruppe commented Feb 26, 2018

Copy link
Copy Markdown
Contributor

I'm not sold on printing just 1000 instead of something indicating the atomic aspect. A better analogy than Vec would be Cell<usize>, which also has interior mutabilty and is in many ways just the single-threaded equivalent to AtomicUsize. And cells are formatted as Cell { value: 1000 }, not just 1000.

One reason for that, I imagine, is that the interior mutability has repercussions for when the value can change, which is something you'd really want to keep in mind while debugging by looking at snapshots of the program state. Thus the reminder that this is not an ordinary integer but one with interior mutability is useful and not just noise. This is even more drastic for atomic primitives than for Cell, since printing an atomic value that another thread is modifying is the very model of a race condition -- assuming these are normal shared-xor-mutable integers could easily be very misleading.

@seanmonstar

Copy link
Copy Markdown
Contributor Author

@rkruppe I was actually looking at Cell, and thinking of making another PR to change it also, because I think the Cell { value: ... } is unnecessary noise. I know I personally have many times avoided derive(Debug) because of these outputs, wanting to make debug logs easier to parse (as a human).

I do think that the extra info is probably needed for RefCell and Mutex, since it is possible that the fmt function cannot get a view, and thus needs to show <borrowed> or <locked>.

@kennytm kennytm added the T-libs-api [DEPRECATED; DO NOT USE] label Feb 28, 2018
@aidanhs

aidanhs commented Mar 1, 2018

Copy link
Copy Markdown
Contributor

I personally am prefer it as-is (for the same reasons as Cell outlined above).

But up to libs team - at random, r? @withoutboats

@rust-highfive rust-highfive assigned withoutboats and unassigned aidanhs Mar 1, 2018
@seanmonstar

Copy link
Copy Markdown
Contributor Author

I'll share what I'm looking at that prompted me writing this patch:

TRACE foo::bar::baz: poll; rx=Receiver { length: AtomicUsize(0), capacity: AtomicUsize(1000) }
TRACE foo::bar::baz: poll; rx=Receiver { length: AtomicUsize(1), capacity: AtomicUsize(999) }
TRACE foo::bar::baz: poll; rx=Receiver { length: AtomicUsize(2), capacity: AtomicUsize(998) }
TRACE foo::bar::baz: poll; rx=Receiver { length: AtomicUsize(0), capacity: AtomicUsize(1000) }

To me, that is noisy and doesn't provide any benefit, compared to:

TRACE foo::bar::baz: poll; rx=Receiver { length: 0, capacity: 1000 }
TRACE foo::bar::baz: poll; rx=Receiver { length: 1, capacity: 999 }
TRACE foo::bar::baz: poll; rx=Receiver { length: 2, capacity: 998 }
TRACE foo::bar::baz: poll; rx=Receiver { length: 0, capacity: 1000 }

Notably, those counters are actually Arc<AtomicUsize>, but thankfully, it already doesn't print out Arc { value: ... }.

I don't feel that since some internal, private state of the item needs atomic operations to change is important at all when printing a Debug format of the type.

@emilyalbini

Copy link
Copy Markdown
Member

Ping from the release team @withoutboats! This PR needs your review!

@emilyalbini

Copy link
Copy Markdown
Member

Ping from triage! This PR needs a review. Can @withoutboats or someone else from @rust-lang/libs do it?

@alexcrichton

Copy link
Copy Markdown
Member

I'd personally lean towards removing wrapper types where possible in the sense that we don't want to debug Box<T> as "Box { inner: T }". Intuitively I'd add wrapper strings/descriptions where it ends up adding semantic value to the debug output, for example File { fd: 32 } is far more useful than 32, but AtomicUsize(32) isn't conveying much more over 32 (other than maybe that it can be modified with a shared borrow?)

I'd like some input from others at @rust-lang/libs, though, so I've tagged this now as waiting on the team. I also agree though that we'd want to be consistent, so it'd be great to touch up other known cases (like Cell) in this PR when a conclusion is reached as well

@alexcrichton alexcrichton added S-waiting-on-team and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 14, 2018
@emilyalbini

Copy link
Copy Markdown
Member

Ping from triage @rust-lang/libs! Your opinion is needed :)

@SimonSapin

Copy link
Copy Markdown
Contributor

+1. I’m in favor of making wrapper types like this and Cell "transparent" in Debug impls.

@alexcrichton

Copy link
Copy Markdown
Member

This was discussed during @rust-lang/libs triage and the conclusion was that this is good to go. Follow-ups can always update the other types in libstd.

@bors: r+

@bors

bors commented Apr 19, 2018

Copy link
Copy Markdown
Collaborator

📌 Commit c689db2 has been approved by alexcrichton

@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-team labels Apr 19, 2018
@bors

bors commented Apr 19, 2018

Copy link
Copy Markdown
Collaborator

⌛ Testing commit c689db2 with merge 230b97a...

bors added a commit that referenced this pull request Apr 19, 2018
atomic: remove 'Atomic*' from Debug output

For the same reason that we don't show `Vec { data: [0, 1, 2, 3] }`, but just the array, the `AtomicUsize(1000)` is noisy, and seeing just `1000` is likely better.
@bors

bors commented Apr 20, 2018

Copy link
Copy Markdown
Collaborator

☀️ Test successful - status-appveyor, status-travis
Approved by: alexcrichton
Pushing 230b97a to master...

@bors
bors merged commit c689db2 into rust-lang:master Apr 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

relnotes Marks issues that should be documented in the release notes of the next release. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs-api [DEPRECATED; DO NOT USE]

Projects

None yet

Development

Successfully merging this pull request may close these issues.