Skip to content

Commit 15ba0c3

Browse files
committed
Demote self to an (almost) regular argument and remove the env param.
Fixes #10667 and closes #10259.
1 parent b0280ac commit 15ba0c3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+1436
-2138
lines changed

src/libextra/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ pub fn run_test(force_ignore: bool,
895895
return;
896896
}
897897
StaticBenchFn(benchfn) => {
898-
let bs = ::test::bench::benchmark(benchfn);
898+
let bs = ::test::bench::benchmark(|harness| benchfn(harness));
899899
monitor_ch.send((desc, TrBench(bs)));
900900
return;
901901
}

src/librustc/metadata/common.rs

+12-13
Original file line numberDiff line numberDiff line change
@@ -176,24 +176,23 @@ pub static tag_link_args_arg: uint = 0x7a;
176176

177177
pub static tag_item_method_tps: uint = 0x7b;
178178
pub static tag_item_method_fty: uint = 0x7c;
179-
pub static tag_item_method_transformed_self_ty: uint = 0x7d;
180179

181-
pub static tag_mod_child: uint = 0x7e;
182-
pub static tag_misc_info: uint = 0x7f;
183-
pub static tag_misc_info_crate_items: uint = 0x80;
180+
pub static tag_mod_child: uint = 0x7d;
181+
pub static tag_misc_info: uint = 0x7e;
182+
pub static tag_misc_info_crate_items: uint = 0x7f;
184183

185-
pub static tag_item_method_provided_source: uint = 0x81;
186-
pub static tag_item_impl_vtables: uint = 0x82;
184+
pub static tag_item_method_provided_source: uint = 0x80;
185+
pub static tag_item_impl_vtables: uint = 0x81;
187186

188-
pub static tag_impls: uint = 0x83;
189-
pub static tag_impls_impl: uint = 0x84;
187+
pub static tag_impls: uint = 0x82;
188+
pub static tag_impls_impl: uint = 0x83;
190189

191-
pub static tag_items_data_item_inherent_impl: uint = 0x85;
192-
pub static tag_items_data_item_extension_impl: uint = 0x86;
190+
pub static tag_items_data_item_inherent_impl: uint = 0x84;
191+
pub static tag_items_data_item_extension_impl: uint = 0x85;
193192

194-
pub static tag_path_elem_pretty_name: uint = 0x87;
195-
pub static tag_path_elem_pretty_name_ident: uint = 0x88;
196-
pub static tag_path_elem_pretty_name_extra: uint = 0x89;
193+
pub static tag_path_elem_pretty_name: uint = 0x86;
194+
pub static tag_path_elem_pretty_name_ident: uint = 0x87;
195+
pub static tag_path_elem_pretty_name_extra: uint = 0x88;
197196

198197
pub static tag_region_param_def: uint = 0x100;
199198
pub static tag_region_param_def_ident: uint = 0x101;

src/librustc/metadata/decoder.rs

+2-14
Original file line numberDiff line numberDiff line change
@@ -227,16 +227,6 @@ fn doc_method_fty(doc: ebml::Doc, tcx: ty::ctxt, cdata: Cmd) -> ty::BareFnTy {
227227
|_, did| translate_def_id(cdata, did))
228228
}
229229

