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