-
Notifications
You must be signed in to change notification settings - Fork 375
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
[ fix ] Fix issue with eager evaluation of crashing functions (fixes #3003) #3004
Conversation
I'm perfectly fine with this fix, mainly because the issue at hand can be very confusing for newcomers especially so once #3002 gets merged. Thanks for looking into this! |
Thanks for doing this, I have some comments, in no particular order: I think this should also check for the import System
partial
unreachable : a
unreachable = idris_crash "unreachable"
main : IO Int
main = do
exitSuccess
assert_total unreachable This currently crashes with Edit: Stefan Höck pointed out the following isn't an issue foo, bah : Int
foo = ?hole
bah = foo Depending on the order in which |
The optimizer generating toplevel constants already runs |
Yeah, I'm relying on the fact that the code is visiting the functions from the leaves up. I've added a check for calls to unsafe primitives. I thought to initialize Note that this still doesn't see an |
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.
I don't think this will catch all cases, because those functions should already have been inlined and replaced with the appropriate NmOp
. I suggest adding a check for NmOp _ Crash _
in the same way as you currently check for NmCrash
.
Both approaches handle your test case, but I think your proposal will be more robust. And it turns out that |
Issue #3003 observes that the eager evaluation of zero-argument functions can cause crashes at startup. PR #3002 triggers this issue by erasing void and unit parameters. It is particularly evident when incremental compilation is on, because inlined or unused functions are still emitted during codegen.
This PR addresses the issue by removing from the list of "constant" functions any functions that are defined to be
NmCrash _ _
or that call such a function. So constants that crash or that call crashing functions will lazy after this change.The two test cases come from #3003, and I've also checked that it unblocks #3002. Per a comment on #3003, I think Stefan Hoeck has some reservations over whether this needs to be fixed, so this change may need further discussion before merging.