@@ -333,7 +333,7 @@ class HandleTable:
333
333
return i
334
334
```
335
335
The ` 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
337
337
kept in a separate Python list here, but an optimizing implementation could
338
338
instead store the free list in the free elements of ` array ` . When adding a new
339
339
handle, ` HandleTable ` first consults the ` free ` list, which is popped LIFO to
@@ -349,11 +349,11 @@ use-after-free:
349
349
return self .array[i]
350
350
```
351
351
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).
355
355
``` python
356
- def remove_or_drop (self , i , t , drop ):
356
+ def transfer_or_drop (self , i , t , drop ):
357
357
h = self .get(i)
358
358
trap_if(h.lend_count != 0 )
359
359
match t:
@@ -370,13 +370,13 @@ the `free` list for later recycling by `add` (above).
370
370
return h
371
371
```
372
372
The ` 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
374
374
transfer of ` own ` handles (via ` lift_own ` below), this ` lend_count ` guard
375
375
ensures that when a component receives an ` own ` , it receives a unique reference
376
376
to 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.
380
380
381
381
Finally, we can define ` HandleTables ` (plural) as simply a wrapper around
382
382
a mutable mapping from ` ResourceType ` to ` HandleTable ` :
@@ -396,16 +396,16 @@ class HandleTables:
396
396
return self .table(t.rt).add(h, t)
397
397
def get (self , i , rt ):
398
398
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 )
401
401
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 )
403
403
```
404
404
While this Python code performs a dynamic hash-table lookup on each handle
405
405
table access, as we'll see below, the ` rt ` parameter is always statically
406
406
known such that a normal implementation can statically enumerate all
407
407
` 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
409
409
net result is that each component instance will contain one handle table per
410
410
resource type used by the component, with each compiled adapter function
411
411
accessing 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
623
623
handle table.
624
624
``` python
625
625
def lift_own (cx , i , t ):
626
- h = cx.inst.handles.remove (i, t)
626
+ h = cx.inst.handles.transfer (i, t)
627
627
return OwnHandle(h.rep, 0 )
628
628
```
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
630
630
shown above, ensure that the handle at index ` i ` is an ` OwnHandle ` .
631
631
632
632
Lastly, ` 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
1002
1002
` resource.rep ` , so lowering might as well avoid the overhead of creating an
1003
1003
intermediate borrow handle.
1004
1004
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.
1010
1005
1011
1006
### Flattening
1012
1007
0 commit comments