-
-
Notifications
You must be signed in to change notification settings - Fork 424
Fix Issue 19635 - -checkaction=context not working with attributes #2479
Conversation
Thanks for your pull request, @wilzbach! Bugzilla references
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 "stable + druntime#2479" |
fd5d690
to
5f17c85
Compare
I'm not sure about catching AssertError, but if an assert fails inside a "Unlike AssertExpressions used elsewhere, the assert is not assumed to hold, and upon assert failure the program is still in a defined state." [1]. |
Hmm but making this work nicely with attributes leads to a lot of problems:
https://dlang.org/library/object/exception.html
|
I know, at the same time the spec says this [1]: "Implementation Defined: Currently this is only possible to implemented by catching Lines 480 to 484 in ca1be3f
|
Does |
I'm no expert at this but it sounds like it could be pure.
Alternatives would be a stack allocated buffer, either using
Yeah, that sounds a bit problematic. |
Stack allocated buffer won't work here because So imho this trick is the best we got for now until rcstring becomes a thing (and even then we might not be able to use it because a |
No, it's called at compile-time ( |
Hmm, interesting. I didn't know that would bypass attributes. |
Not sure if it helps, but if void* foo(void* buffer = alloca(1))
{
return buffer;
} |
This compiles and throws a GC allocated exception. I believe the general sentiment is that assert failure can bypass some language constraints, notably |
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.
Some nit picking
This might be helpful, but the caller needs to be aware of this, or he'll get bitten
|
The current implementation of |
As I mentioned previously: "Unlike AssertExpressions used elsewhere, the assert is not assumed to hold, and upon assert failure the program is still in a defined state." [1]. |
Yeah it looks like we need some input from @andralex or @WalterBright on how to proceed here. I wouldn't mind using a static buffer though it wouldn't fix e.g. user-generated struct MyStruct {
string toString() { return "hello"; }
}
void main() @nogc nothrow {
auto s = MyStruct();
assert(s != s); // <- FAILS here
} |
What about the sink version of |
Yeah that would help, though who uses a sink version of
https://run.dlang.io/is/xQeV33 [1] And, of course, as exceptions still require the GC also not Thus, I'm more leaning forward to this "fake it" approach as long as we can guarantee that it plays nicely with |
What happens then when someone using betterC and doesn't link druntime? |
Then they wouldn't be able to use D's exceptions + errors (e.g. AssertError) and even |
Yes, but what happens then with the assert message? |
|
I use C |
Oh, btw, casting |
Isn't this more of a @WalterBright thing? |
You are right. |
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.
Otherwise looks good.
1de725f
to
38781d5
Compare
Rebased to |
been printed and its not considered part of the "main" program. | ||
Also, catching an AssertError is Undefined Behavior | ||
Hence, we can fake purity and @nogc-ness here. | ||
*/ |
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 disagree with this comment. There are several places in the D code bases where AssertError
is caught.
At the risk of going OT: apropos barely usable, are you aware of https://issues.dlang.org/show_bug.cgi?id=19711? |
Now I'm, but the issue is very unrelated.
Anyhow, the fix is here -> dlang-tour/core-exec#44 |
Yeah, it's that thing, "don't catch Errors" is a rule for business logic, which one might know how to break, druntime code that catches Throwable has code tailored to print a message without much relying on the rest of application code. |
The default unit test runner in druntime will catch all |
It won't execute the application after the tests, will it? If a failing test corrupted memory, then following tests can experience heisenbugs. |
I'm not sure where the discussion is going about. The runtime already uses the GC to allocate other parts of the error handling and formatting. This just makes the new context-aware switch work similar. |
I disagree with the following reasoning, which you have in a comment: The program will be terminated after the assertion error message has been printed and its not considered part of the "main" program. Also, catching an AssertError is Undefined Behavior. Hence, we can fake purity and @nogc-ness here. |
No.
Yes, that might happen. But I assume you would rerun all tests once the failing test is fixed. |
The program will be terminated after the assertion error message has been printed and its not considered part of the "main" program. Also, catching an AssertError is Undefined Behavior.
Hence, we can fake purity and @nogc-ness here.
An alternative would be to directly ignore the
assert
message expression directly in DMD's type checker (see e.g. https://issues.dlang.org/show_bug.cgi?id=15100 for this).