Add tests to serve as some documentation for PostInferenceChecks#15416
Add tests to serve as some documentation for PostInferenceChecks#15416vzarytovskii merged 16 commits intodotnet:mainfrom
Conversation
|
Is it generally acceptable to put an internal function into the corresponding FSI file so that it can be unit tested? In this case, |
I would say go ahead, the test projects are IVT'd, incl. FSharp.Compiler.UnitTests. |
|
(didn't mean to close this PR, was an accidental mispress. I am sorry) |
Yes, this is fine, go ahead. |
|
I am not remotely convinced that my understanding of |
|
(I still intend testing these functions now I've exposed them, by the way.) |
|
So it turned out that one of my claimed properties is not true (" |
|
I've chosen not to use FsCheck here, since it was very easy to stamp out a rough approximation of it, but if you prefer I can pull it in so we get e.g. better distributions over the generated integers. |
|
Sorry about that, things have been busy - let me merge in |
|
As of this commit, I intend to have removed all the changes in behaviour again; I propose merging the tests and just leaving it at that. It took me a nontrivial amount of time to convince myself of the properties that I assert here with tests, so I think this is a small improvement over |
Below the line is what I thought beforehand, but I'm pretty sure it's false. So I've simply reverted all the actual changes in behaviour and left the tests, in the hope that Those Who Come After will be better able to see what properties these functions have and can save a bit of time working it out.
There was no need for this to be in continuation-passing style, and the stack traces look a lot nicer this way - much less pollution.
Handwavy proof of correctness:
There is only one caller of
CheckExprLinearother thanCheckExprLinearitself, and that caller passesidas the continuation.The call on line 1004 supplies
NoLimitas the base case of the recursion; I have extracted this out to the ultimate non-recursive caller ofCheckExprLinear.The only other call to
CheckExprLinearwhich manipulates its result is the one on line 1011. That callsCombineLimits [lim1; result].CombineLimitsis defined as follows:CombineTwoLimitscan be observed to be commutative and associative (as verified by property-based test), which simplifies the analysis because we don't have to care about the order of the recursion changing.