Skip to content

Commit 055158d

Browse files
committed
Revert "Merge pull request #2516 from mozilla/incoming" due to failures
This reverts commit adb717b, reversing changes made to aabf84c.
1 parent adb717b commit 055158d

File tree

18 files changed

+116
-98
lines changed

18 files changed

+116
-98
lines changed

src/libcore/cmp.rs

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

src/libcore/core.rc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ export extfmt;
4444
export tuple;
4545
export to_str;
4646
export dvec, dvec_iter;
47-
export cmp;
4847

4948
// NDM seems to be necessary for resolve to work
5049
export option_iter;
@@ -153,7 +152,6 @@ mod tuple;
153152

154153
// Ubiquitous-utility-type modules
155154

156-
mod cmp;
157155
mod either;
158156
mod iter;
159157
mod logging;

src/libcore/int-template.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import T = inst::T;
2-
import cmp::{eq, ord};
32

43
export min_value, max_value;
54
export min, max;
@@ -11,7 +10,6 @@ export range;
1110
export compl;
1211
export abs;
1312
export parse_buf, from_str, to_str, to_str_bytes, str;
14-
export ord, eq;
1513

1614
const min_value: T = -1 as T << (inst::bits - 1 as T);
1715
const max_value: T = min_value - 1 as T;
@@ -110,18 +108,6 @@ fn to_str_bytes<U>(n: T, radix: uint, f: fn([u8]/&) -> U) -> U {
110108
#[doc = "Convert to a string"]
111109
fn str(i: T) -> str { ret to_str(i, 10u); }
112110

113-
impl ord of ord for T {
114-
fn lt(&&other: T) -> bool {
115-
ret self < other;
116-
}
117-
}
118-
119-
impl eq of eq for T {
120-
fn eq(&&other: T) -> bool {
121-
ret self == other;
122-
}
123-
}
124-
125111

126112
// FIXME: Has alignment issues on windows and 32-bit linux
127113
#[test]

src/libcore/uint-template.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import T = inst::T;
2-
import cmp::{eq, ord};
32

43
export min_value, max_value;
54
export min, max;
@@ -11,7 +10,6 @@ export range;
1110
export compl;
1211
export to_str, to_str_bytes;
1312
export from_str, from_str_radix, str, parse_buf;
14-
export ord, eq;
1513

1614
const min_value: T = 0 as T;
1715
const max_value: T = 0 as T - 1 as T;
@@ -51,18 +49,6 @@ pure fn compl(i: T) -> T {
5149
max_value ^ i
5250
}
5351

54-
impl ord of ord for T {
55-
fn lt(&&other: T) -> bool {
56-
ret self < other;
57-
}
58-
}
59-
60-
impl eq of eq for T {
61-
fn eq(&&other: T) -> bool {
62-
ret self == other;
63-
}
64-
}
65-
6652
#[doc = "
6753
Parse a buffer of bytes
6854

src/libstd/sort.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#[doc = "Sorting methods"];
22
import vec::len;
3-
import int::{eq, ord};
43

54
export le;
65
export merge_sort;
@@ -142,6 +141,7 @@ fn qsort3<T: copy>(compare_func_lt: le<T>, compare_func_eq: le<T>,
142141
qsort3::<T>(compare_func_lt, compare_func_eq, arr, i, right);
143142
}
144143

144+
// FIXME: This should take lt and eq types (#2348)
145145
#[doc = "
146146
Fancy quicksort. Sorts a mut vector in place.
147147
@@ -152,17 +152,22 @@ According to these slides this is the algorithm of choice for
152152
153153
This is an unstable sort.
154154
"]
155-
fn quick_sort3<T: copy ord eq>(arr: [mut T]) {
155+
fn quick_sort3<T: copy>(compare_func_lt: le<T>, compare_func_eq: le<T>,
156+
arr: [mut T]) {
156157
if len::<T>(arr) == 0u { ret; }
157-
qsort3::<T>({ |x, y| x.lt(y) }, { |x, y| x.eq(y) }, arr, 0,
158+
qsort3::<T>(compare_func_lt, compare_func_eq, arr, 0,
158159
(len::<T>(arr) as int) - 1);
159160
}
160161

161162
#[cfg(test)]
162163
mod test_qsort3 {
163164
fn check_sort(v1: [mut int], v2: [mut int]) {
164165
let len = vec::len::<int>(v1);
165-
quick_sort3::<int>(v1);
166+
fn lt(&&a: int, &&b: int) -> bool { ret a < b; }
167+
fn equal(&&a: int, &&b: int) -> bool { ret a == b; }
168+
let f1 = lt;
169+
let f2 = equal;
170+
quick_sort3::<int>(f1, f2, v1);
166171
let mut i = 0u;
167172
while i < len {
168173
log(debug, v2[i]);

src/rustc/driver/driver.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ fn compile_upto(sess: session, cfg: ast::crate_cfg,
194194
bind middle::check_loop::check_crate(ty_cx, crate));
195195
time(time_passes, "alt checking",
196196
bind middle::check_alt::check_crate(ty_cx, crate));
197-
let last_use_map =
197+
let (last_use_map, spill_map) =
198198
time(time_passes, "liveness checking",
199199
bind middle::liveness::check_crate(ty_cx, method_map, crate));
200200
time(time_passes, "typestate checking",
@@ -216,7 +216,7 @@ fn compile_upto(sess: session, cfg: ast::crate_cfg,
216216
let maps = {mutbl_map: mutbl_map, root_map: root_map,
217217
copy_map: copy_map, last_use_map: last_use_map,
218218
impl_map: impl_map, method_map: method_map,
219-
vtable_map: vtable_map};
219+
vtable_map: vtable_map, spill_map: spill_map};
220220

221221
let (llmod, link_meta) =
222222
time(time_passes, "translation",

src/rustc/driver/rustc.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ import std::map::hashmap;
1515
import getopts::{opt_present};
1616
import rustc::driver::driver::*;
1717
import syntax::codemap;
18-
import syntax::diagnostic;
19-
import rustc::driver::session;
18+
import rustc::driver::{diagnostic, session};
2019
import rustc::middle::lint;
2120
import io::reader_util;
2221

src/rustc/metadata/decoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import syntax::{ast, ast_util};
77
import syntax::attr;
88
import middle::ty;
99
import syntax::ast_map;
10+
import common::*;
1011
import tydecode::{parse_ty_data, parse_def_id, parse_bounds_data,
1112
parse_ident};
1213
import syntax::print::pprust;
1314
import cmd=cstore::crate_metadata;
1415
import util::ppaux::ty_to_str;
1516
import ebml::deserializer;
1617
import syntax::diagnostic::span_handler;
17-
import common::*;
1818

1919
export class_dtor;
2020
export get_class_fields;

src/rustc/middle/astencode.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ type maps = {
5757
impl_map: middle::resolve::impl_map,
5858
method_map: middle::typeck::method_map,
5959
vtable_map: middle::typeck::vtable_map,
60+
spill_map: middle::liveness::spill_map
6061
};
6162

6263
type decode_ctxt = @{
@@ -838,6 +839,12 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt,
838839
}
839840
}
840841

842+
option::iter(maps.spill_map.find(id)) {|_m|
843+
ebml_w.tag(c::tag_table_spill) {||
844+
ebml_w.id(id);
845+
}
846+
}
847+
841848
option::iter(maps.last_use_map.find(id)) {|m|
842849
ebml_w.tag(c::tag_table_last_use) {||
843850
ebml_w.id(id);
@@ -946,6 +953,8 @@ fn decode_side_tables(xcx: extended_decode_ctxt,
946953
dcx.maps.mutbl_map.insert(id, ());
947954
} else if tag == (c::tag_table_copy as uint) {
948955
dcx.maps.copy_map.insert(id, ());
956+
} else if tag == (c::tag_table_spill as uint) {
957+
dcx.maps.spill_map.insert(id, ());
949958
} else {
950959
let val_doc = entry_doc[c::tag_table_val];
951960
let val_dsr = ebml::ebml_deserializer(val_doc);

src/rustc/middle/liveness.rs

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import capture::{cap_move, cap_drop, cap_copy, cap_ref};
5757

5858
export check_crate;
5959
export last_use_map;
60+
export spill_map;
6061

6162
// Maps from an expr id to a list of variable ids for which this expr
6263
// is the last use. Typically, the expr is a path and the node id is
@@ -65,6 +66,13 @@ export last_use_map;
6566
// list of closed over variables that can be moved into the closure.
6667
type last_use_map = hashmap<node_id, @dvec<node_id>>;
6768

69+
// A set of variable ids which must be spilled (stored on the stack).
70+
// We add in any variables or arguments where:
71+
// (1) the variables are moved;
72+
// (2) the address of the variable/argument is taken;
73+
// or (3) we find a last use (as they may be moved).
74+
type spill_map = hashmap<node_id, ()>;
75+
6876
enum variable = uint;
6977
enum live_node = uint;
7078

@@ -77,7 +85,7 @@ enum live_node_kind {
7785

7886
fn check_crate(tcx: ty::ctxt,
7987
method_map: typeck::method_map,
80-
crate: @crate) -> last_use_map {
88+
crate: @crate) -> (last_use_map, spill_map) {
8189
let visitor = visit::mk_vt(@{
8290
visit_fn: visit_fn,
8391
visit_local: visit_local,
@@ -86,11 +94,12 @@ fn check_crate(tcx: ty::ctxt,
8694
});
8795

8896
let last_use_map = int_hash();
97+
let spill_map = int_hash();
8998
let initial_maps = @ir_maps(tcx, method_map,
90-
last_use_map);
99+
last_use_map, spill_map);
91100
visit::visit_crate(*crate, initial_maps, visitor);
92101
tcx.sess.abort_if_errors();
93-
ret last_use_map;
102+
ret (last_use_map, spill_map);
94103
}
95104

96105
impl of to_str::to_str for live_node {
@@ -153,6 +162,7 @@ class ir_maps {
153162
let tcx: ty::ctxt;
154163
let method_map: typeck::method_map;
155164
let last_use_map: last_use_map;
165+
let spill_map: spill_map;
156166

157167
let mut num_live_nodes: uint;
158168
let mut num_vars: uint;
@@ -164,10 +174,11 @@ class ir_maps {
164174
let mut lnks: [live_node_kind];
165175

166176
new(tcx: ty::ctxt, method_map: typeck::method_map,
167-
last_use_map: last_use_map) {
177+
last_use_map: last_use_map, spill_map: spill_map) {
168178
self.tcx = tcx;
169179
self.method_map = method_map;
170180
self.last_use_map = last_use_map;
181+
self.spill_map = spill_map;
171182

172183
self.num_live_nodes = 0u;
173184
self.num_vars = 0u;
@@ -253,6 +264,17 @@ class ir_maps {
253264
self.lnks[*ln]
254265
}
255266

267+
fn add_spill(var: variable) {
268+
let vk = self.var_kinds[*var];
269+
alt vk {
270+
vk_local(id, _) | vk_arg(id, _, by_val) {
271+
#debug["adding spill for %?", vk];
272+
self.spill_map.insert(id, ());
273+
}
274+
vk_arg(*) | vk_field(_) | vk_self | vk_implicit_ret {}
275+
}
276+
}
277+
256278
fn add_last_use(expr_id: node_id, var: variable) {
257279
let vk = self.var_kinds[*var];
258280
#debug["Node %d is a last use of variable %?", expr_id, vk];
@@ -286,7 +308,7 @@ fn visit_fn(fk: visit::fn_kind, decl: fn_decl, body: blk,
286308

287309
// swap in a new set of IR maps for this function body:
288310
let fn_maps = @ir_maps(self.tcx, self.method_map,
289-
self.last_use_map);
311+
self.last_use_map, self.spill_map);
290312

291313
#debug["creating fn_maps: %x", ptr::addr_of(*fn_maps) as uint];
292314

@@ -1385,7 +1407,11 @@ fn check_expr(expr: @expr, &&self: @liveness, vt: vt<@liveness>) {
13851407
vt.visit_expr(f, self, vt);
13861408
vec::iter2(args, targs) { |arg_expr, arg_ty|
13871409
alt ty::resolved_mode(self.tcx, arg_ty.mode) {
1388-
by_val | by_copy | by_ref | by_mutbl_ref{
1410+
by_val | by_copy {
1411+
vt.visit_expr(arg_expr, self, vt);
1412+
}
1413+
by_ref | by_mutbl_ref {
1414+
self.spill_expr(arg_expr);
13891415
vt.visit_expr(arg_expr, self, vt);
13901416
}
13911417
by_move {
@@ -1395,6 +1421,10 @@ fn check_expr(expr: @expr, &&self: @liveness, vt: vt<@liveness>) {
13951421
}
13961422
}
13971423

1424+
expr_addr_of(_, arg_expr) {
1425+
self.spill_expr(arg_expr);
1426+
}
1427+
13981428
// no correctness conditions related to liveness
13991429
expr_if_check(*) | expr_if(*) | expr_alt(*) |
14001430
expr_while(*) | expr_loop(*) |
@@ -1404,7 +1434,7 @@ fn check_expr(expr: @expr, &&self: @liveness, vt: vt<@liveness>) {
14041434
expr_assert(*) | expr_check(*) | expr_copy(*) |
14051435
expr_loop_body(*) | expr_cast(*) | expr_unary(*) | expr_fail(*) |
14061436
expr_ret(*) | expr_break | expr_cont | expr_lit(_) |
1407-
expr_block(*) | expr_swap(*) | expr_mac(*) | expr_addr_of(*) {
1437+
expr_block(*) | expr_swap(*) | expr_mac(*) {
14081438
visit::visit_expr(expr, self, vt);
14091439
}
14101440
}
@@ -1471,7 +1501,10 @@ impl check_methods for @liveness {
14711501
ln.to_str(), var.to_str()];
14721502

14731503
alt (*self).live_on_exit(ln, var) {
1474-
none { }
1504+
none {
1505+
// update spill map to include this variable, as it is moved:
1506+
(*self.ir).add_spill(var);
1507+
}
14751508
some(lnk) {
14761509
self.report_illegal_move(span, lnk, var);
14771510
}
@@ -1483,10 +1516,20 @@ impl check_methods for @liveness {
14831516
some(_) {}
14841517
none {
14851518
(*self.ir).add_last_use(expr.id, var);
1519+
1520+
// update spill map to include this variable, as it may be moved:
1521+
(*self.ir).add_spill(var);
14861522
}
14871523
}
14881524
}
14891525

1526+
fn spill_expr(expr: @expr) {
1527+
alt (*self).variable_from_path(expr) {
1528+
some(var) {(*self.ir).add_spill(var)}
1529+
none {}
1530+
}
1531+
}
1532+
14901533
fn check_move_from_expr(expr: @expr, vt: vt<@liveness>) {
14911534
#debug["check_move_from_expr(node %d: %s)",
14921535
expr.id, expr_to_str(expr)];
@@ -1732,4 +1775,4 @@ impl check_methods for @liveness {
17321775
}
17331776
}
17341777
}
1735-
}
1778+
}

0 commit comments

Comments
 (0)