-
Notifications
You must be signed in to change notification settings - Fork 559
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
refaliasing breaks refcounting of field variable #20947
Comments
Agree; the current behaviour is definitely a bug.
I think there are possibly arguments for and against any of these situations. The first thought that comes to mind is that I don't think there are currently any other situations where a refalias operation will actually croak, so doing so here feels weird. I wonder if the best thing to do is to aim at as similar behaviour as would happen on a refalias of a regular (blessed) hash element:
I.e. that the actual field storage in the actual object should be replaced. Annoyingly it would be hard to arrange for that to happen, because during In any case, the actual SV in the pad doesn't look any different, so the refalising operation would have to inspect PadnameIsFIELD() of the corresponding pad name in order to know whether to take special measures here. Exactly what special measures are, as you say, up for debate. Opinions anyone? |
Actually, another thought says that if these field variables behave more like captured lexicals, then perhaps the change is only visible during the lifetime of a single invocation of the method:
|
Actually it's a bit more complicated than that. If you want to treat it like a captured lexical, the refalias replaces that variable permanently for the entire life of that method (asterisk):
Asterisk: of course it's even worse. In reality it would need to replace the "field", for only that method, and for only that instance, and for the entire life of that particular instance. Because conceptually you'd be viewing the method as closed over that specific instance's fields, which means there's a conceptually-separate closure of the method for each instance (in reality they're just one method that rebinds to the fields with each invocation). |
(copied from email)
Combining the experimental core class system with experimental refaliasing, here's an attempt to replace a field variable:
How this ought to behave is up for debate. Maybe the replacement operation should croak, maybe it should affect the pad of the running method without affecting the field variable, and maybe it should replace the field variable in the object representation. But it certainly shouldn't do the above, prematurely freeing an SV and then segfaulting. It looks to me like this is doing a replacement in the pad but getting confused about the refcounting of the pad entry.
https://www.nntp.perl.org/group/perl.perl5.porters/2023/03/msg266060.html
The text was updated successfully, but these errors were encountered: