Skip to content

The Pattern-Matching Bug: testsuite improvements#13121

Merged
gasche merged 3 commits intoocaml:trunkfrom
gasche:matching-partiality-testsuite
Apr 30, 2024
Merged

The Pattern-Matching Bug: testsuite improvements#13121
gasche merged 3 commits intoocaml:trunkfrom
gasche:matching-partiality-testsuite

Conversation

@gasche
Copy link
Copy Markdown
Member

@gasche gasche commented Apr 25, 2024

I am still working on #7241; the next installment of bugfixing PRs is taking a bit more effort than I expected, and here is a PR that only improves the testsuite for this bug in order to make reviewer's life easier in the short future. (cc @Octachron, @trefis, @lthls, @ncik-roberts)

The first commit refines an existing test in a "simple" and a "complex" version. Currently there is only the "complex" version in the testsuite, but both versions behave differently in some cases, and while trying to reason about the compiler behavior I found the behavior surprising. (If someone remembers the full details, we considered two approaches to fix the "context" part of the #7241 bug, and eventually I decided on one; the testsuite was written when I was still working on the first/earlier approach, and so it lacks distinctions that did not matter with that different implementation.)

The second commit adds a more complex test for the "totality bug" part of the fix of #7241, fix which has not been merged yet. This is about testing what happens on argument positions that are immutable themselves (they result from projecting an immutable field) but they are "transitively mutable", they are transitively under a mutable position. This is related to a discussion that we had with @ncik-roberts in #12555 (comment) . Adding a new testcase for this behavior proved very useful because it let me realize that my current "fix for the totality issue" was incomplete in this situation. (I went back and forth on how to handle transitivity, and my working branches include a simplistic approach that I thought was complete and in fact is not.)

The third commit adds coverage for cases that are currently handled by the check_partial logic within runtime/matching.ml, which is a pre-existing, incomplete criterion to downgrade certain pattern-matching problems from Total to Partial. (This heuristic fires when one clause has both mutable fields and either a lazy pattern or a guard.) The final fix for the Pattern-Matching Bug subsumes this incomplete criterion (in a way that also lets us un-pessimize certain programs I think), so that logic will be removed in a further PR. The new testcases ensure that we would detect a regression coming from this, by testing the various settings where it applies.

@ncik-roberts
Copy link
Copy Markdown
Contributor

(I expect you mean #7241 and not #7421.) I'm taking a look at this.

Copy link
Copy Markdown
Contributor

@ncik-roberts ncik-roberts left a comment

Choose a reason for hiding this comment

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

Thank you for these tests, which I expect to make upcoming review easier.

Comment on lines +14 to +24
(* This pattern-matching is in fact total: a Match_failure case is
not necessary for soundness. *)
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.

Suggested change
(* This pattern-matching is in fact total: a Match_failure case is
not necessary for soundness. *)
(* This pattern-matching is in fact total: the Match_failure case
conservatively inserted by the pattern match compiler is not
necessary for soundness. *)

To distinguish this case more clearly from the "This pattern-matching is partial: a Match_failure case is necessary for soundness." comment below on a test where
the case is not inserted.

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 had more explanations before but I repeat those sentences for several examples and the duplication was bad. To take your suggestion into account I added an explanatory paragraph at the beginning of the test file.

Comment on lines +79 to +80
(f/297 =
(function x/298 : int
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.

Mild suggestion: Did you consider adding -dno-unique-ids to the test's flags? That would make this part of the test somewhat less sensitive to the code that comes before, for future changes.

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 don't want to use -dno-unique-ids for pattern-matching tests due to the frequent name conflicts with *match*/nnn identifiers generated during pattern-matching: if we passed the option, some of the -dlambda outputs would become ambiguous. In this testfile for example, the tests immediately below the one you are commenting binds both *match*/307 and *match*/309.

It would be nice to avoid this by tweaking the pattern-matching compiler to generate distinct names in a deterministic way (my idea is to use the path from the root to the current position as a distinguishing suffix), but I never did the work of implement this (not immediate) quality-of-life improvement.

@gasche
Copy link
Copy Markdown
Member Author

gasche commented Apr 30, 2024

Note: this PR and also #13129 would need a maintainer approval so that I can merge them and send the next, more interesting PR in the stack. It would be nice to do this sooner rather than later to benefit from the potential availability of @ncik-roberts.

@gasche gasche force-pushed the matching-partiality-testsuite branch from 96553a3 to cf35906 Compare April 30, 2024 08:59
@gasche
Copy link
Copy Markdown
Member Author

gasche commented Apr 30, 2024

(I have updated the PR after handling the review comments.)

@Octachron
Copy link
Copy Markdown
Member

I will approve once @ncik-roberts approves the review changes.

Copy link
Copy Markdown
Contributor

@ncik-roberts ncik-roberts left a comment

Choose a reason for hiding this comment

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

My review was very much nits and I'm happy with the responses so I'll approve.

Copy link
Copy Markdown
Member

@Octachron Octachron left a comment

Choose a reason for hiding this comment

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

Approving on @ncik-roberts behalf (and also because having more tests to explain the behaviour of the pattern-matching compiler is nice).

@gasche gasche merged commit 63ec086 into ocaml:trunk Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants