Refactor Python definitions related to borrow
handles
#215
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit is at attempt of mine to simplify the moving parts in how handles are specified by refactoring the related Python code which specifies how everything works. Previously I found the interactions between the various methods difficult to understand due to some layers of abstraction and where various methods were invoked. Here I've attempted to (subjectively at least) simplify a few things:
The
add
andremove
methods onHandleTable
no longer do any bookkeeping of borrow-related information. This makesHandleTable
a pure "slab class" where it's ideally easy to see "oh hey it's a slab" and then ignore the bulk of the Python code which otherwise just says what a slab is.The
add_borrow_to_table
andremove_borrow_from_table
methods were removed in favor of "just" frobbing theborrow_count
field directly. The method abstraction at least seemed to me to imply more management behind the scenes but it ended up only ever being an increment/decrement.The
lift_borrow_from
method was renamed totrack_owning_lend
to indicate that it's not doing any lifting operations and it's part of the metadata tracking.The metadata bookkeeping in
add
andremove
is now inlined directly into the{lift,lower}_{own,borrow}
andcanon_resource_drop
functions, along with theadd_borrow_to_table
andremove_borrow_from_table
methods.Overall to me at least this felt easier to understand where there are seven basic primitives here:
resource.{new,rep,drop}
plus{lift,lower}_{own,borrow}
and all seven now relatively clearly document, just by looking at their single method, what each primitive is responsible for. Previously methods had to be followed to understand how the borrowing/own dynamic tracking all interacted but it's, at least in theory, more up-front now.