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

get started on scope diagnostics #5903

Merged
merged 1 commit into from
Jul 5, 2016
Merged

Conversation

WalterBright
Copy link
Member

No description provided.

@WalterBright
Copy link
Member Author

Blocked by dlang/phobos#4549

return;
}
}
error(e.loc, "scope variable %s may not be returned", v);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small language nitpick, "may" sounds a bit too optional for me. Shouldn't we use sth like "can't"?

(Disclaimer: I am not a native speaker.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"may not" does not mean "optional". I also prefer to avoid contractions in code because grepping for them is a pain because of the quote.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"may" can be used to indicate both optionality or regulation, but when negated it is always as strong as "must not", so it sounds good to me.
In the long term we should probably adopt RFC 2119 for the specification and compiler messages, but that would be a huge effort.

@WalterBright WalterBright force-pushed the scopeerror branch 2 times, most recently from 217db64 to a3dc004 Compare July 4, 2016 03:11
@WalterBright
Copy link
Member Author

Blocked by dlang/phobos#4556

@PetarKirov
Copy link
Member

In general I support this change, but as noted in the Phobos PR, this could potentially affect a lot of code that uses functions that take scope delegates. Is it possible to mitigate this by making something like return dg_t work, i.e. ensure that the delegate would not allocate it's captured variables on the heap and cannot be escaped, with exception that it can be returned?

@WalterBright
Copy link
Member Author

In the future there will be return scope which will do what you wish.

@andralex
Copy link
Member

andralex commented Jul 5, 2016

Auto-merge toggled on

@andralex andralex merged commit 51cc53f into dlang:master Jul 5, 2016
@PetarKirov
Copy link
Member

In the future there will be return scope which will do what you wish

Great, that's exactly what I want. I just didn't know that we would be able to use both at the same time.

@MartinNowak
Copy link
Member

This PR caused a regression.
Issue 16582 – [REG2.072.0-b1] ParamterDefaultValueTuple fails to compile for scope paramters
Another breaking change w/o notice or clear workaround.
Why do we make valid code an error before introducing a mean to clarify the intention (return scope) 🙄?

@andralex
Copy link
Member

@MartinNowak shall we undo this?

@WalterBright
Copy link
Member Author

It is fixed by #5972

@MartinNowak
Copy link
Member

It is fixed by #5972

But we can't drag that into the release now that the beta is almost done.
This is what I mean when I say that incremental PRs merged into master create lots of problems.

@MartinNowak shall we undo this?

It's non-trivial (but doable) to undo after 3 month and lots of follow-up refactorings.
Not sure how much code is affected by this, but I'd favor to back this off until return scope works.
Made a hacky workaround for the phobos bug.

@WalterBright
Copy link
Member Author

But we can't drag that into the release now that the beta is almost done.

Sure, but I suggested merging it in a month ago for just that reason.

This is what I mean when I say that incremental PRs merged into master create lots of problems.

Not merging things creates another set of problems. For example, there's not a single review yet of the return scope PR. Nobody wants to review large PRs. And at least with this regression, the culprit is small rather than large.

I'd favor to back this off until return scope works.

A practical alternative is to disable the error unless -transition=safe.

Made a hacky workaround for the phobos bug.

Thank you.

@WalterBright WalterBright deleted the scopeerror branch October 16, 2016 00:08
@MartinNowak
Copy link
Member

MartinNowak commented Oct 16, 2016

Sure, but I suggested merging it in a month ago for just that reason.

Well you still submitted them in a different order :).

Not merging things creates another set of problems. For example, there's not a single review yet of the return scope PR. Nobody wants to review large PRs.

Hence feature branches, early review, no risk in master.

And at least with this regression, the culprit is small rather than large.

The one we see, but not necessarily the effect of it. The phobos bug was triggered by some meta code in vibe.d or so, which would affect plenty of users...
We have little knowledge about other code, and w/o a clear workaround estimating the impact to be small remains a motivated guess.

@MartinNowak
Copy link
Member

A practical alternative is to disable the error unless -transition=safe.

See #6183 for why this isn't the correct approach.

I'll make a pass through the project tester, trying to find any other code that runs into problems with this.
I don't expect to find any, so we might get away with it. Still not the way to do such changes.

@mihails-strasuns
Copy link

Is in expanded right now into scope const as has been stated in docs? If yes, this can cause a huge amount of breakage.

@mihails-strasuns
Copy link

For example, there's not a single review yet of the return scope PR. Nobody wants to review large PRs.

Acceptance tests > reviews. Focus on featuring clear practical examples of new feature as part of PR unittests and there will be much less reluctance to merge because it becomes obvious what that huge PR actually does.

It would help a lot if each time I was sending you e-mail with snippets regarding DIP1000, you would have added them as unit-tests instead of explanations via mail.

@MartinNowak
Copy link
Member

Is in expanded right now into scope const as has been stated in docs?

No, it's not, not even sure I can find docs for that.

@mihails-strasuns
Copy link

@MartinNowak
Copy link
Member

MartinNowak commented Oct 19, 2016

Thanks, dmd doesn't seem to apply scope to in parameters atm. This might actually be an oversight of this PR.

const(int)* test(in int* p)
{
    return p;
}

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

Successfully merging this pull request may close these issues.

6 participants