Skip to content

Commit 9783864

Browse files
committed
---
yaml --- r: 4823 b: refs/heads/master c: 30b5f85 h: refs/heads/master i: 4821: b6889c6 4819: 73569b3 4815: 7c837af v: v3
1 parent 430dd7b commit 9783864

File tree

5 files changed

+64
-43
lines changed

5 files changed

+64
-43
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 031529e3fe34267168a43cf74dbdd9e41f12ac43
2+
refs/heads/master: 30b5f851c57ff1e5aabaf25277aaaacff4df2c7b

trunk/src/comp/driver/rustc.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,13 @@ fn compile_input(sess: session::session, cfg: ast::crate_cfg, input: str,
143143
bind middle::ast_map::map_crate(*crate));
144144
time(time_passes, "external crate/lib resolution",
145145
bind creader::read_crates(sess, *crate));
146-
let d =
146+
let {def_map, ext_map} =
147147
time(time_passes, "resolution",
148148
bind resolve::resolve_crate(sess, ast_map, crate));
149149
let freevars =
150150
time(time_passes, "freevar finding",
151-
bind freevars::annotate_freevars(sess, d, crate));
152-
let ty_cx = ty::mk_ctxt(sess, d, ast_map, freevars);
151+
bind freevars::annotate_freevars(sess, def_map, crate));
152+
let ty_cx = ty::mk_ctxt(sess, def_map, ext_map, ast_map, freevars);
153153
time::<()>(time_passes, "typechecking",
154154
bind typeck::check_crate(ty_cx, crate));
155155
time::<()>(time_passes, "alt checking",
@@ -222,9 +222,9 @@ fn pretty_print_input(sess: session::session, cfg: ast::crate_cfg, input: str,
222222
alt ppm {
223223
ppm_typed. {
224224
let amap = middle::ast_map::map_crate(*crate);
225-
let d = resolve::resolve_crate(sess, amap, crate);
226-
let freevars = freevars::annotate_freevars(sess, d, crate);
227-
let ty_cx = ty::mk_ctxt(sess, d, amap, freevars);
225+
let {def_map, ext_map} = resolve::resolve_crate(sess, amap, crate);
226+
let freevars = freevars::annotate_freevars(sess, def_map, crate);
227+
let ty_cx = ty::mk_ctxt(sess, def_map, ext_map, amap, freevars);
228228
typeck::check_crate(ty_cx, crate);
229229
ann = {pre: ann_paren_for_expr, post: bind ann_typed_post(ty_cx, _)};
230230
}

trunk/src/comp/middle/resolve.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import syntax::print::pprust::*;
3636

3737
export resolve_crate;
3838
export def_map;
39+
export ext_map;
3940

4041
// Resolving happens in two passes. The first pass collects defids of all
4142
// (internal) imports and modules, so that they can be looked up when needed,
@@ -113,6 +114,7 @@ type indexed_mod =
113114
only need to look at them to determine exports, which they can't control.*/
114115

115116
type def_map = hashmap<node_id, def>;
117+
type ext_map = hashmap<def_id, [ident]>;
116118

117119
type env =
118120
{cstore: cstore::cstore,
@@ -133,7 +135,7 @@ tag dir { inside; outside; }
133135
tag namespace { ns_value; ns_type; ns_module; }
134136

135137
fn resolve_crate(sess: session, amap: &ast_map::map, crate: @ast::crate) ->
136-
def_map {
138+
{def_map: def_map, ext_map: ext_map} {
137139
let e =
138140
@{cstore: sess.get_cstore(),
139141
def_map: new_int_hash::<def>(),
@@ -148,7 +150,7 @@ fn resolve_crate(sess: session, amap: &ast_map::map, crate: @ast::crate) ->
148150
resolve_imports(*e);
149151
check_for_collisions(e, *crate);
150152
resolve_names(e, crate);
151-
ret e.def_map;
153+
ret {def_map: e.def_map, ext_map: e.ext_map};
152154
}
153155

154156

trunk/src/comp/middle/ty.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@ type ctxt =
212212
@{ts: @type_store,
213213
sess: session::session,
214214
def_map: resolve::def_map,
215+
// We need the ext_map just for printing the types of tags defined in
216+
// other crates. Once we get cnames back it should go.
217+
ext_map: resolve::ext_map,
215218
node_types: node_type_table,
216219
items: ast_map::map,
217220
freevars: freevars::freevar_map,
@@ -392,7 +395,8 @@ fn mk_rcache() -> creader_cache {
392395
}
393396

394397

395-
fn mk_ctxt(s: session::session, dm: resolve::def_map, amap: ast_map::map,
398+
fn mk_ctxt(s: session::session, dm: resolve::def_map,
399+
em: hashmap<def_id, [ident]>, amap: ast_map::map,
396400
freevars: freevars::freevar_map) -> ctxt {
397401
let ntt: node_type_table =
398402
@smallintmap::mk::<ty::ty_param_substs_opt_and_ty>();
@@ -402,6 +406,7 @@ fn mk_ctxt(s: session::session, dm: resolve::def_map, amap: ast_map::map,
402406
@{ts: ts,
403407
sess: s,
404408
def_map: dm,
409+
ext_map: em,
405410
node_types: ntt,
406411
items: amap,
407412
freevars: freevars,
@@ -1066,6 +1071,13 @@ fn type_kind(cx: &ctxt, ty: &t) -> ast::kind {
10661071
if result == ast::kind_pinned { break; }
10671072
}
10681073
}
1074+
// Tuples lower to the lowest of their members.
1075+
ty_tup(tys) {
1076+
for ty: t in tys {
1077+
result = kind::lower_kind(result, type_kind(cx, ty));
1078+
if result == ast::kind_pinned { break; }
1079+
}
1080+
}
10691081

10701082
// Tags lower to the lowest of their variants.
10711083
ty_tag(did, tps) {

trunk/src/comp/util/ppaux.rs

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import pp::zerobreak;
1818
import pp::hardbreak;
1919
import ast::ty_mach_to_str;
2020
import syntax::ast;
21+
import middle::ast_map;
22+
import metadata::csearch;
2123

2224
fn mode_str(m: &ty::mode) -> str {
2325
alt m {
@@ -35,6 +37,17 @@ fn fn_ident_to_string(id: ast::node_id, i: &ast::fn_ident) -> str {
3537
ret alt i { none. { "anon" + int::str(id) } some(s) { s } };
3638
}
3739

40+
fn get_id_ident(cx: &ctxt, id: ast::def_id) -> str {
41+
if (id.crate != ast::local_crate) {
42+
str::connect(cx.ext_map.get(id), "::")
43+
} else {
44+
alt cx.items.find(id.node) {
45+
some(ast_map::node_item(it)) { it.ident }
46+
_ { fail "get_id_ident: can't find item in ast_map" }
47+
}
48+
}
49+
}
50+
3851
fn ty_to_str(cx: &ctxt, typ: &t) -> str {
3952
fn fn_input_to_str(cx: &ctxt, input: &{mode: middle::ty::mode, ty: t}) ->
4053
str {
@@ -77,67 +90,61 @@ fn ty_to_str(cx: &ctxt, typ: &t) -> str {
7790
ret mstr + ty_to_str(cx, m.ty);
7891
}
7992
alt cname(cx, typ) { some(cs) { ret cs; } _ { } }
80-
let s = "";
81-
alt struct(cx, typ) {
82-
ty_native(_) { s += "native"; }
83-
ty_nil. { s += "()"; }
84-
ty_bot. { s += "_|_"; }
85-
ty_bool. { s += "bool"; }
86-
ty_int. { s += "int"; }
87-
ty_float. { s += "float"; }
88-
ty_uint. { s += "uint"; }
89-
ty_machine(tm) { s += ty_mach_to_str(tm); }
90-
ty_char. { s += "char"; }
91-
ty_str. { s += "str"; }
92-
ty_istr. { s += "istr"; }
93-
ty_box(tm) { s += "@" + mt_to_str(cx, tm); }
94-
ty_uniq(t) { s += "~" + ty_to_str(cx, t); }
95-
ty_vec(tm) { s += "[" + mt_to_str(cx, tm) + "]"; }
96-
ty_type. { s += "type"; }
93+
ret alt struct(cx, typ) {
94+
ty_native(_) { "native" }
95+
ty_nil. { "()" }
96+
ty_bot. { "_|_" }
97+
ty_bool. { "bool" }
98+
ty_int. { "int" }
99+
ty_float. { "float" }
100+
ty_uint. { "uint" }
101+
ty_machine(tm) { ty_mach_to_str(tm) }
102+
ty_char. { "char" }
103+
ty_str. { "str" }
104+
ty_istr. { "istr" }
105+
ty_box(tm) { "@" + mt_to_str(cx, tm) }
106+
ty_uniq(t) { "~" + ty_to_str(cx, t) }
107+
ty_vec(tm) { "[" + mt_to_str(cx, tm) + "]" }
108+
ty_type. { "type" }
97109
ty_rec(elems) {
98110
let strs: [str] = ~[];
99111
for fld: field in elems { strs += ~[field_to_str(cx, fld)]; }
100-
s += "{" + str::connect(strs, ",") + "}";
112+
"{" + str::connect(strs, ",") + "}"
101113
}
102114
ty_tup(elems) {
103115
let strs = ~[];
104116
for elem in elems { strs += ~[ty_to_str(cx, elem)]; }
105-
s += "(" + str::connect(strs, ",") + ")";
117+
"(" + str::connect(strs, ",") + ")"
106118
}
107119
ty_tag(id, tps) {
108-
// The user should never see this if the cname is set properly!
109-
110-
s += "<tag#" + int::str(id.crate) + ":" + int::str(id.node) + ">";
120+
let s = get_id_ident(cx, id);
111121
if vec::len::<t>(tps) > 0u {
112122
let strs: [str] = ~[];
113123
for typ: t in tps { strs += ~[ty_to_str(cx, typ)]; }
114124
s += "[" + str::connect(strs, ",") + "]";
115125
}
126+
s
116127
}
117128
ty_fn(proto, inputs, output, cf, constrs) {
118-
s += fn_to_str(cx, proto, none, inputs, output, cf, constrs);
129+
fn_to_str(cx, proto, none, inputs, output, cf, constrs)
119130
}
120131
ty_native_fn(_, inputs, output) {
121-
s +=
122-
fn_to_str(cx, ast::proto_fn, none, inputs, output, ast::return,
123-
~[]);
132+
fn_to_str(cx, ast::proto_fn, none, inputs, output, ast::return, ~[])
124133
}
125134
ty_obj(meths) {
126135
let strs = ~[];
127136
for m: method in meths { strs += ~[method_to_str(cx, m)]; }
128-
s += "obj {\n\t" + str::connect(strs, "\n\t") + "\n}";
137+
"obj {\n\t" + str::connect(strs, "\n\t") + "\n}"
129138
}
130139
ty_res(id, _, _) {
131-
s +=
132-
"<resource#" + int::str(id.node) + ":" + int::str(id.crate) + ">";
140+
get_id_ident(cx, id)
133141
}
134-
ty_var(v) { s += "<T" + int::str(v) + ">"; }
142+
ty_var(v) { "<T" + int::str(v) + ">" }
135143
ty_param(id,_) {
136-
s += "'" + str::unsafe_from_bytes(~[('a' as u8) + (id as u8)]);
144+
"'" + str::unsafe_from_bytes(~[('a' as u8) + (id as u8)])
137145
}
138-
_ { s += ty_to_short_str(cx, typ); }
146+
_ { ty_to_short_str(cx, typ) }
139147
}
140-
ret s;
141148
}
142149

143150
fn ty_to_short_str(cx: &ctxt, typ: t) -> str {

0 commit comments

Comments
 (0)