diff options
Diffstat (limited to 'compiler/rustc_session/src')
| -rw-r--r-- | compiler/rustc_session/src/config.rs | 47 | ||||
| -rw-r--r-- | compiler/rustc_session/src/errors.rs | 13 | ||||
| -rw-r--r-- | compiler/rustc_session/src/options.rs | 55 | ||||
| -rw-r--r-- | compiler/rustc_session/src/parse.rs | 12 | ||||
| -rw-r--r-- | compiler/rustc_session/src/session.rs | 38 | ||||
| -rw-r--r-- | compiler/rustc_session/src/utils.rs | 2 |
6 files changed, 117 insertions, 50 deletions
diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 3bafd3730bd..1ccfc59f7a9 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -35,6 +35,7 @@ use std::hash::Hash; use std::iter; use std::path::{Path, PathBuf}; use std::str::{self, FromStr}; +use std::sync::LazyLock; pub mod sigpipe; @@ -554,6 +555,16 @@ pub enum PrintRequest { SplitDebuginfo, } +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] +pub enum TraitSolver { + /// Classic trait solver in `rustc_trait_selection::traits::select` + Classic, + /// Chalk trait solver + Chalk, + /// Experimental trait solver in `rustc_trait_selection::solve` + Next, +} + pub enum Input { /// Load source code from a file. File(PathBuf), @@ -787,6 +798,12 @@ impl Options { pub fn get_symbol_mangling_version(&self) -> SymbolManglingVersion { self.cg.symbol_mangling_version.unwrap_or(SymbolManglingVersion::Legacy) } + + #[allow(rustc::bad_opt_access)] + pub fn incremental_relative_spans(&self) -> bool { + self.unstable_opts.incremental_relative_spans + || (self.unstable_features.is_nightly_build() && self.incremental.is_some()) + } } impl UnstableOptions { @@ -1306,7 +1323,12 @@ mod opt { unstable(longer(a, b), move |opts| opts.optmulti(a, b, c, d)) } } - +static EDITION_STRING: LazyLock<String> = LazyLock::new(|| { + format!( + "Specify which edition of the compiler to use when compiling code. \ +The default is {DEFAULT_EDITION} and the latest stable edition is {LATEST_STABLE_EDITION}." + ) +}); /// Returns the "short" subset of the rustc command line options, /// including metadata for each option, such as whether the option is /// part of the stable long-term interface for rustc. @@ -1339,7 +1361,7 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> { opt::opt_s( "", "edition", - "Specify which edition of the compiler to use when compiling code.", + &*EDITION_STRING, EDITION_NAME_LIST, ), opt::multi_s( @@ -2755,7 +2777,7 @@ pub(crate) mod dep_tracking { BranchProtection, CFGuard, CFProtection, CrateType, DebugInfo, ErrorOutputType, InstrumentCoverage, LdImpl, LinkerPluginLto, LocationDetail, LtoCli, OomStrategy, OptLevel, OutputType, OutputTypes, Passes, SourceFileHashAlgorithm, SplitDwarfKind, - SwitchWithOptPath, SymbolManglingVersion, TrimmedDefPaths, + SwitchWithOptPath, SymbolManglingVersion, TraitSolver, TrimmedDefPaths, }; use crate::lint; use crate::options::WasiExecModel; @@ -2855,6 +2877,7 @@ pub(crate) mod dep_tracking { BranchProtection, OomStrategy, LanguageIdentifier, + TraitSolver, ); impl<T1, T2> DepTrackingHash for (T1, T2) @@ -2975,3 +2998,21 @@ pub enum ProcMacroExecutionStrategy { /// Run the proc-macro code on a different thread. CrossThread, } + +/// Which format to use for `-Z dump-mono-stats` +#[derive(Clone, Copy, PartialEq, Hash, Debug)] +pub enum DumpMonoStatsFormat { + /// Pretty-print a markdown table + Markdown, + /// Emit structured JSON + Json, +} + +impl DumpMonoStatsFormat { + pub fn extension(self) -> &'static str { + match self { + Self::Markdown => "md", + Self::Json => "json", + } + } +} diff --git a/compiler/rustc_session/src/errors.rs b/compiler/rustc_session/src/errors.rs index e72b76cfee9..f5a72573d58 100644 --- a/compiler/rustc_session/src/errors.rs +++ b/compiler/rustc_session/src/errors.rs @@ -260,9 +260,11 @@ pub(crate) struct InvalidFloatLiteralSuffix { #[derive(Diagnostic)] #[diag(session_int_literal_too_large)] +#[note] pub(crate) struct IntLiteralTooLarge { #[primary_span] pub span: Span, + pub limit: String, } #[derive(Diagnostic)] @@ -361,8 +363,15 @@ pub fn report_lit_error(sess: &ParseSess, err: LitError, lit: token::Lit, span: _ => unreachable!(), }; } - LitError::IntTooLarge => { - sess.emit_err(IntLiteralTooLarge { span }); + LitError::IntTooLarge(base) => { + let max = u128::MAX; + let limit = match base { + 2 => format!("{max:#b}"), + 8 => format!("{max:#o}"), + 16 => format!("{max:#x}"), + _ => format!("{max}"), + }; + sess.emit_err(IntLiteralTooLarge { span, limit }); } } } diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 9e130287104..4c236067688 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -377,10 +377,13 @@ mod desc { pub const parse_linker_flavor: &str = ::rustc_target::spec::LinkerFlavorCli::one_of(); pub const parse_optimization_fuel: &str = "crate=integer"; pub const parse_mir_spanview: &str = "`statement` (default), `terminator`, or `block`"; + pub const parse_dump_mono_stats: &str = "`markdown` (default) or `json`"; pub const parse_instrument_coverage: &str = "`all` (default), `except-unused-generics`, `except-unused-functions`, or `off`"; pub const parse_unpretty: &str = "`string` or `string=string`"; pub const parse_treat_err_as_bug: &str = "either no value or a number bigger than 0"; + pub const parse_trait_solver: &str = + "one of the supported solver modes (`classic`, `chalk`, or `next`)"; pub const parse_lto: &str = "either a boolean (`yes`, `no`, `on`, `off`, etc), `thin`, `fat`, or omitted"; pub const parse_linker_plugin_lto: &str = @@ -820,6 +823,21 @@ mod parse { true } + pub(crate) fn parse_dump_mono_stats(slot: &mut DumpMonoStatsFormat, v: Option<&str>) -> bool { + match v { + None => true, + Some("json") => { + *slot = DumpMonoStatsFormat::Json; + true + } + Some("markdown") => { + *slot = DumpMonoStatsFormat::Markdown; + true + } + Some(_) => false, + } + } + pub(crate) fn parse_instrument_coverage( slot: &mut Option<InstrumentCoverage>, v: Option<&str>, @@ -864,6 +882,18 @@ mod parse { } } + pub(crate) fn parse_trait_solver(slot: &mut TraitSolver, v: Option<&str>) -> bool { + match v { + Some("classic") => *slot = TraitSolver::Classic, + Some("chalk") => *slot = TraitSolver::Chalk, + Some("next") => *slot = TraitSolver::Next, + // default trait solver is subject to change.. + Some("default") => *slot = TraitSolver::Classic, + _ => return false, + } + true + } + pub(crate) fn parse_lto(slot: &mut LtoCli, v: Option<&str>) -> bool { if v.is_some() { let mut bool_arg = None; @@ -1211,10 +1241,9 @@ options! { // tidy-alphabetical-start allow_features: Option<Vec<String>> = (None, parse_opt_comma_list, [TRACKED], - "only allow the listed language features to be enabled in code (space separated)"), + "only allow the listed language features to be enabled in code (comma separated)"), always_encode_mir: bool = (false, parse_bool, [TRACKED], "encode MIR of all functions into the crate metadata (default: no)"), - #[rustc_lint_opt_deny_field_access("use `Session::asm_comments` instead of this field")] asm_comments: bool = (false, parse_bool, [TRACKED], "generate comments into the assembly (may change behavior) (default: no)"), assert_incr_state: Option<String> = (None, parse_opt_string, [UNTRACKED], @@ -1226,7 +1255,7 @@ options! { binary_dep_depinfo: bool = (false, parse_bool, [TRACKED], "include artifacts (sysroot, crate dependencies) used during compilation in dep-info \ (default: no)"), - box_noalias: Option<bool> = (None, parse_opt_bool, [TRACKED], + box_noalias: bool = (true, parse_bool, [TRACKED], "emit noalias metadata for box (default: yes)"), branch_protection: Option<BranchProtection> = (None, parse_branch_protection, [TRACKED], "set options for branch target identification and pointer authentication on AArch64"), @@ -1234,8 +1263,6 @@ options! { "instrument control-flow architecture protection"), cgu_partitioning_strategy: Option<String> = (None, parse_opt_string, [TRACKED], "the codegen unit partitioning strategy to use"), - chalk: bool = (false, parse_bool, [TRACKED], - "enable the experimental Chalk-based trait solving engine"), codegen_backend: Option<String> = (None, parse_opt_string, [TRACKED], "the backend to use"), combine_cgu: bool = (false, parse_bool, [TRACKED], @@ -1296,7 +1323,9 @@ options! { an additional `.html` file showing the computed coverage spans."), dump_mono_stats: SwitchWithOptPath = (SwitchWithOptPath::Disabled, parse_switch_with_opt_path, [UNTRACKED], - "output statistics about monomorphization collection (format: markdown)"), + "output statistics about monomorphization collection"), + dump_mono_stats_format: DumpMonoStatsFormat = (DumpMonoStatsFormat::Markdown, parse_dump_mono_stats, [UNTRACKED], + "the format to use for -Z dump-mono-stats (`markdown` (default) or `json`)"), dwarf_version: Option<u32> = (None, parse_opt_number, [TRACKED], "version of DWARF debug information to emit (default: 2 or 4, depending on platform)"), dylib_lto: bool = (false, parse_bool, [UNTRACKED], @@ -1333,11 +1362,12 @@ options! { "generate human-readable, predictable names for codegen units (default: no)"), identify_regions: bool = (false, parse_bool, [UNTRACKED], "display unnamed regions as `'<id>`, using a non-ident unique id (default: no)"), - incremental_ignore_spans: bool = (false, parse_bool, [UNTRACKED], + incremental_ignore_spans: bool = (false, parse_bool, [TRACKED], "ignore spans during ICH computation -- used for testing (default: no)"), incremental_info: bool = (false, parse_bool, [UNTRACKED], "print high-level information about incremental reuse (or the lack thereof) \ (default: no)"), + #[rustc_lint_opt_deny_field_access("use `Session::incremental_relative_spans` instead of this field")] incremental_relative_spans: bool = (false, parse_bool, [TRACKED], "hash spans relative to their parent item for incr. comp. (default: no)"), incremental_verify_ich: bool = (false, parse_bool, [UNTRACKED], @@ -1363,7 +1393,6 @@ options! { `=except-unused-generics` `=except-unused-functions` `=off` (default)"), - #[rustc_lint_opt_deny_field_access("use `Session::instrument_mcount` instead of this field")] instrument_mcount: bool = (false, parse_bool, [TRACKED], "insert function instrument code for mcount-based tracing (default: no)"), keep_hygiene_data: bool = (false, parse_bool, [UNTRACKED], @@ -1392,7 +1421,6 @@ options! { merge_functions: Option<MergeFunctions> = (None, parse_merge_functions, [TRACKED], "control the operation of the MergeFunctions LLVM pass, taking \ the same values as the target option of the same name"), - #[rustc_lint_opt_deny_field_access("use `Session::meta_stats` instead of this field")] meta_stats: bool = (false, parse_bool, [UNTRACKED], "gather metadata statistics (default: no)"), mir_emit_retag: bool = (false, parse_bool, [TRACKED], @@ -1409,7 +1437,7 @@ options! { "use line numbers relative to the function in mir pretty printing"), move_size_limit: Option<usize> = (None, parse_opt_number, [TRACKED], "the size at which the `large_assignments` lint starts to be emitted"), - mutable_noalias: Option<bool> = (None, parse_opt_bool, [TRACKED], + mutable_noalias: bool = (true, parse_bool, [TRACKED], "emit noalias metadata for mutable references (default: yes)"), nll_facts: bool = (false, parse_bool, [UNTRACKED], "dump facts from NLL analysis into side files (default: no)"), @@ -1421,6 +1449,8 @@ options! { "run all passes except codegen; no output"), no_generate_arange_section: bool = (false, parse_no_flag, [TRACKED], "omit DWARF address ranges that give faster lookups"), + no_jump_tables: bool = (false, parse_no_flag, [TRACKED], + "disable the jump tables and lookup tables that can be generated from a switch case lowering"), no_leak_check: bool = (false, parse_no_flag, [UNTRACKED], "disable the 'leak check' for subtyping; unsound, but useful for tests"), no_link: bool = (false, parse_no_flag, [TRACKED], @@ -1467,7 +1497,6 @@ options! { See #77382 and #74551."), print_fuel: Option<String> = (None, parse_opt_string, [TRACKED], "make rustc print the total optimization fuel used by a crate"), - #[rustc_lint_opt_deny_field_access("use `Session::print_llvm_passes` instead of this field")] print_llvm_passes: bool = (false, parse_bool, [UNTRACKED], "print the LLVM optimization passes being run (default: no)"), print_mono_items: Option<String> = (None, parse_opt_string, [UNTRACKED], @@ -1581,10 +1610,8 @@ options! { #[rustc_lint_opt_deny_field_access("use `Session::threads` instead of this field")] threads: usize = (1, parse_threads, [UNTRACKED], "use a thread pool with N threads"), - #[rustc_lint_opt_deny_field_access("use `Session::time_llvm_passes` instead of this field")] time_llvm_passes: bool = (false, parse_bool, [UNTRACKED], "measure time of each LLVM pass (default: no)"), - #[rustc_lint_opt_deny_field_access("use `Session::time_passes` instead of this field")] time_passes: bool = (false, parse_bool, [UNTRACKED], "measure time of each rustc pass (default: no)"), #[rustc_lint_opt_deny_field_access("use `Session::tls_model` instead of this field")] @@ -1594,6 +1621,8 @@ options! { "for every macro invocation, print its name and arguments (default: no)"), track_diagnostics: bool = (false, parse_bool, [UNTRACKED], "tracks where in rustc a diagnostic was emitted"), + trait_solver: TraitSolver = (TraitSolver::Classic, parse_trait_solver, [TRACKED], + "specify the trait solver mode used by rustc (default: classic)"), // Diagnostics are considered side-effects of a query (see `QuerySideEffects`) and are saved // alongside query results and changes to translation options can affect diagnostics - so // translation options should be tracked. diff --git a/compiler/rustc_session/src/parse.rs b/compiler/rustc_session/src/parse.rs index f9f4f2979c4..2aa8ca9e4a9 100644 --- a/compiler/rustc_session/src/parse.rs +++ b/compiler/rustc_session/src/parse.rs @@ -122,7 +122,7 @@ pub fn feature_err_issue<'a>( /// Construct a future incompatibility diagnostic for a feature gate. /// /// This diagnostic is only a warning and *does not cause compilation to fail*. -pub fn feature_warn<'a>(sess: &'a ParseSess, feature: Symbol, span: Span, explain: &str) { +pub fn feature_warn(sess: &ParseSess, feature: Symbol, span: Span, explain: &str) { feature_warn_issue(sess, feature, span, GateIssue::Language, explain); } @@ -134,8 +134,8 @@ pub fn feature_warn<'a>(sess: &'a ParseSess, feature: Symbol, span: Span, explai /// Almost always, you want to use this for a language feature. If so, prefer `feature_warn`. #[allow(rustc::diagnostic_outside_of_impl)] #[allow(rustc::untranslatable_diagnostic)] -pub fn feature_warn_issue<'a>( - sess: &'a ParseSess, +pub fn feature_warn_issue( + sess: &ParseSess, feature: Symbol, span: Span, issue: GateIssue, @@ -160,7 +160,7 @@ pub fn feature_warn_issue<'a>( } /// Adds the diagnostics for a feature to an existing error. -pub fn add_feature_diagnostics<'a>(err: &mut Diagnostic, sess: &'a ParseSess, feature: Symbol) { +pub fn add_feature_diagnostics(err: &mut Diagnostic, sess: &ParseSess, feature: Symbol) { add_feature_diagnostics_for_issue(err, sess, feature, GateIssue::Language); } @@ -169,9 +169,9 @@ pub fn add_feature_diagnostics<'a>(err: &mut Diagnostic, sess: &'a ParseSess, fe /// This variant allows you to control whether it is a library or language feature. /// Almost always, you want to use this for a language feature. If so, prefer /// `add_feature_diagnostics`. -pub fn add_feature_diagnostics_for_issue<'a>( +pub fn add_feature_diagnostics_for_issue( err: &mut Diagnostic, - sess: &'a ParseSess, + sess: &ParseSess, feature: Symbol, issue: GateIssue, ) { diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 01a9b100088..1b2e8d9dc70 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -590,7 +590,19 @@ impl Session { pub fn warn(&self, msg: impl Into<DiagnosticMessage>) { self.diagnostic().warn(msg) } - /// Delay a span_bug() call until abort_if_errors() + + /// Ensures that compilation cannot succeed. + /// + /// If this function has been called but no errors have been emitted and + /// compilation succeeds, it will cause an internal compiler error (ICE). + /// + /// This can be used in code paths that should never run on successful compilations. + /// For example, it can be used to create an [`ErrorGuaranteed`] + /// (but you should prefer threading through the [`ErrorGuaranteed`] from an error emission directly). + /// + /// If no span is available, use [`DUMMY_SP`]. + /// + /// [`DUMMY_SP`]: rustc_span::DUMMY_SP #[track_caller] pub fn delay_span_bug<S: Into<MultiSpan>>( &self, @@ -976,34 +988,10 @@ impl Session { self.opts.unstable_opts.verbose } - pub fn instrument_mcount(&self) -> bool { - self.opts.unstable_opts.instrument_mcount - } - - pub fn time_passes(&self) -> bool { - self.opts.unstable_opts.time_passes - } - - pub fn time_llvm_passes(&self) -> bool { - self.opts.unstable_opts.time_llvm_passes - } - - pub fn meta_stats(&self) -> bool { - self.opts.unstable_opts.meta_stats - } - - pub fn asm_comments(&self) -> bool { - self.opts.unstable_opts.asm_comments - } - pub fn verify_llvm_ir(&self) -> bool { self.opts.unstable_opts.verify_llvm_ir || option_env!("RUSTC_VERIFY_LLVM_IR").is_some() } - pub fn print_llvm_passes(&self) -> bool { - self.opts.unstable_opts.print_llvm_passes - } - pub fn binary_dep_depinfo(&self) -> bool { self.opts.unstable_opts.binary_dep_depinfo } diff --git a/compiler/rustc_session/src/utils.rs b/compiler/rustc_session/src/utils.rs index e65b6891e32..b996d36a318 100644 --- a/compiler/rustc_session/src/utils.rs +++ b/compiler/rustc_session/src/utils.rs @@ -3,7 +3,7 @@ use rustc_data_structures::profiling::VerboseTimingGuard; use std::path::{Path, PathBuf}; impl Session { - pub fn timer<'a>(&'a self, what: &'static str) -> VerboseTimingGuard<'a> { + pub fn timer(&self, what: &'static str) -> VerboseTimingGuard<'_> { self.prof.verbose_generic_activity(what) } pub fn time<R>(&self, what: &'static str, f: impl FnOnce() -> R) -> R { |
