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