Skip to content

Commit

Permalink
Demote self to an (almost) regular argument and remove the env param.
Browse files Browse the repository at this point in the history
Fixes #10667 and closes #10259.
  • Loading branch information
eddyb committed Jan 27, 2014
1 parent b0280ac commit 15ba0c3
Show file tree
Hide file tree
Showing 88 changed files with 1,436 additions and 2,138 deletions.
2 changes: 1 addition & 1 deletion src/libextra/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ pub fn run_test(force_ignore: bool,
return;
}
StaticBenchFn(benchfn) => {
let bs = ::test::bench::benchmark(benchfn);
let bs = ::test::bench::benchmark(|harness| benchfn(harness));
monitor_ch.send((desc, TrBench(bs)));
return;
}
Expand Down
25 changes: 12 additions & 13 deletions src/librustc/metadata/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,24 +176,23 @@ pub static tag_link_args_arg: uint = 0x7a;

pub static tag_item_method_tps: uint = 0x7b;
pub static tag_item_method_fty: uint = 0x7c;
pub static tag_item_method_transformed_self_ty: uint = 0x7d;

pub static tag_mod_child: uint = 0x7e;
pub static tag_misc_info: uint = 0x7f;
pub static tag_misc_info_crate_items: uint = 0x80;
pub static tag_mod_child: uint = 0x7d;
pub static tag_misc_info: uint = 0x7e;
pub static tag_misc_info_crate_items: uint = 0x7f;

pub static tag_item_method_provided_source: uint = 0x81;
pub static tag_item_impl_vtables: uint = 0x82;
pub static tag_item_method_provided_source: uint = 0x80;
pub static tag_item_impl_vtables: uint = 0x81;

pub static tag_impls: uint = 0x83;
pub static tag_impls_impl: uint = 0x84;
pub static tag_impls: uint = 0x82;
pub static tag_impls_impl: uint = 0x83;

pub static tag_items_data_item_inherent_impl: uint = 0x85;
pub static tag_items_data_item_extension_impl: uint = 0x86;
pub static tag_items_data_item_inherent_impl: uint = 0x84;
pub static tag_items_data_item_extension_impl: uint = 0x85;

pub static tag_path_elem_pretty_name: uint = 0x87;
pub static tag_path_elem_pretty_name_ident: uint = 0x88;
pub static tag_path_elem_pretty_name_extra: uint = 0x89;
pub static tag_path_elem_pretty_name: uint = 0x86;
pub static tag_path_elem_pretty_name_ident: uint = 0x87;
pub static tag_path_elem_pretty_name_extra: uint = 0x88;

pub static tag_region_param_def: uint = 0x100;
pub static tag_region_param_def_ident: uint = 0x101;
Expand Down
16 changes: 2 additions & 14 deletions src/librustc/metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,16 +227,6 @@ fn doc_method_fty(doc: ebml::Doc, tcx: ty::ctxt, cdata: Cmd) -> ty::BareFnTy {
|_, did| translate_def_id(cdata, did))
}

fn doc_transformed_self_ty(doc: ebml::Doc,
tcx: ty::ctxt,
cdata: Cmd) -> Option<ty::t>
{
reader::maybe_get_doc(doc, tag_item_method_transformed_self_ty).map(|tp| {
parse_ty_data(tp.data, cdata.cnum, tp.start, tcx,
|_, did| translate_def_id(cdata, did))
})
}

