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