#12985: tweak functor error msgs by prefering changes on the left#12988
#12985: tweak functor error msgs by prefering changes on the left#12988gasche merged 6 commits intoocaml:trunkfrom
Conversation
gasche
left a comment
There was a problem hiding this comment.
Looking at the testsuite examples, my impression is that the change introduces some regressions as well as some improvements.
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| Error: This variant or record definition does not match that of type "d" | ||
| Fields "x" and "y" have been swapped. | ||
| Field "y" has been moved from position 1 to 2. |
There was a problem hiding this comment.
I think that this is a regression.
There was a problem hiding this comment.
This was a corner case because the existing weight considered that a move of one field
a b a
↓-------↑
(aka a delete + insertion ) was a good as an exchange of two fields
a b
↓ ↓
b a
(aka two change) I have fixed this case by tweaking the weights to prefer a swap.
| 1. Modules do not match: | ||
| Set : (module Set) | ||
| is not included in | ||
| Set.OrderedType |
There was a problem hiding this comment.
My impression is that this error message is also worse than before -- this would be clearer if A had type OrderedType, which is how I tend to read this example.
There was a problem hiding this comment.
This case is completely symmetrical? We are going from a Delete-Change to Change-Delete? If A was matching, the path that will be selected would be Delete-Match .
There was a problem hiding this comment.
To me as a human, it is very clear that Set cannot possibly be an OrderedType choice, while A looks like a type that may be intended to be an OrderedType (but maybe compare is mis-spelled or something?).
(The actual error may be that Set was written when say ISet was meant, which happens to be an ordered type. But then showing in details the signature of Set is also irrelevant to that sort of error, so the new message is also mostly noise in this case.)
There was a problem hiding this comment.
The module A has type sig type a end so it's not clear to me how it can be considered more similar to OrderedType than Set without requiring human-level sensitivity (although it generated a smaller error message when picked, but I don't know why the missing type t and compare value were not listed before)
There was a problem hiding this comment.
I agree. I'm not saying that whatever criterion we use should recognize one from the other, just that the new error message is (for humans) slightly worse than before.
| 7. Module TY matches the expected module type ty | ||
| 8. Module TY matches the expected module type ty | ||
| 9. Module TY matches the expected module type ty | ||
| 2. Module FiveArgsExt matches the expected module type Ext |
There was a problem hiding this comment.
This is (slightly) better than before.
| 3. Module types X.T and X.T match | ||
| 4. Module types X.T and X.T match | ||
| 5. Module types X.T and X.T match | ||
| 5. An extra argument is provided of module type X.T |
There was a problem hiding this comment.
This is slightly better than before.
| 2. The following extra argument is provided X : sig type x = int end | ||
| 3. Module X matches the expected module type | ||
| 2. Module X matches the expected module type | ||
| 3. The following extra argument is provided X : sig type x = int end |
There was a problem hiding this comment.
These look almost identical but I agree that the new order is slightly better.
|
Preferring swaps to moves is very reasonable -- as a change of its own I would be happy to approve it. On the other hand, I don't understand what this second commit does in the details, it throws away a |
|
After thinking more about this, I have mellowed on this PR. I think that there is probably a reasonable idea behind it, it is not just clear from looking at the diff, and that the regression in the existing messages are probably taken into account reasonably well by your new, additional change. I remain disconcerted from the fact that I have no clue what is going on when looking at the diff. Could you:
|
|
What happens is that the line select_best_proposition [del;insert;diag]enforces an implicit reverse lexicographic order on the minimal weight paths. In more details, consider the case where the three candidate have the same weight, we end-up with three paths ending with By induction, since we have applied this choice for the all preceding matrix position, this means that the selected path among the paths with minimal weight is the smallest one according to the corresponding reverse lexicographic order. Previously, we (I?) choose the order However, for the sake of partial functor application, we already have in place a elision mechanism for the module F: A -> B -> C - > ...
module M = F(A)results in a Unfortunately, this elision mechanism was triggering less often that it should have because of our choice of order for optimal path. For instance, if we apply the previous functor to an argument that doesn't match any parameter module F: A -> B -> C -> ...
module M = F(D)the paths with optimal weights are:
And with the
|
|
I understand the explanation, thanks. Two questions:
|
module F(X:sig module type T module M:T end) = X.M
module type A = sig type a end
module B = struct type b end
module Three = struct
module M(_:A)(_:A)(_:A) = struct end
module type T = module type of M
end
module E = F(Three)(B)we start with a 2x1 matrix and end with a 2x4 matrix. Selecting the path representative using the reverse lexicographic order bypasses the issue. |
|
Status: I understand the explanation for the first change. You haven't tried explaining the second change, and/or reflecting the explanations in the codebase. |
|
I have added the explanation for the path preference in the diffing matrix in the code. I have also tweaked a bit further the weights for the definition diffing, with an explanation of the constraints involved:
|
gasche
left a comment
There was a problem hiding this comment.
Great! These are more explanations than anyone ever knew we could have, so this is a definite improvement and I am happy to Approve.
|
check-typo would like a Changes entry |
with explanation and constraints.
751f934 to
117070e
Compare
This PR improves the error message for partially applied functor by making the diffing algorithm prefers paths with optimal weight that end with deletions or additions.
This one-line change is sufficient to switch the error message for
from
to
close #12985