Skip to content
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

Merged
merged 14 commits into from Nov 1, 2016
Merged

Conversation

@mathias-lang-sociomantic
Copy link
Contributor

The commit message / P.R. message is highly insufficient for most people to understand what the design is.
I don't see a changelog entry, nor a dlang.org P.R. linked. How is anyone supposed to review this P.R. if the only thing available is the diff ?

@WalterBright
Copy link
Member Author

@JackStouffer
Copy link
Member

  • It seems that DIP 90 was never discussed with the community, as I couldn't turn up anything on the forum
  • The DIP says draft, was it accepted?
  • If it wasn't offically accepted, then it should probably go through the new DIP process

@iain-buclaw-sociomantic

So how does (return scope int* p) differ from (int* p)?

@WalterBright
Copy link
Member Author

@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 return ref works.

@wilzbach
Copy link
Member

wilzbach commented Aug 3, 2016

It seems that DIP 90 was never discussed with the community, as I couldn't turn up anything on the forum
The DIP says draft, was it accepted?
If it wasn't offically accepted, then it should probably go through the new DIP process

The new DIP process is intended to be different for Walter. To quote:

Language changes initiated by language authors are also supposed to go through the DIP queue. By their very nature formal approval is not needed. Hence they are processed slightly different and an increased focus is put into bringing community attention and feedback.
At the time of writing this document only Walter Bright and Andrei Alexandrescu are meant as a language authors here.

@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?

@mihails-strasuns
Copy link

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 ;)

@mihails-strasuns
Copy link

(but it was ages ago thus there must be some misunderstanding here)

@WalterBright
Copy link
Member Author

@Dicebot it's there now.

@WalterBright WalterBright changed the title return scope: first support [WIP] return scope: first support Aug 16, 2016
@jacob-carlborg
Copy link
Contributor

What about the -scope flag that the DIP mentions. Shouldn't that be the first step, or included in this PR?

@mihails-strasuns
Copy link

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 [WIP] is there in the title.

@jacob-carlborg
Copy link
Contributor

jacob-carlborg commented Aug 17, 2016

Reviewing the source patches is still welcome but please don't worry about actual feature set and compiler flags while the [WIP] is there in the title.

Fair enough, as long as it doesn't get merged without compiler flags.

@dlang-bot
Copy link
Contributor

@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.

(The DLang Bot is under development. If you experience any issues, please open an issue at its repo.)

@codecov-io
Copy link

codecov-io commented Aug 22, 2016

Current coverage is 87.37% (diff: 89.28%)

Merging #5972 into scope will decrease coverage by 0.05%

@@              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           

Powered by Codecov. Last update 9e6f8a7...48b7815

@WalterBright WalterBright force-pushed the return-scope branch 2 times, most recently from abe2342 to bac69c5 Compare August 22, 2016 23:21
@dlang-bot
Copy link
Contributor

dlang-bot commented Aug 23, 2016

Fix Bugzilla Description
8838 Slicing static arrays should be considered unsafe (@System)
14238 DIP25: escape checks can be circumvented with delegate
15544 Escaping fields to a heap delegate must be disallowed in @safe code

@WalterBright
Copy link
Member Author

@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?

@MartinNowak
Copy link
Member

@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.
But just like with the stable branch we shouldn't drag in master unless really necessary.

@WalterBright
Copy link
Member Author

Thanks, @MartinNowak , you're a life saver!

@MartinNowak
Copy link
Member

Seems like github isn't updating the diff view, but my local diff looks fine.
I was about to pull this anyhow, so we have a discussion base for the call today.
Also PRs on feature branches shouldn't become so big, their point is incremental work on the feature.

@WalterBright
Copy link
Member Author

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? :-)

@MartinNowak
Copy link
Member

Yeah, I wasn't thinking when I rebased it. I tend to routinely rebase things so they don't diverge too far.

Just like stable it has a different base branch, please rebase this branch against upstream/scope next time.
Actually there are few reasons to rebase it, unless we really need something from master.

My diff view isn't changing, either. Maybe if I rebased it again? :-)

Yes, GH only updates on branch changes to limit the repercussions of a commit on master.

Copy link
Member

@MartinNowak MartinNowak left a 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;
Copy link
Member

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;
Copy link
Member

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)
Copy link
Member

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;
Copy link
Member

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)
Copy link
Member

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));
}
}
}
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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);
Copy link
Member

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;
Copy link
Member

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.

@MartinNowak
Copy link
Member

MartinNowak commented Nov 1, 2016

In fact, please never rebase PRs, unless really necessary, you just killed half of my review comments ;), please expand the show outdated stuff.

@MartinNowak
Copy link
Member

MartinNowak commented Nov 1, 2016

What about those @safe failures btw? https://travis-ci.org/dlang/dmd/jobs/172243053#L1070
We could build a preview if you can manage to fix those.

@MartinNowak MartinNowak merged commit 20add0d into dlang:scope Nov 1, 2016
@WalterBright WalterBright deleted the return-scope branch November 1, 2016 11:09
@WalterBright
Copy link
Member Author

What about those @safe failures btw?

I don't know. My first thought is it has something to do with Dicebot's changes from the transition switch to deprecations.

@WalterBright
Copy link
Member Author

rebase this branch against upstream/scope next time.

git fetch upstream scope

right?

@mihails-strasuns-sociomantic
Copy link
Contributor

I don't know. My first thought is it has something to do with Dicebot's changes from the transition switch to deprecations.

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.

@CyberShadow
Copy link
Member

This pull request introduced a regression:
https://issues.dlang.org/show_bug.cgi?id=17445

Specifically, commit 62be2fb.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet