Skip to content

[tools] Fix bug in state comparison - #2000

Merged
maranget merged 1 commit into
masterfrom
fix-mcompare
Sep 14, 2026
Merged

maranget merged 1 commit into
masterfrom
fix-mcompare

Conversation

@maranget

Copy link
Copy Markdown
Member

Very unfortunate error in implementing the difference of two sorted lists, introduced by PR #1970.

@psafont psafont left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Separating the refactorings from the behavioral change, as well as explaining that the exact error was in the commit message would help in reviewing the code.

From what I understood, the issue was that that the diffing was not reducing the problem on the recursive call when the second argument is more than the first one.

Comment thread tools/logState.ml
if r < 0 then sts1@diff stss1 (sts2::stss2)
else if r > 0 then diff stss1 (sts2::stss2)
if r < 0 then sts1@diff r1 stss2
else if r > 0 then diff stss1 r2

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is the only change in behaviour I could find, the list passed as second parameter for diff has one fewer element now.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Hi @psafont, you are correct. Sorry for having hidden the fix.

Comment thread tools/logState.ml
Comment on lines -422 to +426
if r < 0 then sts1@diff stss1 (sts2::stss2)
else if r > 0 then diff stss1 (sts2::stss2)
if r < 0 then sts1@diff r1 stss2
else if r > 0 then diff stss1 r2

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I have updated the commit message.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

thanks!

Very unfortunate error in implementing
the difference of two sorted lists.

The wrong code was in the definition of `do_diff_state`:
```OCaml
       let r = cmp_by_env sts1 sts2 in
       if r < 0 then sts1@diff stss1 (sts2::stss2)
       else if r > 0 then diff stss1 (sts2::stss2)
...
```
Which should have been:
```OCaml
       let r = cmp_by_env sts1 sts2 in
       if r < 0 then sts1@diff stss1 (sts2::stss2)
       else if r > 0 then diff (sts1::stss1) stss2
...
```
@maranget
maranget merged commit 46da782 into master Sep 14, 2026
3 checks passed
@maranget
maranget deleted the fix-mcompare branch September 14, 2026 15:13
@maranget

Copy link
Copy Markdown
Member Author

Merged, thanks @psafont for the quick review.

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