-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#12061 fix: avoid adding inconsistent equations in functor error messages #12063
Conversation
I tried to jump at the diff and read the code, but I need more context to understand what is going on, and I am too lazy to look it up myself so let's just ask here.
|
|
I wasn't meaning to suggest that states in a pair are equivalent. I view the edit matrix for the words W1 and W2 as formed of pairs of prefixes of W1 and W2, with (empty, empty) on one end and (W1, W2) on the other end, and any other point is (P1, P2) for two prefixes. I assume, in the case of "functor diffing", words/prefixes are sequences of module
This is too abstract for me and I would need an example (or to think hard about it, but who wants to do that?). Would you introduce some documentation for |
This would not be the right place for such documentation, since your questions concern the typing of functor applications or functor inclusion in general and are not related to the diffing algorithm. |
631a3e7
to
d2b1f50
Compare
I added some more comments (and one fix for an error detected while writing the comments). More generally, the higher level specification of
Consider for instance: module _: sig
module F: functor (X: sig type 'a t = 'a * 'a end)(Y: sig type 'a t = 'a X.t * 'a list end) -> sig end
end = struct
module F(X: sig type 'a s = 'a list end)(Y: sig type 'a t = ('a * 'a) * 'a X.s end) = struct end
end The second parameters ought to be considered as matching because they both extend to sig type 'a t = ('a * 'a) * 'a list however this equality rely on the type abbreviations defined in the diverging first arguments
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked at the Functor_inclusion_diff part (not the Function_app_diff part), it looks okay. The new comments are really helpful for me to make sense of what is going on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(looking just at the new commit)
| None, None -> | ||
env, subst | ||
in | ||
let env, subst = equate_one_functor_param subst env arg2' name1 name2 in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I would have env
before subst
in the parameter list, because subst
lives "over" env
(its well-formedness depends on the value of env
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather keep the same order as the one in the non-error path.
Env.add_module id1 Mp_present arg2' env, | ||
Subst.add_module id2 (Path.Pident id1) subst | ||
| Some id1, None -> | ||
Env.add_module id1 Mp_present arg2' env, subst |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: in the error code there was a nice symmetry between the None, Some
and the Some, None
case, this is not the case here -- there is a rename in one case and not in the other. Why the difference?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bugfix from #10693 to avoid potential identifier collisions in the non-error path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved, with minor nitpicks to be taken into account or not depending on the author's whims.
let mty' = Subst.modtype Keep st.subst mty in | ||
let env = Env.add_module ~arg:true param Mp_present mty' st.env in | ||
let res = Option.map (Mtype.nondep_supertype env [param]) st.res in | ||
I.expand_params { st with env; res} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reviewed this part with @Octachron's help and I agree that it does what it says it does.
let env, subst = | ||
equate_one_functor_param st.subst st.env arg name1 name2 | ||
in | ||
expand_params { st with env; subst } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The nice refactoring has the slight downside of having heterogeneous abstraction levels across the different cases here, a minor issue which could be solved by moving the Subst+Env logic to their own auxiliary functions as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added a small auxiliary function for binding abstractions in the environment.
9e93063
to
d39ee94
Compare
when computing module inclusion.
d39ee94
to
f649da5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am happy with the new state of the code, and the extra documentation. Approved.
Since this is a localized bug fix, I am thinking of cherry-picking it to 4.14 . Any objections? |
Sounds fine to me. |
This PR fixes by #12061 by making sure that the diffing algorithm for functor errors doesn't add inconsistent equations to the typing environment when exploring potential patches.
More precisely, this PR ensures that whenever the type of the concrete functor argument and the type of the abstract parameter disagree, we don't add any equations between the two.
It might be possible to be more finer-grained and keep consistent equations but that's probably better done at a later point. Note that the second commit in this PR removes a test which is no longer relevant without such addition of consistent equations.
Along the way, this PR fixes a small fixes when the diffing algorithm was not adding enough equations when inserting a missing argument.
Fix #12061