]>
Commit | Line | Data |
---|---|---|
e74abb32 XL |
1 | use crate::interface::parse_cfgspecs; |
2 | ||
dfeec247 XL |
3 | use rustc_data_structures::fx::FxHashSet; |
4 | use rustc_errors::{emitter::HumanReadableErrorType, registry, ColorConfig}; | |
f9f354fc | 5 | use rustc_session::config::Strip; |
ba9703b0 XL |
6 | use rustc_session::config::{build_configuration, build_session_options, to_crate_config}; |
7 | use rustc_session::config::{rustc_optgroups, ErrorOutputType, ExternLocation, Options, Passes}; | |
f9f354fc | 8 | use rustc_session::config::{CFGuard, ExternEntry, LinkerPluginLto, LtoCli, SwitchWithOptPath}; |
f035d41b XL |
9 | use rustc_session::config::{ |
10 | Externs, OutputType, OutputTypes, SanitizerSet, SymbolManglingVersion, | |
11 | }; | |
ba9703b0 XL |
12 | use rustc_session::lint::Level; |
13 | use rustc_session::search_paths::SearchPath; | |
f9f354fc XL |
14 | use rustc_session::utils::NativeLibKind; |
15 | use rustc_session::{build_session, getopts, DiagnosticOutput, Session}; | |
dfeec247 XL |
16 | use rustc_span::edition::{Edition, DEFAULT_EDITION}; |
17 | use rustc_span::symbol::sym; | |
f9f354fc XL |
18 | use rustc_span::SourceFileHashAlgorithm; |
19 | use rustc_target::spec::{CodeModel, LinkerFlavor, MergeFunctions, PanicStrategy}; | |
20 | use rustc_target::spec::{RelocModel, RelroLevel, TlsModel}; | |
dc9dc135 XL |
21 | use std::collections::{BTreeMap, BTreeSet}; |
22 | use std::iter::FromIterator; | |
23 | use std::path::PathBuf; | |
e74abb32 | 24 | |
60c5eb7d XL |
25 | type CfgSpecs = FxHashSet<(String, Option<String>)>; |
26 | ||
27 | fn build_session_options_and_crate_config(matches: getopts::Matches) -> (Options, CfgSpecs) { | |
28 | let sessopts = build_session_options(&matches); | |
29 | let cfg = parse_cfgspecs(matches.opt_strs("cfg")); | |
30 | (sessopts, cfg) | |
31 | } | |
32 | ||
33 | fn mk_session(matches: getopts::Matches) -> (Session, CfgSpecs) { | |
34 | let registry = registry::Registry::new(&[]); | |
35 | let (sessopts, cfg) = build_session_options_and_crate_config(matches); | |
f9f354fc XL |
36 | let sess = build_session( |
37 | sessopts, | |
38 | None, | |
39 | registry, | |
40 | DiagnosticOutput::Default, | |
41 | Default::default(), | |
42 | None, | |
1b1a35ee | 43 | None, |
f9f354fc | 44 | ); |
60c5eb7d | 45 | (sess, cfg) |
e74abb32 XL |
46 | } |
47 | ||
48 | fn new_public_extern_entry<S, I>(locations: I) -> ExternEntry | |
49 | where | |
50 | S: Into<String>, | |
60c5eb7d | 51 | I: IntoIterator<Item = S>, |
e74abb32 | 52 | { |
dfeec247 | 53 | let locations: BTreeSet<_> = locations.into_iter().map(|s| s.into()).collect(); |
e74abb32 XL |
54 | |
55 | ExternEntry { | |
60c5eb7d XL |
56 | location: ExternLocation::ExactPaths(locations), |
57 | is_private_dep: false, | |
58 | add_prelude: true, | |
dc9dc135 XL |
59 | } |
60 | } | |
61 | ||
62 | fn optgroups() -> getopts::Options { | |
63 | let mut opts = getopts::Options::new(); | |
e74abb32 | 64 | for group in rustc_optgroups() { |
dc9dc135 XL |
65 | (group.apply)(&mut opts); |
66 | } | |
67 | return opts; | |
68 | } | |
69 | ||
70 | fn mk_map<K: Ord, V>(entries: Vec<(K, V)>) -> BTreeMap<K, V> { | |
71 | BTreeMap::from_iter(entries.into_iter()) | |
72 | } | |
73 | ||
74 | // When the user supplies --test we should implicitly supply --cfg test | |
75 | #[test] | |
76 | fn test_switch_implies_cfg_test() { | |
3dfed10e | 77 | rustc_span::with_default_session_globals(|| { |
60c5eb7d XL |
78 | let matches = optgroups().parse(&["--test".to_string()]).unwrap(); |
79 | let (sess, cfg) = mk_session(matches); | |
dc9dc135 XL |
80 | let cfg = build_configuration(&sess, to_crate_config(cfg)); |
81 | assert!(cfg.contains(&(sym::test, None))); | |
82 | }); | |
83 | } | |
84 | ||
60c5eb7d | 85 | // When the user supplies --test and --cfg test, don't implicitly add another --cfg test |
dc9dc135 XL |
86 | #[test] |
87 | fn test_switch_implies_cfg_test_unless_cfg_test() { | |
3dfed10e | 88 | rustc_span::with_default_session_globals(|| { |
60c5eb7d XL |
89 | let matches = optgroups().parse(&["--test".to_string(), "--cfg=test".to_string()]).unwrap(); |
90 | let (sess, cfg) = mk_session(matches); | |
dc9dc135 XL |
91 | let cfg = build_configuration(&sess, to_crate_config(cfg)); |
92 | let mut test_items = cfg.iter().filter(|&&(name, _)| name == sym::test); | |
93 | assert!(test_items.next().is_some()); | |
94 | assert!(test_items.next().is_none()); | |
95 | }); | |
96 | } | |
97 | ||
98 | #[test] | |
99 | fn test_can_print_warnings() { | |
3dfed10e | 100 | rustc_span::with_default_session_globals(|| { |
dc9dc135 | 101 | let matches = optgroups().parse(&["-Awarnings".to_string()]).unwrap(); |
60c5eb7d | 102 | let (sess, _) = mk_session(matches); |
e1599b0c | 103 | assert!(!sess.diagnostic().can_emit_warnings()); |
dc9dc135 XL |
104 | }); |
105 | ||
3dfed10e | 106 | rustc_span::with_default_session_globals(|| { |
dfeec247 XL |
107 | let matches = |
108 | optgroups().parse(&["-Awarnings".to_string(), "-Dwarnings".to_string()]).unwrap(); | |
60c5eb7d | 109 | let (sess, _) = mk_session(matches); |
e1599b0c | 110 | assert!(sess.diagnostic().can_emit_warnings()); |
dc9dc135 XL |
111 | }); |
112 | ||
3dfed10e | 113 | rustc_span::with_default_session_globals(|| { |
dc9dc135 | 114 | let matches = optgroups().parse(&["-Adead_code".to_string()]).unwrap(); |
60c5eb7d | 115 | let (sess, _) = mk_session(matches); |
e1599b0c | 116 | assert!(sess.diagnostic().can_emit_warnings()); |
dc9dc135 XL |
117 | }); |
118 | } | |
119 | ||
120 | #[test] | |
121 | fn test_output_types_tracking_hash_different_paths() { | |
122 | let mut v1 = Options::default(); | |
123 | let mut v2 = Options::default(); | |
124 | let mut v3 = Options::default(); | |
125 | ||
dfeec247 XL |
126 | v1.output_types = OutputTypes::new(&[(OutputType::Exe, Some(PathBuf::from("./some/thing")))]); |
127 | v2.output_types = OutputTypes::new(&[(OutputType::Exe, Some(PathBuf::from("/some/thing")))]); | |
dc9dc135 XL |
128 | v3.output_types = OutputTypes::new(&[(OutputType::Exe, None)]); |
129 | ||
130 | assert!(v1.dep_tracking_hash() != v2.dep_tracking_hash()); | |
131 | assert!(v1.dep_tracking_hash() != v3.dep_tracking_hash()); | |
132 | assert!(v2.dep_tracking_hash() != v3.dep_tracking_hash()); | |
133 | ||
134 | // Check clone | |
135 | assert_eq!(v1.dep_tracking_hash(), v1.clone().dep_tracking_hash()); | |
136 | assert_eq!(v2.dep_tracking_hash(), v2.clone().dep_tracking_hash()); | |
137 | assert_eq!(v3.dep_tracking_hash(), v3.clone().dep_tracking_hash()); | |
138 | } | |
139 | ||
140 | #[test] | |
141 | fn test_output_types_tracking_hash_different_construction_order() { | |
142 | let mut v1 = Options::default(); | |
143 | let mut v2 = Options::default(); | |
144 | ||
145 | v1.output_types = OutputTypes::new(&[ | |
146 | (OutputType::Exe, Some(PathBuf::from("./some/thing"))), | |
147 | (OutputType::Bitcode, Some(PathBuf::from("./some/thing.bc"))), | |
148 | ]); | |
149 | ||
150 | v2.output_types = OutputTypes::new(&[ | |
151 | (OutputType::Bitcode, Some(PathBuf::from("./some/thing.bc"))), | |
152 | (OutputType::Exe, Some(PathBuf::from("./some/thing"))), | |
153 | ]); | |
154 | ||
155 | assert_eq!(v1.dep_tracking_hash(), v2.dep_tracking_hash()); | |
156 | ||
157 | // Check clone | |
158 | assert_eq!(v1.dep_tracking_hash(), v1.clone().dep_tracking_hash()); | |
159 | } | |
160 | ||
161 | #[test] | |
162 | fn test_externs_tracking_hash_different_construction_order() { | |
163 | let mut v1 = Options::default(); | |
164 | let mut v2 = Options::default(); | |
165 | let mut v3 = Options::default(); | |
166 | ||
167 | v1.externs = Externs::new(mk_map(vec![ | |
dfeec247 XL |
168 | (String::from("a"), new_public_extern_entry(vec!["b", "c"])), |
169 | (String::from("d"), new_public_extern_entry(vec!["e", "f"])), | |
dc9dc135 XL |
170 | ])); |
171 | ||
172 | v2.externs = Externs::new(mk_map(vec![ | |
dfeec247 XL |
173 | (String::from("d"), new_public_extern_entry(vec!["e", "f"])), |
174 | (String::from("a"), new_public_extern_entry(vec!["b", "c"])), | |
dc9dc135 XL |
175 | ])); |
176 | ||
177 | v3.externs = Externs::new(mk_map(vec![ | |
dfeec247 XL |
178 | (String::from("a"), new_public_extern_entry(vec!["b", "c"])), |
179 | (String::from("d"), new_public_extern_entry(vec!["f", "e"])), | |
dc9dc135 XL |
180 | ])); |
181 | ||
182 | assert_eq!(v1.dep_tracking_hash(), v2.dep_tracking_hash()); | |
183 | assert_eq!(v1.dep_tracking_hash(), v3.dep_tracking_hash()); | |
184 | assert_eq!(v2.dep_tracking_hash(), v3.dep_tracking_hash()); | |
185 | ||
186 | // Check clone | |
187 | assert_eq!(v1.dep_tracking_hash(), v1.clone().dep_tracking_hash()); | |
188 | assert_eq!(v2.dep_tracking_hash(), v2.clone().dep_tracking_hash()); | |
189 | assert_eq!(v3.dep_tracking_hash(), v3.clone().dep_tracking_hash()); | |
190 | } | |
191 | ||
192 | #[test] | |
193 | fn test_lints_tracking_hash_different_values() { | |
194 | let mut v1 = Options::default(); | |
195 | let mut v2 = Options::default(); | |
196 | let mut v3 = Options::default(); | |
197 | ||
198 | v1.lint_opts = vec![ | |
dfeec247 XL |
199 | (String::from("a"), Level::Allow), |
200 | (String::from("b"), Level::Warn), | |
201 | (String::from("c"), Level::Deny), | |
202 | (String::from("d"), Level::Forbid), | |
dc9dc135 XL |
203 | ]; |
204 | ||
205 | v2.lint_opts = vec![ | |
dfeec247 XL |
206 | (String::from("a"), Level::Allow), |
207 | (String::from("b"), Level::Warn), | |
208 | (String::from("X"), Level::Deny), | |
209 | (String::from("d"), Level::Forbid), | |
dc9dc135 XL |
210 | ]; |
211 | ||
212 | v3.lint_opts = vec![ | |
dfeec247 XL |
213 | (String::from("a"), Level::Allow), |
214 | (String::from("b"), Level::Warn), | |
215 | (String::from("c"), Level::Forbid), | |
216 | (String::from("d"), Level::Deny), | |
dc9dc135 XL |
217 | ]; |
218 | ||
219 | assert!(v1.dep_tracking_hash() != v2.dep_tracking_hash()); | |
220 | assert!(v1.dep_tracking_hash() != v3.dep_tracking_hash()); | |
221 | assert!(v2.dep_tracking_hash() != v3.dep_tracking_hash()); | |
222 | ||
223 | // Check clone | |
224 | assert_eq!(v1.dep_tracking_hash(), v1.clone().dep_tracking_hash()); | |
225 | assert_eq!(v2.dep_tracking_hash(), v2.clone().dep_tracking_hash()); | |
226 | assert_eq!(v3.dep_tracking_hash(), v3.clone().dep_tracking_hash()); | |
227 | } | |
228 | ||
229 | #[test] | |
230 | fn test_lints_tracking_hash_different_construction_order() { | |
231 | let mut v1 = Options::default(); | |
232 | let mut v2 = Options::default(); | |
233 | ||
234 | v1.lint_opts = vec![ | |
dfeec247 XL |
235 | (String::from("a"), Level::Allow), |
236 | (String::from("b"), Level::Warn), | |
237 | (String::from("c"), Level::Deny), | |
238 | (String::from("d"), Level::Forbid), | |
dc9dc135 XL |
239 | ]; |
240 | ||
241 | v2.lint_opts = vec![ | |
dfeec247 XL |
242 | (String::from("a"), Level::Allow), |
243 | (String::from("c"), Level::Deny), | |
244 | (String::from("b"), Level::Warn), | |
245 | (String::from("d"), Level::Forbid), | |
dc9dc135 XL |
246 | ]; |
247 | ||
248 | assert_eq!(v1.dep_tracking_hash(), v2.dep_tracking_hash()); | |
249 | ||
250 | // Check clone | |
251 | assert_eq!(v1.dep_tracking_hash(), v1.clone().dep_tracking_hash()); | |
252 | assert_eq!(v2.dep_tracking_hash(), v2.clone().dep_tracking_hash()); | |
253 | } | |
254 | ||
255 | #[test] | |
256 | fn test_search_paths_tracking_hash_different_order() { | |
257 | let mut v1 = Options::default(); | |
258 | let mut v2 = Options::default(); | |
259 | let mut v3 = Options::default(); | |
260 | let mut v4 = Options::default(); | |
261 | ||
e74abb32 | 262 | const JSON: ErrorOutputType = ErrorOutputType::Json { |
dc9dc135 | 263 | pretty: false, |
e74abb32 | 264 | json_rendered: HumanReadableErrorType::Default(ColorConfig::Never), |
dc9dc135 XL |
265 | }; |
266 | ||
267 | // Reference | |
dfeec247 XL |
268 | v1.search_paths.push(SearchPath::from_cli_opt("native=abc", JSON)); |
269 | v1.search_paths.push(SearchPath::from_cli_opt("crate=def", JSON)); | |
270 | v1.search_paths.push(SearchPath::from_cli_opt("dependency=ghi", JSON)); | |
271 | v1.search_paths.push(SearchPath::from_cli_opt("framework=jkl", JSON)); | |
272 | v1.search_paths.push(SearchPath::from_cli_opt("all=mno", JSON)); | |
273 | ||
274 | v2.search_paths.push(SearchPath::from_cli_opt("native=abc", JSON)); | |
275 | v2.search_paths.push(SearchPath::from_cli_opt("dependency=ghi", JSON)); | |
276 | v2.search_paths.push(SearchPath::from_cli_opt("crate=def", JSON)); | |
277 | v2.search_paths.push(SearchPath::from_cli_opt("framework=jkl", JSON)); | |
278 | v2.search_paths.push(SearchPath::from_cli_opt("all=mno", JSON)); | |
279 | ||
280 | v3.search_paths.push(SearchPath::from_cli_opt("crate=def", JSON)); | |
281 | v3.search_paths.push(SearchPath::from_cli_opt("framework=jkl", JSON)); | |
282 | v3.search_paths.push(SearchPath::from_cli_opt("native=abc", JSON)); | |
283 | v3.search_paths.push(SearchPath::from_cli_opt("dependency=ghi", JSON)); | |
284 | v3.search_paths.push(SearchPath::from_cli_opt("all=mno", JSON)); | |
285 | ||
286 | v4.search_paths.push(SearchPath::from_cli_opt("all=mno", JSON)); | |
287 | v4.search_paths.push(SearchPath::from_cli_opt("native=abc", JSON)); | |
288 | v4.search_paths.push(SearchPath::from_cli_opt("crate=def", JSON)); | |
289 | v4.search_paths.push(SearchPath::from_cli_opt("dependency=ghi", JSON)); | |
290 | v4.search_paths.push(SearchPath::from_cli_opt("framework=jkl", JSON)); | |
dc9dc135 XL |
291 | |
292 | assert!(v1.dep_tracking_hash() == v2.dep_tracking_hash()); | |
293 | assert!(v1.dep_tracking_hash() == v3.dep_tracking_hash()); | |
294 | assert!(v1.dep_tracking_hash() == v4.dep_tracking_hash()); | |
295 | ||
296 | // Check clone | |
297 | assert_eq!(v1.dep_tracking_hash(), v1.clone().dep_tracking_hash()); | |
298 | assert_eq!(v2.dep_tracking_hash(), v2.clone().dep_tracking_hash()); | |
299 | assert_eq!(v3.dep_tracking_hash(), v3.clone().dep_tracking_hash()); | |
300 | assert_eq!(v4.dep_tracking_hash(), v4.clone().dep_tracking_hash()); | |
301 | } | |
302 | ||
303 | #[test] | |
304 | fn test_native_libs_tracking_hash_different_values() { | |
305 | let mut v1 = Options::default(); | |
306 | let mut v2 = Options::default(); | |
307 | let mut v3 = Options::default(); | |
308 | let mut v4 = Options::default(); | |
309 | ||
310 | // Reference | |
311 | v1.libs = vec![ | |
f9f354fc XL |
312 | (String::from("a"), None, NativeLibKind::StaticBundle), |
313 | (String::from("b"), None, NativeLibKind::Framework), | |
314 | (String::from("c"), None, NativeLibKind::Unspecified), | |
dc9dc135 XL |
315 | ]; |
316 | ||
317 | // Change label | |
318 | v2.libs = vec![ | |
f9f354fc XL |
319 | (String::from("a"), None, NativeLibKind::StaticBundle), |
320 | (String::from("X"), None, NativeLibKind::Framework), | |
321 | (String::from("c"), None, NativeLibKind::Unspecified), | |
dc9dc135 XL |
322 | ]; |
323 | ||
324 | // Change kind | |
325 | v3.libs = vec![ | |
f9f354fc XL |
326 | (String::from("a"), None, NativeLibKind::StaticBundle), |
327 | (String::from("b"), None, NativeLibKind::StaticBundle), | |
328 | (String::from("c"), None, NativeLibKind::Unspecified), | |
dc9dc135 XL |
329 | ]; |
330 | ||
331 | // Change new-name | |
332 | v4.libs = vec![ | |
f9f354fc XL |
333 | (String::from("a"), None, NativeLibKind::StaticBundle), |
334 | (String::from("b"), Some(String::from("X")), NativeLibKind::Framework), | |
335 | (String::from("c"), None, NativeLibKind::Unspecified), | |
dc9dc135 XL |
336 | ]; |
337 | ||
338 | assert!(v1.dep_tracking_hash() != v2.dep_tracking_hash()); | |
339 | assert!(v1.dep_tracking_hash() != v3.dep_tracking_hash()); | |
340 | assert!(v1.dep_tracking_hash() != v4.dep_tracking_hash()); | |
341 | ||
342 | // Check clone | |
343 | assert_eq!(v1.dep_tracking_hash(), v1.clone().dep_tracking_hash()); | |
344 | assert_eq!(v2.dep_tracking_hash(), v2.clone().dep_tracking_hash()); | |
345 | assert_eq!(v3.dep_tracking_hash(), v3.clone().dep_tracking_hash()); | |
346 | assert_eq!(v4.dep_tracking_hash(), v4.clone().dep_tracking_hash()); | |
347 | } | |
348 | ||
349 | #[test] | |
350 | fn test_native_libs_tracking_hash_different_order() { | |
351 | let mut v1 = Options::default(); | |
352 | let mut v2 = Options::default(); | |
353 | let mut v3 = Options::default(); | |
354 | ||
355 | // Reference | |
356 | v1.libs = vec![ | |
f9f354fc XL |
357 | (String::from("a"), None, NativeLibKind::StaticBundle), |
358 | (String::from("b"), None, NativeLibKind::Framework), | |
359 | (String::from("c"), None, NativeLibKind::Unspecified), | |
dc9dc135 XL |
360 | ]; |
361 | ||
362 | v2.libs = vec![ | |
f9f354fc XL |
363 | (String::from("b"), None, NativeLibKind::Framework), |
364 | (String::from("a"), None, NativeLibKind::StaticBundle), | |
365 | (String::from("c"), None, NativeLibKind::Unspecified), | |
dc9dc135 XL |
366 | ]; |
367 | ||
368 | v3.libs = vec![ | |
f9f354fc XL |
369 | (String::from("c"), None, NativeLibKind::Unspecified), |
370 | (String::from("a"), None, NativeLibKind::StaticBundle), | |
371 | (String::from("b"), None, NativeLibKind::Framework), | |
dc9dc135 XL |
372 | ]; |
373 | ||
374 | assert!(v1.dep_tracking_hash() == v2.dep_tracking_hash()); | |
375 | assert!(v1.dep_tracking_hash() == v3.dep_tracking_hash()); | |
376 | assert!(v2.dep_tracking_hash() == v3.dep_tracking_hash()); | |
377 | ||
378 | // Check clone | |
379 | assert_eq!(v1.dep_tracking_hash(), v1.clone().dep_tracking_hash()); | |
380 | assert_eq!(v2.dep_tracking_hash(), v2.clone().dep_tracking_hash()); | |
381 | assert_eq!(v3.dep_tracking_hash(), v3.clone().dep_tracking_hash()); | |
382 | } | |
383 | ||
384 | #[test] | |
385 | fn test_codegen_options_tracking_hash() { | |
386 | let reference = Options::default(); | |
387 | let mut opts = Options::default(); | |
388 | ||
f9f354fc XL |
389 | macro_rules! untracked { |
390 | ($name: ident, $non_default_value: expr) => { | |
391 | opts.cg.$name = $non_default_value; | |
392 | assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash()); | |
393 | }; | |
394 | } | |
dc9dc135 | 395 | |
f9f354fc XL |
396 | // Make sure that changing an [UNTRACKED] option leaves the hash unchanged. |
397 | // This list is in alphabetical order. | |
398 | untracked!(ar, String::from("abc")); | |
399 | untracked!(codegen_units, Some(42)); | |
400 | untracked!(default_linker_libraries, true); | |
401 | untracked!(extra_filename, String::from("extra-filename")); | |
402 | untracked!(incremental, Some(String::from("abc"))); | |
403 | // `link_arg` is omitted because it just forwards to `link_args`. | |
404 | untracked!(link_args, vec![String::from("abc"), String::from("def")]); | |
3dfed10e | 405 | untracked!(link_dead_code, Some(true)); |
1b1a35ee | 406 | untracked!(link_self_contained, Some(true)); |
f9f354fc XL |
407 | untracked!(linker, Some(PathBuf::from("linker"))); |
408 | untracked!(linker_flavor, Some(LinkerFlavor::Gcc)); | |
409 | untracked!(no_stack_check, true); | |
410 | untracked!(remark, Passes::Some(vec![String::from("pass1"), String::from("pass2")])); | |
411 | untracked!(rpath, true); | |
412 | untracked!(save_temps, true); | |
413 | ||
414 | macro_rules! tracked { | |
415 | ($name: ident, $non_default_value: expr) => { | |
416 | opts = reference.clone(); | |
417 | opts.cg.$name = $non_default_value; | |
418 | assert_ne!(reference.dep_tracking_hash(), opts.dep_tracking_hash()); | |
419 | }; | |
420 | } | |
dc9dc135 | 421 | |
f9f354fc XL |
422 | // Make sure that changing a [TRACKED] option changes the hash. |
423 | // This list is in alphabetical order. | |
424 | tracked!(code_model, Some(CodeModel::Large)); | |
3dfed10e | 425 | tracked!(control_flow_guard, CFGuard::Checks); |
f9f354fc XL |
426 | tracked!(debug_assertions, Some(true)); |
427 | tracked!(debuginfo, 0xdeadbeef); | |
428 | tracked!(embed_bitcode, false); | |
429 | tracked!(force_frame_pointers, Some(false)); | |
430 | tracked!(force_unwind_tables, Some(true)); | |
431 | tracked!(inline_threshold, Some(0xf007ba11)); | |
432 | tracked!(linker_plugin_lto, LinkerPluginLto::LinkerPluginAuto); | |
433 | tracked!(llvm_args, vec![String::from("1"), String::from("2")]); | |
434 | tracked!(lto, LtoCli::Fat); | |
435 | tracked!(metadata, vec![String::from("A"), String::from("B")]); | |
436 | tracked!(no_prepopulate_passes, true); | |
437 | tracked!(no_redzone, Some(true)); | |
438 | tracked!(no_vectorize_loops, true); | |
439 | tracked!(no_vectorize_slp, true); | |
440 | tracked!(opt_level, "3".to_string()); | |
441 | tracked!(overflow_checks, Some(true)); | |
442 | tracked!(panic, Some(PanicStrategy::Abort)); | |
443 | tracked!(passes, vec![String::from("1"), String::from("2")]); | |
444 | tracked!(prefer_dynamic, true); | |
445 | tracked!(profile_generate, SwitchWithOptPath::Enabled(None)); | |
446 | tracked!(profile_use, Some(PathBuf::from("abc"))); | |
447 | tracked!(relocation_model, Some(RelocModel::Pic)); | |
448 | tracked!(soft_float, true); | |
449 | tracked!(target_cpu, Some(String::from("abc"))); | |
450 | tracked!(target_feature, String::from("all the features, all of them")); | |
dc9dc135 XL |
451 | } |
452 | ||
453 | #[test] | |
454 | fn test_debugging_options_tracking_hash() { | |
455 | let reference = Options::default(); | |
456 | let mut opts = Options::default(); | |
457 | ||
f9f354fc XL |
458 | macro_rules! untracked { |
459 | ($name: ident, $non_default_value: expr) => { | |
460 | opts.debugging_opts.$name = $non_default_value; | |
461 | assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash()); | |
462 | }; | |
463 | } | |
464 | ||
465 | // Make sure that changing an [UNTRACKED] option leaves the hash unchanged. | |
466 | // This list is in alphabetical order. | |
467 | untracked!(ast_json, true); | |
468 | untracked!(ast_json_noexpand, true); | |
469 | untracked!(borrowck, String::from("other")); | |
470 | untracked!(borrowck_stats, true); | |
f9f354fc XL |
471 | untracked!(deduplicate_diagnostics, true); |
472 | untracked!(dep_tasks, true); | |
473 | untracked!(dont_buffer_diagnostics, true); | |
474 | untracked!(dump_dep_graph, true); | |
475 | untracked!(dump_mir, Some(String::from("abc"))); | |
476 | untracked!(dump_mir_dataflow, true); | |
477 | untracked!(dump_mir_dir, String::from("abc")); | |
478 | untracked!(dump_mir_exclude_pass_number, true); | |
479 | untracked!(dump_mir_graphviz, true); | |
29967ef6 | 480 | untracked!(emit_future_incompat_report, true); |
f9f354fc XL |
481 | untracked!(emit_stack_sizes, true); |
482 | untracked!(hir_stats, true); | |
483 | untracked!(identify_regions, true); | |
484 | untracked!(incremental_ignore_spans, true); | |
485 | untracked!(incremental_info, true); | |
486 | untracked!(incremental_verify_ich, true); | |
487 | untracked!(input_stats, true); | |
488 | untracked!(keep_hygiene_data, true); | |
489 | untracked!(link_native_libraries, false); | |
490 | untracked!(llvm_time_trace, true); | |
491 | untracked!(ls, true); | |
492 | untracked!(macro_backtrace, true); | |
493 | untracked!(meta_stats, true); | |
494 | untracked!(nll_facts, true); | |
495 | untracked!(no_analysis, true); | |
496 | untracked!(no_interleave_lints, true); | |
497 | untracked!(no_leak_check, true); | |
498 | untracked!(no_parallel_llvm, true); | |
499 | untracked!(parse_only, true); | |
500 | untracked!(perf_stats, true); | |
501 | untracked!(polonius, true); | |
502 | // `pre_link_arg` is omitted because it just forwards to `pre_link_args`. | |
503 | untracked!(pre_link_args, vec![String::from("abc"), String::from("def")]); | |
504 | untracked!(print_link_args, true); | |
505 | untracked!(print_llvm_passes, true); | |
506 | untracked!(print_mono_items, Some(String::from("abc"))); | |
f9f354fc | 507 | untracked!(print_type_sizes, true); |
1b1a35ee | 508 | untracked!(proc_macro_backtrace, true); |
f9f354fc XL |
509 | untracked!(query_dep_graph, true); |
510 | untracked!(query_stats, true); | |
511 | untracked!(save_analysis, true); | |
512 | untracked!(self_profile, SwitchWithOptPath::Enabled(None)); | |
513 | untracked!(self_profile_events, Some(vec![String::new()])); | |
f035d41b | 514 | untracked!(span_debug, true); |
f9f354fc XL |
515 | untracked!(span_free_formats, true); |
516 | untracked!(strip, Strip::None); | |
517 | untracked!(terminal_width, Some(80)); | |
518 | untracked!(threads, 99); | |
519 | untracked!(time, true); | |
520 | untracked!(time_llvm_passes, true); | |
521 | untracked!(time_passes, true); | |
522 | untracked!(trace_macros, true); | |
1b1a35ee | 523 | untracked!(trim_diagnostic_paths, false); |
f9f354fc XL |
524 | untracked!(ui_testing, true); |
525 | untracked!(unpretty, Some("expanded".to_string())); | |
526 | untracked!(unstable_options, true); | |
527 | untracked!(validate_mir, true); | |
528 | untracked!(verbose, true); | |
529 | ||
530 | macro_rules! tracked { | |
531 | ($name: ident, $non_default_value: expr) => { | |
532 | opts = reference.clone(); | |
533 | opts.debugging_opts.$name = $non_default_value; | |
534 | assert_ne!(reference.dep_tracking_hash(), opts.dep_tracking_hash()); | |
535 | }; | |
536 | } | |
537 | ||
538 | // Make sure that changing a [TRACKED] option changes the hash. | |
539 | // This list is in alphabetical order. | |
540 | tracked!(allow_features, Some(vec![String::from("lang_items")])); | |
541 | tracked!(always_encode_mir, true); | |
542 | tracked!(asm_comments, true); | |
543 | tracked!(binary_dep_depinfo, true); | |
544 | tracked!(chalk, true); | |
545 | tracked!(codegen_backend, Some("abc".to_string())); | |
546 | tracked!(crate_attr, vec!["abc".to_string()]); | |
547 | tracked!(debug_macros, true); | |
548 | tracked!(dep_info_omit_d_target, true); | |
549 | tracked!(dual_proc_macros, true); | |
550 | tracked!(fewer_names, true); | |
551 | tracked!(force_overflow_checks, Some(true)); | |
552 | tracked!(force_unstable_if_unmarked, true); | |
553 | tracked!(fuel, Some(("abc".to_string(), 99))); | |
29967ef6 | 554 | tracked!(function_sections, Some(false)); |
f9f354fc XL |
555 | tracked!(human_readable_cgu_names, true); |
556 | tracked!(inline_in_all_cgus, Some(true)); | |
29967ef6 XL |
557 | tracked!(inline_mir_threshold, 123); |
558 | tracked!(inline_mir_hint_threshold, 123); | |
f9f354fc | 559 | tracked!(insert_sideeffect, true); |
f035d41b | 560 | tracked!(instrument_coverage, true); |
f9f354fc XL |
561 | tracked!(instrument_mcount, true); |
562 | tracked!(link_only, true); | |
563 | tracked!(merge_functions, Some(MergeFunctions::Disabled)); | |
564 | tracked!(mir_emit_retag, true); | |
565 | tracked!(mir_opt_level, 3); | |
566 | tracked!(mutable_noalias, true); | |
567 | tracked!(new_llvm_pass_manager, true); | |
568 | tracked!(no_codegen, true); | |
569 | tracked!(no_generate_arange_section, true); | |
570 | tracked!(no_link, true); | |
571 | tracked!(no_profiler_runtime, true); | |
572 | tracked!(osx_rpath_install_name, true); | |
573 | tracked!(panic_abort_tests, true); | |
574 | tracked!(plt, Some(true)); | |
1b1a35ee | 575 | tracked!(precise_enum_drop_elaboration, false); |
f9f354fc XL |
576 | tracked!(print_fuel, Some("abc".to_string())); |
577 | tracked!(profile, true); | |
578 | tracked!(profile_emit, Some(PathBuf::from("abc"))); | |
29967ef6 | 579 | tracked!(relax_elf_relocations, Some(true)); |
f9f354fc XL |
580 | tracked!(relro_level, Some(RelroLevel::Full)); |
581 | tracked!(report_delayed_bugs, true); | |
582 | tracked!(run_dsymutil, false); | |
f035d41b | 583 | tracked!(sanitizer, SanitizerSet::ADDRESS); |
f9f354fc | 584 | tracked!(sanitizer_memory_track_origins, 2); |
f035d41b | 585 | tracked!(sanitizer_recover, SanitizerSet::ADDRESS); |
f9f354fc XL |
586 | tracked!(saturating_float_casts, Some(true)); |
587 | tracked!(share_generics, Some(true)); | |
588 | tracked!(show_span, Some(String::from("abc"))); | |
589 | tracked!(src_hash_algorithm, Some(SourceFileHashAlgorithm::Sha1)); | |
590 | tracked!(symbol_mangling_version, SymbolManglingVersion::V0); | |
591 | tracked!(teach, true); | |
592 | tracked!(thinlto, Some(true)); | |
29967ef6 | 593 | tracked!(tune_cpu, Some(String::from("abc"))); |
f9f354fc XL |
594 | tracked!(tls_model, Some(TlsModel::GeneralDynamic)); |
595 | tracked!(treat_err_as_bug, Some(1)); | |
596 | tracked!(unleash_the_miri_inside_of_you, true); | |
597 | tracked!(use_ctors_section, Some(true)); | |
598 | tracked!(verify_llvm_ir, true); | |
dc9dc135 XL |
599 | } |
600 | ||
601 | #[test] | |
602 | fn test_edition_parsing() { | |
603 | // test default edition | |
604 | let options = Options::default(); | |
605 | assert!(options.edition == DEFAULT_EDITION); | |
606 | ||
dfeec247 | 607 | let matches = optgroups().parse(&["--edition=2018".to_string()]).unwrap(); |
60c5eb7d | 608 | let (sessopts, _) = build_session_options_and_crate_config(matches); |
dc9dc135 XL |
609 | assert!(sessopts.edition == Edition::Edition2018) |
610 | } |