Skip to content

Add mechanism for diffing graphs#557

Open
thomasmarshall wants to merge 2 commits intomainfrom
diff-tool
Open

Add mechanism for diffing graphs#557
thomasmarshall wants to merge 2 commits intomainfrom
diff-tool

Conversation

@thomasmarshall
Copy link
Contributor

@thomasmarshall thomasmarshall commented Feb 4, 2026

This PR adds a diff.rs module that can be used to compare two different graphs. This could be useful for a couple of different cases:

  1. Rubydex should deterministically generate identical graphs for the same source input—being able to verify the result will give us confidence that it's working correctly. For example, in Make IDs 32bits #542 we switch to using 32bit IDs, but on large projects I believe that results in collisions. Using this diff tool I was able to confirm that 64bit IDs resulted in identical graphs but 32bit IDs results in significant differences.
  2. As we implement incremental update functionality, it's useful to verify that the state of an incrementally updated graph is identical to the state of a freshly built one. In my prototypes I have been using a macro in tests like assert_incremental_graph_identical! which validates the incrementally updated graph matches a fresh graph with the same source input. I have also been using an incremental_verify tool (similar to the diff tool in this PR) to compare incremental updates between different git references. This has been really useful in validating that the incremental update prototypes (don't yet) work correctly.

I wasn't sure how to make this tool a development only entry point, so I added a dev-tools feature, which I believe means it won't be published? Though I'm not sure about this, would like some feedback or ideas. I switched to an example instead but I'm not sure that's right either.

Example outputs
$ cargo run --bin diff --features="dev-tools" /Users/thomasmarshall/src/github.com/Shopify/tapioca main main
Checking out main...
Building graph for main...
  1770 declarations, 2252 definitions
Checking out main...
Building graph for main...
  1770 declarations, 2252 definitions
Restoring d52e57dca0efd9da6d64fb68e91ce2a824f91f01...

Comparing graphs...
Graphs are identical!
$ cargo run --bin diff --features="dev-tools" /Users/thomasmarshall/src/github.com/Shopify/tapioca main main~10
Checking out main...
Building graph for main...
  1770 declarations, 2252 definitions
Checking out main~10...
Building graph for main~10...
  1773 declarations, 2254 definitions
Restoring d52e57dca0efd9da6d64fb68e91ce2a824f91f01...

Comparing graphs...
Graphs differ!

Added declarations (8):
  + Tapioca::Dsl::Compilers::ActiveRecordRelations::ENUMERABLE_QUERY_METHODS
  + T::Types::Simple::NamePatch::NAME_METHOD
  + Tapioca::<Tapioca>#with_disabled_exits()
  + T::Types::Simple::NamePatch#qualified_name_of()
  + Tapioca::NOOP_METHOD
  + Tapioca::Dsl::Compilers::ActiveRecordRelations::FIND_OR_CREATE_METHODS
  + Tapioca::Dsl::Compilers::ActiveRecordRelations::BUILDER_METHODS
  + Tapioca::<Tapioca>#silence_warnings()

Removed declarations (5):
  - Tapioca::Runtime::NOOP_METHOD
  - Tapioca::Runtime::<Runtime>
  - Tapioca::Dsl::Compilers::ActiveRecordRelations::RELATION_METHODS
  - Tapioca::Runtime::<Runtime>#with_disabled_exits()
  - Tapioca::Runtime::<Runtime>#silence_warnings()

Changed declarations (7):
  ~ Tapioca::Dsl::Compilers::ActiveRecordRelations
      - Tapioca::Dsl::Compilers::ActiveRecordRelations::RELATION_METHODS
      + Tapioca::Dsl::Compilers::ActiveRecordRelations::BUILDER_METHODS
      + Tapioca::Dsl::Compilers::ActiveRecordRelations::FIND_OR_CREATE_METHODS
      + Tapioca::Dsl::Compilers::ActiveRecordRelations::ENUMERABLE_QUERY_METHODS
  ~ Module
      descendants differ
  ~ Tapioca::<Tapioca>
      + Tapioca::<Tapioca>#with_disabled_exits()
      + Tapioca::<Tapioca>#silence_warnings()
      ancestors differ
      descendants differ
  ~ Object
      descendants differ
  ~ Tapioca::Runtime
      - Tapioca::Runtime::NOOP_METHOD
      singleton_class differs
  ~ T::Types::Simple::NamePatch
      + T::Types::Simple::NamePatch::NAME_METHOD
      + T::Types::Simple::NamePatch#qualified_name_of()
  ~ Tapioca
      + Tapioca::NOOP_METHOD

Added definitions: 380
Removed definitions: 378

Added references: 842
Removed references: 848

Added names: 34
Removed names: 34

@thomasmarshall thomasmarshall marked this pull request as ready for review February 4, 2026 21:32
@thomasmarshall thomasmarshall requested a review from a team as a code owner February 4, 2026 21:32
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.

1 participant