Skip to content
Open
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 .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Run tests
run: cargo test --verbose
- name: Run clippy
run: cargo clippy --verbose --all-targets -- -D clippy::all
run: cargo clippy --all-targets -- -Dwarnings

fmt:
runs-on: ubuntu-latest
Expand Down
44 changes: 44 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,50 @@ wasm-bindgen = { version = "0.2.108", features = ["serde-serialize"] }
wildcard = "0.3.0"
wirefilter = { package = "wirefilter-engine", path = "engine" }

# tombi: format.rules.table-keys-order.disabled = true
[workspace.lints.clippy]
# groups
all = { level = "warn", priority = -1 }
cargo = { level = "warn", priority = -1 }
# group exceptions
cargo_common_metadata = "allow"
multiple_crate_versions = "allow"

# tombi: format.rules.table-keys-order.disabled = true
[workspace.lints.rust]
# groups
deprecated-safe = { level = "warn", priority = -1 }
future-incompatible = { level = "warn", priority = -1 }
keyword-idents = { level = "warn", priority = -1 }
let-underscore = { level = "warn", priority = -1 }
nonstandard-style = { level = "warn", priority = -1 }
refining-impl-trait = { level = "warn", priority = -1 }
rust-2018-compatibility = { level = "warn", priority = -1 }
rust-2018-idioms = { level = "warn", priority = -1 }
rust-2021-compatibility = { level = "warn", priority = -1 }
rust-2024-compatibility = { level = "warn", priority = -1 }
unknown-or-malformed-diagnostic-attributes = { level = "warn", priority = -1 }
unused = { level = "warn", priority = -1 }
warnings = { level = "warn", priority = -1 }
# group exceptions
let-underscore-drop = "allow"
# ungrouped
closure-returning-async-block = "warn"
deprecated-in-future = "warn"
deref-into-dyn-supertrait = "warn"
impl-trait-redundant-captures = "warn"
linker-messages = "warn"
macro-use-extern-crate = "warn"
meta-variable-misuse = "warn"
redundant-imports = "warn"
redundant-lifetimes = "warn"
single-use-lifetimes = "warn"
trivial-numeric-casts = "warn"
unit-bindings = "warn"
unused-import-braces = "warn"
unused-lifetimes = "warn"
unused-qualifications = "warn"

[profile.dev]
panic = "unwind"

Expand Down
1 change: 1 addition & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lint-commented-code = true
2 changes: 2 additions & 0 deletions engine/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
lints.workspace = true

[package]
name = "wirefilter-engine"
version.workspace = true
Expand Down
7 changes: 3 additions & 4 deletions engine/benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use std::alloc::System;
static A: System = System;

