Skip to content

Commit

Permalink
Remove RunCompiler::emitter.
Browse files Browse the repository at this point in the history
It's no longer used.
  • Loading branch information
nnethercote committed Oct 17, 2022
1 parent bf286a8 commit 641f824
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 101 deletions.
33 changes: 10 additions & 23 deletions compiler/rustc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use rustc_session::config::{ErrorOutputType, Input, OutputType, PrintRequest, Tr
use rustc_session::cstore::MetadataLoader;
use rustc_session::getopts;
use rustc_session::lint::{Lint, LintId};
use rustc_session::{config, DiagnosticOutput, Session};
use rustc_session::{config, Session};
use rustc_session::{early_error, early_error_no_abort, early_warn};
use rustc_span::source_map::{FileLoader, FileName};
use rustc_span::symbol::sym;
Expand Down Expand Up @@ -147,19 +147,21 @@ pub struct RunCompiler<'a, 'b> {
at_args: &'a [String],
callbacks: &'b mut (dyn Callbacks + Send),
file_loader: Option<Box<dyn FileLoader + Send + Sync>>,
emitter: Option<Box<dyn Write + Send>>,
make_codegen_backend:
Option<Box<dyn FnOnce(&config::Options) -> Box<dyn CodegenBackend> + Send>>,
}

impl<'a, 'b> RunCompiler<'a, 'b> {
pub fn new(at_args: &'a [String], callbacks: &'b mut (dyn Callbacks + Send)) -> Self {
Self { at_args, callbacks, file_loader: None, emitter: None, make_codegen_backend: None }
Self { at_args, callbacks, file_loader: None, make_codegen_backend: None }
}

/// Set a custom codegen backend.
///
/// Used by cg_clif.
/// Has no uses within this repository, but is used by bjorn3 for "the
/// hotswapping branch of cg_clif" for "setting the codegen backend from a
/// custom driver where the custom codegen backend has arbitrary data."
/// (See #102759.)
pub fn set_make_codegen_backend(
&mut self,
make_codegen_backend: Option<
Expand All @@ -170,17 +172,11 @@ impl<'a, 'b> RunCompiler<'a, 'b> {
self
}

/// Emit diagnostics to the specified location.
///
/// Used by RLS.
pub fn set_emitter(&mut self, emitter: Option<Box<dyn Write + Send>>) -> &mut Self {
self.emitter = emitter;
self
}

/// Load files from sources other than the file system.
///
/// Used by RLS.
/// Has no uses within this repository, but may be used in the future by
/// bjorn3 for "hooking rust-analyzer's VFS into rustc at some point for
/// running rustc without having to save". (See #102759.)
pub fn set_file_loader(
&mut self,
file_loader: Option<Box<dyn FileLoader + Send + Sync>>,
Expand All @@ -191,27 +187,19 @@ impl<'a, 'b> RunCompiler<'a, 'b> {

/// Parse args and run the compiler.
pub fn run(self) -> interface::Result<()> {
run_compiler(
self.at_args,
self.callbacks,
self.file_loader,
self.emitter,
self.make_codegen_backend,
)
run_compiler(self.at_args, self.callbacks, self.file_loader, self.make_codegen_backend)
}
}
fn run_compiler(
at_args: &[String],
callbacks: &mut (dyn Callbacks + Send),
file_loader: Option<Box<dyn FileLoader + Send + Sync>>,
emitter: Option<Box<dyn Write + Send>>,
make_codegen_backend: Option<
Box<dyn FnOnce(&config::Options) -> Box<dyn CodegenBackend> + Send>,
>,
) -> interface::Result<()> {
let args = args::arg_expand_all(at_args);

let diagnostic_output = emitter.map_or(DiagnosticOutput::Default, DiagnosticOutput::Raw);
let Some(matches) = handle_options(&args) else { return Ok(()) };

let sopts = config::build_session_options(&matches);
Expand All @@ -233,7 +221,6 @@ fn run_compiler(
output_file: ofile,
output_dir: odir,
file_loader,
diagnostic_output,
lint_caps: Default::default(),
parse_sess_created: None,
register_lints: None,
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_interface/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use rustc_session::config::{self, CheckCfg, ErrorOutputType, Input, OutputFilena
use rustc_session::early_error;
use rustc_session::lint;
use rustc_session::parse::{CrateConfig, ParseSess};
use rustc_session::{DiagnosticOutput, Session};
use rustc_session::Session;
use rustc_span::source_map::{FileLoader, FileName};
use rustc_span::symbol::sym;
use std::path::PathBuf;
Expand Down Expand Up @@ -247,7 +247,6 @@ pub struct Config {
pub output_dir: Option<PathBuf>,
pub output_file: Option<PathBuf>,
pub file_loader: Option<Box<dyn FileLoader + Send + Sync>>,
pub diagnostic_output: DiagnosticOutput,

pub lint_caps: FxHashMap<lint::LintId, lint::Level>,

Expand Down Expand Up @@ -284,7 +283,6 @@ pub fn create_compiler_and_run<R>(config: Config, f: impl FnOnce(&Compiler) -> R
config.opts,
config.crate_cfg,
config.crate_check_cfg,
config.diagnostic_output,
config.file_loader,
config.input_path.clone(),
config.lint_caps,
Expand Down
13 changes: 2 additions & 11 deletions compiler/rustc_interface/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use rustc_session::config::{CFGuard, ExternEntry, LinkerPluginLto, LtoCli, Switc
use rustc_session::lint::Level;
use rustc_session::search_paths::SearchPath;
use rustc_session::utils::{CanonicalizedPath, NativeLib, NativeLibKind};
use rustc_session::{build_session, getopts, DiagnosticOutput, Session};
use rustc_session::{build_session, getopts, Session};
use rustc_span::edition::{Edition, DEFAULT_EDITION};
use rustc_span::symbol::sym;
use rustc_span::SourceFileHashAlgorithm;
Expand All @@ -40,16 +40,7 @@ fn build_session_options_and_crate_config(matches: getopts::Matches) -> (Options
fn mk_session(matches: getopts::Matches) -> (Session, CfgSpecs) {
let registry = registry::Registry::new(&[]);
let (sessopts, cfg) = build_session_options_and_crate_config(matches);
let sess = build_session(
sessopts,
None,
None,
registry,
DiagnosticOutput::Default,
Default::default(),
None,
None,
);
let sess = build_session(sessopts, None, None, registry, Default::default(), None, None);
(sess, cfg)
}

Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_interface/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use rustc_session::config::{self, CrateType};
use rustc_session::config::{ErrorOutputType, Input, OutputFilenames};
use rustc_session::lint::{self, BuiltinLintDiagnostics, LintBuffer};
use rustc_session::parse::CrateConfig;
use rustc_session::{early_error, filesearch, output, DiagnosticOutput, Session};
use rustc_session::{early_error, filesearch, output, Session};
use rustc_span::edition::Edition;
use rustc_span::lev_distance::find_best_match_for_name;
use rustc_span::source_map::FileLoader;
Expand Down Expand Up @@ -65,7 +65,6 @@ pub fn create_session(
sopts: config::Options,
cfg: FxHashSet<(String, Option<String>)>,
check_cfg: CheckCfg,
diagnostic_output: DiagnosticOutput,
file_loader: Option<Box<dyn FileLoader + Send + Sync + 'static>>,
input_path: Option<PathBuf>,
lint_caps: FxHashMap<lint::LintId, lint::Level>,
Expand Down Expand Up @@ -104,7 +103,6 @@ pub fn create_session(
input_path,
bundle,
descriptions,
diagnostic_output,
lint_caps,
file_loader,
target_override,
Expand Down
69 changes: 14 additions & 55 deletions compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ use rustc_target::spec::{
use std::cell::{self, RefCell};
use std::env;
use std::fmt;
use std::io::Write;
use std::ops::{Div, Mul};
use std::path::{Path, PathBuf};
use std::str::FromStr;
Expand Down Expand Up @@ -1213,11 +1212,10 @@ fn default_emitter(
source_map: Lrc<SourceMap>,
bundle: Option<Lrc<FluentBundle>>,
fallback_bundle: LazyFallbackBundle,
emitter_dest: Option<Box<dyn Write + Send>>,
) -> Box<dyn Emitter + sync::Send> {
let macro_backtrace = sopts.unstable_opts.macro_backtrace;
match (sopts.error_format, emitter_dest) {
(config::ErrorOutputType::HumanReadable(kind), dst) => {
match sopts.error_format {
config::ErrorOutputType::HumanReadable(kind) => {
let (short, color_config) = kind.unzip();

if let HumanReadableErrorType::AnnotateSnippet(_) = kind {
Expand All @@ -1230,33 +1228,20 @@ fn default_emitter(
);
Box::new(emitter.ui_testing(sopts.unstable_opts.ui_testing))
} else {
let emitter = match dst {
None => EmitterWriter::stderr(
color_config,
Some(source_map),
bundle,
fallback_bundle,
short,
sopts.unstable_opts.teach,
sopts.diagnostic_width,
macro_backtrace,
),
Some(dst) => EmitterWriter::new(
dst,
Some(source_map),
bundle,
fallback_bundle,
short,
false, // no teach messages when writing to a buffer
false, // no colors when writing to a buffer
None, // no diagnostic width
macro_backtrace,
),
};
let emitter = EmitterWriter::stderr(
color_config,
Some(source_map),
bundle,
fallback_bundle,
short,
sopts.unstable_opts.teach,
sopts.diagnostic_width,
macro_backtrace,
);
Box::new(emitter.ui_testing(sopts.unstable_opts.ui_testing))
}
}
(config::ErrorOutputType::Json { pretty, json_rendered }, None) => Box::new(
config::ErrorOutputType::Json { pretty, json_rendered } => Box::new(
JsonEmitter::stderr(
Some(registry),
source_map,
Expand All @@ -1269,36 +1254,16 @@ fn default_emitter(
)
.ui_testing(sopts.unstable_opts.ui_testing),
),
(config::ErrorOutputType::Json { pretty, json_rendered }, Some(dst)) => Box::new(
JsonEmitter::new(
dst,
Some(registry),
source_map,
bundle,
fallback_bundle,
pretty,
json_rendered,
sopts.diagnostic_width,
macro_backtrace,
)
.ui_testing(sopts.unstable_opts.ui_testing),
),
}
}

pub enum DiagnosticOutput {
Default,
Raw(Box<dyn Write + Send>),
}

// JUSTIFICATION: literally session construction
#[allow(rustc::bad_opt_access)]
pub fn build_session(
sopts: config::Options,
local_crate_source_file: Option<PathBuf>,
bundle: Option<Lrc<rustc_errors::FluentBundle>>,
registry: rustc_errors::registry::Registry,
diagnostics_output: DiagnosticOutput,
driver_lint_caps: FxHashMap<lint::LintId, lint::Level>,
file_loader: Option<Box<dyn FileLoader + Send + Sync + 'static>>,
target_override: Option<Target>,
Expand All @@ -1314,11 +1279,6 @@ pub fn build_session(
let cap_lints_allow = sopts.lint_cap.map_or(false, |cap| cap == lint::Allow);
let can_emit_warnings = !(warnings_allow || cap_lints_allow);

let write_dest = match diagnostics_output {
DiagnosticOutput::Default => None,
DiagnosticOutput::Raw(write) => Some(write),
};

let sysroot = match &sopts.maybe_sysroot {
Some(sysroot) => sysroot.clone(),
None => filesearch::get_or_default_sysroot(),
Expand Down Expand Up @@ -1351,8 +1311,7 @@ pub fn build_session(
rustc_errors::DEFAULT_LOCALE_RESOURCES,
sopts.unstable_opts.translate_directionality_markers,
);
let emitter =
default_emitter(&sopts, registry, source_map.clone(), bundle, fallback_bundle, write_dest);
let emitter = default_emitter(&sopts, registry, source_map.clone(), bundle, fallback_bundle);

let span_diagnostic = rustc_errors::Handler::with_emitter_and_flags(
emitter,
Expand Down
2 changes: 0 additions & 2 deletions src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use rustc_middle::ty::{ParamEnv, Ty, TyCtxt};
use rustc_resolve as resolve;
use rustc_session::config::{self, CrateType, ErrorOutputType};
use rustc_session::lint;
use rustc_session::DiagnosticOutput;
use rustc_session::Session;
use rustc_span::symbol::sym;
use rustc_span::{source_map, Span, Symbol};
Expand Down Expand Up @@ -286,7 +285,6 @@ pub(crate) fn create_config(
output_file: None,
output_dir: None,
file_loader: None,
diagnostic_output: DiagnosticOutput::Default,
lint_caps,
parse_sess_created: None,
register_lints: Some(Box::new(crate::lint::register_lints)),
Expand Down
3 changes: 1 addition & 2 deletions src/librustdoc/doctest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use rustc_parse::maybe_new_parser_from_source_str;
use rustc_parse::parser::attr::InnerAttrPolicy;
use rustc_session::config::{self, CrateType, ErrorOutputType};
use rustc_session::parse::ParseSess;
use rustc_session::{lint, DiagnosticOutput, Session};
use rustc_session::{lint, Session};
use rustc_span::edition::Edition;
use rustc_span::source_map::SourceMap;
use rustc_span::symbol::sym;
Expand Down Expand Up @@ -100,7 +100,6 @@ pub(crate) fn run(options: RustdocOptions) -> Result<(), ErrorGuaranteed> {
output_file: None,
output_dir: None,
file_loader: None,
diagnostic_output: DiagnosticOutput::Default,
lint_caps,
parse_sess_created: None,
register_lints: Some(Box::new(crate::lint::register_lints)),
Expand Down
2 changes: 0 additions & 2 deletions src/test/run-make-fulldeps/issue-19371/foo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ extern crate rustc_driver;
extern crate rustc_session;
extern crate rustc_span;

use rustc_session::DiagnosticOutput;
use rustc_session::config::{Input, Options, OutputType, OutputTypes};
use rustc_interface::interface;
use rustc_span::source_map::FileName;
Expand Down Expand Up @@ -55,7 +54,6 @@ fn compile(code: String, output: PathBuf, sysroot: PathBuf) {
output_file: Some(output),
output_dir: None,
file_loader: None,
diagnostic_output: DiagnosticOutput::Default,
lint_caps: Default::default(),
parse_sess_created: None,
register_lints: None,
Expand Down

0 comments on commit 641f824

Please sign in to comment.