Skip to content

Commit a034f87

Browse files
committed
Revert "Implement pattern ranges for all numeric types."
This reverts commit ce0f054.
1 parent 410f73f commit a034f87

File tree

14 files changed

+25
-451
lines changed

14 files changed

+25
-451
lines changed

src/comp/middle/alias.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ fn pattern_roots(tcx: ty::ctxt, mut: option::t<unsafe_ty>, pat: @ast::pat)
645645
fn walk(tcx: ty::ctxt, mut: option::t<unsafe_ty>, pat: @ast::pat,
646646
&set: [pattern_root]) {
647647
alt pat.node {
648-
ast::pat_wild. | ast::pat_lit(_) | ast::pat_range(_, _) {}
648+
ast::pat_wild. | ast::pat_lit(_) {}
649649
ast::pat_bind(nm) {
650650
set += [{id: pat.id, name: nm, mut: mut, span: pat.span}];
651651
}

src/comp/middle/check_alt.rs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,12 @@ fn pattern_supersedes(tcx: ty::ctxt, a: @pat, b: @pat) -> bool {
6262
ret true;
6363
}
6464

65+
6566
alt a.node {
6667
pat_wild. | pat_bind(_) { ret true; }
6768
pat_lit(la) {
6869
alt b.node {
6970
pat_lit(lb) { ret util::common::lit_eq(la, lb); }
70-
pat_range(beginb, endb) {
71-
ret util::common::lit_type_eq(la, beginb) &&
72-
util::common::lit_in_range(la, beginb, endb);
73-
}
7471
_ { ret false; }
7572
}
7673
}
@@ -101,19 +98,6 @@ fn pattern_supersedes(tcx: ty::ctxt, a: @pat, b: @pat) -> bool {
10198
_ { ret pattern_supersedes(tcx, suba, b); }
10299
}
103100
}
104-
pat_range(begina, enda) {
105-
alt b.node {
106-
pat_lit(lb) {
107-
ret util::common::lit_type_eq(lb, begina) &&
108-
util::common::lit_in_range(lb, begina, enda);
109-
}
110-
pat_range(beginb, endb) {
111-
ret util::common::lit_type_eq(begina, beginb) &&
112-
util::common::lit_ranges_overlap(begina, enda, beginb, endb);
113-
}
114-
_ { ret false; }
115-
}
116-
}
117101
}
118102
}
119103

src/comp/middle/trans_alt.rs

Lines changed: 20 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import std::{str, vec, option, int};
1+
import std::{str, vec, option};
22
import option::{some, none};
33
import std::map::hashmap;
44

@@ -16,42 +16,25 @@ import util::common::lit_eq;
1616

1717
import trans_common::*;
1818

