Skip to content
Merged
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
236 changes: 168 additions & 68 deletions crates/sqllib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,10 @@ pub type WSet<D> = OrdZSet<D>;
#[doc(hidden)]
pub type IndexedWSet<K, D> = OrdIndexedZSet<K, D>;

// Macro to create variants of a function with 1 argument
// If there exists a function is f_(x: T) -> S, this creates a function
// fN(x: Option<T>) -> Option<S>, defined as
// fN(x) { let x = x?; Some(f_(x)) }.
/// Macro to create variants of a function with 1 argument
/// If there exists a function is f_(x: T) -> S, this creates a function
/// fN(x: Option<T>) -> Option<S>, defined as
/// fN(x) { let x = x?; Some(f_(x)) }.
macro_rules! some_function1 {
($func_name:ident, $arg_type:ty, $ret_type:ty) => {
::paste::paste! {
Expand All @@ -248,10 +248,10 @@ macro_rules! some_function1 {

pub(crate) use some_function1;

// Macro to create variants of a function with 1 argument
// If there exists a function is f_type(x: T) -> S, this creates a function
// f_typeN(x: Option<T>) -> Option<S>
// { let x = x?; Some(f_type(x)) }.
/// Macro to create variants of a function with 1 argument
/// If there exists a function is f_type(x: T) -> S, this creates a function
/// f_typeN(x: Option<T>) -> Option<S>
/// { let x = x?; Some(f_type(x)) }.
macro_rules! some_polymorphic_function1 {
($func_name:ident $(< $( const $var : ident : $ty: ty),* >)?, $type_name: ident, $arg_type:ty, $ret_type:ty) => {
::paste::paste! {
Expand All @@ -266,13 +266,14 @@ macro_rules! some_polymorphic_function1 {

pub(crate) use some_polymorphic_function1;

// Macro to create variants of a function with 2 arguments
// If there exists a function is f__(x: T, y: S) -> U, this creates
// three functions:
// - f_N(x: T, y: Option<S>) -> Option<U>
// - fN_(x: Option<T>, y: S) -> Option<U>
// - fNN(x: Option<T>, y: Option<S>) -> Option<U>
// The resulting functions return Some only if all arguments are 'Some'.
/// Macro to create variants of a function with 2 arguments
/// If there exists a function is f__(x: T, y: S) -> U, this creates
/// three functions:
/// - f_N(x: T, y: Option<S>) -> Option<U>
/// - fN_(x: Option<T>, y: S) -> Option<U>
/// - fNN(x: Option<T>, y: Option<S>) -> Option<U>
///
/// The resulting functions return Some only if all arguments are 'Some'.
macro_rules! some_function2 {
($func_name:ident, $arg_type0:ty, $arg_type1:ty, $ret_type:ty) => {
::paste::paste! {
Expand Down Expand Up @@ -300,13 +301,14 @@ macro_rules! some_function2 {

pub(crate) use some_function2;

// Macro to create variants of a polymorphic function with 2 arguments
// If there exists a function is f_type1_type2(x: T, y: S) -> U, this
// creates three functions:
// - f_type1_type2N(x: T, y: Option<S>) -> Option<U>
// - f_type1N_type2(x: Option<T>, y: S) -> Option<U>
// - f_type1N_type2N(x: Option<T>, y: Option<S>) -> Option<U>
// The resulting functions return Some only if all arguments are 'Some'.
/// Macro to create variants of a polymorphic function with 2 arguments
/// If there exists a function is f_type1_type2(x: T, y: S) -> U, this
/// creates three functions:
/// - f_type1_type2N(x: T, y: Option<S>) -> Option<U>
/// - f_type1N_type2(x: Option<T>, y: S) -> Option<U>
/// - f_type1N_type2N(x: Option<T>, y: Option<S>) -> Option<U>
///
/// The resulting functions return Some only if all arguments are 'Some'.
macro_rules! some_polymorphic_function2 {
($func_name:ident $(< $( const $var:ident : $ty: ty),* >)?, $type_name0: ident, $arg_type0:ty, $type_name1: ident, $arg_type1:ty, $ret_type:ty) => {
::paste::paste! {
Expand Down Expand Up @@ -334,12 +336,13 @@ macro_rules! some_polymorphic_function2 {

pub(crate) use some_polymorphic_function2;

// If there exists a function is f_t1_t2_t3(x: T, y: S, z: V) -> U, this creates
// seven functions:
// - f_t1_t2_t3N(x: T, y: S, z: Option<V>) -> Option<U>
// - f_t1_t2N_t2(x: T, y: Option<S>, z: V) -> Option<U>
// - etc.
// The resulting functions return Some only if all arguments are 'Some'.
/// If there exists a function is f_t1_t2_t3(x: T, y: S, z: V) -> U, this creates
/// seven functions:
/// - f_t1_t2_t3N(x: T, y: S, z: Option<V>) -> Option<U>
/// - f_t1_t2N_t2(x: T, y: Option<S>, z: V) -> Option<U>
/// - etc.
///
/// The resulting functions return Some only if all arguments are 'Some'.
macro_rules! some_polymorphic_function3 {
($func_name:ident,
$type_name0: ident, $arg_type0:ty,
Expand Down Expand Up @@ -427,12 +430,106 @@ macro_rules! some_polymorphic_function3 {

pub(crate) use some_polymorphic_function3;

// If there exists a function is f___(x: T, y: S, z: V) -> U, this creates
// seven functions:
// - f__N(x: T, y: S, z: Option<V>) -> Option<U>
// - f_N_(x: T, y: Option<S>, z: V) -> Option<U>
// - etc.
// The resulting functions return Some only if all arguments are 'Some'.
/// If there exists a function is f_t1_t2_t3(x: T, y: S, z: V) -> Option<U>, this creates
/// seven functions:
/// - f_t1_t2_t3N(x: T, y: S, z: Option<V>) -> Option<U>
/// - f_t1_t2N_t2(x: T, y: Option<S>, z: V) -> Option<U>
/// - etc.
// This is like some_polymorphic_function3, but the result is always Option.
macro_rules! some_polymorphic_null_function3 {
($func_name:ident $(< $( const $var : ident : $ty: ty),* >)?,
$type_name0: ident, $arg_type0:ty,
$type_name1: ident, $arg_type1:ty,
$type_name2: ident, $arg_type2: ty,
$ret_type:ty) => {
::paste::paste! {
#[doc(hidden)]
pub fn [<$func_name _ $type_name0 _ $type_name1 _ $type_name2 N>] $(< $( const $var : $ty ),* >)? (
arg0: $arg_type0,
arg1: $arg_type1,
arg2: Option<$arg_type2>
) -> Option<$ret_type> {
let arg2 = arg2?;
[<$func_name _ $type_name0 _ $type_name1 _ $type_name2>] $(:: < $($var),* >)? (arg0, arg1, arg2)
}

#[doc(hidden)]
pub fn [<$func_name _ $type_name0 _ $type_name1 N _ $type_name2>] $(< $( const $var : $ty ),* >)? (
arg0: $arg_type0,
arg1: Option<$arg_type1>,
arg2: $arg_type2
) -> Option<$ret_type> {
let arg1 = arg1?;
[<$func_name _ $type_name0 _ $type_name1 _ $type_name2>] $(:: < $($var),* >)? (arg0, arg1, arg2)
}

#[doc(hidden)]
pub fn [<$func_name _ $type_name0 _ $type_name1 N _ $type_name2 N>] $(< $( const $var : $ty ),* >)? (
arg0: $arg_type0,
arg1: Option<$arg_type1>,
arg2: Option<$arg_type2>
) -> Option<$ret_type> {
let arg1 = arg1?;
let arg2 = arg2?;
[<$func_name _ $type_name0 _ $type_name1 _ $type_name2>] $(:: < $($var),* >)? (arg0, arg1, arg2)
}

#[doc(hidden)]
pub fn [<$func_name _ $type_name0 N _ $type_name1 _ $type_name2>] $(< $( const $var : $ty ),* >)? (
arg0: Option<$arg_type0>,
arg1: $arg_type1,
arg2: $arg_type2
) -> Option<$ret_type> {
let arg0 = arg0?;
[<$func_name _ $type_name0 _ $type_name1 _ $type_name2>] $(:: < $($var),* >)? (arg0, arg1, arg2)
}

#[doc(hidden)]
pub fn [<$func_name _ $type_name0 N _ $type_name1 _ $type_name2 N>] $(< $( const $var : $ty ),* >)? (
arg0: Option<$arg_type0>,
arg1: $arg_type1,
arg2: Option<$arg_type2>
) -> Option<$ret_type> {
let arg0 = arg0?;
let arg2 = arg2?;
[<$func_name _ $type_name0 _ $type_name1 _ $type_name2>] $(:: < $($var),* >)? (arg0, arg1, arg2)
}

#[doc(hidden)]
pub fn [<$func_name _ $type_name0 N _ $type_name1 N _ $type_name2>] $(< $( const $var : $ty ),* >)? (
arg0: Option<$arg_type0>,
arg1: Option<$arg_type1>,
arg2: $arg_type2
) -> Option<$ret_type> {
let arg0 = arg0?;
let arg1 = arg1?;
[<$func_name _ $type_name0 _ $type_name1 _ $type_name2>] $(:: < $($var),* >)? (arg0, arg1, arg2)
}

#[doc(hidden)]
pub fn [<$func_name _ $type_name0 N _ $type_name1 N _ $type_name2 N>] $(< $( const $var : $ty ),* >)? (
arg0: Option<$arg_type0>,
arg1: Option<$arg_type1>,
arg2: Option<$arg_type2>
) -> Option<$ret_type> {
let arg0 = arg0?;
let arg1 = arg1?;
let arg2 = arg2?;
[<$func_name _ $type_name0 _ $type_name1 _ $type_name2>] $(:: < $($var),* >)? (arg0, arg1, arg2)
}
}
};
}

pub(crate) use some_polymorphic_null_function3;

/// If there exists a function is f___(x: T, y: S, z: V) -> U, this creates
/// seven functions:
/// - f__N(x: T, y: S, z: Option<V>) -> Option<U>
/// - f_N_(x: T, y: Option<S>, z: V) -> Option<U>
/// - etc.
///
/// The resulting functions return Some only if all arguments are 'Some'.
macro_rules! some_function3 {
($func_name:ident, $arg_type0:ty, $arg_type1:ty, $arg_type2: ty, $ret_type:ty) => {
::paste::paste! {
Expand Down Expand Up @@ -488,13 +585,14 @@ macro_rules! some_function3 {

pub(crate) use some_function3;

// Macro to create variants of a function with 4 arguments
// If there exists a function is f____(x: T, y: S, z: V, w: W) -> U, this
// creates fifteen functions:
// - f___N(x: T, y: S, z: V, w: Option<W>) -> Option<U>
// - f__N_(x: T, y: S, z: Option<V>, w: W) -> Option<U>
// - etc.
// The resulting functions return Some only if all arguments are 'Some'.
/// Macro to create variants of a function with 4 arguments
/// If there exists a function is f____(x: T, y: S, z: V, w: W) -> U, this
/// creates fifteen functions:
/// - f___N(x: T, y: S, z: V, w: Option<W>) -> Option<U>
/// - f__N_(x: T, y: S, z: Option<V>, w: W) -> Option<U>
/// - etc.
///
/// The resulting functions return Some only if all arguments are 'Some'.
macro_rules! some_function4 {
($func_name:ident, $arg_type0:ty, $arg_type1:ty, $arg_type2: ty, $arg_type3: ty, $ret_type:ty) => {
::paste::paste! {
Expand Down Expand Up @@ -610,14 +708,15 @@ macro_rules! some_function4 {

pub(crate) use some_function4;

// Macro to create variants of a function with 2 arguments
// optimized for the implementation of arithmetic operators.
// Assuming there exists a function is f__(x: T, y: T) -> U, this creates
// three functions:
// - f_tN_t(x: T, y: Option<T>) -> Option<U>
// - f_t_tN(x: Option<T>, y: T) -> Option<U>
// - f_tN_tN(x: Option<T>, y: Option<T>) -> Option<U>
// The resulting functions return Some only if all arguments are 'Some'.
/// Macro to create variants of a function with 2 arguments
/// optimized for the implementation of arithmetic operators.
/// Assuming there exists a function is f__(x: T, y: T) -> U, this creates
/// three functions:
/// - f_tN_t(x: T, y: Option<T>) -> Option<U>
/// - f_t_tN(x: Option<T>, y: T) -> Option<U>
/// - f_tN_tN(x: Option<T>, y: Option<T>) -> Option<U>
///
/// The resulting functions return Some only if all arguments are 'Some'.
macro_rules! some_existing_operator {
($func_name: ident $(< $( const $var:ident : $ty: ty),* >)?, $short_name: ident, $arg_type: ty, $ret_type: ty) => {
::paste::paste! {
Expand Down Expand Up @@ -648,21 +747,22 @@ macro_rules! some_existing_operator {

pub(crate) use some_existing_operator;

// Macro to create variants of a function with 2 arguments
// optimized for the implementation of arithmetic operators.
// Assuming there exists a function is f(x: T, y: T) -> U, this creates
// four functions:
// - f_t_t(x: T, y: T) -> U
// - f_tN_t(x: T, y: Option<T>) -> Option<U>
// - f_t_tN(x: Option<T>, y: T) -> Option<U>
// - f_tN_tN(x: Option<T>, y: Option<T>) -> Option<U>
// The resulting functions return Some only if all arguments are 'Some'.
//
// Has two variants:
// - Takes the name of the existing function, the generated functions will have
// this prefix
// - Takes the name of the existing function, and the prefix for the generated
// functions
/// Macro to create variants of a function with 2 arguments
/// optimized for the implementation of arithmetic operators.
/// Assuming there exists a function is f(x: T, y: T) -> U, this creates
/// four functions:
/// - f_t_t(x: T, y: T) -> U
/// - f_tN_t(x: T, y: Option<T>) -> Option<U>
/// - f_t_tN(x: Option<T>, y: T) -> Option<U>
/// - f_tN_tN(x: Option<T>, y: Option<T>) -> Option<U>
///
/// The resulting functions return Some only if all arguments are 'Some'.
///
/// Has two variants:
/// - Takes the name of the existing function, the generated functions will have
/// this prefix
/// - Takes the name of the existing function, and the prefix for the generated
/// functions
macro_rules! some_operator {
($func_name: ident $(< $( const $var:ident : $ty: ty),* >)?, $short_name: ident, $arg_type: ty, $ret_type: ty) => {
::paste::paste! {
Expand Down Expand Up @@ -1414,10 +1514,10 @@ where
}
}

// Semigroup for the an aggregate which computes nothing
// Useful when the compiler removes all aggregates from an aggregate operator
// (This is currently never used, because the compiler generates a linear aggregate
// for this case)
/// Semigroup for the an aggregate which computes nothing
/// Useful when the compiler removes all aggregates from an aggregate operator
/// (This is currently never used, because the compiler generates a linear aggregate
/// for this case)
#[derive(Clone)]
#[doc(hidden)]
pub struct EmptySemigroup;
Expand Down
Loading