Skip to content

Commit 24a0de4

Browse files
committed
librustc: Separate out trait storage from evec/estr storage
1 parent 3cee676 commit 24a0de4

File tree

23 files changed

+293
-162
lines changed

23 files changed

+293
-162
lines changed

src/librustc/metadata/tydecode.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,16 @@ fn parse_vstore(st: @mut PState) -> ty::vstore {
157157
}
158158
}
159159

160+
fn parse_trait_store(st: @mut PState) -> ty::TraitStore {
161+
match next(st) {
162+
'~' => ty::UniqTraitStore,
163+
'@' => ty::BoxTraitStore,
164+
'&' => ty::RegionTraitStore(parse_region(st)),
165+
'.' => ty::BareTraitStore,
166+
c => st.tcx.sess.bug(fmt!("parse_trait_store(): bad input '%c'", c))
167+
}
168+
}
169+
160170
fn parse_substs(st: @mut PState, conv: conv_did) -> ty::substs {
161171
let self_r = parse_opt(st, || parse_region(st) );
162172

@@ -269,9 +279,9 @@ fn parse_ty(st: @mut PState, conv: conv_did) -> ty::t {
269279
fail_unless!(next(st) == '[');
270280
let def = parse_def(st, NominalType, conv);
271281
let substs = parse_substs(st, conv);
272-
let vstore = parse_vstore(st);
282+
let store = parse_trait_store(st);
273283
fail_unless!(next(st) == ']');
274-
return ty::mk_trait(st.tcx, def, substs, vstore);
284+
return ty::mk_trait(st.tcx, def, substs, store);
275285
}
276286
'p' => {
277287
let did = parse_def(st, TypeParameter, conv);

src/librustc/metadata/tyencode.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,18 @@ pub fn enc_vstore(w: io::Writer, cx: @ctxt, v: ty::vstore) {
214214
}
215215
}
216216

217+
pub fn enc_trait_store(w: io::Writer, cx: @ctxt, s: ty::TraitStore) {
218+
match s {
219+
ty::UniqTraitStore => w.write_char('~'),
220+
ty::BoxTraitStore => w.write_char('@'),
221+
ty::BareTraitStore => w.write_char('.'),
222+
ty::RegionTraitStore(re) => {
223+
w.write_char('&');
224+
enc_region(w, cx, re);
225+
}
226+
}
227+
}
228+
217229
fn enc_sty(w: io::Writer, cx: @ctxt, +st: ty::sty) {
218230
match st {
219231
ty::ty_nil => w.write_char('n'),
@@ -252,12 +264,12 @@ fn enc_sty(w: io::Writer, cx: @ctxt, +st: ty::sty) {
252264
enc_substs(w, cx, (*substs));
253265
w.write_char(']');
254266
}
255-
ty::ty_trait(def, ref substs, vstore) => {
267+
ty::ty_trait(def, ref substs, store) => {
256268
w.write_str(&"x[");
257269
w.write_str((cx.ds)(def));
258270
w.write_char('|');
259271
enc_substs(w, cx, (*substs));
260-
enc_vstore(w, cx, vstore);
272+
enc_trait_store(w, cx, store);
261273
w.write_char(']');
262274
}
263275
ty::ty_tup(ts) => {

src/librustc/middle/kind.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ pub fn check_cast_for_escaping_regions(
462462
pub fn check_kind_bounds_of_cast(cx: Context, source: @expr, target: @expr) {
463463
let target_ty = ty::expr_ty(cx.tcx, target);
464464
match ty::get(target_ty).sty {
465-
ty::ty_trait(_, _, ty::vstore_uniq) => {
465+
ty::ty_trait(_, _, ty::UniqTraitStore) => {
466466
let source_ty = ty::expr_ty(cx.tcx, source);
467467
if !ty::type_is_owned(cx.tcx, source_ty) {
468468
cx.tcx.sess.span_err(

src/librustc/middle/trans/base.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -802,13 +802,36 @@ pub fn trans_external_path(ccx: @CrateContext, did: ast::def_id, t: ty::t)
802802
pub fn invoke(bcx: block, llfn: ValueRef, +llargs: ~[ValueRef]) -> block {
803803
let _icx = bcx.insn_ctxt("invoke_");
804804
if bcx.unreachable { return bcx; }
805+
806+
match bcx.node_info {
807+
None => error!("invoke at ???"),
808+
Some(node_info) => {
809+
error!("invoke at %s",
810+
bcx.sess().codemap.span_to_str(node_info.span));
811+
}
812+
}
813+
805814
if need_invoke(bcx) {
806-
debug!("invoking");
815+
unsafe {
816+
debug!("invoking %x at %x",
817+
::core::cast::transmute(llfn),
818+
::core::cast::transmute(bcx.llbb));
819+
for llargs.each |&llarg| {
820+
debug!("arg: %x", ::core::cast::transmute(llarg));
821+
}
822+
}
807823
let normal_bcx = sub_block(bcx, ~"normal return");
808824
Invoke(bcx, llfn, llargs, normal_bcx.llbb, get_landing_pad(bcx));
809825
return normal_bcx;
810826
} else {
811-
debug!("calling");
827+
unsafe {
828+
debug!("calling %x at %x",
829+
::core::cast::transmute(llfn),
830+
::core::cast::transmute(bcx.llbb));
831+
for llargs.each |&llarg| {
832+
debug!("arg: %x", ::core::cast::transmute(llarg));
833+
}
834+
}
812835
Call(bcx, llfn, llargs);
813836
return bcx;
814837
}

src/librustc/middle/trans/common.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,17 +1033,19 @@ pub fn T_captured_tydescs(cx: @CrateContext, n: uint) -> TypeRef {
10331033
return T_struct(vec::from_elem::<TypeRef>(n, T_ptr(cx.tydesc_type)));
10341034
}
10351035

1036-
pub fn T_opaque_trait(cx: @CrateContext, vstore: ty::vstore) -> TypeRef {
1037-
match vstore {
1038-
ty::vstore_box => {
1036+
pub fn T_opaque_trait(cx: @CrateContext, store: ty::TraitStore) -> TypeRef {
1037+
match store {
1038+
ty::BoxTraitStore | ty::BareTraitStore => {
10391039
T_struct(~[T_ptr(cx.tydesc_type), T_opaque_box_ptr(cx)])
10401040
}
1041-
ty::vstore_uniq => {
1041+
ty::UniqTraitStore => {
10421042
T_struct(~[T_ptr(cx.tydesc_type),
10431043
T_unique_ptr(T_unique(cx, T_i8())),
10441044
T_ptr(cx.tydesc_type)])
10451045
}
1046-
_ => T_struct(~[T_ptr(cx.tydesc_type), T_ptr(T_i8())])
1046+
ty::RegionTraitStore(_) => {
1047+
T_struct(~[T_ptr(cx.tydesc_type), T_ptr(T_i8())])
1048+
}
10471049
}
10481050
}
10491051

src/librustc/middle/trans/expr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -678,9 +678,9 @@ fn trans_rvalue_dps_unadjusted(bcx: block, expr: @ast::expr,
678678
}
679679
ast::expr_cast(val, _) => {
680680
match ty::get(node_id_type(bcx, expr.id)).sty {
681-
ty::ty_trait(_, _, vstore) => {
681+
ty::ty_trait(_, _, store) => {
682682
return meth::trans_trait_cast(bcx, val, expr.id, dest,
683-
vstore);
683+
store);
684684
}
685685
_ => {
686686
bcx.tcx().sess.span_bug(expr.span,

src/librustc/middle/trans/glue.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -551,11 +551,12 @@ pub fn make_drop_glue(bcx: block, v0: ValueRef, t: ty::t) {
551551
ty::ty_closure(_) => {
552552
closure::make_closure_glue(bcx, v0, t, drop_ty)
553553
}
554-
ty::ty_trait(_, _, ty::vstore_box) => {
554+
ty::ty_trait(_, _, ty::BoxTraitStore) |
555+
ty::ty_trait(_, _, ty::BareTraitStore) => {
555556
let llbox = Load(bcx, GEPi(bcx, v0, [0u, 1u]));
556557
decr_refcnt_maybe_free(bcx, llbox, ty::mk_opaque_box(ccx.tcx))
557558
}
558-
ty::ty_trait(_, _, ty::vstore_uniq) => {
559+
ty::ty_trait(_, _, ty::UniqTraitStore) => {
559560
let lluniquevalue = GEPi(bcx, v0, [0, 1]);
560561
let lltydesc = Load(bcx, GEPi(bcx, v0, [0, 2]));
561562
call_tydesc_glue_full(bcx, lluniquevalue, lltydesc,
@@ -617,12 +618,13 @@ pub fn make_take_glue(bcx: block, v: ValueRef, t: ty::t) {
617618
ty::ty_closure(_) => {
618619
closure::make_closure_glue(bcx, v, t, take_ty)
619620
}
620-
ty::ty_trait(_, _, ty::vstore_box) => {
621+
ty::ty_trait(_, _, ty::BoxTraitStore) |
622+
ty::ty_trait(_, _, ty::BareTraitStore) => {
621623
let llbox = Load(bcx, GEPi(bcx, v, [0u, 1u]));
622624
incr_refcnt_of_boxed(bcx, llbox);
623625
bcx
624626
}
625-
ty::ty_trait(_, _, ty::vstore_uniq) => {
627+
ty::ty_trait(_, _, ty::UniqTraitStore) => {
626628
let llval = GEPi(bcx, v, [0, 1]);
627629
let lltydesc = Load(bcx, GEPi(bcx, v, [0, 2]));
628630
call_tydesc_glue_full(bcx, llval, lltydesc,

src/librustc/middle/trans/meth.rs

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -249,12 +249,12 @@ pub fn trans_method_callee(bcx: block,
249249
None => fail!(~"trans_method_callee: missing param_substs")
250250
}
251251
}
252-
typeck::method_trait(_, off, vstore) => {
252+
typeck::method_trait(_, off, store) => {
253253
trans_trait_callee(bcx,
254254
callee_id,
255255
off,
256256
self,
257-
vstore,
257+
store,
258258
mentry.explicit_self)
259259
}
260260
typeck::method_self(*) | typeck::method_super(*) => {
@@ -570,7 +570,7 @@ pub fn trans_trait_callee(bcx: block,
570570
callee_id: ast::node_id,
571571
n_method: uint,
572572
self_expr: @ast::expr,
573-
vstore: ty::vstore,
573+
store: ty::TraitStore,
574574
explicit_self: ast::self_ty_)
575575
-> Callee {
576576
//!
@@ -599,15 +599,15 @@ pub fn trans_trait_callee(bcx: block,
599599
callee_ty,
600600
n_method,
601601
llpair,
602-
vstore,
602+
store,
603603
explicit_self)
604604
}
605605
606606
pub fn trans_trait_callee_from_llval(bcx: block,
607607
callee_ty: ty::t,
608608
n_method: uint,
609609
llpair: ValueRef,
610-
vstore: ty::vstore,
610+
store: ty::TraitStore,
611611
explicit_self: ast::self_ty_)
612612
-> Callee {
613613
//!
@@ -641,16 +641,15 @@ pub fn trans_trait_callee_from_llval(bcx: block,
641641
}
642642
ast::sty_by_ref => {
643643
// We need to pass a pointer to a pointer to the payload.
644-
match vstore {
645-
ty::vstore_box | ty::vstore_uniq => {
644+
match store {
645+
ty::BoxTraitStore |
646+
ty::BareTraitStore |
647+
ty::UniqTraitStore => {
646648
llself = GEPi(bcx, llbox, [0u, abi::box_field_body]);
647649
}
648-
ty::vstore_slice(_) => {
650+
ty::RegionTraitStore(_) => {
649651
llself = llbox;
650652
}
651-
ty::vstore_fixed(*) => {
652-
bcx.tcx().sess.bug(~"vstore_fixed trait");
653-
}
654653
}
655654
656655
self_mode = ast::by_ref;
@@ -662,16 +661,15 @@ pub fn trans_trait_callee_from_llval(bcx: block,
662661
ast::sty_region(_) => {
663662
// As before, we need to pass a pointer to a pointer to the
664663
// payload.
665-
match vstore {
666-
ty::vstore_box | ty::vstore_uniq => {
664+
match store {
665+
ty::BoxTraitStore |
666+
ty::BareTraitStore |
667+
ty::UniqTraitStore => {
667668
llself = GEPi(bcx, llbox, [0u, abi::box_field_body]);
668669
}
669-
ty::vstore_slice(_) => {
670+
ty::RegionTraitStore(_) => {
670671
llself = llbox;
671672
}
672-
ty::vstore_fixed(*) => {
673-
bcx.tcx().sess.bug(~"vstore_fixed trait");
674-
}
675673
}
676674
677675
let llscratch = alloca(bcx, val_ty(llself));
@@ -687,8 +685,8 @@ pub fn trans_trait_callee_from_llval(bcx: block,
687685
bcx = glue::take_ty(bcx, llbox, callee_ty);
688686

689687
// Pass a pointer to the box.
690-
match vstore {
691-
ty::vstore_box => llself = llbox,
688+
match store {
689+
ty::BoxTraitStore | ty::BareTraitStore => llself = llbox,
692690
_ => bcx.tcx().sess.bug(~"@self receiver with non-@Trait")
693691
}
694692
@@ -700,8 +698,8 @@ pub fn trans_trait_callee_from_llval(bcx: block,
700698
}
701699
ast::sty_uniq(_) => {
702700
// Pass the unique pointer.
703-
match vstore {
704-
ty::vstore_uniq => llself = llbox,
701+
match store {
702+
ty::UniqTraitStore => llself = llbox,
705703
_ => bcx.tcx().sess.bug(~"~self receiver with non-~Trait")
706704
}
707705
@@ -796,7 +794,9 @@ pub fn make_impl_vtable(ccx: @CrateContext,
796794
// XXX: This should support multiple traits.
797795
let trt_id = driver::session::expect(
798796
tcx.sess,
799-
ty::ty_to_def_id(ty::impl_traits(tcx, impl_id, ty::vstore_box)[0]),
797+
ty::ty_to_def_id(ty::impl_traits(tcx,
798+
impl_id,
799+
ty::BoxTraitStore)[0]),
800800
|| ~"make_impl_vtable: non-trait-type implemented");
801801
802802
let has_tps = (*ty::lookup_item_type(ccx.tcx, impl_id).bounds).len() > 0u;
@@ -834,7 +834,7 @@ pub fn trans_trait_cast(bcx: block,
834834
val: @ast::expr,
835835
id: ast::node_id,
836836
dest: expr::Dest,
837-
vstore: ty::vstore)
837+
store: ty::TraitStore)
838838
-> block {
839839
let mut bcx = bcx;
840840
let _icx = bcx.insn_ctxt("impl::trans_cast");
@@ -849,16 +849,16 @@ pub fn trans_trait_cast(bcx: block,
849849
let ccx = bcx.ccx();
850850
let v_ty = expr_ty(bcx, val);
851851

852-
match vstore {
853-
ty::vstore_slice(*) | ty::vstore_box => {
852+
match store {
853+
ty::RegionTraitStore(_) | ty::BoxTraitStore | ty::BareTraitStore => {
854854
let mut llboxdest = GEPi(bcx, lldest, [0u, 1u]);
855855
// Just store the pointer into the pair.
856856
llboxdest = PointerCast(bcx,
857857
llboxdest,
858858
T_ptr(type_of(bcx.ccx(), v_ty)));
859859
bcx = expr::trans_into(bcx, val, SaveIn(llboxdest));
860860
}
861-
ty::vstore_uniq => {
861+
ty::UniqTraitStore => {
862862
// Translate the uniquely-owned value into the second element of
863863
// the triple. (The first element is the vtable.)
864864
let mut llvaldest = GEPi(bcx, lldest, [0, 1]);
@@ -874,10 +874,6 @@ pub fn trans_trait_cast(bcx: block,
874874
let lltydescdest = GEPi(bcx, lldest, [0, 2]);
875875
Store(bcx, tydesc.tydesc, lltydescdest);
876876
}
877-
_ => {
878-
bcx.tcx().sess.span_bug(val.span, ~"unexpected vstore in \
879-
trans_trait_cast");
880-
}
881877
}
882878

883879
// Store the vtable into the pair or triple.

src/librustc/middle/trans/monomorphize.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -286,14 +286,11 @@ pub fn normalize_for_monomorphization(tcx: ty::ctxt,
286286
ty::ty_closure(ref fty) => {
287287
Some(normalized_closure_ty(tcx, fty.sigil))
288288
}
289-
ty::ty_trait(_, _, ref vstore) => {
290-
let sigil = match *vstore {
291-
ty::vstore_uniq => ast::OwnedSigil,
292-
ty::vstore_box => ast::ManagedSigil,
293-
ty::vstore_slice(_) => ast::BorrowedSigil,
294-
ty::vstore_fixed(*) => {
295-
tcx.sess.bug(fmt!("ty_trait with vstore_fixed"));
296-
}
289+
ty::ty_trait(_, _, ref store) => {
290+
let sigil = match *store {
291+
ty::UniqTraitStore => ast::OwnedSigil,
292+
ty::BoxTraitStore | ty::BareTraitStore => ast::ManagedSigil,
293+
ty::RegionTraitStore(_) => ast::BorrowedSigil,
297294
};
298295

299296
// Traits have the same runtime representation as closures.

src/librustc/middle/trans/reflect.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,14 @@ pub impl Reflector {
9696
}
9797
let bool_ty = ty::mk_bool(tcx);
9898
let scratch = scratch_datum(bcx, bool_ty, false);
99-
// XXX: Should not be vstore_box!
99+
// XXX: Should not be BoxTraitStore!
100100
let bcx = callee::trans_call_inner(
101101
self.bcx, None, mth_ty, bool_ty,
102102
|bcx| meth::trans_trait_callee_from_llval(bcx,
103103
mth_ty,
104104
mth_idx,
105105
v,
106-
ty::vstore_box,
106+
ty::BoxTraitStore,
107107
ast::sty_region(
108108
ast::m_imm)),
109109
ArgVals(args), SaveIn(scratch.val), DontAutorefArg);

src/librustc/middle/trans/type_of.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ pub fn sizing_type_of(cx: @CrateContext, t: ty::t) -> TypeRef {
130130

131131
ty::ty_bare_fn(*) => T_ptr(T_i8()),
132132
ty::ty_closure(*) => T_struct(~[T_ptr(T_i8()), T_ptr(T_i8())]),
133-
ty::ty_trait(_, _, vstore) => T_opaque_trait(cx, vstore),
133+
ty::ty_trait(_, _, store) => T_opaque_trait(cx, store),
134134

135135
ty::ty_estr(ty::vstore_fixed(size)) => T_array(T_i8(), size),
136136
ty::ty_evec(mt, ty::vstore_fixed(size)) => {
@@ -234,7 +234,7 @@ pub fn type_of(cx: @CrateContext, t: ty::t) -> TypeRef {
234234

235235
ty::ty_bare_fn(_) => T_ptr(type_of_fn_from_ty(cx, t)),
236236
ty::ty_closure(_) => T_fn_pair(cx, type_of_fn_from_ty(cx, t)),
237-
ty::ty_trait(_, _, vstore) => T_opaque_trait(cx, vstore),
237+
ty::ty_trait(_, _, store) => T_opaque_trait(cx, store),
238238
ty::ty_type => T_ptr(cx.tydesc_type),
239239
ty::ty_tup(*) => {
240240
let repr = adt::represent_type(cx, t);

0 commit comments

Comments
 (0)