Skip to content

Commit 452fc46

Browse files
committed
rustc: Break some of metadata's dependencies on session
1 parent 0f49928 commit 452fc46

File tree

7 files changed

+30
-17
lines changed

7 files changed

+30
-17
lines changed

src/rustc/metadata/decoder.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import std::{ebml, map};
44
import std::map::hashmap;
55
import io::writer_util;
66
import syntax::{ast, ast_util};
7-
import driver::session::session;
87
import syntax::attr;
98
import middle::ty;
109
import middle::ast_map;
@@ -15,6 +14,7 @@ import syntax::print::pprust;
1514
import cmd=cstore::crate_metadata;
1615
import util::ppaux::ty_to_str;
1716
import ebml::deserializer;
17+
import syntax::diagnostic::span_handler;
1818

1919
export get_class_fields;
2020
export get_symbol;
@@ -455,7 +455,9 @@ fn get_iface_methods(cdata: cmd, id: ast::node_id, tcx: ty::ctxt)
455455
let name = item_name(mth);
456456
let ty = doc_type(mth, tcx, cdata);
457457
let fty = alt ty::get(ty).struct { ty::ty_fn(f) { f }
458-
_ { tcx.sess.bug("get_iface_methods: id has non-function type");
458+
_ {
459+
tcx.diag.handler().bug(
460+
"get_iface_methods: id has non-function type");
459461
} };
460462
result += [{ident: name, tps: bounds, fty: fty,
461463
purity: alt check item_family(mth) {

src/rustc/metadata/encoder.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import std::serialization::serializer;
1919
import std::ebml::serializer;
2020
import middle::resolve;
2121
import syntax::ast;
22-
import driver::session::session;
22+
import syntax::diagnostic::span_handler;
2323

2424
export link_meta;
2525
export encode_parms;
@@ -45,6 +45,7 @@ type encode_inlined_item = fn@(ecx: @encode_ctxt,
4545
ii: ast::inlined_item);
4646

4747
type encode_parms = {
48+
diag: span_handler,
4849
tcx: ty::ctxt,
4950
reachable: hashmap<ast::node_id, ()>,
5051
exp_map: resolve::exp_map,
@@ -57,6 +58,7 @@ type encode_parms = {
5758
};
5859

5960
enum encode_ctxt = {
61+
diag: span_handler,
6062
tcx: ty::ctxt,
6163
reachable: hashmap<ast::node_id, ()>,
6264
exp_map: resolve::exp_map,
@@ -281,7 +283,8 @@ fn def_to_str(did: def_id) -> str { ret #fmt["%d:%d", did.crate, did.node]; }
281283

282284
fn encode_type_param_bounds(ebml_w: ebml::writer, ecx: @encode_ctxt,
283285
params: [ty_param]) {
284-
let ty_str_ctxt = @{ds: def_to_str,
286+
let ty_str_ctxt = @{diag: ecx.diag,
287+
ds: def_to_str,
285288
tcx: ecx.tcx,
286289
reachable: reachable(ecx, _),
287290
abbrevs: tyencode::ac_use_abbrevs(ecx.type_abbrevs)};
@@ -301,7 +304,8 @@ fn encode_variant_id(ebml_w: ebml::writer, vid: def_id) {
301304

302305
fn write_type(ecx: @encode_ctxt, ebml_w: ebml::writer, typ: ty::t) {
303306
let ty_str_ctxt =
304-
@{ds: def_to_str,
307+
@{diag: ecx.diag,
308+
ds: def_to_str,
305309
tcx: ecx.tcx,
306310
reachable: reachable(ecx, _),
307311
abbrevs: tyencode::ac_use_abbrevs(ecx.type_abbrevs)};
@@ -318,8 +322,10 @@ fn encode_symbol(ecx: @encode_ctxt, ebml_w: ebml::writer, id: node_id) {
318322
ebml_w.start_tag(tag_items_data_item_symbol);
319323
let sym = alt ecx.item_symbols.find(id) {
320324
some(x) { x }
321-
none { ecx.tcx.sess.bug(#fmt("encode_symbol: \
322-
id not found %d", id)); }
325+
none {
326+
ecx.diag.handler().bug(
327+
#fmt("encode_symbol: id not found %d", id));
328+
}
323329
};
324330
ebml_w.writer.write(str::bytes(sym));
325331
ebml_w.end_tag();
@@ -426,8 +432,8 @@ fn encode_info_for_mod(ecx: @encode_ctxt, ebml_w: ebml::writer, md: _mod,
426432
} // for
427433
} // list::cons alt
428434
_ {
429-
ecx.tcx.sess.bug(#fmt("encode_info_for_mod: empty impl_map \
430-
entry for %?", path));
435+
ecx.diag.handler().bug(#fmt("encode_info_for_mod: empty impl_map \
436+
entry for %?", path));
431437
}
432438
}
433439
encode_path(ebml_w, path, ast_map::path_mod(name));
@@ -1057,6 +1063,7 @@ fn encode_hash(ebml_w: ebml::writer, hash: str) {
10571063

10581064
fn encode_metadata(parms: encode_parms, crate: @crate) -> [u8] {
10591065
let ecx: @encode_ctxt = @encode_ctxt({
1066+
diag: parms.diag,
10601067
tcx: parms.tcx,
10611068
reachable: parms.reachable,
10621069
exp_map: parms.exp_map,
@@ -1102,7 +1109,8 @@ fn encode_metadata(parms: encode_parms, crate: @crate) -> [u8] {
11021109

11031110
// Get the encoded string for a type
11041111
fn encoded_ty(tcx: ty::ctxt, t: ty::t) -> str {
1105-
let cx = @{ds: def_to_str,
1112+
let cx = @{diag: tcx.diag,
1113+
ds: def_to_str,
11061114
tcx: tcx,
11071115
reachable: {|_id| false},
11081116
abbrevs: tyencode::ac_no_abbrevs};

src/rustc/metadata/tydecode.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import syntax::ast_util;
66
import syntax::ast_util::respan;
77
import middle::ty;
88
import std::map::hashmap;
9-
import driver::session;
10-
import session::session;
119

1210
export parse_ty_data, parse_def_id, parse_ident;
1311
export parse_bounds_data;

src/rustc/metadata/tyencode.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import io::writer_util;
44
import std::map::hashmap;
55
import syntax::ast::*;
6-
import driver::session::session;
6+
import syntax::diagnostic::span_handler;
77
import middle::ty;
88
import middle::ty::vid;
99
import syntax::print::pprust::*;
@@ -17,6 +17,7 @@ export enc_bounds;
1717
export enc_mode;
1818

1919
type ctxt = {
20+
diag: span_handler,
2021
// Def -> str Callback:
2122
ds: fn@(def_id) -> str,
2223
// The type context.
@@ -145,7 +146,7 @@ fn enc_region(w: io::writer, cx: @ctxt, r: ty::region) {
145146
}
146147
ty::re_var(_) {
147148
// these should not crop up after typeck
148-
cx.tcx.sess.bug("Cannot encode region variables");
149+
cx.diag.handler().bug("Cannot encode region variables");
149150
}
150151
}
151152
}

src/rustc/middle/astencode.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,8 @@ impl helpers for ebml::ebml_deserializer {
681681

682682
impl helpers for @e::encode_ctxt {
683683
fn ty_str_ctxt() -> @tyencode::ctxt {
684-
@{ds: e::def_to_str,
684+
@{diag: self.tcx.sess.diagnostic(),
685+
ds: e::def_to_str,
685686
tcx: self.tcx,
686687
reachable: encoder::reachable(self, _),
687688
abbrevs: tyencode::ac_use_abbrevs(self.type_abbrevs)}

src/rustc/middle/trans/base.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4998,6 +4998,7 @@ fn crate_ctxt_to_encode_parms(cx: @crate_ctxt)
49984998
bind astencode::encode_inlined_item(_, _, _, _, cx.maps);
49994999

50005000
{
5001+
diag: cx.sess.diagnostic(),
50015002
tcx: cx.tcx,
50025003
reachable: cx.reachable,
50035004
exp_map: cx.exp_map,

src/rustc/middle/ty.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ enum ast_ty_to_ty_cache_entry {
200200
}
201201

202202
type ctxt =
203-
@{interner: hashmap<intern_key, t_box>,
203+
@{diag: syntax::diagnostic::span_handler,
204+
interner: hashmap<intern_key, t_box>,
204205
mut next_id: uint,
205206
sess: session::session,
206207
def_map: resolve::def_map,
@@ -462,7 +463,8 @@ fn mk_ctxt(s: session::session, dm: resolve::def_map, amap: ast_map::map,
462463
hash_type_structure(k.struct) +
463464
option::map_default(k.o_def_id, 0u, ast_util::hash_def_id)
464465
}, {|&&a, &&b| a == b});
465-
@{interner: interner,
466+
@{diag: s.diagnostic(),
467+
interner: interner,
466468
mut next_id: 0u,
467469
sess: s,
468470
def_map: dm,

0 commit comments

Comments
 (0)