Fix the scope handling to detect ambiguous results of applications#9815
Fix the scope handling to detect ambiguous results of applications#9815garrigue wants to merge 1 commit intoocaml:trunkfrom
Conversation
|
Note that I plan to completely remove the |
lpw25
left a comment
There was a problem hiding this comment.
The improved tests look good. The changes to update_scope and the switch to use Env.has_local_constraints instead of trace_gadt_instances seem fine. A couple of small changes are not clear to me and I've left comments on those.
| match expand_head env ty_expected' with | ||
| {desc = Tarrow(Nolabel,ty_arg,ty_res,_); level = lv} | ||
| let lv = (repr ty_expected').level in | ||
| match expand_head env (correct_levels ty_expected') with |
There was a problem hiding this comment.
The appearance of correct_levels makes me nervous. I tend to think that we should never really need to use it -- the levels should already be correct. Could you add a comment explaining why it is needed here?
There was a problem hiding this comment.
The other name of correct_levels is duplicate_type.
Here this allows to check the expansion of ty_expected' without changing the scopes in the original type.
Otherwise we get spurious ambivalence, even though the type doesn't have an interesting shape. We then expand the real type if we know that it is going to be useful.
Note that all this means that there is a high potential that this PR as a whole introduces spurious ambivalence in other similar places. I should probably find a better way to do it, and review all uses of expand_head.
| | Tconstr (p, tl, _) -> | ||
| let abbrevs = proper_abbrevs p tl !abbreviations in | ||
| begin match find_repr p !abbrevs with | ||
| (*let abbrevs = proper_abbrevs env p tl !abbreviations in*) |
There was a problem hiding this comment.
I'm surprised by the removal of proper_abbrevs here. I assume it is just because copy does not currently take an environment, which proper_abbrev now needs. Morally, I think that copy should take an environment anyway, since it creates a type at the current level, which is closely tied to the environment. So it would probably be better to add an environment parameter to copy.
There was a problem hiding this comment.
@lpw25 I need a better analysis of the code, but this doesn't seem to make a difference.
Actually, I wonder whether the original version was correct or no. This change returns the code to what it was in ocaml 2.04.
@trefs Indeed, at some point copy used the environment, but your scope mechanism removed this need. Since I'm not sure it's really needed here, it seems simpler for now to get rid of some dubious code.
|
Thanks for your comments |
Recently GitHub added the ability to create a "draft" pull request (IIRC it is a drop down option from one of the buttons you press when making a PR). I think it would be good if we used those on PRs that we do not yet think are ready for review. |
I didn't know. I'll do that in the future. |
6a695ce to
92fe56f
Compare
|
I'm going to be annoying, but: while I agree that the change to To be honest, I've never tried to understand why the thing was there in the first place, and how it was better than just checking |
|
The |
|
I should also integrate Leo's comments before asking for more... |
7889b80 to
15e931a
Compare
|
Subsumed by #10277. |
Following the discovery of cases where ambiguity was not correctly detected, this extends
Ctype.update_scopeto update scopes recursively.See
ambivalent_apply.mlfor examples.