]> git.lizzy.rs Git - rust.git/blob - src/librustc_session/options.rs
Rollup merge of #67467 - matthewjasper:test-slice-patterns, r=oli-obk
[rust.git] / src / librustc_session / options.rs
1 use crate::config::*;
2
3 use crate::lint;
4 use crate::utils::NativeLibraryKind;
5 use crate::early_error;
6 use crate::search_paths::SearchPath;
7
8 use rustc_target::spec::{LinkerFlavor, MergeFunctions, PanicStrategy, RelroLevel};
9 use rustc_target::spec::TargetTriple;
10
11 use syntax_pos::edition::Edition;
12 use rustc_feature::UnstableFeatures;
13
14 use getopts;
15
16 use std::collections::BTreeMap;
17
18 use std::str;
19 use std::hash::Hasher;
20 use std::collections::hash_map::DefaultHasher;
21 use std::path::PathBuf;
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.insert(stringify!($opt_name),
27                               $opt_expr as &dyn dep_tracking::DepTrackingHash).is_some() {
28             panic!("duplicate key in CLI DepTrackingHash: {}", stringify!($opt_name))
29         }
30     });
31 }
32
33 macro_rules! top_level_options {
34     (pub struct Options { $(
35         $opt:ident : $t:ty [$dep_tracking_marker:ident $($warn_val:expr, $warn_text:expr)*],
36     )* } ) => (
37         #[derive(Clone)]
38         pub struct Options {
39             $(pub $opt: $t),*
40         }
41
42         impl Options {
43             pub fn dep_tracking_hash(&self) -> u64 {
44                 let mut sub_hashes = BTreeMap::new();
45                 $({
46                     hash_option!($opt,
47                                  &self.$opt,
48                                  &mut sub_hashes,
49                                  [$dep_tracking_marker $($warn_val,
50                                                          $warn_text,
51                                                          self.error_format)*]);
52                 })*
53                 let mut hasher = DefaultHasher::new();
54                 dep_tracking::stable_hash(sub_hashes,
55                                           &mut hasher,
56                                           self.error_format);
57                 hasher.finish()
58             }
59         }
60     );
61 }
62
63 // The top-level command-line options struct.
64 //
65 // For each option, one has to specify how it behaves with regard to the
66 // dependency tracking system of incremental compilation. This is done via the
67 // square-bracketed directive after the field type. The options are:
68 //
69 // [TRACKED]
70 // A change in the given field will cause the compiler to completely clear the
71 // incremental compilation cache before proceeding.
72 //
73 // [UNTRACKED]
74 // Incremental compilation is not influenced by this option.
75 //
76 // If you add a new option to this struct or one of the sub-structs like
77 // `CodegenOptions`, think about how it influences incremental compilation. If in
78 // doubt, specify [TRACKED], which is always "correct" but might lead to
79 // unnecessary re-compilation.
80 top_level_options!(
81     pub struct Options {
82         // The crate config requested for the session, which may be combined
83         // with additional crate configurations during the compile process.
84         crate_types: Vec<CrateType> [TRACKED],
85         optimize: OptLevel [TRACKED],
86         // Include the `debug_assertions` flag in dependency tracking, since it
87         // can influence whether overflow checks are done or not.
88         debug_assertions: bool [TRACKED],
89         debuginfo: DebugInfo [TRACKED],
90         lint_opts: Vec<(String, lint::Level)> [TRACKED],
91         lint_cap: Option<lint::Level> [TRACKED],
92         describe_lints: bool [UNTRACKED],
93         output_types: OutputTypes [TRACKED],
94         search_paths: Vec<SearchPath> [UNTRACKED],
95         libs: Vec<(String, Option<String>, Option<NativeLibraryKind>)> [TRACKED],
96         maybe_sysroot: Option<PathBuf> [UNTRACKED],
97
98         target_triple: TargetTriple [TRACKED],
99
100         test: bool [TRACKED],
101         error_format: ErrorOutputType [UNTRACKED],
102
103         // If `Some`, enable incremental compilation, using the given
104         // directory to store intermediate results.
105         incremental: Option<PathBuf> [UNTRACKED],
106
107         debugging_opts: DebuggingOptions [TRACKED],
108         prints: Vec<PrintRequest> [UNTRACKED],
109         // Determines which borrow checker(s) to run. This is the parsed, sanitized
110         // version of `debugging_opts.borrowck`, which is just a plain string.
111         borrowck_mode: BorrowckMode [UNTRACKED],
112         cg: CodegenOptions [TRACKED],
113         externs: Externs [UNTRACKED],
114         crate_name: Option<String> [TRACKED],
115         // An optional name to use as the crate for std during std injection,
116         // written `extern crate name as std`. Defaults to `std`. Used by
117         // out-of-tree drivers.
118         alt_std_name: Option<String> [TRACKED],
119         // Indicates how the compiler should treat unstable features.
120         unstable_features: UnstableFeatures [TRACKED],
121
122         // Indicates whether this run of the compiler is actually rustdoc. This
123         // is currently just a hack and will be removed eventually, so please
124         // try to not rely on this too much.
125         actually_rustdoc: bool [TRACKED],
126
127         // Specifications of codegen units / ThinLTO which are forced as a
128         // result of parsing command line options. These are not necessarily
129         // what rustc was invoked with, but massaged a bit to agree with
130         // commands like `--emit llvm-ir` which they're often incompatible with
131         // if we otherwise use the defaults of rustc.
132         cli_forced_codegen_units: Option<usize> [UNTRACKED],
133         cli_forced_thinlto_off: bool [UNTRACKED],
134
135         // Remap source path prefixes in all output (messages, object files, debug, etc.).
136         remap_path_prefix: Vec<(PathBuf, PathBuf)> [UNTRACKED],
137
138         edition: Edition [TRACKED],
139
140         // `true` if we're emitting JSON blobs about each artifact produced
141         // by the compiler.
142         json_artifact_notifications: bool [TRACKED],
143
144         pretty: Option<PpMode> [UNTRACKED],
145     }
146 );
147
148 /// Defines all `CodegenOptions`/`DebuggingOptions` fields and parsers all at once. The goal of this
149 /// macro is to define an interface that can be programmatically used by the option parser
150 /// to initialize the struct without hardcoding field names all over the place.
151 ///
152 /// The goal is to invoke this macro once with the correct fields, and then this macro generates all
153 /// necessary code. The main gotcha of this macro is the `cgsetters` module which is a bunch of
154 /// generated code to parse an option into its respective field in the struct. There are a few
155 /// hand-written parsers for parsing specific types of values in this module.
156 macro_rules! options {
157     ($struct_name:ident, $setter_name:ident, $defaultfn:ident,
158      $buildfn:ident, $prefix:expr, $outputname:expr,
159      $stat:ident, $mod_desc:ident, $mod_set:ident,
160      $($opt:ident : $t:ty = (
161         $init:expr,
162         $parse:ident,
163         [$dep_tracking_marker:ident $(($dep_warn_val:expr, $dep_warn_text:expr))*],
164         $desc:expr)
165      ),* ,) =>
166 (
167     #[derive(Clone)]
168     pub struct $struct_name { $(pub $opt: $t),* }
169
170     pub fn $defaultfn() -> $struct_name {
171         $struct_name { $($opt: $init),* }
172     }
173
174     pub fn $buildfn(matches: &getopts::Matches, error_format: ErrorOutputType) -> $struct_name
175     {
176         let mut op = $defaultfn();
177         for option in matches.opt_strs($prefix) {
178             let mut iter = option.splitn(2, '=');
179             let key = iter.next().unwrap();
180             let value = iter.next();
181             let option_to_lookup = key.replace("-", "_");
182             let mut found = false;
183             for &(candidate, setter, opt_type_desc, _) in $stat {
184                 if option_to_lookup != candidate { continue }
185                 if !setter(&mut op, value) {
186                     match (value, opt_type_desc) {
187                         (Some(..), None) => {
188                             early_error(error_format, &format!("{} option `{}` takes no \
189                                                                 value", $outputname, key))
190                         }
191                         (None, Some(type_desc)) => {
192                             early_error(error_format, &format!("{0} option `{1}` requires \
193                                                                 {2} ({3} {1}=<value>)",
194                                                                $outputname, key,
195                                                                type_desc, $prefix))
196                         }
197                         (Some(value), Some(type_desc)) => {
198                             early_error(error_format, &format!("incorrect value `{}` for {} \
199                                                                 option `{}` - {} was expected",
200                                                                value, $outputname,
201                                                                key, type_desc))
202                         }
203                         (None, None) => panic!()
204                     }
205                 }
206                 found = true;
207                 break;
208             }
209             if !found {
210                 early_error(error_format, &format!("unknown {} option: `{}`",
211                                                    $outputname, key));
212             }
213         }
214         return op;
215     }
216
217     impl dep_tracking::DepTrackingHash for $struct_name {
218         fn hash(&self, hasher: &mut DefaultHasher, error_format: ErrorOutputType) {
219             let mut sub_hashes = BTreeMap::new();
220             $({
221                 hash_option!($opt,
222                              &self.$opt,
223                              &mut sub_hashes,
224                              [$dep_tracking_marker $($dep_warn_val,
225                                                      $dep_warn_text,
226                                                      error_format)*]);
227             })*
228             dep_tracking::stable_hash(sub_hashes, hasher, error_format);
229         }
230     }
231
232     pub type $setter_name = fn(&mut $struct_name, v: Option<&str>) -> bool;
233     pub const $stat: &[(&str, $setter_name, Option<&str>, &str)] =
234         &[ $( (stringify!($opt), $mod_set::$opt, $mod_desc::$parse, $desc) ),* ];
235
236     #[allow(non_upper_case_globals, dead_code)]
237     mod $mod_desc {
238         pub const parse_bool: Option<&str> = None;
239         pub const parse_opt_bool: Option<&str> =
240             Some("one of: `y`, `yes`, `on`, `n`, `no`, or `off`");
241         pub const parse_string: Option<&str> = Some("a string");
242         pub const parse_string_push: Option<&str> = Some("a string");
243         pub const parse_pathbuf_push: Option<&str> = Some("a path");
244         pub const parse_opt_string: Option<&str> = Some("a string");
245         pub const parse_opt_pathbuf: Option<&str> = Some("a path");
246         pub const parse_list: Option<&str> = Some("a space-separated list of strings");
247         pub const parse_opt_list: Option<&str> = Some("a space-separated list of strings");
248         pub const parse_opt_comma_list: Option<&str> = Some("a comma-separated list of strings");
249         pub const parse_threads: Option<&str> = Some("a number");
250         pub const parse_uint: Option<&str> = Some("a number");
251         pub const parse_passes: Option<&str> =
252             Some("a space-separated list of passes, or `all`");
253         pub const parse_opt_uint: Option<&str> =
254             Some("a number");
255         pub const parse_panic_strategy: Option<&str> =
256             Some("either `unwind` or `abort`");
257         pub const parse_relro_level: Option<&str> =
258             Some("one of: `full`, `partial`, or `off`");
259         pub const parse_sanitizer: Option<&str> =
260             Some("one of: `address`, `leak`, `memory` or `thread`");
261         pub const parse_sanitizer_list: Option<&str> =
262             Some("comma separated list of sanitizers");
263         pub const parse_sanitizer_memory_track_origins: Option<&str> = None;
264         pub const parse_linker_flavor: Option<&str> =
265             Some(::rustc_target::spec::LinkerFlavor::one_of());
266         pub const parse_optimization_fuel: Option<&str> =
267             Some("crate=integer");
268         pub const parse_unpretty: Option<&str> =
269             Some("`string` or `string=string`");
270         pub const parse_treat_err_as_bug: Option<&str> =
271             Some("either no value or a number bigger than 0");
272         pub const parse_lto: Option<&str> =
273             Some("either a boolean (`yes`, `no`, `on`, `off`, etc), `thin`, \
274                   `fat`, or omitted");
275         pub const parse_linker_plugin_lto: Option<&str> =
276             Some("either a boolean (`yes`, `no`, `on`, `off`, etc), \
277                   or the path to the linker plugin");
278         pub const parse_switch_with_opt_path: Option<&str> =
279             Some("an optional path to the profiling data output directory");
280         pub const parse_merge_functions: Option<&str> =
281             Some("one of: `disabled`, `trampolines`, or `aliases`");
282         pub const parse_symbol_mangling_version: Option<&str> =
283             Some("either `legacy` or `v0` (RFC 2603)");
284     }
285
286     #[allow(dead_code)]
287     mod $mod_set {
288         use super::{$struct_name, Passes, Sanitizer, LtoCli, LinkerPluginLto, SwitchWithOptPath,
289             SymbolManglingVersion};
290         use rustc_target::spec::{LinkerFlavor, MergeFunctions, PanicStrategy, RelroLevel};
291         use std::path::PathBuf;
292         use std::str::FromStr;
293
294         $(
295             pub fn $opt(cg: &mut $struct_name, v: Option<&str>) -> bool {
296                 $parse(&mut cg.$opt, v)
297             }
298         )*
299
300         fn parse_bool(slot: &mut bool, v: Option<&str>) -> bool {
301             match v {
302                 Some(..) => false,
303                 None => { *slot = true; true }
304             }
305         }
306
307         fn parse_opt_bool(slot: &mut Option<bool>, v: Option<&str>) -> bool {
308             match v {
309                 Some(s) => {
310                     match s {
311                         "n" | "no" | "off" => {
312                             *slot = Some(false);
313                         }
314                         "y" | "yes" | "on" => {
315                             *slot = Some(true);
316                         }
317                         _ => { return false; }
318                     }
319
320                     true
321                 },
322                 None => { *slot = Some(true); true }
323             }
324         }
325
326         fn parse_opt_string(slot: &mut Option<String>, v: Option<&str>) -> bool {
327             match v {
328                 Some(s) => { *slot = Some(s.to_string()); true },
329                 None => false,
330             }
331         }
332
333         fn parse_opt_pathbuf(slot: &mut Option<PathBuf>, v: Option<&str>) -> bool {
334             match v {
335                 Some(s) => { *slot = Some(PathBuf::from(s)); true },
336                 None => false,
337             }
338         }
339
340         fn parse_string(slot: &mut String, v: Option<&str>) -> bool {
341             match v {
342                 Some(s) => { *slot = s.to_string(); true },
343                 None => false,
344             }
345         }
346
347         fn parse_string_push(slot: &mut Vec<String>, v: Option<&str>) -> bool {
348             match v {
349                 Some(s) => { slot.push(s.to_string()); true },
350                 None => false,
351             }
352         }
353
354         fn parse_pathbuf_push(slot: &mut Vec<PathBuf>, v: Option<&str>) -> bool {
355             match v {
356                 Some(s) => { slot.push(PathBuf::from(s)); true },
357                 None => false,
358             }
359         }
360
361         fn parse_list(slot: &mut Vec<String>, v: Option<&str>)
362                       -> bool {
363             match v {
364                 Some(s) => {
365                     slot.extend(s.split_whitespace().map(|s| s.to_string()));
366                     true
367                 },
368                 None => false,
369             }
370         }
371
372         fn parse_opt_list(slot: &mut Option<Vec<String>>, v: Option<&str>)
373                       -> bool {
374             match v {
375                 Some(s) => {
376                     let v = s.split_whitespace().map(|s| s.to_string()).collect();
377                     *slot = Some(v);
378                     true
379                 },
380                 None => false,
381             }
382         }
383
384         fn parse_opt_comma_list(slot: &mut Option<Vec<String>>, v: Option<&str>)
385                       -> bool {
386             match v {
387                 Some(s) => {
388                     let v = s.split(',').map(|s| s.to_string()).collect();
389                     *slot = Some(v);
390                     true
391                 },
392                 None => false,
393             }
394         }
395
396         fn parse_threads(slot: &mut usize, v: Option<&str>) -> bool {
397             match v.and_then(|s| s.parse().ok()) {
398                 Some(0) => { *slot = ::num_cpus::get(); true },
399                 Some(i) => { *slot = i; true },
400                 None => false
401             }
402         }
403
404         fn parse_uint(slot: &mut usize, v: Option<&str>) -> bool {
405             match v.and_then(|s| s.parse().ok()) {
406                 Some(i) => { *slot = i; true },
407                 None => false
408             }
409         }
410
411         fn parse_opt_uint(slot: &mut Option<usize>, v: Option<&str>) -> bool {
412             match v {
413                 Some(s) => { *slot = s.parse().ok(); slot.is_some() }
414                 None => { *slot = None; false }
415             }
416         }
417
418         fn parse_passes(slot: &mut Passes, v: Option<&str>) -> bool {
419             match v {
420                 Some("all") => {
421                     *slot = Passes::All;
422                     true
423                 }
424                 v => {
425                     let mut passes = vec![];
426                     if parse_list(&mut passes, v) {
427                         *slot = Passes::Some(passes);
428                         true
429                     } else {
430                         false
431                     }
432                 }
433             }
434         }
435
436         fn parse_panic_strategy(slot: &mut Option<PanicStrategy>, v: Option<&str>) -> bool {
437             match v {
438                 Some("unwind") => *slot = Some(PanicStrategy::Unwind),
439                 Some("abort") => *slot = Some(PanicStrategy::Abort),
440                 _ => return false
441             }
442             true
443         }
444
445         fn parse_relro_level(slot: &mut Option<RelroLevel>, v: Option<&str>) -> bool {
446             match v {
447                 Some(s) => {
448                     match s.parse::<RelroLevel>() {
449                         Ok(level) => *slot = Some(level),
450                         _ => return false
451                     }
452                 },
453                 _ => return false
454             }
455             true
456         }
457
458         fn parse_sanitizer(slot: &mut Option<Sanitizer>, v: Option<&str>) -> bool {
459             if let Some(Ok(s)) =  v.map(str::parse) {
460                 *slot = Some(s);
461                 true
462             } else {
463                 false
464             }
465         }
466
467         fn parse_sanitizer_list(slot: &mut Vec<Sanitizer>, v: Option<&str>) -> bool {
468             if let Some(v) = v {
469                 for s in v.split(',').map(str::parse) {
470                     if let Ok(s) = s {
471                         if !slot.contains(&s) {
472                             slot.push(s);
473                         }
474                     } else {
475                         return false;
476                     }
477                 }
478                 true
479             } else {
480                 false
481             }
482         }
483
484         fn parse_sanitizer_memory_track_origins(slot: &mut usize, v: Option<&str>) -> bool {
485             match v.map(|s| s.parse()) {
486                 None => {
487                     *slot = 2;
488                     true
489                 }
490                 Some(Ok(i)) if i <= 2 => {
491                     *slot = i;
492                     true
493                 }
494                 _ => {
495                     false
496                 }
497             }
498         }
499
500         fn parse_linker_flavor(slote: &mut Option<LinkerFlavor>, v: Option<&str>) -> bool {
501             match v.and_then(LinkerFlavor::from_str) {
502                 Some(lf) => *slote = Some(lf),
503                 _ => return false,
504             }
505             true
506         }
507
508         fn parse_optimization_fuel(slot: &mut Option<(String, u64)>, v: Option<&str>) -> bool {
509             match v {
510                 None => false,
511                 Some(s) => {
512                     let parts = s.split('=').collect::<Vec<_>>();
513                     if parts.len() != 2 { return false; }
514                     let crate_name = parts[0].to_string();
515                     let fuel = parts[1].parse::<u64>();
516                     if fuel.is_err() { return false; }
517                     *slot = Some((crate_name, fuel.unwrap()));
518                     true
519                 }
520             }
521         }
522
523         fn parse_unpretty(slot: &mut Option<String>, v: Option<&str>) -> bool {
524             match v {
525                 None => false,
526                 Some(s) if s.split('=').count() <= 2 => {
527                     *slot = Some(s.to_string());
528                     true
529                 }
530                 _ => false,
531             }
532         }
533
534         fn parse_treat_err_as_bug(slot: &mut Option<usize>, v: Option<&str>) -> bool {
535             match v {
536                 Some(s) => { *slot = s.parse().ok().filter(|&x| x != 0); slot.unwrap_or(0) != 0 }
537                 None => { *slot = Some(1); true }
538             }
539         }
540
541         fn parse_lto(slot: &mut LtoCli, v: Option<&str>) -> bool {
542             if v.is_some() {
543                 let mut bool_arg = None;
544                 if parse_opt_bool(&mut bool_arg, v) {
545                     *slot = if bool_arg.unwrap() {
546                         LtoCli::Yes
547                     } else {
548                         LtoCli::No
549                     };
550                     return true
551                 }
552             }
553
554             *slot = match v {
555                 None => LtoCli::NoParam,
556                 Some("thin") => LtoCli::Thin,
557                 Some("fat") => LtoCli::Fat,
558                 Some(_) => return false,
559             };
560             true
561         }
562
563         fn parse_linker_plugin_lto(slot: &mut LinkerPluginLto, v: Option<&str>) -> bool {
564             if v.is_some() {
565                 let mut bool_arg = None;
566                 if parse_opt_bool(&mut bool_arg, v) {
567                     *slot = if bool_arg.unwrap() {
568                         LinkerPluginLto::LinkerPluginAuto
569                     } else {
570                         LinkerPluginLto::Disabled
571                     };
572                     return true
573                 }
574             }
575
576             *slot = match v {
577                 None => LinkerPluginLto::LinkerPluginAuto,
578                 Some(path) => LinkerPluginLto::LinkerPlugin(PathBuf::from(path)),
579             };
580             true
581         }
582
583         fn parse_switch_with_opt_path(slot: &mut SwitchWithOptPath, v: Option<&str>) -> bool {
584             *slot = match v {
585                 None => SwitchWithOptPath::Enabled(None),
586                 Some(path) => SwitchWithOptPath::Enabled(Some(PathBuf::from(path))),
587             };
588             true
589         }
590
591         fn parse_merge_functions(slot: &mut Option<MergeFunctions>, v: Option<&str>) -> bool {
592             match v.and_then(|s| MergeFunctions::from_str(s).ok()) {
593                 Some(mergefunc) => *slot = Some(mergefunc),
594                 _ => return false,
595             }
596             true
597         }
598
599         fn parse_symbol_mangling_version(
600             slot: &mut SymbolManglingVersion,
601             v: Option<&str>,
602         ) -> bool {
603             *slot = match v {
604                 Some("legacy") => SymbolManglingVersion::Legacy,
605                 Some("v0") => SymbolManglingVersion::V0,
606                 _ => return false,
607             };
608             true
609         }
610     }
611 ) }
612
613 options! {CodegenOptions, CodegenSetter, basic_codegen_options,
614           build_codegen_options, "C", "codegen",
615           CG_OPTIONS, cg_type_desc, cgsetters,
616     ar: Option<String> = (None, parse_opt_string, [UNTRACKED],
617         "this option is deprecated and does nothing"),
618     linker: Option<PathBuf> = (None, parse_opt_pathbuf, [UNTRACKED],
619         "system linker to link outputs with"),
620     link_arg: Vec<String> = (vec![], parse_string_push, [UNTRACKED],
621         "a single extra argument to append to the linker invocation (can be used several times)"),
622     link_args: Option<Vec<String>> = (None, parse_opt_list, [UNTRACKED],
623         "extra arguments to append to the linker invocation (space separated)"),
624     link_dead_code: bool = (false, parse_bool, [UNTRACKED],
625         "don't let linker strip dead code (turning it on can be used for code coverage)"),
626     lto: LtoCli = (LtoCli::Unspecified, parse_lto, [TRACKED],
627         "perform LLVM link-time optimizations"),
628     target_cpu: Option<String> = (None, parse_opt_string, [TRACKED],
629         "select target processor (`rustc --print target-cpus` for details)"),
630     target_feature: String = (String::new(), parse_string, [TRACKED],
631         "target specific attributes. (`rustc --print target-features` for details). \
632         This feature is unsafe."),
633     passes: Vec<String> = (Vec::new(), parse_list, [TRACKED],
634         "a list of extra LLVM passes to run (space separated)"),
635     llvm_args: Vec<String> = (Vec::new(), parse_list, [TRACKED],
636         "a list of arguments to pass to LLVM (space separated)"),
637     save_temps: bool = (false, parse_bool, [UNTRACKED],
638         "save all temporary output files during compilation"),
639     rpath: bool = (false, parse_bool, [UNTRACKED],
640         "set rpath values in libs/exes"),
641     overflow_checks: Option<bool> = (None, parse_opt_bool, [TRACKED],
642         "use overflow checks for integer arithmetic"),
643     no_prepopulate_passes: bool = (false, parse_bool, [TRACKED],
644         "don't pre-populate the pass manager with a list of passes"),
645     no_vectorize_loops: bool = (false, parse_bool, [TRACKED],
646         "don't run the loop vectorization optimization passes"),
647     no_vectorize_slp: bool = (false, parse_bool, [TRACKED],
648         "don't run LLVM's SLP vectorization pass"),
649     soft_float: bool = (false, parse_bool, [TRACKED],
650         "use soft float ABI (*eabihf targets only)"),
651     prefer_dynamic: bool = (false, parse_bool, [TRACKED],
652         "prefer dynamic linking to static linking"),
653     no_integrated_as: bool = (false, parse_bool, [TRACKED],
654         "use an external assembler rather than LLVM's integrated one"),
655     no_redzone: Option<bool> = (None, parse_opt_bool, [TRACKED],
656         "disable the use of the redzone"),
657     relocation_model: Option<String> = (None, parse_opt_string, [TRACKED],
658         "choose the relocation model to use (`rustc --print relocation-models` for details)"),
659     code_model: Option<String> = (None, parse_opt_string, [TRACKED],
660         "choose the code model to use (`rustc --print code-models` for details)"),
661     metadata: Vec<String> = (Vec::new(), parse_list, [TRACKED],
662         "metadata to mangle symbol names with"),
663     extra_filename: String = (String::new(), parse_string, [UNTRACKED],
664         "extra data to put in each output filename"),
665     codegen_units: Option<usize> = (None, parse_opt_uint, [UNTRACKED],
666         "divide crate into N units to optimize in parallel"),
667     remark: Passes = (Passes::Some(Vec::new()), parse_passes, [UNTRACKED],
668         "print remarks for these optimization passes (space separated, or \"all\")"),
669     no_stack_check: bool = (false, parse_bool, [UNTRACKED],
670         "the `--no-stack-check` flag is deprecated and does nothing"),
671     debuginfo: Option<usize> = (None, parse_opt_uint, [TRACKED],
672         "debug info emission level, 0 = no debug info, 1 = line tables only, \
673          2 = full debug info with variable and type information"),
674     opt_level: Option<String> = (None, parse_opt_string, [TRACKED],
675         "optimize with possible levels 0-3, s, or z"),
676     force_frame_pointers: Option<bool> = (None, parse_opt_bool, [TRACKED],
677         "force use of the frame pointers"),
678     debug_assertions: Option<bool> = (None, parse_opt_bool, [TRACKED],
679         "explicitly enable the `cfg(debug_assertions)` directive"),
680     inline_threshold: Option<usize> = (None, parse_opt_uint, [TRACKED],
681         "set the threshold for inlining a function (default: 225)"),
682     panic: Option<PanicStrategy> = (None, parse_panic_strategy,
683         [TRACKED], "panic strategy to compile crate with"),
684     incremental: Option<String> = (None, parse_opt_string, [UNTRACKED],
685         "enable incremental compilation"),
686     default_linker_libraries: Option<bool> = (None, parse_opt_bool, [UNTRACKED],
687         "allow the linker to link its default libraries"),
688     linker_flavor: Option<LinkerFlavor> = (None, parse_linker_flavor, [UNTRACKED],
689                                            "linker flavor"),
690     linker_plugin_lto: LinkerPluginLto = (LinkerPluginLto::Disabled,
691         parse_linker_plugin_lto, [TRACKED],
692         "generate build artifacts that are compatible with linker-based LTO."),
693     profile_generate: SwitchWithOptPath = (SwitchWithOptPath::Disabled,
694         parse_switch_with_opt_path, [TRACKED],
695         "compile the program with profiling instrumentation"),
696     profile_use: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
697         "use the given `.profdata` file for profile-guided optimization"),
698 }
699
700 options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
701           build_debugging_options, "Z", "debugging",
702           DB_OPTIONS, db_type_desc, dbsetters,
703     codegen_backend: Option<String> = (None, parse_opt_string, [TRACKED],
704         "the backend to use"),
705     verbose: bool = (false, parse_bool, [UNTRACKED],
706         "in general, enable more debug printouts"),
707     span_free_formats: bool = (false, parse_bool, [UNTRACKED],
708         "when debug-printing compiler state, do not include spans"), // o/w tests have closure@path
709     identify_regions: bool = (false, parse_bool, [UNTRACKED],
710         "make unnamed regions display as '# (where # is some non-ident unique id)"),
711     borrowck: Option<String> = (None, parse_opt_string, [UNTRACKED],
712         "select which borrowck is used (`mir` or `migrate`)"),
713     time_passes: bool = (false, parse_bool, [UNTRACKED],
714         "measure time of each rustc pass"),
715     time: bool = (false, parse_bool, [UNTRACKED],
716         "measure time of rustc processes"),
717     time_llvm_passes: bool = (false, parse_bool, [UNTRACKED],
718         "measure time of each LLVM pass"),
719     input_stats: bool = (false, parse_bool, [UNTRACKED],
720         "gather statistics about the input"),
721     asm_comments: bool = (false, parse_bool, [TRACKED],
722         "generate comments into the assembly (may change behavior)"),
723     verify_llvm_ir: bool = (false, parse_bool, [TRACKED],
724         "verify LLVM IR"),
725     borrowck_stats: bool = (false, parse_bool, [UNTRACKED],
726         "gather borrowck statistics"),
727     no_landing_pads: bool = (false, parse_bool, [TRACKED],
728         "omit landing pads for unwinding"),
729     fewer_names: bool = (false, parse_bool, [TRACKED],
730         "reduce memory use by retaining fewer names within compilation artifacts (LLVM-IR)"),
731     meta_stats: bool = (false, parse_bool, [UNTRACKED],
732         "gather metadata statistics"),
733     print_link_args: bool = (false, parse_bool, [UNTRACKED],
734         "print the arguments passed to the linker"),
735     print_llvm_passes: bool = (false, parse_bool, [UNTRACKED],
736         "prints the LLVM optimization passes being run"),
737     ast_json: bool = (false, parse_bool, [UNTRACKED],
738         "print the AST as JSON and halt"),
739     // We default to 1 here since we want to behave like
740     // a sequential compiler for now. This'll likely be adjusted
741     // in the future. Note that -Zthreads=0 is the way to get
742     // the num_cpus behavior.
743     threads: usize = (1, parse_threads, [UNTRACKED],
744         "use a thread pool with N threads"),
745     ast_json_noexpand: bool = (false, parse_bool, [UNTRACKED],
746         "print the pre-expansion AST as JSON and halt"),
747     ls: bool = (false, parse_bool, [UNTRACKED],
748         "list the symbols defined by a library crate"),
749     save_analysis: bool = (false, parse_bool, [UNTRACKED],
750         "write syntax and type analysis (in JSON format) information, in \
751          addition to normal output"),
752     print_region_graph: bool = (false, parse_bool, [UNTRACKED],
753         "prints region inference graph. \
754          Use with RUST_REGION_GRAPH=help for more info"),
755     parse_only: bool = (false, parse_bool, [UNTRACKED],
756         "parse only; do not compile, assemble, or link"),
757     dual_proc_macros: bool = (false, parse_bool, [TRACKED],
758         "load proc macros for both target and host, but only link to the target"),
759     no_codegen: bool = (false, parse_bool, [TRACKED],
760         "run all passes except codegen; no output"),
761     treat_err_as_bug: Option<usize> = (None, parse_treat_err_as_bug, [TRACKED],
762         "treat error number `val` that occurs as bug"),
763     report_delayed_bugs: bool = (false, parse_bool, [TRACKED],
764         "immediately print bugs registered with `delay_span_bug`"),
765     external_macro_backtrace: bool = (false, parse_bool, [UNTRACKED],
766         "show macro backtraces even for non-local macros"),
767     teach: bool = (false, parse_bool, [TRACKED],
768         "show extended diagnostic help"),
769     terminal_width: Option<usize> = (None, parse_opt_uint, [UNTRACKED],
770         "set the current terminal width"),
771     panic_abort_tests: bool = (false, parse_bool, [TRACKED],
772         "support compiling tests with panic=abort"),
773     continue_parse_after_error: bool = (false, parse_bool, [TRACKED],
774         "attempt to recover from parse errors (experimental)"),
775     dep_tasks: bool = (false, parse_bool, [UNTRACKED],
776         "print tasks that execute and the color their dep node gets (requires debug build)"),
777     incremental: Option<String> = (None, parse_opt_string, [UNTRACKED],
778         "enable incremental compilation (experimental)"),
779     incremental_queries: bool = (true, parse_bool, [UNTRACKED],
780         "enable incremental compilation support for queries (experimental)"),
781     incremental_info: bool = (false, parse_bool, [UNTRACKED],
782         "print high-level information about incremental reuse (or the lack thereof)"),
783     incremental_dump_hash: bool = (false, parse_bool, [UNTRACKED],
784         "dump hash information in textual format to stdout"),
785     incremental_verify_ich: bool = (false, parse_bool, [UNTRACKED],
786         "verify incr. comp. hashes of green query instances"),
787     incremental_ignore_spans: bool = (false, parse_bool, [UNTRACKED],
788         "ignore spans during ICH computation -- used for testing"),
789     instrument_mcount: bool = (false, parse_bool, [TRACKED],
790         "insert function instrument code for mcount-based tracing"),
791     dump_dep_graph: bool = (false, parse_bool, [UNTRACKED],
792         "dump the dependency graph to $RUST_DEP_GRAPH (default: /tmp/dep_graph.gv)"),
793     query_dep_graph: bool = (false, parse_bool, [UNTRACKED],
794         "enable queries of the dependency graph for regression testing"),
795     no_analysis: bool = (false, parse_bool, [UNTRACKED],
796         "parse and expand the source, but run no analysis"),
797     unstable_options: bool = (false, parse_bool, [UNTRACKED],
798         "adds unstable command line options to rustc interface"),
799     force_overflow_checks: Option<bool> = (None, parse_opt_bool, [TRACKED],
800         "force overflow checks on or off"),
801     trace_macros: bool = (false, parse_bool, [UNTRACKED],
802         "for every macro invocation, print its name and arguments"),
803     debug_macros: bool = (false, parse_bool, [TRACKED],
804         "emit line numbers debug info inside macros"),
805     generate_arange_section: bool = (true, parse_bool, [TRACKED],
806         "generate DWARF address ranges for faster lookups"),
807     keep_hygiene_data: bool = (false, parse_bool, [UNTRACKED],
808         "don't clear the hygiene data after analysis"),
809     keep_ast: bool = (false, parse_bool, [UNTRACKED],
810         "keep the AST after lowering it to HIR"),
811     show_span: Option<String> = (None, parse_opt_string, [TRACKED],
812         "show spans for compiler debugging (expr|pat|ty)"),
813     print_type_sizes: bool = (false, parse_bool, [UNTRACKED],
814         "print layout information for each type encountered"),
815     print_mono_items: Option<String> = (None, parse_opt_string, [UNTRACKED],
816         "print the result of the monomorphization collection pass"),
817     mir_opt_level: usize = (1, parse_uint, [TRACKED],
818         "set the MIR optimization level (0-3, default: 1)"),
819     mutable_noalias: Option<bool> = (None, parse_opt_bool, [TRACKED],
820         "emit noalias metadata for mutable references (default: no)"),
821     dump_mir: Option<String> = (None, parse_opt_string, [UNTRACKED],
822         "dump MIR state to file.
823         `val` is used to select which passes and functions to dump. For example:
824         `all` matches all passes and functions,
825         `foo` matches all passes for functions whose name contains 'foo',
826         `foo & ConstProp` only the 'ConstProp' pass for function names containing 'foo',
827         `foo | bar` all passes for function names containing 'foo' or 'bar'."),
828
829     dump_mir_dir: String = (String::from("mir_dump"), parse_string, [UNTRACKED],
830         "the directory the MIR is dumped into"),
831     dump_mir_graphviz: bool = (false, parse_bool, [UNTRACKED],
832         "in addition to `.mir` files, create graphviz `.dot` files"),
833     dump_mir_exclude_pass_number: bool = (false, parse_bool, [UNTRACKED],
834         "if set, exclude the pass number when dumping MIR (used in tests)"),
835     mir_emit_retag: bool = (false, parse_bool, [TRACKED],
836         "emit Retagging MIR statements, interpreted e.g., by miri; implies -Zmir-opt-level=0"),
837     perf_stats: bool = (false, parse_bool, [UNTRACKED],
838         "print some performance-related statistics"),
839     query_stats: bool = (false, parse_bool, [UNTRACKED],
840         "print some statistics about the query system"),
841     hir_stats: bool = (false, parse_bool, [UNTRACKED],
842         "print some statistics about AST and HIR"),
843     always_encode_mir: bool = (false, parse_bool, [TRACKED],
844         "encode MIR of all functions into the crate metadata"),
845     json_rendered: Option<String> = (None, parse_opt_string, [UNTRACKED],
846         "describes how to render the `rendered` field of json diagnostics"),
847     unleash_the_miri_inside_of_you: bool = (false, parse_bool, [TRACKED],
848         "take the breaks off const evaluation. NOTE: this is unsound"),
849     osx_rpath_install_name: bool = (false, parse_bool, [TRACKED],
850         "pass `-install_name @rpath/...` to the macOS linker"),
851     sanitizer: Option<Sanitizer> = (None, parse_sanitizer, [TRACKED],
852                                     "use a sanitizer"),
853     sanitizer_recover: Vec<Sanitizer> = (vec![], parse_sanitizer_list, [TRACKED],
854         "Enable recovery for selected sanitizers"),
855     sanitizer_memory_track_origins: usize = (0, parse_sanitizer_memory_track_origins, [TRACKED],
856         "Enable origins tracking in MemorySanitizer"),
857     fuel: Option<(String, u64)> = (None, parse_optimization_fuel, [TRACKED],
858         "set the optimization fuel quota for a crate"),
859     print_fuel: Option<String> = (None, parse_opt_string, [TRACKED],
860         "make rustc print the total optimization fuel used by a crate"),
861     force_unstable_if_unmarked: bool = (false, parse_bool, [TRACKED],
862         "force all crates to be `rustc_private` unstable"),
863     pre_link_arg: Vec<String> = (vec![], parse_string_push, [UNTRACKED],
864         "a single extra argument to prepend the linker invocation (can be used several times)"),
865     pre_link_args: Option<Vec<String>> = (None, parse_opt_list, [UNTRACKED],
866         "extra arguments to prepend to the linker invocation (space separated)"),
867     profile: bool = (false, parse_bool, [TRACKED],
868                      "insert profiling code"),
869     relro_level: Option<RelroLevel> = (None, parse_relro_level, [TRACKED],
870         "choose which RELRO level to use"),
871     nll_facts: bool = (false, parse_bool, [UNTRACKED],
872                        "dump facts from NLL analysis into side files"),
873     nll_dont_emit_read_for_match: bool = (false, parse_bool, [UNTRACKED],
874         "in match codegen, do not include FakeRead statements (used by mir-borrowck)"),
875     dont_buffer_diagnostics: bool = (false, parse_bool, [UNTRACKED],
876         "emit diagnostics rather than buffering (breaks NLL error downgrading, sorting)."),
877     polonius: bool = (false, parse_bool, [UNTRACKED],
878         "enable polonius-based borrow-checker"),
879     codegen_time_graph: bool = (false, parse_bool, [UNTRACKED],
880         "generate a graphical HTML report of time spent in codegen and LLVM"),
881     thinlto: Option<bool> = (None, parse_opt_bool, [TRACKED],
882         "enable ThinLTO when possible"),
883     inline_in_all_cgus: Option<bool> = (None, parse_opt_bool, [TRACKED],
884         "control whether `#[inline]` functions are in all CGUs"),
885     tls_model: Option<String> = (None, parse_opt_string, [TRACKED],
886         "choose the TLS model to use (`rustc --print tls-models` for details)"),
887     saturating_float_casts: bool = (false, parse_bool, [TRACKED],
888         "make float->int casts UB-free: numbers outside the integer type's range are clipped to \
889          the max/min integer respectively, and NaN is mapped to 0"),
890     human_readable_cgu_names: bool = (false, parse_bool, [TRACKED],
891         "generate human-readable, predictable names for codegen units"),
892     dep_info_omit_d_target: bool = (false, parse_bool, [TRACKED],
893         "in dep-info output, omit targets for tracking dependencies of the dep-info files \
894          themselves"),
895     unpretty: Option<String> = (None, parse_unpretty, [UNTRACKED],
896         "present the input source, unstable (and less-pretty) variants;
897         valid types are any of the types for `--pretty`, as well as:
898         `expanded`, `expanded,identified`,
899         `expanded,hygiene` (with internal representations),
900         `everybody_loops` (all function bodies replaced with `loop {}`),
901         `hir` (the HIR), `hir,identified`,
902         `hir,typed` (HIR with types for each node),
903         `hir-tree` (dump the raw HIR),
904         `mir` (the MIR), or `mir-cfg` (graphviz formatted MIR)"),
905     run_dsymutil: Option<bool> = (None, parse_opt_bool, [TRACKED],
906         "run `dsymutil` and delete intermediate object files"),
907     ui_testing: bool = (false, parse_bool, [UNTRACKED],
908         "format compiler diagnostics in a way that's better suitable for UI testing"),
909     embed_bitcode: bool = (false, parse_bool, [TRACKED],
910         "embed LLVM bitcode in object files"),
911     strip_debuginfo_if_disabled: Option<bool> = (None, parse_opt_bool, [TRACKED],
912         "tell the linker to strip debuginfo when building without debuginfo enabled."),
913     share_generics: Option<bool> = (None, parse_opt_bool, [TRACKED],
914         "make the current crate share its generic instantiations"),
915     chalk: bool = (false, parse_bool, [TRACKED],
916         "enable the experimental Chalk-based trait solving engine"),
917     no_parallel_llvm: bool = (false, parse_bool, [UNTRACKED],
918         "don't run LLVM in parallel (while keeping codegen-units and ThinLTO)"),
919     no_leak_check: bool = (false, parse_bool, [UNTRACKED],
920         "disables the 'leak check' for subtyping; unsound, but useful for tests"),
921     no_interleave_lints: bool = (false, parse_bool, [UNTRACKED],
922         "don't interleave execution of lints; allows benchmarking individual lints"),
923     crate_attr: Vec<String> = (Vec::new(), parse_string_push, [TRACKED],
924         "inject the given attribute in the crate"),
925     self_profile: SwitchWithOptPath = (SwitchWithOptPath::Disabled,
926         parse_switch_with_opt_path, [UNTRACKED],
927         "run the self profiler and output the raw event data"),
928     self_profile_events: Option<Vec<String>> = (None, parse_opt_comma_list, [UNTRACKED],
929         "specifies which kinds of events get recorded by the self profiler"),
930     emit_stack_sizes: bool = (false, parse_bool, [UNTRACKED],
931         "emits a section containing stack size metadata"),
932     plt: Option<bool> = (None, parse_opt_bool, [TRACKED],
933           "whether to use the PLT when calling into shared libraries;
934           only has effect for PIC code on systems with ELF binaries
935           (default: PLT is disabled if full relro is enabled)"),
936     merge_functions: Option<MergeFunctions> = (None, parse_merge_functions, [TRACKED],
937         "control the operation of the MergeFunctions LLVM pass, taking
938          the same values as the target option of the same name"),
939     allow_features: Option<Vec<String>> = (None, parse_opt_comma_list, [TRACKED],
940         "only allow the listed language features to be enabled in code (space separated)"),
941     symbol_mangling_version: SymbolManglingVersion = (SymbolManglingVersion::Legacy,
942         parse_symbol_mangling_version, [TRACKED],
943         "which mangling version to use for symbol names"),
944     binary_dep_depinfo: bool = (false, parse_bool, [TRACKED],
945         "include artifacts (sysroot, crate dependencies) used during compilation in dep-info"),
946     insert_sideeffect: bool = (false, parse_bool, [TRACKED],
947         "fix undefined behavior when a thread doesn't eventually make progress \
948          (such as entering an empty infinite loop) by inserting llvm.sideeffect"),
949 }