add __traits(isReturnOnStack, func)#7908
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. |
84646db to
060cfb9
Compare
|
To get this to work, I had to move |
060cfb9 to
3731145
Compare
3731145 to
f85fe38
Compare
|
@JinShil spec update is there now, too. |
src/dmd/target.d
Outdated
| //printf(" 3 true\n"); | ||
| return true; | ||
| } | ||
| else if ((global.params.isLinux || global.params.isOSX || global.params.isFreeBSD || global.params.isSolaris) && |
There was a problem hiding this comment.
Missing isDragonFlyBSD in the condition.
|
|
||
| static assert(__traits(isReturnOnStack, test1) == false); | ||
| static assert(__traits(isReturnOnStack, test2) == true); | ||
|
|
There was a problem hiding this comment.
I suggest adding a test where a struct is not returned on the stack.
There was a problem hiding this comment.
It's quite a few different conditions and branches in the isReturnOnStack function. Are those covered by other tests? I guess they're implicitly covered by other tests?
There was a problem hiding this comment.
Check the green lines in the code tab, they are lines that are covered.
There was a problem hiding this comment.
Are you referring to this https://codecov.io/gh/dlang/dmd/compare/bde2b0aee87d3199db22d606a63fe034c48f1c61...87a0811b3fd408c54e77569f3f3c666e8c44203c/diff ? I see quite a few lines that are red instead of green.
There was a problem hiding this comment.
All the new code is green. The move of retStyle from one module to another is not new code. Also, the coverage tester does not test Windows specific code.
changelog/isReturnOnStack.dd
Outdated
| @@ -0,0 +1 @@ | |||
| Implement https://dlang.org/spec/traits.html#isReturnOnStack | |||
There was a problem hiding this comment.
Please add a description, not just linking to the spec.
There was a problem hiding this comment.
There's no real point to copy/pasting. That's what links are for.
There was a problem hiding this comment.
The title is already a link. You can't put a link here. Check the preview at DAutoTest.
Also FWIW Ddoc doesn't detect URLs and you have to use LINK2...
There was a problem hiding this comment.
Ddoc does detect URLs starting with http: or https:
There was a problem hiding this comment.
DAutoTest fails:
.generated/stable_dmd-2.078.2/dmd2/linux/bin64/rdmd --compiler=.generated/stable_dmd-2.078.2/dmd2/linux/bin64/dmd -conf=.generated/stable_dmd-2.078.2/dmd2/linux/bin64/dmd.conf -version=Contributors_Lib ../tools/changed.d \
-o changelog/pending.dd --version "2.080.0" \
--date "To be released"
object.Exception@../tools/changed.d(214): Changelog entries should consist of one title line, a blank separator line, and a description.
To fix this you need add a blank line and copy part of description from your spec PR.
There was a problem hiding this comment.
I'll approve this PR after this changelog entry issue is addressd.
| * Returns: | ||
| * true if return value from function is on the stack | ||
| */ | ||
| extern (C++) static bool isReturnOnStack(TypeFunction tf) |
There was a problem hiding this comment.
Although it's pretty obvious, you usually complain of missing Params: section 😉.
Isn't |
It is! Can you do this also please, which removes |
In semantic3(), but it appeared that importing toir.d directly by traits.d caused it to fail on some platforms. It properly belongs in target.d anyway. |
|
@ibuclaw that indeed was the culprit. |
81b44c1 to
cc0a605
Compare
| if (e.ident == Id.isReturnOnStack) | ||
| { | ||
| /* Extract as a boolean if function return value is in registers | ||
| * https://dlang.org/spec/traits.html#isReturnOnStack |
There was a problem hiding this comment.
FWIW we could easily generate the spec from this. It's in the PR queue for a few months already and just needs an approval: #6877
There was a problem hiding this comment.
That PR is labeled "Needs Work" and the title contains "[Proof of Concept]".
There was a problem hiding this comment.
FWIW it was labelled PoC because it has never been formally approved as this would be a precedent in the spec depending on the actual implementation.
"Needs work" was just a result of merge conflicts that happened over the time ...
4710fe3 to
87a0811
Compare
| TEST_OUTPUT: | ||
| --- | ||
| fail_compilation/isreturnonstack.d(11): Error: argument to `__traits(isReturnOnStack, int)` is not a function | ||
| fail_compilation/isreturnonstack.d(12): Error: expected 1 arguments for `isReturnOnStack` but had 2 |
There was a problem hiding this comment.
Isn't it a bit inconsistent to have __traits(isReturnOnStack ... in one error message and only isReturnOnStack in another?
There was a problem hiding this comment.
It's consistent with all the other error messages put out by traits.d. If you want to redo all that, that's ok, but it would be a separate PR.
|
What's the motivation behind this ? |
See the opening comment. |
I suspect it has to do with @WalterBright taking an interest in #6246, but I'm only speculating. @WalterBright, you could elaborate more about why this is needed. |
Determining if a function return value is on the stack or in registers is both complex, with a lot of special cases, and hard to accurately test for. With it as a testable __trait, at lease we can make the testing easy and accurate. |
87a0811 to
365d154
Compare
365d154 to
ab0737e
Compare
|
I would merge this myself, but someone seems to have revoked that ability from me... @wilzbach. :-) |
That someone wasn't me - this time I'm innocent! |
Determining if a function return value is on the stack or in registers is both complex, with a lot of special cases, and hard to accurately test for. With it as a testable
__trait, at lease we can make the testing easy and accurate.Spec Change: dlang/dlang.org#2216