Skip to content

Commit

Permalink
Add #![deny(clippy::all)] to all lib.rs (#453)
Browse files Browse the repository at this point in the history
* Add lint `#![deny(clippy::all)]`
* Automatic fixes from `cargo clippy --fix --all-features; cargo fmt`
* Clean-up based on some clippy recommendations
  • Loading branch information
jpschorr authored Mar 15, 2024
1 parent 6d31b39 commit f9ea25c
Show file tree
Hide file tree
Showing 52 changed files with 596 additions and 488 deletions.
6 changes: 5 additions & 1 deletion extension/partiql-extension-ion-functions/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![deny(rust_2018_idioms)]
#![deny(clippy::all)]

use ion_rs::data_source::ToIonDataSource;
use partiql_catalog::call_defs::{CallDef, CallSpec, CallSpecArg};
Expand Down Expand Up @@ -220,7 +221,10 @@ mod tests {

let parsed = parse(statement);
let lowered = lower(&catalog, &parsed.expect("parse"));
let bindings = env.as_ref().map(|e| (e).into()).unwrap_or_default();
let bindings = env
.as_ref()
.map(std::convert::Into::into)
.unwrap_or_default();
let out = evaluate(&catalog, lowered, bindings);

assert!(out.is_bag());
Expand Down
2 changes: 1 addition & 1 deletion extension/partiql-extension-ion/src/common.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// The encoding to use when decoding/encoding Ion to/from PartiQL [`partiql_value::Value`]
/// The encoding to use when decoding/encoding Ion to/from `PartiQL` [`partiql_value::Value`]
#[derive(Copy, Clone, Eq, PartialEq)]
pub enum Encoding {
/// 'Unlifted'/'Unlowered' Ion to/from PartiQL [`partiql_value::Value`]. [`partiql_value::Value`]s that do not have a direct
Expand Down
7 changes: 6 additions & 1 deletion extension/partiql-extension-ion/src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ use std::str::FromStr;
use thiserror::Error;
use time::Duration;

use crate::common::*;
use crate::common::{
Encoding, BAG_ANNOT, DATE_ANNOT, MISSING_ANNOT, RE_SET_TIME_PARTS, TIME_ANNOT, TIME_PARTS_HOUR,
TIME_PARTS_MINUTE, TIME_PARTS_SECOND, TIME_PARTS_TZ_HOUR, TIME_PARTS_TZ_MINUTE,
};

/// Errors in ion decoding.
///
Expand Down Expand Up @@ -63,6 +66,7 @@ pub struct IonDecoderConfig {

impl IonDecoderConfig {
/// Set the mode to `mode`
#[must_use]
pub fn with_mode(mut self, mode: crate::Encoding) -> Self {
self.mode = mode;
self
Expand All @@ -84,6 +88,7 @@ pub struct IonDecoderBuilder {

impl IonDecoderBuilder {
/// Create the builder from 'config'
#[must_use]
pub fn new(config: IonDecoderConfig) -> Self {
Self { config }
}
Expand Down
41 changes: 27 additions & 14 deletions extension/partiql-extension-ion/src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub struct IonEncoderConfig {

impl IonEncoderConfig {
/// Set the mode to `mode`
#[must_use]
pub fn with_mode(mut self, mode: crate::Encoding) -> Self {
self.mode = mode;
self
Expand All @@ -66,6 +67,7 @@ pub struct IonEncoderBuilder {

impl IonEncoderBuilder {
/// Create the builder from 'config'
#[must_use]
pub fn new(config: IonEncoderConfig) -> Self {
Self { config }
}
Expand Down Expand Up @@ -214,7 +216,7 @@ where
}

fn encode_decimal(&mut self, val: &Decimal) -> IonEncodeResult {
let scale = val.scale() as i64;
let scale = i64::from(val.scale());
let mantissa = val.mantissa();
let dec = ion_rs::Decimal::new(mantissa, -scale);
Ok(self.writer.write_decimal(&dec)?)
Expand All @@ -234,9 +236,13 @@ where
let ts = ion_rs::Timestamp::with_ymd(
ts.year() as u32,
ts.month() as u32,
ts.day() as u32,
u32::from(ts.day()),
)
.with_hms(
u32::from(ts.hour()),
u32::from(ts.minute()),
u32::from(ts.second()),
)
.with_hms(ts.hour() as u32, ts.minute() as u32, ts.second() as u32)
.with_nanoseconds(ts.nanosecond())
.build_at_unknown_offset()?;

Expand All @@ -246,11 +252,15 @@ where
let ts = ion_rs::Timestamp::with_ymd(
ts.year() as u32,
ts.month() as u32,
ts.day() as u32,
u32::from(ts.day()),
)
.with_hms(
u32::from(ts.hour()),
u32::from(ts.minute()),
u32::from(ts.second()),
)
.with_hms(ts.hour() as u32, ts.minute() as u32, ts.second() as u32)
.with_nanoseconds(ts.nanosecond())
.build_at_offset(ts.offset().whole_minutes() as i32)?;
.build_at_offset(i32::from(ts.offset().whole_minutes()))?;

Ok(self.writer.write_timestamp(&ts)?)
}
Expand Down Expand Up @@ -324,9 +334,12 @@ where
self.inner
.writer
.set_annotations(std::iter::once(DATE_ANNOT));
let ts =
ion_rs::Timestamp::with_ymd(date.year() as u32, date.month() as u32, date.day() as u32)
.build()?;
let ts = ion_rs::Timestamp::with_ymd(
date.year() as u32,
date.month() as u32,
u32::from(date.day()),
)
.build()?;

Ok(self.inner.writer.write_timestamp(&ts)?)
}
Expand All @@ -336,19 +349,19 @@ where
writer.set_annotations(std::iter::once(TIME_ANNOT));
writer.step_in(IonType::Struct)?;
writer.set_field_name(TIME_PART_HOUR_KEY);
writer.write_i64(time.hour() as i64)?;
writer.write_i64(i64::from(time.hour()))?;
writer.set_field_name(TIME_PART_MINUTE_KEY);
writer.write_i64(time.minute() as i64)?;
writer.write_i64(i64::from(time.minute()))?;
writer.set_field_name(TIME_PART_SECOND_KEY);

let seconds = Duration::new(time.second() as i64, time.nanosecond() as i32);
let seconds = Duration::new(i64::from(time.second()), time.nanosecond() as i32);
writer.write_f64(seconds.as_seconds_f64())?;

if let Some(offset) = offset {
writer.set_field_name(TIME_PART_TZ_HOUR_KEY);
writer.write_i64(offset.whole_hours() as i64)?;
writer.write_i64(i64::from(offset.whole_hours()))?;
writer.set_field_name(TIME_PART_TZ_MINUTE_KEY);
writer.write_i64(offset.minutes_past_hour() as i64)?;
writer.write_i64(i64::from(offset.minutes_past_hour()))?;
}

writer.step_out()?;
Expand Down
13 changes: 7 additions & 6 deletions extension/partiql-extension-ion/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![deny(rust_2018_idioms)]
#![deny(clippy::all)]

mod common;
pub mod decode;
Expand Down Expand Up @@ -180,7 +181,7 @@ mod tests {
1,
2,
3,
400000000,
400_000_000,
Some(30),
),
);
Expand All @@ -198,7 +199,7 @@ mod tests {
1,
2,
3,
400000000,
400_000_000,
None,
),
);
Expand Down Expand Up @@ -296,7 +297,7 @@ mod tests {
1,
2,
3,
400000000,
400_000_000,
Some(30),
),
);
Expand All @@ -314,7 +315,7 @@ mod tests {
1,
2,
3,
400000000,
400_000_000,
None,
),
);
Expand All @@ -330,7 +331,7 @@ mod tests {
.build(),
)
.with_annotations(["$time"]),
DateTime::from_hms_nano(12, 11, 10, 80000000),
DateTime::from_hms_nano(12, 11, 10, 80_000_000),
);
assert_partiql_encoded_ion(
"$time::{ hour: 12, minute: 11, second: 10.08, timezone_hour: 0, timezone_minute: 30}",
Expand All @@ -346,7 +347,7 @@ mod tests {
.build(),
)
.with_annotations(["$time"]),
DateTime::from_hms_nano_tz(12, 11, 10, 80000000, None, Some(30)),
DateTime::from_hms_nano_tz(12, 11, 10, 80_000_000, None, Some(30)),
);
assert_partiql_encoded_ion(
"$date::1957-05-25T",
Expand Down
1 change: 1 addition & 0 deletions extension/partiql-extension-visualize/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![deny(rust_2018_idioms)]
#![deny(clippy::all)]

#[cfg(feature = "visualize-dot")]
mod ast_to_dot;
Expand Down
3 changes: 2 additions & 1 deletion partiql-ast-passes/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![deny(rust_2018_idioms)]
#![deny(clippy::all)]

//! The PartiQL Abstract Syntax Tree (AST) passes.
//! The `PartiQL` Abstract Syntax Tree (AST) passes.
//!
//! # Note
//!
Expand Down
11 changes: 7 additions & 4 deletions partiql-ast-passes/src/name_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@ impl<'c> NameResolver<'c> {
let is_qnode = |typ, id| {
self.enclosing_clause
.get(&typ)
.map(|nodes| nodes.contains(id))
.unwrap_or(false)
.is_some_and(|nodes| nodes.contains(id))
};
for id in self.id_path_to_root.iter().rev() {
if is_qnode(EnclosingClause::Query, id) {
Expand Down Expand Up @@ -252,7 +251,11 @@ impl<'ast, 'c> Visitor<'ast> for NameResolver<'c> {
produce_optional,
} = keyrefs;
let mut produce: Names = produce_required;
produce.extend(produce_optional.iter().flat_map(|sym| sym.to_owned()));
produce.extend(
produce_optional
.iter()
.filter_map(std::borrow::ToOwned::to_owned),
);

let schema = KeySchema { consume, produce };

Expand Down Expand Up @@ -412,7 +415,7 @@ impl<'ast, 'c> Visitor<'ast> for NameResolver<'c> {
{
self.errors.push(AstTransformError::IllegalState(
"group_key expects a FromLet enclosing clause".to_string(),
))
));
}

self.enclosing_clause
Expand Down
8 changes: 4 additions & 4 deletions partiql-ast-passes/src/partiql_typer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl<'c, 'ast> Visitor<'ast> for AstPartiqlTyper<'c> {
let ty = PartiqlType::new(kind);
let id = *self.current_node();
if let Some(c) = self.container_stack.last_mut() {
c.push(ty.clone())
c.push(ty.clone());
}
self.type_map.insert(id, ty);
Traverse::Continue
Expand Down Expand Up @@ -165,7 +165,7 @@ impl<'c, 'ast> Visitor<'ast> for AstPartiqlTyper<'c> {
self.type_map.insert(id, ty.clone());

if let Some(c) = self.container_stack.last_mut() {
c.push(ty)
c.push(ty);
}

Traverse::Continue
Expand All @@ -188,7 +188,7 @@ impl<'c, 'ast> Visitor<'ast> for AstPartiqlTyper<'c> {

self.type_map.insert(id, ty.clone());
if let Some(s) = self.container_stack.last_mut() {
s.push(ty)
s.push(ty);
}
Traverse::Continue
}
Expand All @@ -210,7 +210,7 @@ impl<'c, 'ast> Visitor<'ast> for AstPartiqlTyper<'c> {

self.type_map.insert(id, ty.clone());
if let Some(s) = self.container_stack.last_mut() {
s.push(ty)
s.push(ty);
}
Traverse::Continue
}
Expand Down
1 change: 1 addition & 0 deletions partiql-ast/partiql-ast-macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![deny(rust_2018_idioms)]
#![deny(clippy::all)]

use darling::{FromDeriveInput, FromField, FromVariant};
use inflector::Inflector;
Expand Down
16 changes: 8 additions & 8 deletions partiql-ast/src/ast.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! A PartiQL abstract syntax tree (AST).
//! A `PartiQL` abstract syntax tree (AST).
//!
//! This module contains the structures for the language AST.
//! Two main entities in the module are [`Item`] and [`AstNode`]. `AstNode` represents an AST node
//! and `Item` represents a PartiQL statement type, e.g. query, data definition language (DDL)
//! and `Item` represents a `PartiQL` statement type, e.g. query, data definition language (DDL)
//! data manipulation language (DML).
// As more changes to this AST are expected, unless explicitly advised, using the structures exposed
Expand Down Expand Up @@ -409,10 +409,10 @@ pub enum Expr {
Error,
}

/// `Lit` is mostly inspired by SQL-92 Literals standard and PartiQL specification.
/// `Lit` is mostly inspired by SQL-92 Literals standard and `PartiQL` specification.
/// See section 5.3 in the following:
/// <https://www.contrib.andrew.cmu.edu/~shadow/sql/sql1992.txt>
/// and Section 2 of the following (Figure 1: BNF Grammar for PartiQL Values):
/// and Section 2 of the following (Figure 1: BNF Grammar for `PartiQL` Values):
/// <https://partiql.org/assets/PartiQL-Specification.pdf>
#[derive(Visit, Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
Expand Down Expand Up @@ -745,7 +745,7 @@ pub struct FromLet {
pub by_alias: Option<SymbolPrimitive>,
}

/// Indicates the type of FromLet, see the following for more details:
/// Indicates the type of `FromLet`, see the following for more details:
/// https:///github.com/partiql/partiql-lang-kotlin/issues/242
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
Expand Down Expand Up @@ -784,7 +784,7 @@ pub enum JoinSpec {
Natural,
}

/// GROUP BY <grouping_strategy> <group_key>[, <group_key>]... \[AS <symbol>\]
/// GROUP BY <`grouping_strategy`> <`group_key`>[, <`group_key`>]... \[AS <symbol>\]
#[derive(Visit, Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct GroupByExpr {
Expand Down Expand Up @@ -813,7 +813,7 @@ pub struct GroupKey {
pub as_alias: Option<SymbolPrimitive>,
}

/// ORDER BY <sort_spec>...
/// ORDER BY <`sort_spec`>...
#[derive(Visit, Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct OrderByExpr {
Expand Down Expand Up @@ -852,7 +852,7 @@ pub enum NullOrderingSpec {
Last,
}

/// Represents all possible PartiQL data types.
/// Represents all possible `PartiQL` data types.
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum Type {
Expand Down
3 changes: 2 additions & 1 deletion partiql-ast/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![deny(rust_2018_idioms)]
#![deny(clippy::all)]

//! The PartiQL Abstract Syntax Tree (AST).
//! The `PartiQL` Abstract Syntax Tree (AST).
//!
//! # Note
//!
Expand Down
6 changes: 3 additions & 3 deletions partiql-ast/src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,9 +556,9 @@ mod tests {
impl<'ast> Visitor<'ast> for Accum {
fn enter_lit(&mut self, literal: &'ast Lit) -> Traverse {
match literal {
Lit::Int8Lit(l) => self.val.get_or_insert(0i64).add_assign(*l as i64),
Lit::Int16Lit(l) => self.val.get_or_insert(0i64).add_assign(*l as i64),
Lit::Int32Lit(l) => self.val.get_or_insert(0i64).add_assign(*l as i64),
Lit::Int8Lit(l) => self.val.get_or_insert(0i64).add_assign(i64::from(*l)),
Lit::Int16Lit(l) => self.val.get_or_insert(0i64).add_assign(i64::from(*l)),
Lit::Int32Lit(l) => self.val.get_or_insert(0i64).add_assign(i64::from(*l)),
Lit::Int64Lit(l) => self.val.get_or_insert(0i64).add_assign(l),
_ => {}
}
Expand Down
6 changes: 1 addition & 5 deletions partiql-catalog/src/call_defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ pub struct CallDef {
}

impl CallDef {
pub fn lookup(
&self,
args: &Vec<CallArgument>,
name: &str,
) -> Result<ValueExpr, CallLookupError> {
pub fn lookup(&self, args: &[CallArgument], name: &str) -> Result<ValueExpr, CallLookupError> {
'overload: for overload in &self.overloads {
let formals = &overload.input;
if formals.len() != args.len() {
Expand Down
Loading

1 comment on commit f9ea25c

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PartiQL (rust) Benchmark

Benchmark suite Current: f9ea25c Previous: 6d31b39 Ratio
arith_agg-avg 753295 ns/iter (± 10692) 749794 ns/iter (± 20334) 1.00
arith_agg-avg_distinct 840324 ns/iter (± 4163) 844710 ns/iter (± 16836) 0.99
arith_agg-count 793350 ns/iter (± 10629) 794064 ns/iter (± 23842) 1.00
arith_agg-count_distinct 839384 ns/iter (± 2146) 827009 ns/iter (± 10296) 1.01
arith_agg-min 798513 ns/iter (± 6679) 803369 ns/iter (± 9148) 0.99
arith_agg-min_distinct 833475 ns/iter (± 2626) 848859 ns/iter (± 6799) 0.98
arith_agg-max 804812 ns/iter (± 46953) 803537 ns/iter (± 3943) 1.00
arith_agg-max_distinct 840423 ns/iter (± 3375) 859256 ns/iter (± 1644) 0.98
arith_agg-sum 799199 ns/iter (± 31039) 801012 ns/iter (± 3588) 1.00
arith_agg-sum_distinct 837469 ns/iter (± 3462) 834489 ns/iter (± 3412) 1.00
arith_agg-avg-count-min-max-sum 940946 ns/iter (± 3800) 943002 ns/iter (± 6682) 1.00
arith_agg-avg-count-min-max-sum-group_by 1191733 ns/iter (± 24045) 1180518 ns/iter (± 8179) 1.01
arith_agg-avg-count-min-max-sum-group_by-group_as 1765004 ns/iter (± 15301) 1794515 ns/iter (± 26653) 0.98
arith_agg-avg_distinct-count_distinct-min_distinct-max_distinct-sum_distinct 1266530 ns/iter (± 6843) 1279122 ns/iter (± 6998) 0.99
arith_agg-avg_distinct-count_distinct-min_distinct-max_distinct-sum_distinct-group_by 1531211 ns/iter (± 18789) 1572001 ns/iter (± 22089) 0.97
arith_agg-avg_distinct-count_distinct-min_distinct-max_distinct-sum_distinct-group_by-group_as 2097034 ns/iter (± 9635) 2158777 ns/iter (± 15168) 0.97
parse-1 4246 ns/iter (± 14) 4175 ns/iter (± 17) 1.02
parse-15 39512 ns/iter (± 138) 40432 ns/iter (± 185) 0.98
parse-30 77971 ns/iter (± 220) 76469 ns/iter (± 226) 1.02
compile-1 4275 ns/iter (± 98) 4263 ns/iter (± 35) 1.00
compile-15 30620 ns/iter (± 105) 30966 ns/iter (± 109) 0.99
compile-30 62886 ns/iter (± 209) 62785 ns/iter (± 239) 1.00
plan-1 69165 ns/iter (± 229) 66750 ns/iter (± 1100) 1.04
plan-15 1069606 ns/iter (± 19098) 1040907 ns/iter (± 10129) 1.03
plan-30 2148107 ns/iter (± 6347) 2084147 ns/iter (± 9640) 1.03
eval-1 13395677 ns/iter (± 284023) 12570554 ns/iter (± 179265) 1.07
eval-15 87240379 ns/iter (± 742836) 85804492 ns/iter (± 867122) 1.02
eval-30 167428923 ns/iter (± 586993) 165209384 ns/iter (± 404633) 1.01
join 9691 ns/iter (± 38) 9670 ns/iter (± 31) 1.00
simple 2511 ns/iter (± 10) 2464 ns/iter (± 11) 1.02
simple-no 431 ns/iter (± 2) 436 ns/iter (± 1) 0.99
numbers 57 ns/iter (± 0) 58 ns/iter (± 0) 0.98
parse-simple 539 ns/iter (± 1) 568 ns/iter (± 3) 0.95
parse-ion 1762 ns/iter (± 16) 1799 ns/iter (± 8) 0.98
parse-group 5689 ns/iter (± 25) 5878 ns/iter (± 14) 0.97
parse-complex 14800 ns/iter (± 86) 14743 ns/iter (± 30) 1.00
parse-complex-fexpr 20886 ns/iter (± 91) 21472 ns/iter (± 347) 0.97

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.