19-
// An option identifying a branch (either a literal, a tag variant or a range)
19+
// An option identifying a branch (either a literal or a tag variant)
2020
tag opt {
2121
lit(@ast::lit);
2222
var(/* variant id */uint, /* variant dids */{tg: def_id, var: def_id});
23-
range(@ast::lit, @ast::lit);
2423
}
2524
fn opt_eq(a: opt, b: opt) -> bool {
2625
alt a {
2726
lit(la) {
28-
ret alt b { lit(lb) { lit_eq(la, lb) } _ { false } };
27+
ret alt b { lit(lb) { lit_eq(la, lb) } var(_, _) { false } };
2928
}
3029
var(ida, _) {
31-
ret alt b { var(idb, _) { ida == idb } _ { false } };
32-
}
33-
range(la1, la2) {
34-
ret alt b {
35-
range(lb1, lb2) { lit_eq(la1, lb1) && lit_eq(la2, lb2) }
36-
_ { false }
37-
};
30+
ret alt b { lit(_) { false } var(idb, _) { ida == idb } };
3831
}
3932
}
4033
}
41-
42-
tag opt_result {
43-
single_result(result);
44-
range_result(result, result);
45-
}
46-
fn trans_opt(bcx: @block_ctxt, o: opt) -> opt_result {
34+
fn trans_opt(bcx: @block_ctxt, o: opt) -> result {
4735
alt o {
48-
lit(l) { ret single_result(trans::trans_lit(bcx, *l)); }
49-
var(id, _) { ret single_result(rslt(bcx, C_int(id as int))); }
50-
range(l1, l2) {
51-
let r1 = trans::trans_lit(bcx, *l1);
52-
let r2 = trans::trans_lit(r1.bcx, *l2);
53-
ret range_result(r1, r2);
54-
}
36+
lit(l) { ret trans::trans_lit(bcx, *l); }
37+
var(id, _) { ret rslt(bcx, C_int(id as int)); }
5538
}
5639
}
5740

@@ -141,9 +124,6 @@ fn enter_opt(ccx: @crate_ctxt, m: match, opt: opt, col: uint, tag_size: uint,
141124
ast::pat_lit(l) {
142125
ret if opt_eq(lit(l), opt) { some([]) } else { none };
143126
}
144-
ast::pat_range(l1, l2) {
145-
ret if opt_eq(range(l1, l2), opt) { some([]) } else { none };
146-
}
147127
_ { ret some(vec::init_elt(dummy, size)); }
148128
}
149129
}
@@ -206,9 +186,6 @@ fn get_options(ccx: @crate_ctxt, m: match, col: uint) -> [opt] {
206186
for br: match_branch in m {
207187
alt br.pats[col].node {
208188
ast::pat_lit(l) { add_to_set(found, lit(l)); }
209-
ast::pat_range(l1, l2) {
210-
add_to_set(found, range(l1, l2));
211-
}
212189
ast::pat_tag(_, _) {
213190
add_to_set(found, variant_opt(ccx, br.pats[col].id));
214191
}
@@ -288,9 +265,7 @@ fn pick_col(m: match) -> uint {
288265
let i = 0u;
289266
for p: @ast::pat in br.pats {
290267
alt p.node {
291-
ast::pat_lit(_) | ast::pat_tag(_, _) | ast::pat_range(_, _) {
292-
scores[i] += 1u;
293-
}
268+
ast::pat_lit(_) | ast::pat_tag(_, _) { scores[i] += 1u; }
294269
_ { }
295270
}
296271
i += 1u;
@@ -435,16 +410,6 @@ fn compile_submatch(bcx: @block_ctxt, m: match, vals: [ValueRef], f: mk_fail,
435410
_ { test_val = Load(bcx, val); switch }
436411
};
437412
}
438-
range(_, _) {
439-
test_val = Load(bcx, val);
440-
kind = compare;
441-
}
442-
}
443-
}
444-
for o: opt in opts {
445-
alt o {
446-
range(_, _) { kind = compare; break; }
447-
_ { }
448413
}
449414
}
450415
let else_cx =
@@ -463,44 +428,22 @@ fn compile_submatch(bcx: @block_ctxt, m: match, vals: [ValueRef], f: mk_fail,
463428
alt kind {
464429
single. { Br(bcx, opt_cx.llbb); }
465430
switch. {
466-
let res = trans_opt(bcx, opt);
467-
alt res {
468-
single_result(r) {
469-
llvm::LLVMAddCase(sw, r.val, opt_cx.llbb);
470-
bcx = r.bcx;
471-
}
472-
}
431+
let r = trans_opt(bcx, opt);
432+
bcx = r.bcx;
433+
llvm::LLVMAddCase(sw, r.val, opt_cx.llbb);
473434
}
474435
compare. {
475436
let compare_cx = new_scope_block_ctxt(bcx, "compare_scope");
476437
Br(bcx, compare_cx.llbb);
477438
bcx = compare_cx;
439+
let r = trans_opt(bcx, opt);
440+
bcx = r.bcx;
478441
let t = ty::node_id_to_type(ccx.tcx, pat_id);
479-
let res = trans_opt(bcx, opt);
480-
alt res {
481-
single_result(r) {
482-
bcx = r.bcx;
483-
let eq =
484-
trans::trans_compare(bcx, ast::eq, test_val, t, r.val, t);
485-
/*let*/ bcx = eq.bcx; //XXX uncomment for assertion
486-
let cleanup_cx = trans::trans_block_cleanups(bcx, compare_cx);
487-
bcx = new_sub_block_ctxt(bcx, "compare_next");
488-
CondBr(cleanup_cx, eq.val, opt_cx.llbb, bcx.llbb);
489-
}
490-
range_result(rbegin, rend) {
491-
bcx = rend.bcx;
492-
let ge = trans::trans_compare(bcx, ast::ge, test_val, t,
493-
rbegin.val, t);
494-
let le = trans::trans_compare(ge.bcx, ast::le, test_val, t,
495-
rend.val, t);
496-
let in_range = rslt(le.bcx, And(le.bcx, ge.val, le.val));
497-
/*let*/ bcx = in_range.bcx; //XXX uncomment for assertion
498-
let cleanup_cx =
499-
trans::trans_block_cleanups(bcx, compare_cx);
500-
bcx = new_sub_block_ctxt(bcx, "compare_next");
501-
CondBr(cleanup_cx, in_range.val, opt_cx.llbb, bcx.llbb);
502-
}
503-
}
442+
let eq =
443+
trans::trans_compare(bcx, ast::eq, test_val, t, r.val, t);
444+
let cleanup_cx = trans::trans_block_cleanups(bcx, compare_cx);
445+
bcx = new_sub_block_ctxt(bcx, "compare_next");
446+
CondBr(cleanup_cx, eq.val, opt_cx.llbb, bcx.llbb);
504447
}
505448
_ { }
506449
}
@@ -513,7 +456,7 @@ fn compile_submatch(bcx: @block_ctxt, m: match, vals: [ValueRef], f: mk_fail,
513456
unpacked = args.vals;
514457
opt_cx = args.bcx;
515458
}
516-
lit(_) | range(_, _) { }
459+
lit(_) { }
517460
}
518461
compile_submatch(opt_cx, enter_opt(ccx, m, opt, col, size, val),
519462
unpacked + vals_left, f, exits);
@@ -688,13 +631,12 @@ fn bind_irrefutable_pat(bcx: @block_ctxt, pat: @ast::pat, val: ValueRef,
688631
[C_int(0), C_int(back::abi::box_rc_field_body)]);
689632
bcx = bind_irrefutable_pat(bcx, inner, unboxed, table, true);
690633
}
691-
ast::pat_wild. | ast::pat_lit(_) | ast::pat_range(_, _) { }
634+
ast::pat_wild. | ast::pat_lit(_) { }
692635
}
693636
ret bcx;
694637
}
695638

