diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2012-02-15 11:25:39 -0800 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2012-02-15 13:26:11 -0800 |
| commit | bfff2a8d55f8d96df77c7e496dc7713fe7faf5f9 (patch) | |
| tree | 23c1e0515c6894f15bbd9c5b473f7f4e2653965d /src/comp/middle | |
| parent | dddd9908d537ce2858f37783779c3b88005ff0a8 (diff) | |
| download | rust-bfff2a8d55f8d96df77c7e496dc7713fe7faf5f9.tar.gz rust-bfff2a8d55f8d96df77c7e496dc7713fe7faf5f9.zip | |
make mut a keyword synonymous with mutable
first step towards issue #1273
Diffstat (limited to 'src/comp/middle')
| -rw-r--r-- | src/comp/middle/alias.rs | 88 | ||||
| -rw-r--r-- | src/comp/middle/debuginfo.rs | 8 | ||||
| -rw-r--r-- | src/comp/middle/kind.rs | 2 | ||||
| -rw-r--r-- | src/comp/middle/last_use.rs | 4 | ||||
| -rw-r--r-- | src/comp/middle/mutbl.rs (renamed from src/comp/middle/mut.rs) | 69 | ||||
| -rw-r--r-- | src/comp/middle/trans/base.rs | 10 | ||||
| -rw-r--r-- | src/comp/middle/trans/closure.rs | 4 | ||||
| -rw-r--r-- | src/comp/middle/trans/common.rs | 4 | ||||
| -rw-r--r-- | src/comp/middle/trans/shape.rs | 2 | ||||
| -rw-r--r-- | src/comp/middle/tstate/auxiliary.rs | 2 | ||||
| -rw-r--r-- | src/comp/middle/tstate/pre_post_conditions.rs | 2 | ||||
| -rw-r--r-- | src/comp/middle/ty.rs | 57 | ||||
| -rw-r--r-- | src/comp/middle/typeck.rs | 20 |
13 files changed, 142 insertions, 130 deletions
diff --git a/src/comp/middle/alias.rs b/src/comp/middle/alias.rs index 2ae8de9abcc..34caf927662 100644 --- a/src/comp/middle/alias.rs +++ b/src/comp/middle/alias.rs @@ -22,7 +22,7 @@ type invalid = {reason: invalid_reason, node_id: node_id, sp: span, path: @ast::path}; -enum unsafe_ty { contains(ty::t), mut_contains(ty::t), } +enum unsafe_ty { contains(ty::t), mutbl_contains(ty::t), } type binding = @{node_id: node_id, span: span, @@ -183,9 +183,9 @@ fn add_bindings_for_let(cx: ctx, &bs: [binding], loc: @ast::local) { err(cx, loc.span, "a reference binding can't be \ rooted in a temporary"); } - for proot in pattern_roots(cx.tcx, root.mut, loc.node.pat) { + for proot in pattern_roots(cx.tcx, root.mutbl, loc.node.pat) { let bnd = mk_binding(cx, proot.id, proot.span, root_var, - unsafe_set(proot.mut)); + unsafe_set(proot.mutbl)); // Don't implicitly copy explicit references bnd.copied = not_allowed; bs += [bnd]; @@ -228,7 +228,7 @@ fn check_call(cx: ctx, sc: scope, f: @ast::expr, args: [@ast::expr]) let arg = args[i]; let root = expr_root(cx, arg, false); alt ty::resolved_mode(cx.tcx, arg_t.mode) { - ast::by_mut_ref { + ast::by_mutbl_ref { alt path_def(cx, arg) { some(def) { let dnum = ast_util::def_id_of_def(def).node; @@ -242,14 +242,14 @@ fn check_call(cx: ctx, sc: scope, f: @ast::expr, args: [@ast::expr]) let root_var = path_def_id(cx, root.ex); let arg_copied = alt ty::resolved_mode(cx.tcx, arg_t.mode) { ast::by_move | ast::by_copy { copied } - ast::by_mut_ref { not_allowed } + ast::by_mutbl_ref { not_allowed } ast::by_ref | ast::by_val { not_copied } }; bindings += [@{node_id: arg.id, span: arg.span, root_var: root_var, local_id: 0u, - unsafe_tys: unsafe_set(root.mut), + unsafe_tys: unsafe_set(root.mutbl), mutable copied: arg_copied}]; i += 1u; } @@ -285,7 +285,7 @@ fn check_call(cx: ctx, sc: scope, f: @ast::expr, args: [@ast::expr]) let i = 0u; for arg_t: ty::arg in arg_ts { let mut_alias = - (ast::by_mut_ref == ty::arg_mode(cx.tcx, arg_t)); + (ast::by_mutbl_ref == ty::arg_mode(cx.tcx, arg_t)); if i != j && ty_can_unsafely_include(cx, unsafe_ty, arg_t.ty, mut_alias) && @@ -339,14 +339,14 @@ fn check_alt(cx: ctx, input: @ast::expr, arms: [ast::arm], sc: scope, span: span}; let binding_info: [info] = []; for pat in a.pats { - for proot in pattern_roots(cx.tcx, root.mut, pat) { + for proot in pattern_roots(cx.tcx, root.mutbl, pat) { let canon_id = pat_id_map.get(proot.name); alt vec::find(binding_info, {|x| x.id == canon_id}) { - some(s) { s.unsafe_tys += unsafe_set(proot.mut); } + some(s) { s.unsafe_tys += unsafe_set(proot.mutbl); } none { binding_info += [ {id: canon_id, - mutable unsafe_tys: unsafe_set(proot.mut), + mutable unsafe_tys: unsafe_set(proot.mutbl), span: proot.span}]; } } @@ -369,20 +369,20 @@ fn check_for(cx: ctx, local: @ast::local, seq: @ast::expr, blk: ast::blk, // If this is a mutable vector, don't allow it to be touched. let seq_t = ty::expr_ty(cx.tcx, seq); - let cur_mut = root.mut; + let cur_mutbl = root.mutbl; alt ty::get(seq_t).struct { ty::ty_vec(mt) { - if mt.mut != ast::imm { - cur_mut = some(contains(seq_t)); + if mt.mutbl != ast::m_imm { + cur_mutbl = some(contains(seq_t)); } } _ {} } let root_var = path_def_id(cx, root.ex); let new_bs = sc.bs; - for proot in pattern_roots(cx.tcx, cur_mut, local.node.pat) { + for proot in pattern_roots(cx.tcx, cur_mutbl, local.node.pat) { new_bs += [mk_binding(cx, proot.id, proot.span, root_var, - unsafe_set(proot.mut))]; + unsafe_set(proot.mutbl))]; } visit::visit_block(blk, {bs: new_bs with sc}, v); } @@ -493,36 +493,36 @@ fn path_def_id(cx: ctx, ex: @ast::expr) -> option<ast::node_id> { } fn ty_can_unsafely_include(cx: ctx, needle: unsafe_ty, haystack: ty::t, - mut: bool) -> bool { - fn get_mut(cur: bool, mt: ty::mt) -> bool { - ret cur || mt.mut != ast::imm; + mutbl: bool) -> bool { + fn get_mutbl(cur: bool, mt: ty::mt) -> bool { + ret cur || mt.mutbl != ast::m_imm; } - fn helper(tcx: ty::ctxt, needle: unsafe_ty, haystack: ty::t, mut: bool) + fn helper(tcx: ty::ctxt, needle: unsafe_ty, haystack: ty::t, mutbl: bool) -> bool { if alt needle { contains(ty) { ty == haystack } - mut_contains(ty) { mut && ty == haystack } + mutbl_contains(ty) { mutbl && ty == haystack } } { ret true; } alt ty::get(haystack).struct { ty::ty_enum(_, ts) { for t: ty::t in ts { - if helper(tcx, needle, t, mut) { ret true; } + if helper(tcx, needle, t, mutbl) { ret true; } } ret false; } ty::ty_box(mt) | ty::ty_ptr(mt) | ty::ty_uniq(mt) { - ret helper(tcx, needle, mt.ty, get_mut(mut, mt)); + ret helper(tcx, needle, mt.ty, get_mutbl(mutbl, mt)); } ty::ty_rec(fields) { for f: ty::field in fields { - if helper(tcx, needle, f.mt.ty, get_mut(mut, f.mt)) { + if helper(tcx, needle, f.mt.ty, get_mutbl(mutbl, f.mt)) { ret true; } } ret false; } ty::ty_tup(ts) { - for t in ts { if helper(tcx, needle, t, mut) { ret true; } } + for t in ts { if helper(tcx, needle, t, mutbl) { ret true; } } ret false; } ty::ty_fn({proto: ast::proto_bare, _}) { ret false; } @@ -532,11 +532,11 @@ fn ty_can_unsafely_include(cx: ctx, needle: unsafe_ty, haystack: ty::t, // treated as opaque downstream, and is thus safe unless we // saw mutable fields, in which case the whole thing can be // overwritten. - ty::ty_param(_, _) { ret mut; } + ty::ty_param(_, _) { ret mutbl; } _ { ret false; } } } - ret helper(cx.tcx, needle, haystack, mut); + ret helper(cx.tcx, needle, haystack, mutbl); } fn def_is_local(d: ast::def) -> bool { @@ -589,66 +589,66 @@ fn copy_is_expensive(tcx: ty::ctxt, ty: ty::t) -> bool { type pattern_root = {id: node_id, name: ident, - mut: option<unsafe_ty>, + mutbl: option<unsafe_ty>, span: span}; -fn pattern_roots(tcx: ty::ctxt, mut: option<unsafe_ty>, pat: @ast::pat) +fn pattern_roots(tcx: ty::ctxt, mutbl: option<unsafe_ty>, pat: @ast::pat) -> [pattern_root] { - fn walk(tcx: ty::ctxt, mut: option<unsafe_ty>, pat: @ast::pat, + fn walk(tcx: ty::ctxt, mutbl: option<unsafe_ty>, pat: @ast::pat, &set: [pattern_root]) { alt normalize_pat(tcx, pat).node { ast::pat_wild | ast::pat_lit(_) | ast::pat_range(_, _) {} ast::pat_ident(nm, sub) { - set += [{id: pat.id, name: path_to_ident(nm), mut: mut, + set += [{id: pat.id, name: path_to_ident(nm), mutbl: mutbl, span: pat.span}]; - alt sub { some(p) { walk(tcx, mut, p, set); } _ {} } + alt sub { some(p) { walk(tcx, mutbl, p, set); } _ {} } } ast::pat_enum(_, ps) | ast::pat_tup(ps) { - for p in ps { walk(tcx, mut, p, set); } + for p in ps { walk(tcx, mutbl, p, set); } } ast::pat_rec(fs, _) { let ty = ty::node_id_to_type(tcx, pat.id); for f in fs { - let m = ty::get_field(ty, f.ident).mt.mut != ast::imm, - c = if m { some(contains(ty)) } else { mut }; + let m = ty::get_field(ty, f.ident).mt.mutbl != ast::m_imm, + c = if m { some(contains(ty)) } else { mutbl }; walk(tcx, c, f.pat, set); } } ast::pat_box(p) { let ty = ty::node_id_to_type(tcx, pat.id); let m = alt ty::get(ty).struct { - ty::ty_box(mt) { mt.mut != ast::imm } + ty::ty_box(mt) { mt.mutbl != ast::m_imm } _ { tcx.sess.span_bug(pat.span, "box pat has non-box type"); } }, - c = if m {some(contains(ty)) } else { mut }; + c = if m {some(contains(ty)) } else { mutbl }; walk(tcx, c, p, set); } ast::pat_uniq(p) { let ty = ty::node_id_to_type(tcx, pat.id); let m = alt ty::get(ty).struct { - ty::ty_uniq(mt) { mt.mut != ast::imm } + ty::ty_uniq(mt) { mt.mutbl != ast::m_imm } _ { tcx.sess.span_bug(pat.span, "uniq pat has non-uniq type"); } }, - c = if m { some(contains(ty)) } else { mut }; + c = if m { some(contains(ty)) } else { mutbl }; walk(tcx, c, p, set); } } } let set = []; - walk(tcx, mut, pat, set); + walk(tcx, mutbl, pat, set); ret set; } -// Wraps the expr_root in mut.rs to also handle roots that exist through +// Wraps the expr_root in mutbl.rs to also handle roots that exist through // return-by-reference fn expr_root(cx: ctx, ex: @ast::expr, autoderef: bool) - -> {ex: @ast::expr, mut: option<unsafe_ty>} { - let base_root = mut::expr_root(cx.tcx, ex, autoderef); + -> {ex: @ast::expr, mutbl: option<unsafe_ty>} { + let base_root = mutbl::expr_root(cx.tcx, ex, autoderef); let unsafe_ty = none; for d in *base_root.ds { - if d.mut { unsafe_ty = some(contains(d.outer_t)); break; } + if d.mutbl { unsafe_ty = some(contains(d.outer_t)); break; } } - ret {ex: base_root.ex, mut: unsafe_ty}; + ret {ex: base_root.ex, mutbl: unsafe_ty}; } fn unsafe_set(from: option<unsafe_ty>) -> [unsafe_ty] { diff --git a/src/comp/middle/debuginfo.rs b/src/comp/middle/debuginfo.rs index d23fa4f5e8c..1349a43e7e0 100644 --- a/src/comp/middle/debuginfo.rs +++ b/src/comp/middle/debuginfo.rs @@ -587,21 +587,21 @@ fn create_ty(_cx: @crate_ctxt, _t: ty::t, _ty: @ast::ty) ty::ty_float(t) { ast::ty_float(t) } ty::ty_uint(t) { ast::ty_uint(t) } ty::ty_box(mt) { ast::ty_box({ty: t_to_ty(cx, mt.ty, span), - mut: mt.mut}) } + mutbl: mt.mutbl}) } ty::ty_uniq(mt) { ast::ty_uniq({ty: t_to_ty(cx, mt.ty, span), - mut: mt.mut}) } + mutbl: mt.mutbl}) } ty::ty_rec(fields) { let fs = []; for field in fields { fs += [{node: {ident: field.ident, mt: {ty: t_to_ty(cx, field.mt.ty, span), - mut: field.mt.mut}}, + mutbl: field.mt.mutbl}}, span: span}]; } ast::ty_rec(fs) } ty::ty_vec(mt) { ast::ty_vec({ty: t_to_ty(cx, mt.ty, span), - mut: mt.mut}) } + mutbl: mt.mutbl}) } _ { cx.tcx.sess.span_bug(span, "t_to_ty: Can't handle this type"); } diff --git a/src/comp/middle/kind.rs b/src/comp/middle/kind.rs index 9a97fb71060..8c12807ae43 100644 --- a/src/comp/middle/kind.rs +++ b/src/comp/middle/kind.rs @@ -167,7 +167,7 @@ fn check_expr(e: @expr, cx: ctx, v: visit::vt<ctx>) { for arg_t in ty::ty_fn_args(ty::expr_ty(cx.tcx, f)) { alt ty::arg_mode(cx.tcx, arg_t) { by_copy { maybe_copy(cx, args[i]); } - by_ref | by_val | by_mut_ref | by_move { } + by_ref | by_val | by_mutbl_ref | by_move { } } i += 1u; } diff --git a/src/comp/middle/last_use.rs b/src/comp/middle/last_use.rs index a0e8388e824..69166d3ba7f 100644 --- a/src/comp/middle/last_use.rs +++ b/src/comp/middle/last_use.rs @@ -156,7 +156,7 @@ fn visit_expr(ex: @expr, cx: ctx, v: visit::vt<ctx>) { } _ { alt ty::arg_mode(cx.tcx, arg_ts[i]) { - by_mut_ref { clear_if_path(cx, arg, v, false); } + by_mutbl_ref { clear_if_path(cx, arg, v, false); } _ { v.visit_expr(arg, cx, v); } } } @@ -299,7 +299,7 @@ fn clear_def_if_path(cx: ctx, d: def, to: bool) clear_in_current(cx, def_id.node, to); some(def_id.node) } - by_ref | by_val | by_mut_ref { + by_ref | by_val | by_mutbl_ref { none } } diff --git a/src/comp/middle/mut.rs b/src/comp/middle/mutbl.rs index cf3388c7f40..7ba837f8231 100644 --- a/src/comp/middle/mut.rs +++ b/src/comp/middle/mutbl.rs @@ -5,7 +5,7 @@ import driver::session::session; enum deref_t { unbox(bool), field, index, } -type deref = @{mut: bool, kind: deref_t, outer_t: ty::t}; +type deref = @{mutbl: bool, kind: deref_t, outer_t: ty::t}; // Finds the root (the thing that is dereferenced) for the given expr, and a // vec of dereferences that were used on this root. Note that, in this vec, @@ -18,15 +18,19 @@ fn expr_root(tcx: ty::ctxt, ex: @expr, autoderef: bool) -> while true { alt ty::get(t).struct { ty::ty_box(mt) { - ds += [@{mut: mt.mut == mut, kind: unbox(false), outer_t: t}]; + ds += [@{mutbl: mt.mutbl == m_mutbl, + kind: unbox(false), + outer_t: t}]; t = mt.ty; } ty::ty_uniq(mt) { - ds += [@{mut: mt.mut == mut, kind: unbox(false), outer_t: t}]; + ds += [@{mutbl: mt.mutbl == m_mutbl, + kind: unbox(false), + outer_t: t}]; t = mt.ty; } ty::ty_res(_, inner, tps) { - ds += [@{mut: false, kind: unbox(false), outer_t: t}]; + ds += [@{mutbl: false, kind: unbox(false), outer_t: t}]; t = ty::substitute_type_params(tcx, tps, inner); } ty::ty_enum(did, tps) { @@ -35,7 +39,7 @@ fn expr_root(tcx: ty::ctxt, ex: @expr, autoderef: bool) -> vec::len(variants[0].args) != 1u { break; } - ds += [@{mut: false, kind: unbox(false), outer_t: t}]; + ds += [@{mutbl: false, kind: unbox(false), outer_t: t}]; t = ty::substitute_type_params(tcx, tps, variants[0].args[0]); } _ { break; } @@ -48,19 +52,19 @@ fn expr_root(tcx: ty::ctxt, ex: @expr, autoderef: bool) -> alt copy ex.node { expr_field(base, ident, _) { let auto_unbox = maybe_auto_unbox(tcx, ty::expr_ty(tcx, base)); - let is_mut = false; + let is_mutbl = false; alt ty::get(auto_unbox.t).struct { ty::ty_rec(fields) { for fld: ty::field in fields { if str::eq(ident, fld.ident) { - is_mut = fld.mt.mut == mut; + is_mutbl = fld.mt.mutbl == m_mutbl; break; } } } _ {} } - ds += [@{mut: is_mut, kind: field, outer_t: auto_unbox.t}]; + ds += [@{mutbl: is_mutbl, kind: field, outer_t: auto_unbox.t}]; ds += auto_unbox.ds; ex = base; } @@ -69,12 +73,12 @@ fn expr_root(tcx: ty::ctxt, ex: @expr, autoderef: bool) -> alt ty::get(auto_unbox.t).struct { ty::ty_vec(mt) { ds += - [@{mut: mt.mut == mut, + [@{mutbl: mt.mutbl == m_mutbl, kind: index, outer_t: auto_unbox.t}]; } ty::ty_str { - ds += [@{mut: false, kind: index, outer_t: auto_unbox.t}]; + ds += [@{mutbl: false, kind: index, outer_t: auto_unbox.t}]; } _ { break; } } @@ -84,17 +88,20 @@ fn expr_root(tcx: ty::ctxt, ex: @expr, autoderef: bool) -> expr_unary(op, base) { if op == deref { let base_t = ty::expr_ty(tcx, base); - let is_mut = false, ptr = false; + let is_mutbl = false, ptr = false; alt ty::get(base_t).struct { - ty::ty_box(mt) { is_mut = mt.mut == mut; } - ty::ty_uniq(mt) { is_mut = mt.mut == mut; } + ty::ty_box(mt) { is_mutbl = mt.mutbl == m_mutbl; } + ty::ty_uniq(mt) { is_mutbl = mt.mutbl == m_mutbl; } ty::ty_res(_, _, _) { } ty::ty_enum(_, _) { } - ty::ty_ptr(mt) { is_mut = mt.mut == mut; ptr = true; } + ty::ty_ptr(mt) { + is_mutbl = mt.mutbl == m_mutbl; + ptr = true; + } _ { tcx.sess.span_bug(base.span, "Ill-typed base \ expression in deref"); } } - ds += [@{mut: is_mut, kind: unbox(ptr && is_mut), + ds += [@{mutbl: is_mutbl, kind: unbox(ptr && is_mutbl), outer_t: base_t}]; ex = base; } else { break; } @@ -109,27 +116,27 @@ fn expr_root(tcx: ty::ctxt, ex: @expr, autoderef: bool) -> ret {ex: ex, ds: @ds}; } -// Actual mut-checking pass +// Actual mutbl-checking pass -type mut_map = std::map::hashmap<node_id, ()>; -type ctx = {tcx: ty::ctxt, mut_map: mut_map}; +type mutbl_map = std::map::hashmap<node_id, ()>; +type ctx = {tcx: ty::ctxt, mutbl_map: mutbl_map}; -fn check_crate(tcx: ty::ctxt, crate: @crate) -> mut_map { - let cx = @{tcx: tcx, mut_map: std::map::new_int_hash()}; +fn check_crate(tcx: ty::ctxt, crate: @crate) -> mutbl_map { + let cx = @{tcx: tcx, mutbl_map: std::map::new_int_hash()}; let v = @{visit_expr: bind visit_expr(cx, _, _, _), visit_decl: bind visit_decl(cx, _, _, _) with *visit::default_visitor()}; visit::visit_crate(*crate, (), visit::mk_vt(v)); - ret cx.mut_map; + ret cx.mutbl_map; } -enum msg { msg_assign, msg_move_out, msg_mut_ref, } +enum msg { msg_assign, msg_move_out, msg_mutbl_ref, } fn mk_err(cx: @ctx, span: syntax::codemap::span, msg: msg, name: str) { cx.tcx.sess.span_err(span, alt msg { msg_assign { "assigning to " + name } msg_move_out { "moving out of " + name } - msg_mut_ref { "passing " + name + " by mutable reference" } + msg_mutbl_ref { "passing " + name + " by mutable reference" } }); } @@ -178,7 +185,7 @@ fn check_lval(cx: @ctx, dest: @expr, msg: msg) { some(name) { mk_err(cx, dest.span, msg, name); } _ { } } - cx.mut_map.insert(ast_util::def_id_of_def(def).node, ()); + cx.mutbl_map.insert(ast_util::def_id_of_def(def).node, ()); } _ { let root = expr_root(cx.tcx, dest, false); @@ -186,12 +193,12 @@ fn check_lval(cx: @ctx, dest: @expr, msg: msg) { if msg != msg_move_out { mk_err(cx, dest.span, msg, "non-lvalue"); } - } else if !root.ds[0].mut { + } else if !root.ds[0].mutbl { let name = alt root.ds[0].kind { - mut::unbox(_) { "immutable box" } - mut::field { "immutable field" } - mut::index { "immutable vec content" } + mutbl::unbox(_) { "immutable box" } + mutbl::field { "immutable field" } + mutbl::index { "immutable vec content" } }; mk_err(cx, dest.span, msg, name); } @@ -227,7 +234,7 @@ fn check_call(cx: @ctx, f: @expr, args: [@expr]) { let i = 0u; for arg_t: ty::arg in arg_ts { alt ty::resolved_mode(cx.tcx, arg_t.mode) { - by_mut_ref { check_lval(cx, args[i], msg_mut_ref); } + by_mutbl_ref { check_lval(cx, args[i], msg_mutbl_ref); } by_move { check_lval(cx, args[i], msg_move_out); } by_ref | by_val | by_copy { } } @@ -242,7 +249,7 @@ fn check_bind(cx: @ctx, f: @expr, args: [option<@expr>]) { alt arg { some(expr) { let o_msg = alt ty::resolved_mode(cx.tcx, arg_ts[i].mode) { - by_mut_ref { some("by mutable reference") } + by_mutbl_ref { some("by mutable reference") } by_move { some("by move") } _ { none } }; @@ -269,7 +276,7 @@ fn is_immutable_def(cx: @ctx, def: def) -> option<str> { def_arg(_, m) { alt ty::resolved_mode(cx.tcx, m) { by_ref | by_val { some("argument") } - by_mut_ref | by_move | by_copy { none } + by_mutbl_ref | by_move | by_copy { none } } } def_self(_) { some("self argument") } diff --git a/src/comp/middle/trans/base.rs b/src/comp/middle/trans/base.rs index 799eadcf69a..3b8bde61cb8 100644 --- a/src/comp/middle/trans/base.rs +++ b/src/comp/middle/trans/base.rs @@ -3987,7 +3987,7 @@ fn alloc_local(cx: @block_ctxt, local: @ast::local) -> @block_ctxt { }; // Do not allocate space for locals that can be kept immediate. let ccx = bcx_ccx(cx); - if is_simple && !ccx.mut_map.contains_key(local.node.pat.id) && + if is_simple && !ccx.mutbl_map.contains_key(local.node.pat.id) && !ccx.last_uses.contains_key(local.node.pat.id) && ty::type_is_immediate(t) { alt local.node.init { @@ -4166,7 +4166,7 @@ fn copy_args_to_allocas(fcx: @fn_ctxt, bcx: @block_ctxt, args: [ast::arg], let argval = alt fcx.llargs.get(id) { local_mem(v) { v } _ { epic_fail() } }; alt ty::resolved_mode(tcx, arg.mode) { - ast::by_mut_ref { } + ast::by_mutbl_ref { } ast::by_move | ast::by_copy { add_clean(bcx, argval, arg.ty); } ast::by_val { if !ty::type_is_immediate(arg.ty) { @@ -4598,7 +4598,7 @@ fn create_main_wrapper(ccx: @crate_ctxt, sp: span, main_llfn: ValueRef, let unit_ty = ty::mk_str(ccx.tcx); let vecarg_ty: ty::arg = {mode: ast::expl(ast::by_val), - ty: ty::mk_vec(ccx.tcx, {ty: unit_ty, mut: ast::imm})}; + ty: ty::mk_vec(ccx.tcx, {ty: unit_ty, mutbl: ast::m_imm})}; // FIXME: mk_nil should have a postcondition let nt = ty::mk_nil(ccx.tcx); let llfty = type_of_fn(ccx, [vecarg_ty], nt, []); @@ -5003,7 +5003,7 @@ fn write_abi_version(ccx: @crate_ctxt) { fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt, output: str, emap: resolve::exp_map, amap: ast_map::map, - mut_map: mut::mut_map, copy_map: alias::copy_map, + mutbl_map: mutbl::mutbl_map, copy_map: alias::copy_map, last_uses: last_use::last_uses, impl_map: resolve::impl_map, method_map: typeck::method_map, dict_map: typeck::dict_map) -> (ModuleRef, link::link_meta) { @@ -5080,7 +5080,7 @@ fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt, type_sha1s: ty::new_ty_hash(), type_short_names: ty::new_ty_hash(), tcx: tcx, - mut_map: mut_map, + mutbl_map: mutbl_map, copy_map: copy_map, last_uses: last_uses, impl_map: impl_map, diff --git a/src/comp/middle/trans/closure.rs b/src/comp/middle/trans/closure.rs index 45e4bfadcbe..b6ef093d534 100644 --- a/src/comp/middle/trans/closure.rs +++ b/src/comp/middle/trans/closure.rs @@ -276,7 +276,7 @@ fn store_environment( // tuple. This could be a ptr in uniq or a box or on stack, // whatever. let cbox_ty = tuplify_box_ty(tcx, cdata_ty); - let cboxptr_ty = ty::mk_ptr(tcx, {ty:cbox_ty, mut:ast::imm}); + let cboxptr_ty = ty::mk_ptr(tcx, {ty:cbox_ty, mutbl:ast::m_imm}); let llbox = cast_if_we_can(bcx, llbox, cboxptr_ty); // If necessary, copy tydescs describing type parameters into the @@ -905,7 +905,7 @@ fn trans_bind_thunk(ccx: @crate_ctxt, bcx = take_ty(bcx, alloc, out_arg.ty); val = alloc; } - ast::by_ref | ast::by_mut_ref | ast::by_move { } + ast::by_ref | ast::by_mutbl_ref | ast::by_move { } } // If the type is parameterized, then we need to cast the diff --git a/src/comp/middle/trans/common.rs b/src/comp/middle/trans/common.rs index d39759ad211..6398928e066 100644 --- a/src/comp/middle/trans/common.rs +++ b/src/comp/middle/trans/common.rs @@ -104,7 +104,7 @@ type crate_ctxt = type_sha1s: hashmap<ty::t, str>, type_short_names: hashmap<ty::t, str>, tcx: ty::ctxt, - mut_map: mut::mut_map, + mutbl_map: mutbl::mutbl_map, copy_map: alias::copy_map, last_uses: last_use::last_uses, impl_map: resolve::impl_map, @@ -622,7 +622,7 @@ fn tuplify_box_ty(tcx: ty::ctxt, t: ty::t) -> ty::t { // descr is embedded in the box (ty::type vs ty::send_type). This is useful // for unique closure boxes, hence the name "cbox_ty" (closure box type). fn tuplify_cbox_ty(tcx: ty::ctxt, t: ty::t, tydesc_t: ty::t) -> ty::t { - let ptr = ty::mk_ptr(tcx, {ty: ty::mk_nil(tcx), mut: ast::imm}); + let ptr = ty::mk_ptr(tcx, {ty: ty::mk_nil(tcx), mutbl: ast::m_imm}); ret ty::mk_tup(tcx, [ty::mk_uint(tcx), tydesc_t, ptr, ptr, t]); diff --git a/src/comp/middle/trans/shape.rs b/src/comp/middle/trans/shape.rs index 2ab8990ff98..2a4a2d423e2 100644 --- a/src/comp/middle/trans/shape.rs +++ b/src/comp/middle/trans/shape.rs @@ -782,7 +782,7 @@ fn dynamic_metrics(cx: @block_ctxt, t: ty::t) -> metrics { // nominal type that has pointers to itself in it. fn simplify_type(tcx: ty::ctxt, typ: ty::t) -> ty::t { fn nilptr(tcx: ty::ctxt) -> ty::t { - ty::mk_ptr(tcx, {ty: ty::mk_nil(tcx), mut: ast::imm}) + ty::mk_ptr(tcx, {ty: ty::mk_nil(tcx), mutbl: ast::m_imm}) } fn simplifier(tcx: ty::ctxt, typ: ty::t) -> ty::t { alt ty::get(typ).struct { diff --git a/src/comp/middle/tstate/auxiliary.rs b/src/comp/middle/tstate/auxiliary.rs index e6884d129fb..cd0cd7e11c3 100644 --- a/src/comp/middle/tstate/auxiliary.rs +++ b/src/comp/middle/tstate/auxiliary.rs @@ -1089,7 +1089,7 @@ fn callee_arg_init_ops(fcx: fn_ctxt, callee: node_id) -> [init_op] { vec::map(callee_modes(fcx, callee)) {|m| alt ty::resolved_mode(fcx.ccx.tcx, m) { by_move { init_move } - by_copy | by_ref | by_val | by_mut_ref { init_assign } + by_copy | by_ref | by_val | by_mutbl_ref { init_assign } } } } diff --git a/src/comp/middle/tstate/pre_post_conditions.rs b/src/comp/middle/tstate/pre_post_conditions.rs index a3fee3a5a75..326c768cabe 100644 --- a/src/comp/middle/tstate/pre_post_conditions.rs +++ b/src/comp/middle/tstate/pre_post_conditions.rs @@ -275,7 +275,7 @@ fn forget_args_moved_in(fcx: fn_ctxt, parent: @expr, modes: [mode], vec::iteri(modes) {|i,mode| alt ty::resolved_mode(fcx.ccx.tcx, mode) { by_move { forget_in_postcond(fcx, parent.id, operands[i].id); } - by_ref | by_val | by_mut_ref | by_copy { } + by_ref | by_val | by_mutbl_ref | by_copy { } } } } diff --git a/src/comp/middle/ty.rs b/src/comp/middle/ty.rs index e5f8fa26ee7..06823f4aa30 100644 --- a/src/comp/middle/ty.rs +++ b/src/comp/middle/ty.rs @@ -147,7 +147,7 @@ type method = {ident: ast::ident, type constr_table = hashmap<ast::node_id, [constr]>; -type mt = {ty: t, mut: ast::mutability}; +type mt = {ty: t, mutbl: ast::mutability}; // Contains information needed to resolve types and (in the future) look up @@ -423,15 +423,18 @@ fn mk_enum(cx: ctxt, did: ast::def_id, tys: [t]) -> t { fn mk_box(cx: ctxt, tm: mt) -> t { mk_t(cx, ty_box(tm)) } -fn mk_imm_box(cx: ctxt, ty: t) -> t { mk_box(cx, {ty: ty, mut: ast::imm}) } +fn mk_imm_box(cx: ctxt, ty: t) -> t { mk_box(cx, {ty: ty, + mutbl: ast::m_imm}) } fn mk_uniq(cx: ctxt, tm: mt) -> t { mk_t(cx, ty_uniq(tm)) } -fn mk_imm_uniq(cx: ctxt, ty: t) -> t { mk_uniq(cx, {ty: ty, mut: ast::imm}) } +fn mk_imm_uniq(cx: ctxt, ty: t) -> t { mk_uniq(cx, {ty: ty, + mutbl: ast::m_imm}) } fn mk_ptr(cx: ctxt, tm: mt) -> t { mk_t(cx, ty_ptr(tm)) } -fn mk_mut_ptr(cx: ctxt, ty: t) -> t { mk_ptr(cx, {ty: ty, mut: ast::mut}) } +fn mk_mut_ptr(cx: ctxt, ty: t) -> t { mk_ptr(cx, {ty: ty, + mutbl: ast::m_mutbl}) } fn mk_vec(cx: ctxt, tm: mt) -> t { mk_t(cx, ty_vec(tm)) } @@ -541,16 +544,16 @@ fn fold_ty(cx: ctxt, fld: fold_mode, ty_0: t) -> t { ty_str | ty_type | ty_send_type | ty_opaque_closure_ptr(_) | ty_opaque_box {} ty_box(tm) { - ty = mk_box(cx, {ty: fold_ty(cx, fld, tm.ty), mut: tm.mut}); + ty = mk_box(cx, {ty: fold_ty(cx, fld, tm.ty), mutbl: tm.mutbl}); } ty_uniq(tm) { - ty = mk_uniq(cx, {ty: fold_ty(cx, fld, tm.ty), mut: tm.mut}); + ty = mk_uniq(cx, {ty: fold_ty(cx, fld, tm.ty), mutbl: tm.mutbl}); } ty_ptr(tm) { - ty = mk_ptr(cx, {ty: fold_ty(cx, fld, tm.ty), mut: tm.mut}); + ty = mk_ptr(cx, {ty: fold_ty(cx, fld, tm.ty), mutbl: tm.mutbl}); } ty_vec(tm) { - ty = mk_vec(cx, {ty: fold_ty(cx, fld, tm.ty), mut: tm.mut}); + ty = mk_vec(cx, {ty: fold_ty(cx, fld, tm.ty), mutbl: tm.mutbl}); } ty_enum(tid, subtys) { ty = mk_enum(cx, tid, vec::map(subtys, {|t| fold_ty(cx, fld, t) })); @@ -565,7 +568,7 @@ fn fold_ty(cx: ctxt, fld: fold_mode, ty_0: t) -> t { let new_fields: [field] = []; for fl: field in fields { let new_ty = fold_ty(cx, fld, fl.mt.ty); - let new_mt = {ty: new_ty, mut: fl.mt.mut}; + let new_mt = {ty: new_ty, mutbl: fl.mt.mutbl}; new_fields += [{ident: fl.ident, mt: new_mt}]; } ty = mk_rec(cx, new_fields); @@ -922,12 +925,11 @@ fn type_allows_implicit_copy(cx: ctxt, ty: t) -> bool { alt sty { ty_param(_, _) { true } ty_vec(mt) { - mt.mut != ast::imm + mt.mutbl != ast::m_imm } ty_rec(fields) { for field in fields { - if field.mt.mut != - ast::imm { + if field.mt.mutbl != ast::m_imm { ret true; } } @@ -1665,7 +1667,7 @@ mod unify { // If you're unifying on something mutable then we have to // be invariant on the inner type let newvariance = alt expected { - ast::mut { + ast::m_mutbl { variance_transform(variance, invariant) } _ { @@ -1675,11 +1677,11 @@ mod unify { if expected == actual { ret some((expected, newvariance)); } if variance == covariant { - if expected == ast::maybe_mut { + if expected == ast::m_const { ret some((actual, newvariance)); } } else if variance == contravariant { - if actual == ast::maybe_mut { + if actual == ast::m_const { ret some((expected, newvariance)); } } @@ -1960,7 +1962,7 @@ mod unify { alt get(actual).struct { ty_box(actual_mt) { let (mutt, var) = alt unify_mut( - expected_mt.mut, actual_mt.mut, variance) { + expected_mt.mutbl, actual_mt.mutbl, variance) { none { ret ures_err(terr_box_mutability); } some(mv) { mv } }; @@ -1968,7 +1970,7 @@ mod unify { cx, expected_mt.ty, actual_mt.ty, var); alt result { ures_ok(result_sub) { - let mt = {ty: result_sub, mut: mutt}; + let mt = {ty: result_sub, mutbl: mutt}; ret ures_ok(mk_box(cx.tcx, mt)); } _ { ret result; } @@ -1981,7 +1983,7 @@ mod unify { alt get(actual).struct { ty_uniq(actual_mt) { let (mutt, var) = alt unify_mut( - expected_mt.mut, actual_mt.mut, variance) { + expected_mt.mutbl, actual_mt.mutbl, variance) { none { ret ures_err(terr_box_mutability); } some(mv) { mv } }; @@ -1989,7 +1991,7 @@ mod unify { cx, expected_mt.ty, actual_mt.ty, var); alt result { ures_ok(result_mt) { - let mt = {ty: result_mt, mut: mutt}; + let mt = {ty: result_mt, mutbl: mutt}; ret ures_ok(mk_uniq(cx.tcx, mt)); } _ { ret result; } @@ -2002,7 +2004,7 @@ mod unify { alt get(actual).struct { ty_vec(actual_mt) { let (mutt, var) = alt unify_mut( - expected_mt.mut, actual_mt.mut, variance) { + expected_mt.mutbl, actual_mt.mutbl, variance) { none { ret ures_err(terr_vec_mutability); } some(mv) { mv } }; @@ -2010,7 +2012,7 @@ mod unify { cx, expected_mt.ty, actual_mt.ty, var); alt result { ures_ok(result_sub) { - let mt = {ty: result_sub, mut: mutt}; + let mt = {ty: result_sub, mutbl: mutt}; ret ures_ok(mk_vec(cx.tcx, mt)); } _ { ret result; } @@ -2023,7 +2025,7 @@ mod unify { alt get(actual).struct { ty_ptr(actual_mt) { let (mutt, var) = alt unify_mut( - expected_mt.mut, actual_mt.mut, variance) { + expected_mt.mutbl, actual_mt.mutbl, variance) { none { ret ures_err(terr_vec_mutability); } some(mv) { mv } }; @@ -2031,7 +2033,7 @@ mod unify { cx, expected_mt.ty, actual_mt.ty, var); alt result { ures_ok(result_sub) { - let mt = {ty: result_sub, mut: mutt}; + let mt = {ty: result_sub, mutbl: mutt}; ret ures_ok(mk_ptr(cx.tcx, mt)); } _ { ret result; } @@ -2086,9 +2088,10 @@ mod unify { while i < expected_len { let expected_field = expected_fields[i]; let actual_field = actual_fields[i]; - let (mutt, var) = alt unify_mut( - expected_field.mt.mut, actual_field.mt.mut, variance) - { + let u_mut = unify_mut(expected_field.mt.mutbl, + actual_field.mt.mutbl, + variance); + let (mutt, var) = alt u_mut { none { ret ures_err(terr_record_mutability); } some(mv) { mv } }; @@ -2103,7 +2106,7 @@ mod unify { actual_field.mt.ty, var); alt result { ures_ok(rty) { - let mt = {ty: rty, mut: mutt}; + let mt = {ty: rty, mutbl: mutt}; result_fields += [{mt: mt with expected_field}]; } _ { ret result; } diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs index 4094b6eddbd..a54a376be2d 100644 --- a/src/comp/middle/typeck.rs +++ b/src/comp/middle/typeck.rs @@ -115,7 +115,7 @@ fn ty_param_bounds_and_ty_for_def(fcx: @fn_ctxt, sp: span, defn: ast::def) -> fcx.ccx.tcx, { ty: ty::mk_mach_uint(fcx.ccx.tcx, ast::ty_u8), - mut: ast::imm + mutbl: ast::m_imm }) }; } @@ -259,7 +259,7 @@ fn ast_ty_to_ty(tcx: ty::ctxt, mode: mode, &&ast_ty: @ast::ty) -> ty::t { tcx.ast_ty_to_ty_cache.insert(ast_ty, none::<ty::t>); fn ast_mt_to_mt(tcx: ty::ctxt, mode: mode, mt: ast::mt) -> ty::mt { - ret {ty: ast_ty_to_ty(tcx, mode, mt.ty), mut: mt.mut}; + ret {ty: ast_ty_to_ty(tcx, mode, mt.ty), mutbl: mt.mutbl}; } fn instantiate(tcx: ty::ctxt, sp: span, mode: mode, id: ast::def_id, args: [@ast::ty]) -> ty::t { @@ -2057,9 +2057,11 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier, bot = check_expr(fcx, oper); let oper_t = expr_ty(tcx, oper); alt unop { - ast::box(mut) { oper_t = ty::mk_box(tcx, {ty: oper_t, mut: mut}); } - ast::uniq(mut) { - oper_t = ty::mk_uniq(tcx, {ty: oper_t, mut: mut}); + ast::box(mutbl) { + oper_t = ty::mk_box(tcx, {ty: oper_t, mutbl: mutbl}); + } + ast::uniq(mutbl) { + oper_t = ty::mk_uniq(tcx, {ty: oper_t, mutbl: mutbl}); } ast::deref { alt structure_of(fcx, expr.span, oper_t) { @@ -2358,10 +2360,10 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier, } write_ty(tcx, id, t_1); } - ast::expr_vec(args, mut) { + ast::expr_vec(args, mutbl) { let t: ty::t = next_ty_var(fcx); for e: @ast::expr in args { bot |= check_expr_with(fcx, e, t); } - let typ = ty::mk_vec(tcx, {ty: t, mut: mut}); + let typ = ty::mk_vec(tcx, {ty: t, mutbl: mutbl}); write_ty(tcx, id, typ); } ast::expr_tup(elts) { @@ -2381,7 +2383,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier, for f: ast::field in fields { bot |= check_expr(fcx, f.node.expr); let expr_t = expr_ty(tcx, f.node.expr); - let expr_mt = {ty: expr_t, mut: f.node.mut}; + let expr_mt = {ty: expr_t, mutbl: f.node.mutbl}; // for the most precise error message, // should be f.node.expr.span, not f.span fields_t += @@ -2894,7 +2896,7 @@ fn check_item(ccx: @crate_ctxt, it: @ast::item) { fn arg_is_argv_ty(_tcx: ty::ctxt, a: ty::arg) -> bool { alt ty::get(a.ty).struct { ty::ty_vec(mt) { - if mt.mut != ast::imm { ret false; } + if mt.mutbl != ast::m_imm { ret false; } alt ty::get(mt.ty).struct { ty::ty_str { ret true; } _ { ret false; } |
