Save and restore univar_pairs instead of clobbering#12920
Conversation
gasche
left a comment
There was a problem hiding this comment.
I believe that the fix is correct. I would rather move towards less global variables than this glorified dynamic binding, but I don't know how to do it in a sustainable way, so I think that for the time being your approach is better than the current state.
98667f7 to
843222e
Compare
|
Apologies for forgetting about this. Merged. |
|
@gasche , my opinion is that the bug fix is subtle enough that it is better to test it in the 5.3 cycle and to not cherry-pick it to 5.2 . Do you agree? |
|
This is a bug that has been there for a while and there is no known urgency. If you believe that it would be costly if it introduced regressions in 5.2 at this stage (I don't realize where things are), it is perfectly fine to delay to 5.3. |
|
For reference, there is now a bug report of actual code in the wild that triggers (2): #13495 |
#12910 demonstrates a soundness issue caused by several functions in
ctype.ml(e.g.Ctype.equal) incorrectly clobberingunivar_pairs. This patch has two changes to resolve this problem:univar_pairsis now temporarily changed and restored afterwards, so e.g. univars remain available across a use of aCtype.equalunify_univars, if a univar is found that is missing fromunivar_pairs, the compiler issues aMisc.fatal_errorPreviously, the clobbering of
univar_pairscausedmcompto incorrectly report that two identical types were incompatible, since univar_pairs was overwritten, andunify_univarsreported this situation as "not unifiable".Change (1) above is sufficient to fix the cases found by @yallop, as
univar_pairsis no longer clobbered. Change (2) alone turns the soundness issue into a compiler failure, which is less bad. I propose doing both, since I'm not completely convinced that it's correct to resetunivar_pairsto the empty list in all the places the compiler does so (even temporarily), and aMisc.fatal_erroris better than a silent soundness bug.