Skip to content

Commit 3020dbf

Browse files
committed
---
yaml --- r: 95036 b: refs/heads/dist-snap c: 6c8e6aa h: refs/heads/master v: v3
1 parent e3edb44 commit 3020dbf

File tree

18 files changed

+265
-424
lines changed

18 files changed

+265
-424
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: c274a6888410ce3e357e014568b43310ed787d36
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: 92e7bb67a8038ff73ad9dc88d8be3d3df4777282
9+
refs/heads/dist-snap: 6c8e6aad7344a62d91d5cf10e0dd1769602a5257
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/Makefile.in

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -608,10 +608,6 @@ config.stamp: $(S)configure $(S)Makefile.in $(S)src/snapshots.txt
608608
# Primary-target makefiles
609609
######################################################################
610610

611-
# Issue #9531: If you change the order of any of the following (or add
612-
# new definitions), make sure definitions always precede their uses,
613-
# especially for the dependency lists of recipes.
614-
615611
include $(CFG_SRC_DIR)mk/target.mk
616612
include $(CFG_SRC_DIR)mk/host.mk
617613
include $(CFG_SRC_DIR)mk/stage0.mk

branches/dist-snap/doc/tutorial.md

Lines changed: 71 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ fn area(sh: Shape) -> float {
737737
match sh {
738738
Circle { radius: radius, _ } => float::consts::pi * square(radius),
739739
Rectangle { top_left: top_left, bottom_right: bottom_right } => {
740-
(bottom_right.x - top_left.x) * (top_left.y - bottom_right.y)
740+
(bottom_right.x - top_left.x) * (bottom_right.y - top_left.y)
741741
}
742742
}
743743
}
@@ -923,22 +923,60 @@ custom destructors.
923923

924924
# Boxes
925925

926-
Many modern languages represent values as pointers to heap memory by
927-
default. In contrast, Rust, like C and C++, represents such types directly.
928-
Another way to say this is that aggregate data in Rust are *unboxed*. This
929-
means that if you `let x = Point { x: 1f, y: 1f };`, you are creating a struct
930-
on the stack. If you then copy it into a data structure, you copy the entire
931-
struct, not just a pointer.
926+
A value in Rust is stored directly inside the owner. If a `struct` contains
927+
four `int` fields, it will be four times as large as a single `int`. The
928+
following `struct` type is invalid, as it would have an infinite size:
932929

933-
For small structs like `Point`, this is usually more efficient than allocating
934-
memory and indirecting through a pointer. But for big structs, or mutable
935-
state, it can be useful to have a single copy on the stack or on the heap, and
936-
refer to that through a pointer.
930+
~~~~ {.xfail-test}
931+
struct List {
932+
next: Option<List>,
933+
data: int
934+
}
935+
~~~~
936+
937+
> ***Note:*** The `Option` type is an enum representing an *optional* value.
938+
> It's comparable to a nullable pointer in many other languages, but stores the
939+
> contained value unboxed.
940+
941+
An *owned box* (`~`) uses a heap allocation to provide the invariant of always
942+
being the size of a pointer, regardless of the contained type. This can be
943+
leveraged to create a valid recursive `struct` type with a finite size:
944+
945+
~~~~
946+
struct List {
947+
next: Option<~List>,
948+
data: int
949+
}
950+
~~~~
951+
952+
Since an owned box has a single owner, they are limited to representing
953+
tree-like data structures.
954+
955+
The most common use case for owned boxes is creating recursive data structures
956+
like a binary search tree. Rust's trait-based generics system (covered later in
957+
the tutorial) is usually used for static dispatch, but also provides dynamic
958+
dispatch via boxing. Values of different types may have different sizes, but a
959+
box is able to *erase* the difference via the layer of indirection they
960+
provide.
937961

938-
## Owned boxes
962+
In uncommon cases, the indirection can provide a performance gain or memory
963+
reduction by making values smaller. However, unboxed values should almost
964+
always be preferred.
939965

