@@ -333,7 +333,7 @@ class HandleTable:
333333 return i
334334```
335335The ` HandleTable ` class maintains a dense array of handles that can contain
336- holes created by the ` remove_or_drop ` method (defined below). These holes are
336+ holes created by the ` transfer_or_drop ` method (defined below). These holes are
337337kept in a separate Python list here, but an optimizing implementation could
338338instead store the free list in the free elements of ` array ` . When adding a new
339339handle, ` HandleTable ` first consults the ` free ` list, which is popped LIFO to
@@ -349,11 +349,11 @@ use-after-free:
349349 return self .array[i]
350350```
351351
352- The last method of ` HandleTable ` , ` remove_or_drop ` , is used to drop or transfer
353- a handle out of the handle table. ` remove_or_drop ` adds the removed handle to
354- the ` free ` list for later recycling by ` add ` (above).
352+ The last method of ` HandleTable ` , ` transfer_or_drop ` , is used to transfer or
353+ drop a handle out of the handle table. ` transfer_or_drop ` adds the removed
354+ handle to the ` free ` list for later recycling by ` add ` (above).
355355``` python
356- def remove_or_drop (self , i , t , drop ):
356+ def transfer_or_drop (self , i , t , drop ):
357357 h = self .get(i)
358358 trap_if(h.lend_count != 0 )
359359 match t:
@@ -370,13 +370,13 @@ the `free` list for later recycling by `add` (above).
370370 return h
371371```
372372The ` lend_count ` guard ensures that no dangling borrows are created when
373- destroying a resource. Because ` remove_or_drop ` is used for cross-component
373+ destroying a resource. Because ` transfer_or_drop ` is used for cross-component
374374transfer of ` own ` handles (via ` lift_own ` below), this ` lend_count ` guard
375375ensures that when a component receives an ` own ` , it receives a unique reference
376376to the resource and that there aren't any dangling borrows hanging around from
377- the previous owner. The bookkeeping performed by ` remove_or_drop ` for borrowed
378- handles records the fulfillment of the obligation of the borrower to drop the
379- handle before the end of the call.
377+ the previous owner. The bookkeeping performed by ` transfer_or_drop ` for
378+ borrowed handles records the fulfillment of the obligation of the borrower to
379+ drop the handle before the end of the call.
380380
381381Finally, we can define ` HandleTables ` (plural) as simply a wrapper around
382382a mutable mapping from ` ResourceType ` to ` HandleTable ` :
@@ -396,16 +396,16 @@ class HandleTables:
396396 return self .table(t.rt).add(h, t)
397397 def get (self , i , rt ):
398398 return self .table(rt).get(i)
399- def remove (self , i , t ):
400- return self .table(t.rt).remove_or_drop (i, t, drop = False )
399+ def transfer (self , i , t ):
400+ return self .table(t.rt).transfer_or_drop (i, t, drop = False )
401401 def drop (self , i , t ):
402- self .table(t.rt).remove_or_drop (i, t, drop = True )
402+ self .table(t.rt).transfer_or_drop (i, t, drop = True )
403403```
404404While this Python code performs a dynamic hash-table lookup on each handle
405405table access, as we'll see below, the ` rt ` parameter is always statically
406406known such that a normal implementation can statically enumerate all
407407` HandleTable ` objects at compile time and then route the calls to ` add ` ,
408- ` get ` and ` remove_or_drop ` to the correct ` HandleTable ` at the callsite. The
408+ ` get ` and ` transfer_or_drop ` to the correct ` HandleTable ` at the callsite. The
409409net result is that each component instance will contain one handle table per
410410resource type used by the component, with each compiled adapter function
411411accessing the correct handle table as-if it were a global variable.
@@ -623,10 +623,10 @@ side will wrap this representation value in its own new `OwnHandle` in its on
623623handle table.
624624``` python
625625def lift_own (cx , i , t ):
626- h = cx.inst.handles.remove (i, t)
626+ h = cx.inst.handles.transfer (i, t)
627627 return OwnHandle(h.rep, 0 )
628628```
629- Note that ` t ` refers to an ` own ` type and thus ` HandleTable.remove ` will, as
629+ Note that ` t ` refers to an ` own ` type and thus ` HandleTable.transfer ` will, as
630630shown above, ensure that the handle at index ` i ` is an ` OwnHandle ` .
631631
632632Lastly, ` borrow ` handles are lifted by getting the handle out of the
@@ -1002,11 +1002,6 @@ type, the only thing the borrowed handle is good for is calling
10021002` resource.rep ` , so lowering might as well avoid the overhead of creating an
10031003intermediate borrow handle.
10041004
1005- Note that the ` rt ` value that is stored in the runtime ` Handle ` captures what
1006- is statically known about the handle right before losing this information in
1007- the homogeneous ` HandleTable ` . Moreoever, as described above, distinct type
1008- imports are given distinct ` rt ` values so that handles produced by lowering
1009- different type imports are never interchangeable.
10101005
10111006### Flattening
10121007
0 commit comments