use criterion::{Bencher, Criterion, criterion_group, criterion_main};
use std::clone::Clone;
use std::fmt::Debug;
use std::net::IpAddr;
use wirefilter::{
Expand Down Expand Up @@ -87,7 +86,7 @@ impl<T: 'static + Copy + Debug + Into<LhsValue<'static>>> FieldBench<'_, T> {
builder.add_function(name, function.clone()).unwrap();
}
let scheme = builder.build();
move |b: &mut Bencher| {
move |b: &mut Bencher<'_>| {
b.iter(|| scheme.parse(filter).unwrap());
}
});
Expand All @@ -103,7 +102,7 @@ impl<T: 'static + Copy + Debug + Into<LhsValue<'static>>> FieldBench<'_, T> {
builder.add_function(name, function.clone()).unwrap();
}
let scheme = builder.build();
move |b: &mut Bencher| {
move |b: &mut Bencher<'_>| {
let filter = scheme.parse(filter).unwrap();

b.iter_with_setup(move || filter.clone(), FilterAst::compile);
Expand All @@ -121,7 +120,7 @@ impl<T: 'static + Copy + Debug + Into<LhsValue<'static>>> FieldBench<'_, T> {
builder.add_function(name, function.clone()).unwrap();
}
let scheme = builder.build();
move |b: &mut Bencher, values: &[T]| {
move |b: &mut Bencher<'_>, values: &[T]| {
let filter = scheme.parse(filter).unwrap();

let filter = filter.compile();
Expand Down
17 changes: 6 additions & 11 deletions engine/src/ast/field_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -791,12 +791,11 @@ impl Expr for ComparisonExpr {
}

#[cfg(test)]
#[allow(clippy::bool_assert_comparison)]
#[expect(clippy::bool_assert_comparison)]
mod tests {
use super::*;
use crate::ast::function_expr::{FunctionCallArgExpr, FunctionCallExpr};
use crate::ast::function_expr::FunctionCallArgExpr;
use crate::ast::logical_expr::LogicalExpr;
use crate::execution_context::ExecutionContext;
use crate::functions::{
FunctionArgKind, FunctionArgs, FunctionDefinition, FunctionDefinitionContext,
FunctionParam, FunctionParamError, SimpleFunctionDefinition, SimpleFunctionImpl,
Expand All @@ -805,17 +804,14 @@ mod tests {
use crate::lhs_types::{Array, Map};
use crate::list_matcher::{ListDefinition, ListMatcher};
use crate::rhs_types::{IpRange, RegexFormat};
use crate::scheme::{FieldIndex, IndexAccessError, Scheme};
use crate::scheme::{FieldIndex, IndexAccessError};
use crate::types::ExpectedType;
use crate::{
BytesFormat, FieldRef, LhsValue, ParserSettings, SchemeBuilder, SimpleFunctionArgKind,
TypedMap,
BytesFormat, FieldRef, ParserSettings, SchemeBuilder, SimpleFunctionArgKind, TypedMap,
};
use cidr::IpCidr;
use serde::Deserialize;
use std::convert::TryFrom;
use std::iter::once;
use std::net::IpAddr;
use std::sync::LazyLock;

fn any_function<'a>(args: FunctionArgs<'_, 'a>) -> Option<LhsValue<'a>> {
Expand Down Expand Up @@ -843,7 +839,6 @@ mod tests {
}
}

#[allow(clippy::unnecessary_wraps)]
fn concat_function<'a>(args: FunctionArgs<'_, 'a>) -> Option<LhsValue<'a>> {
let mut output = Vec::new();
for (index, arg) in args.enumerate() {
Expand Down Expand Up @@ -947,10 +942,10 @@ mod tests {
pub struct NumMListDefinition {}

impl ListDefinition for NumMListDefinition {
fn deserialize_matcher<'de>(
fn deserialize_matcher(
&self,
_: Type,
deserializer: &mut dyn erased_serde::Deserializer<'de>,
deserializer: &mut dyn erased_serde::Deserializer<'_>,
) -> Result<Box<dyn ListMatcher>, erased_serde::Error> {
let matcher = erased_serde::deserialize::<NumMatcher>(deserializer)?;
Ok(Box::new(matcher))
Expand Down
30 changes: 8 additions & 22 deletions engine/src/ast/function_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::ValueExpr;
use super::parse::FilterParser;
use super::visitor::{Visitor, VisitorMut};
use crate::FunctionRef;
use crate::ast::field_expr::{ComparisonExpr, ComparisonOp, ComparisonOpExpr};
use crate::ast::field_expr::{ComparisonExpr, ComparisonOp};
use crate::ast::index_expr::IndexExpr;
use crate::ast::logical_expr::{LogicalExpr, UnaryOp};
use crate::compiler::Compiler;
Expand Down Expand Up @@ -88,17 +88,6 @@ impl FunctionCallArgExpr {
FunctionCallArgExpr::Logical(_) => 0,
}
}

#[allow(dead_code)]
pub(crate) fn simplify(self) -> Self {
match self {
FunctionCallArgExpr::Logical(LogicalExpr::Comparison(ComparisonExpr {
lhs,
op: ComparisonOpExpr::IsTrue,
})) => FunctionCallArgExpr::IndexExpr(lhs),
_ => self,
}
}
}

impl<'i, 's> LexWith<'i, &FilterParser<'s>> for FunctionCallArgExpr {
Expand Down Expand Up @@ -272,10 +261,10 @@ impl ValueExpr for FunctionCallExpr {
let first = args.remove(0);

#[inline(always)]
fn compute<'s, 'a, I: ExactSizeIterator<Item = CompiledValueResult<'a>>>(
fn compute<'a, I: ExactSizeIterator<Item = CompiledValueResult<'a>>>(
first: CompiledValueResult<'a>,
call: &(
dyn for<'b> Fn(FunctionArgs<'_, 'b>) -> Option<LhsValue<'b>> + Sync + Send + 's
dyn for<'b> Fn(FunctionArgs<'_, 'b>) -> Option<LhsValue<'b>> + Sync + Send + '_
),
return_type: Type,
f: impl Fn(LhsValue<'a>) -> I,
Expand Down Expand Up @@ -520,18 +509,15 @@ impl<'i> LexWith<'i, &FilterParser<'_>> for FunctionCallExpr {
#[cfg(test)]
mod tests {
use super::*;
use crate::SimpleFunctionArgKind;
use crate::ast::field_expr::{ComparisonExpr, ComparisonOpExpr, IdentifierExpr, OrderingOp};
use crate::ast::logical_expr::{LogicalExpr, LogicalOp, ParenthesizedExpr};
use crate::ast::parse::FilterParser;
use crate::ast::field_expr::{ComparisonOpExpr, IdentifierExpr, OrderingOp};
use crate::ast::logical_expr::{LogicalOp, ParenthesizedExpr};
use crate::functions::{
FunctionArgKind, FunctionArgKindMismatchError, FunctionArgs, SimpleFunctionDefinition,
SimpleFunctionImpl, SimpleFunctionOptParam, SimpleFunctionParam,
FunctionArgKind, FunctionArgKindMismatchError, SimpleFunctionArgKind,
SimpleFunctionDefinition, SimpleFunctionImpl, SimpleFunctionOptParam, SimpleFunctionParam,
};
use crate::rhs_types::{BytesExpr, BytesFormat};
use crate::scheme::{FieldIndex, IndexAccessError, Scheme};
use crate::types::{RhsValues, Type, TypeMismatchError};
use std::convert::TryFrom;
use crate::types::{RhsValues, TypeMismatchError};
use std::sync::LazyLock;

fn any_function<'a>(args: FunctionArgs<'_, 'a>) -> Option<LhsValue<'a>> {
Expand Down
8 changes: 3 additions & 5 deletions engine/src/ast/index_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub struct IndexExpr {
pub indexes: Vec<FieldIndex>,
}

#[allow(clippy::manual_ok_err)]
#[expect(clippy::manual_ok_err)]
#[inline]
pub fn ok_ref<T, E>(result: &Result<T, E>) -> Option<&T> {
match result {
Expand Down Expand Up @@ -525,11 +525,9 @@ impl<'a> Iterator for MapEachIterator<'a, '_> {
#[cfg(test)]
mod tests {
use super::*;
use crate::ast::field_expr::IdentifierExpr;
use crate::{
Array, FieldIndex, FilterParser, FunctionArgs, FunctionCallArgExpr, FunctionCallExpr,
Scheme, SchemeBuilder, SimpleFunctionArgKind, SimpleFunctionDefinition, SimpleFunctionImpl,
SimpleFunctionParam,
FunctionArgs, FunctionCallArgExpr, FunctionCallExpr, Scheme, SchemeBuilder,
SimpleFunctionArgKind, SimpleFunctionDefinition, SimpleFunctionImpl, SimpleFunctionParam,
};
use std::sync::LazyLock;

Expand Down
3 changes: 1 addition & 2 deletions engine/src/ast/logical_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,7 @@ impl Expr for LogicalExpr {
}

#[test]
#[allow(clippy::bool_assert_comparison)]
#[allow(clippy::cognitive_complexity)]
#[expect(clippy::bool_assert_comparison)]
fn test() {
use super::field_expr::ComparisonExpr;
use crate::ast::field_expr::{ComparisonOpExpr, IdentifierExpr};
Expand Down
2 changes: 1 addition & 1 deletion engine/src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ pub struct Filter<U = ()> {
scheme: Scheme,
}

impl<U> std::fmt::Debug for Filter<U> {
impl<U> fmt::Debug for Filter<U> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Filter")
.field("root", &self.root_expr)
Expand Down
4 changes: 2 additions & 2 deletions engine/src/functions/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ impl FunctionDefinition for AllFunction {
(1, Some(0))
}

fn compile<'s>(
&'s self,
fn compile(
&self,
_: &mut dyn ExactSizeIterator<Item = FunctionParam<'_>>,
_: Option<FunctionDefinitionContext>,
) -> Box<dyn for<'i, 'a> Fn(FunctionArgs<'i, 'a>) -> Option<LhsValue<'a>> + Sync + Send + 'static>
Expand Down
4 changes: 2 additions & 2 deletions engine/src/functions/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ impl FunctionDefinition for AnyFunction {
(1, Some(0))
}

fn compile<'s>(
&'s self,
fn compile(
&self,
_: &mut dyn ExactSizeIterator<Item = FunctionParam<'_>>,
_: Option<FunctionDefinitionContext>,
) -> Box<dyn for<'i, 'a> Fn(FunctionArgs<'i, 'a>) -> Option<LhsValue<'a>> + Sync + Send + 'static>
Expand Down
4 changes: 2 additions & 2 deletions engine/src/functions/concat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ impl FunctionDefinition for ConcatFunction {
(2, None)
}

fn compile<'s>(
&'s self,
fn compile(
&self,
_: &mut dyn ExactSizeIterator<Item = FunctionParam<'_>>,
_: Option<FunctionDefinitionContext>,
) -> Box<dyn for<'i, 'a> Fn(FunctionArgs<'i, 'a>) -> Option<LhsValue<'a>> + Sync + Send + 'static>
Expand Down
15 changes: 7 additions & 8 deletions engine/src/functions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use crate::types::{
ExpectedType, ExpectedTypeList, GetType, LhsValue, RhsValue, Type, TypeMismatchError,
};
use std::any::Any;
use std::convert::TryFrom;
use std::fmt::{self, Debug};
use std::iter::once;
use thiserror::Error;
Expand Down Expand Up @@ -286,7 +285,7 @@ impl<'a> FunctionParam<'a> {
pub struct FunctionDefinitionContext {
inner: Box<dyn Any + Send + Sync>,
clone_cb: fn(&(dyn Any + Send + Sync)) -> Box<dyn Any + Send + Sync>,
fmt_cb: fn(&(dyn Any + Send + Sync), &mut std::fmt::Formatter<'_>) -> std::fmt::Result,
fmt_cb: fn(&(dyn Any + Send + Sync), &mut fmt::Formatter<'_>) -> fmt::Result,
}

impl FunctionDefinitionContext {
Expand All @@ -298,8 +297,8 @@ impl FunctionDefinitionContext {

fn fmt_any<T: Any + Debug + Send + Sync>(
t: &(dyn Any + Send + Sync),
f: &mut std::fmt::Formatter<'_>,
) -> std::fmt::Result {
f: &mut fmt::Formatter<'_>,
) -> fmt::Result {
t.downcast_ref::<T>().unwrap().fmt(f)
}

Expand Down Expand Up @@ -364,8 +363,8 @@ impl Clone for FunctionDefinitionContext {
}
}

impl std::fmt::Debug for FunctionDefinitionContext {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
impl Debug for FunctionDefinitionContext {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "FunctionDefinitionContext(")?;
(self.fmt_cb)(&*self.inner, f)?;
write!(f, ")")?;
Expand Down Expand Up @@ -409,7 +408,7 @@ pub trait FunctionDefinition: Debug + Send + Sync {

// Simple function APIs

type FunctionPtr = for<'i, 'a> fn(FunctionArgs<'i, 'a>) -> Option<LhsValue<'a>>;
type FunctionPtr = for<'a> fn(FunctionArgs<'_, 'a>) -> Option<LhsValue<'a>>;

/// Wrapper around a function pointer providing the runtime implementation.
#[derive(Clone, Copy)]
Expand All @@ -422,7 +421,7 @@ impl SimpleFunctionImpl {
}
}

impl fmt::Debug for SimpleFunctionImpl {
impl Debug for SimpleFunctionImpl {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_tuple("SimpleFunctionImpl")
.field(&(self.0 as *const ()))
Expand Down
2 changes: 1 addition & 1 deletion engine/src/lhs_types/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ mod tests {

#[test]
fn test_size_of_array() {
assert_eq!(std::mem::size_of::<Array<'_>>(), 32);
assert_eq!(size_of::<Array<'_>>(), 32);
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion engine/src/lhs_types/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub enum Bytes<'a> {
Owned(Box<[u8]>),
}

impl<'a> Bytes<'a> {
impl Bytes<'_> {
/// Clones self into a fully owned byte string.
#[inline]
pub fn to_owned(&self) -> Bytes<'static> {
Expand Down
2 changes: 1 addition & 1 deletion engine/src/lhs_types/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ mod tests {

#[test]
fn test_size_of_map() {
assert_eq!(std::mem::size_of::<Map<'_>>(), 40);
assert_eq!(size_of::<Map<'_>>(), 40);
}

#[test]
Expand Down
3 changes: 0 additions & 3 deletions engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@
//! }
//! ```
#![warn(missing_docs)]
#![warn(rust_2018_idioms)]
#![allow(clippy::upper_case_acronyms)]
#![allow(clippy::needless_raw_string_hashes)]

#[macro_use]
mod lex;
Expand Down
Loading