Skip to content

Commit 2791877

Browse files
committed
Merge pull request rust-lang#4388 from lkuper/alt-to-match
Rename identifiers that still use 'alt' to use 'match'
2 parents dd73dd0 + 816cb8c commit 2791877

File tree

19 files changed

+96
-95
lines changed

19 files changed

+96
-95
lines changed

src/librustc/driver/driver.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,8 @@ fn compile_upto(sess: Session, cfg: ast::crate_cfg,
275275
time(time_passes, ~"mode computation", ||
276276
middle::mode::compute_modes(ty_cx, method_map, crate));
277277

278-
time(time_passes, ~"alt checking", ||
279-
middle::check_alt::check_crate(ty_cx, method_map, crate));
278+
time(time_passes, ~"match checking", ||
279+
middle::check_match::check_crate(ty_cx, method_map, crate));
280280

281281
let last_use_map =
282282
time(time_passes, ~"liveness checking", ||

src/librustc/middle/borrowck/gather_loans.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -506,19 +506,19 @@ impl gather_loan_ctxt {
506506
discr_cmt: cmt,
507507
root_pat: @ast::pat,
508508
arm_id: ast::node_id,
509-
alt_id: ast::node_id) {
509+
match_id: ast::node_id) {
510510
do self.bccx.cat_pattern(discr_cmt, root_pat) |cmt, pat| {
511511
match pat.node {
512512
ast::pat_ident(bm, _, _) if self.pat_is_binding(pat) => {
513513
match bm {
514514
ast::bind_by_value | ast::bind_by_move => {
515515
// copying does not borrow anything, so no check
516516
// is required
517-
// as for move, check::alt ensures it's from an rvalue.
517+
// as for move, check::_match ensures it's from an rvalue.
518518
}
519519
ast::bind_by_ref(mutbl) => {
520520
// ref x or ref x @ p --- creates a ptr which must
521-
// remain valid for the scope of the alt
521+
// remain valid for the scope of the match
522522

523523
// find the region of the resulting pointer (note that
524524
// the type of such a pattern will *always* be a
@@ -531,7 +531,7 @@ impl gather_loan_ctxt {
531531
// of the function of this node in method preserve():
532532
let arm_scope = ty::re_scope(arm_id);
533533
if self.bccx.is_subregion_of(scope_r, arm_scope) {
534-
let cmt_discr = self.bccx.cat_discr(cmt, alt_id);
534+
let cmt_discr = self.bccx.cat_discr(cmt, match_id);
535535
self.guarantee_valid(cmt_discr, mutbl, scope_r);
536536
} else {
537537
self.guarantee_valid(cmt, mutbl, scope_r);

src/librustc/middle/borrowck/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -494,8 +494,8 @@ impl borrowck_ctxt {
494494
cat_variant(self.tcx, self.method_map, arg, enum_did, cmt)
495495
}
496496

497-
fn cat_discr(cmt: cmt, alt_id: ast::node_id) -> cmt {
498-
return @{cat:cat_discr(cmt, alt_id),.. *cmt};
497+
fn cat_discr(cmt: cmt, match_id: ast::node_id) -> cmt {
498+
return @{cat:cat_discr(cmt, match_id),.. *cmt};
499499
}
500500

501501
fn cat_pattern(cmt: cmt, pat: @ast::pat, op: fn(cmt, @ast::pat)) {

src/librustc/middle/borrowck/preserve.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -195,15 +195,15 @@ priv impl &preserve_ctxt {
195195
self.attempt_root(cmt, base, derefs)
196196
}
197197
}
198-
cat_discr(base, alt_id) => {
199-
// Subtle: in an alt, we must ensure that each binding
198+
cat_discr(base, match_id) => {
199+
// Subtle: in a match, we must ensure that each binding
200200
// variable remains valid for the duration of the arm in
201201
// which it appears, presuming that this arm is taken.
202202
// But it is inconvenient in trans to root something just
203203
// for one arm. Therefore, we insert a cat_discr(),
204204
// basically a special kind of category that says "if this
205205
// value must be dynamically rooted, root it for the scope
206-
// `alt_id`.
206+
// `match_id`.
207207
//
208208
// As an example, consider this scenario:
209209
//
@@ -213,7 +213,7 @@ priv impl &preserve_ctxt {
213213
// Technically, the value `x` need only be rooted
214214
// in the `some` arm. However, we evaluate `x` in trans
215215
// before we know what arm will be taken, so we just
216-
// always root it for the duration of the alt.
216+
// always root it for the duration of the match.
217217
//
218218
// As a second example, consider *this* scenario:
219219
//
@@ -225,7 +225,7 @@ priv impl &preserve_ctxt {
225225
// found only when checking which pattern matches: but
226226
// this check is done before entering the arm. Therefore,
227227
// even in this case we just choose to keep the value
228-
// rooted for the entire alt. This means the value will be
228+
// rooted for the entire match. This means the value will be
229229
// rooted even if the none arm is taken. Oh well.
230230
//
231231
// At first, I tried to optimize the second case to only
@@ -247,12 +247,12 @@ priv impl &preserve_ctxt {
247247
// Nonetheless, if you decide to optimize this case in the
248248
// future, you need only adjust where the cat_discr()
249249
// node appears to draw the line between what will be rooted
250-
// in the *arm* vs the *alt*.
250+
// in the *arm* vs the *match*.
251251

252-
let alt_rooting_ctxt =
253-
preserve_ctxt({scope_region: ty::re_scope(alt_id),
252+
let match_rooting_ctxt =
253+
preserve_ctxt({scope_region: ty::re_scope(match_id),
254254
.. **self});
255-
(&alt_rooting_ctxt).preserve(base)
255+
(&match_rooting_ctxt).preserve(base)
256256
}
257257
}
258258
}

src/librustc/middle/check_alt.rs renamed to src/librustc/middle/check_match.rs

+18-18
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ use syntax::codemap::span;
3030
use syntax::print::pprust::pat_to_str;
3131
use syntax::visit;
3232

33-
struct AltCheckCtxt {
33+
struct MatchCheckCtxt {
3434
tcx: ty::ctxt,
3535
method_map: method_map,
3636
}
3737

3838
fn check_crate(tcx: ty::ctxt, method_map: method_map, crate: @crate) {
39-
let cx = @AltCheckCtxt { tcx: tcx, method_map: method_map };
39+
let cx = @MatchCheckCtxt { tcx: tcx, method_map: method_map };
4040
visit::visit_crate(*crate, (), visit::mk_vt(@{
4141
visit_expr: |a,b,c| check_expr(cx, a, b, c),
4242
visit_local: |a,b,c| check_local(cx, a, b, c),
@@ -47,7 +47,7 @@ fn check_crate(tcx: ty::ctxt, method_map: method_map, crate: @crate) {
4747
tcx.sess.abort_if_errors();
4848
}
4949

50-
fn expr_is_non_moving_lvalue(cx: @AltCheckCtxt, expr: @expr) -> bool {
50+
fn expr_is_non_moving_lvalue(cx: @MatchCheckCtxt, expr: @expr) -> bool {
5151
if !ty::expr_is_lval(cx.tcx, cx.method_map, expr) {
5252
return false;
5353
}
@@ -61,7 +61,7 @@ fn expr_is_non_moving_lvalue(cx: @AltCheckCtxt, expr: @expr) -> bool {
6161
}
6262
}
6363

64-
fn check_expr(cx: @AltCheckCtxt, ex: @expr, &&s: (), v: visit::vt<()>) {
64+
fn check_expr(cx: @MatchCheckCtxt, ex: @expr, &&s: (), v: visit::vt<()>) {
6565
visit::visit_expr(ex, s, v);
6666
match ex.node {
6767
expr_match(scrut, ref arms) => {
@@ -107,7 +107,7 @@ fn check_expr(cx: @AltCheckCtxt, ex: @expr, &&s: (), v: visit::vt<()>) {
107107
}
108108

109109
// Check for unreachable patterns
110-
fn check_arms(cx: @AltCheckCtxt, arms: ~[arm]) {
110+
fn check_arms(cx: @MatchCheckCtxt, arms: ~[arm]) {
111111
let mut seen = ~[];
112112
for arms.each |arm| {
113113
for arm.pats.each |pat| {
@@ -130,7 +130,7 @@ fn raw_pat(p: @pat) -> @pat {
130130
}
131131
}
132132

133-
fn check_exhaustive(cx: @AltCheckCtxt, sp: span, pats: ~[@pat]) {
133+
fn check_exhaustive(cx: @MatchCheckCtxt, sp: span, pats: ~[@pat]) {
134134
assert(pats.is_not_empty());
135135
let ext = match is_useful(cx, vec::map(pats, |p| ~[*p]), ~[wild()]) {
136136
not_useful => return, // This is good, wildcard pattern isn't reachable
@@ -216,7 +216,7 @@ impl ctor : cmp::Eq {
216216

217217
// Note: is_useful doesn't work on empty types, as the paper notes.
218218
// So it assumes that v is non-empty.
219-
fn is_useful(cx: @AltCheckCtxt, +m: matrix, +v: ~[@pat]) -> useful {
219+
fn is_useful(cx: @MatchCheckCtxt, +m: matrix, +v: ~[@pat]) -> useful {
220220
if m.len() == 0u { return useful_; }
221221
if m[0].len() == 0u { return not_useful; }
222222
let real_pat = match vec::find(m, |r| r[0].id != 0) {
@@ -289,7 +289,7 @@ fn is_useful(cx: @AltCheckCtxt, +m: matrix, +v: ~[@pat]) -> useful {
289289
}
290290
}
291291

292-
fn is_useful_specialized(cx: @AltCheckCtxt, m: matrix, +v: ~[@pat],
292+
fn is_useful_specialized(cx: @MatchCheckCtxt, m: matrix, +v: ~[@pat],
293293
+ctor: ctor, arity: uint, lty: ty::t) -> useful {
294294
let ms = vec::filter_map(m, |r| specialize(cx, *r, ctor, arity, lty));
295295
let could_be_useful = is_useful(
@@ -300,7 +300,7 @@ fn is_useful_specialized(cx: @AltCheckCtxt, m: matrix, +v: ~[@pat],
300300
}
301301
}
302302

303-
fn pat_ctor_id(cx: @AltCheckCtxt, p: @pat) -> Option<ctor> {
303+
fn pat_ctor_id(cx: @MatchCheckCtxt, p: @pat) -> Option<ctor> {
304304
let pat = raw_pat(p);
305305
match /*bad*/copy pat.node {
306306
pat_wild => { None }
@@ -337,7 +337,7 @@ fn pat_ctor_id(cx: @AltCheckCtxt, p: @pat) -> Option<ctor> {
337337
}
338338
}
339339

340-
fn is_wild(cx: @AltCheckCtxt, p: @pat) -> bool {
340+
fn is_wild(cx: @MatchCheckCtxt, p: @pat) -> bool {
341341
let pat = raw_pat(p);
342342
match pat.node {
343343
pat_wild => { true }
@@ -351,7 +351,7 @@ fn is_wild(cx: @AltCheckCtxt, p: @pat) -> bool {
351351
}
352352
}
353353

354-
fn missing_ctor(cx: @AltCheckCtxt,
354+
fn missing_ctor(cx: @MatchCheckCtxt,
355355
m: matrix,
356356
left_ty: ty::t)
357357
-> Option<ctor> {
@@ -451,7 +451,7 @@ fn missing_ctor(cx: @AltCheckCtxt,
451451
}
452452
}
453453

454-
fn ctor_arity(cx: @AltCheckCtxt, ctor: ctor, ty: ty::t) -> uint {
454+
fn ctor_arity(cx: @MatchCheckCtxt, ctor: ctor, ty: ty::t) -> uint {
455455
match /*bad*/copy ty::get(ty).sty {
456456
ty::ty_tup(fs) => fs.len(),
457457
ty::ty_rec(fs) => fs.len(),
@@ -479,7 +479,7 @@ fn wild() -> @pat {
479479
@{id: 0, node: pat_wild, span: ast_util::dummy_sp()}
480480
}
481481

482-
fn specialize(cx: @AltCheckCtxt, r: ~[@pat], ctor_id: ctor, arity: uint,
482+
fn specialize(cx: @MatchCheckCtxt, r: ~[@pat], ctor_id: ctor, arity: uint,
483483
left_ty: ty::t) -> Option<~[@pat]> {
484484
let r0 = raw_pat(r[0]);
485485
match /*bad*/copy r0.node {
@@ -637,12 +637,12 @@ fn specialize(cx: @AltCheckCtxt, r: ~[@pat], ctor_id: ctor, arity: uint,
637637
}
638638
}
639639

640-
fn default(cx: @AltCheckCtxt, r: ~[@pat]) -> Option<~[@pat]> {
640+
fn default(cx: @MatchCheckCtxt, r: ~[@pat]) -> Option<~[@pat]> {
641641
if is_wild(cx, r[0]) { Some(vec::tail(r)) }
642642
else { None }
643643
}
644644

645-
fn check_local(cx: @AltCheckCtxt, loc: @local, &&s: (), v: visit::vt<()>) {
645+
fn check_local(cx: @MatchCheckCtxt, loc: @local, &&s: (), v: visit::vt<()>) {
646646
visit::visit_local(loc, s, v);
647647
if is_refutable(cx, loc.node.pat) {
648648
cx.tcx.sess.span_err(loc.node.pat.span,
@@ -657,7 +657,7 @@ fn check_local(cx: @AltCheckCtxt, loc: @local, &&s: (), v: visit::vt<()>) {
657657
check_legality_of_move_bindings(cx, is_lvalue, false, [ loc.node.pat ]);
658658
}
659659

660-
fn check_fn(cx: @AltCheckCtxt,
660+
fn check_fn(cx: @MatchCheckCtxt,
661661
kind: visit::fn_kind,
662662
decl: fn_decl,
663663
body: blk,
@@ -674,7 +674,7 @@ fn check_fn(cx: @AltCheckCtxt,
674674
}
675675
}
676676

677-
fn is_refutable(cx: @AltCheckCtxt, pat: &pat) -> bool {
677+
fn is_refutable(cx: @MatchCheckCtxt, pat: &pat) -> bool {
678678
match cx.tcx.def_map.find(pat.id) {
679679
Some(def_variant(enum_id, _)) => {
680680
if vec::len(*ty::enum_variants(cx.tcx, enum_id)) != 1u {
@@ -712,7 +712,7 @@ fn is_refutable(cx: @AltCheckCtxt, pat: &pat) -> bool {
712712

713713
// Legality of move bindings checking
714714

715-
fn check_legality_of_move_bindings(cx: @AltCheckCtxt,
715+
fn check_legality_of_move_bindings(cx: @MatchCheckCtxt,
716716
is_lvalue: bool,
717717
has_guard: bool,
718718
pats: &[@pat]) {

src/librustc/middle/const_eval.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ use syntax::ast::*;
4646
// & and * pointers
4747
// copies of general constants
4848
//
49-
// (in theory, probably not at first: if/alt on integer-const
49+
// (in theory, probably not at first: if/match on integer-const
5050
// conditions / descriminants)
5151
//
5252
// - Non-constants: everything else.

src/librustc/middle/mem_categorization.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ impl &mem_categorization_ctxt {
904904
// local(x)->@->@
905905
//
906906
// where the id of `local(x)` is the id of the `x` that appears
907-
// in the alt, the id of `local(x)->@` is the `@y` pattern,
907+
// in the match, the id of `local(x)->@` is the `@y` pattern,
908908
// and the id of `local(x)->@->@` is the id of the `y` pattern.
909909

910910

src/librustc/middle/region.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ struct ctxt {
7171
// that when we visit it we can view it as a parent.
7272
root_exprs: HashMap<ast::node_id, ()>,
7373

74-
// The parent scope is the innermost block, statement, call, or alt
74+
// The parent scope is the innermost block, statement, call, or match
7575
// expression during the execution of which the current expression
7676
// will be evaluated. Generally speaking, the innermost parent
7777
// scope is also the closest suitable ancestor in the AST tree.

src/librustc/middle/trans/alt.rs renamed to src/librustc/middle/trans/_match.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ enum opt_result {
245245
range_result(Result, Result),
246246
}
247247
fn trans_opt(bcx: block, o: &Opt) -> opt_result {
248-
let _icx = bcx.insn_ctxt("alt::trans_opt");
248+
let _icx = bcx.insn_ctxt("match::trans_opt");
249249
let ccx = bcx.ccx();
250250
let mut bcx = bcx;
251251
match *o {
@@ -463,8 +463,8 @@ fn enter_default(bcx: block, dm: DefMap, m: &[@Match/&r],
463463
}
464464

465465
// <pcwalton> nmatsakis: what does enter_opt do?
466-
// <pcwalton> in trans/alt
467-
// <pcwalton> trans/alt.rs is like stumbling around in a dark cave
466+
// <pcwalton> in trans/match
467+
// <pcwalton> trans/match.rs is like stumbling around in a dark cave
468468
// <nmatsakis> pcwalton: the enter family of functions adjust the set of
469469
// patterns as needed
470470
// <nmatsakis> yeah, at some point I kind of achieved some level of
@@ -810,7 +810,7 @@ fn extract_variant_args(bcx: block, pat_id: ast::node_id,
810810
val: ValueRef)
811811
-> {vals: ~[ValueRef], bcx: block}
812812
{
813-
let _icx = bcx.insn_ctxt("alt::extract_variant_args");
813+
let _icx = bcx.insn_ctxt("match::extract_variant_args");
814814
let ccx = bcx.fcx.ccx;
815815
let enum_ty_substs = match ty::get(node_id_type(bcx, pat_id)).sty {
816816
ty::ty_enum(id, ref substs) => {
@@ -841,7 +841,7 @@ fn extract_vec_elems(bcx: block, pat_id: ast::node_id,
841841
elem_count: uint, tail: bool, val: ValueRef)
842842
-> {vals: ~[ValueRef], bcx: block}
843843
{
844-
let _icx = bcx.insn_ctxt("alt::extract_vec_elems");
844+
let _icx = bcx.insn_ctxt("match::extract_vec_elems");
845845
let vt = tvec::vec_types(bcx, node_id_type(bcx, pat_id));
846846
let unboxed = load_if_immediate(bcx, val, vt.vec_ty);
847847
let (base, len) = tvec::get_base_and_len(bcx, unboxed, vt.vec_ty);
@@ -909,7 +909,7 @@ fn root_pats_as_necessary(bcx: block, m: &[@Match],
909909
match bcx.ccx().maps.root_map.find({id:pat_id, derefs:0u}) {
910910
None => (),
911911
Some(scope_id) => {
912-
// Note: the scope_id will always be the id of the alt. See
912+
// Note: the scope_id will always be the id of the match. See
913913
// the extended comment in rustc::middle::borrowck::preserve()
914914
// for details (look for the case covering cat_discr).
915915

@@ -1201,7 +1201,7 @@ fn compile_submatch(bcx: block,
12011201
For an empty match, a fall-through case must exist
12021202
*/
12031203
assert(m.len() > 0u || chk.is_some());
1204-
let _icx = bcx.insn_ctxt("alt::compile_submatch");
1204+
let _icx = bcx.insn_ctxt("match::compile_submatch");
12051205
let mut bcx = bcx;
12061206
let tcx = bcx.tcx(), dm = tcx.def_map;
12071207
if m.len() == 0u {
@@ -1520,22 +1520,22 @@ fn compile_submatch(bcx: block,
15201520
}
15211521
}
15221522
1523-
fn trans_alt(bcx: block,
1524-
alt_expr: @ast::expr,
1523+
fn trans_match(bcx: block,
1524+
match_expr: @ast::expr,
15251525
discr_expr: @ast::expr,
15261526
arms: ~[ast::arm],
15271527
dest: Dest) -> block {
1528-
let _icx = bcx.insn_ctxt("alt::trans_alt");
1529-
do with_scope(bcx, alt_expr.info(), ~"alt") |bcx| {
1530-
trans_alt_inner(bcx, discr_expr, arms, dest)
1528+
let _icx = bcx.insn_ctxt("match::trans_match");
1529+
do with_scope(bcx, match_expr.info(), ~"match") |bcx| {
1530+
trans_match_inner(bcx, discr_expr, arms, dest)
15311531
}
15321532
}
15331533
1534-
fn trans_alt_inner(scope_cx: block,
1534+
fn trans_match_inner(scope_cx: block,
15351535
discr_expr: @ast::expr,
15361536
arms: &[ast::arm],
15371537
dest: Dest) -> block {
1538-
let _icx = scope_cx.insn_ctxt("alt::trans_alt_inner");
1538+
let _icx = scope_cx.insn_ctxt("match::trans_match_inner");
15391539
let mut bcx = scope_cx;
15401540
let tcx = bcx.tcx();
15411541
@@ -1655,18 +1655,18 @@ enum IrrefutablePatternBindingMode {
16551655
BindArgument
16561656
}
16571657
1658-
// Not alt-related, but similar to the pattern-munging code above
1658+
// Not match-related, but similar to the pattern-munging code above
16591659
fn bind_irrefutable_pat(bcx: block,
16601660
pat: @ast::pat,
16611661
val: ValueRef,
16621662
make_copy: bool,
16631663
binding_mode: IrrefutablePatternBindingMode)
16641664
-> block {
1665-
let _icx = bcx.insn_ctxt("alt::bind_irrefutable_pat");
1665+
let _icx = bcx.insn_ctxt("match::bind_irrefutable_pat");
16661666
let ccx = bcx.fcx.ccx;
16671667
let mut bcx = bcx;
16681668

1669-
// Necessary since bind_irrefutable_pat is called outside trans_alt
1669+
// Necessary since bind_irrefutable_pat is called outside trans_match
16701670
match /*bad*/copy pat.node {
16711671
ast::pat_ident(_, _,inner) => {
16721672
if pat_is_variant_or_struct(bcx.tcx().def_map, pat) {

0 commit comments

Comments
 (0)