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
133 changes: 72 additions & 61 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,73 +2,84 @@ name: Rust

on:
push:
branches: [ master ]
branches: [master]
pull_request:
branches: [ master ]
branches: [master]

env:
CARGO_TERM_COLOR: always
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: stable
components: clippy,rustfmt
- uses: tombi-toml/setup-tombi@v1
- name: Print versions
run: |
cargo --version
rustc --version
clippy-driver --version
rustfmt --version
tombi --version
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
- name: Run clippy
run: cargo clippy --verbose --all-targets -- -D clippy::all
- name: Check code formatting
run: cargo fmt --verbose --all -- --check
- name: Check toml formatting
run: tombi format --check
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: stable
components: clippy
- name: Print versions
run: |
cargo --version
rustc --version
clippy-driver --version
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
- name: Run clippy
run: cargo clippy --verbose --all-targets -- -D clippy::all

fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: nightly
components: rustfmt
- uses: tombi-toml/setup-tombi@v1
- name: Print versions
run: |
rustfmt --version
tombi --version
- name: Check code formatting
run: cargo +nightly fmt --check
- name: Check toml formatting
run: tombi format --check

doc:
name: Documentation
runs-on: ubuntu-latest
env:
RUSTDOCFLAGS: -D warnings
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: stable
- name: Print versions
run: |
cargo --version
rustc --version
rustdoc --version
- name: Doc
run: cargo doc --verbose
- name: Doc with all features
run: cargo doc --verbose --all-features
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: stable
- name: Print versions
run: |
cargo --version
rustc --version
rustdoc --version
- name: Doc
run: cargo doc --verbose
- name: Doc with all features
run: cargo doc --verbose --all-features

miri-test:
name: Test with miri
runs-on: ubuntu-latest
env:
MIRIFLAGS: -Zmiri-disable-isolation
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: nightly
components: miri
- run: cargo miri test --verbose --no-default-features
- run: cargo miri test --verbose --all-features
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: nightly
components: miri
- run: cargo miri test --verbose --no-default-features
- run: cargo miri test --verbose --all-features

sanitizer-test:
name: Test with -Zsanitizer=${{ matrix.sanitizer }}
Expand All @@ -78,19 +89,19 @@ jobs:
matrix:
sanitizer: [address, thread, leak]
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: nightly
components: rust-src
- name: Test with sanitizer
env:
RUSTFLAGS: -Zsanitizer=${{ matrix.sanitizer }}
RUSTDOCFLAGS: -Zsanitizer=${{ matrix.sanitizer }}
# only needed by asan
ASAN_OPTIONS: detect_stack_use_after_return=1,detect_leaks=0
# Asan's leak detection occasionally complains
# about some small leaks if backtraces are captured,
# so ensure they're not
RUST_BACKTRACE: 0
run: cargo test -Zbuild-std --verbose --target=x86_64-unknown-linux-gnu --lib --bins --tests
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: nightly
components: rust-src
- name: Test with sanitizer
env:
RUSTFLAGS: -Zsanitizer=${{ matrix.sanitizer }}
RUSTDOCFLAGS: -Zsanitizer=${{ matrix.sanitizer }}
# only needed by asan
ASAN_OPTIONS: detect_stack_use_after_return=1,detect_leaks=0
# Asan's leak detection occasionally complains
# about some small leaks if backtraces are captured,
# so ensure they're not
RUST_BACKTRACE: 0
run: cargo test -Zbuild-std --verbose --target=x86_64-unknown-linux-gnu --lib --bins --tests
11 changes: 6 additions & 5 deletions engine/src/ast/field_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ use crate::{
};
use serde::{Serialize, Serializer};
use sliceslice::MemchrSearcher;
use std::cmp::Ordering;
use std::collections::BTreeSet;
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
#[cfg(any(target_arch = "x86", target_arch = "x86_64", target_arch = "wasm32"))]
use std::sync::LazyLock;
use std::{
cmp::Ordering,
collections::BTreeSet,
net::{IpAddr, Ipv4Addr, Ipv6Addr},
};