696639
// Local Variables:
697-
// mode: rust
698640
// fill-column: 78;
699641
// indent-tabs-mode: nil
700642
// c-basic-offset: 4

src/comp/middle/typeck.rs

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,44 +1266,6 @@ fn check_lit(ccx: @crate_ctxt, lit: @ast::lit) -> ty::t {
12661266
}
12671267
}
12681268

1269-
fn lit_as_uint(l: @ast::lit) -> uint {
1270-
alt l.node {
1271-
ast::lit_uint(u) { u }
1272-
ast::lit_char(c) { c as uint }
1273-
}
1274-
}
1275-
fn lit_as_int(l: @ast::lit) -> int {
1276-
alt l.node {
1277-
ast::lit_int(i) | ast::lit_mach_int(_, i) { i }
1278-
}
1279-
}
1280-
fn lit_as_float(l: @ast::lit) -> str {
1281-
alt l.node {
1282-
ast::lit_float(f) | ast::lit_mach_float(_, f) { f }
1283-
}
1284-
}
1285-
1286-
fn valid_range_bounds(l1: @ast::lit, l2: @ast::lit) -> bool {
1287-
alt l1.node {
1288-
ast::lit_float(s1) | ast::lit_mach_float(_, s1) {
1289-
let s2 = lit_as_float(l2);
1290-
let f1 = util::common::str_to_float(s1);
1291-
let f2 = util::common::str_to_float(s2);
1292-
ret *util::common::min(f1, f2) == f1
1293-
}
1294-
ast::lit_uint(_) | ast::lit_char(_) {
1295-
let u1 = lit_as_uint(l1);
1296-
let u2 = lit_as_uint(l2);
1297-
ret *util::common::min(u1, u2) == u1
1298-
}
1299-
_ {
1300-
let i1 = lit_as_int(l1);
1301-
let i2 = lit_as_int(l2);
1302-
ret *util::common::min(i1, i2) == i1
1303-
}
1304-
}
1305-
}
1306-
13071269
// Pattern checking is top-down rather than bottom-up so that bindings get
13081270
// their types immediately.
13091271
fn check_pat(fcx: @fn_ctxt, map: ast_util::pat_id_map, pat: @ast::pat,
@@ -1315,23 +1277,6 @@ fn check_pat(fcx: @fn_ctxt, map: ast_util::pat_id_map, pat: @ast::pat,
13151277
typ = demand::simple(fcx, pat.span, expected, typ);
13161278
write::ty_only_fixup(fcx, pat.id, typ);
13171279
}
1318-
ast::pat_range(begin, end) {
1319-
if !util::common::lit_is_numeric(begin) ||
1320-
!util::common::lit_is_numeric(end) {
1321-
fcx.ccx.tcx.sess.span_err(pat.span,
1322-
"non-numeric type used in range");
1323-
} else if !valid_range_bounds(begin, end) {
1324-
fcx.ccx.tcx.sess.span_err(begin.span,
1325-
"lower range bound must be less \
1326-
than upper");
1327-
}
1328-
let typ1 = check_lit(fcx.ccx, begin);
1329-
typ1 = demand::simple(fcx, pat.span, expected, typ1);
1330-
write::ty_only_fixup(fcx, pat.id, typ1);
1331-
let typ2 = check_lit(fcx.ccx, end);
1332-
typ2 = demand::simple(fcx, pat.span, typ1, typ2);
1333-
write::ty_only_fixup(fcx, pat.id, typ2);
1334-
}
13351280
ast::pat_bind(name) {
13361281
let vid = lookup_local(fcx, pat.span, pat.id);
13371282
let typ = ty::mk_var(fcx.ccx.tcx, vid);

src/comp/syntax/ast.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ tag pat_ {
9292
pat_rec([field_pat], bool);
9393
pat_tup([@pat]);
9494
pat_box(@pat);
95-
pat_range(@lit, @lit);
9695
}
9796

9897
tag mutability { mut; imm; maybe_mut; }

src/comp/syntax/ast_util.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ iter pat_bindings(pat: @pat) -> @pat {
6969
for elt in elts { for each b in pat_bindings(elt) { put b; } }
7070
}
7171
pat_box(sub) { for each b in pat_bindings(sub) { put b; } }
72-
pat_wild. | pat_lit(_) | pat_range(_, _) { }
72+
pat_wild. | pat_lit(_) { }
7373
}
7474
}
7575

@@ -229,4 +229,3 @@ fn ret_by_ref(style: ret_style) -> bool {
229229
// buffer-file-coding-system: utf-8-unix
230230
// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
231231
// End:
232-

src/comp/syntax/fold.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,6 @@ fn noop_fold_pat(p: pat_, fld: ast_fold) -> pat_ {
291291
}
292292
pat_tup(elts) { pat_tup(vec::map(fld.fold_pat, elts)) }
293293
pat_box(inner) { pat_box(fld.fold_pat(inner)) }
294-
pat_range(_, _) { p }
295294
};
296295
}
297296

