Skip to content

Commit 620c751

Browse files
committed
---
yaml --- r: 138539 b: refs/heads/try2 c: 0ded562 h: refs/heads/master i: 138537: b6f361c 138535: 2a96224 v: v3
1 parent 29f4907 commit 620c751

File tree

592 files changed

+8986
-7539
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

592 files changed

+8986
-7539
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: c77c5c4674c92b342132a56bd1b59f86af3d5a63
8+
refs/heads/try2: 0ded562e8364244c9c0da1d5f4dc97cd900b4fe4
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/AUTHORS.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ Josh Matthews <[email protected]>
9393
Joshua Clark <[email protected]>
9494
Joshua Wise <[email protected]>
9595
Jyun-Yan You <[email protected]>
96+
Kang Seonghoon <[email protected]>
9697
Kelly Wilson <[email protected]>
9798
Kevin Atkinson <[email protected]>
9899
Kevin Cantu <[email protected]>

branches/try2/Makefile.in

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ CFG_LIBFUZZER :=$(call CFG_LIB_NAME,fuzzer)
134134
CFG_LIBRUSTPKG :=$(call CFG_LIB_NAME,rustpkg)
135135
CFG_LIBRUSTDOC :=$(call CFG_LIB_NAME,rustdoc)
136136
CFG_LIBRUSTI :=$(call CFG_LIB_NAME,rusti)
137+
CFG_LIBRUST :=$(call CFG_LIB_NAME,rust)
137138

138139
STDLIB_GLOB :=$(call CFG_LIB_GLOB,std)
139140
CORELIB_GLOB :=$(call CFG_LIB_GLOB,core)
@@ -143,6 +144,7 @@ LIBFUZZER_GLOB :=$(call CFG_LIB_GLOB,fuzzer)
143144
LIBRUSTPKG_GLOB :=$(call CFG_LIB_GLOB,rustpkg)
144145
LIBRUSTDOC_GLOB :=$(call CFG_LIB_GLOB,rustdoc)
145146
LIBRUSTI_GLOB :=$(call CFG_LIB_GLOB,rusti)
147+
LIBRUST_GLOB :=$(call CFG_LIB_GLOB,rust)
146148
STDLIB_DSYM_GLOB :=$(call CFG_LIB_DSYM_GLOB,std)
147149
CORELIB_DSYM_GLOB :=$(call CFG_LIB_DSYM_GLOB,core)
148150
LIBRUSTC_DSYM_GLOB :=$(call CFG_LIB_DSYM_GLOB,rustc)
@@ -151,6 +153,7 @@ LIBFUZZER_DSYM_GLOB :=$(call CFG_LIB_DSYM_GLOB,fuzzer)
151153
LIBRUSTPKG_DSYM_GLOB :=$(call CFG_LIB_DSYM_GLOB,rustpkg)
152154
LIBRUSTDOC_DSYM_GLOB :=$(call CFG_LIB_DSYM_GLOB,rustdoc)
153155
LIBRUSTI_DSYM_GLOB :=$(call CFG_LIB_DSYM_GLOB,rusti)
156+
LIBRUST_DSYM_GLOB :=$(call CFG_LIB_DSYM_GLOB,rust)
154157

155158
# version-string calculation
156159
CFG_GIT_DIR := $(CFG_SRC_DIR).git
@@ -374,18 +377,21 @@ CSREQ$(1)_T_$(2)_H_$(3) = \
374377
$$(HBIN$(1)_H_$(3))/rustpkg$$(X) \
375378
$$(HBIN$(1)_H_$(3))/rustdoc$$(X) \
376379
$$(HBIN$(1)_H_$(3))/rusti$$(X) \
380+
$$(HBIN$(1)_H_$(3))/rust$$(X) \
377381
$$(HLIB$(1)_H_$(3))/$$(CFG_LIBFUZZER) \
378382
$$(HLIB$(1)_H_$(3))/$$(CFG_LIBRUSTPKG) \
379383
$$(HLIB$(1)_H_$(3))/$$(CFG_LIBRUSTDOC) \
380384
$$(HLIB$(1)_H_$(3))/$$(CFG_LIBRUSTI) \
385+
$$(HLIB$(1)_H_$(3))/$$(CFG_LIBRUST) \
381386
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_CORELIB) \
382387
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_STDLIB) \
383388
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBSYNTAX) \
384389
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTC) \
385390
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBFUZZER) \
386391
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTPKG) \
387392
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTDOC) \
388-
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTI)
393+
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTI) \
394+
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUST)
389395

390396
ifeq ($(1),0)
391397
# Don't run the the stage0 compiler under valgrind - that ship has sailed

branches/try2/doc/rust.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ This requirement most often affects name-designator pairs when they occur at the
549549

550550
* `log_syntax!` : print out the arguments at compile time
551551
* `trace_macros!` : supply `true` or `false` to enable or disable printing of the macro expansion process.
552-
* `ident_to_str!` : turn the identifier argument into a string literal
552+
* `stringify!` : turn the identifier argument into a string literal
553553
* `concat_idents!` : create a new identifier by concatenating the arguments
554554

