rustc: Add unique pointers to the set of types we support
This commit is contained in:
parent
a8a4d4ec05
commit
19424dfab6
7 changed files with 49 additions and 24 deletions
|
@ -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_param(st.tcx, parse_int(st) as uint, k);
|
||||||
}
|
}
|
||||||
'@' { ret ty::mk_box(st.tcx, parse_mt(st, sd)); }
|
'@' { 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)); }
|
'*' { ret ty::mk_ptr(st.tcx, parse_mt(st, sd)); }
|
||||||
'V' { ret ty::mk_vec(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)); }
|
'I' { ret ty::mk_ivec(st.tcx, parse_mt(st, sd)); }
|
||||||
|
|
|
@ -121,6 +121,7 @@ fn enc_sty(w: &ioivec::writer, cx: &@ctxt, st: &ty::sty) {
|
||||||
w.write_char(']');
|
w.write_char(']');
|
||||||
}
|
}
|
||||||
ty::ty_box(mt) { w.write_char('@'); enc_mt(w, cx, mt); }
|
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_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_vec(mt) { w.write_char('V'); enc_mt(w, cx, mt); }
|
||||||
ty::ty_ivec(mt) { w.write_char('I'); enc_mt(w, cx, mt); }
|
ty::ty_ivec(mt) { w.write_char('I'); enc_mt(w, cx, mt); }
|
||||||
|
|
|
@ -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}];
|
ds += ~[@{mut: mt.mut != ast::imm, kind: unbox, outer_t: t}];
|
||||||
t = mt.ty;
|
t = mt.ty;
|
||||||
}
|
}
|
||||||
|
ty::ty_uniq(mt) {
|
||||||
|
ds += ~[@{mut: false, kind: unbox, outer_t: t}];
|
||||||
|
}
|
||||||
ty::ty_res(_, inner, tps) {
|
ty::ty_res(_, inner, tps) {
|
||||||
ds += ~[@{mut: false, kind: unbox, outer_t: t}];
|
ds += ~[@{mut: false, kind: unbox, outer_t: t}];
|
||||||
t = ty::substitute_type_params(cx.tcx, tps, inner);
|
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;
|
let mut = false;
|
||||||
alt ty::struct(cx.tcx, base_t) {
|
alt ty::struct(cx.tcx, base_t) {
|
||||||
ty::ty_box(mt) { mut = mt.mut != ast::imm; }
|
ty::ty_box(mt) { mut = mt.mut != ast::imm; }
|
||||||
|
ty::ty_uniq(_) { }
|
||||||
ty::ty_res(_, _, _) { }
|
ty::ty_res(_, _, _) { }
|
||||||
ty::ty_tag(_, _) { }
|
ty::ty_tag(_, _) { }
|
||||||
ty::ty_ptr(mt) { mut = mt.mut != ast::imm; }
|
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) {
|
ty::ty_box(mt) | ty::ty_vec(mt) | ty::ty_ptr(mt) {
|
||||||
ret helper(tcx, needle, mt.ty, get_mut(mut, 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) {
|
ty::ty_rec(fields) {
|
||||||
for f: ty::field in 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_mut(mut, f.mt)) {
|
||||||
|
|
|
@ -67,6 +67,7 @@ const shape_fn : u8 = 18u8;
|
||||||
const shape_obj : u8 = 19u8;
|
const shape_obj : u8 = 19u8;
|
||||||
const shape_res : u8 = 20u8;
|
const shape_res : u8 = 20u8;
|
||||||
const shape_var : u8 = 21u8;
|
const shape_var : u8 = 21u8;
|
||||||
|
const shape_uniq : u8 = 22u8;
|
||||||
|
|
||||||
// FIXME: This is a bad API in trans_common.
|
// FIXME: This is a bad API in trans_common.
|
||||||
fn C_u8(n : u8) -> ValueRef { ret trans_common::C_u8(n as uint); }
|
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];
|
s += ~[shape_box];
|
||||||
add_substr(s, shape_of(ccx, mt.ty));
|
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) {
|
ty::ty_vec(mt) {
|
||||||
s += ~[shape_evec];
|
s += ~[shape_evec];
|
||||||
add_bool(s, ty::type_is_pod(ccx.tcx, mt.ty));
|
add_bool(s, ty::type_is_pod(ccx.tcx, mt.ty));
|
||||||
|
|
|
@ -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_istr. { llty = T_ivec(T_i8()); }
|
||||||
ty::ty_tag(did, _) { llty = type_of_tag(cx, sp, did, t); }
|
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_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_vec(mt) { llty = T_ptr(T_vec(type_of_inner(cx, sp, mt.ty))); }
|
||||||
ty::ty_ivec(mt) {
|
ty::ty_ivec(mt) {
|
||||||
if ty::type_has_dynamic_size(cx.tcx, mt.ty) {
|
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 {
|
fn simplifier(ccx: @crate_ctxt, typ: ty::t) -> ty::t {
|
||||||
alt ty::struct(ccx.tcx, typ) {
|
alt ty::struct(ccx.tcx, typ) {
|
||||||
ty::ty_box(_) { ret ty::mk_imm_box(ccx.tcx, ty::mk_nil(ccx.tcx)); }
|
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_vec(_) { ret ty::mk_imm_vec(ccx.tcx, ty::mk_nil(ccx.tcx)); }
|
||||||
ty::ty_fn(_, _, _, _, _) {
|
ty::ty_fn(_, _, _, _, _) {
|
||||||
ret ty::mk_imm_tup(ccx.tcx,
|
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);
|
let rs = drop_ty(cx, body_val, body_ty);
|
||||||
trans_non_gc_free(rs.bcx, v)
|
trans_non_gc_free(rs.bcx, v)
|
||||||
}
|
}
|
||||||
|
ty::ty_uniq(_) {
|
||||||
|
fail "free uniq unimplemented";
|
||||||
|
}
|
||||||
ty::ty_port(_) {
|
ty::ty_port(_) {
|
||||||
let v = cx.build.Load(v0);
|
let v = cx.build.Load(v0);
|
||||||
cx.build.Call(bcx_ccx(cx).upcalls.del_port,
|
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)
|
maybe_free_ivec_heap_part(rslt.bcx, v1, tm.ty)
|
||||||
}
|
}
|
||||||
ty::ty_box(_) { decr_refcnt_maybe_free(cx, v0, v0, t) }
|
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_port(_) { decr_refcnt_maybe_free(cx, v0, v0, t) }
|
||||||
ty::ty_chan(_) {
|
ty::ty_chan(_) {
|
||||||
let ptr = cx.build.Load(v0);
|
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));
|
v1 = cx.build.PointerCast(body, T_ptr(llty));
|
||||||
} else { v1 = body; }
|
} else { v1 = body; }
|
||||||
}
|
}
|
||||||
|
ty::ty_uniq(t) { fail "autoderef uniq unimplemented"; }
|
||||||
ty::ty_res(did, inner, tps) {
|
ty::ty_res(did, inner, tps) {
|
||||||
t1 = ty::substitute_type_params(ccx.tcx, tps, inner);
|
t1 = ty::substitute_type_params(ccx.tcx, tps, inner);
|
||||||
v1 = cx.build.GEP(v1, ~[C_int(0), C_int(1)]);
|
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(0),
|
||||||
C_int(abi::box_rc_field_body)])
|
C_int(abi::box_rc_field_body)])
|
||||||
}
|
}
|
||||||
|
ty::ty_uniq(_) { fail "uniq lval translation unimplemented" }
|
||||||
ty::ty_res(_, _, _) {
|
ty::ty_res(_, _, _) {
|
||||||
sub.bcx.build.InBoundsGEP(sub.val, ~[C_int(0), C_int(1)])
|
sub.bcx.build.InBoundsGEP(sub.val, ~[C_int(0), C_int(1)])
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,6 +89,7 @@ export mk_tag;
|
||||||
export mk_task;
|
export mk_task;
|
||||||
export mk_type;
|
export mk_type;
|
||||||
export mk_uint;
|
export mk_uint;
|
||||||
|
export mk_uniq;
|
||||||
export mk_var;
|
export mk_var;
|
||||||
export mk_vec;
|
export mk_vec;
|
||||||
export mk_iter_body_fn;
|
export mk_iter_body_fn;
|
||||||
|
@ -147,6 +148,7 @@ export ty_tag;
|
||||||
export ty_task;
|
export ty_task;
|
||||||
export ty_type;
|
export ty_type;
|
||||||
export ty_uint;
|
export ty_uint;
|
||||||
|
export ty_uniq;
|
||||||
export ty_var;
|
export ty_var;
|
||||||
export ty_var_id;
|
export ty_var_id;
|
||||||
export ty_vec;
|
export ty_vec;
|
||||||
|
@ -265,6 +267,7 @@ tag sty {
|
||||||
ty_istr;
|
ty_istr;
|
||||||
ty_tag(def_id, [t]);
|
ty_tag(def_id, [t]);
|
||||||
ty_box(mt);
|
ty_box(mt);
|
||||||
|
ty_uniq(t);
|
||||||
ty_vec(mt);
|
ty_vec(mt);
|
||||||
ty_ivec(mt);
|
ty_ivec(mt);
|
||||||
ty_ptr(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); }
|
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_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_vec(m) { derive_flags_mt(cx, has_params, has_vars, m); }
|
||||||
ty_ivec(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); }
|
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_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_ptr(cx: &ctxt, tm: &mt) -> t { ret gen_ty(cx, ty_ptr(tm)); }
|
||||||
|
|
||||||
fn mk_imm_box(cx: &ctxt, ty: &t) -> t {
|
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_native(_) {/* no-op */ }
|
||||||
ty_task. {/* no-op */ }
|
ty_task. {/* no-op */ }
|
||||||
ty_box(tm) {
|
ty_box(tm) {
|
||||||
ty =
|
ty = mk_box(cx, {ty: fold_ty(cx, fld, tm.ty), mut: tm.mut});
|
||||||
copy_cname(cx,
|
|
||||||
mk_box(cx, {ty: fold_ty(cx, fld, tm.ty), mut: tm.mut}),
|
|
||||||
ty);
|
|
||||||
}
|
}
|
||||||
|
ty_uniq(subty) { ty = mk_uniq(cx, fold_ty(cx, fld, subty)); }
|
||||||
ty_ptr(tm) {
|
ty_ptr(tm) {
|
||||||
ty =
|
ty = mk_ptr(cx, {ty: fold_ty(cx, fld, tm.ty), mut: tm.mut});
|
||||||
copy_cname(cx,
|
|
||||||
mk_ptr(cx, {ty: fold_ty(cx, fld, tm.ty), mut: tm.mut}),
|
|
||||||
ty);
|
|
||||||
}
|
}
|
||||||
ty_vec(tm) {
|
ty_vec(tm) {
|
||||||
ty =
|
ty = mk_vec(cx, {ty: fold_ty(cx, fld, tm.ty), mut: tm.mut});
|
||||||
copy_cname(cx,
|
|
||||||
mk_vec(cx, {ty: fold_ty(cx, fld, tm.ty), mut: tm.mut}),
|
|
||||||
ty);
|
|
||||||
}
|
}
|
||||||
ty_ivec(tm) {
|
ty_ivec(tm) {
|
||||||
ty =
|
ty = mk_ivec(cx, {ty: fold_ty(cx, fld, tm.ty), mut: tm.mut});
|
||||||
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_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) {
|
ty_tag(tid, subtys) {
|
||||||
let new_subtys: [t] = ~[];
|
let new_subtys: [t] = ~[];
|
||||||
for subty: t in subtys { new_subtys += ~[fold_ty(cx, fld, subty)]; }
|
for subty: t in subtys { new_subtys += ~[fold_ty(cx, fld, subty)]; }
|
||||||
|
@ -2494,6 +2484,20 @@ mod unify {
|
||||||
_ { ret ures_err(terr_mismatch); }
|
_ { 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) {
|
ty::ty_vec(expected_mt) {
|
||||||
alt struct(cx.tcx, actual) {
|
alt struct(cx.tcx, actual) {
|
||||||
ty::ty_vec(actual_mt) {
|
ty::ty_vec(actual_mt) {
|
||||||
|
|
|
@ -91,8 +91,9 @@ fn ty_to_str(cx: &ctxt, typ: &t) -> str {
|
||||||
ty_str. { s += "str"; }
|
ty_str. { s += "str"; }
|
||||||
ty_istr. { s += "istr"; }
|
ty_istr. { s += "istr"; }
|
||||||
ty_box(tm) { s += "@" + mt_to_str(cx, tm); }
|
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_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_port(t) { s += "port[" + ty_to_str(cx, t) + "]"; }
|
||||||
ty_chan(t) { s += "chan[" + ty_to_str(cx, t) + "]"; }
|
ty_chan(t) { s += "chan[" + ty_to_str(cx, t) + "]"; }
|
||||||
ty_type. { s += "type"; }
|
ty_type. { s += "type"; }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue