Skip to content

Commit 990d7b0

Browse files
committed
---
yaml --- r: 7913 b: refs/heads/snap-stage3 c: 964bd48 h: refs/heads/master i: 7911: 4a29d9a v: v3
1 parent 4d140cd commit 990d7b0

File tree

9 files changed

+61
-98
lines changed

9 files changed

+61
-98
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
refs/heads/master: 2898dcc5d97da9427ac367542382b6239d9c0bbf
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 98c3396ab68551156021b490cf0ffed9cf3a40e3
4+
refs/heads/snap-stage3: 964bd485c6837fa08212451f45878746c9d3d308
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,14 @@ fn item_impl_iface(item: ebml::doc, tcx: ty::ctxt, cdata: cmd)
128128
result
129129
}
130130

131-
fn item_ty_param_bounds(item: ebml::doc, tcx: ty::ctxt, cdata: cmd,
132-
skip: bool) -> @[ty::param_bounds] {
133-
let bounds = [], skip = skip;
131+
fn item_ty_param_bounds(item: ebml::doc, tcx: ty::ctxt, cdata: cmd)
132+
-> @[ty::param_bounds] {
133+
let bounds = [];
134134
ebml::tagged_docs(item, tag_items_data_item_ty_param_bounds) {|p|
135135
let bd = parse_bounds_data(p.data, p.start, cdata.cnum, tcx, {|did|
136136
translate_def_id(cdata, did)
137137
});
138-
if skip { skip = false; }
139-
else { bounds += [bd]; }
138+
bounds += [bd];
140139
}
141140
@bounds
142141
}
@@ -216,9 +215,8 @@ fn get_type(cdata: cmd, id: ast::node_id, tcx: ty::ctxt)
216215
-> ty::ty_param_bounds_and_ty {
217216
let item = lookup_item(id, cdata.data);
218217
let t = item_type(item, tcx, cdata);
219-
let family = item_family(item);
220-
let tp_bounds = if family_has_type_params(family) {
221-
item_ty_param_bounds(item, tcx, cdata, family == ('I' as u8))
218+
let tp_bounds = if family_has_type_params(item_family(item)) {
219+
item_ty_param_bounds(item, tcx, cdata)
222220
} else { @[] };
223221
ret {bounds: tp_bounds, ty: t};
224222
}
@@ -301,7 +299,7 @@ fn get_iface_methods(cdata: cmd, id: ast::node_id, tcx: ty::ctxt)
301299
let data = cdata.data;
302300
let item = lookup_item(id, data), result = [];
303301
ebml::tagged_docs(item, tag_item_method) {|mth|
304-
let bounds = item_ty_param_bounds(mth, tcx, cdata, false);
302+
let bounds = item_ty_param_bounds(mth, tcx, cdata);
305303
let name = item_name(mth);
306304
let ty = doc_type(mth, tcx, cdata);
307305
let fty = alt ty::struct(tcx, ty) { ty::ty_fn(f) { f } };

branches/snap-stage3/src/comp/middle/resolve.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,7 @@ fn lookup_in_ty_params(e: env, name: ident, ty_params: [ast::ty_param])
999999
} { ret some(ast::def_ty_param(local_def(tp.id), n)); }
10001000
n += 1u;
10011001
}
1002-
ret none;
1002+
ret none::<def>;
10031003
}
10041004

10051005
fn lookup_in_pat(e: env, name: ident, pat: @ast::pat) -> option::t<def_id> {

branches/snap-stage3/src/comp/middle/trans/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ fn linearize_ty_params(cx: @block_ctxt, t: ty::t) ->
881881
}
882882
let x = @{cx: cx, mutable vals: param_vals, mutable defs: param_defs};
883883
let f = bind linearizer(x, _);
884-
ty::walk_ty(bcx_tcx(cx), t, f);
884+
ty::walk_ty(bcx_tcx(cx), f, t);
885885
ret {params: x.defs, descs: x.vals};
886886
}
887887

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

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -664,33 +664,37 @@ pure fn ty_name(cx: ctxt, typ: t) -> option::t<@str> {
664664
}
665665
}
666666

