Skip to content

Rename identifiers that still use 'alt' to use 'match' #4388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 8, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ fn compile_upto(sess: Session, cfg: ast::crate_cfg,
time(time_passes, ~"mode computation", ||
middle::mode::compute_modes(ty_cx, method_map, crate));

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

let last_use_map =
time(time_passes, ~"liveness checking", ||
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/middle/borrowck/gather_loans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,19 +506,19 @@ impl gather_loan_ctxt {
discr_cmt: cmt,
root_pat: @ast::pat,
arm_id: ast::node_id,
alt_id: ast::node_id) {
match_id: ast::node_id) {
do self.bccx.cat_pattern(discr_cmt, root_pat) |cmt, pat| {
match pat.node {
ast::pat_ident(bm, _, _) if self.pat_is_binding(pat) => {
match bm {
ast::bind_by_value | ast::bind_by_move => {
// copying does not borrow anything, so no check
// is required
// as for move, check::alt ensures it's from an rvalue.
// as for move, check::_match ensures it's from an rvalue.
}
ast::bind_by_ref(mutbl) => {
// ref x or ref x @ p --- creates a ptr which must
// remain valid for the scope of the alt
// remain valid for the scope of the match

// find the region of the resulting pointer (note that
// the type of such a pattern will *always* be a
Expand All @@ -531,7 +531,7 @@ impl gather_loan_ctxt {
// of the function of this node in method preserve():
let arm_scope = ty::re_scope(arm_id);
if self.bccx.is_subregion_of(scope_r, arm_scope) {
let cmt_discr = self.bccx.cat_discr(cmt, alt_id);
let cmt_discr = self.bccx.cat_discr(cmt, match_id);
self.guarantee_valid(cmt_discr, mutbl, scope_r);
} else {
self.guarantee_valid(cmt, mutbl, scope_r);
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/borrowck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,8 @@ impl borrowck_ctxt {
cat_variant(self.tcx, self.method_map, arg, enum_did, cmt)
}

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

fn cat_pattern(cmt: cmt, pat: @ast::pat, op: fn(cmt, @ast::pat)) {
Expand Down
18 changes: 9 additions & 9 deletions src/librustc/middle/borrowck/preserve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,15 @@ priv impl &preserve_ctxt {
self.attempt_root(cmt, base, derefs)
}
}
cat_discr(base, alt_id) => {
// Subtle: in an alt, we must ensure that each binding
cat_discr(base, match_id) => {
// Subtle: in a match, we must ensure that each binding
// variable remains valid for the duration of the arm in
// which it appears, presuming that this arm is taken.
// But it is inconvenient in trans to root something just
// for one arm. Therefore, we insert a cat_discr(),
// basically a special kind of category that says "if this
// value must be dynamically rooted, root it for the scope
// `alt_id`.
// `match_id`.
//
// As an example, consider this scenario:
//
Expand All @@ -213,7 +213,7 @@ priv impl &preserve_ctxt {
// Technically, the value `x` need only be rooted
// in the `some` arm. However, we evaluate `x` in trans
// before we know what arm will be taken, so we just
// always root it for the duration of the alt.
// always root it for the duration of the match.
//
// As a second example, consider *this* scenario:
//
Expand All @@ -225,7 +225,7 @@ priv impl &preserve_ctxt {
// found only when checking which pattern matches: but
// this check is done before entering the arm. Therefore,
// even in this case we just choose to keep the value
// rooted for the entire alt. This means the value will be
// rooted for the entire match. This means the value will be
// rooted even if the none arm is taken. Oh well.
//
// At first, I tried to optimize the second case to only
Expand All @@ -247,12 +247,12 @@ priv impl &preserve_ctxt {
// Nonetheless, if you decide to optimize this case in the
// future, you need only adjust where the cat_discr()
// node appears to draw the line between what will be rooted
// in the *arm* vs the *alt*.
// in the *arm* vs the *match*.

let alt_rooting_ctxt =
preserve_ctxt({scope_region: ty::re_scope(alt_id),
let match_rooting_ctxt =
preserve_ctxt({scope_region: ty::re_scope(match_id),
.. **self});
(&alt_rooting_ctxt).preserve(base)
(&match_rooting_ctxt).preserve(base)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ use syntax::codemap::span;
use syntax::print::pprust::pat_to_str;
use syntax::visit;

struct AltCheckCtxt {
struct MatchCheckCtxt {
tcx: ty::ctxt,
method_map: method_map,
}

fn check_crate(tcx: ty::ctxt, method_map: method_map, crate: @crate) {
let cx = @AltCheckCtxt { tcx: tcx, method_map: method_map };
let cx = @MatchCheckCtxt { tcx: tcx, method_map: method_map };
visit::visit_crate(*crate, (), visit::mk_vt(@{
visit_expr: |a,b,c| check_expr(cx, a, b, c),
visit_local: |a,b,c| check_local(cx, a, b, c),
Expand All @@ -47,7 +47,7 @@ fn check_crate(tcx: ty::ctxt, method_map: method_map, crate: @crate) {
tcx.sess.abort_if_errors();
}

fn expr_is_non_moving_lvalue(cx: @AltCheckCtxt, expr: @expr) -> bool {
fn expr_is_non_moving_lvalue(cx: @MatchCheckCtxt, expr: @expr) -> bool {
if !ty::expr_is_lval(cx.tcx, cx.method_map, expr) {
return false;
}
Expand All @@ -61,7 +61,7 @@ fn expr_is_non_moving_lvalue(cx: @AltCheckCtxt, expr: @expr) -> bool {
}
}

fn check_expr(cx: @AltCheckCtxt, ex: @expr, &&s: (), v: visit::vt<()>) {
fn check_expr(cx: @MatchCheckCtxt, ex: @expr, &&s: (), v: visit::vt<()>) {
visit::visit_expr(ex, s, v);
match ex.node {
expr_match(scrut, ref arms) => {
Expand Down Expand Up @@ -107,7 +107,7 @@ fn check_expr(cx: @AltCheckCtxt, ex: @expr, &&s: (), v: visit::vt<()>) {
}

// Check for unreachable patterns
fn check_arms(cx: @AltCheckCtxt, arms: ~[arm]) {
fn check_arms(cx: @MatchCheckCtxt, arms: ~[arm]) {
let mut seen = ~[];
for arms.each |arm| {
for arm.pats.each |pat| {
Expand All @@ -130,7 +130,7 @@ fn raw_pat(p: @pat) -> @pat {
}
}

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

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

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

fn pat_ctor_id(cx: @AltCheckCtxt, p: @pat) -> Option<ctor> {
fn pat_ctor_id(cx: @MatchCheckCtxt, p: @pat) -> Option<ctor> {
let pat = raw_pat(p);
match /*bad*/copy pat.node {
pat_wild => { None }
Expand Down Expand Up @@ -337,7 +337,7 @@ fn pat_ctor_id(cx: @AltCheckCtxt, p: @pat) -> Option<ctor> {
}
}

fn is_wild(cx: @AltCheckCtxt, p: @pat) -> bool {
fn is_wild(cx: @MatchCheckCtxt, p: @pat) -> bool {
let pat = raw_pat(p);
match pat.node {
pat_wild => { true }
Expand All @@ -351,7 +351,7 @@ fn is_wild(cx: @AltCheckCtxt, p: @pat) -> bool {
}
}

fn missing_ctor(cx: @AltCheckCtxt,
fn missing_ctor(cx: @MatchCheckCtxt,
m: matrix,
left_ty: ty::t)
-> Option<ctor> {
Expand Down Expand Up @@ -451,7 +451,7 @@ fn missing_ctor(cx: @AltCheckCtxt,
}
}

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

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

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

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

fn check_fn(cx: @AltCheckCtxt,
fn check_fn(cx: @MatchCheckCtxt,
kind: visit::fn_kind,
decl: fn_decl,
body: blk,
Expand All @@ -674,7 +674,7 @@ fn check_fn(cx: @AltCheckCtxt,
}
}

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

// Legality of move bindings checking

fn check_legality_of_move_bindings(cx: @AltCheckCtxt,
fn check_legality_of_move_bindings(cx: @MatchCheckCtxt,
is_lvalue: bool,
has_guard: bool,
pats: &[@pat]) {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/const_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use syntax::ast::*;
// & and * pointers
// copies of general constants
//
// (in theory, probably not at first: if/alt on integer-const
// (in theory, probably not at first: if/match on integer-const
// conditions / descriminants)
//
// - Non-constants: everything else.
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/mem_categorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,7 @@ impl &mem_categorization_ctxt {
// local(x)->@->@
//
// where the id of `local(x)` is the id of the `x` that appears
// in the alt, the id of `local(x)->@` is the `@y` pattern,
// in the match, the id of `local(x)->@` is the `@y` pattern,
// and the id of `local(x)->@->@` is the id of the `y` pattern.


Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ struct ctxt {
// that when we visit it we can view it as a parent.
root_exprs: HashMap<ast::node_id, ()>,

// The parent scope is the innermost block, statement, call, or alt
// The parent scope is the innermost block, statement, call, or match
// expression during the execution of which the current expression
// will be evaluated. Generally speaking, the innermost parent
// scope is also the closest suitable ancestor in the AST tree.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ enum opt_result {
range_result(Result, Result),
}
fn trans_opt(bcx: block, o: &Opt) -> opt_result {
let _icx = bcx.insn_ctxt("alt::trans_opt");
let _icx = bcx.insn_ctxt("match::trans_opt");
let ccx = bcx.ccx();
let mut bcx = bcx;
match *o {
Expand Down Expand Up @@ -463,8 +463,8 @@ fn enter_default(bcx: block, dm: DefMap, m: &[@Match/&r],
}

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

Expand Down Expand Up @@ -1201,7 +1201,7 @@ fn compile_submatch(bcx: block,
For an empty match, a fall-through case must exist
*/
assert(m.len() > 0u || chk.is_some());
let _icx = bcx.insn_ctxt("alt::compile_submatch");
let _icx = bcx.insn_ctxt("match::compile_submatch");
let mut bcx = bcx;
let tcx = bcx.tcx(), dm = tcx.def_map;
if m.len() == 0u {
Expand Down Expand Up @@ -1520,22 +1520,22 @@ fn compile_submatch(bcx: block,
}
}

fn trans_alt(bcx: block,
alt_expr: @ast::expr,
fn trans_match(bcx: block,
match_expr: @ast::expr,
discr_expr: @ast::expr,
arms: ~[ast::arm],
dest: Dest) -> block {
let _icx = bcx.insn_ctxt("alt::trans_alt");
do with_scope(bcx, alt_expr.info(), ~"alt") |bcx| {
trans_alt_inner(bcx, discr_expr, arms, dest)
let _icx = bcx.insn_ctxt("match::trans_match");
do with_scope(bcx, match_expr.info(), ~"match") |bcx| {
trans_match_inner(bcx, discr_expr, arms, dest)
}
}

fn trans_alt_inner(scope_cx: block,
fn trans_match_inner(scope_cx: block,
discr_expr: @ast::expr,
arms: &[ast::arm],
dest: Dest) -> block {
let _icx = scope_cx.insn_ctxt("alt::trans_alt_inner");
let _icx = scope_cx.insn_ctxt("match::trans_match_inner");
let mut bcx = scope_cx;
let tcx = bcx.tcx();

Expand Down Expand Up @@ -1655,18 +1655,18 @@ enum IrrefutablePatternBindingMode {
BindArgument
}

// Not alt-related, but similar to the pattern-munging code above
// Not match-related, but similar to the pattern-munging code above
fn bind_irrefutable_pat(bcx: block,
pat: @ast::pat,
val: ValueRef,
make_copy: bool,
binding_mode: IrrefutablePatternBindingMode)
-> block {
let _icx = bcx.insn_ctxt("alt::bind_irrefutable_pat");
let _icx = bcx.insn_ctxt("match::bind_irrefutable_pat");
let ccx = bcx.fcx.ccx;
let mut bcx = bcx;

// Necessary since bind_irrefutable_pat is called outside trans_alt
// Necessary since bind_irrefutable_pat is called outside trans_match
match /*bad*/copy pat.node {
ast::pat_ident(_, _,inner) => {
if pat_is_variant_or_struct(bcx.tcx().def_map, pat) {
Expand Down
Loading