Skip to content

Commit 45bbb52

Browse files
committed
---
yaml --- r: 22343 b: refs/heads/snap-stage3 c: 04497ea h: refs/heads/master i: 22341: cf6cba8 22339: 078dfd8 22335: 0f663a0 v: v3
1 parent a8c4988 commit 45bbb52

File tree

18 files changed

+202
-70
lines changed

18 files changed

+202
-70
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: e430a699f2c60890d9b86069fd0c68a70ece7120
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: f8bc0d25455d7bfb299cd0e7693ee575f5dbce21
4+
refs/heads/snap-stage3: 04497ea7b9b9598faa7456e7de1304e9118d2bb0
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/rustc/metadata/encoder.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export metadata_encoding_version;
3434
export def_to_str;
3535
export encode_ctxt;
3636
export write_type;
37+
export write_vstore;
3738
export encode_def_id;
3839

3940
type abbrev_map = map::HashMap<ty::t, tyencode::ty_abbrev>;
@@ -180,6 +181,16 @@ fn write_type(ecx: @encode_ctxt, ebml_w: ebml::Writer, typ: ty::t) {
180181
tyencode::enc_ty(ebml_w.writer, ty_str_ctxt, typ);
181182
}
182183

184+
fn write_vstore(ecx: @encode_ctxt, ebml_w: ebml::Writer, vstore: ty::vstore) {
185+
let ty_str_ctxt =
186+
@{diag: ecx.diag,
187+
ds: def_to_str,
188+
tcx: ecx.tcx,
189+
reachable: |a| reachable(ecx, a),
190+
abbrevs: tyencode::ac_use_abbrevs(ecx.type_abbrevs)};
191+
tyencode::enc_vstore(ebml_w.writer, ty_str_ctxt, vstore);
192+
}
193+
183194
fn encode_type(ecx: @encode_ctxt, ebml_w: ebml::Writer, typ: ty::t) {
184195
ebml_w.start_tag(tag_items_data_item_type);
185196
write_type(ecx, ebml_w, typ);

branches/snap-stage3/src/rustc/metadata/tyencode.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export enc_ty;
1616
export enc_bounds;
1717
export enc_mode;
1818
export enc_arg;
19+
export enc_vstore;
1920

2021
type ctxt = {
2122
diag: span_handler,

branches/snap-stage3/src/rustc/middle/astencode.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,8 +490,8 @@ impl method_origin: tr {
490490
typeck::method_param(mp) => {
491491
typeck::method_param({trait_id:mp.trait_id.tr(xcx),.. mp})
492492
}
493-
typeck::method_trait(did, m) => {
494-
typeck::method_trait(did.tr(xcx), m)
493+
typeck::method_trait(did, m, vstore) => {
494+
typeck::method_trait(did.tr(xcx), m, vstore)
495495
}
496496
}
497497
}
@@ -631,6 +631,7 @@ impl @e::encode_ctxt: get_ty_str_ctxt {
631631
trait ebml_writer_helpers {
632632
fn emit_arg(ecx: @e::encode_ctxt, arg: ty::arg);
633633
fn emit_ty(ecx: @e::encode_ctxt, ty: ty::t);
634+
fn emit_vstore(ecx: @e::encode_ctxt, vstore: ty::vstore);
634635
fn emit_tys(ecx: @e::encode_ctxt, tys: ~[ty::t]);
635636
fn emit_bounds(ecx: @e::encode_ctxt, bs: ty::param_bounds);
636637
fn emit_tpbt(ecx: @e::encode_ctxt, tpbt: ty::ty_param_bounds_and_ty);
@@ -643,6 +644,12 @@ impl ebml::Writer: ebml_writer_helpers {
643644
}
644645
}
645646

647+
fn emit_vstore(ecx: @e::encode_ctxt, vstore: ty::vstore) {
648+
do self.emit_opaque {
649+
e::write_vstore(ecx, self, vstore)
650+
}
651+
}
652+
646653
fn emit_arg(ecx: @e::encode_ctxt, arg: ty::arg) {
647654
do self.emit_opaque {
648655
tyencode::enc_arg(self.writer, ecx.ty_str_ctxt(), arg);

branches/snap-stage3/src/rustc/middle/privacy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ fn check_crate(tcx: ty::ctxt, method_map: &method_map, crate: @ast::crate) {
8181
}
8282
}
8383
method_param({trait_id: trait_id, method_num: method_num, _}) |
84-
method_trait(trait_id, method_num) => {
84+
method_trait(trait_id, method_num, _) => {
8585
if trait_id.crate == local_crate {
8686
match tcx.items.find(trait_id.node) {
8787
Some(node_item(item, _)) => {

branches/snap-stage3/src/rustc/middle/trans/common.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -963,8 +963,13 @@ fn T_captured_tydescs(cx: @crate_ctxt, n: uint) -> TypeRef {
963963
return T_struct(vec::from_elem::<TypeRef>(n, T_ptr(cx.tydesc_type)));
964964
}
965965

966-
fn T_opaque_trait(cx: @crate_ctxt) -> TypeRef {
967-
T_struct(~[T_ptr(cx.tydesc_type), T_opaque_box_ptr(cx)])
966+
fn T_opaque_trait(cx: @crate_ctxt, vstore: ty::vstore) -> TypeRef {
967+
match vstore {
968+
ty::vstore_box =>
969+
T_struct(~[T_ptr(cx.tydesc_type), T_opaque_box_ptr(cx)]),
970+
_ =>
971+
T_struct(~[T_ptr(cx.tydesc_type), T_ptr(T_i8())])
972+
}
968973
}
969974

970975
fn T_opaque_port_ptr() -> TypeRef { return T_ptr(T_i8()); }

branches/snap-stage3/src/rustc/middle/trans/glue.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,10 +477,13 @@ fn make_drop_glue(bcx: block, v0: ValueRef, t: ty::t) {
477477
ty::ty_fn(_) => {
478478
closure::make_fn_glue(bcx, v0, t, drop_ty)
479479
}
480-
ty::ty_trait(_, _, _) => {
480+
ty::ty_trait(_, _, ty::vstore_box) => {
481481
let llbox = Load(bcx, GEPi(bcx, v0, [0u, 1u]));
482482
decr_refcnt_maybe_free(bcx, llbox, ty::mk_opaque_box(ccx.tcx))
483483
}
484+
ty::ty_trait(_, _, ty::vstore_uniq) => {
485+
ccx.tcx.sess.unimpl(~"drop of unique trait");
486+
}
484487
ty::ty_opaque_closure_ptr(ck) => {
485488
closure::make_opaque_cbox_drop_glue(bcx, ck, v0)
486489
}

branches/snap-stage3/src/rustc/middle/trans/meth.rs

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ fn trans_method_callee(bcx: block, callee_id: ast::node_id,
142142
None => fail ~"trans_method_callee: missing param_substs"
143143
}
144144
}
145-
typeck::method_trait(_, off) => {
146-
trans_trait_callee(bcx, callee_id, off, self)
145+
typeck::method_trait(_, off, vstore) => {
146+
trans_trait_callee(bcx, callee_id, off, self, vstore)
147147
}
148148
}
149149
}
@@ -288,8 +288,8 @@ fn trans_monomorphized_callee(bcx: block,
288288
})
289289
}
290290
}
291-
typeck::vtable_trait(*) => {
292-
trans_trait_callee(bcx, callee_id, n_method, base)
291+
typeck::vtable_trait(_, _) => {
292+
trans_trait_callee(bcx, callee_id, n_method, base, ty::vstore_box)
293293
}
294294
typeck::vtable_param(*) => {
295295
fail ~"vtable_param left in monomorphized function's vtable substs";
@@ -390,30 +390,32 @@ fn combine_impl_and_methods_origins(bcx: block,
390390
fn trans_trait_callee(bcx: block,
391391
callee_id: ast::node_id,
392392
n_method: uint,
393-
self_expr: @ast::expr)
393+
self_expr: @ast::expr,
394+
vstore: ty::vstore)
394395
-> Callee
395396
{
396397
//!
397398
//
398399
// Create a method callee where the method is coming from a trait
399400
// instance (e.g., @Trait type). In this case, we must pull the
400401
// fn pointer out of the vtable that is packaged up with the
401-
// @Trait instance. @Traits are represented as a pair, so we first
402-
// evaluate the self expression (expected a by-ref result) and then
402+
// @/~/&Trait instance. @/~/&Traits are represented as a pair, so we
403+
// first evaluate the self expression (expected a by-ref result) and then
403404
// extract the self data and vtable out of the pair.
404405

405406
let _icx = bcx.insn_ctxt("impl::trans_trait_callee");
406407
let mut bcx = bcx;
407408
let self_datum = unpack_datum!(bcx, expr::trans_to_datum(bcx, self_expr));
408409
let llpair = self_datum.to_ref_llval(bcx);
409410
let callee_ty = node_id_type(bcx, callee_id);
410-
trans_trait_callee_from_llval(bcx, callee_ty, n_method, llpair)
411+
trans_trait_callee_from_llval(bcx, callee_ty, n_method, llpair, vstore)
411412
}
412413

413414
fn trans_trait_callee_from_llval(bcx: block,
414415
callee_ty: ty::t,
415416
n_method: uint,
416-
llpair: ValueRef)
417+
llpair: ValueRef,
418+
vstore: ty::vstore)
417419
-> Callee
418420
{
419421
//!
@@ -431,9 +433,21 @@ fn trans_trait_callee_from_llval(bcx: block,
431433
GEPi(bcx, llpair, [0u, 0u]),
432434
T_ptr(T_ptr(T_vtable()))));
433435

434-
// Load the box from the @Trait pair and GEP over the box header:
436+
// Load the box from the @Trait pair and GEP over the box header if
437+
// necessary:
438+
let llself;
435439
let llbox = Load(bcx, GEPi(bcx, llpair, [0u, 1u]));
436-
let llself = GEPi(bcx, llbox, [0u, abi::box_field_body]);
440+
match vstore {
441+
ty::vstore_box | ty::vstore_uniq => {
442+
llself = GEPi(bcx, llbox, [0u, abi::box_field_body]);
443+
}
444+
ty::vstore_slice(_) => {
445+
llself = llbox;
446+
}
447+
ty::vstore_fixed(*) => {
448+
bcx.tcx().sess.bug(~"vstore_fixed trait");
449+
}
450+
}
437451

438452
// Load the function from the vtable and cast it to the expected type.
439453
let llcallee_ty = type_of::type_of_fn_from_ty(ccx, callee_ty);
@@ -503,7 +517,7 @@ fn make_impl_vtable(ccx: @crate_ctxt, impl_id: ast::def_id, substs: ~[ty::t],
503517
// XXX: This should support multiple traits.
504518
let trt_id = driver::session::expect(
505519
tcx.sess,
506-
ty::ty_to_def_id(ty::impl_traits(tcx, impl_id)[0]),
520+
ty::ty_to_def_id(ty::impl_traits(tcx, impl_id, ty::vstore_box)[0]),
507521
|| ~"make_impl_vtable: non-trait-type implemented");
508522

509523
let has_tps = (*ty::lookup_item_type(ccx.tcx, impl_id).bounds).len() > 0u;

branches/snap-stage3/src/rustc/middle/trans/reflect.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,12 @@ impl reflector {
7070
}
7171
let bool_ty = ty::mk_bool(tcx);
7272
let scratch = scratch_datum(bcx, bool_ty, false);
73+
// XXX: Should not be vstore_box!
7374
let bcx = callee::trans_call_inner(
7475
self.bcx, None, mth_ty, bool_ty,
7576
|bcx| meth::trans_trait_callee_from_llval(bcx, mth_ty,
76-
mth_idx, v),
77+
mth_idx, v,
78+
ty::vstore_box),
7779
ArgVals(args), SaveIn(scratch.val), DontAutorefArg);
7880
let result = scratch.to_value_llval(bcx);
7981
let next_bcx = sub_block(bcx, ~"next");

branches/snap-stage3/src/rustc/middle/trans/type_of.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ fn type_of(cx: @crate_ctxt, t: ty::t) -> TypeRef {
159159
T_struct(~[T_struct(tys)])
160160
}
161161
ty::ty_fn(_) => T_fn_pair(cx, type_of_fn_from_ty(cx, t)),
162-
ty::ty_trait(_, _, _) => T_opaque_trait(cx),
162+
ty::ty_trait(_, _, vstore) => T_opaque_trait(cx, vstore),
163163
ty::ty_type => T_ptr(cx.tydesc_type),
164164
ty::ty_tup(elts) => {
165165
let mut tys = ~[];

branches/snap-stage3/src/rustc/middle/trans/type_use.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ fn mark_for_expr(cx: ctx, e: @expr) {
247247
typeck::method_param({param_num: param, _}) => {
248248
cx.uses[param] |= use_tydesc;
249249
}
250-
typeck::method_trait(_, _) => (),
250+
typeck::method_trait(*) => (),
251251
}
252252
}
253253
}

branches/snap-stage3/src/rustc/middle/ty.rs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export ty_estr, mk_estr, type_is_str;
9090
export ty_evec, mk_evec, type_is_vec;
9191
export ty_unboxed_vec, mk_unboxed_vec, mk_mut_unboxed_vec;
9292
export vstore, vstore_fixed, vstore_uniq, vstore_box, vstore_slice;
93+
export serialize_vstore, deserialize_vstore;
9394
export ty_nil, mk_nil, type_is_nil;
9495
export ty_trait, mk_trait;
9596
export ty_param, mk_param, ty_params_to_tys;
@@ -217,6 +218,7 @@ type method = {ident: ast::ident,
217218

218219
type mt = {ty: t, mutbl: ast::mutability};
219220

221+
#[auto_serialize]
220222
enum vstore {
221223
vstore_fixed(uint),
222224
vstore_uniq,
@@ -1624,7 +1626,10 @@ fn type_needs_drop(cx: ctxt, ty: t) -> bool {
16241626
ty_evec(_, vstore_uniq) |
16251627
ty_evec(_, vstore_box) => true,
16261628
1627-
ty_trait(*) => true,
1629+
ty_trait(_, _, vstore_box) |
1630+
ty_trait(_, _, vstore_uniq) => true,
1631+
ty_trait(_, _, vstore_fixed(_)) |
1632+
ty_trait(_, _, vstore_slice(_)) => false,
16281633
16291634
ty_param(*) | ty_infer(*) => true,
16301635
@@ -2821,7 +2826,7 @@ fn method_call_bounds(tcx: ctxt, method_map: typeck::method_map,
28212826
}
28222827
typeck::method_param({trait_id:trt_id,
28232828
method_num:n_mth, _}) |
2824-
typeck::method_trait(trt_id, n_mth) => {
2829+
typeck::method_trait(trt_id, n_mth, _) => {
28252830
// ...trait methods bounds, in contrast, include only the
28262831
// method bounds, so we must preprend the tps from the
28272832
// trait itself. This ought to be harmonized.
@@ -3362,7 +3367,15 @@ fn trait_methods(cx: ctxt, id: ast::def_id) -> @~[method] {
33623367
/*
33633368
Could this return a list of (def_id, substs) pairs?
33643369
*/
3365-
fn impl_traits(cx: ctxt, id: ast::def_id) -> ~[t] {
3370+
fn impl_traits(cx: ctxt, id: ast::def_id, vstore: vstore) -> ~[t] {
3371+
fn vstoreify(cx: ctxt, ty: t, vstore: vstore) -> t {
3372+
match ty::get(ty).sty {
3373+
ty::ty_trait(_, _, trait_vstore) if vstore == trait_vstore => ty,
3374+
ty::ty_trait(did, substs, _) => mk_trait(cx, did, substs, vstore),
3375+
_ => cx.sess.bug(~"impl_traits: not a trait")
3376+
}
3377+
}
3378+
33663379
if id.crate == ast::local_crate {
33673380
debug!("(impl_traits) searching for trait impl %?", id);
33683381
match cx.items.find(id.node) {
@@ -3372,19 +3385,23 @@ fn impl_traits(cx: ctxt, id: ast::def_id) -> ~[t] {
33723385
_)) => {
33733386

33743387
do option::map_default(&opt_trait, ~[]) |trait_ref| {
3375-
~[node_id_to_type(cx, trait_ref.ref_id)]
3388+
~[vstoreify(cx,
3389+
node_id_to_type(cx, trait_ref.ref_id),
3390+
vstore)]
33763391
}
33773392
}
33783393
Some(ast_map::node_item(@{node: ast::item_class(sd,_),
33793394
_},_)) => {
33803395
do vec::map(sd.traits) |trait_ref| {
3381-
node_id_to_type(cx, trait_ref.ref_id)
3396+
vstoreify(cx, node_id_to_type(cx, trait_ref.ref_id),
3397+
vstore)
33823398
}
33833399
}
33843400
_ => ~[]
33853401
}
33863402
} else {
3387-
csearch::get_impl_traits(cx, id)
3403+
vec::map(csearch::get_impl_traits(cx, id),
3404+
|x| vstoreify(cx, *x, vstore))
33883405
}
33893406
}
33903407

branches/snap-stage3/src/rustc/middle/typeck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ enum method_origin {
8686
method_param(method_param),
8787

8888
// method invoked on a trait instance
89-
method_trait(ast::def_id, uint),
89+
method_trait(ast::def_id, uint, ty::vstore),
9090
}
9191

9292
// details for a method invoked with a receiver whose type is a type parameter

branches/snap-stage3/src/rustc/middle/typeck/astconv.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -189,16 +189,19 @@ fn ast_ty_to_ty<AC: ast_conv, RS: region_scope Copy Owned>(
189189
type_def_id, path);
190190
match ty::get(result.ty).sty {
191191
ty::ty_trait(trait_def_id, substs, _) => {
192-
if vst != ty::vstore_box {
193-
tcx.sess.span_unimpl(path.span,
194-
~"`~trait` and `&trait` are \
195-
unimplemented; use \
196-
`@trait` instead for now");
192+
match vst {
193+
ty::vstore_box | ty::vstore_slice(*) => {}
194+
_ => {
195+
tcx.sess.span_unimpl(path.span,
196+
~"`~trait` is \
197+
unimplemented; use \
198+
`@trait` instead for \
199+
now");
200+
}
197201
}
198202
return ty::mk_trait(tcx, trait_def_id, substs, vst);
199203
}
200-
_ =>
201-
{}
204+
_ => {}
202205
}
203206
}
204207
_ => ()

0 commit comments

Comments
 (0)