667-
fn walk_ty(cx: ctxt, ty: t, walker: fn(t)) {
667+
668+
// Type folds
669+
type ty_walk = fn@(t);
670+
671+
fn walk_ty(cx: ctxt, walker: ty_walk, ty: t) {
668672
alt struct(cx, ty) {
669673
ty_nil | ty_bot | ty_bool | ty_int(_) | ty_uint(_) | ty_float(_) |
670674
ty_str | ty_send_type | ty_type | ty_native(_) |
671675
ty_opaque_closure_ptr(_) {
672676
/* no-op */
673677
}
674-
ty_box(tm) | ty_vec(tm) | ty_ptr(tm) { walk_ty(cx, tm.ty, walker); }
678+
ty_box(tm) | ty_vec(tm) | ty_ptr(tm) { walk_ty(cx, walker, tm.ty); }
675679
ty_enum(_, subtys) | ty_iface(_, subtys) {
676-
for subty: t in subtys { walk_ty(cx, subty, walker); }
680+
for subty: t in subtys { walk_ty(cx, walker, subty); }
677681
}
678682
ty_rec(fields) {
679-
for fl: field in fields { walk_ty(cx, fl.mt.ty, walker); }
683+
for fl: field in fields { walk_ty(cx, walker, fl.mt.ty); }
680684
}
681-
ty_tup(ts) { for tt in ts { walk_ty(cx, tt, walker); } }
685+
ty_tup(ts) { for tt in ts { walk_ty(cx, walker, tt); } }
682686
ty_fn(f) {
683-
for a: arg in f.inputs { walk_ty(cx, a.ty, walker); }
684-
walk_ty(cx, f.output, walker);
687+
for a: arg in f.inputs { walk_ty(cx, walker, a.ty); }
688+
walk_ty(cx, walker, f.output);
685689
}
686690
ty_res(_, sub, tps) {
687-
walk_ty(cx, sub, walker);
688-
for tp: t in tps { walk_ty(cx, tp, walker); }
691+
walk_ty(cx, walker, sub);
692+
for tp: t in tps { walk_ty(cx, walker, tp); }
689693
}
690-
ty_constr(sub, _) { walk_ty(cx, sub, walker); }
694+
ty_constr(sub, _) { walk_ty(cx, walker, sub); }
691695
ty_var(_) {/* no-op */ }
692696
ty_param(_, _) {/* no-op */ }
693-
ty_uniq(tm) { walk_ty(cx, tm.ty, walker); }
697+
ty_uniq(tm) { walk_ty(cx, walker, tm.ty); }
694698
}
695699
walker(ty);
696700
}
@@ -1248,7 +1252,7 @@ fn vars_in_type(cx: ctxt, ty: t) -> [int] {
12481252
alt struct(cx, ty) { ty_var(v) { *vars += [v]; } _ { } }
12491253
}
12501254
let rslt: @mutable [int] = @mutable [];
1251-
walk_ty(cx, ty) {|t| collect_var(cx, rslt, t)}
1255+
walk_ty(cx, bind collect_var(cx, rslt, _), ty);
12521256
// Works because of a "convenient" bug that lets us
12531257
// return a mutable vec as if it's immutable
12541258
ret *rslt;
@@ -1503,7 +1507,7 @@ fn count_ty_params(cx: ctxt, ty: t) -> uint {
15031507
}
15041508
let param_indices: @mutable [uint] = @mutable [];
15051509
let f = bind counter(cx, param_indices, _);
1506-
walk_ty(cx, ty, f);
1510+
walk_ty(cx, f, ty);
15071511
ret vec::len::<uint>(*param_indices);
15081512
}
15091513