940-
An owned box (`~`) is a uniquely owned allocation on the heap. It inherits the
941-
mutability and lifetime of the owner as it would if there was no box:
966+
Note that returning large unboxed values via boxes is unnecessary. A large
967+
value is returned via a hidden output parameter, and the decision on where to
968+
place the return value should be left to the caller:
969+
970+
~~~~
971+
fn foo() -> (int, int, int, int, int, int) {
972+
(5, 5, 5, 5, 5, 5)
973+
}
974+
975+
let x = ~foo(); // allocates, and writes the integers directly to it
976+
~~~~
977+
978+
Beyond the properties granted by the size, an owned box behaves as a regular
979+
value by inheriting the mutability and lifetime of the owner:
942980

943981
~~~~
944982
let x = 5; // immutable
@@ -950,35 +988,33 @@ let mut y = ~5; // mutable
950988
*y += 2; // the * operator is needed to access the contained value
951989
~~~~
952990

953-
The purpose of an owned box is to add a layer of indirection in order to create
954-
recursive data structures or cheaply pass around an object larger than a
955-
pointer. Since an owned box has a unique owner, it can only be used to
956-
represent a tree data structure.
991+
As covered earlier, an owned box has a destructor to clean up the allocated
992+
memory. This makes it more restricted than an unboxed type with no destructor
993+
by introducing *move semantics*.
957994

958-
The following struct won't compile, because the lack of indirection would mean
959-
it has an infinite size:
995+
# Move semantics
960996

961-
~~~~ {.xfail-test}
962-
struct Foo {
963-
child: Option<Foo>
964-
}
965-
~~~~
997+
Rust uses a shallow copy for parameter passing, assignment and returning from
998+
functions. This is considered a move of ownership for types with destructors.
999+
After a value has been moved, it can no longer be used from the source location
1000+
and will not be destroyed when the source goes out of scope.
9661001

967-
> ***Note:*** The `Option` type is an enum that represents an *optional* value.
968-
> It's comparable to a nullable pointer in many other languages, but stores the
969-
> contained value unboxed.
1002+
~~~~
1003+
let x = ~5;
1004+
let y = x.clone(); // y is a newly allocated box
1005+
let z = x; // no new memory allocated, x can no longer be used
1006+
~~~~
9701007

971-
Adding indirection with an owned pointer allocates the child outside of the
972-
struct on the heap, which makes it a finite size and won't result in a
973-
compile-time error:
1008+
The mutability of a value may be changed by moving it to a new owner:
9741009

9751010
~~~~
976-
struct Foo {
977-
child: Option<~Foo>
978-
}
1011+
let r = ~13;
1012+
let mut s = r; // box becomes mutable
1013+
*s += 1;
1014+
let t = s; // box becomes immutable
9791015
~~~~
9801016

981-
## Managed boxes
1017+
# Managed boxes
9821018

9831019
A managed box (`@`) is a heap allocation with the lifetime managed by a
9841020
task-local garbage collector. It will be destroyed at some point after there
@@ -1023,30 +1059,6 @@ d = b; // box type is the same, okay
10231059
c = b; // error
10241060
~~~~
10251061

1026-
# Move semantics
1027-
1028-
Rust uses a shallow copy for parameter passing, assignment and returning values
1029-
from functions. A shallow copy is considered a move of ownership if the
1030-
ownership tree of the copied value includes an owned box or a type with a
1031-
custom destructor. After a value has been moved, it can no longer be used from
1032-
the source location and will not be destroyed there.
1033-
1034-
~~~~
1035-
let x = ~5;
1036-
let y = x.clone(); // y is a newly allocated box
1037-
let z = x; // no new memory allocated, x can no longer be used
1038-
~~~~
1039-
1040-
Since in owned boxes mutability is a property of the owner, not the
1041-
box, mutable boxes may become immutable when they are moved, and vice-versa.
1042-
1043-
~~~~
1044-
let r = ~13;
1045-
let mut s = r; // box becomes mutable
1046-
*s += 1;
1047-
let t = s; // box becomes immutable
1048-
~~~~
1049-
10501062
# Borrowed pointers
10511063

10521064
Rust's borrowed pointers are a general purpose reference type. In contrast with

branches/dist-snap/mk/docs.mk

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,10 @@ endif
217217
# Rustdoc (libstd/extra)
218218
######################################################################
219219

