Skip to content
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

Update dependencies #1475

Merged
merged 8 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/assert-instr-macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ test = false
[dependencies]
proc-macro2 = "1.0"
quote = "1.0"
syn = { version = "1.0", features = ["full"] }
syn = { version = "2.0", features = ["full"] }
4 changes: 2 additions & 2 deletions crates/assert-instr-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub fn assert_instr(
let maybe_allow_deprecated = if func
.attrs
.iter()
.any(|attr| attr.path.is_ident("deprecated"))
.any(|attr| attr.path().is_ident("deprecated"))
{
quote! { #[allow(deprecated)] }
} else {
Expand Down Expand Up @@ -117,7 +117,7 @@ pub fn assert_instr(
.attrs
.iter()
.filter(|attr| {
attr.path
attr.path()
.segments
.first()
.expect("attr.path.segments.first() failed")
Expand Down
6 changes: 3 additions & 3 deletions crates/intrinsic-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ lazy_static = "1.4.0"
serde = { version = "1", features = ["derive"] }
serde_json = "1.0"
csv = "1.1"
clap = "2.33.3"
clap = { version = "4.4", features = ["derive"] }
regex = "1.4.2"
log = "0.4.11"
pretty_env_logger = "0.4.0"
pretty_env_logger = "0.5.0"
rayon = "1.5.0"
diff = "0.1.12"
itertools = "0.10.1"
itertools = "0.11.0"
4 changes: 3 additions & 1 deletion crates/intrinsic-test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ each produces the same result from random inputs.
# Usage
```
USAGE:
intrinsic-test [OPTIONS] <INPUT>
intrinsic-test [FLAGS] [OPTIONS] <INPUT>

FLAGS:
--a32 Run tests for A32 instrinsics instead of A64
-h, --help Prints help information
-V, --version Prints version information

OPTIONS:
--cppcompiler <CPPCOMPILER> The C++ compiler to use for compiling the c++ code [default: clang++]
--runner <RUNNER> Run the C programs under emulation with this command
--skip <SKIP> Filename for a list of intrinsics to skip (one per line)
--toolchain <TOOLCHAIN> The rust toolchain to use for building the rust code

ARGS:
Expand Down
3 changes: 2 additions & 1 deletion crates/intrinsic-test/src/json_parser.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::collections::HashMap;
use std::path::Path;

use serde::Deserialize;

Expand Down Expand Up @@ -41,7 +42,7 @@ struct JsonIntrinsic {
architectures: Vec<String>,
}

pub fn get_neon_intrinsics(filename: &str) -> Result<Vec<Intrinsic>, Box<dyn std::error::Error>> {
pub fn get_neon_intrinsics(filename: &Path) -> Result<Vec<Intrinsic>, Box<dyn std::error::Error>> {
let file = std::fs::File::open(filename)?;
let reader = std::io::BufReader::new(file);
let json: Vec<JsonIntrinsic> = serde_json::from_reader(reader).expect("Couldn't parse JSON");
Expand Down
93 changes: 41 additions & 52 deletions crates/intrinsic-test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ extern crate log;

use std::fs::File;
use std::io::Write;
use std::path::PathBuf;
use std::process::Command;

use clap::{App, Arg};
use intrinsic::Intrinsic;
use itertools::Itertools;
use rayon::prelude::*;
Expand Down Expand Up @@ -320,58 +320,47 @@ path = "{intrinsic}/main.rs""#,
}
}

/// Intrinsic test tool
#[derive(clap::Parser)]
#[command(
name = "Intrinsic test tool",
about = "Generates Rust and C programs for intrinsics and compares the output"
)]
struct Cli {
/// The input file containing the intrinsics
input: PathBuf,

/// The rust toolchain to use for building the rust code
#[arg(long)]
toolchain: Option<String>,

/// The C++ compiler to use for compiling the c++ code
#[arg(long, default_value_t = String::from("clang++"))]
cppcompiler: String,

/// Run the C programs under emulation with this command
#[arg(long)]
runner: Option<String>,

/// Filename for a list of intrinsics to skip (one per line)
#[arg(long)]
skip: Option<PathBuf>,

/// Run tests for A32 instrinsics instead of A64
#[arg(long)]
a32: bool,
}

fn main() {
pretty_env_logger::init();

let matches = App::new("Intrinsic test tool")
.about("Generates Rust and C programs for intrinsics and compares the output")
.arg(
Arg::with_name("INPUT")
.help("The input file containing the intrinsics")
.required(true)
.index(1),
)
.arg(
Arg::with_name("TOOLCHAIN")
.takes_value(true)
.long("toolchain")
.help("The rust toolchain to use for building the rust code"),
)
.arg(
Arg::with_name("CPPCOMPILER")
.takes_value(true)
.default_value("clang++")
.long("cppcompiler")
.help("The C++ compiler to use for compiling the c++ code"),
)
.arg(
Arg::with_name("RUNNER")
.takes_value(true)
.long("runner")
.help("Run the C programs under emulation with this command"),
)
.arg(
Arg::with_name("SKIP")
.takes_value(true)
.long("skip")
.help("Filename for a list of intrinsics to skip (one per line)"),
)
.arg(
Arg::with_name("A32")
.takes_value(false)
.long("a32")
.help("Run tests for A32 instrinsics instead of A64"),
)
.get_matches();

let filename = matches.value_of("INPUT").unwrap();
let toolchain = matches
.value_of("TOOLCHAIN")
.map_or("".into(), |t| format!("+{t}"));
let args: Cli = clap::Parser::parse();

let cpp_compiler = matches.value_of("CPPCOMPILER").unwrap();
let c_runner = matches.value_of("RUNNER").unwrap_or("");
let skip = if let Some(filename) = matches.value_of("SKIP") {
let filename = args.input;
let toolchain = args.toolchain.map_or_else(String::new, |t| format!("+{t}"));
let cpp_compiler = args.cppcompiler;
let c_runner = args.runner.unwrap_or_else(String::new);
let skip = if let Some(filename) = args.skip {
let data = std::fs::read_to_string(&filename).expect("Failed to open file");
data.lines()
.map(str::trim)
Expand All @@ -381,8 +370,8 @@ fn main() {
} else {
Default::default()
};
let a32 = matches.is_present("A32");
let mut intrinsics = get_neon_intrinsics(filename).expect("Error parsing input file");
let a32 = args.a32;
let mut intrinsics = get_neon_intrinsics(&filename).expect("Error parsing input file");

intrinsics.sort_by(|a, b| a.name.cmp(&b.name));

Expand All @@ -409,7 +398,7 @@ fn main() {

let notices = build_notices("// ");

if !build_c(&notices, &intrinsics, cpp_compiler, a32) {
if !build_c(&notices, &intrinsics, &cpp_compiler, a32) {
std::process::exit(2);
}

Expand Down
2 changes: 1 addition & 1 deletion crates/stdarch-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ cc = "1.0"
# time, and we want to make updates to this explicit rather than automatically
# picking up updates which might break CI with new instruction names.
[target.'cfg(target_arch = "wasm32")'.dependencies]
wasmprinter = "=0.2.53"
wasmprinter = "=0.2.67"

[features]
default = []
4 changes: 2 additions & 2 deletions crates/stdarch-verify/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ edition = "2021"
[dependencies]
proc-macro2 = "1.0"
quote = "1.0"
syn = { version = "1.0", features = ["full"] }
syn = { version = "2.0", features = ["full"] }

[lib]
proc-macro = true
test = false

[dev-dependencies]
serde = { version = "1.0", features = ['derive'] }
serde-xml-rs = "0.3"
serde-xml-rs = "0.6"
serde_json = "1.0.96"
82 changes: 53 additions & 29 deletions crates/stdarch-verify/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ extern crate syn;
use proc_macro::TokenStream;
use std::{fs::File, io::Read, path::Path};
use syn::ext::IdentExt;
use syn::parse::Parser as _;

#[proc_macro]
pub fn x86_functions(input: TokenStream) -> TokenStream {
Expand Down Expand Up @@ -416,23 +417,29 @@ fn walk(root: &Path, files: &mut Vec<(syn::File, String)>) {

fn find_instrs(attrs: &[syn::Attribute]) -> Vec<String> {
struct AssertInstr {
instr: String,
instr: Option<String>,
}

// A small custom parser to parse out the instruction in `assert_instr`.
//
// TODO: should probably just reuse `Invoc` from the `assert-instr-macro`
// crate.
impl syn::parse::Parse for AssertInstr {
fn parse(content: syn::parse::ParseStream<'_>) -> syn::Result<Self> {
let input;
parenthesized!(input in content);
let _ = input.parse::<syn::Meta>()?;
let _ = input.parse::<Token![,]>()?;
let ident = input.parse::<syn::Ident>()?;
if ident != "assert_instr" {
return Err(input.error("expected `assert_instr`"));
fn parse(input: syn::parse::ParseStream<'_>) -> syn::Result<Self> {
let _ = input.parse::<syn::Meta>().unwrap();
let _ = input.parse::<Token![,]>().unwrap();

match input.parse::<syn::Ident>() {
Ok(ident) if ident == "assert_instr" => {}
_ => {
while !input.is_empty() {
// consume everything
drop(input.parse::<proc_macro2::TokenStream>());
}
return Ok(Self { instr: None });
}
}

let instrs;
parenthesized!(instrs in input);

Expand All @@ -452,48 +459,68 @@ fn find_instrs(attrs: &[syn::Attribute]) -> Vec<String> {
return Err(input.error("failed to parse instruction"));
}
}
Ok(Self { instr })
Ok(Self { instr: Some(instr) })
}
}

attrs
.iter()
.filter(|a| a.path.is_ident("cfg_attr"))
.filter_map(|a| {
syn::parse2::<AssertInstr>(a.tokens.clone())
.ok()
.map(|a| a.instr)
if let syn::Meta::List(ref l) = a.meta {
if l.path.is_ident("cfg_attr") {
Some(l)
} else {
None
}
} else {
None
}
})
.filter_map(|l| syn::parse2::<AssertInstr>(l.tokens.clone()).unwrap().instr)
.collect()
}

fn find_target_feature(attrs: &[syn::Attribute]) -> Option<syn::Lit> {
attrs
.iter()
.flat_map(|a| {
if let Ok(syn::Meta::List(i)) = a.parse_meta() {
if i.path.is_ident("target_feature") {
return i.nested;
if let syn::Meta::List(ref l) = a.meta {
if l.path.is_ident("target_feature") {
if let Ok(l) =
syn::punctuated::Punctuated::<syn::Meta, Token![,]>::parse_terminated
.parse2(l.tokens.clone())
{
return l;
}
}
}
syn::punctuated::Punctuated::new()
})
.filter_map(|nested| match nested {
syn::NestedMeta::Meta(m) => Some(m),
syn::NestedMeta::Lit(_) => None,
})
.find_map(|m| match m {
syn::Meta::NameValue(ref i) if i.path.is_ident("enable") => Some(i.clone().lit),
syn::Meta::NameValue(i) if i.path.is_ident("enable") => {
if let syn::Expr::Lit(lit) = i.value {
Some(lit.lit)
} else {
None
}
}
_ => None,
})
}

fn find_required_const(name: &str, attrs: &[syn::Attribute]) -> Vec<usize> {
attrs
.iter()
.flat_map(|a| {
if a.path.segments[0].ident == name {
syn::parse::<RustcArgsRequiredConst>(a.tokens.clone().into())
.filter_map(|a| {
if let syn::Meta::List(ref l) = a.meta {
Some(l)
} else {
None
}
})
.flat_map(|l| {
if l.path.segments[0].ident == name {
syn::parse2::<RustcArgsRequiredConst>(l.tokens.clone())
.unwrap()
.args
} else {
Expand All @@ -509,10 +536,7 @@ struct RustcArgsRequiredConst {

impl syn::parse::Parse for RustcArgsRequiredConst {
fn parse(input: syn::parse::ParseStream<'_>) -> syn::Result<Self> {
let content;
parenthesized!(content in input);
let list =
syn::punctuated::Punctuated::<syn::LitInt, Token![,]>::parse_terminated(&content)?;
let list = syn::punctuated::Punctuated::<syn::LitInt, Token![,]>::parse_terminated(&input)?;
Ok(Self {
args: list
.into_iter()
Expand Down
4 changes: 2 additions & 2 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ default-run = "hex"
[dependencies]
core_arch = { path = "../crates/core_arch" }
std_detect = { path = "../crates/std_detect" }
quickcheck = "0.9"
rand = "0.7"
quickcheck = "1.0"
rand = "0.8"

[[bin]]
name = "hex"
Expand Down