@@ -2647,6 +2651,7 @@ fn lookup_item_type(cx: ctxt, did: ast::def_id) -> ty_param_bounds_and_ty {
26472651
if did.crate == ast::local_crate {
26482652
// The item is in this crate. The caller should have added it to the
26492653
// type cache already; we simply return it.
2654+
26502655
ret cx.tcache.get(did);
26512656
}
26522657
alt cx.tcache.find(did) {

branches/snap-stage3/src/comp/middle/typeck.rs

Lines changed: 30 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -412,15 +412,16 @@ fn ty_of_item(tcx: ty::ctxt, mode: mode, it: @ast::item)
412412
ret tpt;
413413
}
414414
ast::item_iface(tps, ms) {
415-
let s_tp = vec::len(tps) - 1u;
416-
tcx.ty_param_bounds.insert(tps[s_tp].id, @[]);
417-
let {bounds, params} = mk_ty_params(tcx, vec::slice(tps, 0u, s_tp));
418-
let t = ty::mk_named(tcx, ty::mk_iface(tcx, local_def(it.id), params),
415+
let {bounds, params} = mk_ty_params(tcx, tps);
416+
let t = ty::mk_named(tcx, ty::mk_iface(tcx, local_def(it.id),
417+
params),
419418
@it.ident);
420419
let tpt = {bounds: bounds, ty: t};
421420
tcx.tcache.insert(local_def(it.id), tpt);
422421
ret tpt;
423422
}
423+
ast::item_impl(_, _, _, _) | ast::item_mod(_) |
424+
ast::item_native_mod(_) { fail; }
424425
}
425426
}
426427
fn ty_of_native_item(tcx: ty::ctxt, mode: mode, it: @ast::native_item)
@@ -604,22 +605,12 @@ fn mk_ty_params(tcx: ty::ctxt, atps: [ast::ty_param])
604605
}
605606

