Skip to content

Commit 871e570

Browse files
committed
De-@ codemap and diagnostic.
1 parent 0bb6de3 commit 871e570

33 files changed

+311
-356
lines changed

src/librustc/back/link.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1352,9 +1352,8 @@ fn add_upstream_rust_crates(args: &mut Vec<~str>, sess: &Session,
13521352
}
13531353

13541354
// Converts a library file-stem into a cc -l argument
1355-
fn unlib(config: @session::Config, stem: &str) -> ~str {
1356-
if stem.starts_with("lib") &&
1357-
config.os != abi::OsWin32 {
1355+
fn unlib(config: &session::Config, stem: &str) -> ~str {
1356+
if stem.starts_with("lib") && config.os != abi::OsWin32 {
13581357
stem.slice(3, stem.len()).to_owned()
13591358
} else {
13601359
stem.to_owned()
@@ -1434,7 +1433,7 @@ fn add_upstream_rust_crates(args: &mut Vec<~str>, sess: &Session,
14341433
// what its name is
14351434
let dir = cratepath.dirname_str().unwrap();
14361435
if !dir.is_empty() { args.push("-L" + dir); }
1437-
let libarg = unlib(sess.targ_cfg, cratepath.filestem_str().unwrap());
1436+
let libarg = unlib(&sess.targ_cfg, cratepath.filestem_str().unwrap());
14381437
args.push("-l" + libarg);
14391438
}
14401439
}

src/librustc/driver/driver.rs

+27-38
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use middle::{trans, freevars, kind, ty, typeck, lint, astencode, reachable};
2727
use middle;
2828
use util::common::time;
2929
use util::ppaux;
30-
use util::nodemap::NodeSet;
30+
use util::nodemap::{NodeMap, NodeSet};
3131

3232
use serialize::{json, Encodable};
3333

@@ -39,7 +39,6 @@ use std::mem::drop;
3939
use std::os;
4040
use std::vec_ng::Vec;
4141
use std::vec_ng;
42-
use collections::HashMap;
4342
use getopts::{optopt, optmulti, optflag, optflagopt};
4443
use getopts;
4544
use syntax::ast;
@@ -75,9 +74,9 @@ pub fn anon_src() -> ~str {
7574

7675
pub fn source_name(input: &Input) -> ~str {
7776
match *input {
78-
// FIXME (#9639): This needs to handle non-utf8 paths
79-
FileInput(ref ifile) => ifile.as_str().unwrap().to_str(),
80-
StrInput(_) => anon_src()
77+
// FIXME (#9639): This needs to handle non-utf8 paths
78+
FileInput(ref ifile) => ifile.as_str().unwrap().to_str(),
79+
StrInput(_) => anon_src()
8180
}
8281
}
8382

@@ -213,7 +212,7 @@ pub fn phase_2_configure_and_expand(sess: &Session,
213212
-> (ast::Crate, syntax::ast_map::Map) {
214213
let time_passes = sess.time_passes();
215214

216-
sess.building_library.set(session::building_library(sess.opts, &krate));
215+
sess.building_library.set(session::building_library(&sess.opts, &krate));
217216
sess.crate_types.set(session::collect_crate_types(sess,
218217
krate.attrs
219218
.as_slice()));
@@ -315,7 +314,7 @@ pub fn phase_3_run_analysis_passes(sess: Session,
315314
sess.macro_registrar_fn.with_mut(|r| *r =
316315
time(time_passes, "looking for macro registrar", (), |_|
317316
syntax::ext::registrar::find_macro_registrar(
318-
sess.span_diagnostic, krate)));
317+
sess.diagnostic(), krate)));
319318

320319
let freevars = time(time_passes, "freevar finding", (), |_|
321320
freevars::annotate_freevars(def_map, krate));
@@ -541,19 +540,14 @@ fn write_out_deps(sess: &Session,
541540

542541
// Build a list of files used to compile the output and
543542
// write Makefile-compatible dependency rules
544-
let files: Vec<~str> = {
545-
let files = sess.codemap.files.borrow();
546-
files.get()
547-
.iter()
548-
.filter_map(|fmap| {
549-
if fmap.is_real_file() {
550-
Some(fmap.name.clone())
551-
} else {
552-
None
553-
}
554-
})
555-
.collect()
556-
};
543+
let files: Vec<~str> = sess.codemap().files.borrow().get()
544+
.iter().filter_map(|fmap| {
545+
if fmap.deref().is_real_file() {
546+
Some(fmap.deref().name.clone())
547+
} else {
548+
None
549+
}
550+
}).collect();
557551
let mut file = try!(io::File::create(&deps_filename));
558552
for path in out_filenames.iter() {
559553
try!(write!(&mut file as &mut Writer,
@@ -741,8 +735,7 @@ static architecture_abis : &'static [(&'static str, abi::Architecture)] = &'stat
741735

742736
("mips", abi::Mips)];
743737

744-
pub fn build_target_config(sopts: @session::Options)
745-
-> @session::Config {
738+
pub fn build_target_config(sopts: &session::Options) -> session::Config {
746739
let os = match get_os(sopts.target_triple) {
747740
Some(os) => os,
748741
None => early_error("unknown operating system")
@@ -764,14 +757,13 @@ pub fn build_target_config(sopts: @session::Options)
764757
abi::Arm => arm::get_target_strs(target_triple, os),
765758
abi::Mips => mips::get_target_strs(target_triple, os)
766759
};
767-
let target_cfg = @session::Config {
760+
session::Config {
768761
os: os,
769762
arch: arch,
770763
target_strs: target_strs,
771764
int_type: int_type,
772765
uint_type: uint_type,
773-
};
774-
return target_cfg;
766+
}
775767
}
776768

777769
pub fn host_triple() -> ~str {
@@ -938,7 +930,7 @@ pub fn build_session_options(matches: &getopts::Matches)
938930
matches.opt_present("crate-file-name"));
939931
let cg = build_codegen_options(matches);
940932

941-
@session::Options {
933+
session::Options {
942934
crate_types: crate_types,
943935
gc: gc,
944936
optimize: opt_level,
@@ -991,25 +983,24 @@ pub fn build_codegen_options(matches: &getopts::Matches)
991983
return cg;
992984
}
993985

994-
pub fn build_session(sopts: @session::Options,
986+
pub fn build_session(sopts: session::Options,
995987
local_crate_source_file: Option<Path>)
996988
-> Session {
997-
let codemap = @codemap::CodeMap::new();
989+
let codemap = codemap::CodeMap::new();
998990
let diagnostic_handler =
999991
diagnostic::default_handler();
1000992
let span_diagnostic_handler =
1001993
diagnostic::mk_span_handler(diagnostic_handler, codemap);
1002994

1003-
build_session_(sopts, local_crate_source_file, codemap, span_diagnostic_handler)
995+
build_session_(sopts, local_crate_source_file, span_diagnostic_handler)
1004996
}
1005997

1006-
pub fn build_session_(sopts: @session::Options,
998+
pub fn build_session_(sopts: session::Options,
1007999
local_crate_source_file: Option<Path>,
1008-
codemap: @codemap::CodeMap,
1009-
span_diagnostic_handler: @diagnostic::SpanHandler)
1000+
span_diagnostic: diagnostic::SpanHandler)
10101001
-> Session {
1011-
let target_cfg = build_target_config(sopts);
1012-
let p_s = parse::new_parse_sess_special_handler(span_diagnostic_handler, codemap);
1002+
let target_cfg = build_target_config(&sopts);
1003+
let p_s = parse::new_parse_sess_special_handler(span_diagnostic);
10131004
let default_sysroot = match sopts.maybe_sysroot {
10141005
Some(_) => None,
10151006
None => Some(filesearch::get_or_default_sysroot())
@@ -1029,19 +1020,17 @@ pub fn build_session_(sopts: @session::Options,
10291020
opts: sopts,
10301021
cstore: CStore::new(token::get_ident_interner()),
10311022
parse_sess: p_s,
1032-
codemap: codemap,
10331023
// For a library crate, this is always none
10341024
entry_fn: RefCell::new(None),
10351025
entry_type: Cell::new(None),
10361026
macro_registrar_fn: RefCell::new(None),
1037-
span_diagnostic: span_diagnostic_handler,
10381027
default_sysroot: default_sysroot,
10391028
building_library: Cell::new(false),
10401029
local_crate_source_file: local_crate_source_file,
10411030
working_dir: os::getcwd(),
1042-
lints: RefCell::new(HashMap::new()),
1031+
lints: RefCell::new(NodeMap::new()),
10431032
node_id: Cell::new(1),
1044-
crate_types: @RefCell::new(Vec::new()),
1033+
crate_types: RefCell::new(Vec::new()),
10451034
features: front::feature_gate::Features::new(),
10461035
recursion_limit: Cell::new(64),
10471036
}

src/librustc/driver/session.rs

+29-28
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use front;
1616
use metadata::filesearch;
1717
use metadata;
1818
use middle::lint;
19+
use util::nodemap::NodeMap;
1920

2021
use syntax::attr::AttrMetaMethods;
2122
use syntax::ast::NodeId;
@@ -28,7 +29,7 @@ use syntax;
2829

2930
use std::cell::{Cell, RefCell};
3031
use std::vec_ng::Vec;
31-
use collections::{HashMap,HashSet};
32+
use collections::HashSet;
3233

3334
pub struct Config {
3435
os: abi::Os,
@@ -174,26 +175,23 @@ pub enum CrateType {
174175
}
175176

176177
pub struct Session {
177-
targ_cfg: @Config,
178-
opts: @Options,
178+
targ_cfg: Config,
179+
opts: Options,
179180
cstore: metadata::cstore::CStore,
180181
parse_sess: ParseSess,
181-
codemap: @codemap::CodeMap,
182182
// For a library crate, this is always none
183183
entry_fn: RefCell<Option<(NodeId, codemap::Span)>>,
184184
entry_type: Cell<Option<EntryFnType>>,
185-
span_diagnostic: @diagnostic::SpanHandler,
186185
macro_registrar_fn: RefCell<Option<ast::DefId>>,
187186
default_sysroot: Option<Path>,
188187
building_library: Cell<bool>,
189188
// The name of the root source file of the crate, in the local file system. The path is always
190189
// expected to be absolute. `None` means that there is no source file.
191190
local_crate_source_file: Option<Path>,
192191
working_dir: Path,
193-
lints: RefCell<HashMap<ast::NodeId,
194-
Vec<(lint::Lint, codemap::Span, ~str)> >>,
192+
lints: RefCell<NodeMap<Vec<(lint::Lint, codemap::Span, ~str)>>>,
195193
node_id: Cell<ast::NodeId>,
196-
crate_types: @RefCell<Vec<CrateType> >,
194+
crate_types: RefCell<Vec<CrateType>>,
197195
features: front::feature_gate::Features,
198196

199197
/// The maximum recursion limit for potentially infinitely recursive
@@ -203,52 +201,52 @@ pub struct Session {
203201

204202
impl Session {
205203
pub fn span_fatal(&self, sp: Span, msg: &str) -> ! {
206-
self.span_diagnostic.span_fatal(sp, msg)
204+
self.diagnostic().span_fatal(sp, msg)
207205
}
208206
pub fn fatal(&self, msg: &str) -> ! {
209-
self.span_diagnostic.handler().fatal(msg)
207+
self.diagnostic().handler().fatal(msg)
210208
}
211209
pub fn span_err(&self, sp: Span, msg: &str) {
212-
self.span_diagnostic.span_err(sp, msg)
210+
self.diagnostic().span_err(sp, msg)
213211
}
214212
pub fn err(&self, msg: &str) {
215-
self.span_diagnostic.handler().err(msg)
213+
self.diagnostic().handler().err(msg)
216214
}
217215
pub fn err_count(&self) -> uint {
218-
self.span_diagnostic.handler().err_count()
216+
self.diagnostic().handler().err_count()
219217
}
220218
pub fn has_errors(&self) -> bool {
221-
self.span_diagnostic.handler().has_errors()
219+
self.diagnostic().handler().has_errors()
222220
}
223221
pub fn abort_if_errors(&self) {
224-
self.span_diagnostic.handler().abort_if_errors()
222+
self.diagnostic().handler().abort_if_errors()
225223
}
226224
pub fn span_warn(&self, sp: Span, msg: &str) {
227-
self.span_diagnostic.span_warn(sp, msg)
225+
self.diagnostic().span_warn(sp, msg)
228226
}
229227
pub fn warn(&self, msg: &str) {
230-
self.span_diagnostic.handler().warn(msg)
228+
self.diagnostic().handler().warn(msg)
231229
}
232230
pub fn span_note(&self, sp: Span, msg: &str) {
233-
self.span_diagnostic.span_note(sp, msg)
231+
self.diagnostic().span_note(sp, msg)
234232
}
235233
pub fn span_end_note(&self, sp: Span, msg: &str) {
236-
self.span_diagnostic.span_end_note(sp, msg)
234+
self.diagnostic().span_end_note(sp, msg)
237235
}
238236
pub fn note(&self, msg: &str) {
239-
self.span_diagnostic.handler().note(msg)
237+
self.diagnostic().handler().note(msg)
240238
}
241239
pub fn span_bug(&self, sp: Span, msg: &str) -> ! {
242-
self.span_diagnostic.span_bug(sp, msg)
240+
self.diagnostic().span_bug(sp, msg)
243241
}
244242
pub fn bug(&self, msg: &str) -> ! {
245-
self.span_diagnostic.handler().bug(msg)
243+
self.diagnostic().handler().bug(msg)
246244
}
247245
pub fn span_unimpl(&self, sp: Span, msg: &str) -> ! {
248-
self.span_diagnostic.span_unimpl(sp, msg)
246+
self.diagnostic().span_unimpl(sp, msg)
249247
}
250248
pub fn unimpl(&self, msg: &str) -> ! {
251-
self.span_diagnostic.handler().unimpl(msg)
249+
self.diagnostic().handler().unimpl(msg)
252250
}
253251
pub fn add_lint(&self,
254252
lint: lint::Lint,
@@ -275,12 +273,15 @@ impl Session {
275273

276274
v
277275
}
278-
pub fn diagnostic(&self) -> @diagnostic::SpanHandler {
279-
self.span_diagnostic
276+
pub fn diagnostic<'a>(&'a self) -> &'a diagnostic::SpanHandler {
277+
&self.parse_sess.span_diagnostic
280278
}
281279
pub fn debugging_opt(&self, opt: u64) -> bool {
282280
(self.opts.debugging_opts & opt) != 0
283281
}
282+
pub fn codemap<'a>(&'a self) -> &'a codemap::CodeMap {
283+
&self.parse_sess.span_diagnostic.cm
284+
}
284285
// This exists to help with refactoring to eliminate impossible
285286
// cases later on
286287
pub fn impossible_case(&self, sp: Span, msg: &str) -> ! {
@@ -328,8 +329,8 @@ impl Session {
328329
}
329330

330331
/// Some reasonable defaults
331-
pub fn basic_options() -> @Options {
332-
@Options {
332+
pub fn basic_options() -> Options {
333+
Options {
333334
crate_types: Vec::new(),
334335
gc: false,
335336
optimize: No,

src/librustc/lib.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -295,26 +295,26 @@ pub fn run_compiler(args: &[~str]) {
295295
d::parse_pretty(&sess, a)
296296
});
297297
match pretty {
298-
Some::<d::PpMode>(ppm) => {
299-
d::pretty_print_input(sess, cfg, &input, ppm);
300-
return;
301-
}
302-
None::<d::PpMode> => {/* continue */ }
298+
Some::<d::PpMode>(ppm) => {
299+
d::pretty_print_input(sess, cfg, &input, ppm);
300+
return;
301+
}
302+
None::<d::PpMode> => {/* continue */ }
303303
}
304304
let ls = matches.opt_present("ls");
305305
if ls {
306306
match input {
307-
d::FileInput(ref ifile) => {
308-
let mut stdout = io::stdout();
309-
d::list_metadata(&sess, &(*ifile), &mut stdout).unwrap();
310-
}
311-
d::StrInput(_) => {
312-
d::early_error("can not list metadata for stdin");
313-
}
307+
d::FileInput(ref ifile) => {
308+
let mut stdout = io::stdout();
309+
d::list_metadata(&sess, &(*ifile), &mut stdout).unwrap();
310+
}
311+
d::StrInput(_) => {
312+
d::early_error("can not list metadata for stdin");
313+
}
314314
}
315315
return;
316316
}
317-
let (crate_id, crate_name, crate_file_name) = sopts.print_metas;
317+
let (crate_id, crate_name, crate_file_name) = sess.opts.print_metas;
318318
// these nasty nested conditions are to avoid doing extra work
319319
if crate_id || crate_name || crate_file_name {
320320
let attrs = parse_crate_attrs(&sess, &input);

src/librustc/metadata/creader.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ fn dump_crates(crate_cache: &[cache_entry]) {
8888
}
8989

9090
fn warn_if_multiple_versions(e: &mut Env,
91-
diag: @SpanHandler,
91+
diag: &SpanHandler,
9292
crate_cache: &[cache_entry]) {
9393
if crate_cache.len() != 0u {
9494
let name = crate_cache[crate_cache.len() - 1].crate_id.name.clone();

src/librustc/metadata/csearch.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,11 @@ pub fn get_field_type(tcx: &ty::ctxt, class_id: ast::DefId,
214214
let cstore = &tcx.sess.cstore;
215215
let cdata = cstore.get_crate_data(class_id.krate);
216216
let all_items = reader::get_doc(reader::Doc(cdata.data()), tag_items);
217-
let class_doc = expect(tcx.diag,
217+
let class_doc = expect(tcx.sess.diagnostic(),
218218
decoder::maybe_find_item(class_id.node, all_items),
219219
|| format!("get_field_type: class ID {:?} not found",
220220
class_id) );
221-
let the_field = expect(tcx.diag,
221+
let the_field = expect(tcx.sess.diagnostic(),
222222
decoder::maybe_find_item(def.node, class_doc),
223223
|| format!("get_field_type: in class {:?}, field ID {:?} not found",
224224
class_id, def) );

0 commit comments

Comments
 (0)