-
-
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
Fix Issue 16492 - support @nogc in debug{} blocks #7882
Conversation
|
Oh thank god! |
| auto b = [1, 2, 3]; | ||
| b ~= 4; | ||
| } | ||
| } |
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 can be merged with other compilable tests. Merging them makes the autotester run faster.
src/dmd/nogc.d
Outdated
| if (e && e.op != TOK.error && f && sc.intypeof != 1 && !(sc.flags & SCOPE.ctfe) | ||
| && (f.type.ty == Tfunction | ||
| && (cast(TypeFunction)f.type).isnogc || (f.flags & FUNCFLAG.nogcInprocess) || global.params.vgc) | ||
| && !(sc.flags & SCOPE.debug_)) |
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 code is good, but you're inventing another style of doing multiline conditionals.
if (e && e.op != TOK.error && f && sc.intypeof != 1 && !(sc.flags & SCOPE.ctfe) &&
(f.type.ty == Tfunction &&
(cast(TypeFunction)f.type).isnogc || (f.flags & FUNCFLAG.nogcInprocess) || global.params.vgc) &&
!(sc.flags & SCOPE.debug_))
I.e. the dangling operator goes at the end, not the beginning, and subsequent lines should line up with the character after the opening (.
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.
as already commented
I forgot to use |
8589415 to
25c503e
Compare
|
This feature leaves me feeling a little apprehensive. Is this truly in harmony with the intent of the Note, I'm not against this, but I want to be sure there is deliberate intent behind it. |
|
There's a precendent:
https://dlang.org/spec/function.html#pure-functions
|
Ah...looks like that new option comes in handy :) |
|
@JinShil: writeln() |
|
@wilzbach : '-debug' is a global compile flag, but @nogc / @pure are function local. IMHO This could create some potentially unexpected results: Let's say you want to debug function X, so you switch on -debug, and now suddently function y.y.y.y (potentially in some library), suddenly could have (impure) side effects, require gc etc. |
|
This also worries me. Oftentimes you want just a local effect since you're just debugging one function. Here's how https://nim-lang.org/docs/manual.html#pragmas-push-and-pop-pragmas #here's an example with a particular compile option (`checks:off`) being locally applied
{.push checks: off.}
# compile this section without runtime checks as it is speed critical
# ... some code ...
{.pop.} # restore old settingsin D could look something like: pragma(push, "-debug"); // could push other stuff eg "-noboundscheck, -O, -inline" etc
// compile this section with `-debug`
// ... some code ...
pragma(pop); // restore old settingsor perhaps more idiomatically, taking advantage of scoping rules of pragmas (3 types: single decl, all following decls, or inside // could push other stuff eg "-noboundscheck, -O, -inline" etc
pragma(compilerOptions, "-debug"){
// compile this section with `-debug`
// ... some code ...
}
// old settings restored |
This has been part of the DMD compiler and DSpec for years for
|
This is already possible today. You can trick the compiler into thinking something is void assumeNogc(alias Func, T...)(T xs) @nogc {
import std.traits;
static auto assumeNogcPtr(T)(T f) if (
isFunctionPointer!T || isDelegate!T
) {
enum attrs = functionAttributes!T | FunctionAttribute.nogc;
return cast(SetFunctionAttributes!(T, functionLinkage!T, attrs)) f;
};
assumeNogcPtr(&Func!T)(xs);
}; |
|
@timotheecour Do really like you potential solution, would allow for nicely localized debugging ! |
I tend to expect switching on/off debug have enormous impact on runtime (ie, enable/disable all non-shipping debugging infrastructure; high runtime cost), and likely have loads of 'side effects' (like emitting data to logs, telemetry, etc.) Right now, it's impossible to debug pure/@nogc/etc code. This patch is necessary. |
|
@TurkeyMan I meant negative/unpredictable side effects. When debugging your application, it would be nice if you could finetune your debug only to the part that you are actually interested in, ie the part you are trying to debug. That's why i did like @timotheecour solution so much. |
|
I pulled this because this solution is simple. The casting solution is just too awful, and the push/pop is just annoying. When I write debug code, I don't care about correctness, I just need to do some logging or extra checking, and the compiler should relax its usual strict pedantic checking for it. If you ship code with |
|
Well, that addresses my concerns 😆 UPDATE: I think that comment could easily be misinterpreted. What I mean by the above comment is @WalterBright addressed my concerns completely and definitively in a single K-Pow! I was wondering about the intent behind |
|
Follow up for the other attributes expressing the same problem? |
|
Yes, but they are more complicated. |
|
@TurkeyMan what other attributes would be left? cc @RazvanN7 |
|
|
@JinShil thanks for the clarification. Think of |
|
Oh man, thank you for pulling this an working on the other attributes. This is my biggest pain point on D. I've been doing this in my projects, and I'm looking forward to deleting this cruft version (noAttributes)
{
unittest
{
runTests();
}
}
else
{
@safe pure unittest
{
runTests();
}
} |
|
@wilzbach awesome! Can you add a changelog and update the spec pls? |
It technically already appears on the changelog, but I doubt anyone will notice: I think it makes sense to wait with a proper changelog entry until
Spec is already updated. See dlang/dlang.org#2205 and dlang/dlang.org#2209 |
|
Thanks Seb, I saw those PRs later than this one. |


debugalready allows to use non-purewithinpurescopes, imho it only makes sense to do the same for the rest.If this gets approved, I am happy to do the same for
@safeandnothrow.Spec PR: dlang/dlang.org#2205