Skip to content

Commit ed6b5ad

Browse files
committed
---
yaml --- r: 20769 b: refs/heads/snap-stage3 c: 2cfe8fb h: refs/heads/master i: 20767: 557cb4a v: v3
1 parent 2c7bd7e commit ed6b5ad

File tree

12 files changed

+182
-23
lines changed

12 files changed

+182
-23
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: e430a699f2c60890d9b86069fd0c68a70ece7120
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 567f881fdf4053d4890929eb4cd46c67c4a011ee
4+
refs/heads/snap-stage3: 2cfe8fb357f8ad7e99dc03b09e0ec5fa1c2c9029
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/etc/vim/syntax/rust.vim

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ syn keyword rustKeyword use while with
2323
syn keyword rustKeyword mod trait class struct enum type nextgroup=rustIdentifier skipwhite
2424
syn keyword rustKeyword fn nextgroup=rustFuncName skipwhite
2525

26-
syn match rustIdentifier "\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" display contained
26+
syn match rustIdentifier contains=rustIdentifierPrime "\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" display contained
2727
syn match rustFuncName "\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" display contained
2828

2929
" Reserved words
@@ -114,8 +114,11 @@ syn match rustFatArrowHead contained ">" conceal cchar= 
114114
syn match rustFatArrowTail contained "=" conceal cchar=
115115
syn match rustFatArrowFull "=>" contains=rustFatArrowHead,rustFatArrowTail
116116

117-
hi def link rustHexNumber rustNumber
118-
hi def link rustBinNumber rustNumber
117+
syn match rustIdentifierPrime /\<\@!_\(_*\>\)\@=/ conceal cchar=
118+
119+
hi def link rustHexNumber rustNumber
120+
hi def link rustBinNumber rustNumber
121+
hi def link rustIdentifierPrime rustIdentifier
119122

120123
hi def link rustString String
121124
hi def link rustCharacter Character

branches/snap-stage3/src/libsyntax/ast.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,8 @@ type ty_field = spanned<ty_field_>;
503503

504504
#[auto_serialize]
505505
type ty_method = {ident: ident, attrs: ~[attribute],
506-
decl: fn_decl, tps: ~[ty_param], span: span};
506+
decl: fn_decl, tps: ~[ty_param], self_ty: self_ty,
507+
span: span};
507508

508509
#[auto_serialize]
509510
// A trait method is either required (meaning it doesn't have an

