Skip to content

Commit bbfe462

Browse files
committed
---
yaml --- r: 11197 b: refs/heads/master c: 0263039 h: refs/heads/master i: 11195: 4ff3447 v: v3
1 parent 63eaa64 commit bbfe462

File tree

9 files changed

+79
-59
lines changed

9 files changed

+79
-59
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: fdddf8f9e1d6738d42989a6d8a735dd58127e199
2+
refs/heads/master: 0263039ca0350eb67ce11e985bd7e698de48ca0f
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/Makefile.in

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,9 +410,12 @@ TSREQS := \
410410
FUZZ := $(HBIN3_H_$(CFG_HOST_TRIPLE))/fuzzer$(X)
411411
CARGO := $(HBIN3_H_$(CFG_HOST_TRIPLE))/cargo$(X)
412412
RUSTDOC := $(HBIN3_H_$(CFG_HOST_TRIPLE))/rustdoc$(X)
413-
SERIALIZER := $(HBIN3_H_$(CFG_HOST_TRIPLE))/serializer$(X)
413+
SERIALIZER := $(HBIN2_H_$(CFG_HOST_TRIPLE))/serializer$(X)
414+
# ^^ Note: we use HBIN2 because that is the only stage for which
415+
# we build a complete rustc by default, and serializer requires
416+
# the complete rustc.
414417

415-
all: rustc $(GENERATED) docs $(FUZZ) $(CARGO) $(RUSTDOC)
418+
all: rustc $(GENERATED) docs $(FUZZ) $(CARGO) $(RUSTDOC) $(SERIALIZER)
416419

417420
endif
418421

trunk/src/comp/metadata/decoder.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,11 @@ fn doc_type(doc: ebml::doc, tcx: ty::ctxt, cdata: cmd) -> ty::t {
112112
})
113113
}
114114

