rustc_session/
options.rs

1use std::collections::BTreeMap;
2use std::num::{IntErrorKind, NonZero};
3use std::path::PathBuf;
4use std::str;
5
6use rustc_abi::Align;
7use rustc_data_structures::fx::FxIndexMap;
8use rustc_data_structures::profiling::TimePassesFormat;
9use rustc_data_structures::stable_hasher::StableHasher;
10use rustc_errors::{ColorConfig, LanguageIdentifier, TerminalUrl};
11use rustc_feature::UnstableFeatures;
12use rustc_hashes::Hash64;
13use rustc_macros::{BlobDecodable, Encodable};
14use rustc_span::edition::Edition;
15use rustc_span::{RealFileName, RemapPathScopeComponents, SourceFileHashAlgorithm};
16use rustc_target::spec::{
17    CodeModel, FramePointer, LinkerFlavorCli, MergeFunctions, OnBrokenPipe, PanicStrategy,
18    RelocModel, RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, SymbolVisibility,
19    TargetTuple, TlsModel,
20};
21
22use crate::config::*;
23use crate::search_paths::SearchPath;
24use crate::utils::NativeLib;
25use crate::{EarlyDiagCtxt, Session, lint};
26
27macro_rules! insert {
28    ($opt_name:ident, $opt_expr:expr, $sub_hashes:expr) => {
29        if $sub_hashes
30            .insert(stringify!($opt_name), $opt_expr as &dyn dep_tracking::DepTrackingHash)
31            .is_some()
32        {
33            panic!("duplicate key in CLI DepTrackingHash: {}", stringify!($opt_name))
34        }
35    };
36}
37
38macro_rules! hash_opt {
39    ($opt_name:ident, $opt_expr:expr, $sub_hashes:expr, $_for_crate_hash: ident, [UNTRACKED]) => {{}};
40    ($opt_name:ident, $opt_expr:expr, $sub_hashes:expr, $_for_crate_hash: ident, [TRACKED]) => {{ insert!($opt_name, $opt_expr, $sub_hashes) }};
41    ($opt_name:ident, $opt_expr:expr, $sub_hashes:expr, $for_crate_hash: ident, [TRACKED_NO_CRATE_HASH]) => {{
42        if !$for_crate_hash {
43            insert!($opt_name, $opt_expr, $sub_hashes)
44        }
45    }};
46    ($opt_name:ident, $opt_expr:expr, $sub_hashes:expr, $_for_crate_hash: ident, [SUBSTRUCT]) => {{}};
47}
48
49macro_rules! hash_substruct {
50    ($opt_name:ident, $opt_expr:expr, $error_format:expr, $for_crate_hash:expr, $hasher:expr, [UNTRACKED]) => {{}};
51    ($opt_name:ident, $opt_expr:expr, $error_format:expr, $for_crate_hash:expr, $hasher:expr, [TRACKED]) => {{}};
52    ($opt_name:ident, $opt_expr:expr, $error_format:expr, $for_crate_hash:expr, $hasher:expr, [TRACKED_NO_CRATE_HASH]) => {{}};
53    ($opt_name:ident, $opt_expr:expr, $error_format:expr, $for_crate_hash:expr, $hasher:expr, [SUBSTRUCT]) => {
54        use crate::config::dep_tracking::DepTrackingHash;
55        $opt_expr.dep_tracking_hash($for_crate_hash, $error_format).hash(
56            $hasher,
57            $error_format,
58            $for_crate_hash,
59        );
60    };
61}
62
63/// Extended target modifier info.
64/// For example, when external target modifier is '-Zregparm=2':
65/// Target modifier enum value + user value ('2') from external crate
66/// is converted into description: prefix ('Z'), name ('regparm'), tech value ('Some(2)').
67pub struct ExtendedTargetModifierInfo {
68    /// Flag prefix (usually, 'C' for codegen flags or 'Z' for unstable flags)
69    pub prefix: String,
70    /// Flag name
71    pub name: String,
72    /// Flag parsed technical value
73    pub tech_value: String,
74}
75
76/// A recorded -Zopt_name=opt_value (or -Copt_name=opt_value)
77/// which alter the ABI or effectiveness of exploit mitigations.
78#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Encodable, BlobDecodable)]
79pub struct TargetModifier {
80    /// Option enum value
81    pub opt: OptionsTargetModifiers,
82    /// User-provided option value (before parsing)
83    pub value_name: String,
84}
85
86mod target_modifier_consistency_check {
87    use super::*;
88    pub(super) fn sanitizer(l: &TargetModifier, r: Option<&TargetModifier>) -> bool {
89        let mut lparsed: SanitizerSet = Default::default();
90        let lval = if l.value_name.is_empty() { None } else { Some(l.value_name.as_str()) };
91        parse::parse_sanitizers(&mut lparsed, lval);
92
93        let mut rparsed: SanitizerSet = Default::default();
94        let rval = r.filter(|v| !v.value_name.is_empty()).map(|v| v.value_name.as_str());
95        parse::parse_sanitizers(&mut rparsed, rval);
96
97        // Some sanitizers need to be target modifiers, and some do not.
98        // For now, we should mark all sanitizers as target modifiers except for these:
99        // AddressSanitizer, LeakSanitizer
100        let tmod_sanitizers = SanitizerSet::MEMORY
101            | SanitizerSet::THREAD
102            | SanitizerSet::HWADDRESS
103            | SanitizerSet::CFI
104            | SanitizerSet::MEMTAG
105            | SanitizerSet::SHADOWCALLSTACK
106            | SanitizerSet::KCFI
107            | SanitizerSet::KERNELADDRESS
108            | SanitizerSet::SAFESTACK
109            | SanitizerSet::DATAFLOW;
110
111        lparsed & tmod_sanitizers == rparsed & tmod_sanitizers
112    }
113    pub(super) fn sanitizer_cfi_normalize_integers(
114        sess: &Session,
115        l: &TargetModifier,
116        r: Option<&TargetModifier>,
117    ) -> bool {
118        // For kCFI, the helper flag -Zsanitizer-cfi-normalize-integers should also be a target modifier
119        if sess.sanitizers().contains(SanitizerSet::KCFI) {
120            if let Some(r) = r {
121                return l.extend().tech_value == r.extend().tech_value;
122            } else {
123                return false;
124            }
125        }
126        true
127    }
128}
129
130impl TargetModifier {
131    pub fn extend(&self) -> ExtendedTargetModifierInfo {
132        self.opt.reparse(&self.value_name)
133    }
134    // Custom consistency check for target modifiers (or default `l.tech_value == r.tech_value`)
135    // When other is None, consistency with default value is checked
136    pub fn consistent(&self, sess: &Session, other: Option<&TargetModifier>) -> bool {
137        assert!(other.is_none() || self.opt == other.unwrap().opt);
138        match self.opt {
139            OptionsTargetModifiers::UnstableOptions(unstable) => match unstable {
140                UnstableOptionsTargetModifiers::sanitizer => {
141                    return target_modifier_consistency_check::sanitizer(self, other);
142                }
143                UnstableOptionsTargetModifiers::sanitizer_cfi_normalize_integers => {
144                    return target_modifier_consistency_check::sanitizer_cfi_normalize_integers(
145                        sess, self, other,
146                    );
147                }
148                _ => {}
149            },
150            _ => {}
151        };
152        match other {
153            Some(other) => self.extend().tech_value == other.extend().tech_value,
154            None => false,
155        }
156    }
157}
158
159fn tmod_push_impl(
160    opt: OptionsTargetModifiers,
161    tmod_vals: &BTreeMap<OptionsTargetModifiers, String>,
162    tmods: &mut Vec<TargetModifier>,
163) {
164    if let Some(v) = tmod_vals.get(&opt) {
165        tmods.push(TargetModifier { opt, value_name: v.clone() })
166    }
167}
168
169macro_rules! tmod_push {
170    ($struct_name:ident, $tmod_enum_name:ident, $opt_name:ident, $opt_expr:expr, $init:expr, $mods:expr, $tmod_vals:expr) => {
171        if *$opt_expr != $init {
172            tmod_push_impl(
173                OptionsTargetModifiers::$struct_name($tmod_enum_name::$opt_name),
174                $tmod_vals,
175                $mods,
176            );
177        }
178    };
179}
180
181macro_rules! gather_tmods {
182    ($struct_name:ident, $tmod_enum_name:ident, $opt_name:ident, $opt_expr:expr, $init:expr, $mods:expr, $tmod_vals:expr,
183        [SUBSTRUCT], [TARGET_MODIFIER]) => {
184        compile_error!("SUBSTRUCT can't be target modifier");
185    };
186    ($struct_name:ident, $tmod_enum_name:ident, $opt_name:ident, $opt_expr:expr, $init:expr, $mods:expr, $tmod_vals:expr,
187        [UNTRACKED], [TARGET_MODIFIER]) => {
188        tmod_push!($struct_name, $tmod_enum_name, $opt_name, $opt_expr, $init, $mods, $tmod_vals)
189    };
190    ($struct_name:ident, $tmod_enum_name:ident, $opt_name:ident, $opt_expr:expr, $init:expr, $mods:expr, $tmod_vals:expr,
191        [TRACKED], [TARGET_MODIFIER]) => {
192        tmod_push!($struct_name, $tmod_enum_name, $opt_name, $opt_expr, $init, $mods, $tmod_vals)
193    };
194    ($struct_name:ident, $tmod_enum_name:ident, $opt_name:ident, $opt_expr:expr, $init:expr, $mods:expr, $tmod_vals:expr,
195        [TRACKED_NO_CRATE_HASH], [TARGET_MODIFIER]) => {
196        tmod_push!($struct_name, $tmod_enum_name, $opt_name, $opt_expr, $init, $mods, $tmod_vals)
197    };
198    ($struct_name:ident, $tmod_enum_name:ident, $opt_name:ident, $opt_expr:expr, $init:expr, $mods:expr, $tmod_vals:expr,
199        [SUBSTRUCT], []) => {
200        $opt_expr.gather_target_modifiers($mods, $tmod_vals);
201    };
202    ($struct_name:ident, $tmod_enum_name:ident, $opt_name:ident, $opt_expr:expr, $init:expr, $mods:expr, $tmod_vals:expr,
203        [UNTRACKED], []) => {{}};
204    ($struct_name:ident, $tmod_enum_name:ident, $opt_name:ident, $opt_expr:expr, $init:expr, $mods:expr, $tmod_vals:expr,
205        [TRACKED], []) => {{}};
206    ($struct_name:ident, $tmod_enum_name:ident, $opt_name:ident, $opt_expr:expr, $init:expr, $mods:expr, $tmod_vals:expr,
207        [TRACKED_NO_CRATE_HASH], []) => {{}};
208}
209
210macro_rules! gather_tmods_top_level {
211    ($_opt_name:ident, $opt_expr:expr, $mods:expr, $tmod_vals:expr, [SUBSTRUCT $substruct_enum:ident]) => {
212        $opt_expr.gather_target_modifiers($mods, $tmod_vals);
213    };
214    ($opt_name:ident, $opt_expr:expr, $mods:expr, $tmod_vals:expr, [$non_substruct:ident TARGET_MODIFIER]) => {
215        compile_error!("Top level option can't be target modifier");
216    };
217    ($opt_name:ident, $opt_expr:expr, $mods:expr, $tmod_vals:expr, [$non_substruct:ident]) => {};
218}
219
220/// Macro for generating OptionsTargetsModifiers top-level enum with impl.
221/// Will generate something like:
222/// ```rust,ignore (illustrative)
223/// pub enum OptionsTargetModifiers {
224///     CodegenOptions(CodegenOptionsTargetModifiers),
225///     UnstableOptions(UnstableOptionsTargetModifiers),
226/// }
227/// impl OptionsTargetModifiers {
228///     pub fn reparse(&self, user_value: &str) -> ExtendedTargetModifierInfo {
229///         match self {
230///             Self::CodegenOptions(v) => v.reparse(user_value),
231///             Self::UnstableOptions(v) => v.reparse(user_value),
232///         }
233///     }
234///     pub fn is_target_modifier(flag_name: &str) -> bool {
235///         CodegenOptionsTargetModifiers::is_target_modifier(flag_name) ||
236///         UnstableOptionsTargetModifiers::is_target_modifier(flag_name)
237///     }
238/// }
239/// ```
240macro_rules! top_level_tmod_enum {
241    ($( {$($optinfo:tt)*} ),* $(,)*) => {
242        top_level_tmod_enum! { @parse {}, (user_value){}; $($($optinfo)*|)* }
243    };
244    // Termination
245    (
246        @parse
247        {$($variant:tt($substruct_enum:tt))*},
248        ($user_value:ident){$($pout:tt)*};
249    ) => {
250        #[allow(non_camel_case_types)]
251        #[derive(PartialEq, Eq, PartialOrd, Ord, Debug, Copy, Clone, Encodable, BlobDecodable)]
252        pub enum OptionsTargetModifiers {
253            $($variant($substruct_enum)),*
254        }
255        impl OptionsTargetModifiers {
256            #[allow(unused_variables)]
257            pub fn reparse(&self, $user_value: &str) -> ExtendedTargetModifierInfo {
258                #[allow(unreachable_patterns)]
259                match self {
260                    $($pout)*
261                    _ => panic!("unknown target modifier option: {:?}", *self)
262                }
263            }
264            pub fn is_target_modifier(flag_name: &str) -> bool {
265                $($substruct_enum::is_target_modifier(flag_name))||*
266            }
267        }
268    };
269    // Adding SUBSTRUCT option group into $eout
270    (
271        @parse {$($eout:tt)*}, ($puser_value:ident){$($pout:tt)*};
272            [SUBSTRUCT $substruct_enum:ident $variant:ident] |
273        $($tail:tt)*
274    ) => {
275        top_level_tmod_enum! {
276            @parse
277            {
278                $($eout)*
279                $variant($substruct_enum)
280            },
281            ($puser_value){
282                $($pout)*
283                Self::$variant(v) => v.reparse($puser_value),
284            };
285            $($tail)*
286        }
287    };
288    // Skipping non-target-modifier and non-substruct
289    (
290        @parse {$($eout:tt)*}, ($puser_value:ident){$($pout:tt)*};
291            [$non_substruct:ident] |
292        $($tail:tt)*
293    ) => {
294        top_level_tmod_enum! {
295            @parse
296            {
297                $($eout)*
298            },
299            ($puser_value){
300                $($pout)*
301            };
302            $($tail)*
303        }
304    };
305}
306
307macro_rules! top_level_options {
308    ( $( #[$top_level_attr:meta] )* pub struct Options { $(
309        $( #[$attr:meta] )*
310        $opt:ident : $t:ty [$dep_tracking_marker:ident $( $tmod:ident $variant:ident )?],
311    )* } ) => (
312        top_level_tmod_enum!( {$([$dep_tracking_marker $($tmod $variant),*])|*} );
313
314        #[derive(Clone)]
315        $( #[$top_level_attr] )*
316        pub struct Options {
317            $(
318                $( #[$attr] )*
319                pub $opt: $t
320            ),*,
321            pub target_modifiers: BTreeMap<OptionsTargetModifiers, String>,
322        }
323
324        impl Options {
325            pub fn dep_tracking_hash(&self, for_crate_hash: bool) -> Hash64 {
326                let mut sub_hashes = BTreeMap::new();
327                $({
328                    hash_opt!($opt,
329                                &self.$opt,
330                                &mut sub_hashes,
331                                for_crate_hash,
332                                [$dep_tracking_marker]);
333                })*
334                let mut hasher = StableHasher::new();
335                dep_tracking::stable_hash(sub_hashes,
336                                          &mut hasher,
337                                          self.error_format,
338                                          for_crate_hash);
339                $({
340                    hash_substruct!($opt,
341                        &self.$opt,
342                        self.error_format,
343                        for_crate_hash,
344                        &mut hasher,
345                        [$dep_tracking_marker]);
346                })*
347                hasher.finish()
348            }
349
350            pub fn gather_target_modifiers(&self) -> Vec<TargetModifier> {
351                let mut mods = Vec::<TargetModifier>::new();
352                $({
353                    gather_tmods_top_level!($opt,
354                        &self.$opt, &mut mods, &self.target_modifiers,
355                        [$dep_tracking_marker $($tmod),*]);
356                })*
357                mods.sort_by(|a, b| a.opt.cmp(&b.opt));
358                mods
359            }
360        }
361    );
362}
363
364top_level_options!(
365    /// The top-level command-line options struct.
366    ///
367    /// For each option, one has to specify how it behaves with regard to the
368    /// dependency tracking system of incremental compilation. This is done via the
369    /// square-bracketed directive after the field type. The options are:
370    ///
371    /// - `[TRACKED]`
372    /// A change in the given field will cause the compiler to completely clear the
373    /// incremental compilation cache before proceeding.
374    ///
375    /// - `[TRACKED_NO_CRATE_HASH]`
376    /// Same as `[TRACKED]`, but will not affect the crate hash. This is useful for options that
377    /// only affect the incremental cache.
378    ///
379    /// - `[UNTRACKED]`
380    /// Incremental compilation is not influenced by this option.
381    ///
382    /// - `[SUBSTRUCT]`
383    /// Second-level sub-structs containing more options.
384    ///
385    /// If you add a new option to this struct or one of the sub-structs like
386    /// `CodegenOptions`, think about how it influences incremental compilation. If in
387    /// doubt, specify `[TRACKED]`, which is always "correct" but might lead to
388    /// unnecessary re-compilation.
389    #[rustc_lint_opt_ty]
390    pub struct Options {
391        /// The crate config requested for the session, which may be combined
392        /// with additional crate configurations during the compile process.
393        #[rustc_lint_opt_deny_field_access("use `TyCtxt::crate_types` instead of this field")]
394        crate_types: Vec<CrateType> [TRACKED],
395        optimize: OptLevel [TRACKED],
396        /// Include the `debug_assertions` flag in dependency tracking, since it
397        /// can influence whether overflow checks are done or not.
398        debug_assertions: bool [TRACKED],
399        debuginfo: DebugInfo [TRACKED],
400        debuginfo_compression: DebugInfoCompression [TRACKED],
401        lint_opts: Vec<(String, lint::Level)> [TRACKED_NO_CRATE_HASH],
402        lint_cap: Option<lint::Level> [TRACKED_NO_CRATE_HASH],
403        describe_lints: bool [UNTRACKED],
404        output_types: OutputTypes [TRACKED],
405        search_paths: Vec<SearchPath> [UNTRACKED],
406        libs: Vec<NativeLib> [TRACKED],
407        sysroot: Sysroot [UNTRACKED],
408
409        target_triple: TargetTuple [TRACKED],
410
411        /// Effective logical environment used by `env!`/`option_env!` macros
412        logical_env: FxIndexMap<String, String> [TRACKED],
413
414        test: bool [TRACKED],
415        error_format: ErrorOutputType [UNTRACKED],
416        diagnostic_width: Option<usize> [UNTRACKED],
417
418        /// If `Some`, enable incremental compilation, using the given
419        /// directory to store intermediate results.
420        incremental: Option<PathBuf> [UNTRACKED],
421        assert_incr_state: Option<IncrementalStateAssertion> [UNTRACKED],
422        /// Set by the `Config::hash_untracked_state` callback for custom
423        /// drivers to invalidate the incremental cache
424        #[rustc_lint_opt_deny_field_access("should only be used via `Config::hash_untracked_state`")]
425        untracked_state_hash: Hash64 [TRACKED_NO_CRATE_HASH],
426
427        unstable_opts: UnstableOptions [SUBSTRUCT UnstableOptionsTargetModifiers UnstableOptions],
428        prints: Vec<PrintRequest> [UNTRACKED],
429        cg: CodegenOptions [SUBSTRUCT CodegenOptionsTargetModifiers CodegenOptions],
430        externs: Externs [UNTRACKED],
431        crate_name: Option<String> [TRACKED],
432        /// Indicates how the compiler should treat unstable features.
433        unstable_features: UnstableFeatures [TRACKED],
434
435        /// Indicates whether this run of the compiler is actually rustdoc. This
436        /// is currently just a hack and will be removed eventually, so please
437        /// try to not rely on this too much.
438        actually_rustdoc: bool [TRACKED],
439        /// Whether name resolver should resolve documentation links.
440        resolve_doc_links: ResolveDocLinks [TRACKED],
441
442        /// Control path trimming.
443        trimmed_def_paths: bool [TRACKED],
444
445        /// Specifications of codegen units / ThinLTO which are forced as a
446        /// result of parsing command line options. These are not necessarily
447        /// what rustc was invoked with, but massaged a bit to agree with
448        /// commands like `--emit llvm-ir` which they're often incompatible with
449        /// if we otherwise use the defaults of rustc.
450        #[rustc_lint_opt_deny_field_access("use `Session::codegen_units` instead of this field")]
451        cli_forced_codegen_units: Option<usize> [UNTRACKED],
452        #[rustc_lint_opt_deny_field_access("use `Session::lto` instead of this field")]
453        cli_forced_local_thinlto_off: bool [UNTRACKED],
454
455        /// Remap source path prefixes in all output (messages, object files, debug, etc.).
456        remap_path_prefix: Vec<(PathBuf, PathBuf)> [TRACKED_NO_CRATE_HASH],
457
458        /// Base directory containing the `library/` directory for the Rust standard library.
459        /// Right now it's always `$sysroot/lib/rustlib/src/rust`
460        /// (i.e. the `rustup` `rust-src` component).
461        ///
462        /// This directory is what the virtual `/rustc/$hash` is translated back to,
463        /// if Rust was built with path remapping to `/rustc/$hash` enabled
464        /// (the `rust.remap-debuginfo` option in `bootstrap.toml`).
465        real_rust_source_base_dir: Option<PathBuf> [TRACKED_NO_CRATE_HASH],
466
467        /// Base directory containing the `compiler/` directory for the rustc sources.
468        /// Right now it's always `$sysroot/lib/rustlib/rustc-src/rust`
469        /// (i.e. the `rustup` `rustc-dev` component).
470        ///
471        /// This directory is what the virtual `/rustc-dev/$hash` is translated back to,
472        /// if Rust was built with path remapping to `/rustc/$hash` enabled
473        /// (the `rust.remap-debuginfo` option in `bootstrap.toml`).
474        real_rustc_dev_source_base_dir: Option<PathBuf> [TRACKED_NO_CRATE_HASH],
475
476        edition: Edition [TRACKED],
477
478        /// `true` if we're emitting JSON blobs about each artifact produced
479        /// by the compiler.
480        json_artifact_notifications: bool [TRACKED],
481
482        /// `true` if we're emitting JSON timings with the start and end of
483        /// high-level compilation sections
484        json_timings: bool [UNTRACKED],
485
486        /// `true` if we're emitting a JSON blob containing the unused externs
487        json_unused_externs: JsonUnusedExterns [UNTRACKED],
488
489        /// `true` if we're emitting a JSON job containing a future-incompat report for lints
490        json_future_incompat: bool [TRACKED],
491
492        pretty: Option<PpMode> [UNTRACKED],
493
494        /// The (potentially remapped) working directory
495        #[rustc_lint_opt_deny_field_access("use `SourceMap::working_dir` instead of this field")]
496        working_dir: RealFileName [TRACKED],
497
498        color: ColorConfig [UNTRACKED],
499
500        verbose: bool [TRACKED_NO_CRATE_HASH],
501    }
502);
503
504macro_rules! tmod_enum_opt {
505    ($struct_name:ident, $tmod_enum_name:ident, $opt:ident, $v:ident) => {
506        Some(OptionsTargetModifiers::$struct_name($tmod_enum_name::$opt))
507    };
508    ($struct_name:ident, $tmod_enum_name:ident, $opt:ident, ) => {
509        None
510    };
511}
512
513macro_rules! tmod_enum {
514    ($tmod_enum_name:ident, $prefix:expr, $( {$($optinfo:tt)*} ),* $(,)*) => {
515        tmod_enum! { $tmod_enum_name, $prefix, @parse {}, (user_value){}; $($($optinfo)*|)* }
516    };
517    // Termination
518    (
519        $tmod_enum_name:ident, $prefix:expr,
520        @parse
521        {$($eout:tt)*},
522        ($user_value:ident){$($pout:tt)*};
523    ) => {
524        #[allow(non_camel_case_types)]
525        #[derive(PartialEq, Eq, PartialOrd, Ord, Debug, Copy, Clone, Encodable, BlobDecodable)]
526        pub enum $tmod_enum_name {
527            $($eout),*
528        }
529        impl $tmod_enum_name {
530            #[allow(unused_variables)]
531            pub fn reparse(&self, $user_value: &str) -> ExtendedTargetModifierInfo {
532                #[allow(unreachable_patterns)]
533                match self {
534                    $($pout)*
535                    _ => panic!("unknown target modifier option: {:?}", *self)
536                }
537            }
538            pub fn is_target_modifier(flag_name: &str) -> bool {
539                match flag_name.replace('-', "_").as_str() {
540                    $(stringify!($eout) => true,)*
541                    _ => false,
542                }
543            }
544        }
545    };
546    // Adding target-modifier option into $eout
547    (
548        $tmod_enum_name:ident, $prefix:expr,
549        @parse {$($eout:tt)*}, ($puser_value:ident){$($pout:tt)*};
550            $opt:ident, $parse:ident, $t:ty, [TARGET_MODIFIER] |
551        $($tail:tt)*
552    ) => {
553        tmod_enum! {
554            $tmod_enum_name, $prefix,
555            @parse
556            {
557                $($eout)*
558                $opt
559            },
560            ($puser_value){
561                $($pout)*
562                Self::$opt => {
563                    let mut parsed : $t = Default::default();
564                    let val = if $puser_value.is_empty() { None } else { Some($puser_value) };
565                    parse::$parse(&mut parsed, val);
566                    ExtendedTargetModifierInfo {
567                        prefix: $prefix.to_string(),
568                        name: stringify!($opt).to_string().replace('_', "-"),
569                        tech_value: format!("{:?}", parsed),
570                    }
571                },
572            };
573            $($tail)*
574        }
575    };
576    // Skipping non-target-modifier
577    (
578        $tmod_enum_name:ident, $prefix:expr,
579        @parse {$($eout:tt)*}, ($puser_value:ident){$($pout:tt)*};
580            $opt:ident, $parse:ident, $t:ty, [] |
581        $($tail:tt)*
582    ) => {
583        tmod_enum! {
584            $tmod_enum_name, $prefix,
585            @parse
586            {
587                $($eout)*
588            },
589            ($puser_value){
590                $($pout)*
591            };
592            $($tail)*
593        }
594    };
595}
596
597/// Defines all `CodegenOptions`/`DebuggingOptions` fields and parsers all at once. The goal of this
598/// macro is to define an interface that can be programmatically used by the option parser
599/// to initialize the struct without hardcoding field names all over the place.
600///
601/// The goal is to invoke this macro once with the correct fields, and then this macro generates all
602/// necessary code. The main gotcha of this macro is the `cgsetters` module which is a bunch of
603/// generated code to parse an option into its respective field in the struct. There are a few
604/// hand-written parsers for parsing specific types of values in this module.
605macro_rules! options {
606    ($struct_name:ident, $tmod_enum_name:ident, $stat:ident, $optmod:ident, $prefix:expr, $outputname:expr,
607     $($( #[$attr:meta] )* $opt:ident : $t:ty = (
608        $init:expr,
609        $parse:ident,
610        [$dep_tracking_marker:ident $( $tmod:ident )?],
611        $desc:expr
612        $(, deprecated_do_nothing: $dnn:literal )?)
613     ),* ,) =>
614(
615    #[derive(Clone)]
616    #[rustc_lint_opt_ty]
617    pub struct $struct_name { $( $( #[$attr] )* pub $opt: $t),* }
618
619    tmod_enum!( $tmod_enum_name, $prefix, {$($opt, $parse, $t, [$($tmod),*])|*} );
620
621    impl Default for $struct_name {
622        fn default() -> $struct_name {
623            $struct_name { $($opt: $init),* }
624        }
625    }
626
627    impl $struct_name {
628        pub fn build(
629            early_dcx: &EarlyDiagCtxt,
630            matches: &getopts::Matches,
631            target_modifiers: &mut BTreeMap<OptionsTargetModifiers, String>,
632        ) -> $struct_name {
633            build_options(early_dcx, matches, target_modifiers, $stat, $prefix, $outputname)
634        }
635
636        fn dep_tracking_hash(&self, for_crate_hash: bool, error_format: ErrorOutputType) -> Hash64 {
637            let mut sub_hashes = BTreeMap::new();
638            $({
639                hash_opt!($opt,
640                            &self.$opt,
641                            &mut sub_hashes,
642                            for_crate_hash,
643                            [$dep_tracking_marker]);
644            })*
645            let mut hasher = StableHasher::new();
646            dep_tracking::stable_hash(sub_hashes,
647                                        &mut hasher,
648                                        error_format,
649                                        for_crate_hash
650                                        );
651            hasher.finish()
652        }
653
654        pub fn gather_target_modifiers(
655            &self,
656            _mods: &mut Vec<TargetModifier>,
657            _tmod_vals: &BTreeMap<OptionsTargetModifiers, String>,
658        ) {
659            $({
660                gather_tmods!($struct_name, $tmod_enum_name, $opt, &self.$opt, $init, _mods, _tmod_vals,
661                    [$dep_tracking_marker], [$($tmod),*]);
662            })*
663        }
664    }
665
666    pub const $stat: OptionDescrs<$struct_name> =
667        &[ $( OptionDesc{ name: stringify!($opt), setter: $optmod::$opt,
668            type_desc: desc::$parse, desc: $desc, is_deprecated_and_do_nothing: false $( || $dnn )?,
669            tmod: tmod_enum_opt!($struct_name, $tmod_enum_name, $opt, $($tmod),*) } ),* ];
670
671    mod $optmod {
672    $(
673        pub(super) fn $opt(cg: &mut super::$struct_name, v: Option<&str>) -> bool {
674            super::parse::$parse(&mut redirect_field!(cg.$opt), v)
675        }
676    )*
677    }
678
679) }
680
681impl CodegenOptions {
682    // JUSTIFICATION: defn of the suggested wrapper fn
683    #[allow(rustc::bad_opt_access)]
684    pub fn instrument_coverage(&self) -> InstrumentCoverage {
685        self.instrument_coverage
686    }
687}
688
689// Sometimes different options need to build a common structure.
690// That structure can be kept in one of the options' fields, the others become dummy.
691macro_rules! redirect_field {
692    ($cg:ident.link_arg) => {
693        $cg.link_args
694    };
695    ($cg:ident.pre_link_arg) => {
696        $cg.pre_link_args
697    };
698    ($cg:ident.$field:ident) => {
699        $cg.$field
700    };
701}
702
703type OptionSetter<O> = fn(&mut O, v: Option<&str>) -> bool;
704type OptionDescrs<O> = &'static [OptionDesc<O>];
705
706pub struct OptionDesc<O> {
707    name: &'static str,
708    setter: OptionSetter<O>,
709    // description for return value/type from mod desc
710    type_desc: &'static str,
711    // description for option from options table
712    desc: &'static str,
713    is_deprecated_and_do_nothing: bool,
714    tmod: Option<OptionsTargetModifiers>,
715}
716
717impl<O> OptionDesc<O> {
718    pub fn name(&self) -> &'static str {
719        self.name
720    }
721
722    pub fn desc(&self) -> &'static str {
723        self.desc
724    }
725}
726
727#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
728fn build_options<O: Default>(
729    early_dcx: &EarlyDiagCtxt,
730    matches: &getopts::Matches,
731    target_modifiers: &mut BTreeMap<OptionsTargetModifiers, String>,
732    descrs: OptionDescrs<O>,
733    prefix: &str,
734    outputname: &str,
735) -> O {
736    let mut op = O::default();
737    for option in matches.opt_strs(prefix) {
738        let (key, value) = match option.split_once('=') {
739            None => (option, None),
740            Some((k, v)) => (k.to_string(), Some(v)),
741        };
742
743        let option_to_lookup = key.replace('-', "_");
744        match descrs.iter().find(|opt_desc| opt_desc.name == option_to_lookup) {
745            Some(OptionDesc {
746                name: _,
747                setter,
748                type_desc,
749                desc,
750                is_deprecated_and_do_nothing,
751                tmod,
752            }) => {
753                if *is_deprecated_and_do_nothing {
754                    // deprecation works for prefixed options only
755                    assert!(!prefix.is_empty());
756                    early_dcx.early_warn(format!("`-{prefix} {key}`: {desc}"));
757                }
758                if !setter(&mut op, value) {
759                    match value {
760                        None => early_dcx.early_fatal(
761                            format!(
762                                "{outputname} option `{key}` requires {type_desc} ({prefix} {key}=<value>)"
763                            ),
764                        ),
765                        Some(value) => early_dcx.early_fatal(
766                            format!(
767                                "incorrect value `{value}` for {outputname} option `{key}` - {type_desc} was expected"
768                            ),
769                        ),
770                    }
771                }
772                if let Some(tmod) = *tmod {
773                    let v = value.map_or(String::new(), ToOwned::to_owned);
774                    target_modifiers.insert(tmod, v);
775                }
776            }
777            None => early_dcx.early_fatal(format!("unknown {outputname} option: `{key}`")),
778        }
779    }
780    op
781}
782
783#[allow(non_upper_case_globals)]
784mod desc {
785    pub(crate) const parse_no_value: &str = "no value";
786    pub(crate) const parse_bool: &str =
787        "one of: `y`, `yes`, `on`, `true`, `n`, `no`, `off` or `false`";
788    pub(crate) const parse_opt_bool: &str = parse_bool;
789    pub(crate) const parse_string: &str = "a string";
790    pub(crate) const parse_opt_string: &str = parse_string;
791    pub(crate) const parse_string_push: &str = parse_string;
792    pub(crate) const parse_opt_langid: &str = "a language identifier";
793    pub(crate) const parse_opt_pathbuf: &str = "a path";
794    pub(crate) const parse_list: &str = "a space-separated list of strings";
795    pub(crate) const parse_list_with_polarity: &str =
796        "a comma-separated list of strings, with elements beginning with + or -";
797    pub(crate) const parse_autodiff: &str = "a comma separated list of settings: `Enable`, `PrintSteps`, `PrintTA`, `PrintTAFn`, `PrintAA`, `PrintPerf`, `PrintModBefore`, `PrintModAfter`, `PrintModFinal`, `PrintPasses`, `NoPostopt`, `LooseTypes`, `Inline`, `NoTT`";
798    pub(crate) const parse_offload: &str = "a comma separated list of settings: `Enable`";
799    pub(crate) const parse_comma_list: &str = "a comma-separated list of strings";
800    pub(crate) const parse_opt_comma_list: &str = parse_comma_list;
801    pub(crate) const parse_number: &str = "a number";
802    pub(crate) const parse_opt_number: &str = parse_number;
803    pub(crate) const parse_frame_pointer: &str = "one of `true`/`yes`/`on`, `false`/`no`/`off`, or (with -Zunstable-options) `non-leaf` or `always`";
804    pub(crate) const parse_threads: &str = parse_number;
805    pub(crate) const parse_time_passes_format: &str = "`text` (default) or `json`";
806    pub(crate) const parse_passes: &str = "a space-separated list of passes, or `all`";
807    pub(crate) const parse_panic_strategy: &str = "either `unwind`, `abort`, or `immediate-abort`";
808    pub(crate) const parse_on_broken_pipe: &str = "either `kill`, `error`, or `inherit`";
809    pub(crate) const parse_patchable_function_entry: &str = "either two comma separated integers (total_nops,prefix_nops), with prefix_nops <= total_nops, or one integer (total_nops)";
810    pub(crate) const parse_opt_panic_strategy: &str = parse_panic_strategy;
811    pub(crate) const parse_relro_level: &str = "one of: `full`, `partial`, or `off`";
812    pub(crate) const parse_sanitizers: &str = "comma separated list of sanitizers: `address`, `cfi`, `dataflow`, `hwaddress`, `kcfi`, `kernel-address`, `leak`, `memory`, `memtag`, `safestack`, `shadow-call-stack`, `thread`, or 'realtime'";
813    pub(crate) const parse_sanitizer_memory_track_origins: &str = "0, 1, or 2";
814    pub(crate) const parse_cfguard: &str =
815        "either a boolean (`yes`, `no`, `on`, `off`, etc), `checks`, or `nochecks`";
816    pub(crate) const parse_cfprotection: &str = "`none`|`no`|`n` (default), `branch`, `return`, or `full`|`yes`|`y` (equivalent to `branch` and `return`)";
817    pub(crate) const parse_debuginfo: &str = "either an integer (0, 1, 2), `none`, `line-directives-only`, `line-tables-only`, `limited`, or `full`";
818    pub(crate) const parse_debuginfo_compression: &str = "one of `none`, `zlib`, or `zstd`";
819    pub(crate) const parse_mir_strip_debuginfo: &str =
820        "one of `none`, `locals-in-tiny-functions`, or `all-locals`";
821    pub(crate) const parse_collapse_macro_debuginfo: &str = "one of `no`, `external`, or `yes`";
822    pub(crate) const parse_strip: &str = "either `none`, `debuginfo`, or `symbols`";
823    pub(crate) const parse_linker_flavor: &str = ::rustc_target::spec::LinkerFlavorCli::one_of();
824    pub(crate) const parse_dump_mono_stats: &str = "`markdown` (default) or `json`";
825    pub(crate) const parse_instrument_coverage: &str = parse_bool;
826    pub(crate) const parse_coverage_options: &str = "`block` | `branch` | `condition`";
827    pub(crate) const parse_instrument_xray: &str = "either a boolean (`yes`, `no`, `on`, `off`, etc), or a comma separated list of settings: `always` or `never` (mutually exclusive), `ignore-loops`, `instruction-threshold=N`, `skip-entry`, `skip-exit`";
828    pub(crate) const parse_unpretty: &str = "`string` or `string=string`";
829    pub(crate) const parse_treat_err_as_bug: &str = "either no value or a non-negative number";
830    pub(crate) const parse_next_solver_config: &str =
831        "either `globally` (when used without an argument), `coherence` (default) or `no`";
832    pub(crate) const parse_lto: &str =
833        "either a boolean (`yes`, `no`, `on`, `off`, etc), `thin`, `fat`, or omitted";
834    pub(crate) const parse_linker_plugin_lto: &str =
835        "either a boolean (`yes`, `no`, `on`, `off`, etc), or the path to the linker plugin";
836    pub(crate) const parse_location_detail: &str = "either `none`, or a comma separated list of location details to track: `file`, `line`, or `column`";
837    pub(crate) const parse_fmt_debug: &str = "either `full`, `shallow`, or `none`";
838    pub(crate) const parse_switch_with_opt_path: &str =
839        "an optional path to the profiling data output directory";
840    pub(crate) const parse_merge_functions: &str =
841        "one of: `disabled`, `trampolines`, or `aliases`";
842    pub(crate) const parse_symbol_mangling_version: &str =
843        "one of: `legacy`, `v0` (RFC 2603), or `hashed`";
844    pub(crate) const parse_opt_symbol_visibility: &str =
845        "one of: `hidden`, `protected`, or `interposable`";
846    pub(crate) const parse_cargo_src_file_hash: &str =
847        "one of `blake3`, `md5`, `sha1`, or `sha256`";
848    pub(crate) const parse_src_file_hash: &str = "one of `md5`, `sha1`, or `sha256`";
849    pub(crate) const parse_relocation_model: &str =
850        "one of supported relocation models (`rustc --print relocation-models`)";
851    pub(crate) const parse_code_model: &str =
852        "one of supported code models (`rustc --print code-models`)";
853    pub(crate) const parse_tls_model: &str =
854        "one of supported TLS models (`rustc --print tls-models`)";
855    pub(crate) const parse_target_feature: &str = parse_string;
856    pub(crate) const parse_terminal_url: &str =
857        "either a boolean (`yes`, `no`, `on`, `off`, etc), or `auto`";
858    pub(crate) const parse_wasi_exec_model: &str = "either `command` or `reactor`";
859    pub(crate) const parse_split_debuginfo: &str =
860        "one of supported split-debuginfo modes (`off`, `packed`, or `unpacked`)";
861    pub(crate) const parse_split_dwarf_kind: &str =
862        "one of supported split dwarf modes (`split` or `single`)";
863    pub(crate) const parse_link_self_contained: &str = "one of: `y`, `yes`, `on`, `n`, `no`, `off`, or a list of enabled (`+` prefix) and disabled (`-` prefix) \
864        components: `crto`, `libc`, `unwind`, `linker`, `sanitizers`, `mingw`";
865    pub(crate) const parse_linker_features: &str =
866        "a list of enabled (`+` prefix) and disabled (`-` prefix) features: `lld`";
867    pub(crate) const parse_polonius: &str = "either no value or `legacy` (the default), or `next`";
868    pub(crate) const parse_annotate_moves: &str =
869        "either a boolean (`yes`, `no`, `on`, `off`, etc.), or a size limit in bytes";
870    pub(crate) const parse_stack_protector: &str =
871        "one of (`none` (default), `basic`, `strong`, or `all`)";
872    pub(crate) const parse_branch_protection: &str = "a `,` separated combination of `bti`, `gcs`, `pac-ret`, (optionally with `pc`, `b-key`, `leaf` if `pac-ret` is set)";
873    pub(crate) const parse_proc_macro_execution_strategy: &str =
874        "one of supported execution strategies (`same-thread`, or `cross-thread`)";
875    pub(crate) const parse_remap_path_scope: &str = "comma separated list of scopes: `macro`, `diagnostics`, `debuginfo`, `coverage`, `object`, `all`";
876    pub(crate) const parse_inlining_threshold: &str =
877        "either a boolean (`yes`, `no`, `on`, `off`, etc), or a non-negative number";
878    pub(crate) const parse_llvm_module_flag: &str = "<key>:<type>:<value>:<behavior>. Type must currently be `u32`. Behavior should be one of (`error`, `warning`, `require`, `override`, `append`, `appendunique`, `max`, `min`)";
879    pub(crate) const parse_function_return: &str = "`keep` or `thunk-extern`";
880    pub(crate) const parse_wasm_c_abi: &str = "`spec`";
881    pub(crate) const parse_mir_include_spans: &str =
882        "either a boolean (`yes`, `no`, `on`, `off`, etc), or `nll` (default: `nll`)";
883    pub(crate) const parse_align: &str = "a number that is a power of 2 between 1 and 2^29";
884}
885
886pub mod parse {
887    use std::str::FromStr;
888
889    pub(crate) use super::*;
890    pub(crate) const MAX_THREADS_CAP: usize = 256;
891
892    /// This is for boolean options that don't take a value, and are true simply
893    /// by existing on the command-line.
894    ///
895    /// This style of option is deprecated, and is mainly used by old options
896    /// beginning with `no-`.
897    pub(crate) fn parse_no_value(slot: &mut bool, v: Option<&str>) -> bool {
898        match v {
899            None => {
900                *slot = true;
901                true
902            }
903            // Trying to specify a value is always forbidden.
904            Some(_) => false,
905        }
906    }
907
908    /// Use this for any boolean option that has a static default.
909    pub(crate) fn parse_bool(slot: &mut bool, v: Option<&str>) -> bool {
910        match v {
911            Some("y") | Some("yes") | Some("on") | Some("true") | None => {
912                *slot = true;
913                true
914            }
915            Some("n") | Some("no") | Some("off") | Some("false") => {
916                *slot = false;
917                true
918            }
919            _ => false,
920        }
921    }
922
923    /// Use this for any boolean option that lacks a static default. (The
924    /// actions taken when such an option is not specified will depend on
925    /// other factors, such as other options, or target options.)
926    pub(crate) fn parse_opt_bool(slot: &mut Option<bool>, v: Option<&str>) -> bool {
927        match v {
928            Some("y") | Some("yes") | Some("on") | Some("true") | None => {
929                *slot = Some(true);
930                true
931            }
932            Some("n") | Some("no") | Some("off") | Some("false") => {
933                *slot = Some(false);
934                true
935            }
936            _ => false,
937        }
938    }
939
940    /// Parses whether polonius is enabled, and if so, which version.
941    pub(crate) fn parse_polonius(slot: &mut Polonius, v: Option<&str>) -> bool {
942        match v {
943            Some("legacy") | None => {
944                *slot = Polonius::Legacy;
945                true
946            }
947            Some("next") => {
948                *slot = Polonius::Next;
949                true
950            }
951            _ => false,
952        }
953    }
954
955    pub(crate) fn parse_annotate_moves(slot: &mut AnnotateMoves, v: Option<&str>) -> bool {
956        let mut bslot = false;
957        let mut nslot = 0u64;
958
959        *slot = match v {
960            // No value provided: -Z annotate-moves (enable with default limit)
961            None => AnnotateMoves::Enabled(None),
962            // Explicit boolean value provided: -Z annotate-moves=yes/no
963            s @ Some(_) if parse_bool(&mut bslot, s) => {
964                if bslot {
965                    AnnotateMoves::Enabled(None)
966                } else {
967                    AnnotateMoves::Disabled
968                }
969            }
970            // With numeric limit provided: -Z annotate-moves=1234
971            s @ Some(_) if parse_number(&mut nslot, s) => AnnotateMoves::Enabled(Some(nslot)),
972            _ => return false,
973        };
974
975        true
976    }
977
978    /// Use this for any string option that has a static default.
979    pub(crate) fn parse_string(slot: &mut String, v: Option<&str>) -> bool {
980        match v {
981            Some(s) => {
982                *slot = s.to_string();
983                true
984            }
985            None => false,
986        }
987    }
988
989    /// Use this for any string option that lacks a static default.
990    pub(crate) fn parse_opt_string(slot: &mut Option<String>, v: Option<&str>) -> bool {
991        match v {
992            Some(s) => {
993                *slot = Some(s.to_string());
994                true
995            }
996            None => false,
997        }
998    }
999
1000    /// Parse an optional language identifier, e.g. `en-US` or `zh-CN`.
1001    pub(crate) fn parse_opt_langid(slot: &mut Option<LanguageIdentifier>, v: Option<&str>) -> bool {
1002        match v {
1003            Some(s) => {
1004                *slot = rustc_errors::LanguageIdentifier::from_str(s).ok();
1005                true
1006            }
1007            None => false,
1008        }
1009    }
1010
1011    pub(crate) fn parse_opt_pathbuf(slot: &mut Option<PathBuf>, v: Option<&str>) -> bool {
1012        match v {
1013            Some(s) => {
1014                *slot = Some(PathBuf::from(s));
1015                true
1016            }
1017            None => false,
1018        }
1019    }
1020
1021    pub(crate) fn parse_string_push(slot: &mut Vec<String>, v: Option<&str>) -> bool {
1022        match v {
1023            Some(s) => {
1024                slot.push(s.to_string());
1025                true
1026            }
1027            None => false,
1028        }
1029    }
1030
1031    pub(crate) fn parse_list(slot: &mut Vec<String>, v: Option<&str>) -> bool {
1032        match v {
1033            Some(s) => {
1034                slot.extend(s.split_whitespace().map(|s| s.to_string()));
1035                true
1036            }
1037            None => false,
1038        }
1039    }
1040
1041    pub(crate) fn parse_list_with_polarity(
1042        slot: &mut Vec<(String, bool)>,
1043        v: Option<&str>,
1044    ) -> bool {
1045        match v {
1046            Some(s) => {
1047                for s in s.split(',') {
1048                    let Some(pass_name) = s.strip_prefix(&['+', '-'][..]) else { return false };
1049                    slot.push((pass_name.to_string(), &s[..1] == "+"));
1050                }
1051                true
1052            }
1053            None => false,
1054        }
1055    }
1056
1057    pub(crate) fn parse_fmt_debug(opt: &mut FmtDebug, v: Option<&str>) -> bool {
1058        *opt = match v {
1059            Some("full") => FmtDebug::Full,
1060            Some("shallow") => FmtDebug::Shallow,
1061            Some("none") => FmtDebug::None,
1062            _ => return false,
1063        };
1064        true
1065    }
1066
1067    pub(crate) fn parse_location_detail(ld: &mut LocationDetail, v: Option<&str>) -> bool {
1068        if let Some(v) = v {
1069            ld.line = false;
1070            ld.file = false;
1071            ld.column = false;
1072            if v == "none" {
1073                return true;
1074            }
1075            for s in v.split(',') {
1076                match s {
1077                    "file" => ld.file = true,
1078                    "line" => ld.line = true,
1079                    "column" => ld.column = true,
1080                    _ => return false,
1081                }
1082            }
1083            true
1084        } else {
1085            false
1086        }
1087    }
1088
1089    pub(crate) fn parse_comma_list(slot: &mut Vec<String>, v: Option<&str>) -> bool {
1090        match v {
1091            Some(s) => {
1092                let mut v: Vec<_> = s.split(',').map(|s| s.to_string()).collect();
1093                v.sort_unstable();
1094                *slot = v;
1095                true
1096            }
1097            None => false,
1098        }
1099    }
1100
1101    pub(crate) fn parse_opt_comma_list(slot: &mut Option<Vec<String>>, v: Option<&str>) -> bool {
1102        match v {
1103            Some(s) => {
1104                let mut v: Vec<_> = s.split(',').map(|s| s.to_string()).collect();
1105                v.sort_unstable();
1106                *slot = Some(v);
1107                true
1108            }
1109            None => false,
1110        }
1111    }
1112
1113    pub(crate) fn parse_threads(slot: &mut usize, v: Option<&str>) -> bool {
1114        let ret = match v.and_then(|s| s.parse().ok()) {
1115            Some(0) => {
1116                *slot = std::thread::available_parallelism().map_or(1, NonZero::<usize>::get);
1117                true
1118            }
1119            Some(i) => {
1120                *slot = i;
1121                true
1122            }
1123            None => false,
1124        };
1125        // We want to cap the number of threads here to avoid large numbers like 999999 and compiler panics.
1126        // This solution was suggested here https://github.com/rust-lang/rust/issues/117638#issuecomment-1800925067
1127        *slot = slot.clone().min(MAX_THREADS_CAP);
1128        ret
1129    }
1130
1131    /// Use this for any numeric option that has a static default.
1132    pub(crate) fn parse_number<T: Copy + FromStr>(slot: &mut T, v: Option<&str>) -> bool {
1133        match v.and_then(|s| s.parse().ok()) {
1134            Some(i) => {
1135                *slot = i;
1136                true
1137            }
1138            None => false,
1139        }
1140    }
1141
1142    /// Use this for any numeric option that lacks a static default.
1143    pub(crate) fn parse_opt_number<T: Copy + FromStr>(
1144        slot: &mut Option<T>,
1145        v: Option<&str>,
1146    ) -> bool {
1147        match v {
1148            Some(s) => {
1149                *slot = s.parse().ok();
1150                slot.is_some()
1151            }
1152            None => false,
1153        }
1154    }
1155
1156    pub(crate) fn parse_frame_pointer(slot: &mut FramePointer, v: Option<&str>) -> bool {
1157        let mut yes = false;
1158        match v {
1159            _ if parse_bool(&mut yes, v) && yes => slot.ratchet(FramePointer::Always),
1160            _ if parse_bool(&mut yes, v) => slot.ratchet(FramePointer::MayOmit),
1161            Some("always") => slot.ratchet(FramePointer::Always),
1162            Some("non-leaf") => slot.ratchet(FramePointer::NonLeaf),
1163            _ => return false,
1164        };
1165        true
1166    }
1167
1168    pub(crate) fn parse_passes(slot: &mut Passes, v: Option<&str>) -> bool {
1169        match v {
1170            Some("all") => {
1171                *slot = Passes::All;
1172                true
1173            }
1174            v => {
1175                let mut passes = vec![];
1176                if parse_list(&mut passes, v) {
1177                    slot.extend(passes);
1178                    true
1179                } else {
1180                    false
1181                }
1182            }
1183        }
1184    }
1185
1186    pub(crate) fn parse_opt_panic_strategy(
1187        slot: &mut Option<PanicStrategy>,
1188        v: Option<&str>,
1189    ) -> bool {
1190        match v {
1191            Some("unwind") => *slot = Some(PanicStrategy::Unwind),
1192            Some("abort") => *slot = Some(PanicStrategy::Abort),
1193            Some("immediate-abort") => *slot = Some(PanicStrategy::ImmediateAbort),
1194            _ => return false,
1195        }
1196        true
1197    }
1198
1199    pub(crate) fn parse_panic_strategy(slot: &mut PanicStrategy, v: Option<&str>) -> bool {
1200        match v {
1201            Some("unwind") => *slot = PanicStrategy::Unwind,
1202            Some("abort") => *slot = PanicStrategy::Abort,
1203            Some("immediate-abort") => *slot = PanicStrategy::ImmediateAbort,
1204            _ => return false,
1205        }
1206        true
1207    }
1208
1209    pub(crate) fn parse_on_broken_pipe(slot: &mut OnBrokenPipe, v: Option<&str>) -> bool {
1210        match v {
1211            // OnBrokenPipe::Default can't be explicitly specified
1212            Some("kill") => *slot = OnBrokenPipe::Kill,
1213            Some("error") => *slot = OnBrokenPipe::Error,
1214            Some("inherit") => *slot = OnBrokenPipe::Inherit,
1215            _ => return false,
1216        }
1217        true
1218    }
1219
1220    pub(crate) fn parse_patchable_function_entry(
1221        slot: &mut PatchableFunctionEntry,
1222        v: Option<&str>,
1223    ) -> bool {
1224        let mut total_nops = 0;
1225        let mut prefix_nops = 0;
1226
1227        if !parse_number(&mut total_nops, v) {
1228            let parts = v.and_then(|v| v.split_once(',')).unzip();
1229            if !parse_number(&mut total_nops, parts.0) {
1230                return false;
1231            }
1232            if !parse_number(&mut prefix_nops, parts.1) {
1233                return false;
1234            }
1235        }
1236
1237        if let Some(pfe) =
1238            PatchableFunctionEntry::from_total_and_prefix_nops(total_nops, prefix_nops)
1239        {
1240            *slot = pfe;
1241            return true;
1242        }
1243        false
1244    }
1245
1246    pub(crate) fn parse_relro_level(slot: &mut Option<RelroLevel>, v: Option<&str>) -> bool {
1247        match v {
1248            Some(s) => match s.parse::<RelroLevel>() {
1249                Ok(level) => *slot = Some(level),
1250                _ => return false,
1251            },
1252            _ => return false,
1253        }
1254        true
1255    }
1256
1257    pub(crate) fn parse_sanitizers(slot: &mut SanitizerSet, v: Option<&str>) -> bool {
1258        if let Some(v) = v {
1259            for s in v.split(',') {
1260                *slot |= match s {
1261                    "address" => SanitizerSet::ADDRESS,
1262                    "cfi" => SanitizerSet::CFI,
1263                    "dataflow" => SanitizerSet::DATAFLOW,
1264                    "kcfi" => SanitizerSet::KCFI,
1265                    "kernel-address" => SanitizerSet::KERNELADDRESS,
1266                    "leak" => SanitizerSet::LEAK,
1267                    "memory" => SanitizerSet::MEMORY,
1268                    "memtag" => SanitizerSet::MEMTAG,
1269                    "shadow-call-stack" => SanitizerSet::SHADOWCALLSTACK,
1270                    "thread" => SanitizerSet::THREAD,
1271                    "hwaddress" => SanitizerSet::HWADDRESS,
1272                    "safestack" => SanitizerSet::SAFESTACK,
1273                    "realtime" => SanitizerSet::REALTIME,
1274                    _ => return false,
1275                }
1276            }
1277            true
1278        } else {
1279            false
1280        }
1281    }
1282
1283    pub(crate) fn parse_sanitizer_memory_track_origins(slot: &mut usize, v: Option<&str>) -> bool {
1284        match v {
1285            Some("2") | None => {
1286                *slot = 2;
1287                true
1288            }
1289            Some("1") => {
1290                *slot = 1;
1291                true
1292            }
1293            Some("0") => {
1294                *slot = 0;
1295                true
1296            }
1297            Some(_) => false,
1298        }
1299    }
1300
1301    pub(crate) fn parse_strip(slot: &mut Strip, v: Option<&str>) -> bool {
1302        match v {
1303            Some("none") => *slot = Strip::None,
1304            Some("debuginfo") => *slot = Strip::Debuginfo,
1305            Some("symbols") => *slot = Strip::Symbols,
1306            _ => return false,
1307        }
1308        true
1309    }
1310
1311    pub(crate) fn parse_cfguard(slot: &mut CFGuard, v: Option<&str>) -> bool {
1312        if v.is_some() {
1313            let mut bool_arg = None;
1314            if parse_opt_bool(&mut bool_arg, v) {
1315                *slot = if bool_arg.unwrap() { CFGuard::Checks } else { CFGuard::Disabled };
1316                return true;
1317            }
1318        }
1319
1320        *slot = match v {
1321            None => CFGuard::Checks,
1322            Some("checks") => CFGuard::Checks,
1323            Some("nochecks") => CFGuard::NoChecks,
1324            Some(_) => return false,
1325        };
1326        true
1327    }
1328
1329    pub(crate) fn parse_cfprotection(slot: &mut CFProtection, v: Option<&str>) -> bool {
1330        if v.is_some() {
1331            let mut bool_arg = None;
1332            if parse_opt_bool(&mut bool_arg, v) {
1333                *slot = if bool_arg.unwrap() { CFProtection::Full } else { CFProtection::None };
1334                return true;
1335            }
1336        }
1337
1338        *slot = match v {
1339            None | Some("none") => CFProtection::None,
1340            Some("branch") => CFProtection::Branch,
1341            Some("return") => CFProtection::Return,
1342            Some("full") => CFProtection::Full,
1343            Some(_) => return false,
1344        };
1345        true
1346    }
1347
1348    pub(crate) fn parse_debuginfo(slot: &mut DebugInfo, v: Option<&str>) -> bool {
1349        match v {
1350            Some("0") | Some("none") => *slot = DebugInfo::None,
1351            Some("line-directives-only") => *slot = DebugInfo::LineDirectivesOnly,
1352            Some("line-tables-only") => *slot = DebugInfo::LineTablesOnly,
1353            Some("1") | Some("limited") => *slot = DebugInfo::Limited,
1354            Some("2") | Some("full") => *slot = DebugInfo::Full,
1355            _ => return false,
1356        }
1357        true
1358    }
1359
1360    pub(crate) fn parse_debuginfo_compression(
1361        slot: &mut DebugInfoCompression,
1362        v: Option<&str>,
1363    ) -> bool {
1364        match v {
1365            Some("none") => *slot = DebugInfoCompression::None,
1366            Some("zlib") => *slot = DebugInfoCompression::Zlib,
1367            Some("zstd") => *slot = DebugInfoCompression::Zstd,
1368            _ => return false,
1369        };
1370        true
1371    }
1372
1373    pub(crate) fn parse_mir_strip_debuginfo(slot: &mut MirStripDebugInfo, v: Option<&str>) -> bool {
1374        match v {
1375            Some("none") => *slot = MirStripDebugInfo::None,
1376            Some("locals-in-tiny-functions") => *slot = MirStripDebugInfo::LocalsInTinyFunctions,
1377            Some("all-locals") => *slot = MirStripDebugInfo::AllLocals,
1378            _ => return false,
1379        };
1380        true
1381    }
1382
1383    pub(crate) fn parse_linker_flavor(slot: &mut Option<LinkerFlavorCli>, v: Option<&str>) -> bool {
1384        match v.and_then(|v| LinkerFlavorCli::from_str(v).ok()) {
1385            Some(lf) => *slot = Some(lf),
1386            _ => return false,
1387        }
1388        true
1389    }
1390
1391    pub(crate) fn parse_opt_symbol_visibility(
1392        slot: &mut Option<SymbolVisibility>,
1393        v: Option<&str>,
1394    ) -> bool {
1395        if let Some(v) = v {
1396            if let Ok(vis) = SymbolVisibility::from_str(v) {
1397                *slot = Some(vis);
1398            } else {
1399                return false;
1400            }
1401        }
1402        true
1403    }
1404
1405    pub(crate) fn parse_unpretty(slot: &mut Option<String>, v: Option<&str>) -> bool {
1406        match v {
1407            None => false,
1408            Some(s) if s.split('=').count() <= 2 => {
1409                *slot = Some(s.to_string());
1410                true
1411            }
1412            _ => false,
1413        }
1414    }
1415
1416    pub(crate) fn parse_time_passes_format(slot: &mut TimePassesFormat, v: Option<&str>) -> bool {
1417        match v {
1418            None => true,
1419            Some("json") => {
1420                *slot = TimePassesFormat::Json;
1421                true
1422            }
1423            Some("text") => {
1424                *slot = TimePassesFormat::Text;
1425                true
1426            }
1427            Some(_) => false,
1428        }
1429    }
1430
1431    pub(crate) fn parse_dump_mono_stats(slot: &mut DumpMonoStatsFormat, v: Option<&str>) -> bool {
1432        match v {
1433            None => true,
1434            Some("json") => {
1435                *slot = DumpMonoStatsFormat::Json;
1436                true
1437            }
1438            Some("markdown") => {
1439                *slot = DumpMonoStatsFormat::Markdown;
1440                true
1441            }
1442            Some(_) => false,
1443        }
1444    }
1445
1446    pub(crate) fn parse_offload(slot: &mut Vec<Offload>, v: Option<&str>) -> bool {
1447        let Some(v) = v else {
1448            *slot = vec![];
1449            return true;
1450        };
1451        let mut v: Vec<&str> = v.split(",").collect();
1452        v.sort_unstable();
1453        for &val in v.iter() {
1454            // Split each entry on '=' if it has an argument
1455            let (key, arg) = match val.split_once('=') {
1456                Some((k, a)) => (k, Some(a)),
1457                None => (val, None),
1458            };
1459
1460            let variant = match key {
1461                "Host" => {
1462                    if let Some(p) = arg {
1463                        Offload::Host(p.to_string())
1464                    } else {
1465                        return false;
1466                    }
1467                }
1468                "Device" => {
1469                    if let Some(_) = arg {
1470                        // Device does not accept a value
1471                        return false;
1472                    }
1473                    Offload::Device
1474                }
1475                _ => {
1476                    // FIXME(ZuseZ4): print an error saying which value is not recognized
1477                    return false;
1478                }
1479            };
1480            slot.push(variant);
1481        }
1482
1483        true
1484    }
1485
1486    pub(crate) fn parse_autodiff(slot: &mut Vec<AutoDiff>, v: Option<&str>) -> bool {
1487        let Some(v) = v else {
1488            *slot = vec![];
1489            return true;
1490        };
1491        let mut v: Vec<&str> = v.split(",").collect();
1492        v.sort_unstable();
1493        for &val in v.iter() {
1494            // Split each entry on '=' if it has an argument
1495            let (key, arg) = match val.split_once('=') {
1496                Some((k, a)) => (k, Some(a)),
1497                None => (val, None),
1498            };
1499
1500            let variant = match key {
1501                "Enable" => AutoDiff::Enable,
1502                "PrintTA" => AutoDiff::PrintTA,
1503                "PrintTAFn" => {
1504                    if let Some(fun) = arg {
1505                        AutoDiff::PrintTAFn(fun.to_string())
1506                    } else {
1507                        return false;
1508                    }
1509                }
1510                "PrintAA" => AutoDiff::PrintAA,
1511                "PrintPerf" => AutoDiff::PrintPerf,
1512                "PrintSteps" => AutoDiff::PrintSteps,
1513                "PrintModBefore" => AutoDiff::PrintModBefore,
1514                "PrintModAfter" => AutoDiff::PrintModAfter,
1515                "PrintModFinal" => AutoDiff::PrintModFinal,
1516                "NoPostopt" => AutoDiff::NoPostopt,
1517                "PrintPasses" => AutoDiff::PrintPasses,
1518                "LooseTypes" => AutoDiff::LooseTypes,
1519                "Inline" => AutoDiff::Inline,
1520                "NoTT" => AutoDiff::NoTT,
1521                _ => {
1522                    // FIXME(ZuseZ4): print an error saying which value is not recognized
1523                    return false;
1524                }
1525            };
1526            slot.push(variant);
1527        }
1528
1529        true
1530    }
1531
1532    pub(crate) fn parse_instrument_coverage(
1533        slot: &mut InstrumentCoverage,
1534        v: Option<&str>,
1535    ) -> bool {
1536        if v.is_some() {
1537            let mut bool_arg = false;
1538            if parse_bool(&mut bool_arg, v) {
1539                *slot = if bool_arg { InstrumentCoverage::Yes } else { InstrumentCoverage::No };
1540                return true;
1541            }
1542        }
1543
1544        let Some(v) = v else {
1545            *slot = InstrumentCoverage::Yes;
1546            return true;
1547        };
1548
1549        // Parse values that have historically been accepted by stable compilers,
1550        // even though they're currently just aliases for boolean values.
1551        *slot = match v {
1552            "all" => InstrumentCoverage::Yes,
1553            "0" => InstrumentCoverage::No,
1554            _ => return false,
1555        };
1556        true
1557    }
1558
1559    pub(crate) fn parse_coverage_options(slot: &mut CoverageOptions, v: Option<&str>) -> bool {
1560        let Some(v) = v else { return true };
1561
1562        for option in v.split(',') {
1563            match option {
1564                "block" => slot.level = CoverageLevel::Block,
1565                "branch" => slot.level = CoverageLevel::Branch,
1566                "condition" => slot.level = CoverageLevel::Condition,
1567                "discard-all-spans-in-codegen" => slot.discard_all_spans_in_codegen = true,
1568                _ => return false,
1569            }
1570        }
1571        true
1572    }
1573
1574    pub(crate) fn parse_instrument_xray(
1575        slot: &mut Option<InstrumentXRay>,
1576        v: Option<&str>,
1577    ) -> bool {
1578        if v.is_some() {
1579            let mut bool_arg = None;
1580            if parse_opt_bool(&mut bool_arg, v) {
1581                *slot = if bool_arg.unwrap() { Some(InstrumentXRay::default()) } else { None };
1582                return true;
1583            }
1584        }
1585
1586        let options = slot.get_or_insert_default();
1587        let mut seen_always = false;
1588        let mut seen_never = false;
1589        let mut seen_ignore_loops = false;
1590        let mut seen_instruction_threshold = false;
1591        let mut seen_skip_entry = false;
1592        let mut seen_skip_exit = false;
1593        for option in v.into_iter().flat_map(|v| v.split(',')) {
1594            match option {
1595                "always" if !seen_always && !seen_never => {
1596                    options.always = true;
1597                    options.never = false;
1598                    seen_always = true;
1599                }
1600                "never" if !seen_never && !seen_always => {
1601                    options.never = true;
1602                    options.always = false;
1603                    seen_never = true;
1604                }
1605                "ignore-loops" if !seen_ignore_loops => {
1606                    options.ignore_loops = true;
1607                    seen_ignore_loops = true;
1608                }
1609                option
1610                    if option.starts_with("instruction-threshold")
1611                        && !seen_instruction_threshold =>
1612                {
1613                    let Some(("instruction-threshold", n)) = option.split_once('=') else {
1614                        return false;
1615                    };
1616                    match n.parse() {
1617                        Ok(n) => options.instruction_threshold = Some(n),
1618                        Err(_) => return false,
1619                    }
1620                    seen_instruction_threshold = true;
1621                }
1622                "skip-entry" if !seen_skip_entry => {
1623                    options.skip_entry = true;
1624                    seen_skip_entry = true;
1625                }
1626                "skip-exit" if !seen_skip_exit => {
1627                    options.skip_exit = true;
1628                    seen_skip_exit = true;
1629                }
1630                _ => return false,
1631            }
1632        }
1633        true
1634    }
1635
1636    pub(crate) fn parse_treat_err_as_bug(
1637        slot: &mut Option<NonZero<usize>>,
1638        v: Option<&str>,
1639    ) -> bool {
1640        match v {
1641            Some(s) => match s.parse() {
1642                Ok(val) => {
1643                    *slot = Some(val);
1644                    true
1645                }
1646                Err(e) => {
1647                    *slot = None;
1648                    e.kind() == &IntErrorKind::Zero
1649                }
1650            },
1651            None => {
1652                *slot = NonZero::new(1);
1653                true
1654            }
1655        }
1656    }
1657
1658    pub(crate) fn parse_next_solver_config(slot: &mut NextSolverConfig, v: Option<&str>) -> bool {
1659        if let Some(config) = v {
1660            *slot = match config {
1661                "no" => NextSolverConfig { coherence: false, globally: false },
1662                "coherence" => NextSolverConfig { coherence: true, globally: false },
1663                "globally" => NextSolverConfig { coherence: true, globally: true },
1664                _ => return false,
1665            };
1666        } else {
1667            *slot = NextSolverConfig { coherence: true, globally: true };
1668        }
1669
1670        true
1671    }
1672
1673    pub(crate) fn parse_lto(slot: &mut LtoCli, v: Option<&str>) -> bool {
1674        if v.is_some() {
1675            let mut bool_arg = None;
1676            if parse_opt_bool(&mut bool_arg, v) {
1677                *slot = if bool_arg.unwrap() { LtoCli::Yes } else { LtoCli::No };
1678                return true;
1679            }
1680        }
1681
1682        *slot = match v {
1683            None => LtoCli::NoParam,
1684            Some("thin") => LtoCli::Thin,
1685            Some("fat") => LtoCli::Fat,
1686            Some(_) => return false,
1687        };
1688        true
1689    }
1690
1691    pub(crate) fn parse_linker_plugin_lto(slot: &mut LinkerPluginLto, v: Option<&str>) -> bool {
1692        if v.is_some() {
1693            let mut bool_arg = None;
1694            if parse_opt_bool(&mut bool_arg, v) {
1695                *slot = if bool_arg.unwrap() {
1696                    LinkerPluginLto::LinkerPluginAuto
1697                } else {
1698                    LinkerPluginLto::Disabled
1699                };
1700                return true;
1701            }
1702        }
1703
1704        *slot = match v {
1705            None => LinkerPluginLto::LinkerPluginAuto,
1706            Some(path) => LinkerPluginLto::LinkerPlugin(PathBuf::from(path)),
1707        };
1708        true
1709    }
1710
1711    pub(crate) fn parse_switch_with_opt_path(
1712        slot: &mut SwitchWithOptPath,
1713        v: Option<&str>,
1714    ) -> bool {
1715        *slot = match v {
1716            None => SwitchWithOptPath::Enabled(None),
1717            Some(path) => SwitchWithOptPath::Enabled(Some(PathBuf::from(path))),
1718        };
1719        true
1720    }
1721
1722    pub(crate) fn parse_merge_functions(
1723        slot: &mut Option<MergeFunctions>,
1724        v: Option<&str>,
1725    ) -> bool {
1726        match v.and_then(|s| MergeFunctions::from_str(s).ok()) {
1727            Some(mergefunc) => *slot = Some(mergefunc),
1728            _ => return false,
1729        }
1730        true
1731    }
1732
1733    pub(crate) fn parse_remap_path_scope(
1734        slot: &mut RemapPathScopeComponents,
1735        v: Option<&str>,
1736    ) -> bool {
1737        if let Some(v) = v {
1738            *slot = RemapPathScopeComponents::empty();
1739            for s in v.split(',') {
1740                *slot |= match s {
1741                    "macro" => RemapPathScopeComponents::MACRO,
1742                    "diagnostics" => RemapPathScopeComponents::DIAGNOSTICS,
1743                    "debuginfo" => RemapPathScopeComponents::DEBUGINFO,
1744                    "coverage" => RemapPathScopeComponents::COVERAGE,
1745                    "object" => RemapPathScopeComponents::OBJECT,
1746                    "all" => RemapPathScopeComponents::all(),
1747                    _ => return false,
1748                }
1749            }
1750            true
1751        } else {
1752            false
1753        }
1754    }
1755
1756    pub(crate) fn parse_relocation_model(slot: &mut Option<RelocModel>, v: Option<&str>) -> bool {
1757        match v.and_then(|s| RelocModel::from_str(s).ok()) {
1758            Some(relocation_model) => *slot = Some(relocation_model),
1759            None if v == Some("default") => *slot = None,
1760            _ => return false,
1761        }
1762        true
1763    }
1764
1765    pub(crate) fn parse_code_model(slot: &mut Option<CodeModel>, v: Option<&str>) -> bool {
1766        match v.and_then(|s| CodeModel::from_str(s).ok()) {
1767            Some(code_model) => *slot = Some(code_model),
1768            _ => return false,
1769        }
1770        true
1771    }
1772
1773    pub(crate) fn parse_tls_model(slot: &mut Option<TlsModel>, v: Option<&str>) -> bool {
1774        match v.and_then(|s| TlsModel::from_str(s).ok()) {
1775            Some(tls_model) => *slot = Some(tls_model),
1776            _ => return false,
1777        }
1778        true
1779    }
1780
1781    pub(crate) fn parse_terminal_url(slot: &mut TerminalUrl, v: Option<&str>) -> bool {
1782        *slot = match v {
1783            Some("on" | "" | "yes" | "y") | None => TerminalUrl::Yes,
1784            Some("off" | "no" | "n") => TerminalUrl::No,
1785            Some("auto") => TerminalUrl::Auto,
1786            _ => return false,
1787        };
1788        true
1789    }
1790
1791    pub(crate) fn parse_symbol_mangling_version(
1792        slot: &mut Option<SymbolManglingVersion>,
1793        v: Option<&str>,
1794    ) -> bool {
1795        *slot = match v {
1796            Some("legacy") => Some(SymbolManglingVersion::Legacy),
1797            Some("v0") => Some(SymbolManglingVersion::V0),
1798            Some("hashed") => Some(SymbolManglingVersion::Hashed),
1799            _ => return false,
1800        };
1801        true
1802    }
1803
1804    pub(crate) fn parse_src_file_hash(
1805        slot: &mut Option<SourceFileHashAlgorithm>,
1806        v: Option<&str>,
1807    ) -> bool {
1808        match v.and_then(|s| SourceFileHashAlgorithm::from_str(s).ok()) {
1809            Some(hash_kind) => *slot = Some(hash_kind),
1810            _ => return false,
1811        }
1812        true
1813    }
1814
1815    pub(crate) fn parse_cargo_src_file_hash(
1816        slot: &mut Option<SourceFileHashAlgorithm>,
1817        v: Option<&str>,
1818    ) -> bool {
1819        match v.and_then(|s| SourceFileHashAlgorithm::from_str(s).ok()) {
1820            Some(hash_kind) => {
1821                *slot = Some(hash_kind);
1822            }
1823            _ => return false,
1824        }
1825        true
1826    }
1827
1828    pub(crate) fn parse_target_feature(slot: &mut String, v: Option<&str>) -> bool {
1829        match v {
1830            Some(s) => {
1831                if !slot.is_empty() {
1832                    slot.push(',');
1833                }
1834                slot.push_str(s);
1835                true
1836            }
1837            None => false,
1838        }
1839    }
1840
1841    pub(crate) fn parse_link_self_contained(slot: &mut LinkSelfContained, v: Option<&str>) -> bool {
1842        // Whenever `-C link-self-contained` is passed without a value, it's an opt-in
1843        // just like `parse_opt_bool`, the historical value of this flag.
1844        //
1845        // 1. Parse historical single bool values
1846        let s = v.unwrap_or("y");
1847        match s {
1848            "y" | "yes" | "on" => {
1849                slot.set_all_explicitly(true);
1850                return true;
1851            }
1852            "n" | "no" | "off" => {
1853                slot.set_all_explicitly(false);
1854                return true;
1855            }
1856            _ => {}
1857        }
1858
1859        // 2. Parse a list of enabled and disabled components.
1860        for comp in s.split(',') {
1861            if slot.handle_cli_component(comp).is_none() {
1862                return false;
1863            }
1864        }
1865
1866        true
1867    }
1868
1869    /// Parse a comma-separated list of enabled and disabled linker features.
1870    pub(crate) fn parse_linker_features(slot: &mut LinkerFeaturesCli, v: Option<&str>) -> bool {
1871        match v {
1872            Some(s) => {
1873                for feature in s.split(',') {
1874                    if slot.handle_cli_feature(feature).is_none() {
1875                        return false;
1876                    }
1877                }
1878
1879                true
1880            }
1881            None => false,
1882        }
1883    }
1884
1885    pub(crate) fn parse_wasi_exec_model(slot: &mut Option<WasiExecModel>, v: Option<&str>) -> bool {
1886        match v {
1887            Some("command") => *slot = Some(WasiExecModel::Command),
1888            Some("reactor") => *slot = Some(WasiExecModel::Reactor),
1889            _ => return false,
1890        }
1891        true
1892    }
1893
1894    pub(crate) fn parse_split_debuginfo(
1895        slot: &mut Option<SplitDebuginfo>,
1896        v: Option<&str>,
1897    ) -> bool {
1898        match v.and_then(|s| SplitDebuginfo::from_str(s).ok()) {
1899            Some(e) => *slot = Some(e),
1900            _ => return false,
1901        }
1902        true
1903    }
1904
1905    pub(crate) fn parse_split_dwarf_kind(slot: &mut SplitDwarfKind, v: Option<&str>) -> bool {
1906        match v.and_then(|s| SplitDwarfKind::from_str(s).ok()) {
1907            Some(e) => *slot = e,
1908            _ => return false,
1909        }
1910        true
1911    }
1912
1913    pub(crate) fn parse_stack_protector(slot: &mut StackProtector, v: Option<&str>) -> bool {
1914        match v.and_then(|s| StackProtector::from_str(s).ok()) {
1915            Some(ssp) => *slot = ssp,
1916            _ => return false,
1917        }
1918        true
1919    }
1920
1921    pub(crate) fn parse_branch_protection(
1922        slot: &mut Option<BranchProtection>,
1923        v: Option<&str>,
1924    ) -> bool {
1925        match v {
1926            Some(s) => {
1927                let slot = slot.get_or_insert_default();
1928                for opt in s.split(',') {
1929                    match opt {
1930                        "bti" => slot.bti = true,
1931                        "pac-ret" if slot.pac_ret.is_none() => {
1932                            slot.pac_ret = Some(PacRet { leaf: false, pc: false, key: PAuthKey::A })
1933                        }
1934                        "leaf" => match slot.pac_ret.as_mut() {
1935                            Some(pac) => pac.leaf = true,
1936                            _ => return false,
1937                        },
1938                        "b-key" => match slot.pac_ret.as_mut() {
1939                            Some(pac) => pac.key = PAuthKey::B,
1940                            _ => return false,
1941                        },
1942                        "pc" => match slot.pac_ret.as_mut() {
1943                            Some(pac) => pac.pc = true,
1944                            _ => return false,
1945                        },
1946                        "gcs" => slot.gcs = true,
1947                        _ => return false,
1948                    };
1949                }
1950            }
1951            _ => return false,
1952        }
1953        true
1954    }
1955
1956    pub(crate) fn parse_collapse_macro_debuginfo(
1957        slot: &mut CollapseMacroDebuginfo,
1958        v: Option<&str>,
1959    ) -> bool {
1960        if v.is_some() {
1961            let mut bool_arg = None;
1962            if parse_opt_bool(&mut bool_arg, v) {
1963                *slot = if bool_arg.unwrap() {
1964                    CollapseMacroDebuginfo::Yes
1965                } else {
1966                    CollapseMacroDebuginfo::No
1967                };
1968                return true;
1969            }
1970        }
1971
1972        *slot = match v {
1973            Some("external") => CollapseMacroDebuginfo::External,
1974            _ => return false,
1975        };
1976        true
1977    }
1978
1979    pub(crate) fn parse_proc_macro_execution_strategy(
1980        slot: &mut ProcMacroExecutionStrategy,
1981        v: Option<&str>,
1982    ) -> bool {
1983        *slot = match v {
1984            Some("same-thread") => ProcMacroExecutionStrategy::SameThread,
1985            Some("cross-thread") => ProcMacroExecutionStrategy::CrossThread,
1986            _ => return false,
1987        };
1988        true
1989    }
1990
1991    pub(crate) fn parse_inlining_threshold(slot: &mut InliningThreshold, v: Option<&str>) -> bool {
1992        match v {
1993            Some("always" | "yes") => {
1994                *slot = InliningThreshold::Always;
1995            }
1996            Some("never") => {
1997                *slot = InliningThreshold::Never;
1998            }
1999            Some(v) => {
2000                if let Ok(threshold) = v.parse() {
2001                    *slot = InliningThreshold::Sometimes(threshold);
2002                } else {
2003                    return false;
2004                }
2005            }
2006            None => return false,
2007        }
2008        true
2009    }
2010
2011    pub(crate) fn parse_llvm_module_flag(
2012        slot: &mut Vec<(String, u32, String)>,
2013        v: Option<&str>,
2014    ) -> bool {
2015        let elements = v.unwrap_or_default().split(':').collect::<Vec<_>>();
2016        let [key, md_type, value, behavior] = elements.as_slice() else {
2017            return false;
2018        };
2019        if *md_type != "u32" {
2020            // Currently we only support u32 metadata flags, but require the
2021            // type for forward-compatibility.
2022            return false;
2023        }
2024        let Ok(value) = value.parse::<u32>() else {
2025            return false;
2026        };
2027        let behavior = behavior.to_lowercase();
2028        let all_behaviors =
2029            ["error", "warning", "require", "override", "append", "appendunique", "max", "min"];
2030        if !all_behaviors.contains(&behavior.as_str()) {
2031            return false;
2032        }
2033
2034        slot.push((key.to_string(), value, behavior));
2035        true
2036    }
2037
2038    pub(crate) fn parse_function_return(slot: &mut FunctionReturn, v: Option<&str>) -> bool {
2039        match v {
2040            Some("keep") => *slot = FunctionReturn::Keep,
2041            Some("thunk-extern") => *slot = FunctionReturn::ThunkExtern,
2042            _ => return false,
2043        }
2044        true
2045    }
2046
2047    pub(crate) fn parse_wasm_c_abi(_slot: &mut (), v: Option<&str>) -> bool {
2048        v == Some("spec")
2049    }
2050
2051    pub(crate) fn parse_mir_include_spans(slot: &mut MirIncludeSpans, v: Option<&str>) -> bool {
2052        *slot = match v {
2053            Some("on" | "yes" | "y" | "true") | None => MirIncludeSpans::On,
2054            Some("off" | "no" | "n" | "false") => MirIncludeSpans::Off,
2055            Some("nll") => MirIncludeSpans::Nll,
2056            _ => return false,
2057        };
2058
2059        true
2060    }
2061
2062    pub(crate) fn parse_align(slot: &mut Option<Align>, v: Option<&str>) -> bool {
2063        let mut bytes = 0u64;
2064        if !parse_number(&mut bytes, v) {
2065            return false;
2066        }
2067
2068        let Ok(align) = Align::from_bytes(bytes) else {
2069            return false;
2070        };
2071
2072        *slot = Some(align);
2073
2074        true
2075    }
2076}
2077
2078options! {
2079    CodegenOptions, CodegenOptionsTargetModifiers, CG_OPTIONS, cgopts, "C", "codegen",
2080
2081    // If you add a new option, please update:
2082    // - compiler/rustc_interface/src/tests.rs
2083    // - src/doc/rustc/src/codegen-options/index.md
2084
2085    // tidy-alphabetical-start
2086    #[rustc_lint_opt_deny_field_access("documented to do nothing")]
2087    ar: String = (String::new(), parse_string, [UNTRACKED],
2088        "this option is deprecated and does nothing",
2089        deprecated_do_nothing: true),
2090    #[rustc_lint_opt_deny_field_access("use `Session::code_model` instead of this field")]
2091    code_model: Option<CodeModel> = (None, parse_code_model, [TRACKED],
2092        "choose the code model to use (`rustc --print code-models` for details)"),
2093    codegen_units: Option<usize> = (None, parse_opt_number, [UNTRACKED],
2094        "divide crate into N units to optimize in parallel"),
2095    collapse_macro_debuginfo: CollapseMacroDebuginfo = (CollapseMacroDebuginfo::Unspecified,
2096        parse_collapse_macro_debuginfo, [TRACKED],
2097        "set option to collapse debuginfo for macros"),
2098    control_flow_guard: CFGuard = (CFGuard::Disabled, parse_cfguard, [TRACKED],
2099        "use Windows Control Flow Guard (default: no)"),
2100    debug_assertions: Option<bool> = (None, parse_opt_bool, [TRACKED],
2101        "explicitly enable the `cfg(debug_assertions)` directive"),
2102    debuginfo: DebugInfo = (DebugInfo::None, parse_debuginfo, [TRACKED],
2103        "debug info emission level (0-2, none, line-directives-only, \
2104        line-tables-only, limited, or full; default: 0)"),
2105    default_linker_libraries: bool = (false, parse_bool, [UNTRACKED],
2106        "allow the linker to link its default libraries (default: no)"),
2107    dlltool: Option<PathBuf> = (None, parse_opt_pathbuf, [UNTRACKED],
2108        "import library generation tool (ignored except when targeting windows-gnu)"),
2109    #[rustc_lint_opt_deny_field_access("use `Session::dwarf_version` instead of this field")]
2110    dwarf_version: Option<u32> = (None, parse_opt_number, [TRACKED],
2111        "version of DWARF debug information to emit (default: 2 or 4, depending on platform)"),
2112    embed_bitcode: bool = (true, parse_bool, [TRACKED],
2113        "emit bitcode in rlibs (default: yes)"),
2114    extra_filename: String = (String::new(), parse_string, [UNTRACKED],
2115        "extra data to put in each output filename"),
2116    force_frame_pointers: FramePointer = (FramePointer::MayOmit, parse_frame_pointer, [TRACKED],
2117        "force use of the frame pointers"),
2118    #[rustc_lint_opt_deny_field_access("use `Session::must_emit_unwind_tables` instead of this field")]
2119    force_unwind_tables: Option<bool> = (None, parse_opt_bool, [TRACKED],
2120        "force use of unwind tables"),
2121    incremental: Option<String> = (None, parse_opt_string, [UNTRACKED],
2122        "enable incremental compilation"),
2123    #[rustc_lint_opt_deny_field_access("documented to do nothing")]
2124    inline_threshold: Option<u32> = (None, parse_opt_number, [UNTRACKED],
2125        "this option is deprecated and does nothing \
2126        (consider using `-Cllvm-args=--inline-threshold=...`)",
2127        deprecated_do_nothing: true),
2128    #[rustc_lint_opt_deny_field_access("use `Session::instrument_coverage` instead of this field")]
2129    instrument_coverage: InstrumentCoverage = (InstrumentCoverage::No, parse_instrument_coverage, [TRACKED],
2130        "instrument the generated code to support LLVM source-based code coverage reports \
2131        (note, the compiler build config must include `profiler = true`); \
2132        implies `-C symbol-mangling-version=v0`"),
2133    jump_tables: bool = (true, parse_bool, [TRACKED],
2134        "allow jump table and lookup table generation from switch case lowering (default: yes)"),
2135    link_arg: (/* redirected to link_args */) = ((), parse_string_push, [UNTRACKED],
2136        "a single extra argument to append to the linker invocation (can be used several times)"),
2137    link_args: Vec<String> = (Vec::new(), parse_list, [UNTRACKED],
2138        "extra arguments to append to the linker invocation (space separated)"),
2139    #[rustc_lint_opt_deny_field_access("use `Session::link_dead_code` instead of this field")]
2140    link_dead_code: Option<bool> = (None, parse_opt_bool, [TRACKED],
2141        "try to generate and link dead code (default: no)"),
2142    link_self_contained: LinkSelfContained = (LinkSelfContained::default(), parse_link_self_contained, [UNTRACKED],
2143        "control whether to link Rust provided C objects/libraries or rely \
2144        on a C toolchain or linker installed in the system"),
2145    linker: Option<PathBuf> = (None, parse_opt_pathbuf, [UNTRACKED],
2146        "system linker to link outputs with"),
2147    linker_features: LinkerFeaturesCli = (LinkerFeaturesCli::default(), parse_linker_features, [UNTRACKED],
2148        "a comma-separated list of linker features to enable (+) or disable (-): `lld`"),
2149    linker_flavor: Option<LinkerFlavorCli> = (None, parse_linker_flavor, [UNTRACKED],
2150        "linker flavor"),
2151    linker_plugin_lto: LinkerPluginLto = (LinkerPluginLto::Disabled,
2152        parse_linker_plugin_lto, [TRACKED],
2153        "generate build artifacts that are compatible with linker-based LTO"),
2154    llvm_args: Vec<String> = (Vec::new(), parse_list, [TRACKED],
2155        "a list of arguments to pass to LLVM (space separated)"),
2156    #[rustc_lint_opt_deny_field_access("use `Session::lto` instead of this field")]
2157    lto: LtoCli = (LtoCli::Unspecified, parse_lto, [TRACKED],
2158        "perform LLVM link-time optimizations"),
2159    metadata: Vec<String> = (Vec::new(), parse_list, [TRACKED],
2160        "metadata to mangle symbol names with"),
2161    no_prepopulate_passes: bool = (false, parse_no_value, [TRACKED],
2162        "give an empty list of passes to the pass manager"),
2163    no_redzone: Option<bool> = (None, parse_opt_bool, [TRACKED],
2164        "disable the use of the redzone"),
2165    #[rustc_lint_opt_deny_field_access("documented to do nothing")]
2166    no_stack_check: bool = (false, parse_no_value, [UNTRACKED],
2167        "this option is deprecated and does nothing",
2168        deprecated_do_nothing: true),
2169    no_vectorize_loops: bool = (false, parse_no_value, [TRACKED],
2170        "disable loop vectorization optimization passes"),
2171    no_vectorize_slp: bool = (false, parse_no_value, [TRACKED],
2172        "disable LLVM's SLP vectorization pass"),
2173    opt_level: String = ("0".to_string(), parse_string, [TRACKED],
2174        "optimization level (0-3, s, or z; default: 0)"),
2175    #[rustc_lint_opt_deny_field_access("use `Session::overflow_checks` instead of this field")]
2176    overflow_checks: Option<bool> = (None, parse_opt_bool, [TRACKED],
2177        "use overflow checks for integer arithmetic"),
2178    #[rustc_lint_opt_deny_field_access("use `Session::panic_strategy` instead of this field")]
2179    panic: Option<PanicStrategy> = (None, parse_opt_panic_strategy, [TRACKED],
2180        "panic strategy to compile crate with"),
2181    passes: Vec<String> = (Vec::new(), parse_list, [TRACKED],
2182        "a list of extra LLVM passes to run (space separated)"),
2183    prefer_dynamic: bool = (false, parse_bool, [TRACKED],
2184        "prefer dynamic linking to static linking (default: no)"),
2185    profile_generate: SwitchWithOptPath = (SwitchWithOptPath::Disabled,
2186        parse_switch_with_opt_path, [TRACKED],
2187        "compile the program with profiling instrumentation"),
2188    profile_use: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
2189        "use the given `.profdata` file for profile-guided optimization"),
2190    #[rustc_lint_opt_deny_field_access("use `Session::relocation_model` instead of this field")]
2191    relocation_model: Option<RelocModel> = (None, parse_relocation_model, [TRACKED],
2192        "control generation of position-independent code (PIC) \
2193        (`rustc --print relocation-models` for details)"),
2194    relro_level: Option<RelroLevel> = (None, parse_relro_level, [TRACKED],
2195        "choose which RELRO level to use"),
2196    remark: Passes = (Passes::Some(Vec::new()), parse_passes, [UNTRACKED],
2197        "output remarks for these optimization passes (space separated, or \"all\")"),
2198    rpath: bool = (false, parse_bool, [UNTRACKED],
2199        "set rpath values in libs/exes (default: no)"),
2200    save_temps: bool = (false, parse_bool, [UNTRACKED],
2201        "save all temporary output files during compilation (default: no)"),
2202    soft_float: bool = (false, parse_bool, [TRACKED],
2203        "deprecated option: use soft float ABI (*eabihf targets only) (default: no)"),
2204    #[rustc_lint_opt_deny_field_access("use `Session::split_debuginfo` instead of this field")]
2205    split_debuginfo: Option<SplitDebuginfo> = (None, parse_split_debuginfo, [TRACKED],
2206        "how to handle split-debuginfo, a platform-specific option"),
2207    strip: Strip = (Strip::None, parse_strip, [UNTRACKED],
2208        "tell the linker which information to strip (`none` (default), `debuginfo` or `symbols`)"),
2209    symbol_mangling_version: Option<SymbolManglingVersion> = (None,
2210        parse_symbol_mangling_version, [TRACKED],
2211        "which mangling version to use for symbol names ('legacy' (default), 'v0', or 'hashed')"),
2212    target_cpu: Option<String> = (None, parse_opt_string, [TRACKED],
2213        "select target processor (`rustc --print target-cpus` for details)"),
2214    target_feature: String = (String::new(), parse_target_feature, [TRACKED],
2215        "target specific attributes. (`rustc --print target-features` for details). \
2216        This feature is unsafe."),
2217    unsafe_allow_abi_mismatch: Vec<String> = (Vec::new(), parse_comma_list, [UNTRACKED],
2218        "Allow incompatible target modifiers in dependency crates (comma separated list)"),
2219    // tidy-alphabetical-end
2220
2221    // If you add a new option, please update:
2222    // - compiler/rustc_interface/src/tests.rs
2223    // - src/doc/rustc/src/codegen-options/index.md
2224}
2225
2226options! {
2227    UnstableOptions, UnstableOptionsTargetModifiers, Z_OPTIONS, dbopts, "Z", "unstable",
2228
2229    // If you add a new option, please update:
2230    // - compiler/rustc_interface/src/tests.rs
2231    // - src/doc/unstable-book/src/compiler-flags
2232
2233    // tidy-alphabetical-start
2234    allow_features: Option<Vec<String>> = (None, parse_opt_comma_list, [TRACKED],
2235        "only allow the listed language features to be enabled in code (comma separated)"),
2236    always_encode_mir: bool = (false, parse_bool, [TRACKED],
2237        "encode MIR of all functions into the crate metadata (default: no)"),
2238    annotate_moves: AnnotateMoves = (AnnotateMoves::Disabled, parse_annotate_moves, [TRACKED],
2239        "emit debug info for compiler-generated move and copy operations \
2240        to make them visible in profilers. Can be a boolean or a size limit in bytes (default: disabled)"),
2241    assert_incr_state: Option<String> = (None, parse_opt_string, [UNTRACKED],
2242        "assert that the incremental cache is in given state: \
2243         either `loaded` or `not-loaded`."),
2244    assume_incomplete_release: bool = (false, parse_bool, [TRACKED],
2245        "make cfg(version) treat the current version as incomplete (default: no)"),
2246    autodiff: Vec<crate::config::AutoDiff> = (Vec::new(), parse_autodiff, [TRACKED],
2247        "a list of autodiff flags to enable
2248        Mandatory setting:
2249        `=Enable`
2250        Optional extra settings:
2251        `=PrintTA`
2252        `=PrintAA`
2253        `=PrintPerf`
2254        `=PrintSteps`
2255        `=PrintModBefore`
2256        `=PrintModAfter`
2257        `=PrintModFinal`
2258        `=PrintPasses`,
2259        `=NoPostopt`
2260        `=LooseTypes`
2261        `=Inline`
2262        Multiple options can be combined with commas."),
2263    #[rustc_lint_opt_deny_field_access("use `Session::binary_dep_depinfo` instead of this field")]
2264    binary_dep_depinfo: bool = (false, parse_bool, [TRACKED],
2265        "include artifacts (sysroot, crate dependencies) used during compilation in dep-info \
2266        (default: no)"),
2267    box_noalias: bool = (true, parse_bool, [TRACKED],
2268        "emit noalias metadata for box (default: yes)"),
2269    branch_protection: Option<BranchProtection> = (None, parse_branch_protection, [TRACKED],
2270        "set options for branch target identification and pointer authentication on AArch64"),
2271    build_sdylib_interface: bool = (false, parse_bool, [UNTRACKED],
2272        "whether the stable interface is being built"),
2273    cf_protection: CFProtection = (CFProtection::None, parse_cfprotection, [TRACKED],
2274        "instrument control-flow architecture protection"),
2275    check_cfg_all_expected: bool = (false, parse_bool, [UNTRACKED],
2276        "show all expected values in check-cfg diagnostics (default: no)"),
2277    checksum_hash_algorithm: Option<SourceFileHashAlgorithm> = (None, parse_cargo_src_file_hash, [TRACKED],
2278        "hash algorithm of source files used to check freshness in cargo (`blake3` or `sha256`)"),
2279    codegen_backend: Option<String> = (None, parse_opt_string, [TRACKED],
2280        "the backend to use"),
2281    codegen_source_order: bool = (false, parse_bool, [UNTRACKED],
2282        "emit mono items in the order of spans in source files (default: no)"),
2283    contract_checks: Option<bool> = (None, parse_opt_bool, [TRACKED],
2284        "emit runtime checks for contract pre- and post-conditions (default: no)"),
2285    coverage_options: CoverageOptions = (CoverageOptions::default(), parse_coverage_options, [TRACKED],
2286        "control details of coverage instrumentation"),
2287    crate_attr: Vec<String> = (Vec::new(), parse_string_push, [TRACKED],
2288        "inject the given attribute in the crate"),
2289    cross_crate_inline_threshold: InliningThreshold = (InliningThreshold::Sometimes(100), parse_inlining_threshold, [TRACKED],
2290        "threshold to allow cross crate inlining of functions"),
2291    debug_info_for_profiling: bool = (false, parse_bool, [TRACKED],
2292        "emit discriminators and other data necessary for AutoFDO"),
2293    debug_info_type_line_numbers: bool = (false, parse_bool, [TRACKED],
2294        "emit type and line information for additional data types (default: no)"),
2295    debuginfo_compression: DebugInfoCompression = (DebugInfoCompression::None, parse_debuginfo_compression, [TRACKED],
2296        "compress debug info sections (none, zlib, zstd, default: none)"),
2297    deduplicate_diagnostics: bool = (true, parse_bool, [UNTRACKED],
2298        "deduplicate identical diagnostics (default: yes)"),
2299    default_visibility: Option<SymbolVisibility> = (None, parse_opt_symbol_visibility, [TRACKED],
2300        "overrides the `default_visibility` setting of the target"),
2301    dep_info_omit_d_target: bool = (false, parse_bool, [TRACKED],
2302        "in dep-info output, omit targets for tracking dependencies of the dep-info files \
2303        themselves (default: no)"),
2304    direct_access_external_data: Option<bool> = (None, parse_opt_bool, [TRACKED],
2305        "Direct or use GOT indirect to reference external data symbols"),
2306    dual_proc_macros: bool = (false, parse_bool, [TRACKED],
2307        "load proc macros for both target and host, but only link to the target (default: no)"),
2308    dump_dep_graph: bool = (false, parse_bool, [UNTRACKED],
2309        "dump the dependency graph to $RUST_DEP_GRAPH (default: /tmp/dep_graph.gv) \
2310        (default: no)"),
2311    dump_mir: Option<String> = (None, parse_opt_string, [UNTRACKED],
2312        "dump MIR state to file.
2313        `val` is used to select which passes and functions to dump. For example:
2314        `all` matches all passes and functions,
2315        `foo` matches all passes for functions whose name contains 'foo',
2316        `foo & ConstProp` only the 'ConstProp' pass for function names containing 'foo',
2317        `foo | bar` all passes for function names containing 'foo' or 'bar'."),
2318    dump_mir_dataflow: bool = (false, parse_bool, [UNTRACKED],
2319        "in addition to `.mir` files, create graphviz `.dot` files with dataflow results \
2320        (default: no)"),
2321    dump_mir_dir: String = ("mir_dump".to_string(), parse_string, [UNTRACKED],
2322        "the directory the MIR is dumped into (default: `mir_dump`)"),
2323    dump_mir_exclude_alloc_bytes: bool = (false, parse_bool, [UNTRACKED],
2324        "exclude the raw bytes of allocations when dumping MIR (used in tests) (default: no)"),
2325    dump_mir_exclude_pass_number: bool = (false, parse_bool, [UNTRACKED],
2326        "exclude the pass number when dumping MIR (used in tests) (default: no)"),
2327    dump_mir_graphviz: bool = (false, parse_bool, [UNTRACKED],
2328        "in addition to `.mir` files, create graphviz `.dot` files (default: no)"),
2329    dump_mono_stats: SwitchWithOptPath = (SwitchWithOptPath::Disabled,
2330        parse_switch_with_opt_path, [UNTRACKED],
2331        "output statistics about monomorphization collection"),
2332    dump_mono_stats_format: DumpMonoStatsFormat = (DumpMonoStatsFormat::Markdown, parse_dump_mono_stats, [UNTRACKED],
2333        "the format to use for -Z dump-mono-stats (`markdown` (default) or `json`)"),
2334    #[rustc_lint_opt_deny_field_access("use `Session::dwarf_version` instead of this field")]
2335    dwarf_version: Option<u32> = (None, parse_opt_number, [TRACKED],
2336        "version of DWARF debug information to emit (default: 2 or 4, depending on platform)"),
2337    dylib_lto: bool = (false, parse_bool, [UNTRACKED],
2338        "enables LTO for dylib crate type"),
2339    eagerly_emit_delayed_bugs: bool = (false, parse_bool, [UNTRACKED],
2340        "emit delayed bugs eagerly as errors instead of stashing them and emitting \
2341        them only if an error has not been emitted"),
2342    ehcont_guard: bool = (false, parse_bool, [TRACKED],
2343        "generate Windows EHCont Guard tables"),
2344    embed_metadata: bool = (true, parse_bool, [TRACKED],
2345        "embed metadata in rlibs and dylibs (default: yes)"),
2346    embed_source: bool = (false, parse_bool, [TRACKED],
2347        "embed source text in DWARF debug sections (default: no)"),
2348    emit_stack_sizes: bool = (false, parse_bool, [UNTRACKED],
2349        "emit a section containing stack size metadata (default: no)"),
2350    emit_thin_lto: bool = (true, parse_bool, [TRACKED],
2351        "emit the bc module with thin LTO info (default: yes)"),
2352    emscripten_wasm_eh: bool = (true, parse_bool, [TRACKED],
2353        "Use WebAssembly error handling for wasm32-unknown-emscripten"),
2354    enforce_type_length_limit: bool = (false, parse_bool, [TRACKED],
2355        "enforce the type length limit when monomorphizing instances in codegen"),
2356    experimental_default_bounds: bool = (false, parse_bool, [TRACKED],
2357        "enable default bounds for experimental group of auto traits"),
2358    export_executable_symbols: bool = (false, parse_bool, [TRACKED],
2359        "export symbols from executables, as if they were dynamic libraries"),
2360    external_clangrt: bool = (false, parse_bool, [UNTRACKED],
2361        "rely on user specified linker commands to find clangrt"),
2362    extra_const_ub_checks: bool = (false, parse_bool, [TRACKED],
2363        "turns on more checks to detect const UB, which can be slow (default: no)"),
2364    #[rustc_lint_opt_deny_field_access("use `Session::fewer_names` instead of this field")]
2365    fewer_names: Option<bool> = (None, parse_opt_bool, [TRACKED],
2366        "reduce memory use by retaining fewer names within compilation artifacts (LLVM-IR) \
2367        (default: no)"),
2368    fixed_x18: bool = (false, parse_bool, [TRACKED TARGET_MODIFIER],
2369        "make the x18 register reserved on AArch64 (default: no)"),
2370    flatten_format_args: bool = (true, parse_bool, [TRACKED],
2371        "flatten nested format_args!() and literals into a simplified format_args!() call \
2372        (default: yes)"),
2373    fmt_debug: FmtDebug = (FmtDebug::Full, parse_fmt_debug, [TRACKED],
2374        "how detailed `#[derive(Debug)]` should be. `full` prints types recursively, \
2375        `shallow` prints only type names, `none` prints nothing and disables `{:?}`. (default: `full`)"),
2376    force_unstable_if_unmarked: bool = (false, parse_bool, [TRACKED],
2377        "force all crates to be `rustc_private` unstable (default: no)"),
2378    function_return: FunctionReturn = (FunctionReturn::default(), parse_function_return, [TRACKED],
2379        "replace returns with jumps to `__x86_return_thunk` (default: `keep`)"),
2380    function_sections: Option<bool> = (None, parse_opt_bool, [TRACKED],
2381        "whether each function should go in its own section"),
2382    future_incompat_test: bool = (false, parse_bool, [UNTRACKED],
2383        "forces all lints to be future incompatible, used for internal testing (default: no)"),
2384    graphviz_dark_mode: bool = (false, parse_bool, [UNTRACKED],
2385        "use dark-themed colors in graphviz output (default: no)"),
2386    graphviz_font: String = ("Courier, monospace".to_string(), parse_string, [UNTRACKED],
2387        "use the given `fontname` in graphviz output; can be overridden by setting \
2388        environment variable `RUSTC_GRAPHVIZ_FONT` (default: `Courier, monospace`)"),
2389    has_thread_local: Option<bool> = (None, parse_opt_bool, [TRACKED],
2390        "explicitly enable the `cfg(target_thread_local)` directive"),
2391    higher_ranked_assumptions: bool = (false, parse_bool, [TRACKED],
2392        "allow deducing higher-ranked outlives assumptions from coroutines when proving auto traits"),
2393    hint_mostly_unused: bool = (false, parse_bool, [TRACKED],
2394        "hint that most of this crate will go unused, to minimize work for uncalled functions"),
2395    human_readable_cgu_names: bool = (false, parse_bool, [TRACKED],
2396        "generate human-readable, predictable names for codegen units (default: no)"),
2397    identify_regions: bool = (false, parse_bool, [UNTRACKED],
2398        "display unnamed regions as `'<id>`, using a non-ident unique id (default: no)"),
2399    ignore_directory_in_diagnostics_source_blocks: Vec<String> = (Vec::new(), parse_string_push, [UNTRACKED],
2400        "do not display the source code block in diagnostics for files in the directory"),
2401    incremental_ignore_spans: bool = (false, parse_bool, [TRACKED],
2402        "ignore spans during ICH computation -- used for testing (default: no)"),
2403    incremental_info: bool = (false, parse_bool, [UNTRACKED],
2404        "print high-level information about incremental reuse (or the lack thereof) \
2405        (default: no)"),
2406    incremental_verify_ich: bool = (false, parse_bool, [UNTRACKED],
2407        "verify extended properties for incr. comp. (default: no):
2408        - hashes of green query instances
2409        - hash collisions of query keys
2410        - hash collisions when creating dep-nodes"),
2411    indirect_branch_cs_prefix: bool = (false, parse_bool, [TRACKED TARGET_MODIFIER],
2412        "add `cs` prefix to `call` and `jmp` to indirect thunks (default: no)"),
2413    inline_llvm: bool = (true, parse_bool, [TRACKED],
2414        "enable LLVM inlining (default: yes)"),
2415    inline_mir: Option<bool> = (None, parse_opt_bool, [TRACKED],
2416        "enable MIR inlining (default: no)"),
2417    inline_mir_forwarder_threshold: Option<usize> = (None, parse_opt_number, [TRACKED],
2418        "inlining threshold when the caller is a simple forwarding function (default: 30)"),
2419    inline_mir_hint_threshold: Option<usize> = (None, parse_opt_number, [TRACKED],
2420        "inlining threshold for functions with inline hint (default: 100)"),
2421    inline_mir_preserve_debug: Option<bool> = (None, parse_opt_bool, [TRACKED],
2422        "when MIR inlining, whether to preserve debug info for callee variables \
2423        (default: preserve for debuginfo != None, otherwise remove)"),
2424    inline_mir_threshold: Option<usize> = (None, parse_opt_number, [TRACKED],
2425        "a default MIR inlining threshold (default: 50)"),
2426    input_stats: bool = (false, parse_bool, [UNTRACKED],
2427        "print some statistics about AST and HIR (default: no)"),
2428    instrument_mcount: bool = (false, parse_bool, [TRACKED],
2429        "insert function instrument code for mcount-based tracing (default: no)"),
2430    instrument_xray: Option<InstrumentXRay> = (None, parse_instrument_xray, [TRACKED],
2431        "insert function instrument code for XRay-based tracing (default: no)
2432         Optional extra settings:
2433         `=always`
2434         `=never`
2435         `=ignore-loops`
2436         `=instruction-threshold=N`
2437         `=skip-entry`
2438         `=skip-exit`
2439         Multiple options can be combined with commas."),
2440    layout_seed: Option<u64> = (None, parse_opt_number, [TRACKED],
2441        "seed layout randomization"),
2442    link_directives: bool = (true, parse_bool, [TRACKED],
2443        "honor #[link] directives in the compiled crate (default: yes)"),
2444    link_native_libraries: bool = (true, parse_bool, [UNTRACKED],
2445        "link native libraries in the linker invocation (default: yes)"),
2446    link_only: bool = (false, parse_bool, [TRACKED],
2447        "link the `.rlink` file generated by `-Z no-link` (default: no)"),
2448    lint_llvm_ir: bool = (false, parse_bool, [TRACKED],
2449        "lint LLVM IR (default: no)"),
2450    lint_mir: bool = (false, parse_bool, [UNTRACKED],
2451        "lint MIR before and after each transformation"),
2452    llvm_module_flag: Vec<(String, u32, String)> = (Vec::new(), parse_llvm_module_flag, [TRACKED],
2453        "a list of module flags to pass to LLVM (space separated)"),
2454    llvm_plugins: Vec<String> = (Vec::new(), parse_list, [TRACKED],
2455        "a list LLVM plugins to enable (space separated)"),
2456    llvm_time_trace: bool = (false, parse_bool, [UNTRACKED],
2457        "generate JSON tracing data file from LLVM data (default: no)"),
2458    location_detail: LocationDetail = (LocationDetail::all(), parse_location_detail, [TRACKED],
2459        "what location details should be tracked when using caller_location, either \
2460        `none`, or a comma separated list of location details, for which \
2461        valid options are `file`, `line`, and `column` (default: `file,line,column`)"),
2462    ls: Vec<String> = (Vec::new(), parse_list, [UNTRACKED],
2463        "decode and print various parts of the crate metadata for a library crate \
2464        (space separated)"),
2465    macro_backtrace: bool = (false, parse_bool, [UNTRACKED],
2466        "show macro backtraces (default: no)"),
2467    macro_stats: bool = (false, parse_bool, [UNTRACKED],
2468        "print some statistics about macro expansions (default: no)"),
2469    maximal_hir_to_mir_coverage: bool = (false, parse_bool, [TRACKED],
2470        "save as much information as possible about the correspondence between MIR and HIR \
2471        as source scopes (default: no)"),
2472    merge_functions: Option<MergeFunctions> = (None, parse_merge_functions, [TRACKED],
2473        "control the operation of the MergeFunctions LLVM pass, taking \
2474        the same values as the target option of the same name"),
2475    meta_stats: bool = (false, parse_bool, [UNTRACKED],
2476        "gather metadata statistics (default: no)"),
2477    metrics_dir: Option<PathBuf> = (None, parse_opt_pathbuf, [UNTRACKED],
2478        "the directory metrics emitted by rustc are dumped into (implicitly enables default set of metrics)"),
2479    min_function_alignment: Option<Align> = (None, parse_align, [TRACKED],
2480        "align all functions to at least this many bytes. Must be a power of 2"),
2481    mir_emit_retag: bool = (false, parse_bool, [TRACKED],
2482        "emit Retagging MIR statements, interpreted e.g., by miri; implies -Zmir-opt-level=0 \
2483        (default: no)"),
2484    mir_enable_passes: Vec<(String, bool)> = (Vec::new(), parse_list_with_polarity, [TRACKED],
2485        "use like `-Zmir-enable-passes=+DestinationPropagation,-InstSimplify`. Forces the \
2486        specified passes to be enabled, overriding all other checks. In particular, this will \
2487        enable unsound (known-buggy and hence usually disabled) passes without further warning! \
2488        Passes that are not specified are enabled or disabled by other flags as usual."),
2489    mir_include_spans: MirIncludeSpans = (MirIncludeSpans::default(), parse_mir_include_spans, [UNTRACKED],
2490        "include extra comments in mir pretty printing, like line numbers and statement indices, \
2491         details about types, etc. (boolean for all passes, 'nll' to enable in NLL MIR only, default: 'nll')"),
2492    #[rustc_lint_opt_deny_field_access("use `Session::mir_opt_level` instead of this field")]
2493    mir_opt_level: Option<usize> = (None, parse_opt_number, [TRACKED],
2494        "MIR optimization level (0-4; default: 1 in non optimized builds and 2 in optimized builds)"),
2495    mir_preserve_ub: bool = (false, parse_bool, [TRACKED],
2496        "keep place mention statements and reads in trivial SwitchInt terminators, which are interpreted \
2497        e.g., by miri; implies -Zmir-opt-level=0 (default: no)"),
2498    mir_strip_debuginfo: MirStripDebugInfo = (MirStripDebugInfo::None, parse_mir_strip_debuginfo, [TRACKED],
2499        "Whether to remove some of the MIR debug info from methods.  Default: None"),
2500    move_size_limit: Option<usize> = (None, parse_opt_number, [TRACKED],
2501        "the size at which the `large_assignments` lint starts to be emitted"),
2502    mutable_noalias: bool = (true, parse_bool, [TRACKED],
2503        "emit noalias metadata for mutable references (default: yes)"),
2504    namespaced_crates: bool = (false, parse_bool, [TRACKED],
2505        "allow crates to be namespaced by other crates (default: no)"),
2506    next_solver: NextSolverConfig = (NextSolverConfig::default(), parse_next_solver_config, [TRACKED],
2507        "enable and configure the next generation trait solver used by rustc"),
2508    nll_facts: bool = (false, parse_bool, [UNTRACKED],
2509        "dump facts from NLL analysis into side files (default: no)"),
2510    nll_facts_dir: String = ("nll-facts".to_string(), parse_string, [UNTRACKED],
2511        "the directory the NLL facts are dumped into (default: `nll-facts`)"),
2512    no_analysis: bool = (false, parse_no_value, [UNTRACKED],
2513        "parse and expand the source, but run no analysis"),
2514    no_codegen: bool = (false, parse_no_value, [TRACKED_NO_CRATE_HASH],
2515        "run all passes except codegen; no output"),
2516    no_generate_arange_section: bool = (false, parse_no_value, [TRACKED],
2517        "omit DWARF address ranges that give faster lookups"),
2518    no_implied_bounds_compat: bool = (false, parse_bool, [TRACKED],
2519        "disable the compatibility version of the `implied_bounds_ty` query"),
2520    no_leak_check: bool = (false, parse_no_value, [UNTRACKED],
2521        "disable the 'leak check' for subtyping; unsound, but useful for tests"),
2522    no_link: bool = (false, parse_no_value, [TRACKED],
2523        "compile without linking"),
2524    no_parallel_backend: bool = (false, parse_no_value, [UNTRACKED],
2525        "run LLVM in non-parallel mode (while keeping codegen-units and ThinLTO)"),
2526    no_profiler_runtime: bool = (false, parse_no_value, [TRACKED],
2527        "prevent automatic injection of the profiler_builtins crate"),
2528    no_steal_thir: bool = (false, parse_bool, [UNTRACKED],
2529        "don't steal the THIR when we're done with it; useful for rustc drivers (default: no)"),
2530    no_trait_vptr: bool = (false, parse_no_value, [TRACKED],
2531        "disable generation of trait vptr in vtable for upcasting"),
2532    no_unique_section_names: bool = (false, parse_bool, [TRACKED],
2533        "do not use unique names for text and data sections when -Z function-sections is used"),
2534    normalize_docs: bool = (false, parse_bool, [TRACKED],
2535        "normalize associated items in rustdoc when generating documentation"),
2536    offload: Vec<crate::config::Offload> = (Vec::new(), parse_offload, [TRACKED],
2537        "a list of offload flags to enable
2538        Mandatory setting:
2539        `=Enable`
2540        Currently the only option available"),
2541    on_broken_pipe: OnBrokenPipe = (OnBrokenPipe::Default, parse_on_broken_pipe, [TRACKED],
2542        "behavior of std::io::ErrorKind::BrokenPipe (SIGPIPE)"),
2543    osx_rpath_install_name: bool = (false, parse_bool, [TRACKED],
2544        "pass `-install_name @rpath/...` to the macOS linker (default: no)"),
2545    packed_bundled_libs: bool = (false, parse_bool, [TRACKED],
2546        "change rlib format to store native libraries as archives"),
2547    panic_abort_tests: bool = (false, parse_bool, [TRACKED],
2548        "support compiling tests with panic=abort (default: no)"),
2549    panic_in_drop: PanicStrategy = (PanicStrategy::Unwind, parse_panic_strategy, [TRACKED],
2550        "panic strategy for panics in drops"),
2551    parse_crate_root_only: bool = (false, parse_bool, [UNTRACKED],
2552        "parse the crate root file only; do not parse other files, compile, assemble, or link \
2553        (default: no)"),
2554    patchable_function_entry: PatchableFunctionEntry = (PatchableFunctionEntry::default(), parse_patchable_function_entry, [TRACKED],
2555        "nop padding at function entry"),
2556    plt: Option<bool> = (None, parse_opt_bool, [TRACKED],
2557        "whether to use the PLT when calling into shared libraries;
2558        only has effect for PIC code on systems with ELF binaries
2559        (default: PLT is disabled if full relro is enabled on x86_64)"),
2560    polonius: Polonius = (Polonius::default(), parse_polonius, [TRACKED],
2561        "enable polonius-based borrow-checker (default: no)"),
2562    pre_link_arg: (/* redirected to pre_link_args */) = ((), parse_string_push, [UNTRACKED],
2563        "a single extra argument to prepend the linker invocation (can be used several times)"),
2564    pre_link_args: Vec<String> = (Vec::new(), parse_list, [UNTRACKED],
2565        "extra arguments to prepend to the linker invocation (space separated)"),
2566    precise_enum_drop_elaboration: bool = (true, parse_bool, [TRACKED],
2567        "use a more precise version of drop elaboration for matches on enums (default: yes). \
2568        This results in better codegen, but has caused miscompilations on some tier 2 platforms. \
2569        See #77382 and #74551."),
2570    #[rustc_lint_opt_deny_field_access("use `Session::print_codegen_stats` instead of this field")]
2571    print_codegen_stats: bool = (false, parse_bool, [UNTRACKED],
2572        "print codegen statistics (default: no)"),
2573    print_llvm_passes: bool = (false, parse_bool, [UNTRACKED],
2574        "print the LLVM optimization passes being run (default: no)"),
2575    print_mono_items: bool = (false, parse_bool, [UNTRACKED],
2576        "print the result of the monomorphization collection pass (default: no)"),
2577    print_type_sizes: bool = (false, parse_bool, [UNTRACKED],
2578        "print layout information for each type encountered (default: no)"),
2579    proc_macro_backtrace: bool = (false, parse_bool, [UNTRACKED],
2580         "show backtraces for panics during proc-macro execution (default: no)"),
2581    proc_macro_execution_strategy: ProcMacroExecutionStrategy = (ProcMacroExecutionStrategy::SameThread,
2582        parse_proc_macro_execution_strategy, [UNTRACKED],
2583        "how to run proc-macro code (default: same-thread)"),
2584    profile_closures: bool = (false, parse_no_value, [UNTRACKED],
2585        "profile size of closures"),
2586    profile_sample_use: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
2587        "use the given `.prof` file for sampled profile-guided optimization (also known as AutoFDO)"),
2588    profiler_runtime: String = (String::from("profiler_builtins"), parse_string, [TRACKED],
2589        "name of the profiler runtime crate to automatically inject (default: `profiler_builtins`)"),
2590    query_dep_graph: bool = (false, parse_bool, [UNTRACKED],
2591        "enable queries of the dependency graph for regression testing (default: no)"),
2592    randomize_layout: bool = (false, parse_bool, [TRACKED],
2593        "randomize the layout of types (default: no)"),
2594    reg_struct_return: bool = (false, parse_bool, [TRACKED TARGET_MODIFIER],
2595        "On x86-32 targets, it overrides the default ABI to return small structs in registers.
2596        It is UNSOUND to link together crates that use different values for this flag!"),
2597    regparm: Option<u32> = (None, parse_opt_number, [TRACKED TARGET_MODIFIER],
2598        "On x86-32 targets, setting this to N causes the compiler to pass N arguments \
2599        in registers EAX, EDX, and ECX instead of on the stack for\
2600        \"C\", \"cdecl\", and \"stdcall\" fn.\
2601        It is UNSOUND to link together crates that use different values for this flag!"),
2602    relax_elf_relocations: Option<bool> = (None, parse_opt_bool, [TRACKED],
2603        "whether ELF relocations can be relaxed"),
2604    remap_cwd_prefix: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
2605        "remap paths under the current working directory to this path prefix"),
2606    remap_path_scope: RemapPathScopeComponents = (RemapPathScopeComponents::all(), parse_remap_path_scope, [TRACKED],
2607        "remap path scope (default: all)"),
2608    remark_dir: Option<PathBuf> = (None, parse_opt_pathbuf, [UNTRACKED],
2609        "directory into which to write optimization remarks (if not specified, they will be \
2610written to standard error output)"),
2611    retpoline: bool = (false, parse_bool, [TRACKED TARGET_MODIFIER],
2612        "enables retpoline-indirect-branches and retpoline-indirect-calls target features (default: no)"),
2613    retpoline_external_thunk: bool = (false, parse_bool, [TRACKED TARGET_MODIFIER],
2614        "enables retpoline-external-thunk, retpoline-indirect-branches and retpoline-indirect-calls \
2615        target features (default: no)"),
2616    #[rustc_lint_opt_deny_field_access("use `Session::sanitizers()` instead of this field")]
2617    sanitizer: SanitizerSet = (SanitizerSet::empty(), parse_sanitizers, [TRACKED TARGET_MODIFIER],
2618        "use a sanitizer"),
2619    sanitizer_cfi_canonical_jump_tables: Option<bool> = (Some(true), parse_opt_bool, [TRACKED],
2620        "enable canonical jump tables (default: yes)"),
2621    sanitizer_cfi_generalize_pointers: Option<bool> = (None, parse_opt_bool, [TRACKED],
2622        "enable generalizing pointer types (default: no)"),
2623    sanitizer_cfi_normalize_integers: Option<bool> = (None, parse_opt_bool, [TRACKED TARGET_MODIFIER],
2624        "enable normalizing integer types (default: no)"),
2625    sanitizer_dataflow_abilist: Vec<String> = (Vec::new(), parse_comma_list, [TRACKED],
2626        "additional ABI list files that control how shadow parameters are passed (comma separated)"),
2627    sanitizer_kcfi_arity: Option<bool> = (None, parse_opt_bool, [TRACKED],
2628        "enable KCFI arity indicator (default: no)"),
2629    sanitizer_memory_track_origins: usize = (0, parse_sanitizer_memory_track_origins, [TRACKED],
2630        "enable origins tracking in MemorySanitizer"),
2631    sanitizer_recover: SanitizerSet = (SanitizerSet::empty(), parse_sanitizers, [TRACKED],
2632        "enable recovery for selected sanitizers"),
2633    saturating_float_casts: Option<bool> = (None, parse_opt_bool, [TRACKED],
2634        "make float->int casts UB-free: numbers outside the integer type's range are clipped to \
2635        the max/min integer respectively, and NaN is mapped to 0 (default: yes)"),
2636    self_profile: SwitchWithOptPath = (SwitchWithOptPath::Disabled,
2637        parse_switch_with_opt_path, [UNTRACKED],
2638        "run the self profiler and output the raw event data"),
2639    self_profile_counter: String = ("wall-time".to_string(), parse_string, [UNTRACKED],
2640        "counter used by the self profiler (default: `wall-time`), one of:
2641        `wall-time` (monotonic clock, i.e. `std::time::Instant`)
2642        `instructions:u` (retired instructions, userspace-only)
2643        `instructions-minus-irqs:u` (subtracting hardware interrupt counts for extra accuracy)"
2644    ),
2645    /// keep this in sync with the event filter names in librustc_data_structures/profiling.rs
2646    self_profile_events: Option<Vec<String>> = (None, parse_opt_comma_list, [UNTRACKED],
2647        "specify the events recorded by the self profiler;
2648        for example: `-Z self-profile-events=default,query-keys`
2649        all options: none, all, default, generic-activity, query-provider, query-cache-hit
2650                     query-blocked, incr-cache-load, incr-result-hashing, query-keys, function-args, args, llvm, artifact-sizes"),
2651    share_generics: Option<bool> = (None, parse_opt_bool, [TRACKED],
2652        "make the current crate share its generic instantiations"),
2653    shell_argfiles: bool = (false, parse_bool, [UNTRACKED],
2654        "allow argument files to be specified with POSIX \"shell-style\" argument quoting"),
2655    simulate_remapped_rust_src_base: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
2656        "simulate the effect of remap-debuginfo = true at bootstrapping by remapping path \
2657        to rust's source base directory. only meant for testing purposes"),
2658    small_data_threshold: Option<usize> = (None, parse_opt_number, [TRACKED],
2659        "Set the threshold for objects to be stored in a \"small data\" section"),
2660    span_debug: bool = (false, parse_bool, [UNTRACKED],
2661        "forward proc_macro::Span's `Debug` impl to `Span`"),
2662    /// o/w tests have closure@path
2663    span_free_formats: bool = (false, parse_bool, [UNTRACKED],
2664        "exclude spans when debug-printing compiler state (default: no)"),
2665    split_dwarf_inlining: bool = (false, parse_bool, [TRACKED],
2666        "provide minimal debug info in the object/executable to facilitate online \
2667         symbolication/stack traces in the absence of .dwo/.dwp files when using Split DWARF"),
2668    split_dwarf_kind: SplitDwarfKind = (SplitDwarfKind::Split, parse_split_dwarf_kind, [TRACKED],
2669        "split dwarf variant (only if -Csplit-debuginfo is enabled and on relevant platform)
2670        (default: `split`)
2671
2672        `split`: sections which do not require relocation are written into a DWARF object (`.dwo`)
2673                 file which is ignored by the linker
2674        `single`: sections which do not require relocation are written into object file but ignored
2675                  by the linker"),
2676    split_dwarf_out_dir : Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
2677        "location for writing split DWARF objects (`.dwo`) if enabled"),
2678    split_lto_unit: Option<bool> = (None, parse_opt_bool, [TRACKED],
2679        "enable LTO unit splitting (default: no)"),
2680    src_hash_algorithm: Option<SourceFileHashAlgorithm> = (None, parse_src_file_hash, [TRACKED],
2681        "hash algorithm of source files in debug info (`md5`, `sha1`, or `sha256`)"),
2682    #[rustc_lint_opt_deny_field_access("use `Session::stack_protector` instead of this field")]
2683    stack_protector: StackProtector = (StackProtector::None, parse_stack_protector, [TRACKED],
2684        "control stack smash protection strategy (`rustc --print stack-protector-strategies` for details)"),
2685    staticlib_allow_rdylib_deps: bool = (false, parse_bool, [TRACKED],
2686        "allow staticlibs to have rust dylib dependencies"),
2687    staticlib_prefer_dynamic: bool = (false, parse_bool, [TRACKED],
2688        "prefer dynamic linking to static linking for staticlibs (default: no)"),
2689    strict_init_checks: bool = (false, parse_bool, [TRACKED],
2690        "control if mem::uninitialized and mem::zeroed panic on more UB"),
2691    #[rustc_lint_opt_deny_field_access("use `Session::teach` instead of this field")]
2692    teach: bool = (false, parse_bool, [TRACKED],
2693        "show extended diagnostic help (default: no)"),
2694    temps_dir: Option<String> = (None, parse_opt_string, [UNTRACKED],
2695        "the directory the intermediate files are written to"),
2696    terminal_urls: TerminalUrl = (TerminalUrl::No, parse_terminal_url, [UNTRACKED],
2697        "use the OSC 8 hyperlink terminal specification to print hyperlinks in the compiler output"),
2698    #[rustc_lint_opt_deny_field_access("use `Session::lto` instead of this field")]
2699    thinlto: Option<bool> = (None, parse_opt_bool, [TRACKED],
2700        "enable ThinLTO when possible"),
2701    /// We default to 1 here since we want to behave like
2702    /// a sequential compiler for now. This'll likely be adjusted
2703    /// in the future. Note that -Zthreads=0 is the way to get
2704    /// the num_cpus behavior.
2705    #[rustc_lint_opt_deny_field_access("use `Session::threads` instead of this field")]
2706    threads: usize = (1, parse_threads, [UNTRACKED],
2707        "use a thread pool with N threads"),
2708    time_llvm_passes: bool = (false, parse_bool, [UNTRACKED],
2709        "measure time of each LLVM pass (default: no)"),
2710    time_passes: bool = (false, parse_bool, [UNTRACKED],
2711        "measure time of each rustc pass (default: no)"),
2712    time_passes_format: TimePassesFormat = (TimePassesFormat::Text, parse_time_passes_format, [UNTRACKED],
2713        "the format to use for -Z time-passes (`text` (default) or `json`)"),
2714    tiny_const_eval_limit: bool = (false, parse_bool, [TRACKED],
2715        "sets a tiny, non-configurable limit for const eval; useful for compiler tests"),
2716    #[rustc_lint_opt_deny_field_access("use `Session::tls_model` instead of this field")]
2717    tls_model: Option<TlsModel> = (None, parse_tls_model, [TRACKED],
2718        "choose the TLS model to use (`rustc --print tls-models` for details)"),
2719    trace_macros: bool = (false, parse_bool, [UNTRACKED],
2720        "for every macro invocation, print its name and arguments (default: no)"),
2721    track_diagnostics: bool = (false, parse_bool, [UNTRACKED],
2722        "tracks where in rustc a diagnostic was emitted"),
2723    // Diagnostics are considered side-effects of a query (see `QuerySideEffect`) and are saved
2724    // alongside query results and changes to translation options can affect diagnostics - so
2725    // translation options should be tracked.
2726    translate_additional_ftl: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
2727        "additional fluent translation to preferentially use (for testing translation)"),
2728    translate_directionality_markers: bool = (false, parse_bool, [TRACKED],
2729        "emit directionality isolation markers in translated diagnostics"),
2730    translate_lang: Option<LanguageIdentifier> = (None, parse_opt_langid, [TRACKED],
2731        "language identifier for diagnostic output"),
2732    translate_remapped_path_to_local_path: bool = (true, parse_bool, [TRACKED],
2733        "translate remapped paths into local paths when possible (default: yes)"),
2734    trap_unreachable: Option<bool> = (None, parse_opt_bool, [TRACKED],
2735        "generate trap instructions for unreachable intrinsics (default: use target setting, usually yes)"),
2736    treat_err_as_bug: Option<NonZero<usize>> = (None, parse_treat_err_as_bug, [TRACKED],
2737        "treat the `val`th error that occurs as bug (default if not specified: 0 - don't treat errors as bugs. \
2738        default if specified without a value: 1 - treat the first error as bug)"),
2739    trim_diagnostic_paths: bool = (true, parse_bool, [UNTRACKED],
2740        "in diagnostics, use heuristics to shorten paths referring to items"),
2741    tune_cpu: Option<String> = (None, parse_opt_string, [TRACKED],
2742        "select processor to schedule for (`rustc --print target-cpus` for details)"),
2743    #[rustc_lint_opt_deny_field_access("use `TyCtxt::use_typing_mode_borrowck` instead of this field")]
2744    typing_mode_borrowck: bool = (false, parse_bool, [TRACKED],
2745        "enable `TypingMode::Borrowck`, changing the way opaque types are handled during MIR borrowck"),
2746    #[rustc_lint_opt_deny_field_access("use `Session::ub_checks` instead of this field")]
2747    ub_checks: Option<bool> = (None, parse_opt_bool, [TRACKED],
2748        "emit runtime checks for Undefined Behavior (default: -Cdebug-assertions)"),
2749    ui_testing: bool = (false, parse_bool, [UNTRACKED],
2750        "emit compiler diagnostics in a form suitable for UI testing (default: no)"),
2751    uninit_const_chunk_threshold: usize = (16, parse_number, [TRACKED],
2752        "allow generating const initializers with mixed init/uninit chunks, \
2753        and set the maximum number of chunks for which this is allowed (default: 16)"),
2754    unleash_the_miri_inside_of_you: bool = (false, parse_bool, [TRACKED],
2755        "take the brakes off const evaluation. NOTE: this is unsound (default: no)"),
2756    unpretty: Option<String> = (None, parse_unpretty, [UNTRACKED],
2757        "present the input source, unstable (and less-pretty) variants;
2758        `normal`, `identified`,
2759        `expanded`, `expanded,identified`,
2760        `expanded,hygiene` (with internal representations),
2761        `ast-tree` (raw AST before expansion),
2762        `ast-tree,expanded` (raw AST after expansion),
2763        `hir` (the HIR), `hir,identified`,
2764        `hir,typed` (HIR with types for each node),
2765        `hir-tree` (dump the raw HIR),
2766        `thir-tree`, `thir-flat`,
2767        `mir` (the MIR), or `mir-cfg` (graphviz formatted MIR)"),
2768    unsound_mir_opts: bool = (false, parse_bool, [TRACKED],
2769        "enable unsound and buggy MIR optimizations (default: no)"),
2770    /// This name is kind of confusing: Most unstable options enable something themselves, while
2771    /// this just allows "normal" options to be feature-gated.
2772    ///
2773    /// The main check for `-Zunstable-options` takes place separately from the
2774    /// usual parsing of `-Z` options (see [`crate::config::nightly_options`]),
2775    /// so this boolean value is mostly used for enabling unstable _values_ of
2776    /// stable options. That separate check doesn't handle boolean values, so
2777    /// to avoid an inconsistent state we also forbid them here.
2778    #[rustc_lint_opt_deny_field_access("use `Session::unstable_options` instead of this field")]
2779    unstable_options: bool = (false, parse_no_value, [UNTRACKED],
2780        "adds unstable command line options to rustc interface (default: no)"),
2781    use_ctors_section: Option<bool> = (None, parse_opt_bool, [TRACKED],
2782        "use legacy .ctors section for initializers rather than .init_array"),
2783    use_sync_unwind: Option<bool> = (None, parse_opt_bool, [TRACKED],
2784        "Generate sync unwind tables instead of async unwind tables (default: no)"),
2785    validate_mir: bool = (false, parse_bool, [UNTRACKED],
2786        "validate MIR after each transformation"),
2787    verbose_asm: bool = (false, parse_bool, [TRACKED],
2788        "add descriptive comments from LLVM to the assembly (may change behavior) (default: no)"),
2789    #[rustc_lint_opt_deny_field_access("use `Session::verbose_internals` instead of this field")]
2790    verbose_internals: bool = (false, parse_bool, [TRACKED_NO_CRATE_HASH],
2791        "in general, enable more debug printouts (default: no)"),
2792    #[rustc_lint_opt_deny_field_access("use `Session::verify_llvm_ir` instead of this field")]
2793    verify_llvm_ir: bool = (false, parse_bool, [TRACKED],
2794        "verify LLVM IR (default: no)"),
2795    virtual_function_elimination: bool = (false, parse_bool, [TRACKED],
2796        "enables dead virtual function elimination optimization. \
2797        Requires `-Clto[=[fat,yes]]`"),
2798    wasi_exec_model: Option<WasiExecModel> = (None, parse_wasi_exec_model, [TRACKED],
2799        "whether to build a wasi command or reactor"),
2800    // This option only still exists to provide a more gradual transition path for people who need
2801    // the spec-complaint C ABI to be used.
2802    // FIXME remove this after a couple releases
2803    wasm_c_abi: () = ((), parse_wasm_c_abi, [TRACKED],
2804        "use spec-compliant C ABI for `wasm32-unknown-unknown` (deprecated, always enabled)"),
2805    write_long_types_to_disk: bool = (true, parse_bool, [UNTRACKED],
2806        "whether long type names should be written to files instead of being printed in errors"),
2807    // tidy-alphabetical-end
2808
2809    // If you add a new option, please update:
2810    // - compiler/rustc_interface/src/tests.rs
2811    // - src/doc/unstable-book/src/compiler-flags
2812}