555555

@@ -1117,6 +1117,7 @@ a = Cat{ name: ~"Spotty", weight: 2.7 };
11171117

11181118
In this example, `Cat` is a _struct-like enum variant_,
11191119
whereas `Dog` is simply called an enum variant.
1120+
11201121
### Constants
11211122

11221123
~~~~~~~~ {.ebnf .gram}
@@ -1609,11 +1610,11 @@ The following are examples of structure expressions:
16091610
~~~~
16101611
# struct Point { x: float, y: float }
16111612
# struct TuplePoint(float, float);
1612-
# mod game { pub struct User { name: &str, age: uint, mut score: uint } }
1613+
# mod game { pub struct User { name: &str, age: uint, score: uint } }
16131614
# use game;
16141615
Point {x: 10f, y: 20f};
16151616
TuplePoint(10f, 20f);
1616-
let u = game::User {name: "Joe", age: 35u, mut score: 100_000};
1617+
let u = game::User {name: "Joe", age: 35u, score: 100_000};
16171618
~~~~
16181619

16191620
A structure expression forms a new value of the named structure type.

branches/try2/doc/tutorial-borrowed-ptr.md

Lines changed: 4 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -348,12 +348,12 @@ mutations:
348348
~~~ {.xfail-test}
349349
fn example3() -> int {
350350
struct R { g: int }
351-
struct S { mut f: ~R }
351+
struct S { f: ~R }
352352
353-
let mut x = ~S {mut f: ~R {g: 3}};
353+
let mut x = ~S {f: ~R {g: 3}};
354354
let y = &x.f.g;
355-
x = ~S {mut f: ~R {g: 4}}; // Error reported here.
356-
x.f = ~R {g: 5}; // Error reported here.
355+
x = ~S {f: ~R {g: 4}}; // Error reported here.
356+
x.f = ~R {g: 5}; // Error reported here.
357357
*y
358358
}
359359
~~~
@@ -362,91 +362,6 @@ In this case, two errors are reported, one when the variable `x` is
362362
modified and another when `x.f` is modified. Either modification would
363363
invalidate the pointer `y`.
364364