606607
fn compare_impl_method(tcx: ty::ctxt, sp: span, impl_m: ty::method,
607-
impl_tps: uint, if_m: ty::method, substs: [ty::t])
608-
-> ty::t {
608+
impl_tps: uint, if_m: ty::method, substs: [ty::t]) {
609609
if impl_m.tps != if_m.tps {
610610
tcx.sess.span_err(sp, "method `" + if_m.ident +
611611
"` has an incompatible set of type parameters");
612-
ty::mk_fn(tcx, impl_m.fty)
613612
} else {
614-
let auto_modes = vec::map2(impl_m.fty.inputs, if_m.fty.inputs, {|i, f|
615-
alt ty::struct(tcx, f.ty) {
616-
ty::ty_param(0u, _) if i.mode == ast::mode_infer {
617-
{mode: ast::by_ref with i}
618-
}
619-
_ { i }
620-
}
621-
});
622-
let impl_fty = ty::mk_fn(tcx, {inputs: auto_modes with impl_m.fty});
613+
let impl_fty = ty::mk_fn(tcx, impl_m.fty);
623614
// Add dummy substs for the parameters of the impl method
624615
let substs = substs + vec::init_fn(vec::len(*if_m.tps), {|i|
625616
ty::mk_param(tcx, i + impl_tps, {crate: 0, node: 0})
@@ -631,9 +622,8 @@ fn compare_impl_method(tcx: ty::ctxt, sp: span, impl_m: ty::method,
631622
tcx.sess.span_err(sp, "method `" + if_m.ident +
632623
"` has an incompatible type: " +
633624
ty::type_err_to_str(err));
634-
impl_fty
635625
}
636-
ty::unify::ures_ok(tp) { tp }
626+
_ {}
637627
}
638628
}
639629
}
@@ -701,15 +691,15 @@ mod collect {
701691
for m in ms {
702692
let bounds = ty_param_bounds(cx.tcx, m_collect, m.tps);
703693
let mty = ty_of_method(cx.tcx, m_collect, m);
704-
my_methods += [{mty: mty, id: m.id}];
694+
my_methods += [mty];
705695
let fty = ty::mk_fn(cx.tcx, mty.fty);
706696
cx.tcx.tcache.insert(local_def(m.id),
707697
{bounds: @(*i_bounds + *bounds),
708698
ty: fty});
709699
write::ty_only(cx.tcx, m.id, fty);
710700
}
711-
let selfty = ast_ty_to_ty(cx.tcx, m_collect, selfty);
712-
write::ty_only(cx.tcx, it.id, selfty);
701+
write::ty_only(cx.tcx, it.id, ast_ty_to_ty(cx.tcx, m_collect,
702+
selfty));
713703
alt ifce {
714704
some(t) {
715705
let iface_ty = ast_ty_to_ty(cx.tcx, m_collect, t);
@@ -719,18 +709,10 @@ mod collect {
719709
ty::ty_iface(did, tys) {
720710
for if_m in *ty::iface_methods(cx.tcx, did) {
721711
alt vec::find(my_methods,
722-
{|m| if_m.ident == m.mty.ident}) {
723-
some({mty: m, id}) {
724-
let mt = compare_impl_method(
725-
cx.tcx, t.span, m, vec::len(tps), if_m,
726-
tys + [selfty]);
727-
let old = cx.tcx.tcache.get(local_def(id));
728-
if old.ty != mt {
729-
cx.tcx.tcache.insert(local_def(id),
730-
{bounds: old.bounds,
731-
ty: mt});
732-
write::ty_only(cx.tcx, id, mt);
733-
}
712+
{|m| if_m.ident == m.ident}) {
713+
some(m) {
714+
compare_impl_method(cx.tcx, t.span, m,
715+
vec::len(tps), if_m, tys);
734716
}
735717
none {
736718
cx.tcx.sess.span_err(t.span, "missing method `" +
@@ -1518,7 +1500,7 @@ fn lookup_method(fcx: @fn_ctxt, isc: resolve::iscopes,
15181500
let m = ifce_methods[pos];
15191501
ret some({method_ty: ty::mk_fn(tcx, m.fty),
15201502
n_tps: vec::len(*m.tps),
1521-
substs: tps + [ty],
1503+
substs: tps,
15221504
origin: method_param(iid, pos, n, bound_n)});
15231505
}
15241506
_ {}
@@ -1536,7 +1518,7 @@ fn lookup_method(fcx: @fn_ctxt, isc: resolve::iscopes,
15361518
if m.ident == name {
15371519
ret some({method_ty: ty::mk_fn(tcx, m.fty),
15381520
n_tps: vec::len(*m.tps),
1539-
substs: tps + [ty::mk_int(tcx)],
1521+
substs: tps,
15401522
origin: method_iface(i)});
15411523
}
15421524
i += 1u;
@@ -1545,6 +1527,17 @@ fn lookup_method(fcx: @fn_ctxt, isc: resolve::iscopes,
15451527
_ {}
15461528
}
15471529

1530+
fn ty_from_did(tcx: ty::ctxt, did: ast::def_id) -> ty::t {
1531+
if did.crate == ast::local_crate {
1532+
alt tcx.items.get(did.node) {
1533+
ast_map::node_method(m) {
1534+
let mt = ty_of_method(tcx, m_check, m);
1535+
ty::mk_fn(tcx, mt.fty)
1536+
}
1537+
}
1538+
} else { csearch::get_type(tcx, did).ty }
1539+
}
1540+
15481541
let result = none;
15491542
std::list::iter(isc) {|impls|
15501543
if option::is_some(result) { ret; }
@@ -1563,7 +1556,7 @@ fn lookup_method(fcx: @fn_ctxt, isc: resolve::iscopes,
15631556
sp, "multiple applicable methods in scope");
15641557
} else {
15651558
result = some({
1566-
method_ty: ty::lookup_item_type(tcx, m.did).ty,
1559+
method_ty: ty_from_did(tcx, m.did),
15671560
n_tps: m.n_tps,
15681561
substs: vars,
15691562
origin: method_static(m.did)
@@ -2963,38 +2956,9 @@ mod dict {
29632956
}
29642957
}
29652958
ast::expr_cast(src, _) {
2966-
// Ifaces that refer to a self type can not be cast to -- callers
2967-
// wouldn't know what self refers to.
2968-
fn type_refers_to_self(tcx: ty::ctxt, t: ty::t, s_param: uint)
2969-
-> bool {
2970-
let found = false;
2971-
if ty::type_contains_params(tcx, t) {
2972-
ty::walk_ty(tcx, t) {|t|
2973-
alt ty::struct(tcx, t) {
2974-
ty::ty_param(n, _) if n == s_param { found = true; }
2975-
_ {}
2976-
}
2977-
}
2978-
}
2979-
found
2980-
}
2981-
fn method_refers_to_self(tcx: ty::ctxt, m: ty::method,
2982-
s_param: uint) -> bool {
2983-
vec::any(m.fty.inputs, {|in|
2984-
type_refers_to_self(tcx, in.ty, s_param)
2985-
}) || type_refers_to_self(tcx, m.fty.output, s_param)
2986-
}
29872959
let target_ty = expr_ty(cx.tcx, ex);
29882960
alt ty::struct(cx.tcx, target_ty) {
2989-
ty::ty_iface(id, tps) {
2990-
for m in *ty::iface_methods(cx.tcx, id) {
2991-
if method_refers_to_self(cx.tcx, m, vec::len(tps)) {
2992-
cx.tcx.sess.span_err(
2993-
ex.span, "can not cast to an iface type that \
2994-
refers to `self` " + m.ident);
2995-
break;
2996-
}
2997-
}
2961+
ty::ty_iface(_, _) {
29982962
let impls = cx.impl_map.get(ex.id);
29992963
let dict = lookup_dict(fcx, impls, ex.span,
30002964
expr_ty(cx.tcx, src), target_ty);

branches/snap-stage3/src/comp/syntax/parse/parser.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1850,10 +1850,9 @@ fn parse_method(p: parser) -> @ast::method {
18501850

18511851
fn parse_item_iface(p: parser, attrs: [ast::attribute]) -> @ast::item {
18521852
let lo = p.last_span.lo, ident = parse_ident(p),
1853-
tps = parse_ty_params(p), meths = parse_ty_methods(p),
1854-
self_tp = {ident: "self", id: p.get_id(), bounds: @[]};
1853+
tps = parse_ty_params(p), meths = parse_ty_methods(p);
18551854
ret mk_item(p, lo, p.last_span.hi, ident,
1856-
ast::item_iface(tps + [self_tp], meths), attrs);
1855+
ast::item_iface(tps, meths), attrs);
18571856
}
18581857

18591858
// Parses three variants (with the initial params always optional):

branches/snap-stage3/src/comp/syntax/print/pprust.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,8 +519,7 @@ fn print_item(s: ps, &&item: @ast::item) {
519519
ast::item_iface(tps, methods) {
520520
head(s, "iface");
521521
word(s.s, item.ident);
522-
print_type_params(s, vec::slice(tps, 0u, vec::len(tps) - 1u));
523-
nbsp(s);
522+
print_type_params(s, tps);
524523
bopen(s);
525524
for meth in methods { print_ty_method(s, meth); }
526525
bclose(s, item.span);

branches/snap-stage3/src/test/run-pass/iface-generic.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@ impl of to_str for () {
1212
}
1313

1414
iface map<T> {
15-
fn iter(fn(T));
1615
fn map<U>(f: fn(T) -> U) -> [U];
1716
}
1817
impl <T> of map<T> for [T] {
19-
fn iter(_f: fn(T)) {}
2018
fn map<U>(f: fn(T) -> U) -> [U] {
2119
let r = [];
2220
for x in self { r += [f(x)]; }

0 commit comments

Comments
 (0)