1 use crate::config::*;
2 
3 use crate::early_error;
4 use crate::lint;
5 use crate::search_paths::SearchPath;
6 use crate::utils::NativeLib;
7 
8 use rustc_target::spec::{CodeModel, LinkerFlavor, MergeFunctions, PanicStrategy, SanitizerSet};
9 use rustc_target::spec::{RelocModel, RelroLevel, SplitDebuginfo, TargetTriple, TlsModel};
10 
11 use rustc_feature::UnstableFeatures;
12 use rustc_span::edition::Edition;
13 use rustc_span::SourceFileHashAlgorithm;
14 
15 use std::collections::BTreeMap;
16 
17 use std::collections::hash_map::DefaultHasher;
18 use std::hash::Hasher;
19 use std::num::NonZeroUsize;
20 use std::path::PathBuf;
21 use std::str;
22 
23 macro_rules! insert {
24     ($opt_name:ident, $opt_expr:expr, $sub_hashes:expr) => {
25         if $sub_hashes
26             .insert(stringify!($opt_name), $opt_expr as &dyn dep_tracking::DepTrackingHash)
27             .is_some()
28         {
29             panic!("duplicate key in CLI DepTrackingHash: {}", stringify!($opt_name))
30         }
31     };
32 }
33 
34 macro_rules! hash_opt {
35     ($opt_name:ident, $opt_expr:expr, $sub_hashes:expr, $_for_crate_hash: ident, [UNTRACKED]) => {{}};
36     ($opt_name:ident, $opt_expr:expr, $sub_hashes:expr, $_for_crate_hash: ident, [TRACKED]) => {{ insert!($opt_name, $opt_expr, $sub_hashes) }};
37     ($opt_name:ident, $opt_expr:expr, $sub_hashes:expr, $for_crate_hash: ident, [TRACKED_NO_CRATE_HASH]) => {{
38         if !$for_crate_hash {
39             insert!($opt_name, $opt_expr, $sub_hashes)
40         }
41     }};
42     ($opt_name:ident, $opt_expr:expr, $sub_hashes:expr, $_for_crate_hash: ident, [SUBSTRUCT]) => {{}};
43 }
44 
45 macro_rules! hash_substruct {
46     ($opt_name:ident, $opt_expr:expr, $error_format:expr, $for_crate_hash:expr, $hasher:expr, [UNTRACKED]) => {{}};
47     ($opt_name:ident, $opt_expr:expr, $error_format:expr, $for_crate_hash:expr, $hasher:expr, [TRACKED]) => {{}};
48     ($opt_name:ident, $opt_expr:expr, $error_format:expr, $for_crate_hash:expr, $hasher:expr, [TRACKED_NO_CRATE_HASH]) => {{}};
49     ($opt_name:ident, $opt_expr:expr, $error_format:expr, $for_crate_hash:expr, $hasher:expr, [SUBSTRUCT]) => {
50         use crate::config::dep_tracking::DepTrackingHash;
51         $opt_expr.dep_tracking_hash($for_crate_hash, $error_format).hash($hasher, $error_format);
52     };
53 }
54 
55 macro_rules! top_level_options {
56     ( $( #[$top_level_attr:meta] )* pub struct Options { $(
57         $( #[$attr:meta] )*
58         $opt:ident : $t:ty [$dep_tracking_marker:ident],
59     )* } ) => (
60         #[derive(Clone)]
61         $( #[$top_level_attr] )*
62         pub struct Options {
63             $(
64                 $( #[$attr] )*
65                 pub $opt: $t
66             ),*
67         }
68 
69         impl Options {
70             pub fn dep_tracking_hash(&self, for_crate_hash: bool) -> u64 {
71                 let mut sub_hashes = BTreeMap::new();
72                 $({
73                     hash_opt!($opt,
74                                 &self.$opt,
75                                 &mut sub_hashes,
76                                 for_crate_hash,
77                                 [$dep_tracking_marker]);
78                 })*
79                 let mut hasher = DefaultHasher::new();
80                 dep_tracking::stable_hash(sub_hashes,
81                                           &mut hasher,
82                                           self.error_format);
83                 $({
84                     hash_substruct!($opt,
85                         &self.$opt,
86                         self.error_format,
87                         for_crate_hash,
88                         &mut hasher,
89                         [$dep_tracking_marker]);
90                 })*
91                 hasher.finish()
92             }
93         }
94     );
95 }
96 
97 top_level_options!(
98     /// The top-level command-line options struct.
99     ///
100     /// For each option, one has to specify how it behaves with regard to the
101     /// dependency tracking system of incremental compilation. This is done via the
102     /// square-bracketed directive after the field type. The options are:
103     ///
104     /// - `[TRACKED]`
105     /// A change in the given field will cause the compiler to completely clear the
106     /// incremental compilation cache before proceeding.
107     ///
108     /// - `[TRACKED_NO_CRATE_HASH]`
109     /// Same as `[TRACKED]`, but will not affect the crate hash. This is useful for options that only
110     /// affect the incremental cache.
111     ///
112     /// - `[UNTRACKED]`
113     /// Incremental compilation is not influenced by this option.
114     ///
115     /// - `[SUBSTRUCT]`
116     /// Second-level sub-structs containing more options.
117     ///
118     /// If you add a new option to this struct or one of the sub-structs like
119     /// `CodegenOptions`, think about how it influences incremental compilation. If in
120     /// doubt, specify `[TRACKED]`, which is always "correct" but might lead to
121     /// unnecessary re-compilation.
122     pub struct Options {
123         /// The crate config requested for the session, which may be combined
124         /// with additional crate configurations during the compile process.
125         crate_types: Vec<CrateType> [TRACKED],
126         optimize: OptLevel [TRACKED],
127         /// Include the `debug_assertions` flag in dependency tracking, since it
128         /// can influence whether overflow checks are done or not.
129         debug_assertions: bool [TRACKED],
130         debuginfo: DebugInfo [TRACKED],
131         lint_opts: Vec<(String, lint::Level)> [TRACKED],
132         lint_cap: Option<lint::Level> [TRACKED],
133         describe_lints: bool [UNTRACKED],
134         output_types: OutputTypes [TRACKED],
135         search_paths: Vec<SearchPath> [UNTRACKED],
136         libs: Vec<NativeLib> [TRACKED],
137         maybe_sysroot: Option<PathBuf> [UNTRACKED],
138 
139         target_triple: TargetTriple [TRACKED],
140 
141         test: bool [TRACKED],
142         error_format: ErrorOutputType [UNTRACKED],
143 
144         /// If `Some`, enable incremental compilation, using the given
145         /// directory to store intermediate results.
146         incremental: Option<PathBuf> [UNTRACKED],
147 
148         debugging_opts: DebuggingOptions [SUBSTRUCT],
149         prints: Vec<PrintRequest> [UNTRACKED],
150         /// Determines which borrow checker(s) to run. This is the parsed, sanitized
151         /// version of `debugging_opts.borrowck`, which is just a plain string.
152         borrowck_mode: BorrowckMode [UNTRACKED],
153         cg: CodegenOptions [SUBSTRUCT],
154         externs: Externs [UNTRACKED],
155         extern_dep_specs: ExternDepSpecs [UNTRACKED],
156         crate_name: Option<String> [TRACKED],
157         /// An optional name to use as the crate for std during std injection,
158         /// written `extern crate name as std`. Defaults to `std`. Used by
159         /// out-of-tree drivers.
160         alt_std_name: Option<String> [TRACKED],
161         /// Indicates how the compiler should treat unstable features.
162         unstable_features: UnstableFeatures [TRACKED],
163 
164         /// Indicates whether this run of the compiler is actually rustdoc. This
165         /// is currently just a hack and will be removed eventually, so please
166         /// try to not rely on this too much.
167         actually_rustdoc: bool [TRACKED],
168 
169         /// Control path trimming.
170         trimmed_def_paths: TrimmedDefPaths [TRACKED],
171 
172         /// Specifications of codegen units / ThinLTO which are forced as a
173         /// result of parsing command line options. These are not necessarily
174         /// what rustc was invoked with, but massaged a bit to agree with
175         /// commands like `--emit llvm-ir` which they're often incompatible with
176         /// if we otherwise use the defaults of rustc.
177         cli_forced_codegen_units: Option<usize> [UNTRACKED],
178         cli_forced_thinlto_off: bool [UNTRACKED],
179 
180         /// Remap source path prefixes in all output (messages, object files, debug, etc.).
181         remap_path_prefix: Vec<(PathBuf, PathBuf)> [TRACKED_NO_CRATE_HASH],
182         /// Base directory containing the `src/` for the Rust standard library, and
183         /// potentially `rustc` as well, if we can can find it. Right now it's always
184         /// `$sysroot/lib/rustlib/src/rust` (i.e. the `rustup` `rust-src` component).
185         ///
186         /// This directory is what the virtual `/rustc/$hash` is translated back to,
187         /// if Rust was built with path remapping to `/rustc/$hash` enabled
188         /// (the `rust.remap-debuginfo` option in `config.toml`).
189         real_rust_source_base_dir: Option<PathBuf> [TRACKED_NO_CRATE_HASH],
190 
191         edition: Edition [TRACKED],
192 
193         /// `true` if we're emitting JSON blobs about each artifact produced
194         /// by the compiler.
195         json_artifact_notifications: bool [TRACKED],
196 
197         /// `true` if we're emitting a JSON blob containing the unused externs
198         json_unused_externs: bool [UNTRACKED],
199 
200         pretty: Option<PpMode> [UNTRACKED],
201     }
202 );
203 
204 /// Defines all `CodegenOptions`/`DebuggingOptions` fields and parsers all at once. The goal of this
205 /// macro is to define an interface that can be programmatically used by the option parser
206 /// to initialize the struct without hardcoding field names all over the place.
207 ///
208 /// The goal is to invoke this macro once with the correct fields, and then this macro generates all
209 /// necessary code. The main gotcha of this macro is the `cgsetters` module which is a bunch of
210 /// generated code to parse an option into its respective field in the struct. There are a few
211 /// hand-written parsers for parsing specific types of values in this module.
212 macro_rules! options {
213     ($struct_name:ident, $stat:ident, $prefix:expr, $outputname:expr,
214      $($( #[$attr:meta] )* $opt:ident : $t:ty = (
215         $init:expr,
216         $parse:ident,
217         [$dep_tracking_marker:ident],
218         $desc:expr)
219      ),* ,) =>
220 (
221     #[derive(Clone)]
222     pub struct $struct_name { $(pub $opt: $t),* }
223 
224     impl Default for $struct_name {
225         fn default() -> $struct_name {
226             $struct_name { $( $( #[$attr] )* $opt: $init),* }
227         }
228     }
229 
230     impl $struct_name {
231         pub fn build(
232             matches: &getopts::Matches,
233             error_format: ErrorOutputType,
234         ) -> $struct_name {
235             build_options(matches, $stat, $prefix, $outputname, error_format)
236         }
237 
238         fn dep_tracking_hash(&self, _for_crate_hash: bool, error_format: ErrorOutputType) -> u64 {
239             let mut sub_hashes = BTreeMap::new();
240             $({
241                 hash_opt!($opt,
242                             &self.$opt,
243                             &mut sub_hashes,
244                             _for_crate_hash,
245                             [$dep_tracking_marker]);
246             })*
247             let mut hasher = DefaultHasher::new();
248             dep_tracking::stable_hash(sub_hashes,
249                                         &mut hasher,
250                                         error_format);
251             hasher.finish()
252         }
253     }
254 
255     pub const $stat: OptionDescrs<$struct_name> =
256         &[ $( (stringify!($opt), $opt, desc::$parse, $desc) ),* ];
257 
258     $(
259         fn $opt(cg: &mut $struct_name, v: Option<&str>) -> bool {
260             parse::$parse(&mut redirect_field!(cg.$opt), v)
261         }
262     )*
263 
264 ) }
265 
266 // Sometimes different options need to build a common structure.
267 // That structure can be kept in one of the options' fields, the others become dummy.
268 macro_rules! redirect_field {
269     ($cg:ident.link_arg) => {
270         $cg.link_args
271     };
272     ($cg:ident.pre_link_arg) => {
273         $cg.pre_link_args
274     };
275     ($cg:ident.$field:ident) => {
276         $cg.$field
277     };
278 }
279 
280 type OptionSetter<O> = fn(&mut O, v: Option<&str>) -> bool;
281 type OptionDescrs<O> = &'static [(&'static str, OptionSetter<O>, &'static str, &'static str)];
282 
build_options<O: Default>( matches: &getopts::Matches, descrs: OptionDescrs<O>, prefix: &str, outputname: &str, error_format: ErrorOutputType, ) -> O283 fn build_options<O: Default>(
284     matches: &getopts::Matches,
285     descrs: OptionDescrs<O>,
286     prefix: &str,
287     outputname: &str,
288     error_format: ErrorOutputType,
289 ) -> O {
290     let mut op = O::default();
291     for option in matches.opt_strs(prefix) {
292         let (key, value) = match option.split_once('=') {
293             None => (option, None),
294             Some((k, v)) => (k.to_string(), Some(v)),
295         };
296 
297         let option_to_lookup = key.replace("-", "_");
298         match descrs.iter().find(|(name, ..)| *name == option_to_lookup) {
299             Some((_, setter, type_desc, _)) => {
300                 if !setter(&mut op, value) {
301                     match value {
302                         None => early_error(
303                             error_format,
304                             &format!(
305                                 "{0} option `{1}` requires {2} ({3} {1}=<value>)",
306                                 outputname, key, type_desc, prefix
307                             ),
308                         ),
309                         Some(value) => early_error(
310                             error_format,
311                             &format!(
312                                 "incorrect value `{}` for {} option `{}` - {} was expected",
313                                 value, outputname, key, type_desc
314                             ),
315                         ),
316                     }
317                 }
318             }
319             None => early_error(error_format, &format!("unknown {} option: `{}`", outputname, key)),
320         }
321     }
322     return op;
323 }
324 
325 #[allow(non_upper_case_globals)]
326 mod desc {
327     pub const parse_no_flag: &str = "no value";
328     pub const parse_bool: &str = "one of: `y`, `yes`, `on`, `n`, `no`, or `off`";
329     pub const parse_opt_bool: &str = parse_bool;
330     pub const parse_string: &str = "a string";
331     pub const parse_opt_string: &str = parse_string;
332     pub const parse_string_push: &str = parse_string;
333     pub const parse_opt_pathbuf: &str = "a path";
334     pub const parse_list: &str = "a space-separated list of strings";
335     pub const parse_opt_comma_list: &str = "a comma-separated list of strings";
336     pub const parse_number: &str = "a number";
337     pub const parse_opt_number: &str = parse_number;
338     pub const parse_threads: &str = parse_number;
339     pub const parse_passes: &str = "a space-separated list of passes, or `all`";
340     pub const parse_panic_strategy: &str = "either `unwind` or `abort`";
341     pub const parse_relro_level: &str = "one of: `full`, `partial`, or `off`";
342     pub const parse_sanitizers: &str =
343         "comma separated list of sanitizers: `address`, `hwaddress`, `leak`, `memory` or `thread`";
344     pub const parse_sanitizer_memory_track_origins: &str = "0, 1, or 2";
345     pub const parse_cfguard: &str =
346         "either a boolean (`yes`, `no`, `on`, `off`, etc), `checks`, or `nochecks`";
347     pub const parse_strip: &str = "either `none`, `debuginfo`, or `symbols`";
348     pub const parse_linker_flavor: &str = ::rustc_target::spec::LinkerFlavor::one_of();
349     pub const parse_optimization_fuel: &str = "crate=integer";
350     pub const parse_mir_spanview: &str = "`statement` (default), `terminator`, or `block`";
351     pub const parse_instrument_coverage: &str =
352         "`all` (default), `except-unused-generics`, `except-unused-functions`, or `off`";
353     pub const parse_unpretty: &str = "`string` or `string=string`";
354     pub const parse_treat_err_as_bug: &str = "either no value or a number bigger than 0";
355     pub const parse_lto: &str =
356         "either a boolean (`yes`, `no`, `on`, `off`, etc), `thin`, `fat`, or omitted";
357     pub const parse_linker_plugin_lto: &str =
358         "either a boolean (`yes`, `no`, `on`, `off`, etc), or the path to the linker plugin";
359     pub const parse_switch_with_opt_path: &str =
360         "an optional path to the profiling data output directory";
361     pub const parse_merge_functions: &str = "one of: `disabled`, `trampolines`, or `aliases`";
362     pub const parse_symbol_mangling_version: &str = "either `legacy` or `v0` (RFC 2603)";
363     pub const parse_src_file_hash: &str = "either `md5` or `sha1`";
364     pub const parse_relocation_model: &str =
365         "one of supported relocation models (`rustc --print relocation-models`)";
366     pub const parse_code_model: &str = "one of supported code models (`rustc --print code-models`)";
367     pub const parse_tls_model: &str = "one of supported TLS models (`rustc --print tls-models`)";
368     pub const parse_target_feature: &str = parse_string;
369     pub const parse_wasi_exec_model: &str = "either `command` or `reactor`";
370     pub const parse_split_debuginfo: &str =
371         "one of supported split-debuginfo modes (`off` or `dsymutil`)";
372 }
373 
374 mod parse {
375     crate use super::*;
376     use std::str::FromStr;
377 
378     /// This is for boolean options that don't take a value and start with
379     /// `no-`. This style of option is deprecated.
parse_no_flag(slot: &mut bool, v: Option<&str>) -> bool380     crate fn parse_no_flag(slot: &mut bool, v: Option<&str>) -> bool {
381         match v {
382             None => {
383                 *slot = true;
384                 true
385             }
386             Some(_) => false,
387         }
388     }
389 
390     /// Use this for any boolean option that has a static default.
parse_bool(slot: &mut bool, v: Option<&str>) -> bool391     crate fn parse_bool(slot: &mut bool, v: Option<&str>) -> bool {
392         match v {
393             Some("y") | Some("yes") | Some("on") | None => {
394                 *slot = true;
395                 true
396             }
397             Some("n") | Some("no") | Some("off") => {
398                 *slot = false;
399                 true
400             }
401             _ => false,
402         }
403     }
404 
405     /// Use this for any boolean option that lacks a static default. (The
406     /// actions taken when such an option is not specified will depend on
407     /// other factors, such as other options, or target options.)
parse_opt_bool(slot: &mut Option<bool>, v: Option<&str>) -> bool408     crate fn parse_opt_bool(slot: &mut Option<bool>, v: Option<&str>) -> bool {
409         match v {
410             Some("y") | Some("yes") | Some("on") | None => {
411                 *slot = Some(true);
412                 true
413             }
414             Some("n") | Some("no") | Some("off") => {
415                 *slot = Some(false);
416                 true
417             }
418             _ => false,
419         }
420     }
421 
422     /// Use this for any string option that has a static default.
parse_string(slot: &mut String, v: Option<&str>) -> bool423     crate fn parse_string(slot: &mut String, v: Option<&str>) -> bool {
424         match v {
425             Some(s) => {
426                 *slot = s.to_string();
427                 true
428             }
429             None => false,
430         }
431     }
432 
433     /// Use this for any string option that lacks a static default.
parse_opt_string(slot: &mut Option<String>, v: Option<&str>) -> bool434     crate fn parse_opt_string(slot: &mut Option<String>, v: Option<&str>) -> bool {
435         match v {
436             Some(s) => {
437                 *slot = Some(s.to_string());
438                 true
439             }
440             None => false,
441         }
442     }
443 
parse_opt_pathbuf(slot: &mut Option<PathBuf>, v: Option<&str>) -> bool444     crate fn parse_opt_pathbuf(slot: &mut Option<PathBuf>, v: Option<&str>) -> bool {
445         match v {
446             Some(s) => {
447                 *slot = Some(PathBuf::from(s));
448                 true
449             }
450             None => false,
451         }
452     }
453 
parse_string_push(slot: &mut Vec<String>, v: Option<&str>) -> bool454     crate fn parse_string_push(slot: &mut Vec<String>, v: Option<&str>) -> bool {
455         match v {
456             Some(s) => {
457                 slot.push(s.to_string());
458                 true
459             }
460             None => false,
461         }
462     }
463 
parse_list(slot: &mut Vec<String>, v: Option<&str>) -> bool464     crate fn parse_list(slot: &mut Vec<String>, v: Option<&str>) -> bool {
465         match v {
466             Some(s) => {
467                 slot.extend(s.split_whitespace().map(|s| s.to_string()));
468                 true
469             }
470             None => false,
471         }
472     }
473 
parse_opt_comma_list(slot: &mut Option<Vec<String>>, v: Option<&str>) -> bool474     crate fn parse_opt_comma_list(slot: &mut Option<Vec<String>>, v: Option<&str>) -> bool {
475         match v {
476             Some(s) => {
477                 let mut v: Vec<_> = s.split(',').map(|s| s.to_string()).collect();
478                 v.sort_unstable();
479                 *slot = Some(v);
480                 true
481             }
482             None => false,
483         }
484     }
485 
parse_threads(slot: &mut usize, v: Option<&str>) -> bool486     crate fn parse_threads(slot: &mut usize, v: Option<&str>) -> bool {
487         match v.and_then(|s| s.parse().ok()) {
488             Some(0) => {
489                 *slot = ::num_cpus::get();
490                 true
491             }
492             Some(i) => {
493                 *slot = i;
494                 true
495             }
496             None => false,
497         }
498     }
499 
500     /// Use this for any numeric option that has a static default.
parse_number<T: Copy + FromStr>(slot: &mut T, v: Option<&str>) -> bool501     crate fn parse_number<T: Copy + FromStr>(slot: &mut T, v: Option<&str>) -> bool {
502         match v.and_then(|s| s.parse().ok()) {
503             Some(i) => {
504                 *slot = i;
505                 true
506             }
507             None => false,
508         }
509     }
510 
511     /// Use this for any numeric option that lacks a static default.
parse_opt_number<T: Copy + FromStr>(slot: &mut Option<T>, v: Option<&str>) -> bool512     crate fn parse_opt_number<T: Copy + FromStr>(slot: &mut Option<T>, v: Option<&str>) -> bool {
513         match v {
514             Some(s) => {
515                 *slot = s.parse().ok();
516                 slot.is_some()
517             }
518             None => false,
519         }
520     }
521 
parse_passes(slot: &mut Passes, v: Option<&str>) -> bool522     crate fn parse_passes(slot: &mut Passes, v: Option<&str>) -> bool {
523         match v {
524             Some("all") => {
525                 *slot = Passes::All;
526                 true
527             }
528             v => {
529                 let mut passes = vec![];
530                 if parse_list(&mut passes, v) {
531                     *slot = Passes::Some(passes);
532                     true
533                 } else {
534                     false
535                 }
536             }
537         }
538     }
539 
parse_panic_strategy(slot: &mut Option<PanicStrategy>, v: Option<&str>) -> bool540     crate fn parse_panic_strategy(slot: &mut Option<PanicStrategy>, v: Option<&str>) -> bool {
541         match v {
542             Some("unwind") => *slot = Some(PanicStrategy::Unwind),
543             Some("abort") => *slot = Some(PanicStrategy::Abort),
544             _ => return false,
545         }
546         true
547     }
548 
parse_relro_level(slot: &mut Option<RelroLevel>, v: Option<&str>) -> bool549     crate fn parse_relro_level(slot: &mut Option<RelroLevel>, v: Option<&str>) -> bool {
550         match v {
551             Some(s) => match s.parse::<RelroLevel>() {
552                 Ok(level) => *slot = Some(level),
553                 _ => return false,
554             },
555             _ => return false,
556         }
557         true
558     }
559 
parse_sanitizers(slot: &mut SanitizerSet, v: Option<&str>) -> bool560     crate fn parse_sanitizers(slot: &mut SanitizerSet, v: Option<&str>) -> bool {
561         if let Some(v) = v {
562             for s in v.split(',') {
563                 *slot |= match s {
564                     "address" => SanitizerSet::ADDRESS,
565                     "leak" => SanitizerSet::LEAK,
566                     "memory" => SanitizerSet::MEMORY,
567                     "thread" => SanitizerSet::THREAD,
568                     "hwaddress" => SanitizerSet::HWADDRESS,
569                     _ => return false,
570                 }
571             }
572             true
573         } else {
574             false
575         }
576     }
577 
parse_sanitizer_memory_track_origins(slot: &mut usize, v: Option<&str>) -> bool578     crate fn parse_sanitizer_memory_track_origins(slot: &mut usize, v: Option<&str>) -> bool {
579         match v {
580             Some("2") | None => {
581                 *slot = 2;
582                 true
583             }
584             Some("1") => {
585                 *slot = 1;
586                 true
587             }
588             Some("0") => {
589                 *slot = 0;
590                 true
591             }
592             Some(_) => false,
593         }
594     }
595 
parse_strip(slot: &mut Strip, v: Option<&str>) -> bool596     crate fn parse_strip(slot: &mut Strip, v: Option<&str>) -> bool {
597         match v {
598             Some("none") => *slot = Strip::None,
599             Some("debuginfo") => *slot = Strip::Debuginfo,
600             Some("symbols") => *slot = Strip::Symbols,
601             _ => return false,
602         }
603         true
604     }
605 
parse_cfguard(slot: &mut CFGuard, v: Option<&str>) -> bool606     crate fn parse_cfguard(slot: &mut CFGuard, v: Option<&str>) -> bool {
607         if v.is_some() {
608             let mut bool_arg = None;
609             if parse_opt_bool(&mut bool_arg, v) {
610                 *slot = if bool_arg.unwrap() { CFGuard::Checks } else { CFGuard::Disabled };
611                 return true;
612             }
613         }
614 
615         *slot = match v {
616             None => CFGuard::Checks,
617             Some("checks") => CFGuard::Checks,
618             Some("nochecks") => CFGuard::NoChecks,
619             Some(_) => return false,
620         };
621         true
622     }
623 
parse_linker_flavor(slot: &mut Option<LinkerFlavor>, v: Option<&str>) -> bool624     crate fn parse_linker_flavor(slot: &mut Option<LinkerFlavor>, v: Option<&str>) -> bool {
625         match v.and_then(LinkerFlavor::from_str) {
626             Some(lf) => *slot = Some(lf),
627             _ => return false,
628         }
629         true
630     }
631 
parse_optimization_fuel(slot: &mut Option<(String, u64)>, v: Option<&str>) -> bool632     crate fn parse_optimization_fuel(slot: &mut Option<(String, u64)>, v: Option<&str>) -> bool {
633         match v {
634             None => false,
635             Some(s) => {
636                 let parts = s.split('=').collect::<Vec<_>>();
637                 if parts.len() != 2 {
638                     return false;
639                 }
640                 let crate_name = parts[0].to_string();
641                 let fuel = parts[1].parse::<u64>();
642                 if fuel.is_err() {
643                     return false;
644                 }
645                 *slot = Some((crate_name, fuel.unwrap()));
646                 true
647             }
648         }
649     }
650 
parse_unpretty(slot: &mut Option<String>, v: Option<&str>) -> bool651     crate fn parse_unpretty(slot: &mut Option<String>, v: Option<&str>) -> bool {
652         match v {
653             None => false,
654             Some(s) if s.split('=').count() <= 2 => {
655                 *slot = Some(s.to_string());
656                 true
657             }
658             _ => false,
659         }
660     }
661 
parse_mir_spanview(slot: &mut Option<MirSpanview>, v: Option<&str>) -> bool662     crate fn parse_mir_spanview(slot: &mut Option<MirSpanview>, v: Option<&str>) -> bool {
663         if v.is_some() {
664             let mut bool_arg = None;
665             if parse_opt_bool(&mut bool_arg, v) {
666                 *slot = if bool_arg.unwrap() { Some(MirSpanview::Statement) } else { None };
667                 return true;
668             }
669         }
670 
671         let v = match v {
672             None => {
673                 *slot = Some(MirSpanview::Statement);
674                 return true;
675             }
676             Some(v) => v,
677         };
678 
679         *slot = Some(match v.trim_end_matches("s") {
680             "statement" | "stmt" => MirSpanview::Statement,
681             "terminator" | "term" => MirSpanview::Terminator,
682             "block" | "basicblock" => MirSpanview::Block,
683             _ => return false,
684         });
685         true
686     }
687 
parse_instrument_coverage( slot: &mut Option<InstrumentCoverage>, v: Option<&str>, ) -> bool688     crate fn parse_instrument_coverage(
689         slot: &mut Option<InstrumentCoverage>,
690         v: Option<&str>,
691     ) -> bool {
692         if v.is_some() {
693             let mut bool_arg = None;
694             if parse_opt_bool(&mut bool_arg, v) {
695                 *slot = if bool_arg.unwrap() { Some(InstrumentCoverage::All) } else { None };
696                 return true;
697             }
698         }
699 
700         let v = match v {
701             None => {
702                 *slot = Some(InstrumentCoverage::All);
703                 return true;
704             }
705             Some(v) => v,
706         };
707 
708         *slot = Some(match v {
709             "all" => InstrumentCoverage::All,
710             "except-unused-generics" | "except_unused_generics" => {
711                 InstrumentCoverage::ExceptUnusedGenerics
712             }
713             "except-unused-functions" | "except_unused_functions" => {
714                 InstrumentCoverage::ExceptUnusedFunctions
715             }
716             "off" | "no" | "n" | "false" | "0" => InstrumentCoverage::Off,
717             _ => return false,
718         });
719         true
720     }
721 
parse_treat_err_as_bug(slot: &mut Option<NonZeroUsize>, v: Option<&str>) -> bool722     crate fn parse_treat_err_as_bug(slot: &mut Option<NonZeroUsize>, v: Option<&str>) -> bool {
723         match v {
724             Some(s) => {
725                 *slot = s.parse().ok();
726                 slot.is_some()
727             }
728             None => {
729                 *slot = NonZeroUsize::new(1);
730                 true
731             }
732         }
733     }
734 
parse_lto(slot: &mut LtoCli, v: Option<&str>) -> bool735     crate fn parse_lto(slot: &mut LtoCli, v: Option<&str>) -> bool {
736         if v.is_some() {
737             let mut bool_arg = None;
738             if parse_opt_bool(&mut bool_arg, v) {
739                 *slot = if bool_arg.unwrap() { LtoCli::Yes } else { LtoCli::No };
740                 return true;
741             }
742         }
743 
744         *slot = match v {
745             None => LtoCli::NoParam,
746             Some("thin") => LtoCli::Thin,
747             Some("fat") => LtoCli::Fat,
748             Some(_) => return false,
749         };
750         true
751     }
752 
parse_linker_plugin_lto(slot: &mut LinkerPluginLto, v: Option<&str>) -> bool753     crate fn parse_linker_plugin_lto(slot: &mut LinkerPluginLto, v: Option<&str>) -> bool {
754         if v.is_some() {
755             let mut bool_arg = None;
756             if parse_opt_bool(&mut bool_arg, v) {
757                 *slot = if bool_arg.unwrap() {
758                     LinkerPluginLto::LinkerPluginAuto
759                 } else {
760                     LinkerPluginLto::Disabled
761                 };
762                 return true;
763             }
764         }
765 
766         *slot = match v {
767             None => LinkerPluginLto::LinkerPluginAuto,
768             Some(path) => LinkerPluginLto::LinkerPlugin(PathBuf::from(path)),
769         };
770         true
771     }
772 
parse_switch_with_opt_path(slot: &mut SwitchWithOptPath, v: Option<&str>) -> bool773     crate fn parse_switch_with_opt_path(slot: &mut SwitchWithOptPath, v: Option<&str>) -> bool {
774         *slot = match v {
775             None => SwitchWithOptPath::Enabled(None),
776             Some(path) => SwitchWithOptPath::Enabled(Some(PathBuf::from(path))),
777         };
778         true
779     }
780 
parse_merge_functions(slot: &mut Option<MergeFunctions>, v: Option<&str>) -> bool781     crate fn parse_merge_functions(slot: &mut Option<MergeFunctions>, v: Option<&str>) -> bool {
782         match v.and_then(|s| MergeFunctions::from_str(s).ok()) {
783             Some(mergefunc) => *slot = Some(mergefunc),
784             _ => return false,
785         }
786         true
787     }
788 
parse_relocation_model(slot: &mut Option<RelocModel>, v: Option<&str>) -> bool789     crate fn parse_relocation_model(slot: &mut Option<RelocModel>, v: Option<&str>) -> bool {
790         match v.and_then(|s| RelocModel::from_str(s).ok()) {
791             Some(relocation_model) => *slot = Some(relocation_model),
792             None if v == Some("default") => *slot = None,
793             _ => return false,
794         }
795         true
796     }
797 
parse_code_model(slot: &mut Option<CodeModel>, v: Option<&str>) -> bool798     crate fn parse_code_model(slot: &mut Option<CodeModel>, v: Option<&str>) -> bool {
799         match v.and_then(|s| CodeModel::from_str(s).ok()) {
800             Some(code_model) => *slot = Some(code_model),
801             _ => return false,
802         }
803         true
804     }
805 
parse_tls_model(slot: &mut Option<TlsModel>, v: Option<&str>) -> bool806     crate fn parse_tls_model(slot: &mut Option<TlsModel>, v: Option<&str>) -> bool {
807         match v.and_then(|s| TlsModel::from_str(s).ok()) {
808             Some(tls_model) => *slot = Some(tls_model),
809             _ => return false,
810         }
811         true
812     }
813 
parse_symbol_mangling_version( slot: &mut Option<SymbolManglingVersion>, v: Option<&str>, ) -> bool814     crate fn parse_symbol_mangling_version(
815         slot: &mut Option<SymbolManglingVersion>,
816         v: Option<&str>,
817     ) -> bool {
818         *slot = match v {
819             Some("legacy") => Some(SymbolManglingVersion::Legacy),
820             Some("v0") => Some(SymbolManglingVersion::V0),
821             _ => return false,
822         };
823         true
824     }
825 
parse_src_file_hash( slot: &mut Option<SourceFileHashAlgorithm>, v: Option<&str>, ) -> bool826     crate fn parse_src_file_hash(
827         slot: &mut Option<SourceFileHashAlgorithm>,
828         v: Option<&str>,
829     ) -> bool {
830         match v.and_then(|s| SourceFileHashAlgorithm::from_str(s).ok()) {
831             Some(hash_kind) => *slot = Some(hash_kind),
832             _ => return false,
833         }
834         true
835     }
836 
parse_target_feature(slot: &mut String, v: Option<&str>) -> bool837     crate fn parse_target_feature(slot: &mut String, v: Option<&str>) -> bool {
838         match v {
839             Some(s) => {
840                 if !slot.is_empty() {
841                     slot.push_str(",");
842                 }
843                 slot.push_str(s);
844                 true
845             }
846             None => false,
847         }
848     }
849 
parse_wasi_exec_model(slot: &mut Option<WasiExecModel>, v: Option<&str>) -> bool850     crate fn parse_wasi_exec_model(slot: &mut Option<WasiExecModel>, v: Option<&str>) -> bool {
851         match v {
852             Some("command") => *slot = Some(WasiExecModel::Command),
853             Some("reactor") => *slot = Some(WasiExecModel::Reactor),
854             _ => return false,
855         }
856         true
857     }
858 
parse_split_debuginfo(slot: &mut Option<SplitDebuginfo>, v: Option<&str>) -> bool859     crate fn parse_split_debuginfo(slot: &mut Option<SplitDebuginfo>, v: Option<&str>) -> bool {
860         match v.and_then(|s| SplitDebuginfo::from_str(s).ok()) {
861             Some(e) => *slot = Some(e),
862             _ => return false,
863         }
864         true
865     }
866 }
867 
868 options! {
869     CodegenOptions, CG_OPTIONS, "C", "codegen",
870 
871     // This list is in alphabetical order.
872     //
873     // If you add a new option, please update:
874     // - compiler/rustc_interface/src/tests.rs
875     // - src/doc/rustc/src/codegen-options/index.md
876 
877     ar: String = (String::new(), parse_string, [UNTRACKED],
878         "this option is deprecated and does nothing"),
879     code_model: Option<CodeModel> = (None, parse_code_model, [TRACKED],
880         "choose the code model to use (`rustc --print code-models` for details)"),
881     codegen_units: Option<usize> = (None, parse_opt_number, [UNTRACKED],
882         "divide crate into N units to optimize in parallel"),
883     control_flow_guard: CFGuard = (CFGuard::Disabled, parse_cfguard, [TRACKED],
884         "use Windows Control Flow Guard (default: no)"),
885     debug_assertions: Option<bool> = (None, parse_opt_bool, [TRACKED],
886         "explicitly enable the `cfg(debug_assertions)` directive"),
887     debuginfo: usize = (0, parse_number, [TRACKED],
888         "debug info emission level (0 = no debug info, 1 = line tables only, \
889         2 = full debug info with variable and type information; default: 0)"),
890     default_linker_libraries: bool = (false, parse_bool, [UNTRACKED],
891         "allow the linker to link its default libraries (default: no)"),
892     embed_bitcode: bool = (true, parse_bool, [TRACKED],
893         "emit bitcode in rlibs (default: yes)"),
894     extra_filename: String = (String::new(), parse_string, [UNTRACKED],
895         "extra data to put in each output filename"),
896     force_frame_pointers: Option<bool> = (None, parse_opt_bool, [TRACKED],
897         "force use of the frame pointers"),
898     force_unwind_tables: Option<bool> = (None, parse_opt_bool, [TRACKED],
899         "force use of unwind tables"),
900     incremental: Option<String> = (None, parse_opt_string, [UNTRACKED],
901         "enable incremental compilation"),
902     inline_threshold: Option<u32> = (None, parse_opt_number, [TRACKED],
903         "set the threshold for inlining a function"),
904     link_arg: (/* redirected to link_args */) = ((), parse_string_push, [UNTRACKED],
905         "a single extra argument to append to the linker invocation (can be used several times)"),
906     link_args: Vec<String> = (Vec::new(), parse_list, [UNTRACKED],
907         "extra arguments to append to the linker invocation (space separated)"),
908     link_dead_code: Option<bool> = (None, parse_opt_bool, [TRACKED],
909         "keep dead code at link time (useful for code coverage) (default: no)"),
910     link_self_contained: Option<bool> = (None, parse_opt_bool, [UNTRACKED],
911         "control whether to link Rust provided C objects/libraries or rely
912         on C toolchain installed in the system"),
913     linker: Option<PathBuf> = (None, parse_opt_pathbuf, [UNTRACKED],
914         "system linker to link outputs with"),
915     linker_flavor: Option<LinkerFlavor> = (None, parse_linker_flavor, [UNTRACKED],
916         "linker flavor"),
917     linker_plugin_lto: LinkerPluginLto = (LinkerPluginLto::Disabled,
918         parse_linker_plugin_lto, [TRACKED],
919         "generate build artifacts that are compatible with linker-based LTO"),
920     llvm_args: Vec<String> = (Vec::new(), parse_list, [TRACKED],
921         "a list of arguments to pass to LLVM (space separated)"),
922     lto: LtoCli = (LtoCli::Unspecified, parse_lto, [TRACKED],
923         "perform LLVM link-time optimizations"),
924     metadata: Vec<String> = (Vec::new(), parse_list, [TRACKED],
925         "metadata to mangle symbol names with"),
926     no_prepopulate_passes: bool = (false, parse_no_flag, [TRACKED],
927         "give an empty list of passes to the pass manager"),
928     no_redzone: Option<bool> = (None, parse_opt_bool, [TRACKED],
929         "disable the use of the redzone"),
930     no_stack_check: bool = (false, parse_no_flag, [UNTRACKED],
931         "this option is deprecated and does nothing"),
932     no_vectorize_loops: bool = (false, parse_no_flag, [TRACKED],
933         "disable loop vectorization optimization passes"),
934     no_vectorize_slp: bool = (false, parse_no_flag, [TRACKED],
935         "disable LLVM's SLP vectorization pass"),
936     opt_level: String = ("0".to_string(), parse_string, [TRACKED],
937         "optimization level (0-3, s, or z; default: 0)"),
938     overflow_checks: Option<bool> = (None, parse_opt_bool, [TRACKED],
939         "use overflow checks for integer arithmetic"),
940     panic: Option<PanicStrategy> = (None, parse_panic_strategy, [TRACKED],
941         "panic strategy to compile crate with"),
942     passes: Vec<String> = (Vec::new(), parse_list, [TRACKED],
943         "a list of extra LLVM passes to run (space separated)"),
944     prefer_dynamic: bool = (false, parse_bool, [TRACKED],
945         "prefer dynamic linking to static linking (default: no)"),
946     profile_generate: SwitchWithOptPath = (SwitchWithOptPath::Disabled,
947         parse_switch_with_opt_path, [TRACKED],
948         "compile the program with profiling instrumentation"),
949     profile_use: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
950         "use the given `.profdata` file for profile-guided optimization"),
951     relocation_model: Option<RelocModel> = (None, parse_relocation_model, [TRACKED],
952         "control generation of position-independent code (PIC) \
953         (`rustc --print relocation-models` for details)"),
954     remark: Passes = (Passes::Some(Vec::new()), parse_passes, [UNTRACKED],
955         "print remarks for these optimization passes (space separated, or \"all\")"),
956     rpath: bool = (false, parse_bool, [UNTRACKED],
957         "set rpath values in libs/exes (default: no)"),
958     save_temps: bool = (false, parse_bool, [UNTRACKED],
959         "save all temporary output files during compilation (default: no)"),
960     soft_float: bool = (false, parse_bool, [TRACKED],
961         "use soft float ABI (*eabihf targets only) (default: no)"),
962     split_debuginfo: Option<SplitDebuginfo> = (None, parse_split_debuginfo, [TRACKED],
963         "how to handle split-debuginfo, a platform-specific option"),
964     target_cpu: Option<String> = (None, parse_opt_string, [TRACKED],
965         "select target processor (`rustc --print target-cpus` for details)"),
966     target_feature: String = (String::new(), parse_target_feature, [TRACKED],
967         "target specific attributes. (`rustc --print target-features` for details). \
968         This feature is unsafe."),
969 
970     // This list is in alphabetical order.
971     //
972     // If you add a new option, please update:
973     // - compiler/rustc_interface/src/tests.rs
974     // - src/doc/rustc/src/codegen-options/index.md
975 }
976 
977 options! {
978     DebuggingOptions, DB_OPTIONS, "Z", "debugging",
979 
980     // This list is in alphabetical order.
981     //
982     // If you add a new option, please update:
983     // - compiler/rustc_interface/src/tests.rs
984 
985     allow_features: Option<Vec<String>> = (None, parse_opt_comma_list, [TRACKED],
986         "only allow the listed language features to be enabled in code (space separated)"),
987     always_encode_mir: bool = (false, parse_bool, [TRACKED],
988         "encode MIR of all functions into the crate metadata (default: no)"),
989     assume_incomplete_release: bool = (false, parse_bool, [TRACKED],
990         "make cfg(version) treat the current version as incomplete (default: no)"),
991     asm_comments: bool = (false, parse_bool, [TRACKED],
992         "generate comments into the assembly (may change behavior) (default: no)"),
993     ast_json: bool = (false, parse_bool, [UNTRACKED],
994         "print the AST as JSON and halt (default: no)"),
995     ast_json_noexpand: bool = (false, parse_bool, [UNTRACKED],
996         "print the pre-expansion AST as JSON and halt (default: no)"),
997     binary_dep_depinfo: bool = (false, parse_bool, [TRACKED],
998         "include artifacts (sysroot, crate dependencies) used during compilation in dep-info \
999         (default: no)"),
1000     borrowck: String = ("migrate".to_string(), parse_string, [UNTRACKED],
1001         "select which borrowck is used (`mir` or `migrate`) (default: `migrate`)"),
1002     cgu_partitioning_strategy: Option<String> = (None, parse_opt_string, [TRACKED],
1003         "the codegen unit partitioning strategy to use"),
1004     chalk: bool = (false, parse_bool, [TRACKED],
1005         "enable the experimental Chalk-based trait solving engine"),
1006     codegen_backend: Option<String> = (None, parse_opt_string, [TRACKED],
1007         "the backend to use"),
1008     combine_cgu: bool = (false, parse_bool, [TRACKED],
1009         "combine CGUs into a single one"),
1010     crate_attr: Vec<String> = (Vec::new(), parse_string_push, [TRACKED],
1011         "inject the given attribute in the crate"),
1012     debug_macros: bool = (false, parse_bool, [TRACKED],
1013         "emit line numbers debug info inside macros (default: no)"),
1014     deduplicate_diagnostics: bool = (true, parse_bool, [UNTRACKED],
1015         "deduplicate identical diagnostics (default: yes)"),
1016     dep_info_omit_d_target: bool = (false, parse_bool, [TRACKED],
1017         "in dep-info output, omit targets for tracking dependencies of the dep-info files \
1018         themselves (default: no)"),
1019     dep_tasks: bool = (false, parse_bool, [UNTRACKED],
1020         "print tasks that execute and the color their dep node gets (requires debug build) \
1021         (default: no)"),
1022     dont_buffer_diagnostics: bool = (false, parse_bool, [UNTRACKED],
1023         "emit diagnostics rather than buffering (breaks NLL error downgrading, sorting) \
1024         (default: no)"),
1025     dual_proc_macros: bool = (false, parse_bool, [TRACKED],
1026         "load proc macros for both target and host, but only link to the target (default: no)"),
1027     dump_dep_graph: bool = (false, parse_bool, [UNTRACKED],
1028         "dump the dependency graph to $RUST_DEP_GRAPH (default: /tmp/dep_graph.gv) \
1029         (default: no)"),
1030     dump_mir: Option<String> = (None, parse_opt_string, [UNTRACKED],
1031         "dump MIR state to file.
1032         `val` is used to select which passes and functions to dump. For example:
1033         `all` matches all passes and functions,
1034         `foo` matches all passes for functions whose name contains 'foo',
1035         `foo & ConstProp` only the 'ConstProp' pass for function names containing 'foo',
1036         `foo | bar` all passes for function names containing 'foo' or 'bar'."),
1037     dump_mir_dataflow: bool = (false, parse_bool, [UNTRACKED],
1038         "in addition to `.mir` files, create graphviz `.dot` files with dataflow results \
1039         (default: no)"),
1040     dump_mir_dir: String = ("mir_dump".to_string(), parse_string, [UNTRACKED],
1041         "the directory the MIR is dumped into (default: `mir_dump`)"),
1042     dump_mir_exclude_pass_number: bool = (false, parse_bool, [UNTRACKED],
1043         "exclude the pass number when dumping MIR (used in tests) (default: no)"),
1044     dump_mir_graphviz: bool = (false, parse_bool, [UNTRACKED],
1045         "in addition to `.mir` files, create graphviz `.dot` files (and with \
1046         `-Z instrument-coverage`, also create a `.dot` file for the MIR-derived \
1047         coverage graph) (default: no)"),
1048     dump_mir_spanview: Option<MirSpanview> = (None, parse_mir_spanview, [UNTRACKED],
1049         "in addition to `.mir` files, create `.html` files to view spans for \
1050         all `statement`s (including terminators), only `terminator` spans, or \
1051         computed `block` spans (one span encompassing a block's terminator and \
1052         all statements). If `-Z instrument-coverage` is also enabled, create \
1053         an additional `.html` file showing the computed coverage spans."),
1054     emit_future_incompat_report: bool = (false, parse_bool, [UNTRACKED],
1055         "emits a future-incompatibility report for lints (RFC 2834)"),
1056     emit_stack_sizes: bool = (false, parse_bool, [UNTRACKED],
1057         "emit a section containing stack size metadata (default: no)"),
1058     fewer_names: Option<bool> = (None, parse_opt_bool, [TRACKED],
1059         "reduce memory use by retaining fewer names within compilation artifacts (LLVM-IR) \
1060         (default: no)"),
1061     force_overflow_checks: Option<bool> = (None, parse_opt_bool, [TRACKED],
1062         "force overflow checks on or off"),
1063     force_unstable_if_unmarked: bool = (false, parse_bool, [TRACKED],
1064         "force all crates to be `rustc_private` unstable (default: no)"),
1065     fuel: Option<(String, u64)> = (None, parse_optimization_fuel, [TRACKED],
1066         "set the optimization fuel quota for a crate"),
1067     function_sections: Option<bool> = (None, parse_opt_bool, [TRACKED],
1068         "whether each function should go in its own section"),
1069     graphviz_dark_mode: bool = (false, parse_bool, [UNTRACKED],
1070         "use dark-themed colors in graphviz output (default: no)"),
1071     graphviz_font: String = ("Courier, monospace".to_string(), parse_string, [UNTRACKED],
1072         "use the given `fontname` in graphviz output; can be overridden by setting \
1073         environment variable `RUSTC_GRAPHVIZ_FONT` (default: `Courier, monospace`)"),
1074     hir_stats: bool = (false, parse_bool, [UNTRACKED],
1075         "print some statistics about AST and HIR (default: no)"),
1076     human_readable_cgu_names: bool = (false, parse_bool, [TRACKED],
1077         "generate human-readable, predictable names for codegen units (default: no)"),
1078     identify_regions: bool = (false, parse_bool, [UNTRACKED],
1079         "display unnamed regions as `'<id>`, using a non-ident unique id (default: no)"),
1080     incremental_ignore_spans: bool = (false, parse_bool, [UNTRACKED],
1081         "ignore spans during ICH computation -- used for testing (default: no)"),
1082     incremental_info: bool = (false, parse_bool, [UNTRACKED],
1083         "print high-level information about incremental reuse (or the lack thereof) \
1084         (default: no)"),
1085     incremental_verify_ich: bool = (false, parse_bool, [UNTRACKED],
1086         "verify incr. comp. hashes of green query instances (default: no)"),
1087     inline_mir: Option<bool> = (None, parse_opt_bool, [TRACKED],
1088         "enable MIR inlining (default: no)"),
1089     inline_mir_threshold: Option<usize> = (None, parse_opt_number, [TRACKED],
1090         "a default MIR inlining threshold (default: 50)"),
1091     inline_mir_hint_threshold: Option<usize> = (None, parse_opt_number, [TRACKED],
1092         "inlining threshold for functions with inline hint (default: 100)"),
1093     inline_in_all_cgus: Option<bool> = (None, parse_opt_bool, [TRACKED],
1094         "control whether `#[inline]` functions are in all CGUs"),
1095     input_stats: bool = (false, parse_bool, [UNTRACKED],
1096         "gather statistics about the input (default: no)"),
1097     instrument_coverage: Option<InstrumentCoverage> = (None, parse_instrument_coverage, [TRACKED],
1098         "instrument the generated code to support LLVM source-based code coverage \
1099         reports (note, the compiler build config must include `profiler = true`); \
1100         implies `-Z symbol-mangling-version=v0`. Optional values are:
1101         `=all` (implicit value)
1102         `=except-unused-generics`
1103         `=except-unused-functions`
1104         `=off` (default)"),
1105     instrument_mcount: bool = (false, parse_bool, [TRACKED],
1106         "insert function instrument code for mcount-based tracing (default: no)"),
1107     keep_hygiene_data: bool = (false, parse_bool, [UNTRACKED],
1108         "keep hygiene data after analysis (default: no)"),
1109     link_native_libraries: bool = (true, parse_bool, [UNTRACKED],
1110         "link native libraries in the linker invocation (default: yes)"),
1111     link_only: bool = (false, parse_bool, [TRACKED],
1112         "link the `.rlink` file generated by `-Z no-link` (default: no)"),
1113     llvm_time_trace: bool = (false, parse_bool, [UNTRACKED],
1114         "generate JSON tracing data file from LLVM data (default: no)"),
1115     ls: bool = (false, parse_bool, [UNTRACKED],
1116         "list the symbols defined by a library crate (default: no)"),
1117     macro_backtrace: bool = (false, parse_bool, [UNTRACKED],
1118         "show macro backtraces (default: no)"),
1119     merge_functions: Option<MergeFunctions> = (None, parse_merge_functions, [TRACKED],
1120         "control the operation of the MergeFunctions LLVM pass, taking \
1121         the same values as the target option of the same name"),
1122     meta_stats: bool = (false, parse_bool, [UNTRACKED],
1123         "gather metadata statistics (default: no)"),
1124     mir_emit_retag: bool = (false, parse_bool, [TRACKED],
1125         "emit Retagging MIR statements, interpreted e.g., by miri; implies -Zmir-opt-level=0 \
1126         (default: no)"),
1127     mir_opt_level: Option<usize> = (None, parse_opt_number, [TRACKED],
1128         "MIR optimization level (0-4; default: 1 in non optimized builds and 2 in optimized builds)"),
1129     mutable_noalias: Option<bool> = (None, parse_opt_bool, [TRACKED],
1130         "emit noalias metadata for mutable references (default: yes for LLVM >= 12, otherwise no)"),
1131     new_llvm_pass_manager: Option<bool> = (None, parse_opt_bool, [TRACKED],
1132         "use new LLVM pass manager (default: no)"),
1133     nll_facts: bool = (false, parse_bool, [UNTRACKED],
1134         "dump facts from NLL analysis into side files (default: no)"),
1135     nll_facts_dir: String = ("nll-facts".to_string(), parse_string, [UNTRACKED],
1136         "the directory the NLL facts are dumped into (default: `nll-facts`)"),
1137     no_analysis: bool = (false, parse_no_flag, [UNTRACKED],
1138         "parse and expand the source, but run no analysis"),
1139     no_codegen: bool = (false, parse_no_flag, [TRACKED],
1140         "run all passes except codegen; no output"),
1141     no_generate_arange_section: bool = (false, parse_no_flag, [TRACKED],
1142         "omit DWARF address ranges that give faster lookups"),
1143     no_interleave_lints: bool = (false, parse_no_flag, [UNTRACKED],
1144         "execute lints separately; allows benchmarking individual lints"),
1145     no_leak_check: bool = (false, parse_no_flag, [UNTRACKED],
1146         "disable the 'leak check' for subtyping; unsound, but useful for tests"),
1147     no_link: bool = (false, parse_no_flag, [TRACKED],
1148         "compile without linking"),
1149     no_parallel_llvm: bool = (false, parse_no_flag, [UNTRACKED],
1150         "run LLVM in non-parallel mode (while keeping codegen-units and ThinLTO)"),
1151     no_profiler_runtime: bool = (false, parse_no_flag, [TRACKED],
1152         "prevent automatic injection of the profiler_builtins crate"),
1153     normalize_docs: bool = (false, parse_bool, [TRACKED],
1154         "normalize associated items in rustdoc when generating documentation"),
1155     osx_rpath_install_name: bool = (false, parse_bool, [TRACKED],
1156         "pass `-install_name @rpath/...` to the macOS linker (default: no)"),
1157     panic_abort_tests: bool = (false, parse_bool, [TRACKED],
1158         "support compiling tests with panic=abort (default: no)"),
1159     parse_only: bool = (false, parse_bool, [UNTRACKED],
1160         "parse only; do not compile, assemble, or link (default: no)"),
1161     perf_stats: bool = (false, parse_bool, [UNTRACKED],
1162         "print some performance-related statistics (default: no)"),
1163     plt: Option<bool> = (None, parse_opt_bool, [TRACKED],
1164         "whether to use the PLT when calling into shared libraries;
1165         only has effect for PIC code on systems with ELF binaries
1166         (default: PLT is disabled if full relro is enabled)"),
1167     polonius: bool = (false, parse_bool, [TRACKED],
1168         "enable polonius-based borrow-checker (default: no)"),
1169     polymorphize: bool = (false, parse_bool, [TRACKED],
1170           "perform polymorphization analysis"),
1171     pre_link_arg: (/* redirected to pre_link_args */) = ((), parse_string_push, [UNTRACKED],
1172         "a single extra argument to prepend the linker invocation (can be used several times)"),
1173     pre_link_args: Vec<String> = (Vec::new(), parse_list, [UNTRACKED],
1174         "extra arguments to prepend to the linker invocation (space separated)"),
1175     precise_enum_drop_elaboration: bool = (true, parse_bool, [TRACKED],
1176         "use a more precise version of drop elaboration for matches on enums (default: yes). \
1177         This results in better codegen, but has caused miscompilations on some tier 2 platforms. \
1178         See #77382 and #74551."),
1179     print_fuel: Option<String> = (None, parse_opt_string, [TRACKED],
1180         "make rustc print the total optimization fuel used by a crate"),
1181     print_link_args: bool = (false, parse_bool, [UNTRACKED],
1182         "print the arguments passed to the linker (default: no)"),
1183     print_llvm_passes: bool = (false, parse_bool, [UNTRACKED],
1184         "print the LLVM optimization passes being run (default: no)"),
1185     print_mono_items: Option<String> = (None, parse_opt_string, [UNTRACKED],
1186         "print the result of the monomorphization collection pass"),
1187     print_type_sizes: bool = (false, parse_bool, [UNTRACKED],
1188         "print layout information for each type encountered (default: no)"),
1189     proc_macro_backtrace: bool = (false, parse_bool, [UNTRACKED],
1190          "show backtraces for panics during proc-macro execution (default: no)"),
1191     profile: bool = (false, parse_bool, [TRACKED],
1192         "insert profiling code (default: no)"),
1193     profile_emit: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
1194         "file path to emit profiling data at runtime when using 'profile' \
1195         (default based on relative source path)"),
1196     query_dep_graph: bool = (false, parse_bool, [UNTRACKED],
1197         "enable queries of the dependency graph for regression testing (default: no)"),
1198     query_stats: bool = (false, parse_bool, [UNTRACKED],
1199         "print some statistics about the query system (default: no)"),
1200     relax_elf_relocations: Option<bool> = (None, parse_opt_bool, [TRACKED],
1201         "whether ELF relocations can be relaxed"),
1202     relro_level: Option<RelroLevel> = (None, parse_relro_level, [TRACKED],
1203         "choose which RELRO level to use"),
1204     simulate_remapped_rust_src_base: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
1205         "simulate the effect of remap-debuginfo = true at bootstrapping by remapping path \
1206         to rust's source base directory. only meant for testing purposes"),
1207     report_delayed_bugs: bool = (false, parse_bool, [TRACKED],
1208         "immediately print bugs registered with `delay_span_bug` (default: no)"),
1209     sanitizer: SanitizerSet = (SanitizerSet::empty(), parse_sanitizers, [TRACKED],
1210         "use a sanitizer"),
1211     sanitizer_memory_track_origins: usize = (0, parse_sanitizer_memory_track_origins, [TRACKED],
1212         "enable origins tracking in MemorySanitizer"),
1213     sanitizer_recover: SanitizerSet = (SanitizerSet::empty(), parse_sanitizers, [TRACKED],
1214         "enable recovery for selected sanitizers"),
1215     saturating_float_casts: Option<bool> = (None, parse_opt_bool, [TRACKED],
1216         "make float->int casts UB-free: numbers outside the integer type's range are clipped to \
1217         the max/min integer respectively, and NaN is mapped to 0 (default: yes)"),
1218     save_analysis: bool = (false, parse_bool, [UNTRACKED],
1219         "write syntax and type analysis (in JSON format) information, in \
1220         addition to normal output (default: no)"),
1221     self_profile: SwitchWithOptPath = (SwitchWithOptPath::Disabled,
1222         parse_switch_with_opt_path, [UNTRACKED],
1223         "run the self profiler and output the raw event data"),
1224     /// keep this in sync with the event filter names in librustc_data_structures/profiling.rs
1225     self_profile_events: Option<Vec<String>> = (None, parse_opt_comma_list, [UNTRACKED],
1226         "specify the events recorded by the self profiler;
1227         for example: `-Z self-profile-events=default,query-keys`
1228         all options: none, all, default, generic-activity, query-provider, query-cache-hit
1229                      query-blocked, incr-cache-load, query-keys, function-args, args, llvm"),
1230     share_generics: Option<bool> = (None, parse_opt_bool, [TRACKED],
1231         "make the current crate share its generic instantiations"),
1232     show_span: Option<String> = (None, parse_opt_string, [TRACKED],
1233         "show spans for compiler debugging (expr|pat|ty)"),
1234     span_debug: bool = (false, parse_bool, [UNTRACKED],
1235         "forward proc_macro::Span's `Debug` impl to `Span`"),
1236     /// o/w tests have closure@path
1237     span_free_formats: bool = (false, parse_bool, [UNTRACKED],
1238         "exclude spans when debug-printing compiler state (default: no)"),
1239     src_hash_algorithm: Option<SourceFileHashAlgorithm> = (None, parse_src_file_hash, [TRACKED],
1240         "hash algorithm of source files in debug info (`md5`, `sha1`, or `sha256`)"),
1241     strip: Strip = (Strip::None, parse_strip, [UNTRACKED],
1242         "tell the linker which information to strip (`none` (default), `debuginfo` or `symbols`)"),
1243     split_dwarf_inlining: bool = (true, parse_bool, [UNTRACKED],
1244         "provide minimal debug info in the object/executable to facilitate online \
1245          symbolication/stack traces in the absence of .dwo/.dwp files when using Split DWARF"),
1246     symbol_mangling_version: Option<SymbolManglingVersion> = (None,
1247         parse_symbol_mangling_version, [TRACKED],
1248         "which mangling version to use for symbol names ('legacy' (default) or 'v0')"),
1249     teach: bool = (false, parse_bool, [TRACKED],
1250         "show extended diagnostic help (default: no)"),
1251     terminal_width: Option<usize> = (None, parse_opt_number, [UNTRACKED],
1252         "set the current terminal width"),
1253     tune_cpu: Option<String> = (None, parse_opt_string, [TRACKED],
1254         "select processor to schedule for (`rustc --print target-cpus` for details)"),
1255     thinlto: Option<bool> = (None, parse_opt_bool, [TRACKED],
1256         "enable ThinLTO when possible"),
1257     thir_unsafeck: bool = (false, parse_bool, [TRACKED],
1258         "use the work-in-progress THIR unsafety checker. NOTE: this is unsound (default: no)"),
1259     /// We default to 1 here since we want to behave like
1260     /// a sequential compiler for now. This'll likely be adjusted
1261     /// in the future. Note that -Zthreads=0 is the way to get
1262     /// the num_cpus behavior.
1263     threads: usize = (1, parse_threads, [UNTRACKED],
1264         "use a thread pool with N threads"),
1265     time: bool = (false, parse_bool, [UNTRACKED],
1266         "measure time of rustc processes (default: no)"),
1267     time_llvm_passes: bool = (false, parse_bool, [UNTRACKED],
1268         "measure time of each LLVM pass (default: no)"),
1269     time_passes: bool = (false, parse_bool, [UNTRACKED],
1270         "measure time of each rustc pass (default: no)"),
1271     tls_model: Option<TlsModel> = (None, parse_tls_model, [TRACKED],
1272         "choose the TLS model to use (`rustc --print tls-models` for details)"),
1273     trace_macros: bool = (false, parse_bool, [UNTRACKED],
1274         "for every macro invocation, print its name and arguments (default: no)"),
1275     trap_unreachable: Option<bool> = (None, parse_opt_bool, [TRACKED],
1276         "generate trap instructions for unreachable intrinsics (default: use target setting, usually yes)"),
1277     treat_err_as_bug: Option<NonZeroUsize> = (None, parse_treat_err_as_bug, [TRACKED],
1278         "treat error number `val` that occurs as bug"),
1279     trim_diagnostic_paths: bool = (true, parse_bool, [UNTRACKED],
1280         "in diagnostics, use heuristics to shorten paths referring to items"),
1281     ui_testing: bool = (false, parse_bool, [UNTRACKED],
1282         "emit compiler diagnostics in a form suitable for UI testing (default: no)"),
1283     unleash_the_miri_inside_of_you: bool = (false, parse_bool, [TRACKED],
1284         "take the brakes off const evaluation. NOTE: this is unsound (default: no)"),
1285     unpretty: Option<String> = (None, parse_unpretty, [UNTRACKED],
1286         "present the input source, unstable (and less-pretty) variants;
1287         valid types are any of the types for `--pretty`, as well as:
1288         `expanded`, `expanded,identified`,
1289         `expanded,hygiene` (with internal representations),
1290         `everybody_loops` (all function bodies replaced with `loop {}`),
1291         `ast-tree` (raw AST before expansion),
1292         `ast-tree,expanded` (raw AST after expansion),
1293         `hir` (the HIR), `hir,identified`,
1294         `hir,typed` (HIR with types for each node),
1295         `hir-tree` (dump the raw HIR),
1296         `mir` (the MIR), or `mir-cfg` (graphviz formatted MIR)"),
1297     unsound_mir_opts: bool = (false, parse_bool, [TRACKED],
1298         "enable unsound and buggy MIR optimizations (default: no)"),
1299     unstable_options: bool = (false, parse_bool, [UNTRACKED],
1300         "adds unstable command line options to rustc interface (default: no)"),
1301     use_ctors_section: Option<bool> = (None, parse_opt_bool, [TRACKED],
1302         "use legacy .ctors section for initializers rather than .init_array"),
1303     validate_mir: bool = (false, parse_bool, [UNTRACKED],
1304         "validate MIR after each transformation"),
1305     verbose: bool = (false, parse_bool, [UNTRACKED],
1306         "in general, enable more debug printouts (default: no)"),
1307     verify_llvm_ir: bool = (false, parse_bool, [TRACKED],
1308         "verify LLVM IR (default: no)"),
1309     wasi_exec_model: Option<WasiExecModel> = (None, parse_wasi_exec_model, [TRACKED],
1310         "whether to build a wasi command or reactor"),
1311 
1312     // This list is in alphabetical order.
1313     //
1314     // If you add a new option, please update:
1315     // - compiler/rustc_interface/src/tests.rs
1316 }
1317 
1318 #[derive(Clone, Hash, PartialEq, Eq, Debug)]
1319 pub enum WasiExecModel {
1320     Command,
1321     Reactor,
1322 }
1323