220+
ifeq ($(CFG_PANDOC),)
221+
$(info cfg: no pandoc found, omitting library doc build)
222+
else
223+
220224
# The rustdoc executable
221225
RUSTDOC = $(HBIN2_H_$(CFG_BUILD_TRIPLE))/rustdoc$(X_$(CFG_BUILD_TRIPLE))
222226

@@ -234,6 +238,7 @@ endef
234238

235239
$(eval $(call libdoc,std,$(STDLIB_CRATE),$(CFG_BUILD_TRIPLE)))
236240
$(eval $(call libdoc,extra,$(EXTRALIB_CRATE),$(CFG_BUILD_TRIPLE)))
241+
endif
237242

238243

239244
ifdef CFG_DISABLE_DOCS

branches/dist-snap/mk/stage0.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ $(HBIN0_H_$(CFG_BUILD_TRIPLE))/:
66
$(HLIB0_H_$(CFG_BUILD_TRIPLE))/:
77
mkdir -p $@
88

9+
SNAPSHOT_RUSTC_POST_CLEANUP=$(HBIN0_H_$(CFG_BUILD_TRIPLE))/rustc$(X_$(CFG_BUILD_TRIPLE))
10+
911
$(SNAPSHOT_RUSTC_POST_CLEANUP): \
1012
$(S)src/snapshots.txt \
1113
$(S)src/etc/get-snapshot.py $(MKFILE_DEPS) \

branches/dist-snap/mk/target.mk

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ WFLAGS_ST2 = -D warnings
3636
# had its chance to clean it out; otherwise the other products will be
3737
# inadvertantly included in the clean out.
3838

39-
SNAPSHOT_RUSTC_POST_CLEANUP=$(HBIN0_H_$(CFG_BUILD_TRIPLE))/rustc$(X_$(CFG_BUILD_TRIPLE))
40-
4139
define TARGET_STAGE_N
4240

4341
$$(TLIB$(1)_T_$(2)_H_$(3))/libmorestack.a: \