branches/snap-stage3/src/libsyntax/parse/parser.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ class parser {
286286
// methods are ignored; this could change.
287287
required({ident: ident, attrs: attrs,
288288
decl: {purity: pur with d}, tps: tps,
289+
self_ty: self_ty,
289290
span: mk_sp(lo, hi)})
290291
}
291292
token::LBRACE {

branches/snap-stage3/src/rustc/metadata/common.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ const tag_mod_impl_trait: uint = 0x47u;
9797
const tag_item_impl_method: uint = 0x48u;
9898
const tag_item_dtor: uint = 0x49u;
9999
const tag_paths_foreign_path: uint = 0x4a;
100+
const tag_item_trait_method_self_ty: uint = 0x4b;
101+
const tag_item_trait_method_self_ty_region: uint = 0x4c;
100102

101103
// used to encode crate_ctxt side tables
102104
enum astencode_tag { // Reserves 0x50 -- 0x6f

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

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -565,19 +565,70 @@ fn get_enum_variants(cdata: cmd, id: ast::node_id, tcx: ty::ctxt)
565565
}
566566

567567
// NB: These types are duplicated in resolve.rs
568-
type method_info = {did: ast::def_id, n_tps: uint, ident: ast::ident};
568+
type method_info = {
569+
did: ast::def_id,
570+
n_tps: uint,
571+
ident: ast::ident,
572+
self_type: ast::self_ty_
573+
};
574+
569575
type _impl = {did: ast::def_id, ident: ast::ident, methods: ~[@method_info]};
570576

577+
fn get_self_ty(item: ebml::doc) -> ast::self_ty_ {
578+
fn get_mutability(ch: u8) -> ast::mutability {
579+
alt ch as char {
580+
'i' => { ast::m_imm }
581+
'm' => { ast::m_mutbl }
582+
'c' => { ast::m_const }
583+
_ => {
584+
fail fmt!{"unknown mutability character: `%c`", ch as char}
585+
}
586+
}
587+
}
588+
589+
let self_type_doc = ebml::get_doc(item, tag_item_trait_method_self_ty);
590+
let string = ebml::doc_as_str(self_type_doc);
591+
592+
let self_ty_kind = string[0];
593+
alt self_ty_kind as char {
594+
'r' => { ret ast::sty_by_ref; }
595+
'v' => { ret ast::sty_value; }
596+
'@' => { ret ast::sty_box(get_mutability(string[1])); }
597+
'~' => { ret ast::sty_uniq(get_mutability(string[1])); }
598+
'&' => {
599+
let mutability = get_mutability(string[1]);
600+
601+
let region;
602+
let region_doc =
603+
ebml::get_doc(self_type_doc,
604+
tag_item_trait_method_self_ty_region);
605+
let region_string = str::from_bytes(ebml::doc_data(region_doc));
606+
if str::eq(region_string, ~"") {
607+
region = ast::re_anon;
608+
} else {
609+
region = ast::re_named(@region_string);
610+
}
611+
612+
ret ast::sty_region(@{ id: 0, node: region }, mutability);
613+
}
614+
_ => {
615+
fail fmt!{"unknown self type code: `%c`", self_ty_kind as char};
616+
}
617+
}
618+
}
619+
571620
fn item_impl_methods(cdata: cmd, item: ebml::doc, base_tps: uint)
572621
-> ~[@method_info] {
573622
let mut rslt = ~[];
574623
for ebml::tagged_docs(item, tag_item_impl_method) |doc| {
575624
let m_did = ebml::with_doc_data(doc, |d| parse_def_id(d));
576625
let mth_item = lookup_item(m_did.node, cdata.data);
626+
let self_ty = get_self_ty(mth_item);
577627
vec::push(rslt, @{did: translate_def_id(cdata, m_did),
578628
/* FIXME (maybe #2323) tjc: take a look at this. */
579629
n_tps: item_ty_param_count(mth_item) - base_tps,
580-
ident: item_name(mth_item)});
630+
ident: item_name(mth_item),
631+
self_type: self_ty});
581632
}
582633
rslt
583634
}
@@ -628,7 +679,9 @@ fn get_trait_methods(cdata: cmd, id: ast::node_id, tcx: ty::ctxt)
628679
tcx.diag.handler().bug(
629680
~"get_trait_methods: id has non-function type");
630681
} };
682+
let self_ty = get_self_ty(mth);
631683
vec::push(result, {ident: name, tps: bounds, fty: fty,
684+
self_ty: self_ty,
632685
purity: alt check item_family(mth) {
633686
'u' { ast::unsafe_fn }
634687
'f' { ast::impure_fn }

branches/snap-stage3/src/rustc/metadata/encoder.rs

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,58 @@ fn encode_visibility(ebml_w: ebml::writer, visibility: visibility) {
438438
});
439439
}
440440

441+
fn encode_region(ebml_w: ebml::writer, region: region) {
442+
alt region.node {
443+
re_anon => {
444+
ebml_w.wr_tagged_str(tag_item_trait_method_self_ty, ~"");
445+
}
446+
re_named(ident) => {
447+
ebml_w.wr_tagged_str(tag_item_trait_method_self_ty, *ident);
448+
}
449+
}
450+
}
451+
452+
fn encode_self_type(ebml_w: ebml::writer, self_type: ast::self_ty_) {
453+
ebml_w.start_tag(tag_item_trait_method_self_ty);
454+
455+
// Encode the base self type.
456+
let ch;
457+
alt self_type {
458+
sty_by_ref => { ch = 'r' as u8; }
459+
sty_value => { ch = 'v' as u8; }
460+
sty_region(_, _) => { ch = '&' as u8; }
461+
sty_box(_) => { ch = '@' as u8; }
462+
sty_uniq(_) => { ch = '~' as u8; }
463+
}
464+
ebml_w.writer.write(&[ ch ]);
465+
466+
// Encode mutability.
467+
alt self_type {
468+
sty_by_ref | sty_value => { /* No-op. */ }
469+
sty_region(_, m_imm) | sty_box(m_imm) | sty_uniq(m_imm) => {
470+
ebml_w.writer.write(&[ 'i' as u8 ]);
471+
}
472+
sty_region(_, m_mutbl) | sty_box(m_mutbl) | sty_uniq(m_mutbl) => {
473+
ebml_w.writer.write(&[ 'm' as u8 ]);
474+
}
475+
sty_region(_, m_const) | sty_box(m_const) | sty_uniq(m_const) => {
476+
ebml_w.writer.write(&[ 'c' as u8 ]);
477+
}
478+
}
479+
480+
// Encode the region.
481+
alt self_type {
482+
sty_region(region, _) => {
483+
encode_region(ebml_w, *region);
484+
}
485+
sty_by_ref | sty_value | sty_box(*) | sty_uniq(*) => {
486+
// Nothing to do.
487+
}
488+
}
489+
490+
ebml_w.end_tag();
491+
}
492+
441493
/* Returns an index of items in this class */
442494
fn encode_info_for_class(ecx: @encode_ctxt, ebml_w: ebml::writer,
443495
id: node_id, path: ast_map::path,
@@ -523,6 +575,7 @@ fn encode_info_for_method(ecx: @encode_ctxt, ebml_w: ebml::writer,
523575
encode_type(ecx, ebml_w, node_id_to_type(ecx.tcx, m.id));
524576
encode_name(ebml_w, m.ident);
525577
encode_path(ebml_w, impl_path, ast_map::path_name(m.ident));
578+
encode_self_type(ebml_w, m.self_ty.node);
526579
if all_tps.len() > 0u || should_inline {
527580
ecx.encode_inlined_item(
528581
ecx, ebml_w, impl_path,
@@ -712,9 +765,10 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
712765
encode_type_param_bounds(ebml_w, ecx, m.tps);
713766
encode_type(ecx, ebml_w, node_id_to_type(tcx, m.id));
714767
encode_def_id(ebml_w, local_def(m.id));
768+
encode_self_type(ebml_w, m.self_ty.node);
715769
ebml_w.end_tag();
716770
/* Write the info that's needed when viewing this class
717-
as an impl (just the method def_id) */
771+
as an impl (just the method def_id and self type) */
718772
ebml_w.start_tag(tag_item_impl_method);
719773
ebml_w.writer.write(str::bytes(def_to_str(local_def(m.id))));
720774
ebml_w.end_tag();
@@ -778,6 +832,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
778832
encode_type_param_bounds(ebml_w, ecx, ty_m.tps);
779833
encode_type(ecx, ebml_w, ty::mk_fn(tcx, mty.fty));
780834
encode_family(ebml_w, purity_fn_family(mty.purity));
835+
encode_self_type(ebml_w, mty.self_ty);
781836
ebml_w.end_tag();
782837
}
783838
provided(m) {

branches/snap-stage3/src/rustc/middle/resolve3.rs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ import syntax::ast::{item_mod, item_trait, item_ty, le, local, local_crate};
2828
import syntax::ast::{lt, method, mul, ne, neg, node_id, pat, pat_enum};
2929
import syntax::ast::{pat_ident, path, prim_ty, pat_box, pat_uniq, pat_lit};
3030
import syntax::ast::{pat_range, pat_rec, pat_tup, pat_wild, provided};
31-
import syntax::ast::{required, rem, shl, stmt_decl, subtract, ty, ty_bool};
32-
import syntax::ast::{ty_char, ty_f, ty_f32, ty_f64, ty_float, ty_i, ty_i16};
33-
import syntax::ast::{ty_i32, ty_i64, ty_i8, ty_int, ty_param, ty_path};
34-
import syntax::ast::{ty_str, ty_u, ty_u16, ty_u32, ty_u64, ty_u8, ty_uint};
35-
import syntax::ast::{variant, view_item, view_item_export, view_item_import};
36-
import syntax::ast::{view_item_use, view_path_glob, view_path_list};
37-
import syntax::ast::{view_path_simple};
31+
import syntax::ast::{required, rem, self_ty_, shl, stmt_decl, subtract, ty};
32+
import syntax::ast::{ty_bool, ty_char, ty_f, ty_f32, ty_f64, ty_float, ty_i};
33+
import syntax::ast::{ty_i16, ty_i32, ty_i64, ty_i8, ty_int, ty_param};
34+
import syntax::ast::{ty_path, ty_str, ty_u, ty_u16, ty_u32, ty_u64, ty_u8};
35+
import syntax::ast::{ty_uint, variant, view_item, view_item_export};
36+
import syntax::ast::{view_item_import, view_item_use, view_path_glob};
37+
import syntax::ast::{view_path_list, view_path_simple};
3838
import syntax::ast_util::{def_id_of_def, dummy_sp, local_def, new_def_hash};
3939
import syntax::ast_util::{walk_pat};
4040
import syntax::attr::{attr_metas, contains_name};
@@ -59,7 +59,16 @@ import str_eq = str::eq;
5959
type DefMap = hashmap<node_id,def>;
6060

6161
// Implementation resolution
62-
type MethodInfo = { did: def_id, n_tps: uint, ident: ident };
62+
63+
// XXX: This kind of duplicates information kept in ty::method. Maybe it
64+
// should go away.
65+
type MethodInfo = {
66+
did: def_id,
67+
n_tps: uint,
68+
ident: ident,
69+
self_type: self_ty_
70+
};
71+
6372
type Impl = { did: def_id, ident: ident, methods: ~[@MethodInfo] };
6473
type ImplScope = @~[@Impl];
6574
type ImplScopes = @list<ImplScope>;
@@ -925,7 +934,8 @@ class Resolver {
925934
@{
926935
did: local_def(method.id),
927936
n_tps: method.tps.len(),
928-
ident: method.ident
937+
ident: method.ident,
938+
self_type: method.self_ty.node
929939
}
930940
];
931941
}
@@ -962,7 +972,8 @@ class Resolver {
962972
@{
963973
did: local_def(method.id),
964974
n_tps: method.tps.len(),
965-
ident: method.ident
975+
ident: method.ident,
976+
self_type: method.self_ty.node
966977
}
967978
];
968979
}

branches/snap-stage3/src/rustc/middle/ty.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ type param_bounds = @~[param_bound];
183183
type method = {ident: ast::ident,
184184
tps: @~[param_bounds],
185185
fty: fn_ty,
186+
self_ty: ast::self_ty_,
186187
purity: ast::purity,
187188
vis: ast::visibility};
188189

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

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
/* Code to handle method lookups (which can be quite complex) */
22

33
import coherence::get_base_type_def_id;
4-
import middle::resolve3::Impl;
4+
import middle::resolve3::{Impl, MethodInfo};
5+
import middle::ty::{mk_box, mk_rptr, mk_uniq};
56
import middle::typeck::infer::methods; // next_ty_vars
6-
import syntax::ast::def_id;
7+
import syntax::ast::{def_id, sty_box, sty_by_ref, sty_region, sty_uniq};
8+
import syntax::ast::{sty_value};
79
import syntax::ast_map;
810
import syntax::ast_map::node_id_to_str;
9-
import syntax::ast_util::new_def_hash;
11+
import syntax::ast_util::{dummy_sp, new_def_hash};
1012
import dvec::{dvec, extensions};
1113

1214
type candidate = {
@@ -18,6 +20,28 @@ type candidate = {
1820
entry: method_map_entry
1921
};
2022

23+
fn transform_self_type_for_method(fcx: @fn_ctxt,
24+
impl_ty: ty::t,
25+
method_info: MethodInfo)
26+
-> ty::t {
27+
alt method_info.self_type {
28+
sty_by_ref | sty_value => {
29+
impl_ty
30+
}
31+
sty_region(r, mutability) => {
32+
// XXX: dummy_sp is unfortunate here.
33+
let region = ast_region_to_region(fcx, fcx, dummy_sp(), r);
34+
mk_rptr(fcx.ccx.tcx, region, { ty: impl_ty, mutbl: mutability })
35+
}
36+
sty_box(mutability) => {
37+
mk_box(fcx.ccx.tcx, { ty: impl_ty, mutbl: mutability })
38+
}
39+
sty_uniq(mutability) => {
40+
mk_uniq(fcx.ccx.tcx, { ty: impl_ty, mutbl: mutability })
41+
}
42+
}
43+
}
44+
2145
class lookup {
2246
let fcx: @fn_ctxt;
2347
let expr: @ast::expr;
@@ -370,6 +394,10 @@ class lookup {
370394
let {substs: impl_substs, ty: impl_ty} =
371395
impl_self_ty(self.fcx, im.did);
372396

397+
let impl_ty = transform_self_type_for_method(self.fcx,
398+
impl_ty,
399+
*m);
400+
373401
// Depending on our argument, we find potential
374402
// matches either by checking subtypability or
375403
// type assignability. Collect the matches.

branches/snap-stage3/src/rustc/middle/typeck/coherence.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,8 @@ class CoherenceChecker {
492492
push(methods, @{
493493
did: local_def(ast_method.id),
494494
n_tps: ast_method.tps.len(),
495-
ident: ast_method.ident
495+
ident: ast_method.ident,
496+
self_type: ast_method.self_ty.node
496497
});
497498
}
498499
@@ -513,7 +514,8 @@ class CoherenceChecker {
513514
push(methods, @{
514515
did: local_def(ast_method.id),
515516
n_tps: ast_method.tps.len(),
516-
ident: ast_method.ident
517+
ident: ast_method.ident,
518+
self_type: ast_method.self_ty.node
517519
});
518520
}
519521
}

branches/snap-stage3/src/rustc/middle/typeck/collect.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ fn ty_of_method(ccx: @crate_ctxt,
432432
tps: ty_param_bounds(ccx, m.tps),
433433
fty: ty_of_fn_decl(ccx, type_rscope(rp), ast::proto_bare,
434434
m.decl, none),
435+
self_ty: m.self_ty.node,
435436
purity: m.decl.purity,
436437
vis: m.vis}
437438
}
@@ -444,6 +445,7 @@ fn ty_of_ty_method(self: @crate_ctxt,
444445
fty: ty_of_fn_decl(self, type_rscope(rp), ast::proto_bare,
445446
m.decl, none),
446447
// assume public, because this is only invoked on trait methods
448+
self_ty: m.self_ty.node,
447449
purity: m.decl.purity, vis: ast::public}
448450
}
449451

0 commit comments

Comments
 (0)