@@ -257,22 +257,24 @@ class ComponentInstance:
257
257
The ` HandleTable ` class is defined in terms of a collection of supporting
258
258
runtime bookkeeping classes that we'll go through first.
259
259
260
- The ` Resource ` class represents a runtime instance of a resource type, storing
261
- the core representation value (which is currently fixed to ` i32 ` ) and the
262
- component instance that is implementing this resource .
260
+ The ` ResourceType ` class represents a resource type that has been defined by
261
+ the specific component instance pointed to by ` impl ` with a particular
262
+ function closure as the ` dtor ` .
263
263
``` python
264
264
@dataclass
265
- class Resource :
266
- rep: int
265
+ class ResourceType (Type ):
267
266
impl: ComponentInstance
267
+ dtor: Optional[Callable[[int ],None ]]
268
268
```
269
269
270
- The ` OwnHandle ` and ` BorrowHandle ` classes represent runtime handle values of
271
- ` own ` and ` borrow ` type, resp:
270
+ The ` Handle ` class and its subclasses represent handle values referring to
271
+ resources. The ` rep ` field of ` Handle ` stores the representation value
272
+ (currently fixed to ` i32 ` ) pass to ` resource.new ` for the resource that this
273
+ handle refers to.
272
274
``` python
273
275
@dataclass
274
276
class Handle :
275
- resource: Resource
277
+ rep: int
276
278
rt: ResourceType
277
279
lend_count: int
278
280
@@ -284,8 +286,7 @@ class OwnHandle(Handle):
284
286
class BorrowHandle (Handle ):
285
287
scope: BorrowScope
286
288
```
287
- The ` resource ` field points to the resource instance this handle refers to. The
288
- ` rt ` field points to a runtime value representing the static
289
+ The ` rt ` field points to a runtime value representing the static
289
290
[ ` resourcetype ` ] ( Explainer.md#type-definitions ) of this handle and is used by
290
291
dynamic type checking below. Lastly, the ` lend_count ` field maintains a count
291
292
of the outstanding handles that were lent from this handle (by calls to
@@ -962,13 +963,13 @@ current component instance's `HandleTable`:
962
963
``` python
963
964
def lower_own (cx , src , rt ):
964
965
assert (isinstance (src, OwnHandle))
965
- h = OwnHandle(src.resource , rt, 0 )
966
+ h = OwnHandle(src.rep , rt, 0 )
966
967
return cx.inst.handles.insert(h)
967
968
968
969
def lower_borrow (cx , src , rt ):
969
970
assert (isinstance (src, Handle))
970
971
cx.borrow_scope.add(src)
971
- h = BorrowHandle(src.resource , rt, 0 , cx.borrow_scope)
972
+ h = BorrowHandle(src.rep , rt, 0 , cx.borrow_scope)
972
973
return cx.inst.handles.insert(h)
973
974
```
974
975
Note that the ` rt ` value that is stored in the runtime ` Handle ` captures what
@@ -1542,7 +1543,7 @@ Calling `$f` invokes the following function, which creates a resource object
1542
1543
and inserts it into the current instance's handle table:
1543
1544
``` python
1544
1545
def canon_resource_new (inst , rt , rep ):
1545
- h = OwnHandle(Resource( rep, inst) , rt, 0 )
1546
+ h = OwnHandle(rep, rt, 0 )
1546
1547
return inst.handles.insert(h)
1547
1548
```
1548
1549
@@ -1563,8 +1564,8 @@ optional destructor.
1563
1564
def canon_resource_drop (inst , t , i ):
1564
1565
h = inst.handles.remove(i, t)
1565
1566
if isinstance (t, Own) and t.rt.dtor:
1566
- trap_if(not h.resource .impl.may_enter)
1567
- t.rt.dtor(h.resource. rep)
1567
+ trap_if(not t.rt .impl.may_enter)
1568
+ t.rt.dtor(h.rep)
1568
1569
```
1569
1570
The ` may_enter ` guard ensures the non-reentrance [ component invariant] , since
1570
1571
a destructor call is analogous to a call to an export.
@@ -1586,8 +1587,7 @@ matches. Note that the "locally-defined" requirement above ensures that only
1586
1587
the component instance defining a resource can access its representation.
1587
1588
``` python
1588
1589
def canon_resource_rep (inst , rt , i ):
1589
- h = inst.handles.get(i, rt)
1590
- return h.resource.rep
1590
+ return inst.handles.get(i, rt).rep
1591
1591
```
1592
1592
1593
1593
0 commit comments