pub fn item_type(_item_id: ast::DefId, item: ebml::Doc,
tcx: ty::ctxt, cdata: Cmd) -> ty::t {
doc_type(item, tcx, cdata)
Expand Down Expand Up @@ -781,9 +771,9 @@ fn get_explicit_self(item: ebml::Doc) -> ast::ExplicitSelf_ {
let explicit_self_kind = string[0];
match explicit_self_kind as char {
's' => ast::SelfStatic,
'v' => ast::SelfValue(get_mutability(string[1])),
'v' => ast::SelfValue,
'@' => ast::SelfBox,
'~' => ast::SelfUniq(get_mutability(string[1])),
'~' => ast::SelfUniq,
// FIXME(#4846) expl. region
'&' => ast::SelfRegion(None, get_mutability(string[1])),
_ => fail!("unknown self type code: `{}`", explicit_self_kind as char)
Expand Down Expand Up @@ -847,7 +837,6 @@ pub fn get_method(intr: @IdentInterner, cdata: Cmd, id: ast::NodeId,
let type_param_defs = item_ty_param_defs(method_doc, tcx, cdata,
tag_item_method_tps);
let rp_defs = item_region_param_defs(method_doc, tcx, cdata);
let transformed_self_ty = doc_transformed_self_ty(method_doc, tcx, cdata);
let fty = doc_method_fty(method_doc, tcx, cdata);
let vis = item_visibility(method_doc);
let explicit_self = get_explicit_self(method_doc);
Expand All @@ -859,7 +848,6 @@ pub fn get_method(intr: @IdentInterner, cdata: Cmd, id: ast::NodeId,
type_param_defs: type_param_defs,
region_param_defs: rp_defs,
},
transformed_self_ty,
fty,
explicit_self,
vis,
Expand Down
31 changes: 5 additions & 26 deletions src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,16 +261,6 @@ fn encode_type(ecx: &EncodeContext,
ebml_w.end_tag();
}

fn encode_transformed_self_ty(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder,
opt_typ: Option<ty::t>) {
for &typ in opt_typ.iter() {
ebml_w.start_tag(tag_item_method_transformed_self_ty);
write_type(ecx, ebml_w, typ);
ebml_w.end_tag();
}
}

fn encode_method_fty(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder,
typ: &ty::BareFnTy) {
Expand Down Expand Up @@ -679,23 +669,13 @@ fn encode_explicit_self(ebml_w: &mut writer::Encoder, explicit_self: ast::Explic

// Encode the base self type.
match explicit_self {
SelfStatic => {
ebml_w.writer.write(&[ 's' as u8 ]);
}
SelfValue(m) => {
ebml_w.writer.write(&[ 'v' as u8 ]);
encode_mutability(ebml_w, m);
}
SelfStatic => ebml_w.writer.write(&[ 's' as u8 ]),
SelfValue => ebml_w.writer.write(&[ 'v' as u8 ]),
SelfBox => ebml_w.writer.write(&[ '@' as u8 ]),
SelfUniq => ebml_w.writer.write(&[ '~' as u8 ]),
SelfRegion(_, m) => {
// FIXME(#4846) encode custom lifetime
ebml_w.writer.write(&[ '&' as u8 ]);
encode_mutability(ebml_w, m);
}
SelfBox => {
ebml_w.writer.write(&[ '@' as u8 ]);
}
SelfUniq(m) => {
ebml_w.writer.write(&[ '~' as u8 ]);
ebml_w.writer.write(&['&' as u8]);
encode_mutability(ebml_w, m);
}
}
Expand Down Expand Up @@ -807,7 +787,6 @@ fn encode_method_ty_fields(ecx: &EncodeContext,
encode_ty_type_param_defs(ebml_w, ecx,
method_ty.generics.type_param_defs,
tag_item_method_tps);
encode_transformed_self_ty(ecx, ebml_w, method_ty.transformed_self_ty);
encode_method_fty(ecx, ebml_w, &method_ty.fty);
encode_visibility(ebml_w, method_ty.vis);
encode_explicit_self(ebml_w, method_ty.explicit_self);
Expand Down
4 changes: 0 additions & 4 deletions src/librustc/metadata/tydecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,10 +374,6 @@ fn parse_ty(st: &mut PState, conv: conv_did) -> ty::t {
return ty::mk_bare_fn(st.tcx, parse_bare_fn_ty(st, |x,y| conv(x,y)));
}
'Y' => return ty::mk_type(st.tcx),
'C' => {
let sigil = parse_sigil(st);
return ty::mk_opaque_closure_ptr(st.tcx, sigil);
}
'#' => {
let pos = parse_hex(st);
assert_eq!(next(st), ':');
Expand Down
4 changes: 0 additions & 4 deletions src/librustc/metadata/tyencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,6 @@ fn enc_sty(w: &mut MemWriter, cx: @ctxt, st: &ty::sty) {
mywrite!(w, "s{}|", (cx.ds)(did));
}
ty::ty_type => mywrite!(w, "Y"),
ty::ty_opaque_closure_ptr(p) => {
mywrite!(w, "C&");
enc_sigil(w, p);
}
ty::ty_struct(def, ref substs) => {
mywrite!(w, "a[{}|", (cx.ds)(def));
enc_substs(w, cx, substs);
Expand Down
22 changes: 2 additions & 20 deletions src/librustc/middle/astencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,6 @@ impl tr for ast::Def {
ast::DefMethod(did0.tr(xcx), did1.map(|did1| did1.tr(xcx)))
}
ast::DefSelfTy(nid) => { ast::DefSelfTy(xcx.tr_id(nid)) }
ast::DefSelf(nid, m) => { ast::DefSelf(xcx.tr_id(nid), m) }
ast::DefMod(did) => { ast::DefMod(did.tr(xcx)) }
ast::DefForeignMod(did) => { ast::DefForeignMod(did.tr(xcx)) }
ast::DefStatic(did, m) => { ast::DefStatic(did.tr(xcx), m) }
Expand Down Expand Up @@ -579,16 +578,8 @@ trait read_method_map_entry_helper {
-> method_map_entry;
}

fn encode_method_map_entry(ecx: &e::EncodeContext,
ebml_w: &mut writer::Encoder,
mme: method_map_entry) {
fn encode_method_map_entry(ebml_w: &mut writer::Encoder, mme: method_map_entry) {
ebml_w.emit_struct("method_map_entry", 3, |ebml_w| {
ebml_w.emit_struct_field("self_ty", 0u, |ebml_w| {
ebml_w.emit_ty(ecx, mme.self_ty);
});
ebml_w.emit_struct_field("explicit_self", 2u, |ebml_w| {
mme.explicit_self.encode(ebml_w);
});
ebml_w.emit_struct_field("origin", 1u, |ebml_w| {
mme.origin.encode(ebml_w);
});
Expand All @@ -600,15 +591,6 @@ impl<'a> read_method_map_entry_helper for reader::Decoder<'a> {
-> method_map_entry {
self.read_struct("method_map_entry", 3, |this| {
method_map_entry {
self_ty: this.read_struct_field("self_ty", 0u, |this| {
this.read_ty(xcx)
}),
explicit_self: this.read_struct_field("explicit_self",
2,
|this| {
let explicit_self: ast::ExplicitSelf_ = Decodable::decode(this);
explicit_self
}),
origin: this.read_struct_field("origin", 1, |this| {
let method_origin: method_origin =
Decodable::decode(this);
Expand Down Expand Up @@ -1043,7 +1025,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
ebml_w.tag(c::tag_table_method_map, |ebml_w| {
ebml_w.id(id);
ebml_w.tag(c::tag_table_val, |ebml_w| {
encode_method_map_entry(ecx, ebml_w, *mme)
encode_method_map_entry(ebml_w, *mme)
})
})
}
Expand Down
22 changes: 5 additions & 17 deletions src/librustc/middle/borrowck/check_loans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,7 @@ impl<'a> CheckLoanCtxt<'a> {
debug!("mark_writes_through_upvars_as_used_mut(cmt={})",
cmt.repr(this.tcx()));
match cmt.cat {
mc::cat_local(id) |
mc::cat_arg(id) |
mc::cat_self(id) => {
mc::cat_local(id) | mc::cat_arg(id) => {
let mut used_mut_nodes = this.tcx()
.used_mut_nodes
.borrow_mut();
Expand Down Expand Up @@ -459,7 +457,6 @@ impl<'a> CheckLoanCtxt<'a> {
mc::cat_rvalue(..) |
mc::cat_local(..) |
mc::cat_arg(_) |
mc::cat_self(..) |
mc::cat_deref(_, _, mc::unsafe_ptr(..)) |
mc::cat_static_item(..) |
mc::cat_deref(_, _, mc::gc_ptr) |
Expand Down Expand Up @@ -790,7 +787,6 @@ fn check_loans_in_expr<'a>(this: &mut CheckLoanCtxt<'a>,

let method_map = this.bccx.method_map.borrow();
match expr.node {
ast::ExprSelf |
ast::ExprPath(..) => {
if !this.move_data.is_assignee(expr.id) {
let cmt = this.bccx.cat_expr_unadjusted(expr);
Expand All @@ -808,32 +804,24 @@ fn check_loans_in_expr<'a>(this: &mut CheckLoanCtxt<'a>,
ast::ExprCall(f, ref args, _) => {
this.check_call(expr, Some(f), f.id, f.span, *args);
}
ast::ExprMethodCall(callee_id, _, _, _, ref args, _) => {
ast::ExprMethodCall(callee_id, _, _, ref args, _) => {
this.check_call(expr, None, callee_id, expr.span, *args);
}
ast::ExprIndex(callee_id, _, rval) |
ast::ExprBinary(callee_id, _, _, rval)
if method_map.get().contains_key(&expr.id) => {
this.check_call(expr,
None,
callee_id,
expr.span,
[rval]);
this.check_call(expr, None, callee_id, expr.span, [rval]);
}
ast::ExprUnary(callee_id, _, _) | ast::ExprIndex(callee_id, _, _)
if method_map.get().contains_key(&expr.id) => {
this.check_call(expr,
None,
callee_id,
expr.span,
[]);
this.check_call(expr, None, callee_id, expr.span, []);
}
ast::ExprInlineAsm(ref ia) => {
for &(_, out) in ia.outputs.iter() {
this.check_assignment(out);
}
}
_ => { }
_ => {}
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/librustc/middle/borrowck/gather_loans/gather_moves.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ fn check_is_legal_to_move_from(bccx: &BorrowckCtxt,

mc::cat_rvalue(..) |
mc::cat_local(..) |
mc::cat_arg(..) |
mc::cat_self(..) => {
mc::cat_arg(..) => {
true
}

Expand Down
5 changes: 1 addition & 4 deletions src/librustc/middle/borrowck/gather_loans/lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ impl<'a> GuaranteeLifetimeContext<'a> {
mc::cat_copied_upvar(..) | // L-Local
mc::cat_local(..) | // L-Local
mc::cat_arg(..) | // L-Local
mc::cat_self(..) | // L-Local
mc::cat_deref(_, _, mc::region_ptr(..)) | // L-Deref-Borrowed
mc::cat_deref(_, _, mc::unsafe_ptr(..)) => {
let scope = self.scope(cmt);
Expand Down Expand Up @@ -261,7 +260,6 @@ impl<'a> GuaranteeLifetimeContext<'a> {
match cmt.guarantor().cat {
mc::cat_local(id) |
mc::cat_self(id) |
mc::cat_arg(id) => {
let moved_variables_set = self.bccx
.moved_variables_set
Expand Down Expand Up @@ -303,8 +301,7 @@ impl<'a> GuaranteeLifetimeContext<'a> {
ty::ReStatic
}
mc::cat_local(local_id) |
mc::cat_arg(local_id) |
mc::cat_self(local_id) => {
mc::cat_arg(local_id) => {
ty::ReScope(self.bccx.tcx.region_maps.var_scope(local_id))
}
mc::cat_deref(_, _, mc::unsafe_ptr(..)) => {
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/middle/borrowck/gather_loans/restrictions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ impl<'a> RestrictionsContext<'a> {
}

mc::cat_local(local_id) |
mc::cat_arg(local_id) |
mc::cat_self(local_id) => {
mc::cat_arg(local_id) => {
// R-Variable
let lp = @LpVar(local_id);
SafeIf(lp, ~[Restriction {loan_path: lp,
Expand Down
19 changes: 14 additions & 5 deletions src/librustc/middle/borrowck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use std::ops::{BitOr, BitAnd};
use std::result::{Result};
use syntax::ast;
use syntax::ast_map;
use syntax::ast_util;
use syntax::codemap::Span;
use syntax::parse::token;
use syntax::visit;
Expand Down Expand Up @@ -294,9 +295,7 @@ pub fn opt_loan_path(cmt: mc::cmt) -> Option<@LoanPath> {
None
}

mc::cat_local(id) |
mc::cat_arg(id) |
mc::cat_self(id) => {
mc::cat_local(id) | mc::cat_arg(id) => {
Some(@LpVar(id))
}

Expand Down Expand Up @@ -771,8 +770,18 @@ impl BorrowckCtxt {
match *loan_path {
LpVar(id) => {
match self.tcx.items.find(id) {
Some(ast_map::NodeLocal(ref ident, _)) => {
out.push_str(token::ident_to_str(ident));
Some(ast_map::NodeLocal(pat)) => {
match pat.node {
ast::PatIdent(_, ref path, _) => {
let ident = ast_util::path_to_ident(path);
out.push_str(token::ident_to_str(&ident));
}
_ => {
self.tcx.sess.bug(
format!("Loan path LpVar({:?}) maps to {:?}, not local",
id, pat));
}
}
}
r => {
self.tcx.sess.bug(
Expand Down
5 changes: 2 additions & 3 deletions src/librustc/middle/cfg/construct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,8 @@ impl CFGBuilder {
self.call(expr, pred, func, *args)
}

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

ast::ExprIndex(_, l, r) |
Expand Down Expand Up @@ -410,7 +410,6 @@ impl CFGBuilder {
ast::ExprLogLevel |
ast::ExprMac(..) |
ast::ExprInlineAsm(..) |
ast::ExprSelf |
ast::ExprFnBlock(..) |
ast::ExprProc(..) |
ast::ExprLit(..) |
Expand Down
Loading

13 comments on commit 15ba0c3

@bors
Copy link
Contributor

@bors bors commented on 15ba0c3 Jan 27, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from nikomatsakis
at eddyb@15ba0c3

@bors
Copy link
Contributor

@bors bors commented on 15ba0c3 Jan 27, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging eddyb/rust/env-et-self-no-more = 15ba0c3 into auto

@bors
Copy link
Contributor

@bors bors commented on 15ba0c3 Jan 27, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eddyb/rust/env-et-self-no-more = 15ba0c3 merged ok, testing candidate = 6575b90c

@bors
Copy link
Contributor

@bors bors commented on 15ba0c3 Jan 27, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 15ba0c3 Jan 27, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from nikomatsakis
at eddyb@15ba0c3

@bors
Copy link
Contributor

@bors bors commented on 15ba0c3 Jan 27, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging eddyb/rust/env-et-self-no-more = 15ba0c3 into auto

@bors
Copy link
Contributor

@bors bors commented on 15ba0c3 Jan 27, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eddyb/rust/env-et-self-no-more = 15ba0c3 merged ok, testing candidate = 543eb07d

@bors
Copy link
Contributor

@bors bors commented on 15ba0c3 Jan 27, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from nikomatsakis
at eddyb@15ba0c3

@bors
Copy link
Contributor

@bors bors commented on 15ba0c3 Jan 27, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging eddyb/rust/env-et-self-no-more = 15ba0c3 into auto

@bors
Copy link
Contributor

@bors bors commented on 15ba0c3 Jan 27, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eddyb/rust/env-et-self-no-more = 15ba0c3 merged ok, testing candidate = d6d7812

@bors
Copy link
Contributor

@bors bors commented on 15ba0c3 Jan 27, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 15ba0c3 Jan 27, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = d6d7812

Please sign in to comment.