115-
fn item_type(item: ebml::doc, tcx: ty::ctxt, cdata: cmd) -> ty::t {
115+
fn item_type(item_id: ast::def_id, item: ebml::doc,
116+
tcx: ty::ctxt, cdata: cmd) -> ty::t {
116117
let t = doc_type(item, tcx, cdata);
117118
if family_names_type(item_family(item)) {
118-
ty::mk_named(tcx, t, item_name(item))
119+
ty::mk_with_id(tcx, t, item_id)
119120
} else { t }
120121
}
121122

@@ -240,7 +241,7 @@ fn lookup_def(cnum: ast::crate_num, data: @[u8], did_: ast::def_id) ->
240241
fn get_type(cdata: cmd, id: ast::node_id, tcx: ty::ctxt)
241242
-> ty::ty_param_bounds_and_ty {
242243
let item = lookup_item(id, cdata.data);
243-
let t = item_type(item, tcx, cdata);
244+
let t = item_type({crate: cdata.cnum, node: id}, item, tcx, cdata);
244245
let tp_bounds = if family_has_type_params(item_family(item)) {
245246
item_ty_param_bounds(item, tcx, cdata)
246247
} else { @[] };
@@ -274,7 +275,8 @@ fn get_enum_variants(cdata: cmd, id: ast::node_id, tcx: ty::ctxt)
274275
let disr_val = 0;
275276
for did: ast::def_id in variant_ids {
276277
let item = find_item(did.node, items);
277-
let ctor_ty = item_type(item, tcx, cdata);
278+
let ctor_ty = item_type({crate: cdata.cnum, node: id}, item,
279+
tcx, cdata);
278280
let name = item_name(item);
279281
let arg_tys: [ty::t] = [];
280282
alt ty::get(ctor_ty).struct {

trunk/src/comp/metadata/tydecode.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,11 +293,9 @@ fn parse_ty(st: @pstate, conv: conv_did) -> ty::t {
293293
ret ty::mk_constr(st.tcx, tt, tcs);
294294
}
295295
'"' {
296-
let name = "";
297-
while peek(st) as char != '"' { str::push_byte(name, next(st)); }
298-
st.pos = st.pos + 1u;
296+
let def = parse_def(st, conv);
299297
let inner = parse_ty(st, conv);
300-
ty::mk_named(st.tcx, inner, name)
298+
ty::mk_with_id(st.tcx, inner, def)
301299
}
302300
'B' { ty::mk_opaque_box(st.tcx) }
303301
c { #error("unexpected char in type string: %c", c); fail;}

trunk/src/comp/metadata/tyencode.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ fn enc_ty(w: io::writer, cx: @ctxt, t: ty::t) {
5353
some(a) { w.write_str(*a.s); ret; }
5454
none {
5555
let pos = w.tell();
56-
alt ty::type_name(t) {
57-
some(n) {
58-
w.write_char('"');
59-
w.write_str(n);
56+
alt ty::type_def_id(t) {
57+
some(def_id) {
6058
w.write_char('"');
59+
w.write_str(cx.ds(def_id));
60+
w.write_char('|');
6161
}
6262
_ {}
6363
}

trunk/src/comp/middle/ty.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export method;
4242
export method_idx;
4343
export mk_class;
4444
export mk_ctxt;
45-
export mk_named, type_name;
45+
export mk_with_id, type_def_id;
4646
export mt;
4747
export node_type_table;
4848
export pat_ty;
@@ -151,8 +151,10 @@ type mt = {ty: t, mut: ast::mutability};
151151
// the types of AST nodes.
152152
type creader_cache = hashmap<{cnum: int, pos: uint, len: uint}, t>;
153153

154+
type intern_key = {struct: sty, o_def_id: option<ast::def_id>};
155+
154156
type ctxt =
155-
@{interner: hashmap<{struct: sty, name: option<str>}, t_box>,
157+
@{interner: hashmap<intern_key, t_box>,
156158
mutable next_id: uint,
157159
sess: session::session,
158160
def_map: resolve::def_map,
@@ -175,7 +177,7 @@ type t_box = @{struct: sty,
175177
id: uint,
176178
has_params: bool,
177179
has_vars: bool,
178-
name: option<str>};
180+
o_def_id: option<ast::def_id>};
179181

180182
// To reduce refcounting cost, we're representing types as unsafe pointers
181183
// throughout the compiler. These are simply casted t_box values. Use ty::get
@@ -194,7 +196,7 @@ pure fn get(t: t) -> t_box unsafe {
194196

195197
fn type_has_params(t: t) -> bool { get(t).has_params }
196198
fn type_has_vars(t: t) -> bool { get(t).has_vars }
197-
fn type_name(t: t) -> option<str> { get(t).name }
199+
fn type_def_id(t: t) -> option<ast::def_id> { get(t).o_def_id }
198200
fn type_id(t: t) -> uint { get(t).id }
199201

200202
enum closure_kind {
@@ -308,10 +310,9 @@ fn new_ty_hash<V: copy>() -> map::hashmap<t, V> {
308310

309311
fn mk_ctxt(s: session::session, dm: resolve::def_map, amap: ast_map::map,
310312
freevars: freevars::freevar_map) -> ctxt {
311-
let interner = map::mk_hashmap({|&&k: {struct: sty, name: option<str>}|
312-
hash_type_structure(k.struct) + alt k.name {
313-
some(s) { str::hash(s) } _ { 0u }
314-
}
313+
let interner = map::mk_hashmap({|&&k: intern_key|
314+
hash_type_structure(k.struct) +
315+
option::maybe(0u, k.o_def_id, ast_util::hash_def_id)
315316
}, {|&&a, &&b| a == b});
316317
@{interner: interner,
317318
mutable next_id: 0u,
@@ -335,12 +336,12 @@ fn mk_ctxt(s: session::session, dm: resolve::def_map, amap: ast_map::map,
335336

336337

337338
// Type constructors
338-
fn mk_t(cx: ctxt, st: sty) -> t { mk_t_named(cx, st, none) }
339+
fn mk_t(cx: ctxt, st: sty) -> t { mk_t_with_id(cx, st, none) }
339340

340341
// Interns a type/name combination, stores the resulting box in cx.interner,
341342
// and returns the box as cast to an unsafe ptr (see comments for t above).
342-
fn mk_t_named(cx: ctxt, st: sty, name: option<str>) -> t {
343-
let key = {struct: st, name: name};
343+
fn mk_t_with_id(cx: ctxt, st: sty, o_def_id: option<ast::def_id>) -> t {
344+
let key = {struct: st, o_def_id: o_def_id};
344345
alt cx.interner.find(key) {
345346
some(t) { unsafe { ret unsafe::reinterpret_cast(t); } }
346347
_ {}
@@ -385,7 +386,7 @@ fn mk_t_named(cx: ctxt, st: sty, name: option<str>) -> t {
385386
id: cx.next_id,
386387
has_params: has_params,
387388
has_vars: has_vars,
388-
name: name};
389+
o_def_id: o_def_id};
389390
cx.interner.insert(key, t);
390391
cx.next_id += 1u;
391392
unsafe { unsafe::reinterpret_cast(t) }
@@ -469,8 +470,8 @@ fn mk_opaque_closure_ptr(cx: ctxt, ck: closure_kind) -> t {
469470

470471
fn mk_opaque_box(cx: ctxt) -> t { mk_t(cx, ty_opaque_box) }
471472

472-
fn mk_named(cx: ctxt, base: t, name: str) -> t {
473-
mk_t_named(cx, get(base).struct, some(name))
473+
fn mk_with_id(cx: ctxt, base: t, def_id: ast::def_id) -> t {
474+
mk_t_with_id(cx, get(base).struct, some(def_id))
474475
}
475476

476477
// Converts s to its machine type equivalent

trunk/src/comp/middle/typeck.rs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ fn ty_of_item(tcx: ty::ctxt, mode: mode, it: @ast::item)
373373
some(tpt) { ret tpt; }
374374
_ {}
375375
}
376+
let def_id = {crate: ast::local_crate, node: it.id};
376377
alt it.node {
377378
ast::item_const(t, _) {
378379
let typ = ast_ty_to_ty(tcx, mode, t);
@@ -390,36 +391,42 @@ fn ty_of_item(tcx: ty::ctxt, mode: mode, it: @ast::item)
390391
}
391392
// Tell ast_ty_to_ty() that we want to perform a recursive
392393
// call to resolve any named types.
393-
let tpt = {bounds: ty_param_bounds(tcx, mode, tps),
394-
ty: ty::mk_named(tcx, ast_ty_to_ty(tcx, mode, t),
395-
it.ident)};
394+
let tpt = {
395+
let t0 = ast_ty_to_ty(tcx, mode, t);
396+
{bounds: ty_param_bounds(tcx, mode, tps),
397+
ty: ty::mk_with_id(tcx, t0, def_id)}
398+
};
396399
tcx.tcache.insert(local_def(it.id), tpt);
397400
ret tpt;
398401
}
399402
ast::item_res(decl, tps, _, _, _) {
400403
let {bounds, params} = mk_ty_params(tcx, tps);
401404
let t_arg = ty_of_arg(tcx, mode, decl.inputs[0]);
402-
let t = ty::mk_named(tcx, ty::mk_res(tcx, local_def(it.id), t_arg.ty,
403-
params),
404-
it.ident);
405+
let t = {
406+
let t0 = ty::mk_res(tcx, local_def(it.id), t_arg.ty, params);
407+
ty::mk_with_id(tcx, t0, def_id)
408+
};
405409
let t_res = {bounds: bounds, ty: t};
406410
tcx.tcache.insert(local_def(it.id), t_res);
407411
ret t_res;
408412
}
409413
ast::item_enum(_, tps) {
410414
// Create a new generic polytype.
411415
let {bounds, params} = mk_ty_params(tcx, tps);
412-
let t = ty::mk_named(tcx, ty::mk_enum(tcx, local_def(it.id), params),
413-
it.ident);
416+
let t = {
417+
let t0 = ty::mk_enum(tcx, local_def(it.id), params);
418+
ty::mk_with_id(tcx, t0, def_id)
419+
};
414420
let tpt = {bounds: bounds, ty: t};
415421
tcx.tcache.insert(local_def(it.id), tpt);
416422
ret tpt;
417423
}
418424
ast::item_iface(tps, ms) {
419425
let {bounds, params} = mk_ty_params(tcx, tps);
420-
let t = ty::mk_named(tcx, ty::mk_iface(tcx, local_def(it.id),
421-
params),
422-
it.ident);
426+
let t = {
427+
let t0 = ty::mk_iface(tcx, local_def(it.id), params);
428+
ty::mk_with_id(tcx, t0, def_id)
429+
};
423430
let tpt = {bounds: bounds, ty: t};
424431
tcx.tcache.insert(local_def(it.id), tpt);
425432
ret tpt;

trunk/src/comp/util/ppaux.rs

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import syntax::print::pprust::{path_to_str, constr_args_to_str, proto_to_str,
66
mode_to_str};
77
import syntax::{ast, ast_util};
88
import middle::ast_map;
9+
import driver::session::session;
910

1011
fn ty_to_str(cx: ctxt, typ: t) -> str {
1112
fn fn_input_to_str(cx: ctxt, input: {mode: ast::mode, ty: t}) ->
@@ -60,21 +61,28 @@ fn ty_to_str(cx: ctxt, typ: t) -> str {
6061
}
6162
ret mstr + ty_to_str(cx, m.ty);
6263
}
63-
alt ty::type_name(typ) {
64-
some(cs) {
65-
alt ty::get(typ).struct {
66-
ty_enum(_, tps) | ty_res(_, _, tps) {
67-
if vec::len(tps) > 0u {
68-
let strs = vec::map(tps, {|t| ty_to_str(cx, t)});
69-
ret cs + "<" + str::connect(strs, ",") + ">";
70-
}
71-
}
72-
_ {}
64+
fn parameterized(cx: ctxt, base: str, tps: [ty::t]) -> str {
65+
if vec::len(tps) > 0u {
66+
let strs = vec::map(tps, {|t| ty_to_str(cx, t)});
67+
#fmt["%s<%s>", base, str::connect(strs, ",")]
68+
} else {
69+
base
7370
}
74-
ret cs;
71+
}
72+
73+
// if there is an id, print that instead of the structural type:
74+
alt ty::type_def_id(typ) {
75+
some(def_id) {
76+
let cs = ast_map::path_to_str(ty::item_path(cx, def_id));
77+
ret alt ty::get(typ).struct {
78+
ty_enum(_, tps) | ty_res(_, _, tps) { parameterized(cx, cs, tps) }
79+
_ { cs }
80+
};
7581
}
76-
_ { }
82+
none { /* fallthrough */}
7783
}
84+
85+
// pretty print the structural type representation:
7886
ret alt ty::get(typ).struct {
7987
ty_nil { "()" }
8088
ty_bot { "_|_" }
@@ -110,15 +118,13 @@ fn ty_to_str(cx: ctxt, typ: t) -> str {
110118
ty_param(id, _) {
111119
"'" + str::from_bytes([('a' as u8) + (id as u8)])
112120
}
113-
ty_enum(did, tps) {
121+
ty_enum(did, tps) | ty_res(did, _, tps) {
122+
// Not sure why, but under some circumstances enum or resource types
123+
// do not have an associated id. I didn't investigate enough to know
124+
// if there is a good reason for this. - Niko, 2012-02-10
114125
let path = ty::item_path(cx, did);
115126
let base = ast_map::path_to_str(path);
116-
if vec::is_empty(tps) {
117-
base
118-
} else {
119-
let tps_strs = vec::map(tps) {|t| ty_to_str(cx, t) };
120-
#fmt["%s<%s>", base, str::connect(tps_strs, ",")]
121-
}
127+
parameterized(cx, base, tps)
122128
}
123129
_ { ty_to_short_str(cx, typ) }
124130
}

trunk/src/etc/ctags.rust

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@
66
--regex-rust=/[ \t]*resource[ \t]+([a-zA-Z0-9_]+)/\1/T,types/
77
--regex-rust=/[ \t]*mod[ \t]+([a-zA-Z0-9_]+)/\1/m,modules/
88
--regex-rust=/[ \t]*const[ \t]+([a-zA-Z0-9_]+)/\1/m,consts/
9+
--regex-rust=/[ \t]*iface[ \t]+([a-zA-Z0-9_]+)/\1/m,ifaces/
10+
--regex-rust=/[ \t]*impl[ \t]+([a-zA-Z0-9_]+)/\1/m,impls/
11+
--regex-rust=/[ \t]*impl[ \t]+of[ \t]([a-zA-Z0-9_]+)/\1/m,impls/

0 commit comments

Comments
 (0)