Store arg mode and objfield mutability in their def

This commit is contained in:
Marijn Haverbeke 2011-09-01 10:03:17 +02:00
parent 9ba3fe5e40
commit 34ae491ca9
10 changed files with 43 additions and 43 deletions

View file

@ -481,7 +481,7 @@ fn check_move_rhs(cx: &@ctx, src: &@ast::expr, sc: &scope, v: &vt<scope>) {
alt src.node {
ast::expr_path(p) {
alt cx.tcx.def_map.get(src.id) {
ast::def_obj_field(_) {
ast::def_obj_field(_, _) {
cx.tcx.sess.span_err(src.span,
~"may not move out of an obj field");
}
@ -743,10 +743,10 @@ fn ty_can_unsafely_include(cx: &ctx, needle: ty::t, haystack: ty::t,
fn def_is_local(d: &ast::def, objfields_count: bool) -> bool {
ret alt d {
ast::def_local(_) | ast::def_arg(_) | ast::def_binding(_) { true }
ast::def_obj_field(_) { objfields_count }
_ { false }
};
ast::def_local(_) | ast::def_arg(_, _) | ast::def_binding(_) { true }
ast::def_obj_field(_, _) { objfields_count }
_ { false }
};
}
fn fty_args(cx: &ctx, fty: ty::t) -> [ty::arg] {

View file

@ -60,7 +60,7 @@ fn collect_freevars(def_map: &resolve::def_map, sess: &session::session,
~"internal error in collect_freevars");
}
alt def_map.get(expr.id) {
ast::def_arg(did) { *refs += [expr.id]; }
ast::def_arg(did, _) { *refs += [expr.id]; }
ast::def_local(did) { *refs += [expr.id]; }
ast::def_binding(did) { *refs += [expr.id]; }
_ {/* no-op */ }

View file

@ -624,13 +624,13 @@ fn scope_is_fn(sc: &scope) -> bool {
fn def_is_local(d: &def) -> bool {
ret alt d {
ast::def_arg(_) | ast::def_local(_) | ast::def_binding(_) { true }
_ { false }
};
ast::def_arg(_, _) | ast::def_local(_) | ast::def_binding(_) { true }
_ { false }
};
}
fn def_is_obj_field(d: &def) -> bool {
ret alt d { ast::def_obj_field(_) { true } _ { false } };
ret alt d { ast::def_obj_field(_, _) { true } _ { false } };
}
fn def_is_ty_arg(d: &def) -> bool {
@ -764,7 +764,7 @@ fn lookup_in_fn(name: &ident, decl: &ast::fn_decl,
ns_value. {
for a: ast::arg in decl.inputs {
if istr::eq(a.ident, name) {
ret some(ast::def_arg(local_def(a.id)));
ret some(ast::def_arg(local_def(a.id), a.mode));
}
}
ret none::<def>;
@ -780,7 +780,7 @@ fn lookup_in_obj(name: &ident, ob: &ast::_obj, ty_params: &[ast::ty_param],
ns_value. {
for f: ast::obj_field in ob.fields {
if istr::eq(f.ident, name) {
ret some(ast::def_obj_field(local_def(f.id)));
ret some(ast::def_obj_field(local_def(f.id), f.mut));
}
}
ret none::<def>;
@ -1170,19 +1170,19 @@ fn index_nmod(md: &ast::native_mod) -> mod_index {
// External lookups
fn ns_for_def(d: def) -> namespace {
ret alt d {
ast::def_fn(id, _) { ns_value }
ast::def_obj_field(id) { ns_value }
ast::def_mod(id) { ns_module }
ast::def_native_mod(id) { ns_module }
ast::def_const(id) { ns_value }
ast::def_arg(id) { ns_value }
ast::def_local(id) { ns_value }
ast::def_variant(_, id) { ns_value }
ast::def_ty(id) { ns_type }
ast::def_binding(id) { ns_type }
ast::def_use(id) { ns_module }
ast::def_native_ty(id) { ns_type }
ast::def_native_fn(id) { ns_value }
ast::def_fn(_, _) { ns_value }
ast::def_obj_field(_, _) { ns_value }
ast::def_mod(_) { ns_module }
ast::def_native_mod(_) { ns_module }
ast::def_const(_) { ns_value }
ast::def_arg(_, _) { ns_value }
ast::def_local(_) { ns_value }
ast::def_variant(_, _) { ns_value }
ast::def_ty(_) { ns_type }
ast::def_binding(_) { ns_type }
ast::def_use(_) { ns_module }
ast::def_native_ty(_) { ns_type }
ast::def_native_fn(_) { ns_value }
};
}

View file

@ -3141,7 +3141,7 @@ fn trans_var(cx: &@block_ctxt, sp: &span, id: ast::node_id) -> lval_result {
assert (cx.fcx.llupvars.contains_key(did.node));
ret lval_mem(cx, cx.fcx.llupvars.get(did.node));
}
some(ast::def_arg(did)) {
some(ast::def_arg(did, _)) {
assert (cx.fcx.llargs.contains_key(did.node));
ret lval_mem(cx, cx.fcx.llargs.get(did.node));
}
@ -3153,7 +3153,7 @@ fn trans_var(cx: &@block_ctxt, sp: &span, id: ast::node_id) -> lval_result {
assert (cx.fcx.lllocals.contains_key(did.node));
ret lval_mem(cx, cx.fcx.lllocals.get(did.node));
}
some(ast::def_obj_field(did)) {
some(ast::def_obj_field(did, _)) {
assert (cx.fcx.llobjfields.contains_key(did.node));
ret lval_mem(cx, cx.fcx.llobjfields.get(did.node));
}

View file

@ -625,7 +625,7 @@ fn expr_to_constr_arg(tcx: ty::ctxt, e: &@expr) -> @constr_arg_use {
carg_ident({ident: p.node.idents[0],
node: l_id.node}));
}
some(def_arg(a_id)) {
some(def_arg(a_id, _)) {
ret @respan(p.span,
carg_ident({ident: p.node.idents[0],
node: a_id.node}));
@ -849,7 +849,7 @@ fn local_node_id_to_def_id_strict(fcx: &fn_ctxt, sp: &span, i: &node_id) ->
def_id {
alt local_node_id_to_def(fcx, i) {
some(def_local(d_id)) { ret d_id; }
some(def_arg(a_id)) { ret a_id; }
some(def_arg(a_id, _)) { ret a_id; }
some(_) {
fcx.ccx.tcx.sess.span_fatal(sp,
~"local_node_id_to_def_id: id \
@ -871,7 +871,7 @@ fn local_node_id_to_def(fcx: &fn_ctxt, i: &node_id) -> option::t<def> {
fn local_node_id_to_def_id(fcx: &fn_ctxt, i: &node_id) -> option::t<def_id> {
alt local_node_id_to_def(fcx, i) {
some(def_local(d_id)) { some(d_id) }
some(def_arg(a_id)) { some(a_id) }
some(def_arg(a_id, _)) { some(a_id) }
_ { none }
}
}
@ -880,7 +880,7 @@ fn local_node_id_to_local_def_id(fcx: &fn_ctxt, i: &node_id) ->
option::t<node_id> {
alt local_node_id_to_def(fcx, i) {
some(def_local(d_id)) { some(d_id.node) }
some(def_arg(a_id)) { some(a_id.node) }
some(def_arg(a_id, _)) { some(a_id.node) }
_ { none }
}
}

View file

@ -295,7 +295,7 @@ fn handle_update(fcx: &fn_ctxt, parent: &@expr, lhs: &@expr, rhs: &@expr,
fn handle_var(fcx: &fn_ctxt, rslt: &pre_and_post, id: node_id, name: ident) {
let df = node_id_to_def_upvar_strict(fcx, id);
alt df {
def_local(d_id) | def_arg(d_id) {
def_local(d_id) | def_arg(d_id, _) {
let i = bit_num(fcx, ninit(d_id.node, name));
use_var(fcx, d_id.node);
require_and_preserve(i, rslt);

View file

@ -2600,10 +2600,10 @@ fn substitute_type_params(cx: &ctxt, substs: &[ty::t], typ: t) -> t {
fn def_has_ty_params(def: &ast::def) -> bool {
alt def {
ast::def_fn(_, _) { ret true; }
ast::def_obj_field(_) { ret false; }
ast::def_obj_field(_, _) { ret false; }
ast::def_mod(_) { ret false; }
ast::def_const(_) { ret false; }
ast::def_arg(_) { ret false; }
ast::def_arg(_, _) { ret false; }
ast::def_local(_) { ret false; }
ast::def_variant(_, _) { ret true; }
ast::def_ty(_) { ret false; }

View file

@ -116,8 +116,7 @@ fn ty_param_kinds_and_ty_for_def(fcx: &@fn_ctxt, sp: &span, defn: &ast::def)
-> ty_param_kinds_and_ty {
let no_kinds: [ast::kind] = [];
alt defn {
ast::def_arg(id) {
ast::def_arg(id, _) {
assert (fcx.locals.contains_key(id.node));
let typ = ty::mk_var(fcx.ccx.tcx, lookup_local(fcx, sp, id.node));
ret {kinds: no_kinds, ty: typ};
@ -127,7 +126,7 @@ fn ty_param_kinds_and_ty_for_def(fcx: &@fn_ctxt, sp: &span, defn: &ast::def)
let typ = ty::mk_var(fcx.ccx.tcx, lookup_local(fcx, sp, id.node));
ret {kinds: no_kinds, ty: typ};
}
ast::def_obj_field(id) {
ast::def_obj_field(id, _) {
assert (fcx.locals.contains_key(id.node));
let typ = ty::mk_var(fcx.ccx.tcx, lookup_local(fcx, sp, id.node));
ret {kinds: no_kinds, ty: typ};
@ -2642,8 +2641,9 @@ fn check_constraints(fcx: &@fn_ctxt, cs: [@ast::constr], args:[ast::arg]) {
that's my justification.
*/
let arg_occ_node_id = fcx.ccx.tcx.sess.next_node_id();
fcx.ccx.tcx.def_map.insert(arg_occ_node_id,
ast::def_arg(local_def(args[i].id)));
fcx.ccx.tcx.def_map.insert
(arg_occ_node_id, ast::def_arg(local_def(args[i].id),
args[i].mode));
{id:arg_occ_node_id,
node: ast::expr_path(respan(a.span, p)),
span:a.span}

View file

@ -29,11 +29,11 @@ type ty_param = {ident: ident, kind: kind};
tag def {
def_fn(def_id, purity);
def_obj_field(def_id);
def_obj_field(def_id, mutability);
def_mod(def_id);
def_native_mod(def_id);
def_const(def_id);
def_arg(def_id);
def_arg(def_id, mode);
def_local(def_id);
def_variant(def_id, /* tag */def_id);

View file

@ -29,11 +29,11 @@ fn variant_def_ids(d: &def) -> {tg: def_id, var: def_id} {
fn def_id_of_def(d: def) -> def_id {
alt d {
def_fn(id, _) { ret id; }
def_obj_field(id) { ret id; }
def_obj_field(id, _) { ret id; }
def_mod(id) { ret id; }
def_native_mod(id) { ret id; }
def_const(id) { ret id; }
def_arg(id) { ret id; }
def_arg(id, _) { ret id; }
def_local(id) { ret id; }
def_variant(_, id) { ret id; }
def_ty(id) { ret id; }