Skip to content

Commit 24c9b82

Browse files
committed
---
yaml --- r: 4540 b: refs/heads/master c: 6b756c4 h: refs/heads/master v: v3
1 parent 9bd8bbf commit 24c9b82

File tree

2 files changed

+29
-46
lines changed

2 files changed

+29
-46
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 0daa4fb1c42c26b7b958e15b31e634f73215e4ff
2+
refs/heads/master: 6b756c4b4a0f632e537cdfd2c0ac63cea357c8ad

trunk/doc/rust.texi

Lines changed: 28 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ Rust has a lightweight object system based on structural object types: there
351351
is no ``class hierarchy'' nor any concept of inheritance. Method overriding
352352
and object restriction are performed explicitly on object values, which are
353353
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.
355355

356356
@sp 1
357357
@item Dynamic type
@@ -395,32 +395,16 @@ can designate other tasks to handle signals for them. This permits
395395
organizing tasks into mutually-supervising or mutually-failing groups.
396396

397397
@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.
424408

425409
@sp 1
426410
@item Typestate system
@@ -662,10 +646,7 @@ The keywords are:
662646
@tab @code{import}
663647
@tab @code{export}
664648
@tab @code{let}
665-
@item @code{state}
666-
@tab @code{gc}
667649
@tab @code{const}
668-
@tab @code{thread}
669650
@item @code{auth}
670651
@tab @code{unsafe}
671652
@tab @code{as}
@@ -699,7 +680,7 @@ The keywords are:
699680
@tab @code{iter}
700681
@tab @code{pred}
701682
@tab @code{obj}
702-
@tab @code{drop}
683+
@tab @code{resource}
703684
@item @code{task}
704685
@tab @code{port}
705686
@tab @code{chan}
@@ -1975,13 +1956,15 @@ aspects of a value include:
19751956
@item Whether the value represents textual or numerical information.
19761957
@item Whether the value represents integral or floating-point information.
19771958
@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).
19791960
@end itemize
19801961

19811962
For example, the type @code{@{x: u8, y: u8@}} defines the set of immutable
19821963
values that are composite records, each containing two unsigned 8-bit integers
19831964
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.
19851968

19861969
@node Ref.Item.Tag
19871970
@subsection Ref.Item.Tag
@@ -2269,10 +2252,9 @@ assert (p._1 == "world");
22692252
@cindex Vector types
22702253
@cindex Array types, see @i{Vector types}
22712254

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.
22762258

22772259
Vectors can be sliced. A slice expression builds a new vector by copying a
22782260
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
23782360
language. They cannot be transmitted over channels or otherwise replicated,
23792361
and are always local to the task that creates them.
23802362

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.
23832365

23842366
An example of a @code{port} type:
23852367
@example
@@ -2404,8 +2386,8 @@ Channels are immutable, and can be transmitted over channels to other
24042386
tasks. They are modeled as immutable native types with built-in meaning to the
24052387
language.
24062388

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.
24092391

24102392
When a task sends a message into a channel, the task forms an outgoing queue
24112393
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
24652447
that a variety of particular objects may conform to, by supporting a superset
24662448
of the methods.
24672449

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.
24702453

24712454
An example of an object type with two separate object items supporting it, and
24722455
a client function using both items via the object type:
24732456

24742457
@example
24752458
2476-
state type taker =
2459+
type taker =
24772460
state obj @{
24782461
fn take(int);
24792462
@};
24802463
2481-
state obj adder(mutable int x) @{
2464+
obj adder(mutable int x) @{
24822465
fn take(int y) @{
24832466
x += y;
24842467
@}

0 commit comments

Comments
 (0)