Skip to content

Conversation

@kazimuth
Copy link
Contributor

@kazimuth kazimuth commented Mar 7, 2025

Description of Changes

Fixes issue identified in clockworklabs/com.clockworklabs.spacetimedbsdk#264 by implementing IEquatable<Self> for all [SpacetimeDB.Type]s in C#. Also overrides GetHashCode() and ToString() for these types, which should be helpful if users want to use them as hash map keys or print them.

Ready for review.

API and ABI breaking changes

Technically API breaking, since it is possible users manually implemented IEquatable somewhere.
It's an easy fix though.

This also uses #nullable enable and #nullable restore in the generated code. This requires a version of Unity supporting C# 8. But I believe we already required this.

Expected complexity level and risk

2: this is a slightly-tricky algorithm to implement due to some pitfalls in C#'s type system.

Testing

  • Get all C# module stuff compiling
  • Add equality proptests for a wide variety of types
  • Test that that SDK bug is fixed
  • Test quickstart-chat
  • Test blackholio

@kazimuth kazimuth added the abi-break A PR that makes an ABI breaking change label Mar 7, 2025
@kazimuth kazimuth self-assigned this Mar 7, 2025
@kazimuth kazimuth added api-break A PR that makes an API breaking change and removed abi-break A PR that makes an ABI breaking change labels Mar 10, 2025
@kazimuth kazimuth marked this pull request as ready for review March 10, 2025 21:50
@kazimuth kazimuth changed the title Start implementing IEquatable<Self> for all [SpacetimeDB.Type]s Implement IEquatable<Self> for all [SpacetimeDB.Type]s Mar 11, 2025
Finish generated code

Update test output

Codegen seems to be working, but I want to test in blackholio...

Add nullable annotations

Fix nullability of generated == and !=

More elaborate ToString

Test ToString better + fix ToString for tagged enums

One more test case
@kazimuth kazimuth force-pushed the jgilles/csharp-iequatable branch from 1f007f1 to f6c1a7f Compare March 11, 2025 20:02
@joshua-spacetime
Copy link
Collaborator

I don't know the C# sdk well enough to be able to review this change sufficiently. I've reviewed the repro, and so I'm satisfied as long as it fixes the repro test, but I think @rekhoff will be able to give this a much better review.

@joshua-spacetime joshua-spacetime removed their request for review March 11, 2025 21:46
@rekhoff
Copy link
Contributor

rekhoff commented Mar 11, 2025

There is a decent amount going on here, I don't see any clear issues, and what I see makes sense. It looks like the quickstart-chat and blackholio haven't been manually tested with these changes, which would be good to do. I'm going to hold off on my approval until after I get these tested.

Copy link
Contributor

@rekhoff rekhoff left a comment

Choose a reason for hiding this comment

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

Reviewed code, nothing stood out as wrong. Tested the repo version Blackhol.io locally using both a Rust and C# server without running into issues. Marking this as approved!

@kazimuth kazimuth enabled auto-merge March 12, 2025 18:56
@kazimuth kazimuth added this pull request to the merge queue Mar 12, 2025
Merged via the queue into master with commit f5e4663 Mar 12, 2025
14 checks passed
@kazimuth kazimuth deleted the jgilles/csharp-iequatable branch March 13, 2025 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api-break A PR that makes an API breaking change release-1.0.1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants