-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Remove official ndebug variable support #563
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| - Start Date: (fill me in with today's date, YYYY-MM-DD) | ||
| - RFC PR: (leave this empty) | ||
| - Rust Issue: (leave this empty) | ||
|
|
||
| # Summary | ||
|
|
||
| Remove official support for the `ndebug` config variable, replace the current usage of it with a | ||
| more appropriate 'debug_assertions` compiler-provided config variable. | ||
|
|
||
| # Motivation | ||
|
|
||
| The usage of 'ndebug' to indicate a release build is a strange holdover from C/C++. It is not used | ||
| much and is easy to forget about. Since it used like any other value passed to the `cfg` flag, it | ||
| does not interact with other flags such as `-g` or `-O`. | ||
|
|
||
| The only current users of `ndebug` are the implementations of the `debug_assert!` macro. At the | ||
| time of this writing integer overflow checking is will also be controlled by this variable. Since | ||
| the optimisation setting does not influence `ndebug`, this means that code that the user expects to | ||
| be optimised will still contain the overflow checking logic. Similarly, `debug_assert!` invocations | ||
| are not removed, contrary to what intuition should expect. Enabling optimisations should been seen | ||
| as a request to make the user's code faster, removing `debug_assert!` and other checks seems like | ||
| a natural consequence. | ||
|
|
||
| # Detailed design | ||
|
|
||
| The `debug_assertions` variable, the replacement for the `ndebug` variable, will be compiler | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just clarifying, but by variable do you mean if cfg!(debug_assertions) { /* super-expensive code */ } |
||
| provided based on the value of the `opt-level` codegen flag, including the implied value from `-O`. | ||
| Any value higher than 0 will disable the variable. | ||
|
|
||
| Another codegen flag `debug-assertions` will override this, forcing it on or off based on the value | ||
| passed to it. | ||
|
|
||
| # Drawbacks | ||
|
|
||
| Technically backwards incompatible change. However the only usage of the `ndebug` variable in the | ||
| rust tree is in the implementation of `debug_assert!`, so it's unlikely that any external code is | ||
| using it. | ||
|
|
||
| # Alternatives | ||
|
|
||
| No real alternatives beyond different names and defaults. | ||
|
|
||
| # Unresolved questions | ||
|
|
||
| None. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think markdown doesn't necessarily like this stray tick