]> git.proxmox.com Git - rustc.git/blame - compiler/rustc_session/src/options.rs
New upstream version 1.70.0+dfsg1
[rustc.git] / compiler / rustc_session / src / options.rs
CommitLineData
dfeec247
XL
1use crate::config::*;
2
3use crate::early_error;
4use crate::lint;
5use crate::search_paths::SearchPath;
17df50a5 6use crate::utils::NativeLib;
353b0b11 7use rustc_data_structures::profiling::TimePassesFormat;
9ffffee4 8use rustc_errors::{LanguageIdentifier, TerminalUrl};
f2b60f7d 9use rustc_target::spec::{CodeModel, LinkerFlavorCli, MergeFunctions, PanicStrategy, SanitizerSet};
3c0e092e
XL
10use rustc_target::spec::{
11 RelocModel, RelroLevel, SplitDebuginfo, StackProtector, TargetTriple, TlsModel,
12};
dfeec247
XL
13
14use rustc_feature::UnstableFeatures;
15use rustc_span::edition::Edition;
94222f64 16use rustc_span::RealFileName;
ba9703b0 17use rustc_span::SourceFileHashAlgorithm;
dfeec247 18
dfeec247
XL
19use std::collections::BTreeMap;
20
21use std::collections::hash_map::DefaultHasher;
22use std::hash::Hasher;
6a06907d 23use std::num::NonZeroUsize;
dfeec247
XL
24use std::path::PathBuf;
25use std::str;
26
cdc7bbd5
XL
27macro_rules! insert {
28 ($opt_name:ident, $opt_expr:expr, $sub_hashes:expr) => {
dfeec247
XL
29 if $sub_hashes
30 .insert(stringify!($opt_name), $opt_expr as &dyn dep_tracking::DepTrackingHash)
31 .is_some()
32 {
33 panic!("duplicate key in CLI DepTrackingHash: {}", stringify!($opt_name))
34 }
cdc7bbd5
XL
35 };
36}
37
38macro_rules! hash_opt {
39 ($opt_name:ident, $opt_expr:expr, $sub_hashes:expr, $_for_crate_hash: ident, [UNTRACKED]) => {{}};
40 ($opt_name:ident, $opt_expr:expr, $sub_hashes:expr, $_for_crate_hash: ident, [TRACKED]) => {{ insert!($opt_name, $opt_expr, $sub_hashes) }};
41 ($opt_name:ident, $opt_expr:expr, $sub_hashes:expr, $for_crate_hash: ident, [TRACKED_NO_CRATE_HASH]) => {{
42 if !$for_crate_hash {
43 insert!($opt_name, $opt_expr, $sub_hashes)
44 }
dfeec247 45 }};
cdc7bbd5
XL
46 ($opt_name:ident, $opt_expr:expr, $sub_hashes:expr, $_for_crate_hash: ident, [SUBSTRUCT]) => {{}};
47}
48
49macro_rules! hash_substruct {
50 ($opt_name:ident, $opt_expr:expr, $error_format:expr, $for_crate_hash:expr, $hasher:expr, [UNTRACKED]) => {{}};
51 ($opt_name:ident, $opt_expr:expr, $error_format:expr, $for_crate_hash:expr, $hasher:expr, [TRACKED]) => {{}};
52 ($opt_name:ident, $opt_expr:expr, $error_format:expr, $for_crate_hash:expr, $hasher:expr, [TRACKED_NO_CRATE_HASH]) => {{}};
53 ($opt_name:ident, $opt_expr:expr, $error_format:expr, $for_crate_hash:expr, $hasher:expr, [SUBSTRUCT]) => {
54 use crate::config::dep_tracking::DepTrackingHash;
136023e0
XL
55 $opt_expr.dep_tracking_hash($for_crate_hash, $error_format).hash(
56 $hasher,
57 $error_format,
58 $for_crate_hash,
59 );
cdc7bbd5 60 };
dfeec247
XL
61}
62
63macro_rules! top_level_options {
cdc7bbd5
XL
64 ( $( #[$top_level_attr:meta] )* pub struct Options { $(
65 $( #[$attr:meta] )*
66 $opt:ident : $t:ty [$dep_tracking_marker:ident],
dfeec247
XL
67 )* } ) => (
68 #[derive(Clone)]
cdc7bbd5 69 $( #[$top_level_attr] )*
dfeec247 70 pub struct Options {
cdc7bbd5
XL
71 $(
72 $( #[$attr] )*
73 pub $opt: $t
74 ),*
dfeec247
XL
75 }
76
77 impl Options {
cdc7bbd5 78 pub fn dep_tracking_hash(&self, for_crate_hash: bool) -> u64 {
dfeec247
XL
79 let mut sub_hashes = BTreeMap::new();
80 $({
cdc7bbd5
XL
81 hash_opt!($opt,
82 &self.$opt,
83 &mut sub_hashes,
84 for_crate_hash,
85 [$dep_tracking_marker]);
dfeec247
XL
86 })*
87 let mut hasher = DefaultHasher::new();
88 dep_tracking::stable_hash(sub_hashes,
89 &mut hasher,
136023e0
XL
90 self.error_format,
91 for_crate_hash);
cdc7bbd5
XL
92 $({
93 hash_substruct!($opt,
94 &self.$opt,
95 self.error_format,
96 for_crate_hash,
97 &mut hasher,
98 [$dep_tracking_marker]);
99 })*
dfeec247
XL
100 hasher.finish()
101 }
102 }
103 );
104}
105
dfeec247 106top_level_options!(
cdc7bbd5
XL
107 /// The top-level command-line options struct.
108 ///
109 /// For each option, one has to specify how it behaves with regard to the
110 /// dependency tracking system of incremental compilation. This is done via the
111 /// square-bracketed directive after the field type. The options are:
112 ///
113 /// - `[TRACKED]`
114 /// A change in the given field will cause the compiler to completely clear the
115 /// incremental compilation cache before proceeding.
116 ///
117 /// - `[TRACKED_NO_CRATE_HASH]`
118 /// Same as `[TRACKED]`, but will not affect the crate hash. This is useful for options that only
119 /// affect the incremental cache.
120 ///
121 /// - `[UNTRACKED]`
122 /// Incremental compilation is not influenced by this option.
123 ///
124 /// - `[SUBSTRUCT]`
125 /// Second-level sub-structs containing more options.
126 ///
127 /// If you add a new option to this struct or one of the sub-structs like
128 /// `CodegenOptions`, think about how it influences incremental compilation. If in
129 /// doubt, specify `[TRACKED]`, which is always "correct" but might lead to
130 /// unnecessary re-compilation.
f2b60f7d 131 #[rustc_lint_opt_ty]
dfeec247 132 pub struct Options {
cdc7bbd5
XL
133 /// The crate config requested for the session, which may be combined
134 /// with additional crate configurations during the compile process.
f2b60f7d 135 #[rustc_lint_opt_deny_field_access("use `Session::crate_types` instead of this field")]
dfeec247
XL
136 crate_types: Vec<CrateType> [TRACKED],
137 optimize: OptLevel [TRACKED],
cdc7bbd5
XL
138 /// Include the `debug_assertions` flag in dependency tracking, since it
139 /// can influence whether overflow checks are done or not.
dfeec247
XL
140 debug_assertions: bool [TRACKED],
141 debuginfo: DebugInfo [TRACKED],
136023e0
XL
142 lint_opts: Vec<(String, lint::Level)> [TRACKED_NO_CRATE_HASH],
143 lint_cap: Option<lint::Level> [TRACKED_NO_CRATE_HASH],
dfeec247
XL
144 describe_lints: bool [UNTRACKED],
145 output_types: OutputTypes [TRACKED],
146 search_paths: Vec<SearchPath> [UNTRACKED],
17df50a5 147 libs: Vec<NativeLib> [TRACKED],
dfeec247
XL
148 maybe_sysroot: Option<PathBuf> [UNTRACKED],
149
150 target_triple: TargetTriple [TRACKED],
151
152 test: bool [TRACKED],
153 error_format: ErrorOutputType [UNTRACKED],
064997fb 154 diagnostic_width: Option<usize> [UNTRACKED],
dfeec247 155
cdc7bbd5
XL
156 /// If `Some`, enable incremental compilation, using the given
157 /// directory to store intermediate results.
dfeec247 158 incremental: Option<PathBuf> [UNTRACKED],
3c0e092e 159 assert_incr_state: Option<IncrementalStateAssertion> [UNTRACKED],
dfeec247 160
064997fb 161 unstable_opts: UnstableOptions [SUBSTRUCT],
dfeec247 162 prints: Vec<PrintRequest> [UNTRACKED],
cdc7bbd5 163 cg: CodegenOptions [SUBSTRUCT],
dfeec247
XL
164 externs: Externs [UNTRACKED],
165 crate_name: Option<String> [TRACKED],
cdc7bbd5 166 /// Indicates how the compiler should treat unstable features.
dfeec247
XL
167 unstable_features: UnstableFeatures [TRACKED],
168
cdc7bbd5
XL
169 /// Indicates whether this run of the compiler is actually rustdoc. This
170 /// is currently just a hack and will be removed eventually, so please
171 /// try to not rely on this too much.
dfeec247 172 actually_rustdoc: bool [TRACKED],
9ffffee4
FG
173 /// Whether name resolver should resolve documentation links.
174 resolve_doc_links: ResolveDocLinks [TRACKED],
dfeec247 175
cdc7bbd5 176 /// Control path trimming.
1b1a35ee
XL
177 trimmed_def_paths: TrimmedDefPaths [TRACKED],
178
cdc7bbd5
XL
179 /// Specifications of codegen units / ThinLTO which are forced as a
180 /// result of parsing command line options. These are not necessarily
181 /// what rustc was invoked with, but massaged a bit to agree with
182 /// commands like `--emit llvm-ir` which they're often incompatible with
183 /// if we otherwise use the defaults of rustc.
f2b60f7d 184 #[rustc_lint_opt_deny_field_access("use `Session::codegen_units` instead of this field")]
dfeec247 185 cli_forced_codegen_units: Option<usize> [UNTRACKED],
f2b60f7d 186 #[rustc_lint_opt_deny_field_access("use `Session::lto` instead of this field")]
487cf647 187 cli_forced_local_thinlto_off: bool [UNTRACKED],
dfeec247 188
cdc7bbd5
XL
189 /// Remap source path prefixes in all output (messages, object files, debug, etc.).
190 remap_path_prefix: Vec<(PathBuf, PathBuf)> [TRACKED_NO_CRATE_HASH],
191 /// Base directory containing the `src/` for the Rust standard library, and
2b03887a 192 /// potentially `rustc` as well, if we can find it. Right now it's always
cdc7bbd5
XL
193 /// `$sysroot/lib/rustlib/src/rust` (i.e. the `rustup` `rust-src` component).
194 ///
195 /// This directory is what the virtual `/rustc/$hash` is translated back to,
196 /// if Rust was built with path remapping to `/rustc/$hash` enabled
197 /// (the `rust.remap-debuginfo` option in `config.toml`).
198 real_rust_source_base_dir: Option<PathBuf> [TRACKED_NO_CRATE_HASH],
dfeec247
XL
199
200 edition: Edition [TRACKED],
201
cdc7bbd5
XL
202 /// `true` if we're emitting JSON blobs about each artifact produced
203 /// by the compiler.
dfeec247
XL
204 json_artifact_notifications: bool [TRACKED],
205
cdc7bbd5 206 /// `true` if we're emitting a JSON blob containing the unused externs
04454e1e 207 json_unused_externs: JsonUnusedExterns [UNTRACKED],
cdc7bbd5 208
5e7ed085 209 /// `true` if we're emitting a JSON job containing a future-incompat report for lints
a2a8927a
XL
210 json_future_incompat: bool [TRACKED],
211
dfeec247 212 pretty: Option<PpMode> [UNTRACKED],
94222f64
XL
213
214 /// The (potentially remapped) working directory
215 working_dir: RealFileName [TRACKED],
dfeec247
XL
216 }
217);
218
219/// Defines all `CodegenOptions`/`DebuggingOptions` fields and parsers all at once. The goal of this
220/// macro is to define an interface that can be programmatically used by the option parser
221/// to initialize the struct without hardcoding field names all over the place.
222///
223/// The goal is to invoke this macro once with the correct fields, and then this macro generates all
224/// necessary code. The main gotcha of this macro is the `cgsetters` module which is a bunch of
225/// generated code to parse an option into its respective field in the struct. There are a few
226/// hand-written parsers for parsing specific types of values in this module.
227macro_rules! options {
3c0e092e 228 ($struct_name:ident, $stat:ident, $optmod:ident, $prefix:expr, $outputname:expr,
cdc7bbd5 229 $($( #[$attr:meta] )* $opt:ident : $t:ty = (
dfeec247
XL
230 $init:expr,
231 $parse:ident,
cdc7bbd5 232 [$dep_tracking_marker:ident],
dfeec247
XL
233 $desc:expr)
234 ),* ,) =>
235(
236 #[derive(Clone)]
f2b60f7d 237 #[rustc_lint_opt_ty]
064997fb 238 pub struct $struct_name { $( $( #[$attr] )* pub $opt: $t),* }
dfeec247 239
17df50a5
XL
240 impl Default for $struct_name {
241 fn default() -> $struct_name {
064997fb 242 $struct_name { $($opt: $init),* }
dfeec247 243 }
dfeec247
XL
244 }
245
cdc7bbd5 246 impl $struct_name {
17df50a5
XL
247 pub fn build(
248 matches: &getopts::Matches,
249 error_format: ErrorOutputType,
250 ) -> $struct_name {
251 build_options(matches, $stat, $prefix, $outputname, error_format)
252 }
253
136023e0 254 fn dep_tracking_hash(&self, for_crate_hash: bool, error_format: ErrorOutputType) -> u64 {
dfeec247
XL
255 let mut sub_hashes = BTreeMap::new();
256 $({
cdc7bbd5
XL
257 hash_opt!($opt,
258 &self.$opt,
259 &mut sub_hashes,
136023e0 260 for_crate_hash,
cdc7bbd5 261 [$dep_tracking_marker]);
dfeec247 262 })*
cdc7bbd5
XL
263 let mut hasher = DefaultHasher::new();
264 dep_tracking::stable_hash(sub_hashes,
265 &mut hasher,
136023e0
XL
266 error_format,
267 for_crate_hash
268 );
cdc7bbd5 269 hasher.finish()
dfeec247
XL
270 }
271 }
272
17df50a5 273 pub const $stat: OptionDescrs<$struct_name> =
3c0e092e 274 &[ $( (stringify!($opt), $optmod::$opt, desc::$parse, $desc) ),* ];
dfeec247 275
3c0e092e 276 mod $optmod {
17df50a5 277 $(
3c0e092e
XL
278 pub(super) fn $opt(cg: &mut super::$struct_name, v: Option<&str>) -> bool {
279 super::parse::$parse(&mut redirect_field!(cg.$opt), v)
ba9703b0 280 }
17df50a5 281 )*
3c0e092e 282 }
ba9703b0 283
17df50a5 284) }
dfeec247 285
064997fb
FG
286impl CodegenOptions {
287 // JUSTIFICATION: defn of the suggested wrapper fn
f2b60f7d 288 #[allow(rustc::bad_opt_access)]
064997fb
FG
289 pub fn instrument_coverage(&self) -> InstrumentCoverage {
290 self.instrument_coverage.unwrap_or(InstrumentCoverage::Off)
291 }
292}
293
17df50a5
XL
294// Sometimes different options need to build a common structure.
295// That structure can be kept in one of the options' fields, the others become dummy.
296macro_rules! redirect_field {
297 ($cg:ident.link_arg) => {
298 $cg.link_args
299 };
300 ($cg:ident.pre_link_arg) => {
301 $cg.pre_link_args
302 };
303 ($cg:ident.$field:ident) => {
304 $cg.$field
305 };
306}
307
308type OptionSetter<O> = fn(&mut O, v: Option<&str>) -> bool;
309type OptionDescrs<O> = &'static [(&'static str, OptionSetter<O>, &'static str, &'static str)];
310
311fn build_options<O: Default>(
312 matches: &getopts::Matches,
313 descrs: OptionDescrs<O>,
314 prefix: &str,
315 outputname: &str,
316 error_format: ErrorOutputType,
317) -> O {
318 let mut op = O::default();
319 for option in matches.opt_strs(prefix) {
320 let (key, value) = match option.split_once('=') {
321 None => (option, None),
322 Some((k, v)) => (k.to_string(), Some(v)),
323 };
324
a2a8927a 325 let option_to_lookup = key.replace('-', "_");
17df50a5
XL
326 match descrs.iter().find(|(name, ..)| *name == option_to_lookup) {
327 Some((_, setter, type_desc, _)) => {
328 if !setter(&mut op, value) {
329 match value {
330 None => early_error(
331 error_format,
332 &format!(
333 "{0} option `{1}` requires {2} ({3} {1}=<value>)",
334 outputname, key, type_desc, prefix
335 ),
336 ),
337 Some(value) => early_error(
338 error_format,
339 &format!(
5e7ed085 340 "incorrect value `{value}` for {outputname} option `{key}` - {type_desc} was expected"
17df50a5
XL
341 ),
342 ),
343 }
344 }
ba9703b0 345 }
5e7ed085 346 None => early_error(error_format, &format!("unknown {outputname} option: `{key}`")),
ba9703b0 347 }
17df50a5
XL
348 }
349 return op;
350}
351
352#[allow(non_upper_case_globals)]
353mod desc {
354 pub const parse_no_flag: &str = "no value";
9ffffee4 355 pub const parse_bool: &str = "one of: `y`, `yes`, `on`, `true`, `n`, `no`, `off` or `false`";
17df50a5
XL
356 pub const parse_opt_bool: &str = parse_bool;
357 pub const parse_string: &str = "a string";
358 pub const parse_opt_string: &str = parse_string;
359 pub const parse_string_push: &str = parse_string;
04454e1e 360 pub const parse_opt_langid: &str = "a language identifier";
17df50a5
XL
361 pub const parse_opt_pathbuf: &str = "a path";
362 pub const parse_list: &str = "a space-separated list of strings";
04454e1e
FG
363 pub const parse_list_with_polarity: &str =
364 "a comma-separated list of strings, with elements beginning with + or -";
17df50a5
XL
365 pub const parse_opt_comma_list: &str = "a comma-separated list of strings";
366 pub const parse_number: &str = "a number";
367 pub const parse_opt_number: &str = parse_number;
368 pub const parse_threads: &str = parse_number;
353b0b11 369 pub const parse_time_passes_format: &str = "`text` (default) or `json`";
17df50a5
XL
370 pub const parse_passes: &str = "a space-separated list of passes, or `all`";
371 pub const parse_panic_strategy: &str = "either `unwind` or `abort`";
c295e0f8 372 pub const parse_opt_panic_strategy: &str = parse_panic_strategy;
5e7ed085 373 pub const parse_oom_strategy: &str = "either `panic` or `abort`";
17df50a5 374 pub const parse_relro_level: &str = "one of: `full`, `partial`, or `off`";
9ffffee4 375 pub const parse_sanitizers: &str = "comma separated list of sanitizers: `address`, `cfi`, `hwaddress`, `kcfi`, `kernel-address`, `leak`, `memory`, `memtag`, `shadow-call-stack`, or `thread`";
17df50a5
XL
376 pub const parse_sanitizer_memory_track_origins: &str = "0, 1, or 2";
377 pub const parse_cfguard: &str =
378 "either a boolean (`yes`, `no`, `on`, `off`, etc), `checks`, or `nochecks`";
5099ac24 379 pub const parse_cfprotection: &str = "`none`|`no`|`n` (default), `branch`, `return`, or `full`|`yes`|`y` (equivalent to `branch` and `return`)";
353b0b11 380 pub const parse_debuginfo: &str = "either an integer (0, 1, 2), `none`, `line-directives-only`, `line-tables-only`, `limited`, or `full`";
17df50a5 381 pub const parse_strip: &str = "either `none`, `debuginfo`, or `symbols`";
f2b60f7d 382 pub const parse_linker_flavor: &str = ::rustc_target::spec::LinkerFlavorCli::one_of();
17df50a5
XL
383 pub const parse_optimization_fuel: &str = "crate=integer";
384 pub const parse_mir_spanview: &str = "`statement` (default), `terminator`, or `block`";
9c376795 385 pub const parse_dump_mono_stats: &str = "`markdown` (default) or `json`";
17df50a5
XL
386 pub const parse_instrument_coverage: &str =
387 "`all` (default), `except-unused-generics`, `except-unused-functions`, or `off`";
9ffffee4 388 pub const parse_instrument_xray: &str = "either a boolean (`yes`, `no`, `on`, `off`, etc), or a comma separated list of settings: `always` or `never` (mutually exclusive), `ignore-loops`, `instruction-threshold=N`, `skip-entry`, `skip-exit`";
17df50a5
XL
389 pub const parse_unpretty: &str = "`string` or `string=string`";
390 pub const parse_treat_err_as_bug: &str = "either no value or a number bigger than 0";
9c376795
FG
391 pub const parse_trait_solver: &str =
392 "one of the supported solver modes (`classic`, `chalk`, or `next`)";
17df50a5
XL
393 pub const parse_lto: &str =
394 "either a boolean (`yes`, `no`, `on`, `off`, etc), `thin`, `fat`, or omitted";
395 pub const parse_linker_plugin_lto: &str =
396 "either a boolean (`yes`, `no`, `on`, `off`, etc), or the path to the linker plugin";
064997fb 397 pub const parse_location_detail: &str = "either `none`, or a comma separated list of location details to track: `file`, `line`, or `column`";
17df50a5
XL
398 pub const parse_switch_with_opt_path: &str =
399 "an optional path to the profiling data output directory";
400 pub const parse_merge_functions: &str = "one of: `disabled`, `trampolines`, or `aliases`";
401 pub const parse_symbol_mangling_version: &str = "either `legacy` or `v0` (RFC 2603)";
402 pub const parse_src_file_hash: &str = "either `md5` or `sha1`";
403 pub const parse_relocation_model: &str =
404 "one of supported relocation models (`rustc --print relocation-models`)";
405 pub const parse_code_model: &str = "one of supported code models (`rustc --print code-models`)";
406 pub const parse_tls_model: &str = "one of supported TLS models (`rustc --print tls-models`)";
407 pub const parse_target_feature: &str = parse_string;
9ffffee4
FG
408 pub const parse_terminal_url: &str =
409 "either a boolean (`yes`, `no`, `on`, `off`, etc), or `auto`";
17df50a5
XL
410 pub const parse_wasi_exec_model: &str = "either `command` or `reactor`";
411 pub const parse_split_debuginfo: &str =
412 "one of supported split-debuginfo modes (`off`, `packed`, or `unpacked`)";
a2a8927a
XL
413 pub const parse_split_dwarf_kind: &str =
414 "one of supported split dwarf modes (`split` or `single`)";
17df50a5 415 pub const parse_gcc_ld: &str = "one of: no value, `lld`";
3c0e092e
XL
416 pub const parse_stack_protector: &str =
417 "one of (`none` (default), `basic`, `strong`, or `all`)";
5099ac24
FG
418 pub const parse_branch_protection: &str =
419 "a `,` separated combination of `bti`, `b-key`, `pac-ret`, or `leaf`";
064997fb
FG
420 pub const parse_proc_macro_execution_strategy: &str =
421 "one of supported execution strategies (`same-thread`, or `cross-thread`)";
17df50a5
XL
422}
423
424mod parse {
923072b8 425 pub(crate) use super::*;
17df50a5 426 use std::str::FromStr;
dfeec247 427
17df50a5
XL
428 /// This is for boolean options that don't take a value and start with
429 /// `no-`. This style of option is deprecated.
923072b8 430 pub(crate) fn parse_no_flag(slot: &mut bool, v: Option<&str>) -> bool {
17df50a5
XL
431 match v {
432 None => {
433 *slot = true;
434 true
dfeec247 435 }
17df50a5 436 Some(_) => false,
dfeec247 437 }
17df50a5 438 }
dfeec247 439
17df50a5 440 /// Use this for any boolean option that has a static default.
923072b8 441 pub(crate) fn parse_bool(slot: &mut bool, v: Option<&str>) -> bool {
17df50a5 442 match v {
9ffffee4 443 Some("y") | Some("yes") | Some("on") | Some("true") | None => {
17df50a5
XL
444 *slot = true;
445 true
446 }
9ffffee4 447 Some("n") | Some("no") | Some("off") | Some("false") => {
17df50a5
XL
448 *slot = false;
449 true
dfeec247 450 }
17df50a5 451 _ => false,
dfeec247 452 }
17df50a5 453 }
dfeec247 454
17df50a5
XL
455 /// Use this for any boolean option that lacks a static default. (The
456 /// actions taken when such an option is not specified will depend on
457 /// other factors, such as other options, or target options.)
923072b8 458 pub(crate) fn parse_opt_bool(slot: &mut Option<bool>, v: Option<&str>) -> bool {
17df50a5 459 match v {
9ffffee4 460 Some("y") | Some("yes") | Some("on") | Some("true") | None => {
17df50a5
XL
461 *slot = Some(true);
462 true
463 }
9ffffee4 464 Some("n") | Some("no") | Some("off") | Some("false") => {
17df50a5
XL
465 *slot = Some(false);
466 true
dfeec247 467 }
17df50a5 468 _ => false,
dfeec247 469 }
17df50a5 470 }
dfeec247 471
17df50a5 472 /// Use this for any string option that has a static default.
923072b8 473 pub(crate) fn parse_string(slot: &mut String, v: Option<&str>) -> bool {
17df50a5
XL
474 match v {
475 Some(s) => {
476 *slot = s.to_string();
477 true
dfeec247 478 }
17df50a5 479 None => false,
dfeec247 480 }
17df50a5 481 }
dfeec247 482
17df50a5 483 /// Use this for any string option that lacks a static default.
923072b8 484 pub(crate) fn parse_opt_string(slot: &mut Option<String>, v: Option<&str>) -> bool {
17df50a5
XL
485 match v {
486 Some(s) => {
487 *slot = Some(s.to_string());
488 true
dfeec247 489 }
17df50a5 490 None => false,
dfeec247 491 }
17df50a5 492 }
dfeec247 493
04454e1e 494 /// Parse an optional language identifier, e.g. `en-US` or `zh-CN`.
923072b8 495 pub(crate) fn parse_opt_langid(slot: &mut Option<LanguageIdentifier>, v: Option<&str>) -> bool {
04454e1e
FG
496 match v {
497 Some(s) => {
498 *slot = rustc_errors::LanguageIdentifier::from_str(s).ok();
499 true
500 }
501 None => false,
502 }
503 }
504
923072b8 505 pub(crate) fn parse_opt_pathbuf(slot: &mut Option<PathBuf>, v: Option<&str>) -> bool {
17df50a5
XL
506 match v {
507 Some(s) => {
508 *slot = Some(PathBuf::from(s));
509 true
dfeec247 510 }
17df50a5 511 None => false,
dfeec247 512 }
17df50a5 513 }
dfeec247 514
923072b8 515 pub(crate) fn parse_string_push(slot: &mut Vec<String>, v: Option<&str>) -> bool {
17df50a5
XL
516 match v {
517 Some(s) => {
518 slot.push(s.to_string());
519 true
dfeec247 520 }
17df50a5 521 None => false,
dfeec247 522 }
17df50a5 523 }
dfeec247 524
923072b8 525 pub(crate) fn parse_list(slot: &mut Vec<String>, v: Option<&str>) -> bool {
17df50a5
XL
526 match v {
527 Some(s) => {
528 slot.extend(s.split_whitespace().map(|s| s.to_string()));
529 true
dfeec247 530 }
17df50a5 531 None => false,
dfeec247 532 }
17df50a5 533 }
dfeec247 534
923072b8
FG
535 pub(crate) fn parse_list_with_polarity(
536 slot: &mut Vec<(String, bool)>,
537 v: Option<&str>,
538 ) -> bool {
04454e1e
FG
539 match v {
540 Some(s) => {
064997fb 541 for s in s.split(',') {
04454e1e
FG
542 let Some(pass_name) = s.strip_prefix(&['+', '-'][..]) else { return false };
543 slot.push((pass_name.to_string(), &s[..1] == "+"));
544 }
545 true
546 }
547 None => false,
548 }
549 }
550
923072b8 551 pub(crate) fn parse_location_detail(ld: &mut LocationDetail, v: Option<&str>) -> bool {
3c0e092e
XL
552 if let Some(v) = v {
553 ld.line = false;
554 ld.file = false;
555 ld.column = false;
064997fb
FG
556 if v == "none" {
557 return true;
558 }
3c0e092e
XL
559 for s in v.split(',') {
560 match s {
561 "file" => ld.file = true,
562 "line" => ld.line = true,
563 "column" => ld.column = true,
564 _ => return false,
565 }
566 }
567 true
568 } else {
569 false
570 }
571 }
572
923072b8 573 pub(crate) fn parse_opt_comma_list(slot: &mut Option<Vec<String>>, v: Option<&str>) -> bool {
17df50a5
XL
574 match v {
575 Some(s) => {
576 let mut v: Vec<_> = s.split(',').map(|s| s.to_string()).collect();
577 v.sort_unstable();
578 *slot = Some(v);
579 true
dfeec247 580 }
17df50a5 581 None => false,
dfeec247 582 }
17df50a5 583 }
dfeec247 584
923072b8 585 pub(crate) fn parse_threads(slot: &mut usize, v: Option<&str>) -> bool {
17df50a5
XL
586 match v.and_then(|s| s.parse().ok()) {
587 Some(0) => {
f2b60f7d 588 *slot = std::thread::available_parallelism().map_or(1, std::num::NonZeroUsize::get);
17df50a5
XL
589 true
590 }
591 Some(i) => {
592 *slot = i;
593 true
dfeec247 594 }
17df50a5 595 None => false,
dfeec247 596 }
17df50a5 597 }
dfeec247 598
17df50a5 599 /// Use this for any numeric option that has a static default.
923072b8 600 pub(crate) fn parse_number<T: Copy + FromStr>(slot: &mut T, v: Option<&str>) -> bool {
17df50a5
XL
601 match v.and_then(|s| s.parse().ok()) {
602 Some(i) => {
603 *slot = i;
604 true
dfeec247 605 }
17df50a5 606 None => false,
dfeec247 607 }
17df50a5 608 }
dfeec247 609
17df50a5 610 /// Use this for any numeric option that lacks a static default.
923072b8
FG
611 pub(crate) fn parse_opt_number<T: Copy + FromStr>(
612 slot: &mut Option<T>,
613 v: Option<&str>,
614 ) -> bool {
17df50a5
XL
615 match v {
616 Some(s) => {
617 *slot = s.parse().ok();
618 slot.is_some()
dfeec247 619 }
17df50a5 620 None => false,
dfeec247 621 }
17df50a5 622 }
dfeec247 623
923072b8 624 pub(crate) fn parse_passes(slot: &mut Passes, v: Option<&str>) -> bool {
17df50a5
XL
625 match v {
626 Some("all") => {
627 *slot = Passes::All;
628 true
629 }
630 v => {
631 let mut passes = vec![];
632 if parse_list(&mut passes, v) {
a2a8927a 633 slot.extend(passes);
dfeec247 634 true
17df50a5
XL
635 } else {
636 false
dfeec247
XL
637 }
638 }
639 }
17df50a5 640 }
dfeec247 641
923072b8
FG
642 pub(crate) fn parse_opt_panic_strategy(
643 slot: &mut Option<PanicStrategy>,
644 v: Option<&str>,
645 ) -> bool {
17df50a5
XL
646 match v {
647 Some("unwind") => *slot = Some(PanicStrategy::Unwind),
648 Some("abort") => *slot = Some(PanicStrategy::Abort),
649 _ => return false,
dfeec247 650 }
17df50a5
XL
651 true
652 }
dfeec247 653
923072b8 654 pub(crate) fn parse_panic_strategy(slot: &mut PanicStrategy, v: Option<&str>) -> bool {
c295e0f8
XL
655 match v {
656 Some("unwind") => *slot = PanicStrategy::Unwind,
657 Some("abort") => *slot = PanicStrategy::Abort,
658 _ => return false,
659 }
660 true
661 }
662
923072b8 663 pub(crate) fn parse_oom_strategy(slot: &mut OomStrategy, v: Option<&str>) -> bool {
5e7ed085
FG
664 match v {
665 Some("panic") => *slot = OomStrategy::Panic,
666 Some("abort") => *slot = OomStrategy::Abort,
667 _ => return false,
668 }
669 true
670 }
671
923072b8 672 pub(crate) fn parse_relro_level(slot: &mut Option<RelroLevel>, v: Option<&str>) -> bool {
17df50a5
XL
673 match v {
674 Some(s) => match s.parse::<RelroLevel>() {
675 Ok(level) => *slot = Some(level),
676 _ => return false,
677 },
678 _ => return false,
679 }
680 true
681 }
682
923072b8 683 pub(crate) fn parse_sanitizers(slot: &mut SanitizerSet, v: Option<&str>) -> bool {
17df50a5
XL
684 if let Some(v) = v {
685 for s in v.split(',') {
686 *slot |= match s {
687 "address" => SanitizerSet::ADDRESS,
3c0e092e 688 "cfi" => SanitizerSet::CFI,
9c376795 689 "kcfi" => SanitizerSet::KCFI,
9ffffee4 690 "kernel-address" => SanitizerSet::KERNELADDRESS,
17df50a5
XL
691 "leak" => SanitizerSet::LEAK,
692 "memory" => SanitizerSet::MEMORY,
5099ac24 693 "memtag" => SanitizerSet::MEMTAG,
064997fb 694 "shadow-call-stack" => SanitizerSet::SHADOWCALLSTACK,
17df50a5
XL
695 "thread" => SanitizerSet::THREAD,
696 "hwaddress" => SanitizerSet::HWADDRESS,
697 _ => return false,
698 }
dfeec247
XL
699 }
700 true
17df50a5
XL
701 } else {
702 false
dfeec247 703 }
17df50a5 704 }
dfeec247 705
923072b8 706 pub(crate) fn parse_sanitizer_memory_track_origins(slot: &mut usize, v: Option<&str>) -> bool {
17df50a5
XL
707 match v {
708 Some("2") | None => {
709 *slot = 2;
dfeec247 710 true
dfeec247 711 }
17df50a5
XL
712 Some("1") => {
713 *slot = 1;
714 true
715 }
716 Some("0") => {
717 *slot = 0;
718 true
719 }
720 Some(_) => false,
dfeec247 721 }
17df50a5 722 }
dfeec247 723
923072b8 724 pub(crate) fn parse_strip(slot: &mut Strip, v: Option<&str>) -> bool {
17df50a5
XL
725 match v {
726 Some("none") => *slot = Strip::None,
727 Some("debuginfo") => *slot = Strip::Debuginfo,
728 Some("symbols") => *slot = Strip::Symbols,
729 _ => return false,
dfeec247 730 }
17df50a5
XL
731 true
732 }
dfeec247 733
923072b8 734 pub(crate) fn parse_cfguard(slot: &mut CFGuard, v: Option<&str>) -> bool {
17df50a5
XL
735 if v.is_some() {
736 let mut bool_arg = None;
737 if parse_opt_bool(&mut bool_arg, v) {
738 *slot = if bool_arg.unwrap() { CFGuard::Checks } else { CFGuard::Disabled };
739 return true;
f9f354fc 740 }
f9f354fc
XL
741 }
742
17df50a5
XL
743 *slot = match v {
744 None => CFGuard::Checks,
745 Some("checks") => CFGuard::Checks,
746 Some("nochecks") => CFGuard::NoChecks,
747 Some(_) => return false,
748 };
749 true
750 }
f035d41b 751
923072b8 752 pub(crate) fn parse_cfprotection(slot: &mut CFProtection, v: Option<&str>) -> bool {
5099ac24
FG
753 if v.is_some() {
754 let mut bool_arg = None;
755 if parse_opt_bool(&mut bool_arg, v) {
756 *slot = if bool_arg.unwrap() { CFProtection::Full } else { CFProtection::None };
757 return true;
758 }
759 }
760
761 *slot = match v {
762 None | Some("none") => CFProtection::None,
763 Some("branch") => CFProtection::Branch,
764 Some("return") => CFProtection::Return,
765 Some("full") => CFProtection::Full,
766 Some(_) => return false,
767 };
768 true
769 }
770
353b0b11
FG
771 pub(crate) fn parse_debuginfo(slot: &mut DebugInfo, v: Option<&str>) -> bool {
772 match v {
773 Some("0") | Some("none") => *slot = DebugInfo::None,
774 Some("line-directives-only") => *slot = DebugInfo::LineDirectivesOnly,
775 Some("line-tables-only") => *slot = DebugInfo::LineTablesOnly,
776 Some("1") | Some("limited") => *slot = DebugInfo::Limited,
777 Some("2") | Some("full") => *slot = DebugInfo::Full,
778 _ => return false,
779 }
780 true
781 }
782
f2b60f7d
FG
783 pub(crate) fn parse_linker_flavor(slot: &mut Option<LinkerFlavorCli>, v: Option<&str>) -> bool {
784 match v.and_then(LinkerFlavorCli::from_str) {
17df50a5
XL
785 Some(lf) => *slot = Some(lf),
786 _ => return false,
74b04a01 787 }
17df50a5
XL
788 true
789 }
74b04a01 790
923072b8
FG
791 pub(crate) fn parse_optimization_fuel(
792 slot: &mut Option<(String, u64)>,
793 v: Option<&str>,
794 ) -> bool {
17df50a5
XL
795 match v {
796 None => false,
797 Some(s) => {
798 let parts = s.split('=').collect::<Vec<_>>();
799 if parts.len() != 2 {
800 return false;
801 }
802 let crate_name = parts[0].to_string();
803 let fuel = parts[1].parse::<u64>();
804 if fuel.is_err() {
805 return false;
806 }
807 *slot = Some((crate_name, fuel.unwrap()));
808 true
dfeec247 809 }
dfeec247 810 }
17df50a5 811 }
dfeec247 812
923072b8 813 pub(crate) fn parse_unpretty(slot: &mut Option<String>, v: Option<&str>) -> bool {
17df50a5
XL
814 match v {
815 None => false,
816 Some(s) if s.split('=').count() <= 2 => {
817 *slot = Some(s.to_string());
818 true
dfeec247 819 }
17df50a5 820 _ => false,
dfeec247 821 }
17df50a5 822 }
dfeec247 823
923072b8 824 pub(crate) fn parse_mir_spanview(slot: &mut Option<MirSpanview>, v: Option<&str>) -> bool {
17df50a5
XL
825 if v.is_some() {
826 let mut bool_arg = None;
827 if parse_opt_bool(&mut bool_arg, v) {
9ffffee4 828 *slot = bool_arg.unwrap().then_some(MirSpanview::Statement);
17df50a5 829 return true;
dfeec247
XL
830 }
831 }
832
5e7ed085
FG
833 let Some(v) = v else {
834 *slot = Some(MirSpanview::Statement);
835 return true;
17df50a5
XL
836 };
837
94222f64 838 *slot = Some(match v.trim_end_matches('s') {
17df50a5
XL
839 "statement" | "stmt" => MirSpanview::Statement,
840 "terminator" | "term" => MirSpanview::Terminator,
841 "block" | "basicblock" => MirSpanview::Block,
842 _ => return false,
843 });
844 true
845 }
1b1a35ee 846
353b0b11
FG
847 pub(crate) fn parse_time_passes_format(slot: &mut TimePassesFormat, v: Option<&str>) -> bool {
848 match v {
849 None => true,
850 Some("json") => {
851 *slot = TimePassesFormat::Json;
852 true
853 }
854 Some("text") => {
855 *slot = TimePassesFormat::Text;
856 true
857 }
858 Some(_) => false,
859 }
860 }
861
9c376795
FG
862 pub(crate) fn parse_dump_mono_stats(slot: &mut DumpMonoStatsFormat, v: Option<&str>) -> bool {
863 match v {
864 None => true,
865 Some("json") => {
866 *slot = DumpMonoStatsFormat::Json;
867 true
868 }
869 Some("markdown") => {
870 *slot = DumpMonoStatsFormat::Markdown;
871 true
872 }
873 Some(_) => false,
874 }
875 }
876
923072b8 877 pub(crate) fn parse_instrument_coverage(
17df50a5
XL
878 slot: &mut Option<InstrumentCoverage>,
879 v: Option<&str>,
880 ) -> bool {
881 if v.is_some() {
882 let mut bool_arg = None;
883 if parse_opt_bool(&mut bool_arg, v) {
9ffffee4 884 *slot = bool_arg.unwrap().then_some(InstrumentCoverage::All);
17df50a5
XL
885 return true;
886 }
1b1a35ee
XL
887 }
888
5e7ed085
FG
889 let Some(v) = v else {
890 *slot = Some(InstrumentCoverage::All);
891 return true;
17df50a5 892 };
cdc7bbd5 893
17df50a5
XL
894 *slot = Some(match v {
895 "all" => InstrumentCoverage::All,
896 "except-unused-generics" | "except_unused_generics" => {
897 InstrumentCoverage::ExceptUnusedGenerics
898 }
899 "except-unused-functions" | "except_unused_functions" => {
900 InstrumentCoverage::ExceptUnusedFunctions
901 }
902 "off" | "no" | "n" | "false" | "0" => InstrumentCoverage::Off,
903 _ => return false,
904 });
905 true
906 }
cdc7bbd5 907
9ffffee4
FG
908 pub(crate) fn parse_instrument_xray(
909 slot: &mut Option<InstrumentXRay>,
910 v: Option<&str>,
911 ) -> bool {
912 if v.is_some() {
913 let mut bool_arg = None;
914 if parse_opt_bool(&mut bool_arg, v) {
915 *slot = if bool_arg.unwrap() { Some(InstrumentXRay::default()) } else { None };
916 return true;
917 }
918 }
919
920 let mut options = slot.get_or_insert_default();
921 let mut seen_always = false;
922 let mut seen_never = false;
923 let mut seen_ignore_loops = false;
924 let mut seen_instruction_threshold = false;
925 let mut seen_skip_entry = false;
926 let mut seen_skip_exit = false;
353b0b11 927 for option in v.into_iter().flat_map(|v| v.split(',')) {
9ffffee4
FG
928 match option {
929 "always" if !seen_always && !seen_never => {
930 options.always = true;
931 options.never = false;
932 seen_always = true;
933 }
934 "never" if !seen_never && !seen_always => {
935 options.never = true;
936 options.always = false;
937 seen_never = true;
938 }
939 "ignore-loops" if !seen_ignore_loops => {
940 options.ignore_loops = true;
941 seen_ignore_loops = true;
942 }
943 option
944 if option.starts_with("instruction-threshold")
945 && !seen_instruction_threshold =>
946 {
947 let Some(("instruction-threshold", n)) = option.split_once('=') else {
948 return false;
949 };
950 match n.parse() {
951 Ok(n) => options.instruction_threshold = Some(n),
952 Err(_) => return false,
953 }
954 seen_instruction_threshold = true;
955 }
956 "skip-entry" if !seen_skip_entry => {
957 options.skip_entry = true;
958 seen_skip_entry = true;
959 }
960 "skip-exit" if !seen_skip_exit => {
961 options.skip_exit = true;
962 seen_skip_exit = true;
963 }
964 _ => return false,
965 }
966 }
967 true
968 }
969
923072b8 970 pub(crate) fn parse_treat_err_as_bug(slot: &mut Option<NonZeroUsize>, v: Option<&str>) -> bool {
17df50a5
XL
971 match v {
972 Some(s) => {
973 *slot = s.parse().ok();
974 slot.is_some()
975 }
976 None => {
977 *slot = NonZeroUsize::new(1);
978 true
979 }
cdc7bbd5 980 }
17df50a5 981 }
cdc7bbd5 982
9c376795
FG
983 pub(crate) fn parse_trait_solver(slot: &mut TraitSolver, v: Option<&str>) -> bool {
984 match v {
985 Some("classic") => *slot = TraitSolver::Classic,
986 Some("chalk") => *slot = TraitSolver::Chalk,
987 Some("next") => *slot = TraitSolver::Next,
988 // default trait solver is subject to change..
989 Some("default") => *slot = TraitSolver::Classic,
990 _ => return false,
991 }
992 true
993 }
994
923072b8 995 pub(crate) fn parse_lto(slot: &mut LtoCli, v: Option<&str>) -> bool {
17df50a5
XL
996 if v.is_some() {
997 let mut bool_arg = None;
998 if parse_opt_bool(&mut bool_arg, v) {
999 *slot = if bool_arg.unwrap() { LtoCli::Yes } else { LtoCli::No };
1000 return true;
dfeec247
XL
1001 }
1002 }
1003
17df50a5
XL
1004 *slot = match v {
1005 None => LtoCli::NoParam,
1006 Some("thin") => LtoCli::Thin,
1007 Some("fat") => LtoCli::Fat,
1008 Some(_) => return false,
1009 };
1010 true
1011 }
dfeec247 1012
923072b8 1013 pub(crate) fn parse_linker_plugin_lto(slot: &mut LinkerPluginLto, v: Option<&str>) -> bool {
17df50a5
XL
1014 if v.is_some() {
1015 let mut bool_arg = None;
1016 if parse_opt_bool(&mut bool_arg, v) {
1017 *slot = if bool_arg.unwrap() {
1018 LinkerPluginLto::LinkerPluginAuto
1019 } else {
1020 LinkerPluginLto::Disabled
1021 };
1022 return true;
1023 }
dfeec247
XL
1024 }
1025
17df50a5
XL
1026 *slot = match v {
1027 None => LinkerPluginLto::LinkerPluginAuto,
1028 Some(path) => LinkerPluginLto::LinkerPlugin(PathBuf::from(path)),
1029 };
1030 true
1031 }
dfeec247 1032
923072b8
FG
1033 pub(crate) fn parse_switch_with_opt_path(
1034 slot: &mut SwitchWithOptPath,
1035 v: Option<&str>,
1036 ) -> bool {
17df50a5
XL
1037 *slot = match v {
1038 None => SwitchWithOptPath::Enabled(None),
1039 Some(path) => SwitchWithOptPath::Enabled(Some(PathBuf::from(path))),
1040 };
1041 true
1042 }
dfeec247 1043
923072b8
FG
1044 pub(crate) fn parse_merge_functions(
1045 slot: &mut Option<MergeFunctions>,
1046 v: Option<&str>,
1047 ) -> bool {
17df50a5
XL
1048 match v.and_then(|s| MergeFunctions::from_str(s).ok()) {
1049 Some(mergefunc) => *slot = Some(mergefunc),
1050 _ => return false,
dfeec247 1051 }
17df50a5
XL
1052 true
1053 }
dfeec247 1054
923072b8 1055 pub(crate) fn parse_relocation_model(slot: &mut Option<RelocModel>, v: Option<&str>) -> bool {
17df50a5
XL
1056 match v.and_then(|s| RelocModel::from_str(s).ok()) {
1057 Some(relocation_model) => *slot = Some(relocation_model),
1058 None if v == Some("default") => *slot = None,
1059 _ => return false,
dfeec247 1060 }
17df50a5
XL
1061 true
1062 }
dfeec247 1063
923072b8 1064 pub(crate) fn parse_code_model(slot: &mut Option<CodeModel>, v: Option<&str>) -> bool {
17df50a5
XL
1065 match v.and_then(|s| CodeModel::from_str(s).ok()) {
1066 Some(code_model) => *slot = Some(code_model),
1067 _ => return false,
f9f354fc 1068 }
17df50a5
XL
1069 true
1070 }
f9f354fc 1071
923072b8 1072 pub(crate) fn parse_tls_model(slot: &mut Option<TlsModel>, v: Option<&str>) -> bool {
17df50a5
XL
1073 match v.and_then(|s| TlsModel::from_str(s).ok()) {
1074 Some(tls_model) => *slot = Some(tls_model),
1075 _ => return false,
f9f354fc 1076 }
17df50a5
XL
1077 true
1078 }
f9f354fc 1079
9ffffee4
FG
1080 pub(crate) fn parse_terminal_url(slot: &mut TerminalUrl, v: Option<&str>) -> bool {
1081 *slot = match v {
1082 Some("on" | "" | "yes" | "y") | None => TerminalUrl::Yes,
1083 Some("off" | "no" | "n") => TerminalUrl::No,
1084 Some("auto") => TerminalUrl::Auto,
1085 _ => return false,
1086 };
1087 true
1088 }
1089
923072b8 1090 pub(crate) fn parse_symbol_mangling_version(
17df50a5
XL
1091 slot: &mut Option<SymbolManglingVersion>,
1092 v: Option<&str>,
1093 ) -> bool {
1094 *slot = match v {
1095 Some("legacy") => Some(SymbolManglingVersion::Legacy),
1096 Some("v0") => Some(SymbolManglingVersion::V0),
1097 _ => return false,
1098 };
1099 true
1100 }
f9f354fc 1101
923072b8 1102 pub(crate) fn parse_src_file_hash(
17df50a5
XL
1103 slot: &mut Option<SourceFileHashAlgorithm>,
1104 v: Option<&str>,
1105 ) -> bool {
1106 match v.and_then(|s| SourceFileHashAlgorithm::from_str(s).ok()) {
1107 Some(hash_kind) => *slot = Some(hash_kind),
1108 _ => return false,
dfeec247 1109 }
17df50a5
XL
1110 true
1111 }
ba9703b0 1112
923072b8 1113 pub(crate) fn parse_target_feature(slot: &mut String, v: Option<&str>) -> bool {
17df50a5
XL
1114 match v {
1115 Some(s) => {
1116 if !slot.is_empty() {
3c0e092e 1117 slot.push(',');
17df50a5
XL
1118 }
1119 slot.push_str(s);
1120 true
ba9703b0 1121 }
17df50a5 1122 None => false,
ba9703b0 1123 }
17df50a5 1124 }
f9f354fc 1125
923072b8 1126 pub(crate) fn parse_wasi_exec_model(slot: &mut Option<WasiExecModel>, v: Option<&str>) -> bool {
17df50a5
XL
1127 match v {
1128 Some("command") => *slot = Some(WasiExecModel::Command),
1129 Some("reactor") => *slot = Some(WasiExecModel::Reactor),
1130 _ => return false,
f9f354fc 1131 }
17df50a5
XL
1132 true
1133 }
5869c6ff 1134
923072b8
FG
1135 pub(crate) fn parse_split_debuginfo(
1136 slot: &mut Option<SplitDebuginfo>,
1137 v: Option<&str>,
1138 ) -> bool {
17df50a5
XL
1139 match v.and_then(|s| SplitDebuginfo::from_str(s).ok()) {
1140 Some(e) => *slot = Some(e),
1141 _ => return false,
5869c6ff 1142 }
17df50a5
XL
1143 true
1144 }
5869c6ff 1145
923072b8 1146 pub(crate) fn parse_split_dwarf_kind(slot: &mut SplitDwarfKind, v: Option<&str>) -> bool {
a2a8927a
XL
1147 match v.and_then(|s| SplitDwarfKind::from_str(s).ok()) {
1148 Some(e) => *slot = e,
1149 _ => return false,
1150 }
1151 true
1152 }
1153
923072b8 1154 pub(crate) fn parse_gcc_ld(slot: &mut Option<LdImpl>, v: Option<&str>) -> bool {
17df50a5
XL
1155 match v {
1156 None => *slot = None,
1157 Some("lld") => *slot = Some(LdImpl::Lld),
1158 _ => return false,
5869c6ff 1159 }
17df50a5 1160 true
dfeec247 1161 }
3c0e092e 1162
923072b8 1163 pub(crate) fn parse_stack_protector(slot: &mut StackProtector, v: Option<&str>) -> bool {
3c0e092e
XL
1164 match v.and_then(|s| StackProtector::from_str(s).ok()) {
1165 Some(ssp) => *slot = ssp,
1166 _ => return false,
1167 }
1168 true
1169 }
5099ac24 1170
923072b8
FG
1171 pub(crate) fn parse_branch_protection(
1172 slot: &mut Option<BranchProtection>,
1173 v: Option<&str>,
1174 ) -> bool {
5099ac24
FG
1175 match v {
1176 Some(s) => {
1177 let slot = slot.get_or_insert_default();
1178 for opt in s.split(',') {
1179 match opt {
1180 "bti" => slot.bti = true,
1181 "pac-ret" if slot.pac_ret.is_none() => {
1182 slot.pac_ret = Some(PacRet { leaf: false, key: PAuthKey::A })
1183 }
1184 "leaf" => match slot.pac_ret.as_mut() {
1185 Some(pac) => pac.leaf = true,
1186 _ => return false,
1187 },
1188 "b-key" => match slot.pac_ret.as_mut() {
1189 Some(pac) => pac.key = PAuthKey::B,
1190 _ => return false,
1191 },
1192 _ => return false,
1193 };
1194 }
1195 }
1196 _ => return false,
1197 }
1198 true
1199 }
064997fb
FG
1200
1201 pub(crate) fn parse_proc_macro_execution_strategy(
1202 slot: &mut ProcMacroExecutionStrategy,
1203 v: Option<&str>,
1204 ) -> bool {
1205 *slot = match v {
1206 Some("same-thread") => ProcMacroExecutionStrategy::SameThread,
1207 Some("cross-thread") => ProcMacroExecutionStrategy::CrossThread,
1208 _ => return false,
1209 };
1210 true
1211 }
17df50a5 1212}
dfeec247 1213
17df50a5 1214options! {
3c0e092e 1215 CodegenOptions, CG_OPTIONS, cgopts, "C", "codegen",
f9f354fc 1216
f9f354fc 1217 // If you add a new option, please update:
29967ef6 1218 // - compiler/rustc_interface/src/tests.rs
f9f354fc
XL
1219 // - src/doc/rustc/src/codegen-options/index.md
1220
2b03887a 1221 // tidy-alphabetical-start
ba9703b0 1222 ar: String = (String::new(), parse_string, [UNTRACKED],
dfeec247 1223 "this option is deprecated and does nothing"),
f2b60f7d 1224 #[rustc_lint_opt_deny_field_access("use `Session::code_model` instead of this field")]
f9f354fc
XL
1225 code_model: Option<CodeModel> = (None, parse_code_model, [TRACKED],
1226 "choose the code model to use (`rustc --print code-models` for details)"),
cdc7bbd5 1227 codegen_units: Option<usize> = (None, parse_opt_number, [UNTRACKED],
f9f354fc 1228 "divide crate into N units to optimize in parallel"),
3dfed10e
XL
1229 control_flow_guard: CFGuard = (CFGuard::Disabled, parse_cfguard, [TRACKED],
1230 "use Windows Control Flow Guard (default: no)"),
f9f354fc
XL
1231 debug_assertions: Option<bool> = (None, parse_opt_bool, [TRACKED],
1232 "explicitly enable the `cfg(debug_assertions)` directive"),
353b0b11
FG
1233 debuginfo: DebugInfo = (DebugInfo::None, parse_debuginfo, [TRACKED],
1234 "debug info emission level (0-2, none, line-directives-only, \
1235 line-tables-only, limited, or full; default: 0)"),
f9f354fc
XL
1236 default_linker_libraries: bool = (false, parse_bool, [UNTRACKED],
1237 "allow the linker to link its default libraries (default: no)"),
1238 embed_bitcode: bool = (true, parse_bool, [TRACKED],
1239 "emit bitcode in rlibs (default: yes)"),
1240 extra_filename: String = (String::new(), parse_string, [UNTRACKED],
1241 "extra data to put in each output filename"),
1242 force_frame_pointers: Option<bool> = (None, parse_opt_bool, [TRACKED],
1243 "force use of the frame pointers"),
f2b60f7d 1244 #[rustc_lint_opt_deny_field_access("use `Session::must_emit_unwind_tables` instead of this field")]
f9f354fc
XL
1245 force_unwind_tables: Option<bool> = (None, parse_opt_bool, [TRACKED],
1246 "force use of unwind tables"),
1247 incremental: Option<String> = (None, parse_opt_string, [UNTRACKED],
1248 "enable incremental compilation"),
cdc7bbd5 1249 inline_threshold: Option<u32> = (None, parse_opt_number, [TRACKED],
f9f354fc 1250 "set the threshold for inlining a function"),
f2b60f7d 1251 #[rustc_lint_opt_deny_field_access("use `Session::instrument_coverage` instead of this field")]
5099ac24
FG
1252 instrument_coverage: Option<InstrumentCoverage> = (None, parse_instrument_coverage, [TRACKED],
1253 "instrument the generated code to support LLVM source-based code coverage \
1254 reports (note, the compiler build config must include `profiler = true`); \
1255 implies `-C symbol-mangling-version=v0`. Optional values are:
1256 `=all` (implicit value)
1257 `=except-unused-generics`
1258 `=except-unused-functions`
1259 `=off` (default)"),
ba9703b0 1260 link_arg: (/* redirected to link_args */) = ((), parse_string_push, [UNTRACKED],
dfeec247 1261 "a single extra argument to append to the linker invocation (can be used several times)"),
ba9703b0 1262 link_args: Vec<String> = (Vec::new(), parse_list, [UNTRACKED],
dfeec247 1263 "extra arguments to append to the linker invocation (space separated)"),
f2b60f7d 1264 #[rustc_lint_opt_deny_field_access("use `Session::link_dead_code` instead of this field")]
cdc7bbd5 1265 link_dead_code: Option<bool> = (None, parse_opt_bool, [TRACKED],
ba9703b0 1266 "keep dead code at link time (useful for code coverage) (default: no)"),
1b1a35ee
XL
1267 link_self_contained: Option<bool> = (None, parse_opt_bool, [UNTRACKED],
1268 "control whether to link Rust provided C objects/libraries or rely
1269 on C toolchain installed in the system"),
f9f354fc
XL
1270 linker: Option<PathBuf> = (None, parse_opt_pathbuf, [UNTRACKED],
1271 "system linker to link outputs with"),
f2b60f7d 1272 linker_flavor: Option<LinkerFlavorCli> = (None, parse_linker_flavor, [UNTRACKED],
f9f354fc
XL
1273 "linker flavor"),
1274 linker_plugin_lto: LinkerPluginLto = (LinkerPluginLto::Disabled,
1275 parse_linker_plugin_lto, [TRACKED],
1276 "generate build artifacts that are compatible with linker-based LTO"),
dfeec247
XL
1277 llvm_args: Vec<String> = (Vec::new(), parse_list, [TRACKED],
1278 "a list of arguments to pass to LLVM (space separated)"),
f2b60f7d 1279 #[rustc_lint_opt_deny_field_access("use `Session::lto` instead of this field")]
f9f354fc
XL
1280 lto: LtoCli = (LtoCli::Unspecified, parse_lto, [TRACKED],
1281 "perform LLVM link-time optimizations"),
1282 metadata: Vec<String> = (Vec::new(), parse_list, [TRACKED],
1283 "metadata to mangle symbol names with"),
ba9703b0
XL
1284 no_prepopulate_passes: bool = (false, parse_no_flag, [TRACKED],
1285 "give an empty list of passes to the pass manager"),
dfeec247
XL
1286 no_redzone: Option<bool> = (None, parse_opt_bool, [TRACKED],
1287 "disable the use of the redzone"),
ba9703b0
XL
1288 no_stack_check: bool = (false, parse_no_flag, [UNTRACKED],
1289 "this option is deprecated and does nothing"),
f9f354fc
XL
1290 no_vectorize_loops: bool = (false, parse_no_flag, [TRACKED],
1291 "disable loop vectorization optimization passes"),
1292 no_vectorize_slp: bool = (false, parse_no_flag, [TRACKED],
1293 "disable LLVM's SLP vectorization pass"),
ba9703b0
XL
1294 opt_level: String = ("0".to_string(), parse_string, [TRACKED],
1295 "optimization level (0-3, s, or z; default: 0)"),
f2b60f7d 1296 #[rustc_lint_opt_deny_field_access("use `Session::overflow_checks` instead of this field")]
f9f354fc
XL
1297 overflow_checks: Option<bool> = (None, parse_opt_bool, [TRACKED],
1298 "use overflow checks for integer arithmetic"),
f2b60f7d 1299 #[rustc_lint_opt_deny_field_access("use `Session::panic_strategy` instead of this field")]
c295e0f8 1300 panic: Option<PanicStrategy> = (None, parse_opt_panic_strategy, [TRACKED],
f9f354fc
XL
1301 "panic strategy to compile crate with"),
1302 passes: Vec<String> = (Vec::new(), parse_list, [TRACKED],
1303 "a list of extra LLVM passes to run (space separated)"),
1304 prefer_dynamic: bool = (false, parse_bool, [TRACKED],
1305 "prefer dynamic linking to static linking (default: no)"),
dfeec247
XL
1306 profile_generate: SwitchWithOptPath = (SwitchWithOptPath::Disabled,
1307 parse_switch_with_opt_path, [TRACKED],
1308 "compile the program with profiling instrumentation"),
1309 profile_use: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
1310 "use the given `.profdata` file for profile-guided optimization"),
f2b60f7d 1311 #[rustc_lint_opt_deny_field_access("use `Session::relocation_model` instead of this field")]
f9f354fc
XL
1312 relocation_model: Option<RelocModel> = (None, parse_relocation_model, [TRACKED],
1313 "control generation of position-independent code (PIC) \
1314 (`rustc --print relocation-models` for details)"),
1315 remark: Passes = (Passes::Some(Vec::new()), parse_passes, [UNTRACKED],
1316 "print remarks for these optimization passes (space separated, or \"all\")"),
1317 rpath: bool = (false, parse_bool, [UNTRACKED],
1318 "set rpath values in libs/exes (default: no)"),
1319 save_temps: bool = (false, parse_bool, [UNTRACKED],
1320 "save all temporary output files during compilation (default: no)"),
1321 soft_float: bool = (false, parse_bool, [TRACKED],
1322 "use soft float ABI (*eabihf targets only) (default: no)"),
f2b60f7d 1323 #[rustc_lint_opt_deny_field_access("use `Session::split_debuginfo` instead of this field")]
5869c6ff
XL
1324 split_debuginfo: Option<SplitDebuginfo> = (None, parse_split_debuginfo, [TRACKED],
1325 "how to handle split-debuginfo, a platform-specific option"),
3c0e092e
XL
1326 strip: Strip = (Strip::None, parse_strip, [UNTRACKED],
1327 "tell the linker which information to strip (`none` (default), `debuginfo` or `symbols`)"),
a2a8927a
XL
1328 symbol_mangling_version: Option<SymbolManglingVersion> = (None,
1329 parse_symbol_mangling_version, [TRACKED],
1330 "which mangling version to use for symbol names ('legacy' (default) or 'v0')"),
f9f354fc
XL
1331 target_cpu: Option<String> = (None, parse_opt_string, [TRACKED],
1332 "select target processor (`rustc --print target-cpus` for details)"),
1333 target_feature: String = (String::new(), parse_target_feature, [TRACKED],
1334 "target specific attributes. (`rustc --print target-features` for details). \
1335 This feature is unsafe."),
2b03887a 1336 // tidy-alphabetical-end
f9f354fc 1337
f9f354fc 1338 // If you add a new option, please update:
29967ef6 1339 // - compiler/rustc_interface/src/tests.rs
f9f354fc 1340 // - src/doc/rustc/src/codegen-options/index.md
dfeec247
XL
1341}
1342
17df50a5 1343options! {
064997fb 1344 UnstableOptions, Z_OPTIONS, dbopts, "Z", "unstable",
f9f354fc 1345
f9f354fc 1346 // If you add a new option, please update:
29967ef6 1347 // - compiler/rustc_interface/src/tests.rs
064997fb 1348 // - src/doc/unstable-book/src/compiler-flags
f9f354fc 1349
2b03887a 1350 // tidy-alphabetical-start
f9f354fc 1351 allow_features: Option<Vec<String>> = (None, parse_opt_comma_list, [TRACKED],
9c376795 1352 "only allow the listed language features to be enabled in code (comma separated)"),
f9f354fc
XL
1353 always_encode_mir: bool = (false, parse_bool, [TRACKED],
1354 "encode MIR of all functions into the crate metadata (default: no)"),
dfeec247 1355 asm_comments: bool = (false, parse_bool, [TRACKED],
ba9703b0 1356 "generate comments into the assembly (may change behavior) (default: no)"),
3c0e092e
XL
1357 assert_incr_state: Option<String> = (None, parse_opt_string, [UNTRACKED],
1358 "assert that the incremental cache is in given state: \
1359 either `loaded` or `not-loaded`."),
2b03887a
FG
1360 assume_incomplete_release: bool = (false, parse_bool, [TRACKED],
1361 "make cfg(version) treat the current version as incomplete (default: no)"),
f2b60f7d 1362 #[rustc_lint_opt_deny_field_access("use `Session::binary_dep_depinfo` instead of this field")]
f9f354fc
XL
1363 binary_dep_depinfo: bool = (false, parse_bool, [TRACKED],
1364 "include artifacts (sysroot, crate dependencies) used during compilation in dep-info \
1365 (default: no)"),
9c376795 1366 box_noalias: bool = (true, parse_bool, [TRACKED],
064997fb 1367 "emit noalias metadata for box (default: yes)"),
5099ac24
FG
1368 branch_protection: Option<BranchProtection> = (None, parse_branch_protection, [TRACKED],
1369 "set options for branch target identification and pointer authentication on AArch64"),
1370 cf_protection: CFProtection = (CFProtection::None, parse_cfprotection, [TRACKED],
1371 "instrument control-flow architecture protection"),
3dfed10e
XL
1372 cgu_partitioning_strategy: Option<String> = (None, parse_opt_string, [TRACKED],
1373 "the codegen unit partitioning strategy to use"),
f9f354fc
XL
1374 codegen_backend: Option<String> = (None, parse_opt_string, [TRACKED],
1375 "the backend to use"),
1b1a35ee
XL
1376 combine_cgu: bool = (false, parse_bool, [TRACKED],
1377 "combine CGUs into a single one"),
f9f354fc
XL
1378 crate_attr: Vec<String> = (Vec::new(), parse_string_push, [TRACKED],
1379 "inject the given attribute in the crate"),
c295e0f8
XL
1380 debug_info_for_profiling: bool = (false, parse_bool, [TRACKED],
1381 "emit discriminators and other data necessary for AutoFDO"),
f9f354fc
XL
1382 debug_macros: bool = (false, parse_bool, [TRACKED],
1383 "emit line numbers debug info inside macros (default: no)"),
1384 deduplicate_diagnostics: bool = (true, parse_bool, [UNTRACKED],
1385 "deduplicate identical diagnostics (default: yes)"),
1386 dep_info_omit_d_target: bool = (false, parse_bool, [TRACKED],
1387 "in dep-info output, omit targets for tracking dependencies of the dep-info files \
1388 themselves (default: no)"),
dfeec247 1389 dep_tasks: bool = (false, parse_bool, [UNTRACKED],
ba9703b0
XL
1390 "print tasks that execute and the color their dep node gets (requires debug build) \
1391 (default: no)"),
2b03887a
FG
1392 diagnostic_width: Option<usize> = (None, parse_opt_number, [UNTRACKED],
1393 "set the current output width for diagnostic truncation"),
5099ac24
FG
1394 dlltool: Option<PathBuf> = (None, parse_opt_pathbuf, [UNTRACKED],
1395 "import library generation tool (windows-gnu only)"),
f9f354fc
XL
1396 dont_buffer_diagnostics: bool = (false, parse_bool, [UNTRACKED],
1397 "emit diagnostics rather than buffering (breaks NLL error downgrading, sorting) \
ba9703b0 1398 (default: no)"),
5099ac24
FG
1399 drop_tracking: bool = (false, parse_bool, [TRACKED],
1400 "enables drop tracking in generators (default: no)"),
9ffffee4
FG
1401 drop_tracking_mir: bool = (false, parse_bool, [TRACKED],
1402 "enables drop tracking on MIR in generators (default: no)"),
f9f354fc
XL
1403 dual_proc_macros: bool = (false, parse_bool, [TRACKED],
1404 "load proc macros for both target and host, but only link to the target (default: no)"),
dfeec247 1405 dump_dep_graph: bool = (false, parse_bool, [UNTRACKED],
ba9703b0
XL
1406 "dump the dependency graph to $RUST_DEP_GRAPH (default: /tmp/dep_graph.gv) \
1407 (default: no)"),
064997fb
FG
1408 dump_drop_tracking_cfg: Option<String> = (None, parse_opt_string, [UNTRACKED],
1409 "dump drop-tracking control-flow graph as a `.dot` file (default: no)"),
dfeec247
XL
1410 dump_mir: Option<String> = (None, parse_opt_string, [UNTRACKED],
1411 "dump MIR state to file.
1412 `val` is used to select which passes and functions to dump. For example:
1413 `all` matches all passes and functions,
1414 `foo` matches all passes for functions whose name contains 'foo',
1415 `foo & ConstProp` only the 'ConstProp' pass for function names containing 'foo',
1416 `foo | bar` all passes for function names containing 'foo' or 'bar'."),
f9f354fc
XL
1417 dump_mir_dataflow: bool = (false, parse_bool, [UNTRACKED],
1418 "in addition to `.mir` files, create graphviz `.dot` files with dataflow results \
1419 (default: no)"),
ba9703b0
XL
1420 dump_mir_dir: String = ("mir_dump".to_string(), parse_string, [UNTRACKED],
1421 "the directory the MIR is dumped into (default: `mir_dump`)"),
dfeec247 1422 dump_mir_exclude_pass_number: bool = (false, parse_bool, [UNTRACKED],
ba9703b0 1423 "exclude the pass number when dumping MIR (used in tests) (default: no)"),
f9f354fc 1424 dump_mir_graphviz: bool = (false, parse_bool, [UNTRACKED],
29967ef6
XL
1425 "in addition to `.mir` files, create graphviz `.dot` files (and with \
1426 `-Z instrument-coverage`, also create a `.dot` file for the MIR-derived \
1427 coverage graph) (default: no)"),
1b1a35ee
XL
1428 dump_mir_spanview: Option<MirSpanview> = (None, parse_mir_spanview, [UNTRACKED],
1429 "in addition to `.mir` files, create `.html` files to view spans for \
1430 all `statement`s (including terminators), only `terminator` spans, or \
1431 computed `block` spans (one span encompassing a block's terminator and \
29967ef6
XL
1432 all statements). If `-Z instrument-coverage` is also enabled, create \
1433 an additional `.html` file showing the computed coverage spans."),
9c376795
FG
1434 dump_mono_stats: SwitchWithOptPath = (SwitchWithOptPath::Disabled,
1435 parse_switch_with_opt_path, [UNTRACKED],
1436 "output statistics about monomorphization collection"),
1437 dump_mono_stats_format: DumpMonoStatsFormat = (DumpMonoStatsFormat::Markdown, parse_dump_mono_stats, [UNTRACKED],
1438 "the format to use for -Z dump-mono-stats (`markdown` (default) or `json`)"),
064997fb
FG
1439 dwarf_version: Option<u32> = (None, parse_opt_number, [TRACKED],
1440 "version of DWARF debug information to emit (default: 2 or 4, depending on platform)"),
2b03887a
FG
1441 dylib_lto: bool = (false, parse_bool, [UNTRACKED],
1442 "enables LTO for dylib crate type"),
f9f354fc
XL
1443 emit_stack_sizes: bool = (false, parse_bool, [UNTRACKED],
1444 "emit a section containing stack size metadata (default: no)"),
064997fb
FG
1445 emit_thin_lto: bool = (true, parse_bool, [TRACKED],
1446 "emit the bc module with thin LTO info (default: yes)"),
1447 export_executable_symbols: bool = (false, parse_bool, [TRACKED],
1448 "export symbols from executables, as if they were dynamic libraries"),
f2b60f7d
FG
1449 extra_const_ub_checks: bool = (false, parse_bool, [TRACKED],
1450 "turns on more checks to detect const UB, which can be slow (default: no)"),
1451 #[rustc_lint_opt_deny_field_access("use `Session::fewer_names` instead of this field")]
fc512014 1452 fewer_names: Option<bool> = (None, parse_opt_bool, [TRACKED],
f9f354fc 1453 "reduce memory use by retaining fewer names within compilation artifacts (LLVM-IR) \
ba9703b0 1454 (default: no)"),
353b0b11
FG
1455 flatten_format_args: bool = (false, parse_bool, [TRACKED],
1456 "flatten nested format_args!() and literals into a simplified format_args!() call \
1457 (default: no)"),
f9f354fc
XL
1458 force_unstable_if_unmarked: bool = (false, parse_bool, [TRACKED],
1459 "force all crates to be `rustc_private` unstable (default: no)"),
1460 fuel: Option<(String, u64)> = (None, parse_optimization_fuel, [TRACKED],
1461 "set the optimization fuel quota for a crate"),
29967ef6
XL
1462 function_sections: Option<bool> = (None, parse_opt_bool, [TRACKED],
1463 "whether each function should go in its own section"),
136023e0
XL
1464 future_incompat_test: bool = (false, parse_bool, [UNTRACKED],
1465 "forces all lints to be future incompatible, used for internal testing (default: no)"),
17df50a5 1466 gcc_ld: Option<LdImpl> = (None, parse_gcc_ld, [TRACKED], "implementation of ld used by cc"),
1b1a35ee
XL
1467 graphviz_dark_mode: bool = (false, parse_bool, [UNTRACKED],
1468 "use dark-themed colors in graphviz output (default: no)"),
1469 graphviz_font: String = ("Courier, monospace".to_string(), parse_string, [UNTRACKED],
1470 "use the given `fontname` in graphviz output; can be overridden by setting \
1471 environment variable `RUSTC_GRAPHVIZ_FONT` (default: `Courier, monospace`)"),
dfeec247 1472 hir_stats: bool = (false, parse_bool, [UNTRACKED],
ba9703b0 1473 "print some statistics about AST and HIR (default: no)"),
f9f354fc
XL
1474 human_readable_cgu_names: bool = (false, parse_bool, [TRACKED],
1475 "generate human-readable, predictable names for codegen units (default: no)"),
1476 identify_regions: bool = (false, parse_bool, [UNTRACKED],
1477 "display unnamed regions as `'<id>`, using a non-ident unique id (default: no)"),
9c376795 1478 incremental_ignore_spans: bool = (false, parse_bool, [TRACKED],
f9f354fc
XL
1479 "ignore spans during ICH computation -- used for testing (default: no)"),
1480 incremental_info: bool = (false, parse_bool, [UNTRACKED],
1481 "print high-level information about incremental reuse (or the lack thereof) \
1482 (default: no)"),
9c376795 1483 #[rustc_lint_opt_deny_field_access("use `Session::incremental_relative_spans` instead of this field")]
c295e0f8
XL
1484 incremental_relative_spans: bool = (false, parse_bool, [TRACKED],
1485 "hash spans relative to their parent item for incr. comp. (default: no)"),
f9f354fc
XL
1486 incremental_verify_ich: bool = (false, parse_bool, [UNTRACKED],
1487 "verify incr. comp. hashes of green query instances (default: no)"),
2b03887a
FG
1488 inline_in_all_cgus: Option<bool> = (None, parse_opt_bool, [TRACKED],
1489 "control whether `#[inline]` functions are in all CGUs"),
f2b60f7d
FG
1490 inline_llvm: bool = (true, parse_bool, [TRACKED],
1491 "enable LLVM inlining (default: yes)"),
6a06907d
XL
1492 inline_mir: Option<bool> = (None, parse_opt_bool, [TRACKED],
1493 "enable MIR inlining (default: no)"),
cdc7bbd5 1494 inline_mir_hint_threshold: Option<usize> = (None, parse_opt_number, [TRACKED],
29967ef6 1495 "inlining threshold for functions with inline hint (default: 100)"),
2b03887a
FG
1496 inline_mir_threshold: Option<usize> = (None, parse_opt_number, [TRACKED],
1497 "a default MIR inlining threshold (default: 50)"),
f9f354fc
XL
1498 input_stats: bool = (false, parse_bool, [UNTRACKED],
1499 "gather statistics about the input (default: no)"),
f2b60f7d 1500 #[rustc_lint_opt_deny_field_access("use `Session::instrument_coverage` instead of this field")]
cdc7bbd5 1501 instrument_coverage: Option<InstrumentCoverage> = (None, parse_instrument_coverage, [TRACKED],
3dfed10e 1502 "instrument the generated code to support LLVM source-based code coverage \
17df50a5 1503 reports (note, the compiler build config must include `profiler = true`); \
a2a8927a 1504 implies `-C symbol-mangling-version=v0`. Optional values are:
17df50a5
XL
1505 `=all` (implicit value)
1506 `=except-unused-generics`
1507 `=except-unused-functions`
1508 `=off` (default)"),
f9f354fc
XL
1509 instrument_mcount: bool = (false, parse_bool, [TRACKED],
1510 "insert function instrument code for mcount-based tracing (default: no)"),
9ffffee4
FG
1511 instrument_xray: Option<InstrumentXRay> = (None, parse_instrument_xray, [TRACKED],
1512 "insert function instrument code for XRay-based tracing (default: no)
1513 Optional extra settings:
1514 `=always`
1515 `=never`
1516 `=ignore-loops`
1517 `=instruction-threshold=N`
1518 `=skip-entry`
1519 `=skip-exit`
1520 Multiple options can be combined with commas."),
f9f354fc
XL
1521 keep_hygiene_data: bool = (false, parse_bool, [UNTRACKED],
1522 "keep hygiene data after analysis (default: no)"),
2b03887a
FG
1523 layout_seed: Option<u64> = (None, parse_opt_number, [TRACKED],
1524 "seed layout randomization"),
9ffffee4
FG
1525 link_directives: bool = (true, parse_bool, [TRACKED],
1526 "honor #[link] directives in the compiled crate (default: yes)"),
f9f354fc
XL
1527 link_native_libraries: bool = (true, parse_bool, [UNTRACKED],
1528 "link native libraries in the linker invocation (default: yes)"),
1529 link_only: bool = (false, parse_bool, [TRACKED],
1530 "link the `.rlink` file generated by `-Z no-link` (default: no)"),
136023e0
XL
1531 llvm_plugins: Vec<String> = (Vec::new(), parse_list, [TRACKED],
1532 "a list LLVM plugins to enable (space separated)"),
f9f354fc
XL
1533 llvm_time_trace: bool = (false, parse_bool, [UNTRACKED],
1534 "generate JSON tracing data file from LLVM data (default: no)"),
3c0e092e 1535 location_detail: LocationDetail = (LocationDetail::all(), parse_location_detail, [TRACKED],
064997fb
FG
1536 "what location details should be tracked when using caller_location, either \
1537 `none`, or a comma separated list of location details, for which \
1538 valid options are `file`, `line`, and `column` (default: `file,line,column`)"),
9ffffee4
FG
1539 lower_impl_trait_in_trait_to_assoc_ty: bool = (false, parse_bool, [TRACKED],
1540 "modify the lowering strategy for `impl Trait` in traits so that they are lowered to \
1541 generic associated types"),
f9f354fc
XL
1542 ls: bool = (false, parse_bool, [UNTRACKED],
1543 "list the symbols defined by a library crate (default: no)"),
1544 macro_backtrace: bool = (false, parse_bool, [UNTRACKED],
1545 "show macro backtraces (default: no)"),
487cf647
FG
1546 maximal_hir_to_mir_coverage: bool = (false, parse_bool, [TRACKED],
1547 "save as much information as possible about the correspondence between MIR and HIR \
1548 as source scopes (default: no)"),
f9f354fc
XL
1549 merge_functions: Option<MergeFunctions> = (None, parse_merge_functions, [TRACKED],
1550 "control the operation of the MergeFunctions LLVM pass, taking \
1551 the same values as the target option of the same name"),
1552 meta_stats: bool = (false, parse_bool, [UNTRACKED],
1553 "gather metadata statistics (default: no)"),
1554 mir_emit_retag: bool = (false, parse_bool, [TRACKED],
1555 "emit Retagging MIR statements, interpreted e.g., by miri; implies -Zmir-opt-level=0 \
1556 (default: no)"),
04454e1e
FG
1557 mir_enable_passes: Vec<(String, bool)> = (Vec::new(), parse_list_with_polarity, [TRACKED],
1558 "use like `-Zmir-enable-passes=+DestProp,-InstCombine`. Forces the specified passes to be \
1559 enabled, overriding all other checks. Passes that are not specified are enabled or \
1560 disabled by other flags as usual."),
f2b60f7d 1561 #[rustc_lint_opt_deny_field_access("use `Session::mir_opt_level` instead of this field")]
cdc7bbd5 1562 mir_opt_level: Option<usize> = (None, parse_opt_number, [TRACKED],
6a06907d 1563 "MIR optimization level (0-4; default: 1 in non optimized builds and 2 in optimized builds)"),
2b03887a
FG
1564 mir_pretty_relative_line_numbers: bool = (false, parse_bool, [UNTRACKED],
1565 "use line numbers relative to the function in mir pretty printing"),
94222f64
XL
1566 move_size_limit: Option<usize> = (None, parse_opt_number, [TRACKED],
1567 "the size at which the `large_assignments` lint starts to be emitted"),
9c376795 1568 mutable_noalias: bool = (true, parse_bool, [TRACKED],
3c0e092e 1569 "emit noalias metadata for mutable references (default: yes)"),
f9f354fc
XL
1570 nll_facts: bool = (false, parse_bool, [UNTRACKED],
1571 "dump facts from NLL analysis into side files (default: no)"),
29967ef6
XL
1572 nll_facts_dir: String = ("nll-facts".to_string(), parse_string, [UNTRACKED],
1573 "the directory the NLL facts are dumped into (default: `nll-facts`)"),
f9f354fc
XL
1574 no_analysis: bool = (false, parse_no_flag, [UNTRACKED],
1575 "parse and expand the source, but run no analysis"),
136023e0 1576 no_codegen: bool = (false, parse_no_flag, [TRACKED_NO_CRATE_HASH],
f9f354fc
XL
1577 "run all passes except codegen; no output"),
1578 no_generate_arange_section: bool = (false, parse_no_flag, [TRACKED],
1579 "omit DWARF address ranges that give faster lookups"),
9c376795
FG
1580 no_jump_tables: bool = (false, parse_no_flag, [TRACKED],
1581 "disable the jump tables and lookup tables that can be generated from a switch case lowering"),
f9f354fc
XL
1582 no_leak_check: bool = (false, parse_no_flag, [UNTRACKED],
1583 "disable the 'leak check' for subtyping; unsound, but useful for tests"),
1584 no_link: bool = (false, parse_no_flag, [TRACKED],
1585 "compile without linking"),
1586 no_parallel_llvm: bool = (false, parse_no_flag, [UNTRACKED],
1587 "run LLVM in non-parallel mode (while keeping codegen-units and ThinLTO)"),
94222f64
XL
1588 no_profiler_runtime: bool = (false, parse_no_flag, [TRACKED],
1589 "prevent automatic injection of the profiler_builtins crate"),
2b03887a
FG
1590 no_unique_section_names: bool = (false, parse_bool, [TRACKED],
1591 "do not use unique names for text and data sections when -Z function-sections is used"),
fc512014
XL
1592 normalize_docs: bool = (false, parse_bool, [TRACKED],
1593 "normalize associated items in rustdoc when generating documentation"),
5e7ed085
FG
1594 oom: OomStrategy = (OomStrategy::Abort, parse_oom_strategy, [TRACKED],
1595 "panic strategy for out-of-memory handling"),
dfeec247 1596 osx_rpath_install_name: bool = (false, parse_bool, [TRACKED],
ba9703b0 1597 "pass `-install_name @rpath/...` to the macOS linker (default: no)"),
f2b60f7d
FG
1598 packed_bundled_libs: bool = (false, parse_bool, [TRACKED],
1599 "change rlib format to store native libraries as archives"),
f9f354fc
XL
1600 panic_abort_tests: bool = (false, parse_bool, [TRACKED],
1601 "support compiling tests with panic=abort (default: no)"),
c295e0f8
XL
1602 panic_in_drop: PanicStrategy = (PanicStrategy::Unwind, parse_panic_strategy, [TRACKED],
1603 "panic strategy for panics in drops"),
f9f354fc
XL
1604 parse_only: bool = (false, parse_bool, [UNTRACKED],
1605 "parse only; do not compile, assemble, or link (default: no)"),
1606 perf_stats: bool = (false, parse_bool, [UNTRACKED],
1607 "print some performance-related statistics (default: no)"),
1608 plt: Option<bool> = (None, parse_opt_bool, [TRACKED],
1609 "whether to use the PLT when calling into shared libraries;
1610 only has effect for PIC code on systems with ELF binaries
1611 (default: PLT is disabled if full relro is enabled)"),
fc512014 1612 polonius: bool = (false, parse_bool, [TRACKED],
f9f354fc 1613 "enable polonius-based borrow-checker (default: no)"),
3dfed10e
XL
1614 polymorphize: bool = (false, parse_bool, [TRACKED],
1615 "perform polymorphization analysis"),
ba9703b0 1616 pre_link_arg: (/* redirected to pre_link_args */) = ((), parse_string_push, [UNTRACKED],
dfeec247 1617 "a single extra argument to prepend the linker invocation (can be used several times)"),
ba9703b0 1618 pre_link_args: Vec<String> = (Vec::new(), parse_list, [UNTRACKED],
dfeec247 1619 "extra arguments to prepend to the linker invocation (space separated)"),
1b1a35ee
XL
1620 precise_enum_drop_elaboration: bool = (true, parse_bool, [TRACKED],
1621 "use a more precise version of drop elaboration for matches on enums (default: yes). \
1622 This results in better codegen, but has caused miscompilations on some tier 2 platforms. \
1623 See #77382 and #74551."),
f9f354fc
XL
1624 print_fuel: Option<String> = (None, parse_opt_string, [TRACKED],
1625 "make rustc print the total optimization fuel used by a crate"),
f9f354fc
XL
1626 print_llvm_passes: bool = (false, parse_bool, [UNTRACKED],
1627 "print the LLVM optimization passes being run (default: no)"),
1628 print_mono_items: Option<String> = (None, parse_opt_string, [UNTRACKED],
1629 "print the result of the monomorphization collection pass"),
f9f354fc
XL
1630 print_type_sizes: bool = (false, parse_bool, [UNTRACKED],
1631 "print layout information for each type encountered (default: no)"),
1b1a35ee
XL
1632 proc_macro_backtrace: bool = (false, parse_bool, [UNTRACKED],
1633 "show backtraces for panics during proc-macro execution (default: no)"),
064997fb
FG
1634 proc_macro_execution_strategy: ProcMacroExecutionStrategy = (ProcMacroExecutionStrategy::SameThread,
1635 parse_proc_macro_execution_strategy, [UNTRACKED],
1636 "how to run proc-macro code (default: same-thread)"),
dfeec247 1637 profile: bool = (false, parse_bool, [TRACKED],
ba9703b0 1638 "insert profiling code (default: no)"),
136023e0
XL
1639 profile_closures: bool = (false, parse_no_flag, [UNTRACKED],
1640 "profile size of closures"),
f9f354fc
XL
1641 profile_emit: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
1642 "file path to emit profiling data at runtime when using 'profile' \
1643 (default based on relative source path)"),
c295e0f8
XL
1644 profile_sample_use: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
1645 "use the given `.prof` file for sampled profile-guided optimization (also known as AutoFDO)"),
2b03887a
FG
1646 profiler_runtime: String = (String::from("profiler_builtins"), parse_string, [TRACKED],
1647 "name of the profiler runtime crate to automatically inject (default: `profiler_builtins`)"),
f9f354fc
XL
1648 query_dep_graph: bool = (false, parse_bool, [UNTRACKED],
1649 "enable queries of the dependency graph for regression testing (default: no)"),
c295e0f8
XL
1650 randomize_layout: bool = (false, parse_bool, [TRACKED],
1651 "randomize the layout of types (default: no)"),
29967ef6
XL
1652 relax_elf_relocations: Option<bool> = (None, parse_opt_bool, [TRACKED],
1653 "whether ELF relocations can be relaxed"),
dfeec247
XL
1654 relro_level: Option<RelroLevel> = (None, parse_relro_level, [TRACKED],
1655 "choose which RELRO level to use"),
c295e0f8
XL
1656 remap_cwd_prefix: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
1657 "remap paths under the current working directory to this path prefix"),
f9f354fc
XL
1658 report_delayed_bugs: bool = (false, parse_bool, [TRACKED],
1659 "immediately print bugs registered with `delay_span_bug` (default: no)"),
f035d41b 1660 sanitizer: SanitizerSet = (SanitizerSet::empty(), parse_sanitizers, [TRACKED],
f9f354fc
XL
1661 "use a sanitizer"),
1662 sanitizer_memory_track_origins: usize = (0, parse_sanitizer_memory_track_origins, [TRACKED],
1663 "enable origins tracking in MemorySanitizer"),
f035d41b 1664 sanitizer_recover: SanitizerSet = (SanitizerSet::empty(), parse_sanitizers, [TRACKED],
f9f354fc
XL
1665 "enable recovery for selected sanitizers"),
1666 saturating_float_casts: Option<bool> = (None, parse_opt_bool, [TRACKED],
1667 "make float->int casts UB-free: numbers outside the integer type's range are clipped to \
1668 the max/min integer respectively, and NaN is mapped to 0 (default: yes)"),
dfeec247
XL
1669 self_profile: SwitchWithOptPath = (SwitchWithOptPath::Disabled,
1670 parse_switch_with_opt_path, [UNTRACKED],
1671 "run the self profiler and output the raw event data"),
923072b8
FG
1672 self_profile_counter: String = ("wall-time".to_string(), parse_string, [UNTRACKED],
1673 "counter used by the self profiler (default: `wall-time`), one of:
1674 `wall-time` (monotonic clock, i.e. `std::time::Instant`)
1675 `instructions:u` (retired instructions, userspace-only)
1676 `instructions-minus-irqs:u` (subtracting hardware interrupt counts for extra accuracy)"
1677 ),
2b03887a
FG
1678 /// keep this in sync with the event filter names in librustc_data_structures/profiling.rs
1679 self_profile_events: Option<Vec<String>> = (None, parse_opt_comma_list, [UNTRACKED],
1680 "specify the events recorded by the self profiler;
1681 for example: `-Z self-profile-events=default,query-keys`
1682 all options: none, all, default, generic-activity, query-provider, query-cache-hit
1683 query-blocked, incr-cache-load, incr-result-hashing, query-keys, function-args, args, llvm, artifact-sizes"),
f9f354fc
XL
1684 share_generics: Option<bool> = (None, parse_opt_bool, [TRACKED],
1685 "make the current crate share its generic instantiations"),
1686 show_span: Option<String> = (None, parse_opt_string, [TRACKED],
1687 "show spans for compiler debugging (expr|pat|ty)"),
2b03887a
FG
1688 simulate_remapped_rust_src_base: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
1689 "simulate the effect of remap-debuginfo = true at bootstrapping by remapping path \
1690 to rust's source base directory. only meant for testing purposes"),
f035d41b
XL
1691 span_debug: bool = (false, parse_bool, [UNTRACKED],
1692 "forward proc_macro::Span's `Debug` impl to `Span`"),
cdc7bbd5 1693 /// o/w tests have closure@path
f9f354fc
XL
1694 span_free_formats: bool = (false, parse_bool, [UNTRACKED],
1695 "exclude spans when debug-printing compiler state (default: no)"),
9c376795 1696 split_dwarf_inlining: bool = (false, parse_bool, [TRACKED],
2b03887a
FG
1697 "provide minimal debug info in the object/executable to facilitate online \
1698 symbolication/stack traces in the absence of .dwo/.dwp files when using Split DWARF"),
1699 split_dwarf_kind: SplitDwarfKind = (SplitDwarfKind::Split, parse_split_dwarf_kind, [TRACKED],
1700 "split dwarf variant (only if -Csplit-debuginfo is enabled and on relevant platform)
1701 (default: `split`)
1702
1703 `split`: sections which do not require relocation are written into a DWARF object (`.dwo`)
1704 file which is ignored by the linker
1705 `single`: sections which do not require relocation are written into object file but ignored
1706 by the linker"),
f9f354fc 1707 src_hash_algorithm: Option<SourceFileHashAlgorithm> = (None, parse_src_file_hash, [TRACKED],
29967ef6 1708 "hash algorithm of source files in debug info (`md5`, `sha1`, or `sha256`)"),
f2b60f7d 1709 #[rustc_lint_opt_deny_field_access("use `Session::stack_protector` instead of this field")]
3c0e092e
XL
1710 stack_protector: StackProtector = (StackProtector::None, parse_stack_protector, [TRACKED],
1711 "control stack smash protection strategy (`rustc --print stack-protector-strategies` for details)"),
923072b8
FG
1712 strict_init_checks: bool = (false, parse_bool, [TRACKED],
1713 "control if mem::uninitialized and mem::zeroed panic on more UB"),
f9f354fc
XL
1714 strip: Strip = (Strip::None, parse_strip, [UNTRACKED],
1715 "tell the linker which information to strip (`none` (default), `debuginfo` or `symbols`)"),
fc512014 1716 symbol_mangling_version: Option<SymbolManglingVersion> = (None,
dfeec247 1717 parse_symbol_mangling_version, [TRACKED],
fc512014 1718 "which mangling version to use for symbol names ('legacy' (default) or 'v0')"),
f2b60f7d 1719 #[rustc_lint_opt_deny_field_access("use `Session::teach` instead of this field")]
f9f354fc
XL
1720 teach: bool = (false, parse_bool, [TRACKED],
1721 "show extended diagnostic help (default: no)"),
3c0e092e
XL
1722 temps_dir: Option<String> = (None, parse_opt_string, [UNTRACKED],
1723 "the directory the intermediate files are written to"),
9ffffee4
FG
1724 terminal_urls: TerminalUrl = (TerminalUrl::No, parse_terminal_url, [UNTRACKED],
1725 "use the OSC 8 hyperlink terminal specification to print hyperlinks in the compiler output"),
f2b60f7d 1726 #[rustc_lint_opt_deny_field_access("use `Session::lto` instead of this field")]
f9f354fc
XL
1727 thinlto: Option<bool> = (None, parse_opt_bool, [TRACKED],
1728 "enable ThinLTO when possible"),
17df50a5 1729 thir_unsafeck: bool = (false, parse_bool, [TRACKED],
94222f64 1730 "use the THIR unsafety checker (default: no)"),
cdc7bbd5
XL
1731 /// We default to 1 here since we want to behave like
1732 /// a sequential compiler for now. This'll likely be adjusted
1733 /// in the future. Note that -Zthreads=0 is the way to get
1734 /// the num_cpus behavior.
f2b60f7d 1735 #[rustc_lint_opt_deny_field_access("use `Session::threads` instead of this field")]
f9f354fc
XL
1736 threads: usize = (1, parse_threads, [UNTRACKED],
1737 "use a thread pool with N threads"),
f9f354fc
XL
1738 time_llvm_passes: bool = (false, parse_bool, [UNTRACKED],
1739 "measure time of each LLVM pass (default: no)"),
1740 time_passes: bool = (false, parse_bool, [UNTRACKED],
1741 "measure time of each rustc pass (default: no)"),
353b0b11
FG
1742 time_passes_format: TimePassesFormat = (TimePassesFormat::Text, parse_time_passes_format, [UNTRACKED],
1743 "the format to use for -Z time-passes (`text` (default) or `json`)"),
9ffffee4
FG
1744 tiny_const_eval_limit: bool = (false, parse_bool, [TRACKED],
1745 "sets a tiny, non-configurable limit for const eval; useful for compiler tests"),
f2b60f7d 1746 #[rustc_lint_opt_deny_field_access("use `Session::tls_model` instead of this field")]
f9f354fc
XL
1747 tls_model: Option<TlsModel> = (None, parse_tls_model, [TRACKED],
1748 "choose the TLS model to use (`rustc --print tls-models` for details)"),
1749 trace_macros: bool = (false, parse_bool, [UNTRACKED],
1750 "for every macro invocation, print its name and arguments (default: no)"),
487cf647
FG
1751 track_diagnostics: bool = (false, parse_bool, [UNTRACKED],
1752 "tracks where in rustc a diagnostic was emitted"),
9c376795
FG
1753 trait_solver: TraitSolver = (TraitSolver::Classic, parse_trait_solver, [TRACKED],
1754 "specify the trait solver mode used by rustc (default: classic)"),
2b03887a
FG
1755 // Diagnostics are considered side-effects of a query (see `QuerySideEffects`) and are saved
1756 // alongside query results and changes to translation options can affect diagnostics - so
1757 // translation options should be tracked.
1758 translate_additional_ftl: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
1759 "additional fluent translation to preferentially use (for testing translation)"),
1760 translate_directionality_markers: bool = (false, parse_bool, [TRACKED],
1761 "emit directionality isolation markers in translated diagnostics"),
1762 translate_lang: Option<LanguageIdentifier> = (None, parse_opt_langid, [TRACKED],
1763 "language identifier for diagnostic output"),
923072b8
FG
1764 translate_remapped_path_to_local_path: bool = (true, parse_bool, [TRACKED],
1765 "translate remapped paths into local paths when possible (default: yes)"),
fc512014
XL
1766 trap_unreachable: Option<bool> = (None, parse_opt_bool, [TRACKED],
1767 "generate trap instructions for unreachable intrinsics (default: use target setting, usually yes)"),
6a06907d 1768 treat_err_as_bug: Option<NonZeroUsize> = (None, parse_treat_err_as_bug, [TRACKED],
f9f354fc 1769 "treat error number `val` that occurs as bug"),
1b1a35ee
XL
1770 trim_diagnostic_paths: bool = (true, parse_bool, [UNTRACKED],
1771 "in diagnostics, use heuristics to shorten paths referring to items"),
2b03887a
FG
1772 tune_cpu: Option<String> = (None, parse_opt_string, [TRACKED],
1773 "select processor to schedule for (`rustc --print target-cpus` for details)"),
f9f354fc
XL
1774 ui_testing: bool = (false, parse_bool, [UNTRACKED],
1775 "emit compiler diagnostics in a form suitable for UI testing (default: no)"),
5e7ed085
FG
1776 uninit_const_chunk_threshold: usize = (16, parse_number, [TRACKED],
1777 "allow generating const initializers with mixed init/uninit chunks, \
1778 and set the maximum number of chunks for which this is allowed (default: 16)"),
f9f354fc
XL
1779 unleash_the_miri_inside_of_you: bool = (false, parse_bool, [TRACKED],
1780 "take the brakes off const evaluation. NOTE: this is unsound (default: no)"),
1781 unpretty: Option<String> = (None, parse_unpretty, [UNTRACKED],
1782 "present the input source, unstable (and less-pretty) variants;
94222f64 1783 `normal`, `identified`,
f9f354fc
XL
1784 `expanded`, `expanded,identified`,
1785 `expanded,hygiene` (with internal representations),
6a06907d
XL
1786 `ast-tree` (raw AST before expansion),
1787 `ast-tree,expanded` (raw AST after expansion),
f9f354fc
XL
1788 `hir` (the HIR), `hir,identified`,
1789 `hir,typed` (HIR with types for each node),
1790 `hir-tree` (dump the raw HIR),
1791 `mir` (the MIR), or `mir-cfg` (graphviz formatted MIR)"),
1b1a35ee
XL
1792 unsound_mir_opts: bool = (false, parse_bool, [TRACKED],
1793 "enable unsound and buggy MIR optimizations (default: no)"),
064997fb
FG
1794 /// This name is kind of confusing: Most unstable options enable something themselves, while
1795 /// this just allows "normal" options to be feature-gated.
f2b60f7d 1796 #[rustc_lint_opt_deny_field_access("use `Session::unstable_options` instead of this field")]
f9f354fc
XL
1797 unstable_options: bool = (false, parse_bool, [UNTRACKED],
1798 "adds unstable command line options to rustc interface (default: no)"),
1799 use_ctors_section: Option<bool> = (None, parse_opt_bool, [TRACKED],
1800 "use legacy .ctors section for initializers rather than .init_array"),
1801 validate_mir: bool = (false, parse_bool, [UNTRACKED],
1802 "validate MIR after each transformation"),
f2b60f7d 1803 #[rustc_lint_opt_deny_field_access("use `Session::verbose` instead of this field")]
f9f354fc
XL
1804 verbose: bool = (false, parse_bool, [UNTRACKED],
1805 "in general, enable more debug printouts (default: no)"),
f2b60f7d 1806 #[rustc_lint_opt_deny_field_access("use `Session::verify_llvm_ir` instead of this field")]
f9f354fc
XL
1807 verify_llvm_ir: bool = (false, parse_bool, [TRACKED],
1808 "verify LLVM IR (default: no)"),
923072b8
FG
1809 virtual_function_elimination: bool = (false, parse_bool, [TRACKED],
1810 "enables dead virtual function elimination optimization. \
1811 Requires `-Clto[=[fat,yes]]`"),
5869c6ff
XL
1812 wasi_exec_model: Option<WasiExecModel> = (None, parse_wasi_exec_model, [TRACKED],
1813 "whether to build a wasi command or reactor"),
2b03887a 1814 // tidy-alphabetical-end
f9f354fc 1815
f9f354fc 1816 // If you add a new option, please update:
5869c6ff
XL
1817 // - compiler/rustc_interface/src/tests.rs
1818}
1819
cdc7bbd5 1820#[derive(Clone, Hash, PartialEq, Eq, Debug)]
5869c6ff
XL
1821pub enum WasiExecModel {
1822 Command,
1823 Reactor,
dfeec247 1824}
17df50a5
XL
1825
1826#[derive(Clone, Copy, Hash)]
1827pub enum LdImpl {
1828 Lld,
1829}