From 19424dfab6cf0432477396e73dea567678a715b8 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Wed, 10 Aug 2011 17:23:46 -0700 Subject: [PATCH] rustc: Add unique pointers to the set of types we support --- src/comp/metadata/tydecode.rs | 1 + src/comp/metadata/tyencode.rs | 1 + src/comp/middle/alias.rs | 5 ++++ src/comp/middle/shape.rs | 5 ++++ src/comp/middle/trans.rs | 8 ++++++ src/comp/middle/ty.rs | 50 +++++++++++++++++++---------------- src/comp/util/ppaux.rs | 3 ++- 7 files changed, 49 insertions(+), 24 deletions(-) diff --git a/src/comp/metadata/tydecode.rs b/src/comp/metadata/tydecode.rs index 1ff547c0a4dc..e23c2aa2193d 100644 --- a/src/comp/metadata/tydecode.rs +++ b/src/comp/metadata/tydecode.rs @@ -215,6 +215,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_ptr(st.tcx, parse_mt(st, sd)); } 'V' { ret ty::mk_vec(st.tcx, parse_mt(st, sd)); } 'I' { ret ty::mk_ivec(st.tcx, parse_mt(st, sd)); } diff --git a/src/comp/metadata/tyencode.rs b/src/comp/metadata/tyencode.rs index 529c51f602ff..5aeb2cdf31df 100644 --- a/src/comp/metadata/tyencode.rs +++ b/src/comp/metadata/tyencode.rs @@ -121,6 +121,7 @@ fn enc_sty(w: &ioivec::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_ptr(mt) { w.write_char('*'); enc_mt(w, cx, mt); } ty::ty_vec(mt) { w.write_char('V'); enc_mt(w, cx, mt); } ty::ty_ivec(mt) { w.write_char('I'); enc_mt(w, cx, mt); } diff --git a/src/comp/middle/alias.rs b/src/comp/middle/alias.rs index 2eefe1c9f5d2..613f8510fe0b 100644 --- a/src/comp/middle/alias.rs +++ b/src/comp/middle/alias.rs @@ -537,6 +537,9 @@ fn expr_root(cx: &ctx, ex: @ast::expr, autoderef: bool) -> ds += ~[@{mut: mt.mut != ast::imm, kind: unbox, outer_t: t}]; t = mt.ty; } + ty::ty_uniq(mt) { + ds += ~[@{mut: false, kind: unbox, outer_t: t}]; + } ty::ty_res(_, inner, tps) { ds += ~[@{mut: false, kind: unbox, outer_t: t}]; t = ty::substitute_type_params(cx.tcx, tps, inner); @@ -603,6 +606,7 @@ fn expr_root(cx: &ctx, ex: @ast::expr, autoderef: bool) -> let mut = false; alt ty::struct(cx.tcx, base_t) { ty::ty_box(mt) { mut = mt.mut != ast::imm; } + ty::ty_uniq(_) { } ty::ty_res(_, _, _) { } ty::ty_tag(_, _) { } ty::ty_ptr(mt) { mut = mt.mut != ast::imm; } @@ -665,6 +669,7 @@ fn ty_can_unsafely_include(cx: &ctx, needle: ty::t, haystack: ty::t, ty::ty_box(mt) | ty::ty_vec(mt) | ty::ty_ptr(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)) { diff --git a/src/comp/middle/shape.rs b/src/comp/middle/shape.rs index 459129238891..02b0253cf3ff 100644 --- a/src/comp/middle/shape.rs +++ b/src/comp/middle/shape.rs @@ -67,6 +67,7 @@ const shape_fn : u8 = 18u8; const shape_obj : u8 = 19u8; const shape_res : u8 = 20u8; const shape_var : u8 = 21u8; +const shape_uniq : u8 = 22u8; // FIXME: This is a bad API in trans_common. fn C_u8(n : u8) -> ValueRef { ret trans_common::C_u8(n as uint); } @@ -342,6 +343,10 @@ fn shape_of(ccx : &@crate_ctxt, t : ty::t) -> [u8] { s += ~[shape_box]; add_substr(s, shape_of(ccx, mt.ty)); } + ty::ty_uniq(subt) { + s += ~[shape_uniq]; + add_substr(s, shape_of(ccx, subt)); + } ty::ty_vec(mt) { s += ~[shape_evec]; add_bool(s, ty::type_is_pod(ccx.tcx, mt.ty)); diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index 34a01bb2e813..08921f3a7a92 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -217,6 +217,7 @@ fn type_of_inner(cx: &@crate_ctxt, sp: &span, t: &ty::t) -> TypeRef { ty::ty_istr. { llty = T_ivec(T_i8()); } ty::ty_tag(did, _) { llty = type_of_tag(cx, sp, did, t); } ty::ty_box(mt) { llty = T_ptr(T_box(type_of_inner(cx, sp, mt.ty))); } + ty::ty_uniq(t) { llty = T_ptr(type_of_inner(cx, sp, t)); } ty::ty_vec(mt) { llty = T_ptr(T_vec(type_of_inner(cx, sp, mt.ty))); } ty::ty_ivec(mt) { if ty::type_has_dynamic_size(cx.tcx, mt.ty) { @@ -476,6 +477,7 @@ 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_vec(_) { ret ty::mk_imm_vec(ccx.tcx, ty::mk_nil(ccx.tcx)); } ty::ty_fn(_, _, _, _, _) { ret ty::mk_imm_tup(ccx.tcx, @@ -1303,6 +1305,9 @@ fn make_free_glue(cx: &@block_ctxt, v0: ValueRef, t: &ty::t) { let rs = drop_ty(cx, body_val, body_ty); trans_non_gc_free(rs.bcx, v) } + ty::ty_uniq(_) { + fail "free uniq unimplemented"; + } ty::ty_port(_) { let v = cx.build.Load(v0); cx.build.Call(bcx_ccx(cx).upcalls.del_port, @@ -1402,6 +1407,7 @@ fn make_drop_glue(cx: &@block_ctxt, v0: ValueRef, t: &ty::t) { maybe_free_ivec_heap_part(rslt.bcx, v1, tm.ty) } ty::ty_box(_) { decr_refcnt_maybe_free(cx, v0, v0, t) } + ty::ty_uniq(_) { fail "drop uniq unimplemented"; } ty::ty_port(_) { decr_refcnt_maybe_free(cx, v0, v0, t) } ty::ty_chan(_) { let ptr = cx.build.Load(v0); @@ -3257,6 +3263,7 @@ fn autoderef(cx: &@block_ctxt, v: ValueRef, t: &ty::t) -> result_t { v1 = cx.build.PointerCast(body, T_ptr(llty)); } else { v1 = body; } } + ty::ty_uniq(t) { fail "autoderef uniq unimplemented"; } ty::ty_res(did, inner, tps) { t1 = ty::substitute_type_params(ccx.tcx, tps, inner); v1 = cx.build.GEP(v1, ~[C_int(0), C_int(1)]); @@ -4077,6 +4084,7 @@ fn trans_lval_gen(cx: &@block_ctxt, e: &@ast::expr) -> lval_result { ~[C_int(0), C_int(abi::box_rc_field_body)]) } + ty::ty_uniq(_) { fail "uniq lval translation unimplemented" } ty::ty_res(_, _, _) { sub.bcx.build.InBoundsGEP(sub.val, ~[C_int(0), C_int(1)]) } diff --git a/src/comp/middle/ty.rs b/src/comp/middle/ty.rs index 7a7bea34b8da..7ab295fd2e1a 100644 --- a/src/comp/middle/ty.rs +++ b/src/comp/middle/ty.rs @@ -89,6 +89,7 @@ export mk_tag; export mk_task; export mk_type; export mk_uint; +export mk_uniq; export mk_var; export mk_vec; export mk_iter_body_fn; @@ -147,6 +148,7 @@ export ty_tag; export ty_task; export ty_type; export ty_uint; +export ty_uniq; export ty_var; export ty_var_id; export ty_vec; @@ -265,6 +267,7 @@ tag sty { ty_istr; ty_tag(def_id, [t]); ty_box(mt); + ty_uniq(t); ty_vec(mt); ty_ivec(mt); ty_ptr(mt); @@ -471,6 +474,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_vec(m) { derive_flags_mt(cx, has_params, has_vars, m); } ty_ivec(m) { derive_flags_mt(cx, has_params, has_vars, m); } ty_ptr(m) { derive_flags_mt(cx, has_params, has_vars, m); } @@ -558,6 +562,8 @@ 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_ptr(cx: &ctxt, tm: &mt) -> t { ret gen_ty(cx, ty_ptr(tm)); } fn mk_imm_box(cx: &ctxt, ty: &t) -> t { @@ -728,36 +734,20 @@ fn fold_ty(cx: &ctxt, fld: fold_mode, ty_0: t) -> t { ty_native(_) {/* no-op */ } ty_task. {/* no-op */ } ty_box(tm) { - ty = - copy_cname(cx, - mk_box(cx, {ty: fold_ty(cx, fld, tm.ty), mut: tm.mut}), - ty); + 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_ptr(tm) { - ty = - copy_cname(cx, - mk_ptr(cx, {ty: fold_ty(cx, fld, tm.ty), mut: tm.mut}), - ty); + ty = mk_ptr(cx, {ty: fold_ty(cx, fld, tm.ty), mut: tm.mut}); } ty_vec(tm) { - ty = - copy_cname(cx, - mk_vec(cx, {ty: fold_ty(cx, fld, tm.ty), mut: tm.mut}), - ty); + ty = mk_vec(cx, {ty: fold_ty(cx, fld, tm.ty), mut: tm.mut}); } ty_ivec(tm) { - ty = - copy_cname(cx, - mk_ivec(cx, - {ty: fold_ty(cx, fld, tm.ty), mut: tm.mut}), - ty); - } - ty_port(subty) { - ty = copy_cname(cx, mk_port(cx, fold_ty(cx, fld, subty)), ty); - } - ty_chan(subty) { - ty = copy_cname(cx, mk_chan(cx, fold_ty(cx, fld, subty)), ty); + ty = mk_ivec(cx, {ty: fold_ty(cx, fld, tm.ty), mut: tm.mut}); } + ty_port(subty) { ty = mk_port(cx, fold_ty(cx, fld, subty)); } + ty_chan(subty) { ty = mk_chan(cx, fold_ty(cx, fld, subty)); } ty_tag(tid, subtys) { let new_subtys: [t] = ~[]; for subty: t in subtys { new_subtys += ~[fold_ty(cx, fld, subty)]; } @@ -2494,6 +2484,20 @@ mod unify { _ { ret ures_err(terr_mismatch); } } } + ty::ty_uniq(expected_sub) { + alt struct(cx.tcx, actual) { + ty::ty_uniq(actual_sub) { + let result = unify_step(cx, expected_sub, actual_sub); + alt result { + ures_ok(result_sub) { + ret ures_ok(mk_uniq(cx.tcx, result_sub)); + } + _ { ret result; } + } + } + _ { ret ures_err(terr_mismatch); } + } + } ty::ty_vec(expected_mt) { alt struct(cx.tcx, actual) { ty::ty_vec(actual_mt) { diff --git a/src/comp/util/ppaux.rs b/src/comp/util/ppaux.rs index 63d84d363e4f..2bdb87424789 100644 --- a/src/comp/util/ppaux.rs +++ b/src/comp/util/ppaux.rs @@ -91,8 +91,9 @@ fn ty_to_str(cx: &ctxt, typ: &t) -> str { ty_str. { s += "str"; } ty_istr. { s += "istr"; } ty_box(tm) { s += "@" + mt_to_str(cx, tm); } + ty_uniq(t) { s += "~" + ty_to_str(cx, t); } ty_vec(tm) { s += "vec[" + mt_to_str(cx, tm) + "]"; } - ty_ivec(tm) { s += "ivec[" + mt_to_str(cx, tm) + "]"; } + ty_ivec(tm) { s += "[" + mt_to_str(cx, tm) + "]"; } ty_port(t) { s += "port[" + ty_to_str(cx, t) + "]"; } ty_chan(t) { s += "chan[" + ty_to_str(cx, t) + "]"; } ty_type. { s += "type"; }