-
Notifications
You must be signed in to change notification settings - Fork 602
Warn when refalias desynchronises a closure-captured variable
#24026
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
base: blead
Are you sure you want to change the base?
Conversation
The `refalias` feature is currently experimental due to a number of limitations of its implementation, most notably the effect it has on closures such as the one illustrated in this unit test. Any change in implementation to make this case function as intended would be a large undertaking, so instead as a path towards being able to remove the experimental status from this feature, we consider this behaviour warning instead.
9d6094b to
260c8d6
Compare
|
I'm not hugely happy about this being a runtime warning emitted by the Unfortunately, I sat and thought about it for a while and I couldn't think of a way to reliably detect the situation in all cases at compiletime. While in some cases it can be detected, it could be that at the time the As an example: my sub inner;
my @x;
\@x = ["break"];
inner();
sub inner { my @y = @x; }I think the only way to reliably detect that at compiletime would be to add a new PADNAME flag to annotate every variable that is ever the target of a refalias operation, and warn when attempting to form a closure over them. But then that would hit a lot of "safe" cases too, such as the superficially similar case below, that behaves entirely differently: my @x;
\@x = ["not-broken"];
{
my sub inner { my @y = @x; }
inner();
}I don't have any good ideas besides this currently. |
|
please look also at test at https://github.com/Perl/perl5/pull/23873/files#diff-0a339d203b77e8f749d630a9f5b59e74a9bef94e1dc4515b7027abfe92476b77R119 refaliasing in for-over loop, unlike other kind of global variables, doesn't preserve original value before loop. |
|
It's unclear from that link quite what you mean, but I believe this test illustrates it? my $var = 42;
foreach \$var ( \(1, 2, 3) ) { say "VAR is $var"; }
say "VAR finished $var";I believe we were expecting the final line to print 42. If that's the case, perhaps raise this as a new issue? That should just be a small implementation detail that can be fixed with the SAVE stack. |
|
yes, test case I linked shows exactly this issue. |
|
I see now opened as #24028 |
The
refaliasfeature is currently experimental due to a number of limitations of its implementation, most notably the effect it has on closures such as the one illustrated in this unit test. Any change in implementation to make this case function as intended would be a large undertaking, so instead as a path towards being able to remove the experimental status from this feature, we consider this behaviour warning instead.