Skip to content

Commit bcbc54a

Browse files
committed
---
yaml --- r: 63530 b: refs/heads/snap-stage3 c: 62dc4e0 h: refs/heads/master v: v3
1 parent 09af4fe commit bcbc54a

File tree

13 files changed

+222
-275
lines changed

13 files changed

+222
-275
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: 2d28d645422c1617be58c8ca7ad9a457264ca850
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: ba05af7b1cbb5ccf25226ca5cd8d84f872426466
4+
refs/heads/snap-stage3: 62dc4e0d4cebc390de4053da881a74b9e72c52e6
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libextra/sha1.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use core::vec;
3636
/// The SHA-1 interface
3737
trait Sha1 {
3838
/// Provide message input as bytes
39-
fn input(&mut self, &const [u8]);
39+
fn input(&mut self, &[u8]);
4040
/// Provide message input as string
4141
fn input_str(&mut self, &str);
4242
/**
@@ -74,9 +74,9 @@ pub fn sha1() -> @Sha1 {
7474
computed: bool,
7575
work_buf: @mut ~[u32]};
7676

77-
fn add_input(st: &mut Sha1State, msg: &const [u8]) {
77+
fn add_input(st: &mut Sha1State, msg: &[u8]) {
7878
assert!((!st.computed));
79-
for vec::each_const(msg) |element| {
79+
for msg.iter().advance |element| {
8080
st.msg_block[st.msg_block_idx] = *element;
8181
st.msg_block_idx += 1u;
8282
st.len_low += 8u32;
@@ -242,7 +242,7 @@ pub fn sha1() -> @Sha1 {
242242
self.h[4] = 0xC3D2E1F0u32;
243243
self.computed = false;
244244
}
245-
fn input(&mut self, msg: &const [u8]) { add_input(self, msg); }
245+
fn input(&mut self, msg: &[u8]) { add_input(self, msg); }
246246
fn input_str(&mut self, msg: &str) {
247247
add_input(self, msg.as_bytes());
248248
}

branches/snap-stage3/src/librustc/metadata/csearch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ pub fn get_impl_trait(tcx: ty::ctxt,
229229
pub fn get_impl_method(cstore: @mut cstore::CStore,
230230
def: ast::def_id,
231231
mname: ast::ident)
232-
-> Option<ast::def_id> {
232+
-> ast::def_id {
233233
let cdata = cstore::get_crate_data(cstore, def.crate);
234234
decoder::get_impl_method(cstore.intr, cdata, def.node, mname)
235235
}

branches/snap-stage3/src/librustc/metadata/decoder.rs

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ pub fn get_impl_trait(cdata: cmd,
415415
}
416416

417417
pub fn get_impl_method(intr: @ident_interner, cdata: cmd, id: ast::node_id,
418-
name: ast::ident) -> Option<ast::def_id> {
418+
name: ast::ident) -> ast::def_id {
419419
let items = reader::get_doc(reader::Doc(cdata.data), tag_items);
420420
let mut found = None;
421421
for reader::tagged_docs(find_item(id, items), tag_item_impl_method)
@@ -425,7 +425,7 @@ pub fn get_impl_method(intr: @ident_interner, cdata: cmd, id: ast::node_id,
425425
found = Some(translate_def_id(cdata, m_did));
426426
}
427427
}
428-
found
428+
found.get()
429429
}
430430

431431
pub fn get_symbol(data: @~[u8], id: ast::node_id) -> ~str {
@@ -755,13 +755,40 @@ pub fn get_provided_trait_methods(intr: @ident_interner, cdata: cmd,
755755
let item = lookup_item(id, data);
756756
let mut result = ~[];
757757

758-
for reader::tagged_docs(item, tag_item_trait_method) |mth_id| {
759-
let did = item_def_id(mth_id, cdata);
760-
let mth = lookup_item(did.node, data);
761-
758+
for reader::tagged_docs(item, tag_item_trait_method) |mth| {
762759
if item_method_sort(mth) != 'p' { loop; }
763760

764-
let ty_method = get_method(intr, cdata, did.node, tcx);
761+
let did = item_def_id(mth, cdata);
762+
763+
let type_param_defs =
764+
item_ty_param_defs(mth, tcx, cdata,
765+
tag_items_data_item_ty_param_bounds);
766+
let name = item_name(intr, mth);
767+
let ty = doc_type(mth, tcx, cdata);
768+
769+
let fty = match ty::get(ty).sty {
770+
ty::ty_bare_fn(ref f) => copy *f,
771+
_ => {
772+
tcx.diag.handler().bug("get_provided_trait_methods(): id \
773+
has non-function type");
774+
}
775+
};
776+
777+
let transformed_self_ty = doc_transformed_self_ty(mth, tcx, cdata);
778+
let explicit_self = get_explicit_self(mth);
779+
780+
let ty_method = ty::Method::new(
781+
name,
782+
ty::Generics {
783+
type_param_defs: type_param_defs,
784+
region_param: None
785+
},
786+
transformed_self_ty,
787+
fty,
788+
explicit_self,
789+
ast::public,
790+
did
791+
);
765792
let provided_trait_method_info = ProvidedTraitMethodInfo {
766793
ty: ty_method,
767794
def_id: did

branches/snap-stage3/src/librustc/middle/trans/callee.rs

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ use middle::trans::type_of;
4242
use middle::ty;
4343
use middle::subst::Subst;
4444
use middle::typeck;
45-
use middle::typeck::coherence::make_substs_for_receiver_types;
4645
use util::ppaux::Repr;
4746

4847
use core::vec;
@@ -254,24 +253,50 @@ pub fn trans_fn_ref_with_vtables(
254253
// So, what we need to do is find this substitution and
255254
// compose it with the one we already have.
256255

257-
let trait_ref = ty::impl_trait_ref(tcx, source.impl_id)
258-
.expect("could not find trait_ref for impl with \
259-
default methods");
260-
let method = ty::method(tcx, source.method_id);
261-
262-
// Compute the first substitution
263-
let first_subst = make_substs_for_receiver_types(
264-
tcx, source.impl_id, trait_ref, method);
256+
// In order to find the substitution for the trait params,
257+
// we look up the impl in the ast map, find its trait_ref
258+
// id, then look up its trait ref. I feel like there
259+
// should be a better way.
260+
let map_node = session::expect(
261+
ccx.sess,
262+
ccx.tcx.items.find_copy(&source.impl_id.node),
263+
|| fmt!("couldn't find node while monomorphizing \
264+
default method: %?", source.impl_id.node));
265+
let item = match map_node {
266+
ast_map::node_item(item, _) => item,
267+
_ => ccx.tcx.sess.bug("Not an item")
268+
};
269+
let ast_trait_ref = match copy item.node {
270+
ast::item_impl(_, Some(tr), _, _) => tr,
271+
_ => ccx.tcx.sess.bug("Not an impl with trait_ref")
272+
};
273+
let trait_ref = ccx.tcx.trait_refs.get(&ast_trait_ref.ref_id);
274+
275+
// The substs from the trait_ref only substitues for the
276+
// trait parameters. Our substitution also needs to be
277+
// able to substitute for the actual method type
278+
// params. To do this, we figure out how many method
279+
// parameters there are and pad out the substitution with
280+
// substitution for the variables.
281+
let item_ty = ty::lookup_item_type(tcx, source.method_id);
282+
let num_params = item_ty.generics.type_param_defs.len() -
283+
trait_ref.substs.tps.len();
284+
let id_subst = do vec::from_fn(num_params) |i| {
285+
ty::mk_param(tcx, i, ast::def_id {crate: 0, node: 0})
286+
};
287+
// Merge the two substitions together now.
288+
let first_subst = ty::substs {tps: trait_ref.substs.tps + id_subst,
289+
.. trait_ref.substs};
265290

266-
// And compose them
291+
// And compose them.
267292
let new_substs = first_subst.subst(tcx, &substs);
268293
debug!("trans_fn_with_vtables - default method: \
269-
substs = %s, trait_subst = %s, \
294+
substs = %s, id_subst = %s, trait_subst = %s, \
270295
first_subst = %s, new_subst = %s",
271-
substs.repr(tcx), trait_ref.substs.repr(tcx),
296+
substs.repr(tcx),
297+
id_subst.repr(tcx), trait_ref.substs.repr(tcx),
272298
first_subst.repr(tcx), new_substs.repr(tcx));
273299

274-
275300
(source.method_id, Some(source.impl_id), new_substs)
276301
}
277302
};

branches/snap-stage3/src/librustc/middle/trans/inline.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,11 @@ pub fn maybe_instantiate_inline(ccx: @mut CrateContext, fn_id: ast::def_id,
9393
csearch::found(ast::ii_method(impl_did, mth)) => {
9494
ccx.stats.n_inlines += 1;
9595
ccx.external.insert(fn_id, Some(mth.id));
96-
// If this is a default method, we can't look up the
97-
// impl type. But we aren't going to translate anyways, so don't.
98-
if !translate { return local_def(mth.id); }
99-
100-
let impl_tpt = ty::lookup_item_type(ccx.tcx, impl_did);
101-
let num_type_params =
102-
impl_tpt.generics.type_param_defs.len() +
103-
mth.generics.ty_params.len();
104-
105-
if num_type_params == 0 {
96+
let impl_tpt = ty::lookup_item_type(ccx.tcx, impl_did);
97+
let num_type_params =
98+
impl_tpt.generics.type_param_defs.len() +
99+
mth.generics.ty_params.len();
100+
if translate && num_type_params == 0 {
106101
let llfn = get_item_val(ccx, mth.id);
107102
let path = vec::append(
108103
ty::item_path(ccx.tcx, impl_did),

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

Lines changed: 56 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -383,48 +383,71 @@ pub fn method_with_name_or_default(ccx: @mut CrateContext,
383383
name: ast::ident) -> ast::def_id {
384384
let imp = ccx.impl_method_cache.find_copy(&(impl_id, name));
385385
match imp {
386-
Some(m) => return m,
387-
None => {}
388-
}
389-
390-
// None of this feels like it should be the best way to do this.
391-
let mut did = if impl_id.crate == ast::local_crate {
392-
match ccx.tcx.items.get_copy(&impl_id.node) {
393-
ast_map::node_item(@ast::item {
394-
node: ast::item_impl(_, _, _, ref ms), _
395-
}, _) => { method_from_methods(*ms, name) },
396-
_ => fail!("method_with_name")
397-
}
398-
} else {
399-
csearch::get_impl_method(ccx.sess.cstore, impl_id, name)
400-
};
401-
402-
if did.is_none() {
403-
// Look for a default method
404-
let pmm = ccx.tcx.provided_methods;
405-
match pmm.find(&impl_id) {
406-
Some(pmis) => {
407-
for pmis.each |pmi| {
408-
if pmi.method_info.ident == name {
409-
debug!("pmi.method_info.did = %?",
410-
pmi.method_info.did);
411-
did = Some(pmi.method_info.did);
386+
Some(m) => m,
387+
None => {
388+
let imp = if impl_id.crate == ast::local_crate {
389+
match ccx.tcx.items.get_copy(&impl_id.node) {
390+
ast_map::node_item(@ast::item {
391+
node: ast::item_impl(_, _, _, ref ms), _
392+
}, _) => {
393+
let did = method_from_methods(*ms, name);
394+
if did.is_some() {
395+
did.get()
396+
} else {
397+
// Look for a default method
398+
let pmm = ccx.tcx.provided_methods;
399+
match pmm.find(&impl_id) {
400+
Some(pmis) => {
401+
for pmis.each |pmi| {
402+
if pmi.method_info.ident == name {
403+
debug!("pmi.method_info.did = %?", pmi.method_info.did);
404+
return pmi.method_info.did;
405+
}
406+
}
407+
fail!()
408+
}
409+
None => fail!()
410+
}
411+
}
412412
}
413+
_ => fail!("method_with_name")
413414
}
414-
}
415-
None => {}
415+
} else {
416+
csearch::get_impl_method(ccx.sess.cstore, impl_id, name)
417+
};
418+
419+
ccx.impl_method_cache.insert((impl_id, name), imp);
420+
421+
imp
416422
}
417423
}
418-
419-
let imp = did.expect("could not find method while translating");
420-
ccx.impl_method_cache.insert((impl_id, name), imp);
421-
imp
422424
}
423425

424426
pub fn method_ty_param_count(ccx: &CrateContext, m_id: ast::def_id,
425427
i_id: ast::def_id) -> uint {
426428
debug!("method_ty_param_count: m_id: %?, i_id: %?", m_id, i_id);
427-
ty::method(ccx.tcx, m_id).generics.type_param_defs.len()
429+
if m_id.crate == ast::local_crate {
430+
match ccx.tcx.items.find(&m_id.node) {
431+
Some(&ast_map::node_method(m, _, _)) => m.generics.ty_params.len(),
432+
None => {
433+
match ccx.tcx.provided_method_sources.find(&m_id) {
434+
Some(source) => {
435+
method_ty_param_count(
436+
ccx, source.method_id, source.impl_id)
437+
}
438+
None => fail!()
439+
}
440+
}
441+
Some(&ast_map::node_trait_method(@ast::provided(@ref m),
442+
_, _)) => {
443+
m.generics.ty_params.len()
444+
}
445+
ref e => fail!("method_ty_param_count %?", *e)
446+
}
447+
} else {
448+
csearch::get_type_param_count(ccx.sess.cstore, m_id) -
449+
csearch::get_type_param_count(ccx.sess.cstore, i_id)
450+
}
428451
}
429452

430453
pub fn trans_monomorphized_callee(bcx: block,

branches/snap-stage3/src/librustc/middle/typeck/check/method.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -541,10 +541,6 @@ impl<'self> LookupContext<'self> {
541541
if !self.impl_dups.insert(impl_info.did) {
542542
return; // already visited
543543
}
544-
debug!("push_candidates_from_impl: %s %s %s",
545-
self.m_name.repr(self.tcx()),
546-
impl_info.ident.repr(self.tcx()),
547-
impl_info.methods.map(|m| m.ident).repr(self.tcx()));
548544

549545
let idx = {
550546
match impl_info.methods.position(|m| m.ident == self.m_name) {

0 commit comments

Comments
 (0)