Skip to content

Commit

Permalink
Added verification for doc comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sayantn authored and Amanieu committed Jul 7, 2024
1 parent d17687d commit bd9267e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
23 changes: 23 additions & 0 deletions crates/stdarch-verify/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ fn functions(input: TokenStream, dirs: &[&str]) -> TokenStream {
}
let has_test = tests.contains(&format!("test_{test_name_id}"));

let doc = find_doc(&f.attrs);

quote! {
Function {
name: stringify!(#name),
Expand All @@ -162,6 +164,7 @@ fn functions(input: TokenStream, dirs: &[&str]) -> TokenStream {
file: stringify!(#path),
required_const: &[#(#required_const),*],
has_test: #has_test,
doc: #doc
}
}
})
Expand Down Expand Up @@ -508,6 +511,26 @@ fn find_target_feature(attrs: &[syn::Attribute]) -> Option<syn::Lit> {
})
}

fn find_doc(attrs: &[syn::Attribute]) -> String {
attrs
.iter()
.filter_map(|a| {
if let syn::Meta::NameValue(ref l) = a.meta {
if l.path.is_ident("doc") {
if let syn::Expr::Lit(syn::ExprLit {
lit: syn::Lit::Str(ref s),
..
}) = l.value
{
return Some(s.value());
}
}
}
return None;
})
.collect()
}

fn find_required_const(name: &str, attrs: &[syn::Attribute]) -> Vec<usize> {
attrs
.iter()
Expand Down
1 change: 1 addition & 0 deletions crates/stdarch-verify/tests/arm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ struct Function {
file: &'static str,
required_const: &'static [usize],
has_test: bool,
doc: &'static str,
}

static F16: Type = Type::PrimFloat(16);
Expand Down
1 change: 1 addition & 0 deletions crates/stdarch-verify/tests/mips.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct Function {
file: &'static str,
required_const: &'static [usize],
has_test: bool,
doc: &'static str,
}

static F16: Type = Type::PrimFloat(16);
Expand Down
15 changes: 15 additions & 0 deletions crates/stdarch-verify/tests/x86-intel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct Function {
file: &'static str,
required_const: &'static [usize],
has_test: bool,
doc: &'static str,
}

static BF16: Type = Type::BFloat16;
Expand Down Expand Up @@ -659,6 +660,20 @@ fn matches(rust: &Function, intel: &Intrinsic) -> Result<(), String> {
rust.name
);
}
if !rust.doc.contains("Intel") {
bail!("No link to Intel");
}
let recognized_links = [
"https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html",
"https://software.intel.com/sites/landingpage/IntrinsicsGuide/",
];
if !recognized_links.iter().any(|link| rust.doc.contains(link)) {
bail!("Unrecognized Intel Link");
}
if !rust.doc.contains(&rust.name[1..]) {
// We can leave the leading underscore
bail!("Bad link to Intel");
}
Ok(())
}

Expand Down

0 comments on commit bd9267e

Please sign in to comment.