Replies: 2 comments 5 replies
-
@phate @sjalander @haved should have tagged as RFC |
Beta Was this translation helpful? Give feedback.
-
Proposed transition strategy:
This changes the places that currently store a unique_ptr to shared_ptr, and also the return value of the copy method. This is a minor API change that slightly causes compile-breakage to downstream clients (HLS), but it is also really trivially fixed (just make the same trivial change for every user-defined type). In principle the API change of the copy method could be delayed, or rolled out differently (i.e. adding a transitionary additional copy_shared method or so), if this creates problems for anyone.
Currently all of these methods need to copy the received type in order to store them anywhere. After this change, they can just receive the reference they received and store it, so this will step-by-step remove all copy operations. The intent is here to also allow time for downstream to adapt and provide a transitionary period. 2a. singleton instances for "frequently used types" should be self-explanatory, can happen in parallel/together with 2
I do not see much value in it, it is basically a container for a unique_ptr, and would become mostly synonymous with shared_ptr. If this is removed, it might however be neat to also change the signature of the "type" method of inputs/outputs so the shared_ptr is exposed (otherwise they are not shallow-copyable by simply copying the shared_ptr). goal would be to also enforce at the interface level that no "hidden" type copying exists anymore
should be self-explanatory In a follow-up could then try to add a "hash" method to types to try and uniquify instances that compare equal. |
Beta Was this translation helpful? Give feedback.
-
For context, also refer to PR: #496 (for illustration, not for immediate merging)
The intent is to replace the current pattern of "copying + allocating type instances" all over the place, to just declare types "constant objects" that are not copied anymore, but just have their pointers copied (with reference counting).
The way this presently works:
The way it should work:
The PR should illustrate:
The PR in itself does not attempt to (substantially) reduce the number of copying yet. This would be achieved by replacing function call patterns of the form:
fn(const rvsdg::some_type & type) { .... do_something(type.copy()) ... }
with
fn(std::shared_ptr type) { ... do_something(type) ... }
which can be done on top of this PR, converting the individual use sites one-by-one. (Converting everything in one go creates a merge-conflict-nightmare IMHO). The "end state" would be reached when the "copy" method on types can be removed entirely.
There are various nuances not address in this PR, like having singleton instances for commonly used types (would be feasible, and result in appreciable reduction of copies already).
The main "concern" with this is that the work cannot be meaningfully finished without some API changes that affect downstream projects, so I would appreciate comments on this. I can think of various ways to provide compatibility adaptors to ease the API transition, but it will unfortunately not be entirely disruption-free.
Beta Was this translation helpful? Give feedback.
All reactions