Skip to content

Commit b573e96

Browse files
committed
---
yaml --- r: 49087 b: refs/heads/snap-stage3 c: e01cf3c h: refs/heads/master i: 49085: ed98ff5 49083: 5d8554d 49079: 3173548 49071: e3d18f8 49055: f2a997e 49023: c4fbbd8 v: v3
1 parent 9c7d241 commit b573e96

40 files changed

+563
-121
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: 3bbcac322669cff3abde5be937cc4ec3860f3985
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 069529bc5cc14f63035609cdfae5b21ca7999d4b
4+
refs/heads/snap-stage3: e01cf3caf534a5fe7767fef9e14e8cde2f63f1d2
55
refs/heads/try: 2a8fb58d79e685d5ca07b039badcf2ae3ef077ea
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libcore/ops.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,5 @@ pub trait Shr<RHS,Result> {
7777

7878
#[lang="index"]
7979
pub trait Index<Index,Result> {
80-
fn index(&self, index: &Index) -> Result;
80+
fn index(&self, index: Index) -> Result;
8181
}

branches/snap-stage3/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/snap-stage3/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/snap-stage3/src/librustc/middle/astencode.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ fn simplify_ast(ii: ast::inlined_item) -> ast::inlined_item {
342342
}
343343
344344
fn decode_ast(par_doc: ebml::Doc) -> ast::inlined_item {
345-
let chi_doc = par_doc.get(c::tag_tree as uint);
345+
let chi_doc = par_doc[c::tag_tree as uint];
346346
let d = &reader::Decoder(chi_doc);
347347
Decodable::decode(d)
348348
}
@@ -1089,9 +1089,9 @@ impl ebml_decoder_decoder_helpers for reader::Decoder {
10891089
fn decode_side_tables(xcx: @ExtendedDecodeContext,
10901090
ast_doc: ebml::Doc) {
10911091
let dcx = xcx.dcx;
1092-
let tbl_doc = ast_doc.get(c::tag_table as uint);
1092+
let tbl_doc = ast_doc[c::tag_table as uint];
10931093
for reader::docs(tbl_doc) |tag, entry_doc| {
1094-
let id0 = entry_doc.get(c::tag_table_id as uint).as_int();
1094+
let id0 = entry_doc[c::tag_table_id as uint].as_int();
10951095
let id = xcx.tr_id(id0);
10961096
10971097
debug!(">> Side table document with tag 0x%x \
@@ -1103,7 +1103,7 @@ fn decode_side_tables(xcx: @ExtendedDecodeContext,
11031103
} else if tag == (c::tag_table_moves_map as uint) {
11041104
dcx.maps.moves_map.insert(id);
11051105
} else {
1106-
let val_doc = entry_doc.get(c::tag_table_val as uint);
1106+
let val_doc = entry_doc[c::tag_table_val as uint];
11071107
let val_dsr = &reader::Decoder(val_doc);
11081108
if tag == (c::tag_table_def as uint) {
11091109
let def = decode_def(xcx, val_doc);
@@ -1172,7 +1172,7 @@ fn encode_item_ast(ebml_w: writer::Encoder, item: @ast::item) {
11721172
11731173
#[cfg(test)]
11741174
fn decode_item_ast(par_doc: ebml::Doc) -> @ast::item {
1175-
let chi_doc = par_doc.get(c::tag_tree as uint);
1175+
let chi_doc = par_doc[c::tag_tree as uint];
11761176
let d = &reader::Decoder(chi_doc);
11771177
@Decodable::decode(d)
11781178
}

branches/snap-stage3/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/snap-stage3/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/snap-stage3/src/librustc/middle/moves.rs

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ pub impl VisitContext {
436436

437437
expr_unary(deref, base) => { // *base
438438
if !self.use_overloaded_operator(
439-
expr, base, [], visitor)
439+
expr, DontDerefArgs, base, [], visitor)
440440
{
441441
// Moving out of *base moves out of base.
442442
self.use_expr(base, comp_mode, visitor);
@@ -450,7 +450,7 @@ pub impl VisitContext {
450450

451451
expr_index(lhs, rhs) => { // lhs[rhs]
452452
if !self.use_overloaded_operator(
453-
expr, lhs, [rhs], visitor)
453+
expr, DontDerefArgs, lhs, [rhs], visitor)
454454
{
455455
self.use_expr(lhs, comp_mode, visitor);
456456
self.consume_expr(rhs, visitor);
@@ -579,15 +579,15 @@ pub impl VisitContext {
579579

580580
expr_unary(_, lhs) => {
581581
if !self.use_overloaded_operator(
582-
expr, lhs, [], visitor)
582+
expr, DontDerefArgs, lhs, [], visitor)
583583
{
584584
self.consume_expr(lhs, visitor);
585585
}
586586
}
587587

588588
expr_binary(_, lhs, rhs) => {
589589
if !self.use_overloaded_operator(
590-
expr, lhs, [rhs], visitor)
590+
expr, DoDerefArgs, lhs, [rhs], visitor)
591591
{
592592
self.consume_expr(lhs, visitor);
593593
self.consume_expr(rhs, visitor);
@@ -659,6 +659,7 @@ pub impl VisitContext {
659659

660660
fn use_overloaded_operator(&self,
661661
expr: @expr,
662+
deref_args: DerefArgs,
662663
receiver_expr: @expr,
663664
arg_exprs: &[@expr],
664665
visitor: vt<VisitContext>) -> bool
@@ -669,10 +670,21 @@ pub impl VisitContext {
669670

670671
self.use_receiver(expr.id, expr.span, receiver_expr, visitor);
671672

672-
// for overloaded operatrs, we are always passing in a
673-
// borrowed pointer, so it's always read mode:
674-
for arg_exprs.each |arg_expr| {
675-
self.use_expr(*arg_expr, Read, visitor);
673+
// The deref_args stuff should eventually be converted into
674+
// adjustments. Moreover, it should eventually be applied
675+
// consistently to all overloaded operators. But that's not
676+
// how it is today.
677+
match deref_args {
678+
DoDerefArgs => {
679+
// we are always passing in a borrowed pointer,
680+
// so it's always read mode:
681+
for arg_exprs.each |arg_expr| {
682+
self.use_expr(*arg_expr, Read, visitor);
683+
}
684+
}
685+
DontDerefArgs => {
686+
self.use_fn_args(expr.callee_id, arg_exprs, visitor);
687+
}
676688
}
677689

678690
return true;
@@ -725,7 +737,20 @@ pub impl VisitContext {
725737
receiver_expr: @expr,
726738
visitor: vt<VisitContext>)
727739
{
728-
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);
729754
}
730755

731756
fn use_fn_args(&self,

branches/snap-stage3/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/snap-stage3/src/librustc/middle/trans/expr.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -766,15 +766,18 @@ fn trans_rvalue_dps_unadjusted(bcx: block, expr: @ast::expr,
766766
}
767767
ast::expr_binary(_, lhs, rhs) => {
768768
// if not overloaded, would be RvalueDatumExpr
769-
return trans_overloaded_op(bcx, expr, lhs, ~[rhs], dest);
769+
return trans_overloaded_op(bcx, expr, lhs, ~[rhs], dest,
770+
DoAutorefArg);
770771
}
771772
ast::expr_unary(_, subexpr) => {
772773
// if not overloaded, would be RvalueDatumExpr
773-
return trans_overloaded_op(bcx, expr, subexpr, ~[], dest);
774+
return trans_overloaded_op(bcx, expr, subexpr, ~[], dest,
775+
DontAutorefArg);
774776
}
775777
ast::expr_index(base, idx) => {
776778
// if not overloaded, would be RvalueDatumExpr
777-
return trans_overloaded_op(bcx, expr, base, ~[idx], dest);
779+
return trans_overloaded_op(bcx, expr, base, ~[idx], dest,
780+
DontAutorefArg);
778781
}
779782
ast::expr_cast(val, _) => {
780783
match ty::get(node_id_type(bcx, expr.id)).sty {
@@ -1641,15 +1644,16 @@ fn trans_overloaded_op(bcx: block,
16411644
expr: @ast::expr,
16421645
rcvr: @ast::expr,
16431646
+args: ~[@ast::expr],
1644-
dest: Dest) -> block
1647+
dest: Dest,
1648+
+autoref_arg: AutorefArg) -> block
16451649
{
16461650
let origin = *bcx.ccx().maps.method_map.get(&expr.id);
16471651
let fty = node_id_type(bcx, expr.callee_id);
16481652
return callee::trans_call_inner(
16491653
bcx, expr.info(), fty,
16501654
expr_ty(bcx, expr),
16511655
|bcx| meth::trans_method_callee(bcx, expr.callee_id, rcvr, origin),
1652-
callee::ArgExprs(args), dest, DoAutorefArg);
1656+
callee::ArgExprs(args), dest, autoref_arg);
16531657
}
16541658
16551659
fn int_cast(bcx: block, lldsttype: TypeRef, llsrctype: TypeRef,
@@ -1802,7 +1806,7 @@ fn trans_assign_op(bcx: block,
18021806
// FIXME(#2528) evaluates the receiver twice!!
18031807
let scratch = scratch_datum(bcx, dst_datum.ty, false);
18041808
let bcx = trans_overloaded_op(bcx, expr, dst, ~[src],
1805-
SaveIn(scratch.val));
1809+
SaveIn(scratch.val), DoAutorefArg);
18061810
return scratch.move_to_datum(bcx, DROP_EXISTING, dst_datum);
18071811
}
18081812

branches/snap-stage3/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/snap-stage3/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/snap-stage3/src/librustc/middle/typeck/check/mod.rs

Lines changed: 40 additions & 3 deletions
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
};
@@ -1549,7 +1586,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
15491586
lookup_op_method(
15501587
fcx, ex, rhs_expr, rhs_t,
15511588
fcx.tcx().sess.ident_of(mname), ~[],
1552-
DoDerefArgs, DontAutoderefReceiver,
1589+
DontDerefArgs, DontAutoderefReceiver,
15531590
|| {
15541591
fcx.type_error_message(ex.span, |actual| {
15551592
fmt!("cannot apply unary operator `%s` to type `%s`",
@@ -2757,7 +2794,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
27572794
expr.span, raw_base_t);
27582795
let ret_ty = lookup_op_method(fcx, expr, base, resolved,
27592796
tcx.sess.ident_of(~"index"),
2760-
~[idx], DoDerefArgs, AutoderefReceiver,
2797+
~[idx], DontDerefArgs, AutoderefReceiver,
27612798
|| {
27622799
fcx.type_error_message(expr.span, |actual|
27632800
fmt!("cannot index a value \

0 commit comments

Comments
 (0)