-
-
Notifications
You must be signed in to change notification settings - Fork 609
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
add -check command line switch #8972
Conversation
Thanks for your pull request, @WalterBright! Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub fetch digger
dub run digger -- build "master + dmd#8972" |
doc tester doesn't like something there. |
6290263
to
58a2df5
Compare
It definitely cover our needs, thanks! The DIP should probably be updated too, although it is mostly only an update on names (switch and values) and add/remove some options. |
A question about behaviour: if one excludes |
src/dmd/cli.d
Outdated
@@ -169,14 +169,30 @@ struct Usage | |||
Option("c", | |||
"compile only, do not link" | |||
), | |||
Option("check=[assert|bounds|in|invariant|out|switch][=[on|off]]", | |||
"Enable or disable specific checks", | |||
`Overrides default, -boundscheck, and -release options to enable or disable specific checks. |
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.
It currently overrides -boundscheck only if it is specified after it on the command line. I'd rather leave bounds
out here, it already has two options and another setting safeonly
.
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.
We actually have boundscheck
and noboundscheck
. I'd like to deprecate them and just go with the more general check
. I also want to add safe
as a third option to check
, so that all the checks are handled the same way with one switch.
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.
The current implementation is not in line with this documentation: To match it -boundscheck
has to remember its setting and change params.useArrayBounds only if not set already by -check=bounds=on|off
.
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.
We actually have
boundscheck
andnoboundscheck
. I'd like to deprecate them and just go with the more generalcheck
. I also want to addsafe
as a third option tocheck
, so that all the checks are handled the same way with one switch.
If you want to go this route, I might suggest considering adding back the all
and none
values present in the DIP.
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.
On the other hand, what you said afterwards contradicts this idea:
The idea is that changing one setting with -check has no effect on any other settings. It's designed so that each setting can be controlled independently of the others. Therefore, if you set check=in, then the in contracts are run, but if assert is turned off, then they'll be vacuous.
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 can see someone running the in
contracts with the assert
turned off, after all, they may want to do their own wacky thing. I fear that if we get too clever with "surely the user wants assert
on if in
is on" we'll find ourselves in the future inevitably adding another switch so that becomes settable.
I don't want to be adding more switches. We've already tried several times to "package" these settings into other switches. The desire for this switch shows it obviously is inadequate.
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.
It currently overrides -boundscheck only if it is specified after it on the command line.
Fixed.
@@ -169,14 +169,30 @@ struct Usage | |||
Option("c", | |||
"compile only, do not link" | |||
), | |||
Option("check=[assert|bounds|in|invariant|out|switch][=[on|off]]", |
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.
Don't want to start bikeshedding, but the duplicate =
looks strange. Why not use check-[assert|...]
?
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.
Because 1) we use on|off
elsewhere, not +|-
2) I want to add a safe
option as well 3) other options may become useful than just on|off|safe
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 didn't mean to remove the on/off, but to replace the first =
with -
, e.g. -check-assert=on
instead of -check=assert=on
.
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.
We already use =
for the mv
switch.
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.
Another syntax question: is it assumed that the user will write separate -check=assert -check=in -check=out -check=bounds
calls, or do we want to support a syntax like -check=assert,bounds,in,out
that allows all the options to be specified in a single flag?
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.
Perhaps in the future. For right now, I want to maximize simplicity.
The idea is that changing one setting with |
Why not use the existing work from #7980? |
*/ | ||
|
||
// Check for legal option string; return true if so | ||
static bool check(const(char)* p, string name, ref CHECKENABLE ce) |
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.
This seems awfully rigid, re checking for exactly =on
or =off
For a first implementation it might be alight though.
I find |
Gotcha. So (for example) if one just set I remember suggesting a |
No. All asserts would run. |
58a2df5
to
f4945ba
Compare
f4945ba
to
5cf441c
Compare
Presumably not asserts in Other than that, where else would you see |
That's right.
In executable code, which would be those areas you mentioned. |
@@ -175,6 +175,7 @@ struct Param | |||
CHECKENABLE useArrayBounds = CHECKENABLE._default; // when to generate code for array bounds checks | |||
CHECKENABLE useAssert = CHECKENABLE._default; // when to generate code for assert()'s | |||
CHECKENABLE useSwitchError = CHECKENABLE._default; // check for switches without a default | |||
CHECKENABLE boundscheck = CHECKENABLE._default; // state of -boundscheck switch |
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.
While this now works as documented, I think it's a bit confusing to have both useArrayBounds
and boundscheck
as fields of Param
. I would expect boundscheck
to be a local variable in parseCommandLine()
.
It's not very testable because of the use of global variables, particularly around line 339 of mars.d. I've had thoughts once this is pulled to pull out that section into a separate function, and pass |
5cf441c
to
559252e
Compare
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 understand this has also been OK by Sociomantic.
Why are there still no tests? This shouldn't have been merged without tests!! |
@wilzbach please add them! |
Guess what: I was correct. the feature didn't work: #9195
I'm sorry, but my main focus isn't D anymore. |
An implementation of the idea behind DIP1006, but not the specifics.
https://github.com/dlang/DIPs/blob/master/DIPs/DIP1006.md