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