Skip to content

Commit

Permalink
Convert ty::ty_uniq to contain a mutable type
Browse files Browse the repository at this point in the history
Issue #409
  • Loading branch information
brson committed Sep 22, 2011
1 parent 4d088bd commit 1b3023e
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/comp/metadata/tydecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ fn parse_ty(st: @pstate, sd: str_def) -> ty::t {
ret ty::mk_param(st.tcx, parse_int(st) as uint, k);
}
'@' { ret ty::mk_box(st.tcx, parse_mt(st, sd)); }
'~' { ret ty::mk_uniq(st.tcx, parse_ty(st, sd)); }
'~' { ret ty::mk_uniq(st.tcx, parse_mt(st, sd)); }
'*' { ret ty::mk_ptr(st.tcx, parse_mt(st, sd)); }
'I' { ret ty::mk_vec(st.tcx, parse_mt(st, sd)); }
'R' {
Expand Down
2 changes: 1 addition & 1 deletion src/comp/metadata/tyencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ fn enc_sty(w: io::writer, cx: @ctxt, st: ty::sty) {
w.write_char(']');
}
ty::ty_box(mt) { w.write_char('@'); enc_mt(w, cx, mt); }
ty::ty_uniq(t) { w.write_char('~'); enc_ty(w, cx, t); }
ty::ty_uniq(mt) { w.write_char('~'); enc_mt(w, cx, mt); }
ty::ty_ptr(mt) { w.write_char('*'); enc_mt(w, cx, mt); }
ty::ty_vec(mt) { w.write_char('I'); enc_mt(w, cx, mt); }
ty::ty_rec(fields) {
Expand Down
5 changes: 2 additions & 3 deletions src/comp/middle/alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,10 +559,9 @@ fn ty_can_unsafely_include(cx: ctx, needle: unsafe_ty, haystack: ty::t,
}
ret false;
}
ty::ty_box(mt) | ty::ty_ptr(mt) {
ty::ty_box(mt) | ty::ty_ptr(mt) | ty::ty_uniq(mt) {
ret helper(tcx, needle, mt.ty, get_mut(mut, mt));
}
ty::ty_uniq(t) { ret helper(tcx, needle, t, false); }
ty::ty_rec(fields) {
for f: ty::field in fields {
if helper(tcx, needle, f.mt.ty, get_mut(mut, f.mt)) {
Expand Down Expand Up @@ -619,7 +618,7 @@ fn copy_is_expensive(tcx: ty::ctxt, ty: ty::t) -> bool {
ty::ty_fn(_, _, _, _, _) | ty::ty_native_fn(_, _, _) |
ty::ty_obj(_) { 4u }
ty::ty_str. | ty::ty_vec(_) | ty::ty_param(_, _) { 50u }
ty::ty_uniq(t) { 1u + score_ty(tcx, t) }
ty::ty_uniq(mt) { 1u + score_ty(tcx, mt.ty) }
ty::ty_tag(_, ts) | ty::ty_tup(ts) {
let sum = 0u;
for t in ts { sum += score_ty(tcx, t); }
Expand Down
2 changes: 1 addition & 1 deletion src/comp/middle/mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn expr_root(tcx: ty::ctxt, ex: @expr, autoderef: bool) ->
t = mt.ty;
}
ty::ty_uniq(mt) {
ds += [@{mut: false, kind: unbox, outer_t: t}];
ds += [@{mut: mt.mut != imm, kind: unbox, outer_t: t}];
}
ty::ty_res(_, inner, tps) {
ds += [@{mut: false, kind: unbox, outer_t: t}];
Expand Down
4 changes: 2 additions & 2 deletions src/comp/middle/shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,9 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t, ty_param_map: [uint]) -> [u8] {
s += [shape_box];
add_substr(s, shape_of(ccx, mt.ty, ty_param_map));
}
ty::ty_uniq(subt) {
ty::ty_uniq(mt) {
s += [shape_uniq];
add_substr(s, shape_of(ccx, subt, ty_param_map));
add_substr(s, shape_of(ccx, mt.ty, ty_param_map));
}
ty::ty_vec(mt) {
s += [shape_vec];
Expand Down
15 changes: 9 additions & 6 deletions src/comp/middle/trans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,10 @@ fn type_of_inner(cx: @crate_ctxt, sp: span, t: ty::t)
let mt_ty = mt.ty;
check non_ty_var(cx, mt_ty);
T_ptr(T_box(type_of_inner(cx, sp, mt_ty))) }
ty::ty_uniq(t) {
check non_ty_var(cx, t);
T_ptr(type_of_inner(cx, sp, t)) }
ty::ty_uniq(mt) {
let mt_ty = mt.ty;
check non_ty_var(cx, mt_ty);
T_ptr(type_of_inner(cx, sp, mt_ty)) }
ty::ty_vec(mt) {
let mt_ty = mt.ty;
if ty::type_has_dynamic_size(cx.tcx, mt_ty) {
Expand Down Expand Up @@ -478,7 +479,9 @@ fn simplify_type(ccx: @crate_ctxt, typ: ty::t) -> ty::t {
fn simplifier(ccx: @crate_ctxt, typ: ty::t) -> ty::t {
alt ty::struct(ccx.tcx, typ) {
ty::ty_box(_) { ret ty::mk_imm_box(ccx.tcx, ty::mk_nil(ccx.tcx)); }
ty::ty_uniq(_) { ret ty::mk_uniq(ccx.tcx, ty::mk_nil(ccx.tcx)); }
ty::ty_uniq(_) {
ret ty::mk_imm_uniq(ccx.tcx, ty::mk_nil(ccx.tcx));
}
ty::ty_fn(_, _, _, _, _) {
ret ty::mk_tup(ccx.tcx,
[ty::mk_imm_box(ccx.tcx, ty::mk_nil(ccx.tcx)),
Expand Down Expand Up @@ -1313,15 +1316,15 @@ fn make_free_glue(bcx: @block_ctxt, v0: ValueRef, t: ty::t) {
trans_non_gc_free(bcx, v)
} else { bcx }
}
ty::ty_uniq(content_t) {
ty::ty_uniq(content_mt) {
let free_cx = new_sub_block_ctxt(bcx, "uniq_free");
let next_cx = new_sub_block_ctxt(bcx, "uniq_free_next");
let vptr = Load(bcx, v0);
let null_test = IsNull(bcx, vptr);
CondBr(bcx, null_test, next_cx.llbb, free_cx.llbb);

let bcx = free_cx;
let bcx = drop_ty(bcx, vptr, content_t);
let bcx = drop_ty(bcx, vptr, content_mt.ty);
let bcx = trans_shared_free(bcx, vptr);
Store(bcx, C_null(val_ty(vptr)), v0);
Br(bcx, next_cx.llbb);
Expand Down
36 changes: 25 additions & 11 deletions src/comp/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export mk_ctxt;
export mk_float;
export mk_fn;
export mk_imm_box;
export mk_imm_uniq;
export mk_mut_ptr;
export mk_int;
export mk_str;
Expand Down Expand Up @@ -251,7 +252,7 @@ tag sty {
ty_str;
ty_tag(def_id, [t]);
ty_box(mt);
ty_uniq(t);
ty_uniq(mt);
ty_vec(mt);
ty_ptr(mt);
ty_rec([field]);
Expand Down Expand Up @@ -448,7 +449,7 @@ fn mk_raw_ty(cx: ctxt, st: sty, _in_cname: option::t<str>) -> @raw_t {
for tt: t in tys { derive_flags_t(cx, has_params, has_vars, tt); }
}
ty_box(m) { derive_flags_mt(cx, has_params, has_vars, m); }
ty_uniq(tt) { derive_flags_t(cx, has_params, has_vars, tt); }
ty_uniq(m) { derive_flags_mt(cx, has_params, has_vars, m); }
ty_vec(m) { derive_flags_mt(cx, has_params, has_vars, m); }
ty_ptr(m) { derive_flags_mt(cx, has_params, has_vars, m); }
ty_rec(flds) {
Expand Down Expand Up @@ -534,7 +535,11 @@ fn mk_tag(cx: ctxt, did: ast::def_id, tys: [t]) -> t {

fn mk_box(cx: ctxt, tm: mt) -> t { ret gen_ty(cx, ty_box(tm)); }

fn mk_uniq(cx: ctxt, typ: t) -> t { ret gen_ty(cx, ty_uniq(typ)); }
fn mk_uniq(cx: ctxt, tm: mt) -> t { ret gen_ty(cx, ty_uniq(tm)); }

fn mk_imm_uniq(cx: ctxt, ty: t) -> t {
ret mk_uniq(cx, {ty: ty, mut: ast::imm});
}

fn mk_ptr(cx: ctxt, tm: mt) -> t { ret gen_ty(cx, ty_ptr(tm)); }

Expand Down Expand Up @@ -643,7 +648,7 @@ fn walk_ty(cx: ctxt, walker: ty_walk, ty: t) {
ty_constr(sub, _) { walk_ty(cx, walker, sub); }
ty_var(_) {/* no-op */ }
ty_param(_, _) {/* no-op */ }
ty_uniq(sub) { walk_ty(cx, walker, sub); }
ty_uniq(tm) { walk_ty(cx, walker, tm.ty); }
}
walker(ty);
}
Expand Down Expand Up @@ -678,7 +683,9 @@ fn fold_ty(cx: ctxt, fld: fold_mode, ty_0: t) -> t {
ty_box(tm) {
ty = mk_box(cx, {ty: fold_ty(cx, fld, tm.ty), mut: tm.mut});
}
ty_uniq(subty) { ty = mk_uniq(cx, fold_ty(cx, fld, subty)); }
ty_uniq(tm) {
ty = mk_uniq(cx, {ty: fold_ty(cx, fld, tm.ty), mut: tm.mut});
}
ty_ptr(tm) {
ty = mk_ptr(cx, {ty: fold_ty(cx, fld, tm.ty), mut: tm.mut});
}
Expand Down Expand Up @@ -1420,7 +1427,7 @@ fn hash_type_structure(st: sty) -> uint {
for c: @type_constr in cs { h += h << 5u + hash_type_constr(h, c); }
ret h;
}
ty_uniq(t) { let h = 37u; h += h << 5u + hash_ty(t); ret h; }
ty_uniq(mt) { let h = 37u; h += h << 5u + hash_ty(mt.ty); ret h; }
}
}

Expand Down Expand Up @@ -2184,13 +2191,20 @@ mod unify {
_ { ret ures_err(terr_mismatch); }
}
}
ty::ty_uniq(expected_sub) {
ty::ty_uniq(expected_mt) {
alt struct(cx.tcx, actual) {
ty::ty_uniq(actual_sub) {
let result = unify_step(cx, expected_sub, actual_sub);
ty::ty_uniq(actual_mt) {
let mut = expected_mt.mut;
// FIXME (409) Write a test then uncomment
/*alt unify_mut(expected_mt.mut, actual_mt.mut) {
none. { ret ures_err(terr_box_mutability); }
some(m) { mut = m; }
}*/
let result = unify_step(cx, expected_mt.ty, actual_mt.ty);
alt result {
ures_ok(result_sub) {
ret ures_ok(mk_uniq(cx.tcx, result_sub));
ures_ok(result_mt) {
let mt = {ty: result_mt, mut: mut};
ret ures_ok(mk_uniq(cx.tcx, mt));
}
_ { ret result; }
}
Expand Down
6 changes: 3 additions & 3 deletions src/comp/middle/typeck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ fn ast_ty_to_ty(tcx: ty::ctxt, getter: ty_getter, ast_ty: @ast::ty) -> ty::t {
typ = ty::mk_box(tcx, ast_mt_to_mt(tcx, getter, mt));
}
ast::ty_uniq(mt) {
typ = ty::mk_uniq(tcx, ast_ty_to_ty(tcx, getter, mt.ty));
typ = ty::mk_uniq(tcx, ast_mt_to_mt(tcx, getter, mt));
}
ast::ty_vec(mt) {
typ = ty::mk_vec(tcx, ast_mt_to_mt(tcx, getter, mt));
Expand Down Expand Up @@ -1720,12 +1720,12 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
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, oper_t);
oper_t = ty::mk_uniq(tcx, {ty: oper_t, mut: mut});
}
ast::deref. {
alt structure_of(fcx, expr.span, oper_t) {
ty::ty_box(inner) { oper_t = inner.ty; }
ty::ty_uniq(inner) { oper_t = inner; }
ty::ty_uniq(inner) { oper_t = inner.ty; }
ty::ty_res(_, inner, _) { oper_t = inner; }
ty::ty_tag(id, tps) {
let variants = ty::tag_variants(tcx, id);
Expand Down
2 changes: 1 addition & 1 deletion src/comp/util/ppaux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ fn ty_to_str(cx: ctxt, typ: t) -> str {
ty_char. { "char" }
ty_str. { "str" }
ty_box(tm) { "@" + mt_to_str(cx, tm) }
ty_uniq(t) { "~" + ty_to_str(cx, t) }
ty_uniq(tm) { "~" + mt_to_str(cx, tm) }
ty_vec(tm) { "[" + mt_to_str(cx, tm) + "]" }
ty_type. { "type" }
ty_rec(elems) {
Expand Down

0 comments on commit 1b3023e

Please sign in to comment.