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