Skip to content

fix(ffi): Export Eq and Hash traits in enums used as HashMap keys#6259

Draft
Slko wants to merge 1 commit intomatrix-org:mainfrom
Slko:ffi-export-eq-hash
Draft

fix(ffi): Export Eq and Hash traits in enums used as HashMap keys#6259
Slko wants to merge 1 commit intomatrix-org:mainfrom
Slko:ffi-export-eq-hash

Conversation

@Slko
Copy link

@Slko Slko commented Mar 9, 2026

matrix_sdk_ffi::ruma::TagName and matrix_sdk_ffi::event::TimelineEventType enums that are used as HashMap keys by matrix_sdk_ffi::ruma::Tag and matrix_sdk_ffi::room::power_levels::RoomPowerLevels respectively should probably export Eq and Hash traits in the FFI as well, so that we can generate correct bindings for languages that implement UniFFI's record (in UDL)/HashMap (in proc-macros) type using a hash table (e.g. std::unordered_map in C++).

After applying these changes, I was able to generate working bindings using my WIP generator for C++ (that I haven't open-sourced yet).

Additional context: mozilla/uniffi-rs#2839

  • I've documented the public API Changes in the appropriate CHANGELOG.md files.
  • This PR was made with the help of AI.

matrix_sdk_ffi::ruma::TagName and matrix_sdk_ffi::event::TimelineEventType enums
that are used as HashMap keys by matrix_sdk_ffi::ruma::Tag and
matrix_sdk_ffi::room::power_levels::RoomPowerLevels respectively should probably
export Eq and Hash traits, so that we can generate bindings for languages that
implement uniffi's record/HashMap type using a hash table (e.g.
std::unordered_map in C++)

Signed-off-by: Stanislav Skobelkin <[email protected]>
@Slko Slko requested a review from a team as a code owner March 9, 2026 08:51
@Slko Slko requested review from Hywan and removed request for a team March 9, 2026 08:51
Copy link
Member

@bnjbvr bnjbvr left a comment

Choose a reason for hiding this comment

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

C++ bindings? 👀 Nice!

Let's see how Complement Crypto likes those new additions…

@Slko
Copy link
Author

Slko commented Mar 9, 2026

Oops, I wasn't familiar with that that test suite. I guess it doesn't like them. That makes everything much more complicated...

@codecov
Copy link

codecov bot commented Mar 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.90%. Comparing base (7c16d67) to head (609277e).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6259      +/-   ##
==========================================
- Coverage   89.90%   89.90%   -0.01%     
==========================================
  Files         372      372              
  Lines      102475   102475              
  Branches   102475   102475              
==========================================
- Hits        92135    92126       -9     
- Misses       6785     6790       +5     
- Partials     3555     3559       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bnjbvr
Copy link
Member

bnjbvr commented Mar 9, 2026

We're unfortunately stuck on older features of uniffi because Complement Crypto doesn't use the latest version. It's been updated recently, but it still might be a bit behind, or require some custom updates for the Go bindings generator 🤔

@codspeed-hq
Copy link

codspeed-hq bot commented Mar 9, 2026

Merging this PR will not alter performance

✅ 50 untouched benchmarks


Comparing Slko:ffi-export-eq-hash (609277e) with main (deabb8b)

Open in CodSpeed

@Slko
Copy link
Author

Slko commented Mar 9, 2026

Yeah, seems like enum traits require at least UniFFI 0.30 which contains non-trivial number of breaking changes and new features, and most generators (including uniffi-bindgen-go) are stuck on 0.29.x. This could probably be worked around with a feature flag, but I feel like it's not worth it for such a minor change.

@Slko Slko marked this pull request as draft March 9, 2026 09:21
@bnjbvr bnjbvr removed the request for review from Hywan March 9, 2026 10:50
@poljar
Copy link
Contributor

poljar commented Mar 9, 2026

Yeah, seems like enum traits require at least UniFFI 0.30 which contains non-trivial number of breaking changes and new features, and most generators (including uniffi-bindgen-go) are stuck on 0.29.x. This could probably be worked around with a feature flag, but I feel like it's not worth it for such a minor change.

Well there is hope: NordSecurity/uniffi-bindgen-go#88.

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.

3 participants