branches/dist-snap/src/librustc/middle/check_match.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -773,12 +773,12 @@ pub fn specialize(cx: &MatchCheckCtxt,
773773
let num_elements = before.len() + after.len();
774774
if num_elements < arity && slice.is_some() {
775775
Some(vec::append(
776-
[
776+
vec::concat(&[
777777
before,
778778
vec::from_elem(
779779
arity - num_elements, wild()),
780780
after
781-
].concat_vec(),
781+
]),
782782
r.tail()
783783
))
784784
} else if num_elements == arity {

branches/dist-snap/src/librustdoc/clean.rs

Lines changed: 48 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl Clean<Crate> for visit_ast::RustdocVisitor {
8484
#[deriving(Clone, Encodable, Decodable)]
8585
pub struct Item {
8686
/// Stringified span
87-
source: Span,
87+
source: ~str,
8888
/// Not everything has a name. E.g., impls
8989
name: Option<~str>,
9090
attrs: ~[Attribute],
@@ -173,11 +173,12 @@ impl Clean<Item> for doctree::Module {
173173
visibility: self.vis.clean(),
174174
id: self.id,
175175
inner: ModuleItem(Module {
176-
items: [self.structs.clean(), self.enums.clean(),
177-
self.fns.clean(), self.foreigns.clean().concat_vec(),
178-
self.mods.clean(), self.typedefs.clean(),
179-
self.statics.clean(), self.traits.clean(),
180-
self.impls.clean(), self.view_items.clean()].concat_vec()
176+
items: std::vec::concat(&[self.structs.clean(),
177+
self.enums.clean(), self.fns.clean(),
178+
std::vec::concat(self.foreigns.clean()),
179+
self.mods.clean(), self.typedefs.clean(),
180+
self.statics.clean(), self.traits.clean(),
181+
self.impls.clean(), self.view_items.clean()])
181182
})
182183
}
183184
}
@@ -539,11 +540,9 @@ impl Clean<TraitMethod> for ast::trait_method {
539540
#[deriving(Clone, Encodable, Decodable)]
540541
pub enum Type {
541542
/// structs/enums/traits (anything that'd be an ast::ty_path)
542-
ResolvedPath {
543-
path: Path,
544-
typarams: Option<~[TyParamBound]>,
545-
did: ast::DefId
546-
},
543+
ResolvedPath { path: Path, typarams: Option<~[TyParamBound]>, id: ast::NodeId },
544+
/// Reference to an item in an external crate (fully qualified path)
545+
External(~str, ~str),
547546
// I have no idea how to usefully use this.
548547
TyParamBinder(ast::NodeId),
549548
/// For parameterized types, so the consumer of the JSON don't go looking
@@ -738,28 +737,10 @@ impl Clean<VariantKind> for ast::variant_kind {
738737
}
739738
}
740739

741-
#[deriving(Clone, Encodable, Decodable)]
742-
pub struct Span {
743-
filename: ~str,
744-
loline: uint,
745-
locol: uint,
746-
hiline: uint,
747-
hicol: uint,
748-
}
749-
750-
impl Clean<Span> for syntax::codemap::Span {
751-
fn clean(&self) -> Span {
752-
let cm = local_data::get(super::ctxtkey, |x| *x.unwrap()).sess.codemap;
753-
let filename = cm.span_to_filename(*self);
754-
let lo = cm.lookup_char_pos(self.lo);
755-
let hi = cm.lookup_char_pos(self.hi);
756-
Span {
757-
filename: filename.to_owned(),
758-
loline: lo.line,
759-
locol: *lo.col,
760-
hiline: hi.line,
761-
hicol: *hi.col,
762-
}
740+
impl Clean<~str> for syntax::codemap::Span {
741+
fn clean(&self) -> ~str {
742+
let cm = local_data::get(super::ctxtkey, |x| x.unwrap().clone()).sess.codemap;
743+
cm.span_to_str(*self)
763744
}
764745
}
765746

@@ -1053,7 +1034,7 @@ trait ToSource {
10531034

10541035
impl ToSource for syntax::codemap::Span {
10551036
fn to_src(&self) -> ~str {
1056-
debug!("converting span %? to snippet", self.clean());
1037+
debug!("converting span %s to snippet", self.clean());
10571038
let cm = local_data::get(super::ctxtkey, |x| x.unwrap().clone()).sess.codemap.clone();
10581039
let sn = match cm.span_to_snippet(*self) {
10591040
Some(x) => x,
@@ -1149,7 +1130,39 @@ fn resolve_type(path: Path, tpbs: Option<~[TyParamBound]>,
11491130
},
11501131
x => fail!("resolved type maps to a weird def %?", x),
11511132
};
1152-
ResolvedPath{ path: path, typarams: tpbs, did: def_id }
1133+
1134+
if def_id.crate != ast::CRATE_NODE_ID {
1135+
use rustc::metadata::decoder::*;
1136+
1137+
let sess = local_data::get(super::ctxtkey, |x| *x.unwrap()).sess;
1138+
let cratedata = ::rustc::metadata::cstore::get_crate_data(sess.cstore, def_id.crate);
1139+
let doc = lookup_item(def_id.node, cratedata.data);
1140+
let path = syntax::ast_map::path_to_str_with_sep(item_path(doc), "::", sess.intr());
1141+
let ty = match def_like_to_def(item_to_def_like(doc, def_id, def_id.crate)) {
1142+
DefFn(*) => ~"fn",
1143+
DefTy(*) => ~"enum",
1144+
DefTrait(*) => ~"trait",
1145+
DefPrimTy(p) => match p {
1146+
ty_str => ~"str",
1147+
ty_bool => ~"bool",
1148+
ty_int(t) => match t.to_str() {
1149+
~"" => ~"i",
1150+
s => s
1151+
},
1152+
ty_uint(t) => t.to_str(),
1153+
ty_float(t) => t.to_str(),
1154+
ty_char => ~"char",
1155+
},
1156+
DefTyParam(*) => ~"generic",
1157+
DefStruct(*) => ~"struct",
1158+
DefTyParamBinder(*) => ~"typaram_binder",
1159+
x => fail!("resolved external maps to a weird def %?", x),
1160+
};
1161+
let cname = cratedata.name.to_owned();
1162+
External(cname + "::" + path, ty)
1163+
} else {
1164+
ResolvedPath {path: path.clone(), typarams: tpbs, id: def_id.node}
1165+
}
11531166
}
11541167

11551168
fn resolve_use_source(path: Path, id: ast::NodeId) -> ImportSource {

0 commit comments

Comments
 (0)