Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop GAT workarounds #3395

Merged
merged 23 commits into from Jan 11, 2023
Merged

Drop GAT workarounds #3395

merged 23 commits into from Jan 11, 2023

Conversation

Elrendio
Copy link
Contributor

@Elrendio Elrendio commented Nov 6, 2022

What it does:

  • Migrates GatWorkarounds to actual GATs

Good to know:

  • Trait ConnectionSealed is kept to keep the feature gate around the Connection implementation.
  • I had to keep the associated type on RowFieldLifetimeHelper in order to express FieldRet without the lifetime of Row
  • This increases the minimal rust version from 1.60.0 to 1.65.0

@Elrendio Elrendio marked this pull request as ready for review November 6, 2022 19:38
@Elrendio
Copy link
Contributor Author

Elrendio commented Nov 6, 2022

Tests seems to fail because of GAT not stable 🤔

@Ten0
Copy link
Member

Ten0 commented Nov 6, 2022

Tests seems to fail because of GAT not stable

toolchain: nightly-2022-08-12

/// Field type returned by a `Row` implementation
///
/// * Crates using existing backend should not concern themself with the
/// concrete type of this associated type.
///
/// * Crates implementing custom backends should provide their own type
/// meeting the required trait bounds
type Field: Field<'a, DB>;
type Field<'a>: Field<'a, DB>;
Copy link
Member

Choose a reason for hiding this comment

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

why doesn't this move on the Row trait?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had to keep the associated type on RowSealed in order to express FieldRet without the lifetime of Row

Copy link
Member

Choose a reason for hiding this comment

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

explained in the commit message and additional doc

Copy link
Member

Choose a reason for hiding this comment

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

Can you check if pub type FieldRet<'a, R, DB> = <R as Row<'a, DB>>::Field<'a>; works for all provided cases? If that's the case I would rather move the Field GAT to Row instead of having another trait for this.

diesel/src/row.rs Outdated Show resolved Hide resolved
@Ten0 Ten0 changed the title Drop gat workarounds Drop GAT workarounds Nov 6, 2022
@Ten0
Copy link
Member

Ten0 commented Nov 6, 2022

Likely needs some msrv upgrade, compile tests output regeneration and some clippy stuff

@Elrendio
Copy link
Contributor Author

Elrendio commented Nov 6, 2022

Clippy warnings seems to be mostly unrelevant. For the elided lifetime, it is required and I really don't think '_ is clearer than 'conn

@Elrendio
Copy link
Contributor Author

Elrendio commented Nov 7, 2022

The compile error comes from a warning that's also generated and seems to be a bug from Rust, as it complains for the experimental feature when it's actually feature-flagged out.

Copy link
Member

@weiznich weiznich left a comment

Choose a reason for hiding this comment

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

Thanks for opening this PR 👍
I've left a number of comments about which parts should be changed so that it is clearer for potential users what the the corresponding types look like.

For the clippy/ci stuff: I've opened #3396 to address that.

@@ -295,7 +295,7 @@ jobs:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly-2022-08-12
toolchain: nightly-2022-11-05
Copy link
Member

Choose a reason for hiding this comment

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

This likely requires rerunning the compile tests with TRYBUILD=overwrite + committing all the changes.

@@ -423,11 +423,11 @@ jobs:
run: cargo +nightly -Z build-std test --manifest-path diesel/Cargo.toml --no-default-features --features "sqlite extras libsqlite3-sys libsqlite3-sys/bundled libsqlite3-sys/with-asan" --target x86_64-unknown-linux-gnu

minimal_rust_version:
name: Check Minimal supported rust version (1.60.0)
name: Check Minimal supported rust version (1.65.0)
Copy link
Member

Choose a reason for hiding this comment

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

This requires an change log entry.

diesel/src/connection/mod.rs Show resolved Hide resolved
/// The cursor type returned by [`LoadConnection::load`]
///
/// Users should handle this as opaque type that implements [`Iterator`]
type Cursor<'conn, 'query>: Iterator<Item = QueryResult<Self::Row<'conn, 'query>>>;
Copy link
Member

Choose a reason for hiding this comment

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

The LoadConnection::load method should be changed so that it returns QueryResult<Self::Cursor<'conn, 'query> now. I think that's much easier to understand for potential users + it's the same type as before.

@@ -40,7 +40,17 @@ pub trait SimpleConnection {
///
/// Users should threat this type as `impl Iterator<Item = QueryResult<impl Row<DB>>>`
pub type LoadRowIter<'conn, 'query, C, DB, B = DefaultLoadingMode> =
Copy link
Member

Choose a reason for hiding this comment

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

This type can be deprecated. (It should be behind the with-deprecated feature flag + removed for the without-deprecated flag)

@@ -29,15 +29,15 @@ pub trait RowIndex<I> {
/// Return type of [`Row::get`]
///
/// Users should threat this as opaque [`impl Field<DB>`](Field) type.
pub type FieldRet<'a, R, DB> = <R as RowGatWorkaround<'a, DB>>::Field;
pub type FieldRet<'a, R, DB> = <R as RowFieldLifetimeHelper<DB>>::Field<'a>;
Copy link
Member

Choose a reason for hiding this comment

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

This type should be deprecated as well

/// Field type returned by a `Row` implementation
///
/// * Crates using existing backend should not concern themself with the
/// concrete type of this associated type.
///
/// * Crates implementing custom backends should provide their own type
/// meeting the required trait bounds
type Field: Field<'a, DB>;
type Field<'a>: Field<'a, DB>;
Copy link
Member

Choose a reason for hiding this comment

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

Can you check if pub type FieldRet<'a, R, DB> = <R as Row<'a, DB>>::Field<'a>; works for all provided cases? If that's the case I would rather move the Field GAT to Row instead of having another trait for this.

diesel/src/connection/mod.rs Outdated Show resolved Hide resolved
@Ten0
Copy link
Member

Ten0 commented Nov 9, 2022

It looks like HasBindCollector may be a gat workaround too

@weiznich
Copy link
Member

weiznich commented Nov 9, 2022

Yes HasBindCollector and also HasRawValue are GAT workarounds. Both can be added directly to Backend.

@weiznich
Copy link
Member

@Elrendio Do you plan to follow up onto the comments above?

@weiznich
Copy link
Member

weiznich commented Jan 5, 2023

This is currently blocked on rust-lang/rust#106417 and on a trybuild release containing dtolnay/trybuild#213

diesel/src/connection/mod.rs Outdated Show resolved Hide resolved
diesel/src/query_dsl/load_dsl.rs Show resolved Hide resolved
diesel/src/row.rs Outdated Show resolved Hide resolved
diesel/src/row.rs Outdated Show resolved Hide resolved
@weiznich weiznich merged commit b48925f into diesel-rs:master Jan 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants