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