365-
Things get trickier when the unique box is not uniquely owned by the
366-
stack frame, or when there is no way for the compiler to determine the
367-
box's owner. Consider a program like this:
368-
369-
~~~ {.xfail-test}
370-
struct R { g: int }
371-
struct S { mut f: ~R }
372-
fn example5a(x: @S, callback: @fn()) -> int {
373-
let y = &x.f.g; // Error reported here.
374-
...
375-
callback();
376-
...
377-
# return 0;
378-
}
379-
~~~
380-
381-
Here the heap looks something like:
382-
383-
~~~ {.notrust}
384-
Stack Managed Heap Exchange Heap
385-
386-
x +------+ +-------------+ +------+
387-
| @... | ----> | mut f: ~... | --+-> | g: 3 |
388-
y +------+ +-------------+ | +------+
389-
| &int | -------------------------+
390-
+------+
391-
~~~
392-
393-
In this case, the owning reference to the value being borrowed is
394-
`x.f`. Moreover, `x.f` is both mutable and *aliasable*. Aliasable
395-
means that there may be other pointers to that same managed box, so
396-
even if the compiler were to prove an absence of mutations to `x.f`,
397-
code could mutate `x.f` indirectly by changing an alias of
398-
`x`. Therefore, to be safe, the compiler only accepts *pure* actions
399-
during the lifetime of `y`. We define what "pure" means in the section
400-
on [purity](#purity).
401-
402-
Besides ensuring purity, the only way to borrow the interior of a
403-
unique found in aliasable memory is to ensure that the borrowed field
404-
itself is also unique, as in the following example:
405-
406-
~~~
407-
struct R { g: int }
408-
struct S { f: ~R }
409-
fn example5b(x: @S) -> int {
410-
let y = &x.f.g;
411-
...
412-
# return 0;
413-
}
414-
~~~
415-
416-
Here, the field `f` is not declared as mutable. But that is enough for
417-
the compiler to know that, even if aliases to `x` exist, the field `f`
418-
cannot be changed and hence the unique box `g` will remain valid.
419-
420-
If you do have a unique box in a mutable field, and you wish to borrow
421-
it, one option is to use the swap operator to move that unique box
422-
onto your stack:
423-
424-
~~~
425-
struct R { g: int }
426-
struct S { mut f: ~R }
427-
fn example5c(x: @S) -> int {
428-
let mut v = ~R {g: 0};
429-
v <-> x.f; // Swap v and x.f
430-
{ // Block constrains the scope of `y`:
431-
let y = &v.g;
432-
...
433-
}
434-
x.f = v; // Replace x.f
435-
...
436-
# return 0;
437-
}
438-
~~~
439-
440-
Of course, this has the side effect of modifying your managed box for
441-
the duration of the borrow, so it only works when you know that you
442-
won't be accessing that same box for the duration of the loan. Also,
443-
it is sometimes necessary to introduce additional blocks to constrain
444-
the scope of the loan. In this example, the borrowed pointer `y`
445-
would still be in scope when you moved the value `v` back into `x.f`,
446-
and hence moving `v` would be considered illegal. You cannot move
447-
values if they are the targets of valid outstanding loans. Introducing
448-
the block restricts the scope of `y`, making the move legal.
449-
450365
# Borrowing and enums
451366

452367
The previous example showed that the type system forbids any borrowing
@@ -558,11 +473,6 @@ permit `ref` bindings into data owned by the stack frame even if the
558473
data are mutable, but otherwise it requires that the data reside in
559474
immutable memory.
560475

561-
> ***Note:*** Right now, pattern bindings not explicitly annotated
562-
> with `ref` or `copy` use a special mode of "implicit by reference".
563-
> This is changing as soon as we finish updating all the existing code
564-
> in the compiler that relies on the current settings.
565-
566476
# Returning borrowed pointers
567477

568478
So far, all of the examples we've looked at use borrowed pointers in a
@@ -745,69 +655,6 @@ fn select<T>(shape: &Shape, threshold: float,
745655

746656
This is equivalent to the previous definition.
747657

748-
# Purity
749-
750-
As mentioned before, the Rust compiler offers a kind of escape hatch
751-
that permits borrowing of any data, as long as the actions that occur
752-
during the lifetime of the borrow are pure. Pure actions are those
753-
that only modify data owned by the current stack frame. The compiler
754-
can therefore permit arbitrary pointers into the heap, secure in the
755-
knowledge that no pure action will ever cause them to become
756-
invalidated (the compiler must still track data on the stack which is
757-
borrowed and enforce those rules normally, of course). A pure function
758-
in Rust is referentially transparent: it returns the same results
759-
given the same (observably equivalent) inputs. That is because while
760-
pure functions are allowed to modify data, they may only modify
761-
*stack-local* data, which cannot be observed outside the scope of the
762-
function itself. (Using an `unsafe` block invalidates this guarantee.)
763-
764-
Let’s revisit a previous example and show how purity can affect
765-
typechecking. Here is `example5a()`, which borrows the interior of a
766-
unique box found in an aliasable, mutable location, only now we’ve
767-
replaced the `...` with some specific code:
768-
769-
~~~
770-
struct R { g: int }
771-
struct S { mut f: ~R }
772-
fn example5a(x: @S ...) -> int {
773-
let y = &x.f.g; // Unsafe
774-
*y + 1
775-
}
776-
~~~
777-
778-
The new code simply returns an incremented version of `y`. This code
779-
clearly doesn't mutate the heap, so the compiler is satisfied.
780-
781-
But suppose we wanted to pull the increment code into a helper, like
782-
this:
783-
784-
~~~
785-
fn add_one(x: &int) -> int { *x + 1 }
786-
~~~
787-
788-
We can now update `example5a()` to use `add_one()`:
789-
790-
~~~
791-
# struct R { g: int }
792-
# struct S { mut f: ~R }
793-
# pure fn add_one(x: &int) -> int { *x + 1 }
794-
fn example5a(x: @S ...) -> int {
795-
let y = &x.f.g;
796-
add_one(y) // Error reported here
797-
}
798-
~~~
799-
800-
But now the compiler will report an error again. The reason is that it
801-
only considers one function at a time (like most typecheckers), and
802-
so it does not know that `add_one()` consists of pure code. We can
803-
help the compiler by labeling `add_one()` as pure:
804-
805-
~~~
806-
pure fn add_one(x: &int) -> int { *x + 1 }
807-
~~~
808-
809-
With this change, the modified version of `example5a()` will again compile.
810-
811658
# Conclusion
812659

813660
So there you have it: a (relatively) brief tour of the borrowed pointer

branches/try2/doc/tutorial-ffi.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -220,21 +220,21 @@ extern mod std;
220220
use libc::c_ulonglong;
221221
222222
struct timeval {
223-
mut tv_sec: c_ulonglong,
224-
mut tv_usec: c_ulonglong
223+
tv_sec: c_ulonglong,
224+
tv_usec: c_ulonglong
225225
}
226226
227227
#[nolink]
228228
extern mod lib_c {
229-
fn gettimeofday(tv: *timeval, tz: *()) -> i32;
229+
fn gettimeofday(tv: *mut timeval, tz: *()) -> i32;
230230
}
231231
fn unix_time_in_microseconds() -> u64 {
232232
unsafe {
233-
let x = timeval {
234-
mut tv_sec: 0 as c_ulonglong,
235-
mut tv_usec: 0 as c_ulonglong
233+
let mut x = timeval {
234+
tv_sec: 0 as c_ulonglong,
235+
tv_usec: 0 as c_ulonglong
236236
};
237-
lib_c::gettimeofday(ptr::addr_of(&x), ptr::null());
237+
lib_c::gettimeofday(&mut x, ptr::null());
238238
return (x.tv_sec as u64) * 1000_000_u64 + (x.tv_usec as u64);
239239
}
240240
}

0 commit comments

Comments
 (0)