Skip to content

Commit 5ffaace

Browse files
nikomatsakisgraydon
authored andcommitted
---
yaml --- r: 59293 b: refs/heads/snap-stage3 c: c15fa3a h: refs/heads/master i: 59291: c615ddf v: v3
1 parent b5d1f97 commit 5ffaace

File tree

8 files changed

+61
-95
lines changed

8 files changed

+61
-95
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: c081ffbd1e845687202a975ea2e698b623e5722f
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 32b3d3e9ebd8dbc1073445b3be9676da85b6410c
4+
refs/heads/snap-stage3: c15fa3a02aa3e7e5111f0410abf7321387a7a97f
55
refs/heads/try: c50a9d5b664478e533ba1d1d353213d70c8ad589
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libcore/cleanup.rs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,22 +126,29 @@ struct AnnihilateStats {
126126
n_bytes_freed: uint
127127
}
128128

129-
unsafe fn each_live_alloc(f: &fn(box: *mut BoxRepr, uniq: bool) -> bool) {
129+
unsafe fn each_live_alloc(read_next_before: bool,
130+
f: &fn(box: *mut BoxRepr, uniq: bool) -> bool) {
131+
//! Walks the internal list of allocations
132+
130133
use managed;
131134

132135
let task: *Task = transmute(rustrt::rust_get_task());
133136
let box = (*task).boxed_region.live_allocs;
134137
let mut box: *mut BoxRepr = transmute(copy box);
135138
while box != mut_null() {
136-
let next = transmute(copy (*box).header.next);
139+
let next_before = transmute(copy (*box).header.next);
137140
let uniq =
138141
(*box).header.ref_count == managed::raw::RC_MANAGED_UNIQUE;
139142

140143
if ! f(box, uniq) {
141144
break
142145
}
143146

144-
box = next
147+
if read_next_before {
148+
box = next_before;
149+
} else {
150+
box = transmute(copy (*box).header.next);
151+
}
145152
}
146153
}
147154

@@ -173,7 +180,10 @@ pub unsafe fn annihilate() {
173180
};
174181

175182
// Pass 1: Make all boxes immortal.
176-
for each_live_alloc |box, uniq| {
183+
//
184+
// In this pass, nothing gets freed, so it does not matter whether
185+
// we read the next field before or after the callback.
186+
for each_live_alloc(true) |box, uniq| {
177187
stats.n_total_boxes += 1;
178188
if uniq {
179189
stats.n_unique_boxes += 1;
@@ -183,7 +193,11 @@ pub unsafe fn annihilate() {
183193
}
184194

185195
// Pass 2: Drop all boxes.
186-
for each_live_alloc |box, uniq| {
196+
//
197+
// In this pass, unique-managed boxes may get freed, but not
198+
// managed boxes, so we must read the `next` field *after* the
199+
// callback, as the original value may have been freed.
200+
for each_live_alloc(false) |box, uniq| {
187201
if !uniq {
188202
let tydesc: *TypeDesc = transmute(copy (*box).header.type_desc);
189203
let drop_glue: DropGlue = transmute(((*tydesc).drop_glue, 0));
@@ -192,7 +206,12 @@ pub unsafe fn annihilate() {
192206
}
193207

194208
// Pass 3: Free all boxes.
195-
for each_live_alloc |box, uniq| {
209+
//
210+
// In this pass, managed boxes may get freed (but not
211+
// unique-managed boxes, though I think that none of those are
212+
// left), so we must read the `next` field before, since it will
213+
// not be valid after.
214+
for each_live_alloc(true) |box, uniq| {
196215
if !uniq {
197216
stats.n_bytes_freed +=
198217
(*((*box).header.type_desc)).size

branches/snap-stage3/src/libcore/prelude.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub use io::{print, println};
3131
/* Reexported types and traits */
3232

3333
pub use clone::Clone;
34-
pub use cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering, Less, Equal, Greater, Equiv};
34+
pub use cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering, Less, Equal, Greater};
3535
pub use container::{Container, Mutable, Map, Set};
3636
pub use hash::Hash;
3737
pub use old_iter::{BaseIter, ReverseIter, MutableIter, ExtendedIter, EqIter};

branches/snap-stage3/src/libcore/str/ascii.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
//! Operations on ASCII strings and characters.
12-
1311
use to_str::{ToStr,ToStrConsume};
1412
use str;
1513
use cast;

branches/snap-stage3/src/librustc/middle/typeck/check/_match.rs

Lines changed: 31 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -114,53 +114,37 @@ pub fn check_pat_variant(pcx: &pat_ctxt, pat: @ast::pat, path: @ast::Path,
114114
ty::ty_enum(_, ref expected_substs) => {
115115
// Lookup the enum and variant def ids:
116116
let v_def = lookup_def(pcx.fcx, pat.span, pat.id);
117-
match ast_util::variant_def_ids(v_def) {
118-
Some((enm, var)) => {
119-
// Assign the pattern the type of the *enum*, not the variant.
120-
let enum_tpt = ty::lookup_item_type(tcx, enm);
121-
instantiate_path(pcx.fcx, path, enum_tpt, pat.span, pat.id,
122-
pcx.block_region);
123-
124-
// check that the type of the value being matched is a subtype
125-
// of the type of the pattern:
126-
let pat_ty = fcx.node_ty(pat.id);
127-
demand::subtype(fcx, pat.span, expected, pat_ty);
128-
129-
// Get the expected types of the arguments.
130-
arg_types = {
131-
let vinfo =
132-
ty::enum_variant_with_id(tcx, enm, var);
133-
let var_tpt = ty::lookup_item_type(tcx, var);
134-
vinfo.args.map(|t| {
135-
if var_tpt.generics.type_param_defs.len() ==
136-
expected_substs.tps.len()
137-
{
138-
ty::subst(tcx, expected_substs, *t)
139-
}
140-
else {
141-
*t // In this case, an error was already signaled
142-
// anyway
143-
}
144-
})
145-
};
146-
147-
kind_name = "variant";
148-
}
149-
None => {
150-
let resolved_expected =
151-
fcx.infcx().ty_to_str(fcx.infcx().resolve_type_vars_if_possible(expected));
152-
fcx.infcx().type_error_message_str(pat.span,
153-
|actual| {
154-
fmt!("mismatched types: expected `%s` but found %s",
155-
resolved_expected, actual)},
156-
~"a structure pattern",
157-
None);
158-
fcx.write_error(pat.id);
159-
kind_name = "[error]";
160-
arg_types = (copy subpats).get_or_default(~[]).map(|_|
161-
ty::mk_err());
162-
}
163-
}
117+
let (enm, var) = ast_util::variant_def_ids(v_def);
118+
119+
// Assign the pattern the type of the *enum*, not the variant.
120+
let enum_tpt = ty::lookup_item_type(tcx, enm);
121+
instantiate_path(pcx.fcx, path, enum_tpt, pat.span, pat.id,
122+
pcx.block_region);
123+
124+
// check that the type of the value being matched is a subtype
125+
// of the type of the pattern:
126+
let pat_ty = fcx.node_ty(pat.id);
127+
demand::subtype(fcx, pat.span, expected, pat_ty);
128+
129+
// Get the expected types of the arguments.
130+
arg_types = {
131+
let vinfo =
132+
ty::enum_variant_with_id(tcx, enm, var);
133+
let var_tpt = ty::lookup_item_type(tcx, var);
134+
vinfo.args.map(|t| {
135+
if var_tpt.generics.type_param_defs.len() ==
136+
expected_substs.tps.len()
137+
{
138+
ty::subst(tcx, expected_substs, *t)
139+
}
140+
else {
141+
*t // In this case, an error was already signaled
142+
// anyway
143+
}
144+
})
145+
};
146+
147+
kind_name = "variant";
164148
}
165149
ty::ty_struct(struct_def_id, ref expected_substs) => {
166150
// Lookup the struct ctor def id

branches/snap-stage3/src/libsyntax/ast_util.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ pub fn stmt_id(s: &stmt) -> node_id {
4141
}
4242
}
4343
44-
pub fn variant_def_ids(d: def) -> Option<(def_id, def_id)> {
44+
pub fn variant_def_ids(d: def) -> (def_id, def_id) {
4545
match d {
4646
def_variant(enum_id, var_id) => {
47-
Some((enum_id, var_id))
47+
return (enum_id, var_id);
4848
}
49-
_ => None
49+
_ => fail!(~"non-variant in variant_def_ids")
5050
}
5151
}
5252

branches/snap-stage3/src/test/compile-fail/issue-5358-1.rs

Lines changed: 0 additions & 18 deletions
This file was deleted.

branches/snap-stage3/src/test/compile-fail/issue-5358.rs

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)