230-
fn doc_transformed_self_ty(doc: ebml::Doc,
231-
tcx: ty::ctxt,
232-
cdata: Cmd) -> Option<ty::t>
233-
{
234-
reader::maybe_get_doc(doc, tag_item_method_transformed_self_ty).map(|tp| {
235-
parse_ty_data(tp.data, cdata.cnum, tp.start, tcx,
236-
|_, did| translate_def_id(cdata, did))
237-
})
238-
}
239-
240230
pub fn item_type(_item_id: ast::DefId, item: ebml::Doc,
241231
tcx: ty::ctxt, cdata: Cmd) -> ty::t {
242232
doc_type(item, tcx, cdata)
@@ -781,9 +771,9 @@ fn get_explicit_self(item: ebml::Doc) -> ast::ExplicitSelf_ {
781771
let explicit_self_kind = string[0];
782772
match explicit_self_kind as char {
783773
's' => ast::SelfStatic,
784-
'v' => ast::SelfValue(get_mutability(string[1])),
774+
'v' => ast::SelfValue,
785775
'@' => ast::SelfBox,
786-
'~' => ast::SelfUniq(get_mutability(string[1])),
776+
'~' => ast::SelfUniq,
787777
// FIXME(#4846) expl. region
788778
'&' => ast::SelfRegion(None, get_mutability(string[1])),
789779
_ => fail!("unknown self type code: `{}`", explicit_self_kind as char)
@@ -847,7 +837,6 @@ pub fn get_method(intr: @IdentInterner, cdata: Cmd, id: ast::NodeId,
847837
let type_param_defs = item_ty_param_defs(method_doc, tcx, cdata,
848838
tag_item_method_tps);
849839
let rp_defs = item_region_param_defs(method_doc, tcx, cdata);
850-
let transformed_self_ty = doc_transformed_self_ty(method_doc, tcx, cdata);
851840
let fty = doc_method_fty(method_doc, tcx, cdata);
852841
let vis = item_visibility(method_doc);
853842
let explicit_self = get_explicit_self(method_doc);
@@ -859,7 +848,6 @@ pub fn get_method(intr: @IdentInterner, cdata: Cmd, id: ast::NodeId,
859848
type_param_defs: type_param_defs,
860849
region_param_defs: rp_defs,
861850
},
862-
transformed_self_ty,
863851
fty,
864852
explicit_self,
865853
vis,

src/librustc/metadata/encoder.rs

+5-26
Original file line numberDiff line numberDiff line change
@@ -261,16 +261,6 @@ fn encode_type(ecx: &EncodeContext,
261261
ebml_w.end_tag();
262262
}
263263

264-
fn encode_transformed_self_ty(ecx: &EncodeContext,
265-
ebml_w: &mut writer::Encoder,
266-
opt_typ: Option<ty::t>) {
267-
for &typ in opt_typ.iter() {
268-
ebml_w.start_tag(tag_item_method_transformed_self_ty);
269-
write_type(ecx, ebml_w, typ);
270-
ebml_w.end_tag();
271-
}
272-
}
273-
274264
fn encode_method_fty(ecx: &EncodeContext,
275265
ebml_w: &mut writer::Encoder,
276266
typ: &ty::BareFnTy) {
@@ -679,23 +669,13 @@ fn encode_explicit_self(ebml_w: &mut writer::Encoder, explicit_self: ast::Explic
679669

680670
// Encode the base self type.
681671
match explicit_self {
682-
SelfStatic => {
683-
ebml_w.writer.write(&[ 's' as u8 ]);
684-
}
685-
SelfValue(m) => {
686-
ebml_w.writer.write(&[ 'v' as u8 ]);
687-
encode_mutability(ebml_w, m);
688-
}
672+
SelfStatic => ebml_w.writer.write(&[ 's' as u8 ]),
673+
SelfValue => ebml_w.writer.write(&[ 'v' as u8 ]),
674+
SelfBox => ebml_w.writer.write(&[ '@' as u8 ]),
675+
SelfUniq => ebml_w.writer.write(&[ '~' as u8 ]),
689676
SelfRegion(_, m) => {
690677
// FIXME(#4846) encode custom lifetime
691-
ebml_w.writer.write(&[ '&' as u8 ]);
692-
encode_mutability(ebml_w, m);
693-
}
694-
SelfBox => {
695-
ebml_w.writer.write(&[ '@' as u8 ]);
696-
}
697-
SelfUniq(m) => {
698-
ebml_w.writer.write(&[ '~' as u8 ]);
678+
ebml_w.writer.write(&['&' as u8]);
699679
encode_mutability(ebml_w, m);
700680
}
701681
}
@@ -807,7 +787,6 @@ fn encode_method_ty_fields(ecx: &EncodeContext,
807787
encode_ty_type_param_defs(ebml_w, ecx,
808788
method_ty.generics.type_param_defs,
809789
tag_item_method_tps);
810-
encode_transformed_self_ty(ecx, ebml_w, method_ty.transformed_self_ty);
811790
encode_method_fty(ecx, ebml_w, &method_ty.fty);
812791
encode_visibility(ebml_w, method_ty.vis);
813792
encode_explicit_self(ebml_w, method_ty.explicit_self);

src/librustc/metadata/tydecode.rs

-4
Original file line numberDiff line numberDiff line change
@@ -374,10 +374,6 @@ fn parse_ty(st: &mut PState, conv: conv_did) -> ty::t {
374374
return ty::mk_bare_fn(st.tcx, parse_bare_fn_ty(st, |x,y| conv(x,y)));
375375
}
376376
'Y' => return ty::mk_type(st.tcx),
377-
'C' => {
378-
let sigil = parse_sigil(st);
379-
return ty::mk_opaque_closure_ptr(st.tcx, sigil);
380-
}
381377
'#' => {
382378
let pos = parse_hex(st);
383379
assert_eq!(next(st), ':');

src/librustc/metadata/tyencode.rs

-4
Original file line numberDiff line numberDiff line change
@@ -327,10 +327,6 @@ fn enc_sty(w: &mut MemWriter, cx: @ctxt, st: &ty::sty) {
327327
mywrite!(w, "s{}|", (cx.ds)(did));
328328
}
329329
ty::ty_type => mywrite!(w, "Y"),
330-
ty::ty_opaque_closure_ptr(p) => {
331-
mywrite!(w, "C&");
332-
enc_sigil(w, p);
333-
}
334330
ty::ty_struct(def, ref substs) => {
335331
mywrite!(w, "a[{}|", (cx.ds)(def));
336332
enc_substs(w, cx, substs);

src/librustc/middle/astencode.rs

+2-20
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,6 @@ impl tr for ast::Def {
435435
ast::DefMethod(did0.tr(xcx), did1.map(|did1| did1.tr(xcx)))
436436
}
437437
ast::DefSelfTy(nid) => { ast::DefSelfTy(xcx.tr_id(nid)) }
438-
ast::DefSelf(nid, m) => { ast::DefSelf(xcx.tr_id(nid), m) }
439438
ast::DefMod(did) => { ast::DefMod(did.tr(xcx)) }
440439
ast::DefForeignMod(did) => { ast::DefForeignMod(did.tr(xcx)) }
441440
ast::DefStatic(did, m) => { ast::DefStatic(did.tr(xcx), m) }
@@ -579,16 +578,8 @@ trait read_method_map_entry_helper {
579578
-> method_map_entry;
580579
}
581580

582-
fn encode_method_map_entry(ecx: &e::EncodeContext,
583-
ebml_w: &mut writer::Encoder,
584-
mme: method_map_entry) {
581+
fn encode_method_map_entry(ebml_w: &mut writer::Encoder, mme: method_map_entry) {
585582
ebml_w.emit_struct("method_map_entry", 3, |ebml_w| {
586-
ebml_w.emit_struct_field("self_ty", 0u, |ebml_w| {
587-
ebml_w.emit_ty(ecx, mme.self_ty);
588-
});
589-
ebml_w.emit_struct_field("explicit_self", 2u, |ebml_w| {
590-
mme.explicit_self.encode(ebml_w);
591-
});
592583
ebml_w.emit_struct_field("origin", 1u, |ebml_w| {
593584
mme.origin.encode(ebml_w);
594585
});
@@ -600,15 +591,6 @@ impl<'a> read_method_map_entry_helper for reader::Decoder<'a> {
600591
-> method_map_entry {
601592
self.read_struct("method_map_entry", 3, |this| {
602593
method_map_entry {
603-
self_ty: this.read_struct_field("self_ty", 0u, |this| {
604-
this.read_ty(xcx)
605-
}),
606-
explicit_self: this.read_struct_field("explicit_self",
607-
2,
608-
|this| {
609-
let explicit_self: ast::ExplicitSelf_ = Decodable::decode(this);
610-
explicit_self
611-
}),
612594
origin: this.read_struct_field("origin", 1, |this| {
613595
let method_origin: method_origin =
614596
Decodable::decode(this);
@@ -1043,7 +1025,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
10431025
ebml_w.tag(c::tag_table_method_map, |ebml_w| {
10441026
ebml_w.id(id);
10451027
ebml_w.tag(c::tag_table_val, |ebml_w| {
1046-
encode_method_map_entry(ecx, ebml_w, *mme)
1028+
encode_method_map_entry(ebml_w, *mme)
10471029
})
10481030
})
10491031
}

src/librustc/middle/borrowck/check_loans.rs

+5-17
Original file line numberDiff line numberDiff line change
@@ -371,9 +371,7 @@ impl<'a> CheckLoanCtxt<'a> {
371371
debug!("mark_writes_through_upvars_as_used_mut(cmt={})",
372372
cmt.repr(this.tcx()));
373373
match cmt.cat {
374-
mc::cat_local(id) |
375-
mc::cat_arg(id) |
376-
mc::cat_self(id) => {
374+
mc::cat_local(id) | mc::cat_arg(id) => {
377375
let mut used_mut_nodes = this.tcx()
378376
.used_mut_nodes
379377
.borrow_mut();
@@ -459,7 +457,6 @@ impl<'a> CheckLoanCtxt<'a> {
459457
mc::cat_rvalue(..) |
460458
mc::cat_local(..) |
461459
mc::cat_arg(_) |
462-
mc::cat_self(..) |
463460
mc::cat_deref(_, _, mc::unsafe_ptr(..)) |
464461
mc::cat_static_item(..) |
465462
mc::cat_deref(_, _, mc::gc_ptr) |
@@ -790,7 +787,6 @@ fn check_loans_in_expr<'a>(this: &mut CheckLoanCtxt<'a>,
790787

791788
let method_map = this.bccx.method_map.borrow();
792789
match expr.node {
793-
ast::ExprSelf |
794790
ast::ExprPath(..) => {
795791
if !this.move_data.is_assignee(expr.id) {
796792
let cmt = this.bccx.cat_expr_unadjusted(expr);
@@ -808,32 +804,24 @@ fn check_loans_in_expr<'a>(this: &mut CheckLoanCtxt<'a>,
808804
ast::ExprCall(f, ref args, _) => {
809805
this.check_call(expr, Some(f), f.id, f.span, *args);
810806
}
811-
ast::ExprMethodCall(callee_id, _, _, _, ref args, _) => {
807+
ast::ExprMethodCall(callee_id, _, _, ref args, _) => {
812808
this.check_call(expr, None, callee_id, expr.span, *args);
813809
}
814810
ast::ExprIndex(callee_id, _, rval) |
815811
ast::ExprBinary(callee_id, _, _, rval)
816812
if method_map.get().contains_key(&expr.id) => {
817-
this.check_call(expr,
818-
None,
819-
callee_id,
820-
expr.span,
821-
[rval]);
813+
this.check_call(expr, None, callee_id, expr.span, [rval]);
822814
}
823815
ast::ExprUnary(callee_id, _, _) | ast::ExprIndex(callee_id, _, _)
824816
if method_map.get().contains_key(&expr.id) => {
825-
this.check_call(expr,
826-
None,
827-
callee_id,
828-
expr.span,
829-
[]);
817+
this.check_call(expr, None, callee_id, expr.span, []);
830818
}
831819
ast::ExprInlineAsm(ref ia) => {
832820
for &(_, out) in ia.outputs.iter() {
833821
this.check_assignment(out);
834822
}
835823
}
836-
_ => { }
824+
_ => {}
837825
}
838826
}
839827

src/librustc/middle/borrowck/gather_loans/gather_moves.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,7 @@ fn check_is_legal_to_move_from(bccx: &BorrowckCtxt,
133133

134134
mc::cat_rvalue(..) |
135135
mc::cat_local(..) |
136-
mc::cat_arg(..) |
137-
mc::cat_self(..) => {
136+
mc::cat_arg(..) => {
138137
true
139138
}
140139

src/librustc/middle/borrowck/gather_loans/lifetime.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ impl<'a> GuaranteeLifetimeContext<'a> {
7676
mc::cat_copied_upvar(..) | // L-Local
7777
mc::cat_local(..) | // L-Local
7878
mc::cat_arg(..) | // L-Local
79-
mc::cat_self(..) | // L-Local
8079
mc::cat_deref(_, _, mc::region_ptr(..)) | // L-Deref-Borrowed
8180
mc::cat_deref(_, _, mc::unsafe_ptr(..)) => {
8281
let scope = self.scope(cmt);
@@ -261,7 +260,6 @@ impl<'a> GuaranteeLifetimeContext<'a> {
261260
262261
match cmt.guarantor().cat {
263262
mc::cat_local(id) |
264-
mc::cat_self(id) |
265263
mc::cat_arg(id) => {
266264
let moved_variables_set = self.bccx
267265
.moved_variables_set
@@ -303,8 +301,7 @@ impl<'a> GuaranteeLifetimeContext<'a> {
303301
ty::ReStatic
304302
}
305303
mc::cat_local(local_id) |
306-
mc::cat_arg(local_id) |
307-
mc::cat_self(local_id) => {
304+
mc::cat_arg(local_id) => {
308305
ty::ReScope(self.bccx.tcx.region_maps.var_scope(local_id))
309306
}
310307
mc::cat_deref(_, _, mc::unsafe_ptr(..)) => {

src/librustc/middle/borrowck/gather_loans/restrictions.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ impl<'a> RestrictionsContext<'a> {
7474
}
7575

7676
mc::cat_local(local_id) |
77-
mc::cat_arg(local_id) |
78-
mc::cat_self(local_id) => {
77+
mc::cat_arg(local_id) => {
7978
// R-Variable
8079
let lp = @LpVar(local_id);
8180
SafeIf(lp, ~[Restriction {loan_path: lp,

src/librustc/middle/borrowck/mod.rs

+14-5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use std::ops::{BitOr, BitAnd};
2525
use std::result::{Result};
2626
use syntax::ast;
2727
use syntax::ast_map;
28+
use syntax::ast_util;
2829
use syntax::codemap::Span;
2930
use syntax::parse::token;
3031
use syntax::visit;
@@ -294,9 +295,7 @@ pub fn opt_loan_path(cmt: mc::cmt) -> Option<@LoanPath> {
294295
None
295296
}
296297

297-
mc::cat_local(id) |
298-
mc::cat_arg(id) |
299-
mc::cat_self(id) => {
298+
mc::cat_local(id) | mc::cat_arg(id) => {
300299
Some(@LpVar(id))
301300
}
302301

@@ -771,8 +770,18 @@ impl BorrowckCtxt {
771770
match *loan_path {
772771
LpVar(id) => {
773772
match self.tcx.items.find(id) {
774-
Some(ast_map::NodeLocal(ref ident, _)) => {
775-
out.push_str(token::ident_to_str(ident));
773+
Some(ast_map::NodeLocal(pat)) => {
774+
match pat.node {
775+
ast::PatIdent(_, ref path, _) => {
776+
let ident = ast_util::path_to_ident(path);
777+
out.push_str(token::ident_to_str(&ident));
778+
}
779+
_ => {
780+
self.tcx.sess.bug(
781+
format!("Loan path LpVar({:?}) maps to {:?}, not local",
782+
id, pat));
783+
}
784+
}
776785
}
777786
r => {
778787
self.tcx.sess.bug(

src/librustc/middle/cfg/construct.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,8 @@ impl CFGBuilder {
355355
self.call(expr, pred, func, *args)
356356
}
357357

358-
ast::ExprMethodCall(_, rcvr, _, _, ref args, _) => {
359-
self.call(expr, pred, rcvr, *args)
358+
ast::ExprMethodCall(_, _, _, ref args, _) => {
359+
self.call(expr, pred, args[0], args.slice_from(1))
360360
}
361361

362362
ast::ExprIndex(_, l, r) |
@@ -410,7 +410,6 @@ impl CFGBuilder {
410410
ast::ExprLogLevel |
411411
ast::ExprMac(..) |
412412
ast::ExprInlineAsm(..) |
413-
ast::ExprSelf |
414413
ast::ExprFnBlock(..) |
415414
ast::ExprProc(..) |
416415
ast::ExprLit(..) |

0 commit comments

Comments
 (0)