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