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