-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Guarantee @assert
will not be removed
#53223
Conversation
In many languages I do still want a way to put function-internal debug assertions that get removed for releases. On Slack @adienes suggested |
I'm hoping to get a "guaranteed never-removed check" into 1.11 - I don't care so much if it's called @DilumAluthge I see from the other PR that you favor @vchuravy I see your 👎, would you mind explaining your position regarding |
I think some languages also call the removable checks preconditions (or postconditions)? |
Do you have an example of that? Such an interpretation would invert the meaning of "precondition", i.e. a condition that is assumed to be true to make that call sound. The check isn't really removed, but assumed to be done/inferred ahead of time. |
Swift calls them preconditions at times https://developer.apple.com/documentation/swift/precondition(_:_:file:line:)#discussion (though it also has assertions) |
For a while .Net had "Code Contracts" with preconditions, invariants, and postconditions, but it has been abandoned: https://learn.microsoft.com/en-us/dotnet/framework/debug-trace-profile/code-contracts They were conditionally compiled -- removed by default. FWIW, .Net has separate "Debug.Assert" and "Trace.Assert" methods, the former is removed in release and the latter is retained. (based on a compiler symbol that is defined by default, so it's still technically removable if someone wanted.) |
Swift doesn't remove them though:
It only removes the check with I'm not sure I understand the ADA docs correctly, but I think the "enabled" there refers to whether its required to be checked by some other part of the class hierarchy..? -- Either way, I think it's good to have non-removable version in general, but I don't think |
If we want to call it something else we should do #41342; if not, we should do this. But I think we should do one of them. |
In all languages I am familiar with, assertion checks are for debugging, and can be disabled in "release builds". They are in particular not meant for user input validation, but rather for checking internal state where a diversion from the expect is really indicator of some fundamental issue. So my preference is that Julia follow this pattern. We define our own macros for use in argument validation (which throw |
The documentation mentions not relying on |
No this is not breaking, it only adds guarantees. |
Someone needs to make a decision on this one... |
I don't think this "needs" a decision per-se; judging by the 👎 on the original post, people seem to be pretty opposed to changing the guarantees of |
The only counterargument made in this thread is consistency with other languages:
However, Rust is a counterexample: it distinguishes
I sorta think consistency with Rust is almost as good as consistency with a bunch of other languages. There is another strong argument in favor, which is that a fair amount code already acts as if Are there any other arguments against merging? |
Several people have suggested that
@assert
should never be removed because too many people rely on it for correctness. This PR changes the docstring to guarantee that it will not be removed.This PR is an alternative to
@check
from #41342.