Skip to content

Commit

Permalink
Merge pull request #3167 from weiznich/improve/compile_times
Browse files Browse the repository at this point in the history
Optimise build times
  • Loading branch information
weiznich committed May 6, 2022
2 parents 209f22a + ce39fe7 commit 99f209f
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -357,46 +357,14 @@ macro_rules! tuple_impls {
}

macro_rules! impl_contains_defaultable_value {
(
@build
start_ts = [$($ST: ident,)*],
ts = [$T1: ident,],
bounds = [$($bounds: tt)*],
out = [$($out: tt)*],
)=> {
impl<$($ST,)*> ContainsDefaultableValue for ($($ST,)*)
where
$($ST: ContainsDefaultableValue,)*
$($bounds)*
$T1::Out: Any<$($out)*>,
{
type Out = <$T1::Out as Any<$($out)*>>::Out;
}

};
(
@build
start_ts = [$($ST: ident,)*],
ts = [$T1: ident, $($T: ident,)+],
bounds = [$($bounds: tt)*],
out = [$($out: tt)*],
)=> {
impl_contains_defaultable_value! {
@build
start_ts = [$($ST,)*],
ts = [$($T,)*],
bounds = [$($bounds)* $T1::Out: Any<$($out)*>,],
out = [<$T1::Out as Any<$($out)*>>::Out],
}
};
($T1: ident, $($T: ident,)+) => {
impl_contains_defaultable_value! {
@build
start_ts = [$T1, $($T,)*],
ts = [$($T,)*],
bounds = [],
out = [$T1::Out],
}
impl<$T1, $($T,)*> ContainsDefaultableValue for ($T1, $($T,)*)
where $T1: ContainsDefaultableValue,
($($T,)*): ContainsDefaultableValue,
$T1::Out: Any<<($($T,)*) as ContainsDefaultableValue>::Out>
{
type Out = <$T1::Out as Any<<($($T,)*) as ContainsDefaultableValue>::Out>>::Out;
}
};
($T1: ident,) => {
impl<$T1> ContainsDefaultableValue for ($T1,)
Expand Down
72 changes: 23 additions & 49 deletions diesel/src/type_impls/tuples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use crate::deserialize::{
};
use crate::expression::{
is_contained_in_group_by, AppearsOnTable, AsExpression, AsExpressionList, Expression,
IsContainedInGroupBy, QueryMetadata, Selectable, SelectableExpression, TypedExpressionType,
ValidGrouping,
IsContainedInGroupBy, MixedAggregates, QueryMetadata, Selectable, SelectableExpression,
TypedExpressionType, ValidGrouping,
};
use crate::insertable::{CanInsertInSingleQuery, InsertValues, Insertable, InsertableOptionHelper};
use crate::query_builder::*;
Expand Down Expand Up @@ -114,12 +114,6 @@ macro_rules! tuple_impls {
const HAS_STATIC_QUERY_ID: bool = $($T::HAS_STATIC_QUERY_ID &&)+ true;
}

const _: () = {
#[derive(ValidGrouping)]
#[diesel(foreign_derive)]
struct TupleWrapper<$($T,)*>(($($T,)*));
};

impl_valid_grouping_for_tuple_of_columns!($($T,)*);

impl<$($T,)+ Tab> UndecoratedInsertRecord<Tab> for ($($T,)+)
Expand Down Expand Up @@ -453,49 +447,23 @@ macro_rules! impl_from_sql_row {
}

macro_rules! impl_valid_grouping_for_tuple_of_columns {
(
@build
start_ts = [$($ST: ident,)*],
ts = [$T1: ident,],
bounds = [$($bounds: tt)*],
is_aggregate = [$($is_aggregate: tt)*],
) => {
impl<$($ST,)* Col> IsContainedInGroupBy<Col> for ($($ST,)*)
where Col: Column,
$($ST: IsContainedInGroupBy<Col>,)*
$($bounds)*
<$T1 as IsContainedInGroupBy<Col>>::Output: is_contained_in_group_by::IsAny<$($is_aggregate)*>,
($T1: ident, $($T: ident,)+) => {
impl<$T1, $($T,)* __GroupByClause> ValidGrouping<__GroupByClause> for ($T1, $($T,)*)
where
$T1: ValidGrouping<__GroupByClause>,
($($T,)*): ValidGrouping<__GroupByClause>,
$T1::IsAggregate: MixedAggregates<<($($T,)*) as ValidGrouping<__GroupByClause>>::IsAggregate>,
{
type Output = <<$T1 as IsContainedInGroupBy<Col>>::Output as is_contained_in_group_by::IsAny<$($is_aggregate)*>>::Output;
}
};
(
@build
start_ts = [$($ST: ident,)*],
ts = [$T1: ident, $($T: ident,)+],
bounds = [$($bounds: tt)*],
is_aggregate = [$($is_aggregate: tt)*],
) => {
impl_valid_grouping_for_tuple_of_columns! {
@build
start_ts = [$($ST,)*],
ts = [$($T,)*],
bounds = [
$($bounds)*
<$T1 as IsContainedInGroupBy<Col>>::Output: is_contained_in_group_by::IsAny<$($is_aggregate)*>,
],
is_aggregate = [
<<$T1 as IsContainedInGroupBy<Col>>::Output as is_contained_in_group_by::IsAny<$($is_aggregate)*>>::Output
],
type IsAggregate = <$T1::IsAggregate as MixedAggregates<<($($T,)*) as ValidGrouping<__GroupByClause>>::IsAggregate>>::Output;
}
};
($T1: ident, $($T: ident,)+) => {
impl_valid_grouping_for_tuple_of_columns! {
@build
start_ts = [$T1, $($T,)*],
ts = [$($T,)*],
bounds = [],
is_aggregate = [<$T1 as IsContainedInGroupBy<Col>>::Output],

impl<$T1, $($T,)* Col> IsContainedInGroupBy<Col> for ($T1, $($T,)*)
where Col: Column,
($($T,)*): IsContainedInGroupBy<Col>,
$T1: IsContainedInGroupBy<Col>,
$T1::Output: is_contained_in_group_by::IsAny<<($($T,)*) as IsContainedInGroupBy<Col>>::Output>
{
type Output = <$T1::Output as is_contained_in_group_by::IsAny<<($($T,)*) as IsContainedInGroupBy<Col>>::Output>>::Output;
}
};
($T1: ident,) => {
Expand All @@ -505,6 +473,12 @@ macro_rules! impl_valid_grouping_for_tuple_of_columns {
{
type Output = <$T1 as IsContainedInGroupBy<Col>>::Output;
}

impl<$T1, __GroupByClause> ValidGrouping<__GroupByClause> for ($T1,)
where $T1: ValidGrouping<__GroupByClause>
{
type IsAggregate = $T1::IsAggregate;
}
};
}

Expand Down
12 changes: 7 additions & 5 deletions diesel_cli/src/infer_schema_internals/information_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::error::Error;
use diesel::backend::Backend;
use diesel::deserialize::{FromSql, FromSqlRow};
use diesel::dsl::*;
use diesel::expression::{is_aggregate, MixedAggregates, QueryMetadata, ValidGrouping};
use diesel::expression::{is_aggregate, QueryMetadata, ValidGrouping};
#[cfg(feature = "mysql")]
use diesel::mysql::Mysql;
#[cfg(feature = "postgres")]
Expand Down Expand Up @@ -160,10 +160,12 @@ where
)>,
Conn::Backend,
>,
is_aggregate::No: MixedAggregates<
<<Conn::Backend as UsesInformationSchema>::TypeSchema as ValidGrouping<()>>::IsAggregate,
Output = is_aggregate::No,
>,
(
columns::column_name,
<Conn::Backend as UsesInformationSchema>::TypeColumn,
<Conn::Backend as UsesInformationSchema>::TypeSchema,
columns::__is_nullable,
): ValidGrouping<()>,
String: FromSql<sql_types::Text, Conn::Backend>,
Option<String>: FromSql<sql_types::Nullable<sql_types::Text>, Conn::Backend>,
Order<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ error[E0277]: the trait bound `f64: ValidGrouping<()>` is not satisfied
| crate::dsl::BareSelect<T>: AsQuery,
| ------- required by this bound in `diesel::select`
|
= note: required because of the requirements on the impl of `ValidGrouping<()>` for `(diesel::internal::derives::as_expression::Bound<diesel::sql_types::Integer, i32>, f64)`
= note: 1 redundant requirements hidden
= note: required because of the requirements on the impl of `ValidGrouping<()>` for `(f64,)`
= note: 2 redundant requirements hidden
= note: required because of the requirements on the impl of `ValidGrouping<()>` for `diesel::pg::expression::array::ArrayLiteral<(diesel::internal::derives::as_expression::Bound<diesel::sql_types::Integer, i32>, f64), diesel::sql_types::Integer>`
= note: required because of the requirements on the impl of `Query` for `SelectStatement<NoFromClause, diesel::query_builder::select_clause::SelectClause<diesel::pg::expression::array::ArrayLiteral<(diesel::internal::derives::as_expression::Bound<diesel::sql_types::Integer, i32>, f64), diesel::sql_types::Integer>>>`
= note: required because of the requirements on the impl of `AsQuery` for `SelectStatement<NoFromClause, diesel::query_builder::select_clause::SelectClause<diesel::pg::expression::array::ArrayLiteral<(diesel::internal::derives::as_expression::Bound<diesel::sql_types::Integer, i32>, f64), diesel::sql_types::Integer>>>`
Expand All @@ -52,8 +52,8 @@ error[E0277]: the trait bound `f64: ValidGrouping<()>` is not satisfied
11 | select(array((1, 3f64))).get_result::<Vec<i32>>(&mut connection).unwrap();
| ^^^^^^^^^^ the trait `ValidGrouping<()>` is not implemented for `f64`
|
= note: required because of the requirements on the impl of `ValidGrouping<()>` for `(diesel::internal::derives::as_expression::Bound<diesel::sql_types::Integer, i32>, f64)`
= note: 1 redundant requirements hidden
= note: required because of the requirements on the impl of `ValidGrouping<()>` for `(f64,)`
= note: 2 redundant requirements hidden
= note: required because of the requirements on the impl of `ValidGrouping<()>` for `diesel::pg::expression::array::ArrayLiteral<(diesel::internal::derives::as_expression::Bound<diesel::sql_types::Integer, i32>, f64), diesel::sql_types::Integer>`
= note: required because of the requirements on the impl of `Query` for `SelectStatement<NoFromClause, diesel::query_builder::select_clause::SelectClause<diesel::pg::expression::array::ArrayLiteral<(diesel::internal::derives::as_expression::Bound<diesel::sql_types::Integer, i32>, f64), diesel::sql_types::Integer>>>`
= note: required because of the requirements on the impl of `LoadQuery<'_, _, Vec<i32>>` for `SelectStatement<NoFromClause, diesel::query_builder::select_clause::SelectClause<diesel::pg::expression::array::ArrayLiteral<(diesel::internal::derives::as_expression::Bound<diesel::sql_types::Integer, i32>, f64), diesel::sql_types::Integer>>>`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ error[E0277]: the trait bound `users::columns::id: IsContainedInGroupBy<comments
and 2 others
= note: required because of the requirements on the impl of `IsContainedInGroupBy<comments::columns::id>` for `(users::columns::id, posts::columns::id)`
= note: required because of the requirements on the impl of `ValidGrouping<(users::columns::id, posts::columns::id)>` for `comments::columns::id`
= note: 1 redundant requirements hidden
= note: 2 redundant requirements hidden
= note: required because of the requirements on the impl of `ValidGrouping<(users::columns::id, posts::columns::id)>` for `((users::columns::id, users::columns::name, users::columns::hair_color), (posts::columns::id, posts::columns::title, posts::columns::user_id), comments::columns::id)`
= note: required because of the requirements on the impl of `SelectDsl<((users::columns::id, users::columns::name, users::columns::hair_color), (posts::columns::id, posts::columns::title, posts::columns::user_id), comments::columns::id)>` for `SelectStatement<FromClause<JoinOn<diesel::internal::table_macro::Join<users::table, SelectStatement<FromClause<JoinOn<diesel::internal::table_macro::Join<posts::table, comments::table, Inner>, diesel::expression::grouped::Grouped<diesel::expression::operators::Eq<NullableExpression<comments::columns::post_id>, NullableExpression<posts::columns::id>>>>>>, Inner>, diesel::expression::grouped::Grouped<diesel::expression::operators::Eq<NullableExpression<posts::columns::user_id>, NullableExpression<users::columns::id>>>>>, diesel::query_builder::select_clause::DefaultSelectClause<FromClause<JoinOn<diesel::internal::table_macro::Join<users::table, SelectStatement<FromClause<JoinOn<diesel::internal::table_macro::Join<posts::table, comments::table, Inner>, diesel::expression::grouped::Grouped<diesel::expression::operators::Eq<NullableExpression<comments::columns::post_id>, NullableExpression<posts::columns::id>>>>>>, Inner>, diesel::expression::grouped::Grouped<diesel::expression::operators::Eq<NullableExpression<posts::columns::user_id>, NullableExpression<users::columns::id>>>>>>, diesel::query_builder::distinct_clause::NoDistinctClause, diesel::query_builder::where_clause::NoWhereClause, diesel::query_builder::order_clause::NoOrderClause, diesel::query_builder::limit_offset_clause::LimitOffsetClause<diesel::query_builder::limit_clause::NoLimitClause, diesel::query_builder::offset_clause::NoOffsetClause>, diesel::query_builder::group_by_clause::GroupByClause<(users::columns::id, posts::columns::id)>>`

Expand All @@ -77,8 +77,10 @@ error[E0277]: the trait bound `posts::columns::id: IsContainedInGroupBy<comments
<posts::columns::id as IsContainedInGroupBy<posts::columns::user_id>>
<posts::columns::id as IsContainedInGroupBy<users::columns::hair_color>>
and 2 others
= note: required because of the requirements on the impl of `IsContainedInGroupBy<comments::columns::id>` for `(posts::columns::id,)`
= note: 1 redundant requirements hidden
= note: required because of the requirements on the impl of `IsContainedInGroupBy<comments::columns::id>` for `(users::columns::id, posts::columns::id)`
= note: required because of the requirements on the impl of `ValidGrouping<(users::columns::id, posts::columns::id)>` for `comments::columns::id`
= note: 1 redundant requirements hidden
= note: 2 redundant requirements hidden
= note: required because of the requirements on the impl of `ValidGrouping<(users::columns::id, posts::columns::id)>` for `((users::columns::id, users::columns::name, users::columns::hair_color), (posts::columns::id, posts::columns::title, posts::columns::user_id), comments::columns::id)`
= note: required because of the requirements on the impl of `SelectDsl<((users::columns::id, users::columns::name, users::columns::hair_color), (posts::columns::id, posts::columns::title, posts::columns::user_id), comments::columns::id)>` for `SelectStatement<FromClause<JoinOn<diesel::internal::table_macro::Join<users::table, SelectStatement<FromClause<JoinOn<diesel::internal::table_macro::Join<posts::table, comments::table, Inner>, diesel::expression::grouped::Grouped<diesel::expression::operators::Eq<NullableExpression<comments::columns::post_id>, NullableExpression<posts::columns::id>>>>>>, Inner>, diesel::expression::grouped::Grouped<diesel::expression::operators::Eq<NullableExpression<posts::columns::user_id>, NullableExpression<users::columns::id>>>>>, diesel::query_builder::select_clause::DefaultSelectClause<FromClause<JoinOn<diesel::internal::table_macro::Join<users::table, SelectStatement<FromClause<JoinOn<diesel::internal::table_macro::Join<posts::table, comments::table, Inner>, diesel::expression::grouped::Grouped<diesel::expression::operators::Eq<NullableExpression<comments::columns::post_id>, NullableExpression<posts::columns::id>>>>>>, Inner>, diesel::expression::grouped::Grouped<diesel::expression::operators::Eq<NullableExpression<posts::columns::user_id>, NullableExpression<users::columns::id>>>>>>, diesel::query_builder::distinct_clause::NoDistinctClause, diesel::query_builder::where_clause::NoWhereClause, diesel::query_builder::order_clause::NoOrderClause, diesel::query_builder::limit_offset_clause::LimitOffsetClause<diesel::query_builder::limit_clause::NoLimitClause, diesel::query_builder::offset_clause::NoOffsetClause>, diesel::query_builder::group_by_clause::GroupByClause<(users::columns::id, posts::columns::id)>>`
Loading

0 comments on commit 99f209f

Please sign in to comment.