From 4f61dcb026910da60b85564fbee1b340569337f4 Mon Sep 17 00:00:00 2001 From: Michael Sullivan Date: Tue, 12 Jun 2012 10:53:29 -0700 Subject: [PATCH] Introduce an unboxed_vec type --- src/rustc/metadata/tydecode.rs | 1 + src/rustc/metadata/tyencode.rs | 1 + src/rustc/middle/trans/reflect.rs | 1 + src/rustc/middle/trans/shape.rs | 14 ++++++++------ src/rustc/middle/trans/type_of.rs | 3 +++ src/rustc/middle/ty.rs | 22 ++++++++++++++++++---- src/rustc/util/ppaux.rs | 3 ++- 7 files changed, 34 insertions(+), 11 deletions(-) diff --git a/src/rustc/metadata/tydecode.rs b/src/rustc/metadata/tydecode.rs index 61f6210b49d7..02ba2597d767 100644 --- a/src/rustc/metadata/tydecode.rs +++ b/src/rustc/metadata/tydecode.rs @@ -308,6 +308,7 @@ fn parse_ty(st: @pstate, conv: conv_did) -> ty::t { ret ty::mk_rptr(st.tcx, r, mt); } 'I' { ret ty::mk_vec(st.tcx, parse_mt(st, conv)); } + 'U' { ret ty::mk_unboxed_vec(st.tcx, parse_mt(st, conv)); } 'V' { let mt = parse_mt(st, conv); let v = parse_vstore(st); diff --git a/src/rustc/metadata/tyencode.rs b/src/rustc/metadata/tyencode.rs index 4893275f9531..051ea9e444ec 100644 --- a/src/rustc/metadata/tyencode.rs +++ b/src/rustc/metadata/tyencode.rs @@ -252,6 +252,7 @@ fn enc_sty(w: io::writer, cx: @ctxt, st: ty::sty) { enc_vstore(w, cx, v); } ty::ty_vec(mt) { w.write_char('I'); enc_mt(w, cx, mt); } + ty::ty_unboxed_vec(mt) { w.write_char('U'); enc_mt(w, cx, mt); } ty::ty_rec(fields) { w.write_str("R["/&); for fields.each {|field| diff --git a/src/rustc/middle/trans/reflect.rs b/src/rustc/middle/trans/reflect.rs index 414693c62875..4b6e92aa5ada 100644 --- a/src/rustc/middle/trans/reflect.rs +++ b/src/rustc/middle/trans/reflect.rs @@ -257,6 +257,7 @@ impl methods for reflector { }; self.visit("closure_ptr", [self.c_uint(ckval)]) } + ty::ty_unboxed_vec(mt) { self.bracketed_mt("vec", mt, []) } } } } diff --git a/src/rustc/middle/trans/shape.rs b/src/rustc/middle/trans/shape.rs index f67509f2db70..2b21e3e954ea 100644 --- a/src/rustc/middle/trans/shape.rs +++ b/src/rustc/middle/trans/shape.rs @@ -269,14 +269,16 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t) -> [u8] { add_substr(s, shape_of(ccx, mt.ty)); s } + ty::ty_unboxed_vec(mt) { + let mut s = [shape_unboxed_vec]; + add_bool(s, ty::type_is_pod(ccx.tcx, mt.ty)); + add_substr(s, shape_of(ccx, mt.ty)); + s + } ty::ty_evec(mt, ty::vstore_uniq) | ty::ty_vec(mt) { - let mut s_inner = [shape_unboxed_vec]; - add_bool(s_inner, ty::type_is_pod(ccx.tcx, mt.ty)); - add_substr(s_inner, shape_of(ccx, mt.ty)); - let mut s = [shape_uniq]; - add_substr(s, s_inner); - s + shape_of(ccx, + ty::mk_imm_uniq(ccx.tcx, ty::mk_unboxed_vec(ccx.tcx, mt))) } ty::ty_estr(ty::vstore_fixed(n)) { diff --git a/src/rustc/middle/trans/type_of.rs b/src/rustc/middle/trans/type_of.rs index a94a8116be03..fb9112fc751f 100644 --- a/src/rustc/middle/trans/type_of.rs +++ b/src/rustc/middle/trans/type_of.rs @@ -99,6 +99,9 @@ fn type_of(cx: @crate_ctxt, t: ty::t) -> TypeRef { ty::ty_vec(mt) { T_unique_ptr(T_unique(cx, T_vec(cx, type_of(cx, mt.ty)))) } + ty::ty_unboxed_vec(mt) { + T_vec(cx, type_of(cx, mt.ty)) + } ty::ty_ptr(mt) { T_ptr(type_of(cx, mt.ty)) } ty::ty_rptr(_, mt) { T_ptr(type_of(cx, mt.ty)) } diff --git a/src/rustc/middle/ty.rs b/src/rustc/middle/ty.rs index 972c6c7e708a..c770e7d71b77 100644 --- a/src/rustc/middle/ty.rs +++ b/src/rustc/middle/ty.rs @@ -88,6 +88,7 @@ export ty_str, mk_str, type_is_str; export ty_vec, mk_vec, type_is_vec; export ty_estr, mk_estr; export ty_evec, mk_evec; +export ty_unboxed_vec, mk_unboxed_vec; export vstore, vstore_fixed, vstore_uniq, vstore_box, vstore_slice; export ty_nil, mk_nil, type_is_nil; export ty_iface, mk_iface; @@ -378,6 +379,7 @@ enum sty { ty_type, // type_desc* ty_opaque_box, // used by monomorphizer to represent any @ box ty_opaque_closure_ptr(closure_kind), // ptr to env for fn, fn@, fn~ + ty_unboxed_vec(mt), } // In the middle end, constraints have a def_id attached, referring @@ -576,7 +578,8 @@ fn mk_t_with_id(cx: ctxt, st: sty, o_def_id: option) -> t { ty_enum(_, substs) | ty_class(_, substs) | ty_iface(_, substs) { flags |= sflags(substs); } - ty_box(m) | ty_uniq(m) | ty_vec(m) | ty_evec(m, _) | ty_ptr(m) { + ty_box(m) | ty_uniq(m) | ty_vec(m) | ty_evec(m, _) | + ty_ptr(m) | ty_unboxed_vec(m) { flags |= get(m.ty).flags; } ty_rptr(r, m) { @@ -671,6 +674,11 @@ fn mk_evec(cx: ctxt, tm: mt, t: vstore) -> t { mk_t(cx, ty_evec(tm, t)) } +fn mk_unboxed_vec(cx: ctxt, tm: mt) -> t { + mk_t(cx, ty_unboxed_vec(tm)) +} + + fn mk_rec(cx: ctxt, fs: [field]) -> t { mk_t(cx, ty_rec(fs)) } fn mk_constr(cx: ctxt, t: t, cs: [@type_constr]) -> t { @@ -752,7 +760,7 @@ fn maybe_walk_ty(ty: t, f: fn(t) -> bool) { ty_opaque_closure_ptr(_) | ty_var(_) | ty_var_integral(_) | ty_param(_, _) { } - ty_box(tm) | ty_vec(tm) | ty_evec(tm, _) | + ty_box(tm) | ty_vec(tm) | ty_evec(tm, _) | ty_unboxed_vec(tm) | ty_ptr(tm) | ty_rptr(_, tm) { maybe_walk_ty(tm.ty, f); } @@ -801,6 +809,9 @@ fn fold_sty(sty: sty, fldop: fn(t) -> t) -> sty { ty_vec(tm) { ty_vec({ty: fldop(tm.ty), mutbl: tm.mutbl}) } + ty_unboxed_vec(tm) { + ty_unboxed_vec({ty: fldop(tm.ty), mutbl: tm.mutbl}) + } ty_evec(tm, vst) { ty_evec({ty: fldop(tm.ty), mutbl: tm.mutbl}, vst) } @@ -1155,7 +1166,7 @@ pure fn type_is_unsafe_ptr(ty: t) -> bool { pure fn type_is_vec(ty: t) -> bool { ret alt get(ty).struct { - ty_vec(_) | ty_evec(_, _) { true } + ty_vec(_) | ty_evec(_, _) | ty_unboxed_vec(_) { true } ty_str | ty_estr(_) { true } _ { false } }; @@ -1593,7 +1604,7 @@ fn type_kind(cx: ctxt, ty: t) -> kind { ty_var(_) | ty_var_integral(_) { cx.sess.bug("Asked to compute kind of a type variable"); } - ty_type | ty_opaque_closure_ptr(_) | ty_opaque_box { + ty_type | ty_opaque_closure_ptr(_) | ty_opaque_box | ty_unboxed_vec(_) { cx.sess.bug("Asked to compute kind of fictitious type"); } }; @@ -1647,6 +1658,7 @@ fn is_instantiable(cx: ctxt, r_ty: t) -> bool { ty_opaque_box | ty_opaque_closure_ptr(_) | ty_evec(_, _) | + ty_unboxed_vec(_) | ty_vec(_) { false } @@ -2052,6 +2064,7 @@ fn hash_type_structure(st: sty) -> uint { ty_box(mt) { hash_subty(19u, mt.ty) } ty_evec(mt, _) { hash_subty(20u, mt.ty) } ty_vec(mt) { hash_subty(21u, mt.ty) } + ty_unboxed_vec(mt) { hash_subty(22u, mt.ty) } ty_tup(ts) { hash_subtys(25u, ts) } ty_rec(fields) { let mut h = 26u; @@ -2411,6 +2424,7 @@ fn ty_sort_str(cx: ctxt, t: t) -> str { ty_box(_) { "@-ptr" } ty_uniq(_) { "~-ptr" } ty_evec(_, _) | ty_vec(_) { "vector" } + ty_unboxed_vec(_) { "unboxed vector" } ty_ptr(_) { "*-ptr" } ty_rptr(_, _) { "&-ptr" } ty_rec(_) { "record" } diff --git a/src/rustc/util/ppaux.rs b/src/rustc/util/ppaux.rs index c5c445702d51..3c60cb911fe4 100644 --- a/src/rustc/util/ppaux.rs +++ b/src/rustc/util/ppaux.rs @@ -8,7 +8,7 @@ import middle::ty::{ty_estr, ty_evec, ty_float, ty_fn, ty_iface, ty_int}; import middle::ty::{ty_nil, ty_opaque_box, ty_opaque_closure_ptr, ty_param}; import middle::ty::{ty_ptr, ty_rec, ty_res, ty_rptr, ty_self, ty_str, ty_tup}; import middle::ty::{ty_type, ty_uniq, ty_uint, ty_var, ty_var_integral}; -import middle::ty::{ty_vec, vid}; +import middle::ty::{ty_vec, ty_unboxed_vec, vid}; import metadata::encoder; import syntax::codemap; import syntax::print::pprust; @@ -186,6 +186,7 @@ fn ty_to_str(cx: ctxt, typ: t) -> str { } } ty_vec(tm) { "[" + mt_to_str(cx, tm) + "]" } + ty_unboxed_vec(tm) { "unboxed_vec<" + mt_to_str(cx, tm) + ">" } ty_type { "type" } ty_rec(elems) { let mut strs: [str] = [];