Skip to content

Commit 2b45da8

Browse files
committed
refactor to store the types during inference in tables in the fcx
this is a step towards separating out the repr. of types during inference from the repr. in later stages.
1 parent f682b99 commit 2b45da8

File tree

4 files changed

+358
-180
lines changed

4 files changed

+358
-180
lines changed

src/librustsyntax/visit.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ fn visit_item<E>(i: @item, e: E, v: vt<E>) {
130130
}
131131
item_impl(tps, ifce, ty, methods) {
132132
v.visit_ty_params(tps, e, v);
133-
alt ifce { some(ty) { v.visit_ty(ty, e, v); } _ {} }
133+
alt ifce { some(ty) { v.visit_ty(ty, e, v); } none {} }
134134
v.visit_ty(ty, e, v);
135135
for m in methods {
136136
visit_method_helper(m, e, v)
@@ -193,7 +193,11 @@ fn visit_ty<E>(t: @ty, e: E, v: vt<E>) {
193193
v.visit_constr(tc.node.path, tc.span, tc.node.id, e, v);
194194
}
195195
}
196-
_ {}
196+
ty_nil |
197+
ty_bot |
198+
ty_mac(_) |
199+
ty_infer {
200+
}
197201
}
198202
}
199203

@@ -243,7 +247,7 @@ fn visit_ty_params<E>(tps: [ty_param], e: E, v: vt<E>) {
243247
for bound in *tp.bounds {
244248
alt bound {
245249
bound_iface(t) { v.visit_ty(t, e, v); }
246-
_ {}
250+
bound_copy | bound_send { }
247251
}
248252
}
249253
}

src/rustc/middle/ast_map.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import std::map;
22
import std::map::hashmap;
33
import syntax::ast::*;
4+
import syntax::print::pprust;
45
import syntax::ast_util;
56
import syntax::ast_util::inlined_item_methods;
67
import syntax::{visit, codemap};
@@ -20,6 +21,14 @@ fn path_to_str_with_sep(p: path, sep: str) -> str {
2021
str::connect(strs, sep)
2122
}
2223

24+
fn path_ident_to_str(p: path, i: ident) -> str {
25+
if vec::is_empty(p) {
26+
i
27+
} else {
28+
#fmt["%s::%s", path_to_str(p), i]
29+
}
30+
}
31+
2332
fn path_to_str(p: path) -> str {
2433
path_to_str_with_sep(p, "::")
2534
}
@@ -224,6 +233,49 @@ fn map_expr(ex: @expr, cx: ctx, v: vt) {
224233
visit::visit_expr(ex, cx, v);
225234
}
226235

236+
fn node_id_to_str(map: map, id: node_id) -> str {
237+
alt map.find(id) {
238+
none {
239+
#fmt["unknown node (id=%d)", id]
240+
}
241+
some(node_item(item, path)) {
242+
#fmt["item %s (id=%?)", path_ident_to_str(*path, item.ident), id]
243+
}
244+
some(node_native_item(item, abi, path)) {
245+
#fmt["native item %s with abi %? (id=%?)",
246+
path_ident_to_str(*path, item.ident), abi, id]
247+
}
248+
some(node_method(m, impl_did, path)) {
249+
#fmt["method %s in %s (id=%?)",
250+
m.ident, path_to_str(*path), id]
251+
}
252+
some(node_variant(variant, def_id, path)) {
253+
#fmt["variant %s in %s (id=%?)",
254+
variant.node.name, path_to_str(*path), id]
255+
}
256+
some(node_expr(expr)) {
257+
#fmt["expr %s (id=%?)",
258+
pprust::expr_to_str(expr), id]
259+
}
260+
some(node_export(_, path)) {
261+
#fmt["export %s (id=%?)", // FIXME: add more info here
262+
path_to_str(*path), id]
263+
}
264+
some(node_arg(_, _)) { // FIXME: add more info here
265+
#fmt["arg (id=%?)", id]
266+
}
267+
some(node_local(_)) { // FIXME: add more info here
268+
#fmt["local (id=%?)", id]
269+
}
270+
some(node_ctor(_, _)) { // FIXME: add more info here
271+
#fmt["node_ctor (id=%?)", id]
272+
}
273+
some(node_block(_)) {
274+
#fmt["block"]
275+
}
276+
}
277+
}
278+
227279
// Local Variables:
228280
// mode: rust
229281
// fill-column: 78;

src/rustc/middle/ty.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1561,7 +1561,8 @@ fn constrs_eq(cs: [@constr], ds: [@constr]) -> bool {
15611561
fn node_id_to_type(cx: ctxt, id: ast::node_id) -> t {
15621562
alt smallintmap::find(*cx.node_types, id as uint) {
15631563
some(t) { t }
1564-
none { cx.sess.bug(#fmt("node_id_to_type: unbound node ID %?", id)); }
1564+
none { cx.sess.bug(#fmt("node_id_to_type: unbound node ID %s",
1565+
ast_map::node_id_to_str(cx.items, id))); }
15651566
}
15661567
}
15671568

0 commit comments

Comments
 (0)