Skip to content

Commit 406271c

Browse files
committed
---
yaml --- r: 4522 b: refs/heads/master c: 8bc4291 h: refs/heads/master v: v3
1 parent 4f2dc8d commit 406271c

File tree

2 files changed

+29
-41
lines changed

2 files changed

+29
-41
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: f5c8c851966e98778a03f5539431832ee8d452b5
2+
refs/heads/master: 8bc42917645669ba0453e23d7c930e3671a5cfad

trunk/doc/rust.texi

Lines changed: 28 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Version: @gitversion
1919

2020
Copyright 2006-2010 Graydon Hoare
2121

22-
Copyright 2009-2010 Mozilla Foundation
22+
Copyright 2009-2011 Mozilla Foundation
2323

2424
See accompanying LICENSE.txt for terms.
2525

@@ -192,12 +192,12 @@ subsumed into the more general facility of disjoint union types. A program
192192
must explicitly model its use of such types.
193193

194194
@sp 1
195-
@item Lightweight tasks with no shared mutable state
195+
@item Lightweight tasks with no shared values
196196

197197
Like many @emph{actor} languages, Rust provides an isolation (and concurrency)
198198
model based on lightweight tasks scheduled by the language runtime. These
199-
tasks are very inexpensive and statically unable to mutate one another's local
200-
memory. Breaking the rule of task isolation is only possible by calling
199+
tasks are very inexpensive and statically unable to manipulate one another's
200+
local memory. Breaking the rule of task isolation is only possible by calling
201201
external (C/C++) code.
202202

203203
Inter-task communication is typed, asynchronous and simplex, based on passing
@@ -247,10 +247,11 @@ roles.
247247
@item Static control over memory allocation, packing and aliasing.
248248

249249
Many values in Rust are allocated @emph{within} their containing stack-frame
250-
or parent structure. Numbers, records, tuples and tags are all allocated this
250+
or parent structure. Numbers, records and tags are all allocated this
251251
way. To allocate such values in the heap, they must be explicitly
252252
@emph{boxed}. A @dfn{box} is a pointer to a heap allocation that holds another
253-
value, its @emph{content}.
253+
value, its @emph{content}. Boxes may be either shared or unique, depending
254+
on which sort of storage management is desired.
254255

255256
Boxing and unboxing in Rust is explicit, though in many cases (arithmetic
256257
operations, name-component dereferencing) Rust will automatically ``reach
@@ -273,42 +274,29 @@ still guaranteeing that every use of a slot occurs after it has been
273274
initialized.
274275

275276
@sp 1
276-
@item Static control over mutability and garbage collection.
277+
@item Immutable data by default
277278

278-
Types in Rust are classified into @emph{layers}. There is a layer of immutable
279-
values, a layer of state values, and a layer of GC values. By default, all
280-
types are immutable.
279+
All types in Rust are immutable by default. A field within a type must be
280+
declared as @code{mutable} in order to be modified.
281281

282-
If a field within a type is declared as @code{mutable}, then the type is part
283-
of the @code{state} layer and must be declared as such. Any type directly
284-
marked as @code{state} @emph{or indirectly referring to} a state type is also
285-
a state type.
286-
287-
If a field within a type is potentially cyclic (this is a narrow, but
288-
well-defined condition involving mutable recursive types) then it is part of
289-
the @code{gc} layer and must be declared as such.
290-
291-
This classification of data types in Rust interacts with the memory allocation,
292-
transmission and destruction rules. In particular:
293-
294-
@itemize
295-
@item Only immutable values can be sent over channels.
296-
@item Only non-GC objects can have destructor functions.
297-
@end itemize
298-
299-
Garbage collection, when present, operates per-task and does not interrupt
300-
other tasks while running. It is limited to types that need it and can be
301-
statically avoided altogether by limiting the types in a program to the state
302-
and immutable layers.
303-
304-
Non-GC values are reference-counted and have a deterministic destruction
305-
order: top-down, immediately upon release of the last live reference.
306-
307-
State values can refer to non-state values, but not vice-versa; likewise GC
308-
values can refer to non-GC values but not vice-versa. Rust therefore
309-
encourages the programmer to write in a style that consists primarily of
310-
immutable types, but also permits limited, local (per-task) mutability,
311-
and provides local (per-task) GC only when required.
282+
@sp 1
283+
@item Move semantics and unique pointers
284+
285+
Rust differentiates copying values from moving them, and permits moving and
286+
swapping values explicitly rather than copying. Moving can be more efficient and,
287+
crucially, represents an indivisible transfer of ownership of a value from its
288+
source to its destination.
289+
290+
In addition, pointer types in Rust come in several varieties. One important
291+
type of pointer related to move semantics is the @emph{unique} pointer,
292+
denoted @code{~}, which is statically guaranteed to be the only pointer
293+
pointing to its referent at any given time.
294+
295+
Combining move-semantics and unique pointers, Rust permits a very lightweight
296+
form of inter-task communication: values are sent between tasks by moving, and
297+
only types composed of unique pointers can be sent. This statically ensures
298+
there can never be sharing of data between tasks, while keeping the costs of
299+
transferring data between tasks as cheap as moving a pointer.
312300

313301
@sp 1
314302
@item Stack-based iterators

0 commit comments

Comments
 (0)