Skip to content

Commit bd9267e

Browse files
sayantnAmanieu
authored andcommitted
Added verification for doc comments
1 parent d17687d commit bd9267e

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

crates/stdarch-verify/src/lib.rs

+23
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ fn functions(input: TokenStream, dirs: &[&str]) -> TokenStream {
152152
}
153153
let has_test = tests.contains(&format!("test_{test_name_id}"));
154154

155+
let doc = find_doc(&f.attrs);
156+
155157
quote! {
156158
Function {
157159
name: stringify!(#name),
@@ -162,6 +164,7 @@ fn functions(input: TokenStream, dirs: &[&str]) -> TokenStream {
162164
file: stringify!(#path),
163165
required_const: &[#(#required_const),*],
164166
has_test: #has_test,
167+
doc: #doc
165168
}
166169
}
167170
})
@@ -508,6 +511,26 @@ fn find_target_feature(attrs: &[syn::Attribute]) -> Option<syn::Lit> {
508511
})
509512
}
510513

514+
fn find_doc(attrs: &[syn::Attribute]) -> String {
515+
attrs
516+
.iter()
517+
.filter_map(|a| {
518+
if let syn::Meta::NameValue(ref l) = a.meta {
519+
if l.path.is_ident("doc") {
520+
if let syn::Expr::Lit(syn::ExprLit {
521+
lit: syn::Lit::Str(ref s),
522+
..
523+
}) = l.value
524+
{
525+
return Some(s.value());
526+
}
527+
}
528+
}
529+
return None;
530+
})
531+
.collect()
532+
}
533+
511534
fn find_required_const(name: &str, attrs: &[syn::Attribute]) -> Vec<usize> {
512535
attrs
513536
.iter()

crates/stdarch-verify/tests/arm.rs

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ struct Function {
1313
file: &'static str,
1414
required_const: &'static [usize],
1515
has_test: bool,
16+
doc: &'static str,
1617
}
1718

1819
static F16: Type = Type::PrimFloat(16);

crates/stdarch-verify/tests/mips.rs

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ struct Function {
1616
file: &'static str,
1717
required_const: &'static [usize],
1818
has_test: bool,
19+
doc: &'static str,
1920
}
2021

2122
static F16: Type = Type::PrimFloat(16);

crates/stdarch-verify/tests/x86-intel.rs

+15
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ struct Function {
2020
file: &'static str,
2121
required_const: &'static [usize],
2222
has_test: bool,
23+
doc: &'static str,
2324
}
2425

2526
static BF16: Type = Type::BFloat16;
@@ -659,6 +660,20 @@ fn matches(rust: &Function, intel: &Intrinsic) -> Result<(), String> {
659660
rust.name
660661
);
661662
}
663+
if !rust.doc.contains("Intel") {
664+
bail!("No link to Intel");
665+
}
666+
let recognized_links = [
667+
"https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html",
668+
"https://software.intel.com/sites/landingpage/IntrinsicsGuide/",
669+
];
670+
if !recognized_links.iter().any(|link| rust.doc.contains(link)) {
671+
bail!("Unrecognized Intel Link");
672+
}
673+
if !rust.doc.contains(&rust.name[1..]) {
674+
// We can leave the leading underscore
675+
bail!("Bad link to Intel");
676+
}
662677
Ok(())
663678
}
664679

0 commit comments

Comments
 (0)