-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add test directive needs-target-has-atomic
#133095
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -171,9 +171,12 @@ pub(super) fn handle_needs( | |
}, | ||
]; | ||
|
||
let (name, comment) = match ln.split_once([':', ' ']) { | ||
Some((name, comment)) => (name, Some(comment)), | ||
None => (ln, None), | ||
// Because `needs-target-has-atomic` accepts comma separated arguments following a colon to | ||
// specify data sizes, we check whether comment starts with colon. | ||
let (name, comment, comment_starts_with_colon) = if let Some(index) = ln.find([':', ' ']) { | ||
(&ln[..index], Some(&ln[index + 1..]), ln.as_bytes()[index] == b':') | ||
} else { | ||
(ln, None, false) | ||
}; | ||
Comment on lines
+176
to
180
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: this also accepts a whitespace separator, please only accept There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This accepts a whitespace separator, but only when the directive isn't There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll double-check tmrw |
||
|
||
if !name.starts_with("needs-") { | ||
|
@@ -185,6 +188,11 @@ pub(super) fn handle_needs( | |
return IgnoreDecision::Continue; | ||
} | ||
|
||
// Check here because `needs-target-has-atomic` requires parsing comments. | ||
if name == "needs-target-has-atomic" { | ||
return handle_needs_target_has_atomic(comment_starts_with_colon, comment, config); | ||
} | ||
|
||
let mut found_valid = false; | ||
for need in needs { | ||
if need.name == name { | ||
|
@@ -210,6 +218,42 @@ pub(super) fn handle_needs( | |
} | ||
} | ||
|
||
fn handle_needs_target_has_atomic( | ||
comment_starts_with_colon: bool, | ||
comment: Option<&str>, | ||
config: &Config, | ||
) -> IgnoreDecision { | ||
// `needs-target-has-atomic` requires comma-separated data sizes following a collon. | ||
if !comment_starts_with_colon || comment.is_none() { | ||
return IgnoreDecision::Error { | ||
message: "`needs-target-has-atomic` requires data sizes for atomic operations".into(), | ||
}; | ||
} | ||
let comment = comment.unwrap(); | ||
|
||
// Parse the comment to specify data sizes. | ||
for size in comment.split(',').map(|size| size.trim()) { | ||
if !["ptr", "128", "64", "32", "16", "8"].contains(&size) { | ||
return IgnoreDecision::Error { | ||
message: "expected values for `needs-target-has-atomic` are: `128`, `16`, \\ | ||
`32`, `64`, `8`, and `ptr`" | ||
.into(), | ||
}; | ||
} | ||
if !config.has_atomic(size) { | ||
return IgnoreDecision::Ignore { | ||
reason: if size == "ptr" { | ||
"ignored on targets without ptr-size atomic operations".into() | ||
} else { | ||
format!("ignored on targets without {size}-bit atomic operations") | ||
}, | ||
}; | ||
} | ||
} | ||
|
||
IgnoreDecision::Continue | ||
} | ||
|
||
struct Need { | ||
name: &'static str, | ||
condition: bool, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Problem: we should keep
//@ needs-target-has-atomic
matching the#[cfg(target_has_atomic)]
semantics otherwise it adds needless confusion. In particular, this directive should support (cf. https://doc.rust-lang.org/reference/conditional-compilation.html#target_has_atomic):Possibly comma-separated so the test-writer can combine them, e.g.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we accept (none), i.e. below
//@ needs-target-has-atomic
like the cfg equivalent?
#[cfg(target_has_atomic)]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. Apparently
target_has_atomic = "8"
is not quitetarget_has_atomic
; the latter is a nightly-only unstable cfg. For the purposes of these tests, I think we are only interested in thetarget_has_atomic="value"
builtin cfgs. We can always slightly adjust this logic in a follow-up if needed.