Skip to content

Commit adb717b

Browse files
committed
Merge pull request #2516 from mozilla/incoming
Incoming
2 parents aabf84c + 17e707c commit adb717b

File tree

18 files changed

+98
-116
lines changed

18 files changed

+98
-116
lines changed

src/libcore/cmp.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#[doc="Interfaces used for comparison."]
2+
3+
iface ord {
4+
fn lt(&&other: self) -> bool;
5+
}
6+
7+
iface eq {
8+
fn eq(&&other: self) -> bool;
9+
}
10+

src/libcore/core.rc

+2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export extfmt;
4444
export tuple;
4545
export to_str;
4646
export dvec, dvec_iter;
47+
export cmp;
4748

4849
// NDM seems to be necessary for resolve to work
4950
export option_iter;
@@ -152,6 +153,7 @@ mod tuple;
152153

153154
// Ubiquitous-utility-type modules
154155

156+
mod cmp;
155157
mod either;
156158
mod iter;
157159
mod logging;

src/libcore/int-template.rs

+14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import T = inst::T;
2+
import cmp::{eq, ord};
23

34
export min_value, max_value;
45
export min, max;
@@ -10,6 +11,7 @@ export range;
1011
export compl;
1112
export abs;
1213
export parse_buf, from_str, to_str, to_str_bytes, str;
14+
export ord, eq;
1315

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

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+
111125

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

src/libcore/uint-template.rs

+14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import T = inst::T;
2+
import cmp::{eq, ord};
23

34
export min_value, max_value;
45
export min, max;
@@ -10,6 +11,7 @@ export range;
1011
export compl;
1112
export to_str, to_str_bytes;
1213
export from_str, from_str_radix, str, parse_buf;
14+
export ord, eq;
1315

1416
const min_value: T = 0 as T;
1517
const max_value: T = 0 as T - 1 as T;
@@ -49,6 +51,18 @@ pure fn compl(i: T) -> T {
4951
max_value ^ i
5052
}
5153

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+
5266
#[doc = "
5367
Parse a buffer of bytes
5468

src/libstd/sort.rs

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

45
export le;
56
export merge_sort;
@@ -141,7 +142,6 @@ fn qsort3<T: copy>(compare_func_lt: le<T>, compare_func_eq: le<T>,
141142
qsort3::<T>(compare_func_lt, compare_func_eq, arr, i, right);
142143
}
143144

144-
// FIXME: This should take lt and eq types (#2348)
145145
#[doc = "
146146
Fancy quicksort. Sorts a mut vector in place.
147147
@@ -152,22 +152,17 @@ 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>(compare_func_lt: le<T>, compare_func_eq: le<T>,
156-
arr: [mut T]) {
155+
fn quick_sort3<T: copy ord eq>(arr: [mut T]) {
157156
if len::<T>(arr) == 0u { ret; }
158-
qsort3::<T>(compare_func_lt, compare_func_eq, arr, 0,
157+
qsort3::<T>({ |x, y| x.lt(y) }, { |x, y| x.eq(y) }, arr, 0,
159158
(len::<T>(arr) as int) - 1);
160159
}
161160

162161
#[cfg(test)]
163162
mod test_qsort3 {
164163
fn check_sort(v1: [mut int], v2: [mut int]) {
165164
let len = vec::len::<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);
165+
quick_sort3::<int>(v1);
171166
let mut i = 0u;
172167
while i < len {
173168
log(debug, v2[i]);

src/rustc/driver/driver.rs

+2-2
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, spill_map) =
197+
let last_use_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, spill_map: spill_map};
219+
vtable_map: vtable_map};
220220

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

src/rustc/driver/rustc.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import std::map::hashmap;
1515
import getopts::{opt_present};
1616
import rustc::driver::driver::*;
1717
import syntax::codemap;
18-
import rustc::driver::{diagnostic, session};
18+
import syntax::diagnostic;
19+
import rustc::driver::session;
1920
import rustc::middle::lint;
2021
import io::reader_util;
2122

src/rustc/metadata/decoder.rs

+1-1
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::*;
1110
import tydecode::{parse_ty_data, parse_def_id, parse_bounds_data,
1211
parse_ident};
1312
import syntax::print::pprust;
1413
import cmd=cstore::crate_metadata;
1514
import util::ppaux::ty_to_str;
1615
import ebml::deserializer;
1716
import syntax::diagnostic::span_handler;
17+
import common::*;
1818

1919
export class_dtor;
2020
export get_class_fields;

src/rustc/middle/astencode.rs

-9
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ 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
6160
};
6261

