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
Desugar pattern guards *after* type checking #2801
Conversation
(Ah I discovered binding groups are a part of |
I have discovered another issue. For a test I wrote:
This gets correctly translated to:
Now the codegen, still correct:
It rightfully spots the very small function
It still applies |
@alexbiehl are you able to verify that the issue is in the optimizer? You could turn the optimizer off and see if the generated code is correct. |
Using -- | Apply a series of optimizer passes to simplified JavaScript code
optimize :: MonadSupply m => AST -> m AST
optimize js = pure js I get "use strict";
var f = function (x) {
return (function () {
var v = (function () {
var $1 = x;
var x1 = $1;
if (true) {
return 1234;
};
throw new Error("Failed pattern match at X line 3, column 1 - line 5, column 12: " + [ $1.constructor.name ]);
})();
return (function () {
var $2 = x;
var x1 = $2;
return (function () {
var $3 = x1;
if ($3 === 1) {
return x1;
};
return v(true);
throw new Error("Failed pattern match at X line 3, column 1 - line 5, column 12: " + [ $3.constructor.name ]);
})();
throw new Error("Failed pattern match at X line 3, column 1 - line 5, column 12: " + [ $2.constructor.name ]);
})();
})();
}; This looks correct. Variable |
Ah! No, we can see |
Is it possible to run your pass between the exhaustivity and type checking passes? Would that help? |
433b99b
to
bdc59dc
Compare
ValueDeclaration rem_case_id Private [NullBinder] | ||
[MkUnguarded desugared] | ||
ValueDeclaration rem_case_id Private [] | ||
[MkUnguarded (Abs (VarBinder unused_binder) desugared)] |
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 was the culprit. After desugaring we need to generate code which obeys the invariants of desugared code..
@paf31 Please take a look; I think this is ready for review now. Test suite succeeds locally. |
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.
Looks great, thanks very much!
@paf31
This is a fix for #2795
It's not working properly currently:
I am using
everywhereOnValuesM
traversal to traverse the list ofDeclaration
s. It seems to miss the expressions in there. Please take a look atdesugarCaseGuards
for a hint. Any pointer on how to fix this?