Skip to content

Commit daad5c8

Browse files
committed
---
yaml --- r: 51028 b: refs/heads/try c: 2f1ab3a h: refs/heads/master v: v3
1 parent 12cb301 commit daad5c8

File tree

18 files changed

+286
-22
lines changed

18 files changed

+286
-22
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 5f13e9ccc2e3328d4cd8ca49f84e6840dd998346
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: f7a2371c176663d59062ec5158f39faecba45768
5-
refs/heads/try: 2c17ff7dbc667a7d579b02b86d4c08a1093683fd
5+
refs/heads/try: 2f1ab3a7fad9aeb871479470785250fe2e923e19
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/librustc/metadata/decoder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,7 @@ fn get_self_ty(item: ebml::Doc) -> ast::self_ty_ {
630630
let self_ty_kind = string[0];
631631
match self_ty_kind as char {
632632
's' => { return ast::sty_static; }
633+
'r' => { return ast::sty_by_ref; }
633634
'v' => { return ast::sty_value; }
634635
'@' => { return ast::sty_box(get_mutability(string[1])); }
635636
'~' => { return ast::sty_uniq(get_mutability(string[1])); }

branches/try/src/librustc/metadata/encoder.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,9 @@ fn encode_self_type(ebml_w: writer::Encoder, self_type: ast::self_ty_) {
410410
sty_static => {
411411
ebml_w.writer.write(&[ 's' as u8 ]);
412412
}
413+
sty_by_ref => {
414+
ebml_w.writer.write(&[ 'r' as u8 ]);
415+
}
413416
sty_value => {
414417
ebml_w.writer.write(&[ 'v' as u8 ]);
415418
}

branches/try/src/librustc/middle/borrowck/gather_loans.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,21 @@ fn req_loans_in_expr(ex: @ast::expr,
180180
}
181181
}
182182

183+
match self.bccx.method_map.find(&ex.id) {
184+
Some(ref method_map_entry) => {
185+
match (*method_map_entry).explicit_self {
186+
ast::sty_by_ref => {
187+
let rcvr_cmt = self.bccx.cat_expr(rcvr);
188+
self.guarantee_valid(rcvr_cmt, m_imm, scope_r);
189+
}
190+
_ => {} // Nothing to do.
191+
}
192+
}
193+
None => {
194+
self.tcx().sess.span_bug(ex.span, ~"no method map entry");
195+
}
196+
}
197+
183198
visit::visit_expr(ex, self, vt);
184199
}
185200

branches/try/src/librustc/middle/liveness.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,11 @@ fn visit_fn(fk: &visit::fn_kind,
467467
match *fk {
468468
fk_method(_, _, method) => {
469469
match method.self_ty.node {
470+
sty_by_ref => {
471+
fn_maps.add_variable(Arg(method.self_id,
472+
special_idents::self_,
473+
by_ref));
474+
}
470475
sty_value | sty_region(*) | sty_box(_) | sty_uniq(_) => {
471476
fn_maps.add_variable(Arg(method.self_id,
472477
special_idents::self_,

branches/try/src/librustc/middle/moves.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,20 @@ pub impl VisitContext {
737737
receiver_expr: @expr,
738738
visitor: vt<VisitContext>)
739739
{
740-
self.use_fn_arg(by_copy, receiver_expr, visitor);
740+
let callee_mode = match self.method_map.find(&expr_id) {
741+
Some(ref method_map_entry) => {
742+
match method_map_entry.explicit_self {
743+
sty_by_ref => by_ref,
744+
_ => by_copy
745+
}
746+
}
747+
None => {
748+
self.tcx.sess.span_bug(
749+
span,
750+
~"no method map entry");
751+
}
752+
};
753+
self.use_fn_arg(callee_mode, receiver_expr, visitor);
741754
}
742755

743756
fn use_fn_args(&self,

branches/try/src/librustc/middle/resolve.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ use syntax::ast::{named_field, ne, neg, node_id, pat, pat_enum, pat_ident};
5050
use syntax::ast::{path, pat_box, pat_lit, pat_range, pat_struct};
5151
use syntax::ast::{pat_tup, pat_uniq, pat_wild, prim_ty, private, provided};
5252
use syntax::ast::{public, required, rem, self_ty_, shl, shr, stmt_decl};
53-
use syntax::ast::{struct_dtor, struct_field, struct_variant_kind};
53+
use syntax::ast::{struct_dtor, struct_field, struct_variant_kind, sty_by_ref};
5454
use syntax::ast::{sty_static, subtract, trait_ref, tuple_variant_kind, Ty};
5555
use syntax::ast::{ty_bool, ty_char, ty_f, ty_f32, ty_f64, ty_float, ty_i};
5656
use syntax::ast::{ty_i16, ty_i32, ty_i64, ty_i8, ty_int, TyParam, ty_path};
@@ -3792,6 +3792,7 @@ pub impl Resolver {
37923792
// we only have self ty if it is a non static method
37933793
let self_binding = match method.self_ty.node {
37943794
sty_static => { NoSelfBinding }
3795+
sty_by_ref => { HasSelfBinding(method.self_id, true) }
37953796
_ => { HasSelfBinding(method.self_id, false) }
37963797
};
37973798

branches/try/src/librustc/middle/trans/meth.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ pub fn trans_trait_callee(bcx: block,
596596
597597
let llpair = match explicit_self {
598598
ast::sty_region(*) => Load(bcx, llpair),
599-
ast::sty_static | ast::sty_value |
599+
ast::sty_static | ast::sty_by_ref | ast::sty_value |
600600
ast::sty_box(_) | ast::sty_uniq(_) => llpair
601601
};
602602
@@ -645,6 +645,21 @@ pub fn trans_trait_callee_from_llval(bcx: block,
645645
ast::sty_static => {
646646
bcx.tcx().sess.bug(~"shouldn't see static method here");
647647
}
648+
ast::sty_by_ref => {
649+
// We need to pass a pointer to a pointer to the payload.
650+
match store {
651+
ty::BoxTraitStore |
652+
ty::BareTraitStore |
653+
ty::UniqTraitStore => {
654+
llself = GEPi(bcx, llbox, [0u, abi::box_field_body]);
655+
}
656+
ty::RegionTraitStore(_) => {
657+
llself = llbox;
658+
}
659+
}
660+
661+
self_mode = ast::by_ref;
662+
}
648663
ast::sty_value => {
649664
bcx.tcx().sess.bug(~"methods with by-value self should not be \
650665
called on objects");

branches/try/src/librustc/middle/typeck/check/method.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ use core::hashmap::linear::LinearSet;
9999
use core::result;
100100
use core::uint;
101101
use core::vec;
102-
use syntax::ast::{def_id, sty_value, sty_region, sty_box};
102+
use syntax::ast::{def_id, sty_by_ref, sty_value, sty_region, sty_box};
103103
use syntax::ast::{sty_uniq, sty_static, node_id, by_copy, by_ref};
104104
use syntax::ast::{m_const, m_mutbl, m_imm};
105105
use syntax::ast;
@@ -527,7 +527,7 @@ pub impl<'self> LookupContext<'self> {
527527
ast::sty_region(_) => {
528528
return; // inapplicable
529529
}
530-
ast::sty_region(_) => vstore_slice(r)
530+
ast::sty_by_ref | ast::sty_region(_) => vstore_slice(r)
531531
ast::sty_box(_) => vstore_box, // XXX NDM mutability
532532
ast::sty_uniq(_) => vstore_uniq
533533
}
@@ -741,7 +741,7 @@ pub impl<'self> LookupContext<'self> {
741741
// shouldn't really have to be.
742742
let rcvr_substs = {
743743
match self_decl {
744-
sty_static | sty_value |
744+
sty_static | sty_value | sty_by_ref |
745745
sty_box(_) | sty_uniq(_) => {
746746
self_substs
747747
}
@@ -1327,7 +1327,7 @@ pub fn transform_self_type_for_method(tcx: ty::ctxt,
13271327
tcx.sess.bug(~"calling transform_self_type_for_method on \
13281328
static method");
13291329
}
1330-
sty_value => {
1330+
sty_by_ref | sty_value => {
13311331
impl_ty
13321332
}
13331333
sty_region(_, mutability) => {

branches/try/src/librustc/middle/typeck/check/mod.rs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1064,7 +1064,44 @@ pub fn impl_self_ty(vcx: &VtableContext,
10641064
-> ty_param_substs_and_ty {
10651065
let tcx = vcx.tcx();
10661066

1067-
let (n_tps, region_param, raw_ty) = {
1067+
let (n_tps, region_param, raw_ty) = if did.crate == ast::local_crate {
1068+
let region_param = tcx.region_paramd_items.find(&did.node).
1069+
map_consume(|x| *x);
1070+
match tcx.items.find(&did.node) {
1071+
Some(&ast_map::node_item(@ast::item {
1072+
node: ast::item_impl(ref ts, _, st, _),
1073+
_
1074+
}, _)) => {
1075+
let region_parameterization =
1076+
RegionParameterization::from_variance_and_generics(
1077+
region_param,
1078+
ts);
1079+
(ts.ty_params.len(),
1080+
region_param,
1081+
vcx.ccx.to_ty(&rscope::type_rscope(region_parameterization), st))
1082+
}
1083+
Some(&ast_map::node_item(@ast::item {
1084+
node: ast::item_struct(_, ref ts),
1085+
id: class_id,
1086+
_
1087+
},_)) => {
1088+
/* If the impl is a class, the self ty is just the class ty
1089+
(doing a no-op subst for the ty params; in the next step,
1090+
we substitute in fresh vars for them)
1091+
*/
1092+
(ts.ty_params.len(),
1093+
region_param,
1094+
ty::mk_struct(tcx, local_def(class_id),
1095+
substs {
1096+
self_r: rscope::bound_self_region(region_param),
1097+
self_ty: None,
1098+
tps: ty::ty_params_to_tys(tcx, ts)
1099+
}))
1100+
}
1101+
_ => { tcx.sess.bug(~"impl_self_ty: unbound item or item that \
1102+
doesn't have a self_ty"); }
1103+
}
1104+
} else {
10681105
let ity = ty::lookup_item_type(tcx, did);
10691106
(vec::len(*ity.bounds), ity.region_param, ity.ty)
10701107
};

branches/try/src/libsyntax/ast.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,7 @@ impl to_bytes::IterBytes for ret_style {
10031003
#[deriving(Eq)]
10041004
pub enum self_ty_ {
10051005
sty_static, // no self
1006+
sty_by_ref, // ``
10061007
sty_value, // `self`
10071008
sty_region(Option<@Lifetime>, mutability), // `&'lt self`
10081009
sty_box(mutability), // `@self`

branches/try/src/libsyntax/ext/deriving/clone.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use ast::{item_enum, item_impl, item_struct, Generics};
1717
use ast::{m_imm, meta_item, method};
1818
use ast::{named_field, or, pat, pat_ident, pat_wild, public, pure_fn};
1919
use ast::{stmt, struct_def, struct_variant_kind};
20-
use ast::{sty_region, tuple_variant_kind, ty_nil, TyParam};
20+
use ast::{sty_by_ref, sty_region, tuple_variant_kind, ty_nil, TyParam};
2121
use ast::{TyParamBound, ty_path, ty_rptr, unnamed_field, variant};
2222
use ext::base::ext_ctxt;
2323
use ext::build;

branches/try/src/libsyntax/ext/deriving/eq.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use ast::{item_enum, item_impl, item_struct, Generics};
1717
use ast::{m_imm, meta_item, method};
1818
use ast::{named_field, or, pat, pat_ident, pat_wild, public, pure_fn};
1919
use ast::{stmt, struct_def, struct_variant_kind};
20-
use ast::{sty_region, tuple_variant_kind, ty_nil, TyParam};
20+
use ast::{sty_by_ref, sty_region, tuple_variant_kind, ty_nil, TyParam};
2121
use ast::{TyParamBound, ty_path, ty_rptr, unnamed_field, variant};
2222
use ext::base::ext_ctxt;
2323
use ext::build;

branches/try/src/libsyntax/ext/deriving/iter_bytes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use ast::{item_enum, item_impl, item_struct, Generics};
1717
use ast::{m_imm, meta_item, method};
1818
use ast::{named_field, or, pat, pat_ident, pat_wild, public, pure_fn};
1919
use ast::{stmt, struct_def, struct_variant_kind};
20-
use ast::{sty_region, tuple_variant_kind, ty_nil, TyParam};
20+
use ast::{sty_by_ref, sty_region, tuple_variant_kind, ty_nil, TyParam};
2121
use ast::{TyParamBound, ty_path, ty_rptr, unnamed_field, variant};
2222
use ext::base::ext_ctxt;
2323
use ext::build;

branches/try/src/libsyntax/ext/deriving/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use ast::{item_enum, item_impl, item_struct, Generics};
2020
use ast::{m_imm, meta_item, method};
2121
use ast::{named_field, or, pat, pat_ident, pat_wild, public, pure_fn};
2222
use ast::{stmt, struct_def, struct_variant_kind};
23-
use ast::{sty_region, tuple_variant_kind, ty_nil, TyParam};
23+
use ast::{sty_by_ref, sty_region, tuple_variant_kind, ty_nil, TyParam};
2424
use ast::{TyParamBound, ty_path, ty_rptr, unnamed_field, variant};
2525
use ext::base::ext_ctxt;
2626
use ext::build;

0 commit comments

Comments
 (0)