diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:18:25 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:18:25 +0000 |
commit | 5363f350887b1e5b5dd21a86f88c8af9d7fea6da (patch) | |
tree | 35ca005eb6e0e9a1ba3bb5dbc033209ad445dc17 /compiler/rustc_session/src/config.rs | |
parent | Adding debian version 1.66.0+dfsg1-1. (diff) | |
download | rustc-5363f350887b1e5b5dd21a86f88c8af9d7fea6da.tar.xz rustc-5363f350887b1e5b5dd21a86f88c8af9d7fea6da.zip |
Merging upstream version 1.67.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | compiler/rustc_session/src/config.rs | 110 |
1 files changed, 64 insertions, 46 deletions
diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index f2ee52262..7a20100fd 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -10,8 +10,8 @@ use crate::{lint, HashStableContext}; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; -use rustc_data_structures::stable_hasher::ToStableHashKey; -use rustc_target::abi::{Align, TargetDataLayout}; +use rustc_data_structures::stable_hasher::{StableOrd, ToStableHashKey}; +use rustc_target::abi::Align; use rustc_target::spec::{PanicStrategy, SanitizerSet, SplitDebuginfo}; use rustc_target::spec::{Target, TargetTriple, TargetWarnings, TARGETS}; @@ -288,6 +288,9 @@ pub enum OutputType { DepInfo, } +// Safety: Trivial C-Style enums have a stable sort order across compilation sessions. +unsafe impl StableOrd for OutputType {} + impl<HCX: HashStableContext> ToStableHashKey<HCX> for OutputType { type KeyType = Self; @@ -548,6 +551,7 @@ pub enum PrintRequest { NativeStaticLibs, StackProtectorStrategies, LinkArgs, + SplitDebuginfo, } pub enum Input { @@ -621,7 +625,7 @@ impl OutputFilenames { /// should be placed on disk. pub fn output_path(&self, flavor: OutputType) -> PathBuf { let extension = flavor.extension(); - self.with_directory_and_extension(&self.out_directory, &extension) + self.with_directory_and_extension(&self.out_directory, extension) } /// Gets the path where a compilation artifact of the given type for the @@ -658,7 +662,7 @@ impl OutputFilenames { let temps_directory = self.temps_directory.as_ref().unwrap_or(&self.out_directory); - self.with_directory_and_extension(&temps_directory, &extension) + self.with_directory_and_extension(temps_directory, &extension) } pub fn with_extension(&self, extension: &str) -> PathBuf { @@ -738,7 +742,7 @@ impl Default for Options { actually_rustdoc: false, trimmed_def_paths: TrimmedDefPaths::default(), cli_forced_codegen_units: None, - cli_forced_thinlto_off: false, + cli_forced_local_thinlto_off: false, remap_path_prefix: Vec::new(), real_rust_source_base_dir: None, edition: DEFAULT_EDITION, @@ -794,6 +798,7 @@ impl UnstableOptions { report_delayed_bugs: self.report_delayed_bugs, macro_backtrace: self.macro_backtrace, deduplicate_diagnostics: self.deduplicate_diagnostics, + track_diagnostics: self.track_diagnostics, } } } @@ -898,7 +903,7 @@ fn default_configuration(sess: &Session) -> CrateConfig { let min_atomic_width = sess.target.min_atomic_width(); let max_atomic_width = sess.target.max_atomic_width(); let atomic_cas = sess.target.atomic_cas; - let layout = TargetDataLayout::parse(&sess.target).unwrap_or_else(|err| { + let layout = sess.target.parse_data_layout().unwrap_or_else(|err| { sess.emit_fatal(err); }); @@ -1157,7 +1162,7 @@ impl CrateCheckConfig { values_target_family .extend(target.options.families.iter().map(|family| Symbol::intern(family))); values_target_arch.insert(Symbol::intern(&target.arch)); - values_target_endian.insert(Symbol::intern(&target.options.endian.as_str())); + values_target_endian.insert(Symbol::intern(target.options.endian.as_str())); values_target_env.insert(Symbol::intern(&target.options.env)); values_target_abi.insert(Symbol::intern(&target.options.abi)); values_target_vendor.insert(Symbol::intern(&target.options.vendor)); @@ -1478,7 +1483,7 @@ pub fn get_cmd_lint_options( /// Parses the `--color` flag. pub fn parse_color(matches: &getopts::Matches) -> ColorConfig { - match matches.opt_str("color").as_ref().map(|s| &s[..]) { + match matches.opt_str("color").as_deref() { Some("auto") => ColorConfig::Auto, Some("always") => ColorConfig::Always, Some("never") => ColorConfig::Never, @@ -1587,7 +1592,7 @@ pub fn parse_error_format( // is unstable, it will not be present. We have to use `opts_present` not // `opt_present` because the latter will panic. let error_format = if matches.opts_present(&["error-format".to_owned()]) { - match matches.opt_str("error-format").as_ref().map(|s| &s[..]) { + match matches.opt_str("error-format").as_deref() { None | Some("human") => { ErrorOutputType::HumanReadable(HumanReadableErrorType::Default(color)) } @@ -1720,7 +1725,7 @@ fn should_override_cgus_and_disable_thinlto( error_format: ErrorOutputType, mut codegen_units: Option<usize>, ) -> (bool, Option<usize>) { - let mut disable_thinlto = false; + let mut disable_local_thinlto = false; // Issue #30063: if user requests LLVM-related output to one // particular path, disable codegen-units. let incompatible: Vec<_> = output_types @@ -1745,12 +1750,12 @@ fn should_override_cgus_and_disable_thinlto( } early_warn(error_format, "resetting to default -C codegen-units=1"); codegen_units = Some(1); - disable_thinlto = true; + disable_local_thinlto = true; } } _ => { codegen_units = Some(1); - disable_thinlto = true; + disable_local_thinlto = true; } } } @@ -1759,7 +1764,7 @@ fn should_override_cgus_and_disable_thinlto( early_error(error_format, "value for codegen units must be a positive non-zero integer"); } - (disable_thinlto, codegen_units) + (disable_local_thinlto, codegen_units) } fn check_thread_count(unstable_opts: &UnstableOptions, error_format: ErrorOutputType) { @@ -1788,34 +1793,50 @@ fn collect_print_requests( cg.target_feature = String::new(); } - prints.extend(matches.opt_strs("print").into_iter().map(|s| match &*s { - "crate-name" => PrintRequest::CrateName, - "file-names" => PrintRequest::FileNames, - "sysroot" => PrintRequest::Sysroot, - "target-libdir" => PrintRequest::TargetLibdir, - "cfg" => PrintRequest::Cfg, - "calling-conventions" => PrintRequest::CallingConventions, - "target-list" => PrintRequest::TargetList, - "target-cpus" => PrintRequest::TargetCPUs, - "target-features" => PrintRequest::TargetFeatures, - "relocation-models" => PrintRequest::RelocationModels, - "code-models" => PrintRequest::CodeModels, - "tls-models" => PrintRequest::TlsModels, - "native-static-libs" => PrintRequest::NativeStaticLibs, - "stack-protector-strategies" => PrintRequest::StackProtectorStrategies, - "target-spec-json" => { - if unstable_opts.unstable_options { - PrintRequest::TargetSpec - } else { + const PRINT_REQUESTS: &[(&str, PrintRequest)] = &[ + ("crate-name", PrintRequest::CrateName), + ("file-names", PrintRequest::FileNames), + ("sysroot", PrintRequest::Sysroot), + ("target-libdir", PrintRequest::TargetLibdir), + ("cfg", PrintRequest::Cfg), + ("calling-conventions", PrintRequest::CallingConventions), + ("target-list", PrintRequest::TargetList), + ("target-cpus", PrintRequest::TargetCPUs), + ("target-features", PrintRequest::TargetFeatures), + ("relocation-models", PrintRequest::RelocationModels), + ("code-models", PrintRequest::CodeModels), + ("tls-models", PrintRequest::TlsModels), + ("native-static-libs", PrintRequest::NativeStaticLibs), + ("stack-protector-strategies", PrintRequest::StackProtectorStrategies), + ("target-spec-json", PrintRequest::TargetSpec), + ("link-args", PrintRequest::LinkArgs), + ("split-debuginfo", PrintRequest::SplitDebuginfo), + ]; + + prints.extend(matches.opt_strs("print").into_iter().map(|req| { + match PRINT_REQUESTS.iter().find(|&&(name, _)| name == req) { + Some((_, PrintRequest::TargetSpec)) => { + if unstable_opts.unstable_options { + PrintRequest::TargetSpec + } else { + early_error( + error_format, + "the `-Z unstable-options` flag must also be passed to \ + enable the target-spec-json print option", + ); + } + } + Some(&(_, print_request)) => print_request, + None => { + let prints = + PRINT_REQUESTS.iter().map(|(name, _)| format!("`{name}`")).collect::<Vec<_>>(); + let prints = prints.join(", "); early_error( error_format, - "the `-Z unstable-options` flag must also be passed to \ - enable the target-spec-json print option", + &format!("unknown print request `{req}`. Valid print requests are: {prints}"), ); } } - "link-args" => PrintRequest::LinkArgs, - req => early_error(error_format, &format!("unknown print request `{req}`")), })); prints @@ -1828,7 +1849,7 @@ pub fn parse_target_triple( match matches.opt_str("target") { Some(target) if target.ends_with(".json") => { let path = Path::new(&target); - TargetTriple::from_path(&path).unwrap_or_else(|_| { + TargetTriple::from_path(path).unwrap_or_else(|_| { early_error(error_format, &format!("target file {path:?} does not exist")) }) } @@ -1974,7 +1995,7 @@ fn parse_native_lib_modifiers( ) -> (NativeLibKind, Option<bool>) { let mut verbatim = None; for modifier in modifiers.split(',') { - let (modifier, value) = match modifier.strip_prefix(&['+', '-']) { + let (modifier, value) = match modifier.strip_prefix(['+', '-']) { Some(m) => (m, modifier.starts_with('+')), None => early_error( error_format, @@ -2011,10 +2032,7 @@ fn parse_native_lib_modifiers( "linking modifier `bundle` is only compatible with `static` linking kind", ), - ("verbatim", _) => { - report_unstable_modifier(); - assign_modifier(&mut verbatim) - } + ("verbatim", _) => assign_modifier(&mut verbatim), ("whole-archive", NativeLibKind::Static { whole_archive, .. }) => { assign_modifier(whole_archive) @@ -2249,7 +2267,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options { let output_types = parse_output_types(&unstable_opts, matches, error_format); let mut cg = CodegenOptions::build(matches, error_format); - let (disable_thinlto, mut codegen_units) = should_override_cgus_and_disable_thinlto( + let (disable_local_thinlto, mut codegen_units) = should_override_cgus_and_disable_thinlto( &output_types, matches, error_format, @@ -2406,7 +2424,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options { let mut search_paths = vec![]; for s in &matches.opt_strs("L") { - search_paths.push(SearchPath::from_cli_opt(&s, error_format)); + search_paths.push(SearchPath::from_cli_opt(s, error_format)); } let libs = parse_libs(matches, error_format); @@ -2431,7 +2449,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options { let sysroot = match &sysroot_opt { Some(s) => s, None => { - tmp_buf = crate::filesearch::get_or_default_sysroot(); + tmp_buf = crate::filesearch::get_or_default_sysroot().expect("Failed finding sysroot"); &tmp_buf } }; @@ -2492,7 +2510,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options { actually_rustdoc: false, trimmed_def_paths: TrimmedDefPaths::default(), cli_forced_codegen_units: codegen_units, - cli_forced_thinlto_off: disable_thinlto, + cli_forced_local_thinlto_off: disable_local_thinlto, remap_path_prefix, real_rust_source_base_dir, edition, |