-
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
typing: fix a try_expand_once forgotten from #10170 #12974
Conversation
Accepting the code in your test without |
Hmmm. I agree, and I wonder why I didn't notice this earlier -- I guess I had convinced myself that the test somehow used a feature that allows equi-recursive types. This suggests that something is slightly wrong with #12691 that we want to fix before the 5.2 release. I think that this also strengthens my point that this one-line PR is good to have, if only to then backport it to older versions. What do you think? |
Sorry to forgot to mention it before, but #12691 is not enough to replicate the bug in isolation. |
Sorry for being unclear. I propose to include in 4.14 a fix for the uncaught |
Hard disagree: that would be backporting a bug to 4.14 to erase a bad error message. |
I'm confused. If I apply my change to 4.14, the repro case behavior changes from
to
Are you saying that the latter output is buggy? (The error message looks a bit odd, but who doesn't?) |
For reference, the behavior of the testcase on 4.12 and older (the bug was introduced in 4.13) is as follows:
|
Ah, I was mislead by your test case and missed the fact that the change resulted in a error message on 4.14. Sorry! However, the wording of the error message might hint to a deeper problem with error trace, and I would still prefer to understand and fix the issue on 5.2 before backporting to 4.14. |
I disagree with your analysis (the bug has been around since 4.13, so I don't understand why figuring out what went wrong with an independent change in 5.2 should be taken as a prerequisite to fixing it), but I will wait to see you in-person to discuss this further. |
After an in-person discussion, Florian remains unconvinced that this is the right first move. (I remain convinced.) I am closing for now, I guess he volunteered to look at this himself. |
let to_seq (xt : 'a t) : 'a Seq.t = | ||
let T x = xt in | ||
Seq.cons Seq.empty x | ||
|
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.
Alternative test which leads to the same error on 5.2:
let strange x = Seq.[cons x empty; cons empty x]
After reminding me of the context, I think that this is a correct partial fix. In particular, the " This PR doesn't solve the general bug described in #10170 (that it is possible to escape from the scrutiny of |
Would you like to see further changes to the PR (besides writing a Changes entry) before approving? (Should I replace the test with your alternative proposal? Or maybe include both?) |
The current state is fine now that I agree that the state after this PR is clearer. |
652b0dd
to
09b27f3
Compare
I added a Changes entry, a second test as you suggested, and wrote a comment in the first test explaining that the current output is not correct. |
Sorry I forgot to mention it, but there is already a test for recursive occurrence in |
Ok. I initially did not use an |
The behavior of your testcase on let strange x = Seq.[cons x empty; cons empty x];;
[%%expect{|
Uncaught exception: Ctype.Escape(_)
|}, Principal{|
val strange : 'a Seq.t Seq.t -> 'a Seq.t Seq.t Seq.t list = <fun>
|}];; |
Reported-by: Neven Villani <vanille@crans.org>
09b27f3
to
2d7053b
Compare
@Octachron I have rebased the PR with the test as you suggested. The first commit adds the test on trunk (no type-checker change), so we can see the before-PR beahvior; the second commit has the fix and updates the testsuite. |
Uncaught exception: Ctype.Escape(_) | ||
|
||
|}, Principal{| | ||
val strange : 'a Seq.t Seq.t -> 'a Seq.t Seq.t Seq.t list = <fun> |
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.
Self-comment: this unsound part is somehow dependent on the previous test, the compiler does not give this unsound type to strange
by itself.
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 makes me strictly less confident in except
tests for this kind of bugs, but oh well.)
Cherry-picked to 4.14, 5.2, and changes entry duplicated to the 5.2 section. |
(In #10170, almost all callsites of
try_expand_once
were replaced by calls totry_expand_safe
which catches theEscape
exception and returnsNone
instead, except a few places that were already catchingEscape
... and the one occurrence in the diff here, which should also have been replaced.)On OCaml versions 5.1 and older, this glitch causes a
Ctype.Escape(_)
uncaught exception on the included test case. See #12971.With the fix in the present PR (which applies cleanly to 4.14, trunk and everything in between), the included test case results in a proper error on OCaml 5.1 and older.
In OCaml 5.2 and trunk, the included test case does not raise an uncaught exception, and it does not fail with an error instead, the program is accepted with a (recursive) type. This is due to #12691 (included in 5.2), which improved the definition of some expansion functions to not raise
Escape
and do something more sensible instead. (Edit: not more sensible, it was in fact a regression, see discussion below.)The summary of my understanding of the issue:
expand_abbrev_gen
#12691 is even better than the one-line fix (Edit: wrong). But backporting it to older versions (as @Octachron suggested) would be sensibly more work -- I would not take the initiative to do it.I therefore propose to merge the present PR in trunk, and backport it in 4.14 for now.