6362
type decode_ctxt = @{
@@ -839,12 +838,6 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt,
839838
}
840839
}
841840

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-
848841
option::iter(maps.last_use_map.find(id)) {|m|
849842
ebml_w.tag(c::tag_table_last_use) {||
850843
ebml_w.id(id);
@@ -953,8 +946,6 @@ fn decode_side_tables(xcx: extended_decode_ctxt,
953946
dcx.maps.mutbl_map.insert(id, ());
954947
} else if tag == (c::tag_table_copy as uint) {
955948
dcx.maps.copy_map.insert(id, ());
956-
} else if tag == (c::tag_table_spill as uint) {
957-
dcx.maps.spill_map.insert(id, ());
958949
} else {
959950
let val_doc = entry_doc[c::tag_table_val];
960951
let val_dsr = ebml::ebml_deserializer(val_doc);

src/rustc/middle/liveness.rs

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

5858
export check_crate;
5959
export last_use_map;
60-
export spill_map;
6160

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

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-
7668
enum variable = uint;
7769
enum live_node = uint;
7870

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

8678
fn check_crate(tcx: ty::ctxt,
8779
method_map: typeck::method_map,
88-
crate: @crate) -> (last_use_map, spill_map) {
80+
crate: @crate) -> last_use_map {
8981
let visitor = visit::mk_vt(@{
9082
visit_fn: visit_fn,
9183
visit_local: visit_local,
@@ -94,12 +86,11 @@ fn check_crate(tcx: ty::ctxt,
9486
});
9587

9688
let last_use_map = int_hash();
97-
let spill_map = int_hash();
9889
let initial_maps = @ir_maps(tcx, method_map,
99-
last_use_map, spill_map);
90+
last_use_map);
10091
visit::visit_crate(*crate, initial_maps, visitor);
10192
tcx.sess.abort_if_errors();
102-
ret (last_use_map, spill_map);
93+
ret last_use_map;
10394
}
10495

10596
impl of to_str::to_str for live_node {
@@ -162,7 +153,6 @@ class ir_maps {
162153
let tcx: ty::ctxt;
163154
let method_map: typeck::method_map;
164155
let last_use_map: last_use_map;
165-
let spill_map: spill_map;
166156

167157
let mut num_live_nodes: uint;
168158
let mut num_vars: uint;
@@ -174,11 +164,10 @@ class ir_maps {
174164
let mut lnks: [live_node_kind];
175165

176166
new(tcx: ty::ctxt, method_map: typeck::method_map,
177-
last_use_map: last_use_map, spill_map: spill_map) {
167+
last_use_map: last_use_map) {
178168
self.tcx = tcx;
179169
self.method_map = method_map;
180170
self.last_use_map = last_use_map;
181-
self.spill_map = spill_map;
182171

183172
self.num_live_nodes = 0u;
184173
self.num_vars = 0u;
@@ -264,17 +253,6 @@ class ir_maps {
264253
self.lnks[*ln]
265254
}
266255

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-
278256
fn add_last_use(expr_id: node_id, var: variable) {
279257
let vk = self.var_kinds[*var];
280258
#debug["Node %d is a last use of variable %?", expr_id, vk];
@@ -308,7 +286,7 @@ fn visit_fn(fk: visit::fn_kind, decl: fn_decl, body: blk,
308286

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

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

@@ -1407,11 +1385,7 @@ fn check_expr(expr: @expr, &&self: @liveness, vt: vt<@liveness>) {
14071385
vt.visit_expr(f, self, vt);
14081386
vec::iter2(args, targs) { |arg_expr, arg_ty|
14091387
alt ty::resolved_mode(self.tcx, arg_ty.mode) {
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);
1388+
by_val | by_copy | by_ref | by_mutbl_ref{
14151389
vt.visit_expr(arg_expr, self, vt);
14161390
}
14171391
by_move {
@@ -1421,10 +1395,6 @@ fn check_expr(expr: @expr, &&self: @liveness, vt: vt<@liveness>) {
14211395
}
14221396
}
14231397

1424-
expr_addr_of(_, arg_expr) {
1425-
self.spill_expr(arg_expr);
1426-
}
1427-
14281398
// no correctness conditions related to liveness
14291399
expr_if_check(*) | expr_if(*) | expr_alt(*) |
14301400
expr_while(*) | expr_loop(*) |
@@ -1434,7 +1404,7 @@ fn check_expr(expr: @expr, &&self: @liveness, vt: vt<@liveness>) {
14341404
expr_assert(*) | expr_check(*) | expr_copy(*) |
14351405
expr_loop_body(*) | expr_cast(*) | expr_unary(*) | expr_fail(*) |
14361406
expr_ret(*) | expr_break | expr_cont | expr_lit(_) |
1437-
expr_block(*) | expr_swap(*) | expr_mac(*) {
1407+
expr_block(*) | expr_swap(*) | expr_mac(*) | expr_addr_of(*) {
14381408
visit::visit_expr(expr, self, vt);
14391409
}
14401410
}
@@ -1501,10 +1471,7 @@ impl check_methods for @liveness {
15011471
ln.to_str(), var.to_str()];
15021472

15031473
alt (*self).live_on_exit(ln, var) {
1504-
none {
1505-
// update spill map to include this variable, as it is moved:
1506-
(*self.ir).add_spill(var);
1507-
}
1474+
none { }
15081475
some(lnk) {
15091476
self.report_illegal_move(span, lnk, var);
15101477
}
@@ -1516,20 +1483,10 @@ impl check_methods for @liveness {
15161483
some(_) {}
15171484
none {
15181485
(*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);
15221486
}
15231487
}
15241488
}
15251489

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-
15331490
fn check_move_from_expr(expr: @expr, vt: vt<@liveness>) {
15341491
#debug["check_move_from_expr(node %d: %s)",
15351492
expr.id, expr_to_str(expr)];
@@ -1775,4 +1732,4 @@ impl check_methods for @liveness {
17751732
}
17761733
}
17771734
}
1778-
}
1735+
}

0 commit comments

Comments
 (0)