-
-
Notifications
You must be signed in to change notification settings - Fork 606
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 22298 - Nested function's scope parameters can be assigned to variables in enclosing function #13530
Conversation
Thanks for your pull request and interest in making D better, @dkorpel! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla references
Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + dmd#13530" |
This is a memory safety issue, it should probably go to stable |
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.
LGTM.
if (va && | ||
(va.enclosesLifetimeOf(v) && !(v.storage_class & (STC.parameter | STC.temp)) || | ||
if (va && !va.isDataseg() && | ||
(va.enclosesLifetimeOf(v) && !(v.storage_class & STC.temp) || |
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.
Is the check for STC.temp
still necessary?
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.
Maybe not, let's see what the test suite says.
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.
std/datetime/systime.d(9085): Error: scope variable `__tup794` assigned to `foundTZ` with longer lifetime
Looks like it's still needed for tuple lowering.
8352b22
to
dbfecff
Compare
…to variables in enclosing function
dbfecff
to
8722687
Compare
In the initial implementation of lifetimes (#5972), a
__gshared
counter was added that was incremented whenever aVarDeclaration
was created. This is supposed to give a lexical order to local variables, but it fails because there are multiple stages whereVarDeclarations
are created:FuncDeclaration
mixin
are created during function body semanticSpecial cases were added to
VarDeclaration.enclosesLifetimeOf(VarDeclaration v)
, where temporaries were compared using line and column number, and parameters assumed thatlifetime(parameter) > lifetime(local)
always holds. Of course, this can fail when the parameter is from a nested function, and the local is in the enclosing function. It also doesn't account formixin
:I made the sequence counter increment during symbol semantic of the
VarDeclaration
instead of in the constructor, and moved the counter to theglobal
struct so it can be reset easier. This is still hacky and not how I want to see lifetimes implemented, but it'll do for now.