Skip to content

Commit 6f47273

Browse files
committed
---
yaml --- r: 95191 b: refs/heads/dist-snap c: 03099e5 h: refs/heads/master i: 95189: e9831b1 95187: c7311b2 95183: 9b82ec3 v: v3
1 parent e287941 commit 6f47273

File tree

5 files changed

+118
-129
lines changed

5 files changed

+118
-129
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: bae0ce2a69e7cef568279e2228cde3b2d225f880
9+
refs/heads/dist-snap: 03099e56789271c35e64c18542db192c086b586e
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/etc/get-snapshot.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ def unpack_snapshot(triple, dl_path):
2626
print("extracting " + p)
2727
tar.extract(p, download_unpack_base)
2828
tp = os.path.join(download_unpack_base, p)
29-
if os.path.isdir(tp) and os.path.exists(fp):
30-
continue
3129
shutil.move(tp, fp)
3230
tar.close()
3331
shutil.rmtree(download_unpack_base)

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

Lines changed: 111 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ pub enum constness {
6060
non_const
6161
}
6262

63-
type constness_cache = HashMap<ast::DefId, constness>;
64-
6563
pub fn join(a: constness, b: constness) -> constness {
6664
match (a, b) {
6765
(integral_const, integral_const) => integral_const,
@@ -76,12 +74,102 @@ pub fn join_all<It: Iterator<constness>>(mut cs: It) -> constness {
7674
cs.fold(integral_const, |a, b| join(a, b))
7775
}
7876

77+
pub fn classify(e: &Expr,
78+
tcx: ty::ctxt)
79+
-> constness {
80+
let did = ast_util::local_def(e.id);
81+
match tcx.ccache.find(&did) {
82+
Some(&x) => x,
83+
None => {
84+
let cn =
85+
match e.node {
86+
ast::ExprLit(lit) => {
87+
match lit.node {
88+
ast::lit_str(*) |
89+
ast::lit_float(*) => general_const,
90+
_ => integral_const
91+
}
92+
}
93+
94+
ast::ExprUnary(_, _, inner) |
95+
ast::ExprParen(inner) => {
96+
classify(inner, tcx)
97+
}
98+
99+
ast::ExprBinary(_, _, a, b) => {
100+
join(classify(a, tcx),
101+
classify(b, tcx))
102+
}
103+
104+
ast::ExprTup(ref es) |
105+
ast::ExprVec(ref es, ast::MutImmutable) => {
106+
join_all(es.iter().map(|e| classify(*e, tcx)))
107+
}
108+
109+
ast::ExprVstore(e, vstore) => {
110+
match vstore {
111+
ast::ExprVstoreSlice => classify(e, tcx),
112+
ast::ExprVstoreUniq |
113+
ast::ExprVstoreBox |
114+
ast::ExprVstoreMutBox |
115+
ast::ExprVstoreMutSlice => non_const
116+
}
117+
}
118+
119+
ast::ExprStruct(_, ref fs, None) => {
120+
let cs = do fs.iter().map |f| {
121+
classify(f.expr, tcx)
122+
};
123+
join_all(cs)
124+
}
125+
126+
ast::ExprCast(base, _) => {
127+
let ty = ty::expr_ty(tcx, e);
128+
let base = classify(base, tcx);
129+
if ty::type_is_integral(ty) {
130+
join(integral_const, base)
131+
} else if ty::type_is_fp(ty) {
132+
join(general_const, base)
133+
} else {
134+
non_const
135+
}
136+
}
137+
138+
ast::ExprField(base, _, _) => {
139+
classify(base, tcx)
140+
}
141+
142+
ast::ExprIndex(_, base, idx) => {
143+
join(classify(base, tcx),
144+
classify(idx, tcx))
145+
}
146+
147+
ast::ExprAddrOf(ast::MutImmutable, base) => {
148+
classify(base, tcx)
149+
}
150+
151+
// FIXME: (#3728) we can probably do something CCI-ish
152+
// surrounding nonlocal constants. But we don't yet.
153+
ast::ExprPath(_) => {
154+
lookup_constness(tcx, e)
155+
}
156+
157+
ast::ExprRepeat(*) => general_const,
158+
159+
_ => non_const
160+
};
161+
tcx.ccache.insert(did, cn);
162+
cn
163+
}
164+
}
165+
}
166+
79167
pub fn lookup_const(tcx: ty::ctxt, e: &Expr) -> Option<@Expr> {
80168
match tcx.def_map.find(&e.id) {
81-
Some(&ast::DefStatic(def_id, false)) =>
82-
lookup_const_by_id(tcx, def_id),
83-
Some(&ast::DefVariant(enum_def, variant_def, _)) =>
84-
lookup_variant_by_id(tcx, enum_def, variant_def),
169+
Some(&ast::DefStatic(def_id, false)) => lookup_const_by_id(tcx, def_id),
170+
Some(&ast::DefVariant(enum_def, variant_def, _)) => lookup_variant_by_id(tcx,
171+
enum_def,
172+
variant_def),
85173
_ => None
86174
}
87175
}
@@ -111,18 +199,14 @@ pub fn lookup_variant_by_id(tcx: ty::ctxt,
111199
Some(_) => None
112200
}
113201
} else {
114-
match tcx.extern_const_variants.find(&variant_def) {
115-
Some(&e) => return e,
116-
None => {}
117-
}
118202
let maps = astencode::Maps {
119203
root_map: @mut HashMap::new(),
120204
method_map: @mut HashMap::new(),
121205
vtable_map: @mut HashMap::new(),
122206
write_guard_map: @mut HashSet::new(),
123207
capture_map: @mut HashMap::new()
124208
};
125-
let e = match csearch::maybe_get_item_ast(tcx, enum_def,
209+
match csearch::maybe_get_item_ast(tcx, enum_def,
126210
|a, b, c, d| astencode::decode_inlined_item(a,
127211
b,
128212
maps,
@@ -135,9 +219,7 @@ pub fn lookup_variant_by_id(tcx: ty::ctxt,
135219
_ => None
136220
},
137221
_ => None
138-
};
139-
tcx.extern_const_variants.insert(variant_def, e);
140-
return e;
222+
}
141223
}
142224
}
143225

@@ -154,136 +236,49 @@ pub fn lookup_const_by_id(tcx: ty::ctxt,
154236
Some(_) => None
155237
}
156238
} else {
157-
match tcx.extern_const_statics.find(&def_id) {
158-
Some(&e) => return e,
159-
None => {}
160-
}
161239
let maps = astencode::Maps {
162240
root_map: @mut HashMap::new(),
163241
method_map: @mut HashMap::new(),
164242
vtable_map: @mut HashMap::new(),
165243
write_guard_map: @mut HashSet::new(),
166244
capture_map: @mut HashMap::new()
167245
};
168-
let e = match csearch::maybe_get_item_ast(tcx, def_id,
246+
match csearch::maybe_get_item_ast(tcx, def_id,
169247
|a, b, c, d| astencode::decode_inlined_item(a, b, maps, c, d)) {
170248
csearch::found(ast::ii_item(item)) => match item.node {
171249
item_static(_, ast::MutImmutable, const_expr) => Some(const_expr),
172250
_ => None
173251
},
174252
_ => None
175-
};
176-
tcx.extern_const_statics.insert(def_id, e);
177-
return e;
178-
}
179-
}
180-
181-
struct ConstEvalVisitor {
182-
tcx: ty::ctxt,
183-
ccache: constness_cache,
184-
}
185-
186-
impl ConstEvalVisitor {
187-
fn classify(&mut self, e: &Expr) -> constness {
188-
let did = ast_util::local_def(e.id);
189-
match self.ccache.find(&did) {
190-
Some(&x) => return x,
191-
None => {}
192253
}
193-
let cn = match e.node {
194-
ast::ExprLit(lit) => {
195-
match lit.node {
196-
ast::lit_str(*) | ast::lit_float(*) => general_const,
197-
_ => integral_const
198-
}
199-
}
200-
201-
ast::ExprUnary(_, _, inner) | ast::ExprParen(inner) =>
202-
self.classify(inner),
203-
204-
ast::ExprBinary(_, _, a, b) =>
205-
join(self.classify(a), self.classify(b)),
206-
207-
ast::ExprTup(ref es) |
208-
ast::ExprVec(ref es, ast::MutImmutable) =>
209-
join_all(es.iter().map(|e| self.classify(*e))),
210-
211-
ast::ExprVstore(e, vstore) => {
212-
match vstore {
213-
ast::ExprVstoreSlice => self.classify(e),
214-
ast::ExprVstoreUniq |
215-
ast::ExprVstoreBox |
216-
ast::ExprVstoreMutBox |
217-
ast::ExprVstoreMutSlice => non_const
218-
}
219-
}
220-
221-
ast::ExprStruct(_, ref fs, None) => {
222-
let cs = do fs.iter().map |f| {
223-
self.classify(f.expr)
224-
};
225-
join_all(cs)
226-
}
227-
228-
ast::ExprCast(base, _) => {
229-
let ty = ty::expr_ty(self.tcx, e);
230-
let base = self.classify(base);
231-
if ty::type_is_integral(ty) {
232-
join(integral_const, base)
233-
} else if ty::type_is_fp(ty) {
234-
join(general_const, base)
235-
} else {
236-
non_const
237-
}
238-
}
239-
240-
ast::ExprField(base, _, _) => self.classify(base),
241-
242-
ast::ExprIndex(_, base, idx) =>
243-
join(self.classify(base), self.classify(idx)),
244-
245-
ast::ExprAddrOf(ast::MutImmutable, base) => self.classify(base),
246-
247-
// FIXME: (#3728) we can probably do something CCI-ish
248-
// surrounding nonlocal constants. But we don't yet.
249-
ast::ExprPath(_) => self.lookup_constness(e),
250-
251-
ast::ExprRepeat(*) => general_const,
252-
253-
_ => non_const
254-
};
255-
self.ccache.insert(did, cn);
256-
cn
257254
}
255+
}
258256

