@@ -564,7 +564,7 @@ type_path_tail : '<' type_expr [ ',' type_expr ] + '>'
564
564
565
565
A _ path_ is a sequence of one or more path components _ logically_ separated by
566
566
a namespace qualifier (` :: ` ). If a path consists of only one component, it may
567
- refer to either an [ item] ( #items ) or a [ variable ] ( #variables ) in a local control
567
+ refer to either an [ item] ( #items ) or a [ slot ] ( #memory-slots ) in a local control
568
568
scope. If a path has multiple components, it refers to an item.
569
569
570
570
Every item has a _ canonical path_ within its crate, but the path naming an item
@@ -735,11 +735,13 @@ Rust syntax is restricted in two ways:
735
735
736
736
# Crates and source files
737
737
738
- Rust is a * compiled* language. Its semantics obey a * phase distinction* between
739
- compile-time and run-time. Those semantic rules that have a * static
740
- interpretation* govern the success or failure of compilation. Those semantics
741
- that have a * dynamic interpretation* govern the behavior of the program at
742
- run-time.
738
+ Rust is a * compiled* language. Its semantics obey a * phase distinction*
739
+ between compile-time and run-time. Those semantic rules that have a * static
740
+ interpretation* govern the success or failure of compilation. We refer to
741
+ these rules as "static semantics". Semantic rules called "dynamic semantics"
742
+ govern the behavior of programs at run-time. A program that fails to compile
743
+ due to violation of a compile-time rule has no defined dynamic semantics; the
744
+ compiler should halt with an error report, and produce no executable artifact.
743
745
744
746
The compilation model centers on artifacts called _ crates_ . Each compilation
745
747
processes a single crate in source form, and if successful, produces a single
@@ -1062,9 +1064,9 @@ fn main() {}
1062
1064
A _ function item_ defines a sequence of [ statements] ( #statements ) and an
1063
1065
optional final [ expression] ( #expressions ) , along with a name and a set of
1064
1066
parameters. Functions are declared with the keyword ` fn ` . Functions declare a
1065
- set of * input* [ * variables * ] ( #variables ) as parameters, through which the caller
1066
- passes arguments into the function, and the * output* [ * type * ] ( #types )
1067
- of the value the function will return to its caller on completion .
1067
+ set of * input* [ * slots * ] ( #memory-slots ) as parameters, through which the caller
1068
+ passes arguments into the function, and an * output* [ * slot * ] ( #memory-slots )
1069
+ through which the function passes results back to the caller.
1068
1070
1069
1071
A function may also be copied into a first-class * value* , in which case the
1070
1072
value has the corresponding [ * function type* ] ( #function-types ) , and can be used
@@ -1227,7 +1229,7 @@ be undesired.
1227
1229
#### Diverging functions
1228
1230
1229
1231
A special kind of function can be declared with a ` ! ` character where the
1230
- output type would normally be. For example:
1232
+ output slot type would normally be. For example:
1231
1233
1232
1234
```
1233
1235
fn my_err(s: &str) -> ! {
@@ -1300,11 +1302,18 @@ contiguous stack segments like C.
1300
1302
1301
1303
A _ type alias_ defines a new name for an existing [ type] ( #types ) . Type
1302
1304
aliases are declared with the keyword ` type ` . Every value has a single,
1303
- specific type, but may implement several different traits, or be compatible with
1304
- several different type constraints.
1305
+ specific type; the type-specified aspects of a value include:
1305
1306
1306
- For example, the following defines the type ` Point ` as a synonym for the type
1307
- ` (u8, u8) ` , the type of pairs of unsigned 8 bit integers.:
1307
+ * Whether the value is composed of sub-values or is indivisible.
1308
+ * Whether the value represents textual or numerical information.
1309
+ * Whether the value represents integral or floating-point information.
1310
+ * The sequence of memory operations required to access the value.
1311
+ * The [ kind] ( #type-kinds ) of the type.
1312
+
1313
+ For example, the type ` (u8, u8) ` defines the set of immutable values that are
1314
+ composite pairs, each containing two unsigned 8-bit integers accessed by
1315
+ pattern-matching and laid out in memory with the ` x ` component preceding the
1316
+ ` y ` component:
1308
1317
1309
1318
```
1310
1319
type Point = (u8, u8);
@@ -2542,7 +2551,7 @@ statements](#expression-statements).
2542
2551
### Declaration statements
2543
2552
2544
2553
A _ declaration statement_ is one that introduces one or more * names* into the
2545
- enclosing statement block. The declared names may denote new variables or new
2554
+ enclosing statement block. The declared names may denote new slots or new
2546
2555
items.
2547
2556
2548
2557
#### Item declarations
@@ -2557,18 +2566,18 @@ in meaning to declaring the item outside the statement block.
2557
2566
> ** Note** : there is no implicit capture of the function's dynamic environment when
2558
2567
> declaring a function-local item.
2559
2568
2560
- #### Variable declarations
2569
+ #### Slot declarations
2561
2570
2562
2571
``` {.ebnf .gram}
2563
2572
let_decl : "let" pat [':' type ] ? [ init ] ? ';' ;
2564
2573
init : [ '=' ] expr ;
2565
2574
```
2566
2575
2567
- A _ variable declaration_ introduces a new set of variable , given by a pattern. The
2576
+ A _ slot declaration_ introduces a new set of slots , given by a pattern. The
2568
2577
pattern may be followed by a type annotation, and/or an initializer expression.
2569
2578
When no type annotation is given, the compiler will infer the type, or signal
2570
2579
an error if insufficient type information is available for definite inference.
2571
- Any variables introduced by a variable declaration are visible from the point of
2580
+ Any slots introduced by a slot declaration are visible from the point of
2572
2581
declaration until the end of the enclosing block scope.
2573
2582
2574
2583
### Expression statements
@@ -2623,7 +2632,7 @@ of any reference that points to it.
2623
2632
2624
2633
#### Moved and copied types
2625
2634
2626
- When a [ local variable] ( #variables ) is used as an
2635
+ When a [ local variable] ( #memory-slots ) is used as an
2627
2636
[ rvalue] ( #lvalues,-rvalues-and-temporaries ) the variable will either be moved
2628
2637
or copied, depending on its type. All values whose type implements ` Copy ` are
2629
2638
copied, all others are moved.
@@ -3033,9 +3042,10 @@ paren_expr_list : '(' expr_list ')' ;
3033
3042
call_expr : expr paren_expr_list ;
3034
3043
```
3035
3044
3036
- A _ call expression_ invokes a function, providing zero or more input variables
3037
- and an optional location to move the function's output into. If the function
3038
- eventually returns, then the expression completes.
3045
+ A _ call expression_ invokes a function, providing zero or more input slots and
3046
+ an optional reference slot to serve as the function's output, bound to the
3047
+ ` lval ` on the right hand side of the call. If the function eventually returns,
3048
+ then the expression completes.
3039
3049
3040
3050
Some examples of call expressions:
3041
3051
@@ -3446,9 +3456,9 @@ return_expr : "return" expr ? ;
3446
3456
```
3447
3457
3448
3458
Return expressions are denoted with the keyword ` return ` . Evaluating a ` return `
3449
- expression moves its argument into the designated output location for the
3450
- current function call, destroys the current function activation frame, and
3451
- transfers control to the caller frame.
3459
+ expression moves its argument into the output slot of the current function,
3460
+ destroys the current function activation frame, and transfers control to the
3461
+ caller frame.
3452
3462
3453
3463
An example of a ` return ` expression:
3454
3464
@@ -3465,7 +3475,7 @@ fn max(a: i32, b: i32) -> i32 {
3465
3475
3466
3476
## Types
3467
3477
3468
- Every variable , item and value in a Rust program has a type. The _ type_ of a
3478
+ Every slot , item and value in a Rust program has a type. The _ type_ of a
3469
3479
* value* defines the interpretation of the memory holding it.
3470
3480
3471
3481
Built-in types and type-constructors are tightly integrated into the language,
@@ -3483,7 +3493,7 @@ The primitive types are the following:
3483
3493
* The machine-dependent integer and floating-point types.
3484
3494
3485
3495
[ ^ unittype ] : The "unit" value ` () ` is * not* a sentinel "null pointer" value for
3486
- reference variables ; the "unit" type is the implicit return type from functions
3496
+ reference slots ; the "unit" type is the implicit return type from functions
3487
3497
otherwise lacking a return type, and can be used in other contexts (such as
3488
3498
message-sending or type-parametric code) as a zero-size type.]
3489
3499
@@ -3821,33 +3831,29 @@ impl Printable for String {
3821
3831
` self ` refers to the value of type ` String ` that is the receiver for a call to
3822
3832
the method ` make_string ` .
3823
3833
3824
- # Special traits
3825
-
3826
- Several traits define special evaluation behavior.
3834
+ # The ` Copy ` trait
3827
3835
3828
- ## The ` Copy ` trait
3836
+ Rust has a special trait, ` Copy ` , which when implemented changes the semantics
3837
+ of a value. Values whose type implements ` Copy ` are copied rather than moved
3838
+ upon assignment.
3829
3839
3830
- The ` Copy ` trait changes the semantics of a type implementing it. Values whose
3831
- type implements ` Copy ` are copied rather than moved upon assignment.
3840
+ # The ` Sized ` trait
3832
3841
3833
- ## The ` Sized ` trait
3842
+ ` Sized ` is a special trait which indicates that the size of this type is known
3843
+ at compile-time.
3834
3844
3835
- The ` Sized ` trait indicates that the size of this type is known at compile-time.
3836
-
3837
- ## The ` Drop ` trait
3845
+ # The ` Drop ` trait
3838
3846
3839
3847
The ` Drop ` trait provides a destructor, to be run whenever a value of this type
3840
3848
is to be destroyed.
3841
3849
3842
3850
# Memory model
3843
3851
3844
3852
A Rust program's memory consists of a static set of * items* and a * heap* .
3845
- Immutable portions of the heap may be safely shared between threads, mutable
3846
- portions may not be safely shared, but several mechanisms for effectively-safe
3847
- sharing of mutable values, built on unsafe code but enforcing a safe locking
3848
- discipline, exist in the standard library.
3853
+ Immutable portions of the heap may be shared between threads, mutable portions
3854
+ may not.
3849
3855
3850
- Allocations in the stack consist of * variables * , and allocations in the heap
3856
+ Allocations in the stack consist of * slots * , and allocations in the heap
3851
3857
consist of * boxes* .
3852
3858
3853
3859
### Memory allocation and lifetime
@@ -3866,11 +3872,10 @@ in the heap, heap allocations may outlive the frame they are allocated within.
3866
3872
When a stack frame is exited, its local allocations are all released, and its
3867
3873
references to boxes are dropped.
3868
3874
3869
- ### Variables
3875
+ ### Memory slots
3870
3876
3871
- A _ variable_ is a component of a stack frame, either a named function parameter,
3872
- an anonymous [ temporary] ( #lvalues,-rvalues-and-temporaries ) , or a named local
3873
- variable.
3877
+ A _ slot_ is a component of a stack frame, either a function parameter, a
3878
+ [ temporary] ( #lvalues,-rvalues-and-temporaries ) , or a local variable.
3874
3879
3875
3880
A _ local variable_ (or * stack-local* allocation) holds a value directly,
3876
3881
allocated within the stack's memory. The value is a part of the stack frame.
@@ -3883,7 +3888,7 @@ Box<i32>, y: Box<i32>)` declare one mutable variable `x` and one immutable
3883
3888
variable ` y ` ).
3884
3889
3885
3890
Methods that take either ` self ` or ` Box<Self> ` can optionally place them in a
3886
- mutable variable by prefixing them with ` mut ` (similar to regular arguments):
3891
+ mutable slot by prefixing them with ` mut ` (similar to regular arguments):
3887
3892
3888
3893
```
3889
3894
trait Changer {
@@ -3898,7 +3903,44 @@ state. Subsequent statements within a function may or may not initialize the
3898
3903
local variables. Local variables can be used only after they have been
3899
3904
initialized; this is enforced by the compiler.
3900
3905
3901
- # Linkage
3906
+ # Runtime services, linkage and debugging
3907
+
3908
+ The Rust _ runtime_ is a relatively compact collection of Rust code that
3909
+ provides fundamental services and datatypes to all Rust threads at run-time. It
3910
+ is smaller and simpler than many modern language runtimes. It is tightly
3911
+ integrated into the language's execution model of memory, threads, communication
3912
+ and logging.
3913
+
3914
+ ### Memory allocation
3915
+
3916
+ The runtime memory-management system is based on a _ service-provider
3917
+ interface_ , through which the runtime requests blocks of memory from its
3918
+ environment and releases them back to its environment when they are no longer
3919
+ needed. The default implementation of the service-provider interface consists
3920
+ of the C runtime functions ` malloc ` and ` free ` .
3921
+
3922
+ The runtime memory-management system, in turn, supplies Rust threads with
3923
+ facilities for allocating releasing stacks, as well as allocating and freeing
3924
+ heap data.
3925
+
3926
+ ### Built in types
3927
+
3928
+ The runtime provides C and Rust code to assist with various built-in types,
3929
+ such as arrays, strings, and the low level communication system (ports,
3930
+ channels, threads).
3931
+
3932
+ Support for other built-in types such as simple types, tuples and enums is
3933
+ open-coded by the Rust compiler.
3934
+
3935
+ ### Thread scheduling and communication
3936
+
3937
+ The runtime provides code to manage inter-thread communication. This includes
3938
+ the system of thread-lifecycle state transitions depending on the contents of
3939
+ queues, as well as code to copy values between queues and their recipients and
3940
+ to serialize values for transmission over operating-system inter-process
3941
+ communication facilities.
3942
+
3943
+ ### Linkage
3902
3944
3903
3945
The Rust compiler supports various methods to link crates together both
3904
3946
statically and dynamically. This section will explore the various methods to
0 commit comments