-
Notifications
You must be signed in to change notification settings - Fork 165
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
WIP Stop system setters storing attribute values in mutable objects #3588
Conversation
These setters are used by `IsAttributeStoringRep`. It isn't safe to store attribute values in mutable objects in general, because changes to the object may invalidate the value. If you know it is safe, you can install a custom setter. The only reason for mutable objects being is `IsAttributeStoringRep` at all is that they may want to start storing attributes if and when they are made immutable.
@stevelinton just for curiosity: In the case of attributes, the change you propose seems to switch off also the effect of explicitly calling |
@ThomasBreuer That's a tricky question. What I wanted to do was to allow for specially installed Setter methods, so that if you knew that the allowed mutations of your object could not change the value of a particular attribute, you could install a setter for it. Hence I put the test in the system setter. We certainly could (and perhaps for consistency with properties should) do the test in I don't have a strong feeling as to which is nicer. I don't see a sensible compromise option although that doesn't mean there isn't one. |
@stevelinton Thanks for your reply.
This is the current behaviour of properties.
Currently 4. does not hold in the sense that attribute setters are called automatically also for mutable objects as soon as the attribute call returns its value --this is the bug described in #1371 . However, the above statements describe only the "default behaviour" of attributes. However, the situation is different for property setters. |
@stevelinton I am not sure where to put my comments, now we have issue #1371 and pull requests #3560, #3588, #3592. As I wrote in a comment to #3588, I think that a proper handling of attributes for mutable objects in
(One possible implementation would distinguish between unconditional calls of the setter operation (in the case of an explicit setter call) and conditional calls (just as a side effect of calling the attribute). I think the real problem is that the same approach will not work for properties, in the sense that we cannot work with individual property setter methods. |
@ThomasBreuer My feeling is that we can implement the first, and either one of your second and third bullet points:
quite easily and with only very local changes. Essentially the two PRs demonstrate the two choices. I agree it's possible to have all three, for instance as you describe, but I don't see a way to do it which is simple and doesn't involve very widespread changes. So the question is then, is it worth it? and if not, which compromise to we take? |
@stevelinton o.k., if I have to choose between the two proposed solutions, I am in favour of #3592.
|
Superceded by #3592 |
Please use the following template to submit a pull request, filling
in at least the "Text for release notes" and/or "Further details".
Thank You!
Description
The system setters used for objects in
IsAttributeStoringRep
did not check the objects for mutability.This leads to unsafe behaviour where attribute values were stored in mutable objects. Mutable objects in
IsAttributeStoringRep
are thankfully rare, but they are not impossible or unreasonable, especially for objects that may be made immutable byMakeImmutable
in the future (whereupon they should start storing attribute values).This addresses #1371 and questions that arose in #3560
At this stage this PR is just a proof of concept to get comment an wider testing
Text for release notes
The values of computed Attributes will no longer be stored automatically in mutable attribute-storing
objects, since they may become out of date as the object mutates. If you wish to store such a value and know that it is safe to do so, then you can address this by defining a custom setter method for your object.
Further details
Still needed before merge:
One of the diffs is a bit bigger than it could be because I clang-formatted a bit too much code.
Checklist for pull request reviewers