Merge pull request #461 from AleoHQ/feat/clippy

Update ci.yml
This commit is contained in:
Collin Chin 2020-12-04 16:40:50 -05:00 committed by GitHub
commit 9bb04fd75a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 62 additions and 19 deletions

View File

@ -31,6 +31,49 @@ jobs:
command: fmt
args: --all -- --check
clippy:
name: Clippy
runs-on: ubuntu-latest
env:
RUSTFLAGS: -Dwarnings
strategy:
matrix:
rust:
- stable
- nightly
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install Rust (${{ matrix.rust }})
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
override: true
components: clippy
- name: Check examples
uses: actions-rs/cargo@v1
with:
command: clippy
args: --examples --all
- name: Check examples with all features on stable
uses: actions-rs/cargo@v1
with:
command: clippy
args: --examples --all-features --all
if: matrix.rust == 'stable'
- name: Check benchmarks on nightly
uses: actions-rs/cargo@v1
with:
command: clippy
args: --all-features --examples --all --benches
if: matrix.rust == 'nightly'
test:
name: Test
runs-on: ubuntu-latest

View File

@ -20,64 +20,64 @@ use leo_grammar::Grammar;
use criterion::{criterion_group, criterion_main, Criterion};
use std::{path::Path, time::Duration};
fn ast<'ast>(ast: &Grammar<'ast>) -> Ast {
fn ast(ast: &Grammar) -> Ast {
Ast::new("leo_tree", &ast)
}
fn bench_big_if_else(c: &mut Criterion) {
let filepath = Path::new("./big_if_else.leo").to_path_buf();
let program_string = include_str!("./big_if_else.leo");
let ast = Grammar::new(&filepath, program_string).unwrap();
let grammar = Grammar::new(&filepath, program_string).unwrap();
c.bench_function("Ast::big_if_else", |b| b.iter(|| ast(&ast)));
c.bench_function("Ast::big_if_else", |b| b.iter(|| ast(&grammar)));
}
fn bench_big_ternary(c: &mut Criterion) {
let filepath = Path::new("./big_ternary.leo").to_path_buf();
let program_string = include_str!("./big_ternary.leo");
let ast = Grammar::new(&filepath, program_string).unwrap();
let grammar = Grammar::new(&filepath, program_string).unwrap();
c.bench_function("Ast::big_ternary", |b| b.iter(|| ast(&ast)));
c.bench_function("Ast::big_ternary", |b| b.iter(|| ast(&grammar)));
}
fn bench_big_circuit(c: &mut Criterion) {
let filepath = Path::new("./big_circuit.leo").to_path_buf();
let program_string = include_str!("./big_circuit.leo");
let ast = Grammar::new(&filepath, program_string).unwrap();
let grammar = Grammar::new(&filepath, program_string).unwrap();
c.bench_function("Ast::big_circuit", |b| b.iter(|| ast(&ast)));
c.bench_function("Ast::big_circuit", |b| b.iter(|| ast(&grammar)));
}
fn bench_long_expr(c: &mut Criterion) {
let filepath = Path::new("./long_expr.leo").to_path_buf();
let program_string = include_str!("./long_expr.leo");
let ast = Grammar::new(&filepath, program_string).unwrap();
let grammar = Grammar::new(&filepath, program_string).unwrap();
c.bench_function("Ast::long_expr", |b| b.iter(|| ast(&ast)));
c.bench_function("Ast::long_expr", |b| b.iter(|| ast(&grammar)));
}
fn bench_long_array(c: &mut Criterion) {
let filepath = Path::new("./long_array.leo").to_path_buf();
let program_string = include_str!("./long_array.leo");
let ast = Grammar::new(&filepath, program_string).unwrap();
let grammar = Grammar::new(&filepath, program_string).unwrap();
c.bench_function("Ast::long_array", |b| b.iter(|| ast(&ast)));
c.bench_function("Ast::long_array", |b| b.iter(|| ast(&grammar)));
}
fn bench_many_foos(c: &mut Criterion) {
let filepath = Path::new("./many_foos.leo").to_path_buf();
let program_string = include_str!("./many_foos.leo");
let ast = Grammar::new(&filepath, program_string).unwrap();
let grammar = Grammar::new(&filepath, program_string).unwrap();
c.bench_function("Ast::many_foos", |b| b.iter(|| ast(&ast)));
c.bench_function("Ast::many_foos", |b| b.iter(|| ast(&grammar)));
}
fn bench_many_assigns(c: &mut Criterion) {
let filepath = Path::new("./many_assigns.leo").to_path_buf();
let program_string = include_str!("./many_assigns.leo");
let ast = Grammar::new(&filepath, program_string).unwrap();
let grammar = Grammar::new(&filepath, program_string).unwrap();
c.bench_function("Ast::many_assigns", |b| b.iter(|| ast(&ast)));
c.bench_function("Ast::many_assigns", |b| b.iter(|| ast(&grammar)));
}
criterion_group!(

View File

@ -53,8 +53,8 @@ impl InputValue {
Ok(InputValue::Boolean(boolean))
}
fn from_number(integer_type: IntegerType, number: String) -> Result<Self, InputParserError> {
Ok(InputValue::Integer(integer_type, number))
fn from_number(integer_type: IntegerType, number: String) -> Self {
InputValue::Integer(integer_type, number)
}
fn from_group(group: InputGroupValue) -> Self {
@ -69,7 +69,7 @@ impl InputValue {
match data_type {
DataType::Address(_) => Err(InputParserError::implicit_type(data_type, implicit)),
DataType::Boolean(_) => Err(InputParserError::implicit_type(data_type, implicit)),
DataType::Integer(integer_type) => InputValue::from_number(integer_type, implicit.to_string()),
DataType::Integer(integer_type) => Ok(InputValue::from_number(integer_type, implicit.to_string())),
DataType::Group(_) => Err(InputParserError::implicit_group(implicit)),
DataType::Field(_) => Ok(InputValue::Field(implicit.to_string())),
}
@ -80,7 +80,7 @@ impl InputValue {
(DataType::Address(_), Value::Address(address)) => Ok(InputValue::from_address_value(address)),
(DataType::Boolean(_), Value::Boolean(boolean)) => InputValue::from_boolean(boolean),
(DataType::Integer(integer_type), Value::Integer(integer)) => {
InputValue::from_number(integer_type, integer.to_string())
Ok(InputValue::from_number(integer_type, integer.to_string()))
}
(DataType::Group(_), Value::Group(group)) => Ok(InputValue::from_group(group)),
(DataType::Field(_), Value::Field(field)) => Ok(InputValue::from_field(field)),