Conversation
cee345a to
91f05d9
Compare
Yes, I think that risking breaking our users' code as a way to recover information about our codebase is not a good idea. I would rather keep the line unless someone can prove (by reasoning on the code statically) that is never useful -- or @garrigue remembers why it's there and reassures us that it can safely be removed. Maybe it's not too hard to use |
| let rec remove_first_column = function | ||
| | (_::ps)::rem -> ps::remove_first_column rem | ||
| | _ -> [] | ||
| in |
There was a problem hiding this comment.
Is this the same thing as List.map List.tl?
There was a problem hiding this comment.
Not exactly: what about matrices which contains some rows but no columns?
I don't know off-hand whether we can have some in that places and the current implementation was meant to handle them, or if the code was just written this way because it was written this way.
Not sure it's worth changing.
To clarify, you are talking of squashing all the commits. Yes, I think it's a bad idea: countless time people thought "oh it's painful to prepare a proper patchset and it won't matter anyway", and we find the giant commit while bisecting something or blaming to understand the reason for a change, and it's a pain. Here all your changes are reasonable as self-contained commits, there is nothing that obviously needs to be squashed into previous commits. Would you have a semi-automated way to check that the compiler remains buildable and passes the testsuite after each commit? If you do, and if it passes, then I would support merging the PR with the separate commits. |
|
(One way to do the check is to write a script that does |
|
The My understanding of the discussion with @maranget is that this is good to merge modulo the two points that @garrigue should comment on. (I still think that 9cc2261 should not be in the PR by default, and its presence is what discouraged me from "approving" already.) |
I had actually, blaming gave me no insights. There was no Here is a minimal reproduction case: type abstract
type opt =
| N
| S of abstract
let name_of_input = function
| N -> ()
| S _ -> ()OCaml 4.00With the following patch applied: diff --git a/typing/parmatch.ml b/typing/parmatch.ml
index 0873f2b6d..36f011331 100644
--- a/typing/parmatch.ml
+++ b/typing/parmatch.ml
@@ -1187,7 +1187,18 @@ let exhaust_gadt ext pss n =
Rnone -> Rnone
| Rsome lst ->
(* The following line is needed to compile stdlib/printf.ml *)
- if lst = [] then Rsome (omegas n) else
+ if lst = [] then (
+ let () =
+ let loc =
+ try let pat = List.hd (List.hd pss) in pat.pat_loc
+ with _ -> Location.none
+ in
+ Format.fprintf Format.err_formatter
+ "%a: empty witness list (will return _×%d)\n%!"
+ Location.print_error loc n
+ in
+ Rsome (omegas n)
+ ) else
let singletons =
List.map
(functionHere is what I get: This branchWith the following diff: diff --git a/typing/parmatch.ml b/typing/parmatch.ml
index e723c2c32..c7754a75f 100644
--- a/typing/parmatch.ml
+++ b/typing/parmatch.ml
@@ -1234,6 +1234,18 @@ let exhaust ext pss n =
match ret with
No_matching_value -> No_matching_value
| Witnesses lst ->
+ if lst = [] then (
+ let () =
+ let loc =
+ try let pat = List.hd (List.hd pss) in pat.pat_loc
+ with _ -> Location.none
+ in
+ Format.fprintf Format.err_formatter
+ "%a: empty witness list (will return _×%d)\n%!"
+ Location.print_error loc n
+ in
+ Witnesses (omegas n)
+ ) else
let singletons =
List.map
(functionHere is what I get: ConclusionI do not understand what was going wrong, but I'm still in favor of removing the line since we know what it was trying to catch. I'd be happy to update the patch to add this small example to the testsuite to make sure it is not broken in the future. |
Keeping cruft that nobody understand is not a good solution either. I agree we should track the original reason, but if one cannot find it and if removing the irregularity does not break any known code, I'm in favor of doing the clean up. |
|
I don't disagree. You have my encouragement to remove it if someone checks that the whole of opam builds without it. Unless this is done, please keep it in. |
|
About the controversial line |
|
But Thomas above had a reproduction case where the conditional fires in OCaml 4.00. Does his repro case not get into this path anymore on trunk? |
|
@garrigue, Now let us look at function If Jacques confirms that the code should stay as it is, I suggest deleting the comment. |
typing/parmatch.ml
Outdated
| * D non-exhaustive => we have a non-filtered value | ||
| *) | ||
| let r = exhaust_gadt ext (filter_extra pss) (n-1) in | ||
| (* As the default matrix is included in [pss] one can avoid recursive |
There was a problem hiding this comment.
Here is one contradiction: the recursive calls are not avoided, Even more, they are performed in all situations, the result being bound to before.
|
As far as I know, @gasche Thomas repro case is for OCaml 4.0, not for trunk. |
All the commits do compile on their own, except for the one preceding "make depend". I should probably just squash the "make depend" commit into it.
Note that that wasn't the case in 4.04 (search for "dug"). |
Sorry I do not see your point. Looking for |
|
That’s because I should have written 4.00... |
|
Ok I see, My other remark on the discrepancy between code and comment is still valid. |
|
If both of you are convinced through static reasoning that this code/case cannot be executed with the current compiler codebase, then of course it is reasonable to remove it. |
Indeed. To sum up: @garrigue could you please comment on the following two points:
Btw, I'm not fond of the wording of that last comment, I'd appreciate it if someone (@gasche?) could make improvement suggestions. Perhaps the comment should simply be removed and the conditional made easier to read, again, suggestions would be appreciated. |
There was a problem hiding this comment.
I think that we shouldn't wait for Jacques feedback (which may come at an arbitrary later time) or my ability to review the comment and suggest improvements (same absence of timeline), and merge now. The risk of merging is that two marginally wrong/improvable comments stay around, but the overall effect of the patch is positive (we fix more such comments). The cost of delaying the merge is that this has to be rebased over and over again, and that everyone willing to understand the codebase today is reading the harder-to-understand version.
Here is a formal approval. I think we could merge now, but I'm waiting for at least @trefis opinion on the merge timing/strategy.
(I ignored the issue of buildability and make depend in my approval decision. If you rebase to restore the property, great, otherwise people will just have to do git bisect skip on this one.)
|
Ok for merging, at least mark the comments as being obsolete. |
|
I'll do a proper last rebase in the next few days, squashing the few things that needs to be squashed and marking as obsolete the comment pointed out by Luc. |
9c5b502 to
8096b22
Compare
This line was here to handle the case where "Rsome []" was being returned, which seemed to happen (at least on OCaml 4.00) when matching on values of abstract types (or with abstract parts). This cannot happen anymore as all the sites returning "Rsome _" return a non-empty list. See ocaml#1488 (comment) for a lengthier discussion on the matter.
|
This is now done. I've also update the description of the commit removing the line talking about printf to summarize the situation and link to this discussion. @gasche: good to merge whenever. |
|
@trefis Concerning point 2 (in For the discussion about the relation with a past bug in |
Fine. Thanks Jacques.
We can now consider that the Printf comment and the |
…as well This is a post merge cleanup. [build_specialized_submatrices] always builds the default bmatrix as part of its work, but was previously only returning it when there were no specialized matrices and when the [return_omega_group] parameter was [true] (yes, this was ugly). As it turns out, all the places calling this function also ended up building the default matrix as a follow up. The function now always returns the default matrix along with the (possibly empty) list of specialized matrices. As a consequence [build_default_matrix] became redundant and was removed. Thanks to Gabriel for noticing this.
Previously, after exhaust had produced a pattern not matched by the matrix formed of the unguarded clauses of the matching, we would try to match the pattern with the matrix formed of the full matching. This implies more work than necessary: we already know the unguarded clauses don't match the pattern, so we only need to test it on the guarded ones.
We avoid doing some redundant work in the process.
The other option was to simply use [option].
[satisfiable] could be expressed in terms of [list_satisfying_vectors] as it only cares about the existance of such a vector. However - it might have a non negligeable impact on performances - satisfiable is a simple function that can be seen as a reference. There is value in keeping it.
Suggested by Luc.
Suggested by Gabriel.
8096b22 to
875e73b
Compare
|
Thanks! I rebased one last time to take into account the lasts comments. I'll merge once travis/appveyor confirm I haven't broken anything. |
This line was here to handle the case where "Rsome []" was being returned, which seemed to happen (at least on OCaml 4.00) when matching on values of abstract types (or with abstract parts). This cannot happen anymore as all the sites returning "Rsome _" return a non-empty list. See #1488 (comment) for a lengthier discussion on the matter.
This imports the Principles and Users sections which have been discussed on Discuss. The actual roadmap (i.e. the development workflows) are still in progress and will be shared with the community for feedback before they are imported. --------- Co-authored-by: Christine Rose <christinerose@users.noreply.github.com>
tl;dr: adding comments, renaming things and deduplicating code
A previous version of this work has already been reviewed by @gasche and @maranget, the comments that follow (apart from some obvious exceptions) are meant for them and might not make sense without a log of the previous discussions.
That being said the commits should all be somewhat atomic and a majority of them contain no meaningful code change (so they should be fairly easy to read).
External review required
Some commits in the list would be better reviewed by @garrigue than by Gabriel or Luc.
Jacques could you have a look at the following commits:
The stdlib, and the testsuite compile fine without that line. So I just removed it.
@gasche would like to keep the line "for safety", but I still would like to see it removed. We have currently no example of code requiring that line (but perhaps you can produce one), and I don't think it's good to keep code that has no visible impact and that no one (at least in Europe, although I haven't asked @yallop) understands. The "good" thing is that the worst that can happen if we remove this line is that we might encounter some code that needs it, at which point the
assert falseinorify_manywill trigger and we can then reintroduce the line and update the testsuite!What do you think / what can you tell us about this?
Updates w.r.t. the previous version
(this section is targeted at Gabriel and Luc)
I implemented the discussed change to [build_specialized_submatrices], I did that in a separate commit (
build_specialized_submatricesreturns the default matrix) to make it easier to review (but it should be squashed eventually).I also removed
build_default_matrixas (as we guessed) it became unused.@gasche: you said you didn't remember why we didn't keep the "omega group" even when we had constructors in the first column, as we would need it if the signature is not complete. And we do indeed need it but were recomputing it (i.e. we were calling
build_default_matrix).@gasche you had suggested that
do_matchcould be factorized. Were you talking about the changes that are done in "remove some code duplication"?I unmerged
satisfiableandsatisfiablesas Luc requested. But I did keep the new name (list_satisfying_vectors) forsatisfiables.I believe I addressed every other comment present in the notes you sent, but you should double check.
PS: my initial plan was to merge all of these commits, but @gasche seemed to be against it. So I delegate the decision to him.