Skip to content

Conversation

stephencelis
Copy link
Member

We currently depend directly on the hashability of Statement in the various fetch property wrappers, but this conformance has been found to be problematic and so we should remove it. We can make this change today, though, before removing it, by computing the hashability of a statement from its query fragment data.

We currently depend directly on the hashability of `Statement` in the
various fetch property wrappers, but this conformance has been found to
be problematic and so we should remove it. We can make this change
today, though, before removing it, by computing the hashability of a
statement from its query fragment data.
@stephencelis stephencelis requested a review from mbrandonw October 7, 2025 22:13
stephencelis added a commit to pointfreeco/swift-structured-queries that referenced this pull request Oct 7, 2025
We made `Statement: Hashable` for convenience in holding onto statements
in a shared key for SQLiteData, but that isn't really necessary, since
we can always call out to the underlying query fragment to get a
hashable value.

This conformance unfortunately can cause bugs, including `==` resolving
to the equality operator when a query operator was expected. Another bug
is that `@Table @Selection` types conform to `Statement`, and this
equatable implementation was preferred over the default synthesized
version, making `Table` values equatable strictly by the underlying
query, which meant `@Ephemeral` fields weren't taken into account at
all.

With 0.20.0, all `@Table` applications introduced a `Statement`
conformance, and so this issue becomes much more widespread.

While this change can break SQLiteData if someone upgrades
StructuredQueries before upgrading SQLiteData with the changes from
pointfreeco/sqlite-data#245.
stephencelis added a commit to pointfreeco/swift-structured-queries that referenced this pull request Oct 8, 2025
* `Statement` shouldn't inherit from `Hashable`

We made `Statement: Hashable` for convenience in holding onto statements
in a shared key for SQLiteData, but that isn't really necessary, since
we can always call out to the underlying query fragment to get a
hashable value.

This conformance unfortunately can cause bugs, including `==` resolving
to the equality operator when a query operator was expected. Another bug
is that `@Table @Selection` types conform to `Statement`, and this
equatable implementation was preferred over the default synthesized
version, making `Table` values equatable strictly by the underlying
query, which meant `@Ephemeral` fields weren't taken into account at
all.

With 0.20.0, all `@Table` applications introduced a `Statement`
conformance, and so this issue becomes much more widespread.

While this change can break SQLiteData if someone upgrades
StructuredQueries before upgrading SQLiteData with the changes from
pointfreeco/sqlite-data#245.

* fix
@stephencelis stephencelis merged commit 2235c9e into main Oct 8, 2025
5 checks passed
@stephencelis stephencelis deleted the derive-hashability-from-fragments branch October 8, 2025 20:00
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.

2 participants