Skip to content

Commit

Permalink
rust: fix some clap deprecation warnings in move
Browse files Browse the repository at this point in the history
  • Loading branch information
bmwill committed Aug 29, 2023
1 parent 87b4af2 commit 41a8eff
Show file tree
Hide file tree
Showing 19 changed files with 239 additions and 272 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub enum ParsedValue<Extra: ParsableValue = ()> {
Custom(Extra),
}

pub trait ParsableValue: Sized + Send {
pub trait ParsableValue: Sized + Send + Sync + Clone + 'static {
type ConcreteValue: Send;
fn parse_value<'a, I: Iterator<Item = (ValueToken, &'a str)>>(
parser: &mut Parser<'a, ValueToken, I>,
Expand Down
4 changes: 2 additions & 2 deletions external-crates/move/move-compiler/src/bin/move-build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct Options {
name = "PATH_TO_SOURCE_FILE",
takes_value(true),
multiple_values(true),
multiple_occurrences(true)
action = clap::ArgAction::Append,
)]
pub source_files: Vec<String>,

Expand Down Expand Up @@ -58,7 +58,7 @@ pub struct Options {
name = "NAMED_ADDRESSES",
short = 'a',
long = "addresses",
parse(try_from_str = shared::parse_named_address)
value_parser = shared::parse_named_address,
)]
pub named_addresses: Vec<(String, NumericalAddress)>,

Expand Down
4 changes: 2 additions & 2 deletions external-crates/move/move-compiler/src/bin/move-check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct Options {
name = "PATH_TO_SOURCE_FILE",
takes_value(true),
multiple_values(true),
multiple_occurrences(true)
action = clap::ArgAction::Append,
)]
pub source_files: Vec<String>,

Expand All @@ -50,7 +50,7 @@ pub struct Options {
name = "NAMED_ADDRESSES",
short = 'a',
long = "addresses",
parse(try_from_str = shared::parse_named_address)
value_parser = shared::parse_named_address,
)]
pub named_addresses: Vec<(String, NumericalAddress)>,

Expand Down
1 change: 0 additions & 1 deletion external-crates/move/move-ir-compiler/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ struct Args {
#[clap(long = "no-verify")]
pub no_verify: bool,
/// Path to the Move IR source to compile
#[clap(parse(from_os_str))]
pub source_path: PathBuf,
/// Instead of compiling the source, emit a dependency list of the compiled source
#[clap(short = 'l', long = "list-dependencies")]
Expand Down
14 changes: 7 additions & 7 deletions external-crates/move/move-prover/interpreter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,35 +43,35 @@ use crate::concrete::{
#[derive(Parser)]
pub struct InterpreterOptions {
/// The function to be executed, specified in the format of `addr::module_name::function_name`
#[clap(long = "entry", parse(try_from_str = parse_entrypoint))]
#[clap(long = "entry", value_parser = parse_entrypoint)]
pub entrypoint: (ModuleId, Identifier),

/// Possibly-empty list of signers for the execution
#[clap(
long = "signers",
parse(try_from_str = AccountAddress::from_hex_literal),
value_parser = AccountAddress::from_hex_literal,
takes_value(true),
multiple_values(true),
multiple_occurrences(true)
action = clap::ArgAction::Append,
)]
pub signers: Vec<AccountAddress>,
/// Possibly-empty list of arguments passed to the transaction
#[clap(
long = "args",
parse(try_from_str = parse_transaction_argument),
value_parser = parse_transaction_argument,
takes_value(true),
multiple_values(true),
multiple_occurrences(true)
action = clap::ArgAction::Append,
)]
pub args: Vec<TransactionArgument>,
/// Possibly-empty list of type arguments passed to the transaction (e.g., `T` in
/// `main<T>()`). Must match the type arguments kinds expected by `script_file`.
#[clap(
long = "ty-args",
parse(try_from_str = parse_type_tag),
value_parser = parse_type_tag,
takes_value(true),
multiple_values(true),
multiple_occurrences(true)
action = clap::ArgAction::Append,
)]
pub ty_args: Vec<TypeTag>,

Expand Down
12 changes: 6 additions & 6 deletions external-crates/move/move-prover/lab/src/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub fn benchmark(args: &[String]) {
.short('c')
.long("config")
.takes_value(true)
.multiple_occurrences(true)
.action(clap::ArgAction::Append)
.number_of_values(1)
.value_name("CONFIG_PATH")
.help(
Expand All @@ -66,7 +66,7 @@ pub fn benchmark(args: &[String]) {
Arg::new("dependencies")
.long("dependency")
.short('d')
.multiple_occurrences(true)
.action(clap::ArgAction::Append)
.number_of_values(1)
.takes_value(true)
.value_name("PATH_TO_DEPENDENCY")
Expand All @@ -77,26 +77,26 @@ pub fn benchmark(args: &[String]) {
)
.arg(
Arg::new("sources")
.multiple_occurrences(true)
.action(clap::ArgAction::Append)
.value_name("PATH_TO_SOURCE_FILE")
.min_values(1)
.help("the source files to verify"),
);
let matches = cmd_line_parser.get_matches_from(args);
let get_vec = |s: &str| -> Vec<String> {
match matches.values_of(s) {
match matches.get_many::<String>(s) {
Some(vs) => vs.map(|v| v.to_string()).collect(),
_ => vec![],
}
};
let sources = get_vec("sources");
let deps = get_vec("dependencies");
let configs: Vec<Option<String>> = if matches.is_present("config") {
let configs: Vec<Option<String>> = if matches.contains_id("config") {
get_vec("config").into_iter().map(Some).collect_vec()
} else {
vec![None]
};
let per_function = matches.is_present("function");
let per_function = matches.get_flag("function");

for config_spec in configs {
let (config, out) = if let Some(config_file) = &config_spec {
Expand Down
92 changes: 29 additions & 63 deletions external-crates/move/move-prover/lab/src/plot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
benchmark::{Benchmark, BenchmarkData},
};
use anyhow::Context;
use clap::{Arg, Command};
use clap::Parser;
use itertools::Itertools;
use plotters::{
coord::types::RangedCoordu32,
Expand All @@ -24,79 +24,45 @@ use std::collections::BTreeMap;
// =====================================================================================
// Command line interface

#[derive(Parser)]
#[clap(
name = "plot",
version = "0.1.0",
about = "Benchmark plotter for the Move Prover",
author
)]
struct Plot {
/// file where output will be written too
#[clap(long, value_name = "FILE", default_value = "plot.svg")]
out: String,
/// whether to sort the benchmark data based on the first data file
#[clap(long)]
sort: bool,
/// plot on ly the top N entries
#[clap(long, value_name = "NUMBER")]
top: Option<usize>,
/// the benchmark data files to plot
#[clap(value_name = "PATH_TO_BENCHMARK_DATA")]
data_files: Vec<String>,
}

pub fn plot_svg(args: &[String]) -> anyhow::Result<()> {
let is_number = |s: &str| {
s.parse::<usize>()
.map(|_| ())
.map_err(|_| "expected number".to_string())
};
let cmd_line_parser = Command::new("plot")
.version("0.1.0")
.about("Benchmark plotter for the Move Prover")
.author("The Diem Core Contributors")
.arg(
Arg::new("out")
.long("out")
.takes_value(true)
.value_name("FILE")
.help("file where output will be written too"),
)
.arg(
Arg::new("sort")
.long("sort")
.help("whether to sort the benchmark data based on the first data file"),
)
.arg(
Arg::new("top")
.long("top")
.takes_value(true)
.value_name("NUMBER")
.validator(is_number)
.help("plot only the top N entries"),
)
.arg(
Arg::new("data-files")
.multiple_occurrences(true)
.value_name("PATH_TO_BENCHMARK_DATA")
.min_values(1)
.default_value("")
.forbid_empty_values(true)
.help("the benchmark data files to plot"),
);
let matches = cmd_line_parser.try_get_matches_from(args)?;
let get_vec = |s: &str| -> Vec<String> {
match matches.values_of(s) {
Some(vs) => vs.map(|v| v.to_string()).collect(),
_ => vec![],
}
};
let out_file = if matches.is_present("out") {
matches.value_of("out").unwrap().to_string()
} else {
"plot.svg".to_owned()
};
let sort = matches.is_present("sort");
let top = if matches.is_present("top") {
Some(matches.value_of("top").unwrap().parse::<usize>()?)
} else {
None
};
let data_files = get_vec("data-files");
let plot = Plot::try_parse_from(args)?;
let mut data = vec![];
for file in data_files {
for file in plot.data_files {
data.push(benchmark::read_benchmark(&file).context(format!("cannot open `{}`", file))?);
}

if sort {
if plot.sort {
data[0].sort();
}

if let Some(n) = top {
if let Some(n) = plot.top {
data[0].take(n)
}

println!("plotting to `{}`", out_file);
plot_benchmarks_to_file(&out_file, data.as_slice())
println!("plotting to `{}`", plot.out);
plot_benchmarks_to_file(&plot.out, data.as_slice())
}

pub const LIGHT_GRAY: RGBColor = RGBColor(0xb4, 0xb4, 0xb4);
Expand Down
12 changes: 6 additions & 6 deletions external-crates/move/move-prover/mutation/src/mutator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub fn mutate(args: &[String]) {
Arg::new("addresses")
.long("address")
.short('a')
.multiple_occurrences(true)
.action(clap::ArgAction::Append)
.number_of_values(1)
.takes_value(true)
.value_name("ADDRESS")
Expand All @@ -52,7 +52,7 @@ pub fn mutate(args: &[String]) {
.short('c')
.long("config")
.takes_value(true)
.multiple_occurrences(true)
.action(clap::ArgAction::Append)
.number_of_values(1)
.value_name("CONFIG_PATH")
.help(
Expand All @@ -65,7 +65,7 @@ pub fn mutate(args: &[String]) {
Arg::new("dependencies")
.long("dependency")
.short('d')
.multiple_occurrences(true)
.action(clap::ArgAction::Append)
.number_of_values(1)
.takes_value(true)
.value_name("PATH_TO_DEPENDENCY")
Expand All @@ -76,22 +76,22 @@ pub fn mutate(args: &[String]) {
)
.arg(
Arg::new("sources")
.multiple_occurrences(true)
.action(clap::ArgAction::Append)
.value_name("PATH_TO_SOURCE_FILE")
.min_values(1)
.help("the source files to verify"),
);
let matches = cmd_line_parser.get_matches_from(args);
let get_vec = |s: &str| -> Vec<String> {
match matches.values_of(s) {
match matches.get_many::<String>(s) {
Some(vs) => vs.map(|v| v.to_string()).collect(),
_ => vec![],
}
};
let addresses = get_vec("addresses");
let sources = get_vec("sources");
let deps = get_vec("dependencies");
let configs: Vec<Option<String>> = if matches.is_present("config") {
let configs: Vec<Option<String>> = if matches.contains_id("config") {
get_vec("config").into_iter().map(Some).collect_vec()
} else {
vec![None]
Expand Down
Loading

0 comments on commit 41a8eff

Please sign in to comment.