Skip to content

Make pattern matching compilation more robust to ill-typed columns#1538

Merged
trefis merged 4 commits intoocaml:trunkfrom
trefis:robuster-matching
Dec 19, 2017
Merged

Make pattern matching compilation more robust to ill-typed columns#1538
trefis merged 4 commits intoocaml:trunkfrom
trefis:robuster-matching

Conversation

@trefis
Copy link
Copy Markdown
Contributor

@trefis trefis commented Dec 19, 2017

The first commit is extracted from #1518 and the test is the one produced in #1493 .

This GPR, unlike #1518, focuses only on the compilation of pattern matchings and fixes the regression introduced by GPR#1459 (which broke the build of jbuilder).
There is a consensus (among @maranget , @gasche and I) that we should merge it and then cherry-pick it on the 4.06 branch (which I'll do once someone formally approves).
The alternative being to revert #1459 from the 4.06 branch, but that means reintroducing a known compilation bug.

@trefis
Copy link
Copy Markdown
Contributor Author

trefis commented Dec 19, 2017

PS: more tests could be added to this GPR, indeed there is a quite extensive list in GPR#1518, but I was too lazy to select the subset of tests from that list which exercised "bugs" in matching.ml while also avoiding assertion failures in parmatch.ml.

I vote for adding more tests only after parmatch.ml is fixed.

@trefis trefis mentioned this pull request Dec 19, 2017
Copy link
Copy Markdown
Member

@gasche gasche left a comment

Choose a reason for hiding this comment

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

I reviewed it again and I believe the PR is correct -- and corresponds to what we discussed. Good to hear that jbuilder is fixed.

| Tpat_any
| Tpat_var _ ->
record_matching_line num_fields [] @ rem
| Tpat_record ([], _) when num_fields = 0 -> rem
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Interesting, how did that line about the empty record end up here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It seemed better to be robust rather than assert false (especially considering other GPRs/discussions currently happening).
As we've discovered, assert falses can go unnoticed for a while even when the underlying invariant cannot be safely assumed anymore.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

On the other hand, the module code generally assumes that record are non-empty everywhere (I thought about this when writing my part of the patch, notice the ubiquitous (_, lbl, _) :: _ patterns). I think it would have been better, for consistency, to have all the code share this same assumption, rather than have some parts be clever and some not. But I also think that the new line you added is correct, and will not require further work by people willing to add empty records, so it's fine to leave it in.

@trefis
Copy link
Copy Markdown
Contributor Author

trefis commented Dec 19, 2017

@gasche looking at the 4.06 branch, it seems that #1459, while listed under the "4.06 maintenance branch" section of Changes, was never cherry-picked.

Should I just cherry-pick and then cherry-pick the current GPR?

PS: for cherry-picking, I planned to squash all the commits of the PR together, for simplicity, does that sound OK to you?

@trefis trefis merged commit 0f342e5 into ocaml:trunk Dec 19, 2017
@trefis trefis mentioned this pull request Dec 19, 2017
@gasche
Copy link
Copy Markdown
Member

gasche commented Dec 19, 2017

@trefis: indeed, the cherry-pick of #1459 is in my working copy, but I did not push it upstream. Let me do it, and I'll also cherry-pick this one. (I use git cherry-pick -x to keep track of the original commit in the cherry-pick messages, very refined.)

gasche pushed a commit to gasche/ocaml that referenced this pull request Dec 19, 2017
Make pattern matching compilation more robust to ill-typed columns

(cherry picked from commit 0f342e5)
@gasche gasche mentioned this pull request Dec 19, 2017
@gasche
Copy link
Copy Markdown
Member

gasche commented Dec 19, 2017

I pushed the two cherry-picked (and conflict-solved) commits in #1539, but I'd like to make a pause before merging in 4.06, give others the opportunity to object.

xavierleroy added a commit that referenced this pull request Dec 21, 2017
Pattern matching fixes (cherry-pick of #1459 and #1538 against the bugfix branch 4.06).
@trefis trefis deleted the robuster-matching branch May 31, 2019 09:34
EmileTrotignon pushed a commit to EmileTrotignon/ocaml that referenced this pull request Jan 12, 2024
Co-authored-by: Christine Rose <christinerose@users.noreply.github.com>
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