-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
debug-fmt-detail option #123940
debug-fmt-detail option #123940
Conversation
Some changes occurred in cfg and check-cfg configuration cc @Urgau |
This comment has been minimized.
This comment has been minimized.
I'd love to see this happen. I have a suggestion for a refinement: In the This constant string should be |
7437d70
to
aabf2f6
Compare
This comment has been minimized.
This comment has been minimized.
aabf2f6
to
1721c63
Compare
Some changes occurred in tests/ui/check-cfg cc @Urgau |
This comment has been minimized.
This comment has been minimized.
@kpreid But There is |
1721c63
to
bceb534
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
bf36e51
to
3905795
Compare
Some changes occurred in src/doc/rustc/src/check-cfg.md cc @Urgau |
This comment has been minimized.
This comment has been minimized.
3905795
to
92cac91
Compare
This comment has been minimized.
This comment has been minimized.
7736b47
to
88b9edc
Compare
@rfcbot fcp cancel This does not need FCP approval now, since it will need another FCP on stabilization (if ever). This should count as having been MCP'd though, since it's been like 3 months and nobody has spoken up. |
@compiler-errors proposal cancelled. |
This should be ready for review. |
…llaumeGomez Rollup of 7 pull requests Successful merges: - rust-lang#123940 (debug-fmt-detail option) - rust-lang#128166 (Improved `checked_isqrt` and `isqrt` methods) - rust-lang#128970 (Add `-Zlint-llvm-ir`) - rust-lang#129316 (riscv64imac: allow shadow call stack sanitizer) - rust-lang#129690 (Add `needs-unwind` compiletest directive to `libtest-thread-limit` and replace some `Path` with `path` in `run-make`) - rust-lang#129732 (Add `unreachable_pub`, round 3) - rust-lang#129743 (Fix rustdoc clippy lints) r? `@ghost` `@rustbot` modify labels: rollup
…llaumeGomez Rollup of 7 pull requests Successful merges: - rust-lang#123940 (debug-fmt-detail option) - rust-lang#128166 (Improved `checked_isqrt` and `isqrt` methods) - rust-lang#128970 (Add `-Zlint-llvm-ir`) - rust-lang#129316 (riscv64imac: allow shadow call stack sanitizer) - rust-lang#129690 (Add `needs-unwind` compiletest directive to `libtest-thread-limit` and replace some `Path` with `path` in `run-make`) - rust-lang#129732 (Add `unreachable_pub`, round 3) - rust-lang#129743 (Fix rustdoc clippy lints) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#123940 - kornelski:remove-derived-debug, r=Urgau debug-fmt-detail option I'd like to propose a new option that makes `#[derive(Debug)]` generate no-op implementations that don't print anything, and makes `{:?}` in format strings a no-op. There are a couple of motivations for this: 1. A more thorough stripping of debug symbols. Binaries stripped of debug symbols still retain some of them through `Debug` implementations. It's hard to avoid that without compiler's help, because debug formatting can be used in many places, including dependencies, and their loggers, asserts, panics, etc. * In my testing it gives about 2% binary size reduction on top of all other binary-minimizing best practices (including `panic_immediate_abort`). There are targets like Web WASM or embedded where users pay attention to binary sizes. * Users distributing closed-source binaries may not want to "leak" any symbol names as a matter of principle. 2. Adds ability to test whether code depends on specifics of the `Debug` format implementation in unwise ways (e.g. trying to get data unavailable via public interface, or using it as a serialization format). Because current Rust's debug implementation doesn't change, there's a risk of it becoming a fragile de-facto API that [won't be possible to change in the future](https://www.hyrumslaw.com/). An option that "breaks" it can act as a [grease](https://www.rfc-editor.org/rfc/rfc8701.html). This implementation is a `-Z fmt-debug=opt` flag that takes: * `full` — the default, current state. * `none` — makes derived `Debug` and `{:?}` no-ops. Explicit `impl Debug for T` implementations are left unharmed, but `{:?}` format won't use them, so they may get dead-code eliminated if they aren't invoked directly. * `shallow` — makes derived `Debug` print only the type's name, without recursing into fields. Fieldless enums print their variant names. `{:?}` works. The `shallow` option is a compromise between minimizing the `Debug` code, and compatibility. There are popular proc-macro crates that use `Debug::fmt` as a way to convert enum values into their Rust source code. There's a corresponding `cfg` flag: `#[cfg(fmt_debug = "none")]` that can be used in user code to react to this setting to minimize custom `Debug` implementations or remove unnecessary formatting helper functions.
Thank you all for helping to merge this. |
I'm really happy to see progress on binary size in Rust. Many of our clients in ICU4X care about this subject, and anything we can do here increases our value proposition. I would like to see more documentation about how this is intended to work with custom Debug impls. There are a number of reasons why we can't always use
Would something like Additional question: would it be possible for |
This does currently work, it should be documented.
An important feature of Worth sketching out what you're looking for exactly. Currently, the behavior of
In your proposal, what would you have Trying to get the behavior of |
Really, for the custom |
Since Yeah, Thought: a format syntax character could prevent the debug impl from being removed by the fmt-debug config. Something like I think a well-balanced setting would be:
I don't think the current proposal has an option for this. |
...kiiiind of,
Can you expand on what you mean here? A real format string would probably have more than just I think "use the type name instead of blank" is probably a viable way to improve
n.b. use of a DebugAsDisplay wrapper object would solve that problem. Footnotes
|
I'd like to propose a new option that makes
#[derive(Debug)]
generate no-op implementations that don't print anything, and makes{:?}
in format strings a no-op.There are a couple of motivations for this:
Debug
implementations. It's hard to avoid that without compiler's help, because debug formatting can be used in many places, including dependencies, and their loggers, asserts, panics, etc.panic_immediate_abort
). There are targets like Web WASM or embedded where users pay attention to binary sizes.Debug
format implementation in unwise ways (e.g. trying to get data unavailable via public interface, or using it as a serialization format). Because current Rust's debug implementation doesn't change, there's a risk of it becoming a fragile de-facto API that won't be possible to change in the future. An option that "breaks" it can act as a grease.This implementation is a
-Z fmt-debug=opt
flag that takes:full
— the default, current state.none
— makes derivedDebug
and{:?}
no-ops. Explicitimpl Debug for T
implementations are left unharmed, but{:?}
format won't use them, so they may get dead-code eliminated if they aren't invoked directly.shallow
— makes derivedDebug
print only the type's name, without recursing into fields. Fieldless enums print their variant names.{:?}
works.The
shallow
option is a compromise between minimizing theDebug
code, and compatibility. There are popular proc-macro crates that useDebug::fmt
as a way to convert enum values into their Rust source code.There's a corresponding
cfg
flag:#[cfg(fmt_debug = "none")]
that can be used in user code to react to this setting to minimize customDebug
implementations or remove unnecessary formatting helper functions.