const LESS: u8 = 0b001;
const GREATER: u8 = 0b010;
Expand Down Expand Up @@ -819,8 +821,7 @@ mod tests {
};
use cidr::IpCidr;
use serde::Deserialize;
use std::sync::LazyLock;
use std::{convert::TryFrom, iter::once, net::IpAddr};
use std::{convert::TryFrom, iter::once, net::IpAddr, sync::LazyLock};

fn any_function<'a>(args: FunctionArgs<'_, 'a>) -> Option<LhsValue<'a>> {
match args.next()? {
Expand Down
9 changes: 5 additions & 4 deletions engine/src/ast/function_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ use crate::{
types::{GetType, LhsValue, RhsValue, Type},
};
use serde::Serialize;
use std::hash::{Hash, Hasher};
use std::iter::once;
use std::{
hash::{Hash, Hasher},
iter::once,
};

/// Represents a function argument in a function call.
#[derive(Debug, PartialEq, Eq, Clone, Hash, Serialize)]
Expand Down Expand Up @@ -541,8 +543,7 @@ mod tests {
scheme::{FieldIndex, IndexAccessError, Scheme},
types::{RhsValues, Type, TypeMismatchError},
};
use std::convert::TryFrom;
use std::sync::LazyLock;
use std::{convert::TryFrom, sync::LazyLock};

fn any_function<'a>(args: FunctionArgs<'_, 'a>) -> Option<LhsValue<'a>> {
match args.next()? {
Expand Down
2 changes: 1 addition & 1 deletion engine/src/ast/index_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ impl GetType for IndexExpr {
(Type::Array(sub_ty), FieldIndex::MapEach) => sub_ty.into(),
(Type::Map(sub_ty), FieldIndex::MapKey(_)) => sub_ty.into(),
(Type::Map(sub_ty), FieldIndex::MapEach) => sub_ty.into(),
(_, _) => unreachable!(),
(..) => unreachable!(),
}
}
ty
Expand Down
6 changes: 4 additions & 2 deletions engine/src/ast/logical_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,10 @@ impl Expr for LogicalExpr {
fn test() {
use super::field_expr::ComparisonExpr;
use crate::{
ast::field_expr::{ComparisonOpExpr, IdentifierExpr},
ast::index_expr::IndexExpr,
ast::{
field_expr::{ComparisonOpExpr, IdentifierExpr},
index_expr::IndexExpr,
},
execution_context::ExecutionContext,
lex::complete,
lhs_types::Array,
Expand Down
4 changes: 1 addition & 3 deletions engine/src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ pub mod logical_expr;
pub mod parse;
pub mod visitor;

use self::index_expr::IndexExpr;
use self::logical_expr::LogicalExpr;
use self::parse::FilterParser;
use self::{index_expr::IndexExpr, logical_expr::LogicalExpr, parse::FilterParser};
use crate::{
compiler::{Compiler, DefaultCompiler},
filter::{CompiledExpr, CompiledValueExpr, Filter, FilterValue},
Expand Down
8 changes: 5 additions & 3 deletions engine/src/ast/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ use crate::{
lex::{LexErrorKind, LexResult, LexWith, complete},
scheme::Scheme,
};
use std::cmp::{max, min};
use std::error::Error;
use std::fmt::{self, Debug, Display, Formatter};
use std::{
cmp::{max, min},
error::Error,
fmt::{self, Debug, Display, Formatter},
};

/// An opaque filter parsing error associated with the original input.
///
Expand Down
18 changes: 8 additions & 10 deletions engine/src/execution_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ use crate::{
scheme::{Field, List, Scheme, SchemeMismatchError},
types::{GetType, LhsValue, LhsValueSeed, Type, TypeMismatchError},
};
use serde::Serialize;
use serde::de::{self, DeserializeSeed, Deserializer, MapAccess, SeqAccess, Visitor};
use serde::ser::{SerializeMap, SerializeSeq, Serializer};
use std::borrow::Cow;
use std::fmt;
use std::fmt::Debug;
use serde::{
Serialize,
de::{self, DeserializeSeed, Deserializer, MapAccess, SeqAccess, Visitor},
ser::{SerializeMap, SerializeSeq, Serializer},
};
use std::{borrow::Cow, fmt, fmt::Debug};
use thiserror::Error;

/// An error that occurs when setting the field value in the [`crate::ExecutionContext`].
Expand Down Expand Up @@ -570,8 +570,7 @@ fn test_scheme_mismatch() {
#[test]
fn test_serde() {
use crate::lhs_types::{Array, TypedMap};
use std::net::IpAddr;
use std::str::FromStr;
use std::{net::IpAddr, str::FromStr};

let scheme = Scheme! {
bool: Bool,
Expand Down Expand Up @@ -730,8 +729,7 @@ fn test_serde() {

#[test]
fn test_clear() {
use std::net::IpAddr;
use std::str::FromStr;
use std::{net::IpAddr, str::FromStr};

let scheme = Scheme! {
bool: Bool,
Expand Down
12 changes: 7 additions & 5 deletions engine/src/functions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ use crate::{
pub use all::AllFunction;
pub use any::AnyFunction;
pub use concat::ConcatFunction;
use std::any::Any;
use std::convert::TryFrom;
use std::fmt::{self, Debug};
use std::iter::once;
use std::{
any::Any,
convert::TryFrom,
fmt::{self, Debug},
iter::once,
};
use thiserror::Error;

pub(crate) struct ExactSizeChain<A, B>
Expand Down Expand Up @@ -407,7 +409,7 @@ pub trait FunctionDefinition: Debug + Send + Sync {
) -> Box<dyn for<'i, 'a> Fn(FunctionArgs<'i, 'a>) -> Option<LhsValue<'a>> + Sync + Send + 'static>;
}

/* Simple function APIs */
// Simple function APIs

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

Expand Down
7 changes: 3 additions & 4 deletions engine/src/lhs_types/array.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use super::{TypedMap, map::InnerMap};
use crate::{
lhs_types::AsRefIterator,
types::{CompoundType, GetType, IntoValue, LhsValue, LhsValueSeed, Type, TypeMismatchError},
Expand All @@ -13,8 +14,6 @@ use std::{
hint::unreachable_unchecked,
};

use super::{TypedMap, map::InnerMap};

// Ideally, we would want to use Cow<'a, LhsValue<'a>> here
// but it doesnt work for unknown reasons
// See https://github.com/rust-lang/rust/issues/23707#issuecomment-557312736
Expand Down Expand Up @@ -322,8 +321,8 @@ impl ExactSizeIterator for ArrayIntoIter<'_> {
}

impl<'a> IntoIterator for Array<'a> {
type Item = LhsValue<'a>;
type IntoIter = ArrayIntoIter<'a>;
type Item = LhsValue<'a>;

fn into_iter(self) -> Self::IntoIter {
match self.data {
Expand Down Expand Up @@ -357,8 +356,8 @@ impl ExactSizeIterator for ArrayIter<'_, '_> {
}

impl<'a, 'b> IntoIterator for &'b Array<'a> {
type Item = &'b LhsValue<'a>;
type IntoIter = ArrayIter<'a, 'b>;
type Item = &'b LhsValue<'a>;

#[inline]
fn into_iter(self) -> Self::IntoIter {
Expand Down
11 changes: 6 additions & 5 deletions engine/src/lhs_types/bytes.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use serde::de::Visitor;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::borrow::{Borrow, Cow};
use std::hash::{Hash, Hasher};
use std::ops::Deref;
use serde::{Deserialize, Deserializer, Serialize, Serializer, de::Visitor};
use std::{
borrow::{Borrow, Cow},
hash::{Hash, Hasher},
ops::Deref,
};

/// A byte string.
#[derive(Debug, Clone)]
Expand Down
Loading