src/comp/syntax/parse/parser.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,14 +1494,8 @@ fn parse_pat(p: parser) -> @ast::pat {
14941494
tok {
14951495
if !is_ident(tok) || is_word(p, "true") || is_word(p, "false") {
14961496
let lit = parse_lit(p);
1497-
if eat_word(p, "to") {
1498-
let end = parse_lit(p);
1499-
hi = end.span.hi;
1500-
pat = ast::pat_range(@lit, @end);
1501-
} else {
1502-
hi = lit.span.hi;
1503-
pat = ast::pat_lit(@lit);
1504-
}
1497+
hi = lit.span.hi;
1498+
pat = ast::pat_lit(@lit);
15051499
} else if is_plain_ident(p) &&
15061500
alt p.look_ahead(1u) {
15071501
token::DOT. | token::LPAREN. | token::LBRACKET. {

src/comp/syntax/print/pprust.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,12 +1113,6 @@ fn print_pat(s: ps, pat: @ast::pat) {
11131113
pclose(s);
11141114
}
11151115
ast::pat_box(inner) { word(s.s, "@"); print_pat(s, inner); }
1116-
ast::pat_range(begin, end) {
1117-
print_literal(s, begin);
1118-
space(s.s);
1119-
word_space(s, "to");
1120-
print_literal(s, end);
1121-
}
11221116
}
11231117
s.ann.post(ann_node);
11241118
}

0 commit comments

Comments
 (0)