259-
fn lookup_constness(&self, e: &Expr) -> constness {
260-
match lookup_const(self.tcx, e) {
261-
Some(rhs) => {
262-
let ty = ty::expr_ty(self.tcx, rhs);
263-
if ty::type_is_integral(ty) {
264-
integral_const
265-
} else {
266-
general_const
267-
}
257+
pub fn lookup_constness(tcx: ty::ctxt, e: &Expr) -> constness {
258+
match lookup_const(tcx, e) {
259+
Some(rhs) => {
260+
let ty = ty::expr_ty(tcx, rhs);
261+
if ty::type_is_integral(ty) {
262+
integral_const
263+
} else {
264+
general_const
268265
}
269-
None => non_const
270266
}
267+
None => non_const
271268
}
272-
273269
}
274270

271+
struct ConstEvalVisitor { tcx: ty::ctxt }
272+
275273
impl Visitor<()> for ConstEvalVisitor {
276274
fn visit_expr_post(&mut self, e:@Expr, _:()) {
277-
self.classify(e);
275+
classify(e, self.tcx);
278276
}
279277
}
280278

281279
pub fn process_crate(crate: &ast::Crate,
282280
tcx: ty::ctxt) {
283-
let mut v = ConstEvalVisitor {
284-
tcx: tcx,
285-
ccache: HashMap::new(),
286-
};
281+
let mut v = ConstEvalVisitor { tcx: tcx };
287282
visit::walk_crate(&mut v, crate, ());
288283
tcx.sess.abort_if_errors();
289284
}

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ struct ctxt_ {
290290
freevars: freevars::freevar_map,
291291
tcache: type_cache,
292292
rcache: creader_cache,
293+
ccache: constness_cache,
293294
short_names_cache: @mut HashMap<t, @str>,
294295
needs_unwind_cleanup_cache: @mut HashMap<t, bool>,
295296
tc_cache: @mut HashMap<uint, TypeContents>,
@@ -345,11 +346,6 @@ struct ctxt_ {
345346
// The set of external traits whose implementations have been read. This
346347
// is used for lazy resolution of traits.
347348
populated_external_traits: @mut HashSet<ast::DefId>,
348-
349-
// These two caches are used by const_eval when decoding external statics
350-
// and variants that are found.
351-
extern_const_statics: @mut HashMap<ast::DefId, Option<@ast::Expr>>,
352-
extern_const_variants: @mut HashMap<ast::DefId, Option<@ast::Expr>>,
353349
}
354350

355351
pub enum tbox_flag {
@@ -901,6 +897,8 @@ pub struct ty_param_substs_and_ty {
901897

902898
type type_cache = @mut HashMap<ast::DefId, ty_param_bounds_and_ty>;
903899

900+
type constness_cache = @mut HashMap<ast::DefId, const_eval::constness>;
901+
904902
pub type node_type_table = @mut HashMap<uint,t>;
905903

906904
fn mk_rcache() -> creader_cache {
@@ -937,6 +935,7 @@ pub fn mk_ctxt(s: session::Session,
937935
freevars: freevars,
938936
tcache: @mut HashMap::new(),
939937
rcache: mk_rcache(),
938+
ccache: @mut HashMap::new(),
940939
short_names_cache: new_ty_hash(),
941940
needs_unwind_cleanup_cache: new_ty_hash(),
942941
tc_cache: @mut HashMap::new(),
@@ -962,9 +961,6 @@ pub fn mk_ctxt(s: session::Session,
962961
impl_vtables: @mut HashMap::new(),
963962
populated_external_types: @mut HashSet::new(),
964963
populated_external_traits: @mut HashSet::new(),
965-
966-
extern_const_statics: @mut HashMap::new(),
967-
extern_const_variants: @mut HashMap::new(),
968964
}
969965
}
970966

branches/dist-snap/src/libstd/str.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ String manipulation
1616
1717
Rust's string type is one of the core primitive types of the language. While
1818
represented by the name `str`, the name `str` is not actually a valid type in
19-
Rust. Each string must also be decorated with its ownership. This means that
19+
Rust. Each string must also be decorated with how its ownership. This means that
2020
there are three common kinds of strings in rust:
2121
2222
* `~str` - This is an owned string. This type obeys all of the normal semantics
@@ -26,7 +26,7 @@ there are three common kinds of strings in rust:
2626
2727
* `@str` - This is a managed string. Similarly to `@T`, this type can be
2828
implicitly copied, and each implicit copy will increment the
29-
reference count to the string. This means that there is not "true
29+
reference count to the string. This means that there is no "true
3030
owner" of the string, and the string will be deallocated when the
3131
reference count reaches 0.
3232

0 commit comments

Comments
 (0)