diff --git a/src/comp/metadata/tydecode.rs b/src/comp/metadata/tydecode.rs index 250522dda4f..0e1a01b0e15 100644 --- a/src/comp/metadata/tydecode.rs +++ b/src/comp/metadata/tydecode.rs @@ -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' { diff --git a/src/comp/metadata/tyencode.rs b/src/comp/metadata/tyencode.rs index 99f171907de..7c3c396ec35 100644 --- a/src/comp/metadata/tyencode.rs +++ b/src/comp/metadata/tyencode.rs @@ -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) { diff --git a/src/comp/middle/alias.rs b/src/comp/middle/alias.rs index f1788fda27e..2353aebb50f 100644 --- a/src/comp/middle/alias.rs +++ b/src/comp/middle/alias.rs @@ -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)) { @@ -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); } diff --git a/src/comp/middle/mut.rs b/src/comp/middle/mut.rs index 8974509a8a9..6ac17db4209 100644 --- a/src/comp/middle/mut.rs +++ b/src/comp/middle/mut.rs @@ -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}]; diff --git a/src/comp/middle/shape.rs b/src/comp/middle/shape.rs index 5a213e31ca5..2f4718223c4 100644 --- a/src/comp/middle/shape.rs +++ b/src/comp/middle/shape.rs @@ -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]; diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index bb3c399dda4..3f29c757aaf 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -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) { @@ -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)), @@ -1313,7 +1316,7 @@ 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); @@ -1321,7 +1324,7 @@ fn make_free_glue(bcx: @block_ctxt, v0: ValueRef, t: ty::t) { 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); diff --git a/src/comp/middle/ty.rs b/src/comp/middle/ty.rs index 56f9ab3d7f9..0ed7fd66935 100644 --- a/src/comp/middle/ty.rs +++ b/src/comp/middle/ty.rs @@ -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; @@ -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]); @@ -448,7 +449,7 @@ fn mk_raw_ty(cx: ctxt, st: sty, _in_cname: option::t) -> @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) { @@ -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)); } @@ -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); } @@ -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}); } @@ -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; } } } @@ -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; } } diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs index 758883a1aa0..88035da6c62 100644 --- a/src/comp/middle/typeck.rs +++ b/src/comp/middle/typeck.rs @@ -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)); @@ -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); diff --git a/src/comp/util/ppaux.rs b/src/comp/util/ppaux.rs index 44cf92ea1b9..11c50affd28 100644 --- a/src/comp/util/ppaux.rs +++ b/src/comp/util/ppaux.rs @@ -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) {