diff options
| author | John Kåre Alsaker <john.kare.alsaker@gmail.com> | 2018-12-08 20:30:23 +0100 |
|---|---|---|
| committer | John Kåre Alsaker <john.kare.alsaker@gmail.com> | 2019-02-28 19:30:31 +0100 |
| commit | 23a51f91c928a4ff2cbf39218e6e991365e5f562 (patch) | |
| tree | e27a82e677e472550536820a8af2390d8f1da364 /src/librustc/session | |
| parent | 1999a2288123173b2e487865c9a04386173025f7 (diff) | |
| download | rust-23a51f91c928a4ff2cbf39218e6e991365e5f562.tar.gz rust-23a51f91c928a4ff2cbf39218e6e991365e5f562.zip | |
Introduce rustc_interface and move some methods there
Diffstat (limited to 'src/librustc/session')
| -rw-r--r-- | src/librustc/session/config.rs | 7 | ||||
| -rw-r--r-- | src/librustc/session/mod.rs | 109 |
2 files changed, 73 insertions, 43 deletions
diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 65da458efbf..99eee4b559a 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -499,6 +499,13 @@ impl Input { Input::Str { ref mut input, .. } => Some(input), } } + + pub fn source_name(&self) -> FileName { + match *self { + Input::File(ref ifile) => ifile.clone().into(), + Input::Str { ref name, .. } => name.clone(), + } + } } #[derive(Clone, Hash)] diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index 833785f0407..5b9b70edc68 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -899,14 +899,14 @@ impl Session { /// Returns the number of query threads that should be used for this /// compilation - pub fn threads_from_opts(opts: &config::Options) -> usize { - opts.debugging_opts.threads.unwrap_or(::num_cpus::get()) + pub fn threads_from_count(query_threads: Option<usize>) -> usize { + query_threads.unwrap_or(::num_cpus::get()) } /// Returns the number of query threads that should be used for this /// compilation pub fn threads(&self) -> usize { - Self::threads_from_opts(&self.opts) + Self::threads_from_count(self.opts.debugging_opts.threads) } /// Returns the number of codegen units that should be used for this @@ -1023,16 +1023,67 @@ pub fn build_session( local_crate_source_file, registry, Lrc::new(source_map::SourceMap::new(file_path_mapping)), - None, + DiagnosticOutput::Default, + Default::default(), ) } +fn default_emitter( + sopts: &config::Options, + registry: errors::registry::Registry, + source_map: &Lrc<source_map::SourceMap>, + emitter_dest: Option<Box<dyn Write + Send>>, +) -> Box<dyn Emitter + sync::Send> { + match (sopts.error_format, emitter_dest) { + (config::ErrorOutputType::HumanReadable(color_config), None) => Box::new( + EmitterWriter::stderr( + color_config, + Some(source_map.clone()), + false, + sopts.debugging_opts.teach, + ).ui_testing(sopts.debugging_opts.ui_testing), + ), + (config::ErrorOutputType::HumanReadable(_), Some(dst)) => Box::new( + EmitterWriter::new(dst, Some(source_map.clone()), false, false) + .ui_testing(sopts.debugging_opts.ui_testing), + ), + (config::ErrorOutputType::Json(pretty), None) => Box::new( + JsonEmitter::stderr( + Some(registry), + source_map.clone(), + pretty, + ).ui_testing(sopts.debugging_opts.ui_testing), + ), + (config::ErrorOutputType::Json(pretty), Some(dst)) => Box::new( + JsonEmitter::new( + dst, + Some(registry), + source_map.clone(), + pretty, + ).ui_testing(sopts.debugging_opts.ui_testing), + ), + (config::ErrorOutputType::Short(color_config), None) => Box::new( + EmitterWriter::stderr(color_config, Some(source_map.clone()), true, false), + ), + (config::ErrorOutputType::Short(_), Some(dst)) => { + Box::new(EmitterWriter::new(dst, Some(source_map.clone()), true, false)) + } + } +} + +pub enum DiagnosticOutput { + Default, + Raw(Box<dyn Write + Send>), + Emitter(Box<dyn Emitter + Send + sync::Send>) +} + pub fn build_session_with_source_map( sopts: config::Options, local_crate_source_file: Option<PathBuf>, registry: errors::registry::Registry, source_map: Lrc<source_map::SourceMap>, - emitter_dest: Option<Box<dyn Write + Send>>, + diagnostics_output: DiagnosticOutput, + lint_caps: FxHashMap<lint::LintId, lint::Level>, ) -> Session { // FIXME: This is not general enough to make the warning lint completely override // normal diagnostic warnings, since the warning lint can also be denied and changed @@ -1054,42 +1105,13 @@ pub fn build_session_with_source_map( let external_macro_backtrace = sopts.debugging_opts.external_macro_backtrace; - let emitter: Box<dyn Emitter + sync::Send> = - match (sopts.error_format, emitter_dest) { - (config::ErrorOutputType::HumanReadable(color_config), None) => Box::new( - EmitterWriter::stderr( - color_config, - Some(source_map.clone()), - false, - sopts.debugging_opts.teach, - ).ui_testing(sopts.debugging_opts.ui_testing), - ), - (config::ErrorOutputType::HumanReadable(_), Some(dst)) => Box::new( - EmitterWriter::new(dst, Some(source_map.clone()), false, false) - .ui_testing(sopts.debugging_opts.ui_testing), - ), - (config::ErrorOutputType::Json(pretty), None) => Box::new( - JsonEmitter::stderr( - Some(registry), - source_map.clone(), - pretty, - ).ui_testing(sopts.debugging_opts.ui_testing), - ), - (config::ErrorOutputType::Json(pretty), Some(dst)) => Box::new( - JsonEmitter::new( - dst, - Some(registry), - source_map.clone(), - pretty, - ).ui_testing(sopts.debugging_opts.ui_testing), - ), - (config::ErrorOutputType::Short(color_config), None) => Box::new( - EmitterWriter::stderr(color_config, Some(source_map.clone()), true, false), - ), - (config::ErrorOutputType::Short(_), Some(dst)) => { - Box::new(EmitterWriter::new(dst, Some(source_map.clone()), true, false)) - } - }; + let emitter = match diagnostics_output { + DiagnosticOutput::Default => default_emitter(&sopts, registry, &source_map, None), + DiagnosticOutput::Raw(write) => { + default_emitter(&sopts, registry, &source_map, Some(write)) + } + DiagnosticOutput::Emitter(emitter) => emitter, + }; let diagnostic_handler = errors::Handler::with_emitter_and_flags( emitter, @@ -1103,7 +1125,7 @@ pub fn build_session_with_source_map( }, ); - build_session_(sopts, local_crate_source_file, diagnostic_handler, source_map) + build_session_(sopts, local_crate_source_file, diagnostic_handler, source_map, lint_caps) } pub fn build_session_( @@ -1111,6 +1133,7 @@ pub fn build_session_( local_crate_source_file: Option<PathBuf>, span_diagnostic: errors::Handler, source_map: Lrc<source_map::SourceMap>, + driver_lint_caps: FxHashMap<lint::LintId, lint::Level>, ) -> Session { let host_triple = TargetTriple::from_triple(config::host_triple()); let host = Target::search(&host_triple).unwrap_or_else(|e| @@ -1235,7 +1258,7 @@ pub fn build_session_( }, has_global_allocator: Once::new(), has_panic_handler: Once::new(), - driver_lint_caps: Default::default(), + driver_lint_caps, }; validate_commandline_args_with_session_available(&sess); |
