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
return scope: first support #5972
Conversation
96b69e2
to
5210031
Compare
The commit message / P.R. message is highly insufficient for most people to understand what the design is. |
|
So how does |
@iain-buclaw-sociomantic it enables the compiler to see which arguments are being returned by a function, so it can see if those arguments are escaping. It's analogous to how |
The new DIP process is intended to be different for Walter. To quote:
@WalterBright there is a conversion tool from MediaWiki to Markdown, I just ran it for DIP90 and cleaned its output a bit. How about submitting DIP90 to the new DIP list? I think no matter whether it's draft or already decided, this should be the intended process. Is this correct @Dicebot? |
I have already converted DIP90 to new format myself and sent to @WalterBright via e-mail for submitting to the queue. Will start forum discussion as soon as it finally happens ;) |
(but it was ages ago thus there must be some misunderstanding here) |
@Dicebot it's there now. |
5210031
to
723f4cb
Compare
What about the |
OK, for the record - we had tele-meeting discussing further plan to move with DIP1000 (https://github.com/dlang/DIPs/blob/master/DIPs/DIP1000.md) which will be announced on NG by the end of this week in more details. But essentials regarding this PR is that @WalterBright will continue work on this PR as he sees fit until it is more feature complete. Reviewing the source patches is still welcome but please don't worry about actual feature set and compiler flags while the |
Fair enough, as long as it doesn't get merged without compiler flags. |
@WalterBright, thanks for your PR! By analyzing the annotation information on this pull request, we identified @yebblies, @9rnsr and @MartinNowak to be potential reviewers. @yebblies: The PR was automatically assigned to you, please reassign it if you were identified mistakenly. |
9be2540
to
6bf1c9d
Compare
Current coverage is 87.37% (diff: 89.28%)@@ scope #5972 diff @@
==========================================
Files 107 104 -3
Lines 61712 57703 -4009
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
- Hits 53954 50416 -3538
+ Misses 7758 7287 -471
Partials 0 0
|
abe2342
to
bac69c5
Compare
0ba2d30
to
d45f171
Compare
e4428f3
to
4ecb21e
Compare
ca77791
to
b2cb96c
Compare
@MartinNowak I rebased this on master, and now it has 6000 different lines. Uh-oh, maybe this has something to with it going on a feature branch? |
No worries, already working on it ;). I merged master into the scope base branch so that the diff should be the actual PR again. |
Thanks, @MartinNowak , you're a life saver! |
Seems like github isn't updating the diff view, but my local diff looks fine. |
Yeah, I wasn't thinking when I rebased it. I tend to routinely rebase things so they don't diverge too far. My diff view isn't changing, either. Maybe if I rebased it again? :-) |
b2cb96c
to
225c713
Compare
Just like stable it has a different base branch, please rebase this branch against upstream/scope next time.
Yes, GH only updates on branch changes to limit the repercussions of a commit on master. |
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.
Looks reasonable with that few questions and suggestions.
As said before starring at the low-level code is no replacement for properly reviewing the design. It's not impossible to infer a high-level implications for a low-level escape checker.
@@ -6247,9 +6247,6 @@ extern (C++) final class TypeFunction : TypeNext | |||
fparam.storageClass |= STCscope; // 'return' implies 'scope' | |||
if (tf.isref) | |||
{ | |||
error(loc, "parameter %s is 'return' but function returns 'ref'", | |||
fparam.ident ? fparam.ident.toChars() : ""); | |||
errors = true; |
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.
Test case for that would have been nice.
@@ -53,20 +53,19 @@ bool checkAssignEscape(Scope* sc, Expression e, bool gag) | |||
if (e1.op == TOKslice) | |||
return false; | |||
|
|||
VarDeclarations byref, byvalue; | |||
Expressions byexp; | |||
EscapeByResults er; |
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.
That's a very undescriptive name, as usual any translation a reader has to juggle in mind while going through the code makes understanding harder, a bit similar to using rare loanwords in articles.
How about Escapes
instead? I wouldn't argue if that name didn't hinder my understanding of the code.
@@ -41,11 +41,13 @@ import ddmd.arraytypes; | |||
*/ | |||
bool checkAssignEscape(Scope* sc, Expression e, bool gag) | |||
{ | |||
if (e.op != TOKassign && e.op != TOKblit) | |||
//printf("checkAssignEscape(e: %s)\n", e.toChars()); | |||
if (e.op != TOKassign && e.op != TOKblit && e.op != TOKconstruct) |
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.
Looks like it's not strictly part of the commit Issue to fix 15544.
return false; | ||
|
||
VarDeclaration va; | ||
while (e1.op == TOKdotvar) | ||
e1 = (cast(DotVarExp)e1).e1; |
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.
Sure about this? Couldn't one of the DotVarExps return a value with an independent lifetime?
for (auto p = fd.parent; p; p = p.parent) | ||
{ | ||
auto fdp = p.isFuncDeclaration(); | ||
if (fdp) |
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.
Please get accustomed to early return/continue to avoid such deep nesting ;).
ìf (fdp is nulll)
continue;
assert(!(p.storageClass & STCmaybescope)); | ||
} | ||
} | ||
} |
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.
Shouldn't this unset STCreturn if that doesn't apply?
@@ -1016,6 +1016,8 @@ extern (C++) class VarDeclaration : Declaration | |||
{ | |||
Initializer _init; | |||
uint offset; | |||
uint sequenceNumber; // order the variables are declared |
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.
order the variables are declared???
Thought you were the native speaker :).
Did you mean order the declaration of variables?
@@ -1016,6 +1016,8 @@ extern (C++) class VarDeclaration : Declaration | |||
{ | |||
Initializer _init; | |||
uint offset; | |||
uint sequenceNumber; // order the variables are declared | |||
__gshared uint nextSequenceNumber; // the counter for sequenceNumber |
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.
Also seems to work for nested scopes. Could we have some weird semantic order of nested functions or so that conflicts with this sequence number scheme?
{ | ||
auto t = e.e1.type.toBasetype(); | ||
if (t.ty == Tstruct) | ||
e.e1.accept(this); |
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.
Just a single layer, why not a.b.c
?
/* v is not 'scope', and is assigned to a parameter that may escape. | ||
* Therefore, v can never be 'scope'. | ||
*/ | ||
v.doNotInferScope = true; |
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.
Why can't this use the prevalent scheme of clearing STCmaybescope
?
Maybe I'm looking at the commits in the wrong order, the PR is a bit messed up.
In fact, please never rebase PRs, unless really necessary, you just killed half of my review comments ;), please expand the show outdated stuff. |
What about those |
I don't know. My first thought is it has something to do with Dicebot's changes from the transition switch to deprecations. |
right? |
I was just about to ask what is the current state of branches regarding merging stable into master and so on. I will need to fixup both master and this branch when it is done. |
This pull request introduced a regression: Specifically, commit 62be2fb. |
Works much like
return ref
.Fix https://issues.dlang.org/show_bug.cgi?id=5270
Fix https://issues.dlang.org/show_bug.cgi?id=8993
Fix https://issues.dlang.org/show_bug.cgi?id=14238
Fix https://issues.dlang.org/show_bug.cgi?id=15544
Fix https://issues.dlang.org/show_bug.cgi?id=15996