-
Notifications
You must be signed in to change notification settings - Fork 648
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
Replace use of id() with global counter-based id. #2313
Conversation
Seeing an odd, seemingly unrelated doctest failure in one case here that confuses me, I'll have to look into it later. |
60dae36
to
831ee54
Compare
ha - I noticed from a failing user's unit test that any construction-created/self-bound unique id scheme will break under default |
Historically we key'd on id() to record sharing relationships during lifting and outer module adoption. This was dumb, and after recently fixing one bad bug arising from id reuse, we should use something sound instead.
Is this actually what we want? Supposing a deepcopy will return an identical copy of the object, so maybe the id should be the same as well? |
Probably not since it would break the previous behavior, we really want the semantics to be "share by reference" which meant "key on object instance identity" following what we intended w. the old id()-based sharing. In any case there are internal code/tests that assume the previous behavior: deepcopy should return a new non-shared instance. (some people seem to use it as a hack to clone layer definitions) |
So is id() the right approach after all? Or perhaps we should error out on deep copies? |
It's pretty easy to maintain the per-instance behavior (non shared ids) by defining I would just rather never have to worry about id() lifetime issues again, it's a bit silly to introduce lifetime concerns into python of all languages! |
Oops, this was accidentally merged early because of a miscommunication, we can roll it back if this change is ultimately unwanted (it should have no user-visible effects either way). |
I have no problem with this change, your explanation makes sense to me so I am fine with the change as it is. For reference: this is a strict improvement over the id() approach which was flawed since it could result in multiple objects having the same id. This is because id() just returns the address of the C pointer to the object instance, which can be reused after garbage collection. This can lead to bugs. |
Historically we key'd on id() to record sharing relationships during
lifting and outer module adoption. This was dumb, and after recently
fixing one bad bug arising from id reuse, we should use something
sound instead.