@@ -351,7 +351,7 @@ Rust has a lightweight object system based on structural object types: there
351
351
is no ``class hierarchy'' nor any concept of inheritance. Method overriding
352
352
and object restriction are performed explicitly on object values, which are
353
353
little more than order-insensitive records of methods sharing a common private
354
- value. Objects that reside outside the GC layer can have destructors.
354
+ value.
355
355
356
356
@sp 1
357
357
@item Dynamic type
@@ -395,32 +395,16 @@ can designate other tasks to handle signals for them. This permits
395
395
organizing tasks into mutually-supervising or mutually-failing groups.
396
396
397
397
@sp 1
398
- @item Deterministic destruction
399
-
400
- Non-GC objects can have destructor functions, which are executed
401
- deterministically in top-down ownership order, as control frames are exited
402
- and/or objects are otherwise freed from data structures holding them. The same
403
- destructors are run in the same order whether the object is deleted by
404
- unwinding during failure or normal execution.
405
-
406
- Similarly, the rules for freeing non-GC values are deterministic and
407
- predictable: on scope-exit or structure-release, local slots are released
408
- immediately. Referenced boxes have their reference count decreased and are
409
- released if the count drops to zero. Aliases are silently forgotten.
410
-
411
- GC values are local to a task, and are subject to per-task garbage
412
- collection. As a result, unreferenced GC-layer boxes are not necessarily freed
413
- immediately; if an unreferenced GC box is part of an acyclic graph, it is
414
- freed when the last reference to it drops, but if it is part of a reference
415
- cycle it will be freed when the GC collects it (or when the owning task
416
- terminates, at the latest).
417
-
418
- GC values can point to non-GC values but not vice-versa. Doing so merely
419
- delays (to an undefined future time) the moment when the deterministic,
420
- top-down destruction sequence for the referenced non-GC values
421
- @emph {start }. In other words, the non-GC ``leaves'' of a GC value are released
422
- in a locally-predictable order, even if the ``interior'' cyclic part of the GC
423
- value is released in an unpredictable order.
398
+ @item Resource types with deterministic destruction
399
+
400
+ Rust includes a type constructor for @emph {resource } types, which have an
401
+ associated destructor and cannot be moved in memory. Resources types belong to
402
+ the kind of @emph {pinned } types, and any value that directly contains a
403
+ resource is implicitly pinned as well.
404
+
405
+ Resources can only contain types from the pinned or unique kinds of type,
406
+ which means that unlike finalizers, there is always a deterministic, top-down
407
+ order to run the destructors of a resource and its sub-resources.
424
408
425
409
@sp 1
426
410
@item Typestate system
@@ -662,10 +646,7 @@ The keywords are:
662
646
@tab @code {import }
663
647
@tab @code {export }
664
648
@tab @code {let }
665
- @item @code {state }
666
- @tab @code {gc }
667
649
@tab @code {const }
668
- @tab @code {thread }
669
650
@item @code {auth }
670
651
@tab @code {unsafe }
671
652
@tab @code {as }
@@ -699,7 +680,7 @@ The keywords are:
699
680
@tab @code {iter }
700
681
@tab @code {pred }
701
682
@tab @code {obj }
702
- @tab @code {drop }
683
+ @tab @code {resource }
703
684
@item @code {task }
704
685
@tab @code {port }
705
686
@tab @code {chan }
@@ -1975,13 +1956,15 @@ aspects of a value include:
1975
1956
@item Whether the value represents textual or numerical information.
1976
1957
@item Whether the value represents integral or floating-point information.
1977
1958
@item The sequence of memory operations required to access the value.
1978
- @item The storage layer the value resides in (immutable, state or gc ).
1959
+ @item The @emph { kind } of the type (pinned, unique or shared ).
1979
1960
@end itemize
1980
1961
1981
1962
For example, the type @code {@{ x: u8 , y: u8 @} } defines the set of immutable
1982
1963
values that are composite records, each containing two unsigned 8-bit integers
1983
1964
accessed through the components @code {x } and @code {y }, and laid out in memory
1984
- with the @code {x } component preceding the @code {y } component.
1965
+ with the @code {x } component preceding the @code {y } component. This type is of
1966
+ @emph {unique } kind, meaning that there is no shared substructure with other
1967
+ types, but it can be copied and moved freely.
1985
1968
1986
1969
@node Ref.Item.Tag
1987
1970
@subsection Ref.Item.Tag
@@ -2269,10 +2252,9 @@ assert (p._1 == "world");
2269
2252
@cindex Vector types
2270
2253
@cindex Array types , see @i {Vector types }
2271
2254
2272
- The vector type-constructor represents a homogeneous array of
2273
- values of a given type. A vector has a fixed size. The layer of a vector type
2274
- is to the layer of its member type, like any type that contains a single
2275
- member type.
2255
+ The vector type-constructor represents a homogeneous array of values of a
2256
+ given type. A vector has a fixed size. The kind of a vector type depends on
2257
+ the kind of its member type, as with other simple structural types.
2276
2258
2277
2259
Vectors can be sliced. A slice expression builds a new vector by copying a
2278
2260
contiguous range -- given by a pair of indices representing a half-open
@@ -2378,8 +2360,8 @@ Ports are modeled as stateful native types, with built-in meaning to the
2378
2360
language. They cannot be transmitted over channels or otherwise replicated,
2379
2361
and are always local to the task that creates them.
2380
2362
2381
- Ports (like channels) can only be carry types of the immutable layer . No
2382
- mutable values can pass over a port or channel.
2363
+ Ports (like channels) can only be carry types of unique kind . No shared or
2364
+ pinned values can pass over a port or channel.
2383
2365
2384
2366
An example of a @code {port } type:
2385
2367
@example
@@ -2404,8 +2386,8 @@ Channels are immutable, and can be transmitted over channels to other
2404
2386
tasks. They are modeled as immutable native types with built-in meaning to the
2405
2387
language.
2406
2388
2407
- Channels (like ports) can only be carry types of the immutable layer . No
2408
- mutable values can pass over a port or channel.
2389
+ Channels (like ports) can only be carry types of unique kind . No
2390
+ pinned or shared values can pass over a port or channel.
2409
2391
2410
2392
When a task sends a message into a channel, the task forms an outgoing queue
2411
2393
associated with that channel. The per-task queue @emph {associated } with a
@@ -2465,20 +2447,21 @@ declaration. Such a ``plain'' object type can be used to describe an interface
2465
2447
that a variety of particular objects may conform to, by supporting a superset
2466
2448
of the methods.
2467
2449
2468
- An object type that can contain fields of a given layer must be declared as
2469
- residing in that layer (or lower), like any other type.
2450
+ The kind of an object type serves as a restriction to the kinds of fields that
2451
+ may be stored in it. Unique objects, for example, can only carry unique values
2452
+ in their fields.
2470
2453
2471
2454
An example of an object type with two separate object items supporting it, and
2472
2455
a client function using both items via the object type:
2473
2456
2474
2457
@example
2475
2458
2476
- state type taker =
2459
+ type taker =
2477
2460
state obj @{
2478
2461
fn take(int);
2479
2462
@} ;
2480
2463
2481
- state obj adder(mutable int x) @{
2464
+ obj adder(mutable int x) @{
2482
2465
fn take(int y) @{
2483
2466
x += y;
2484
2467
@}
0 commit comments