-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Introduce TerminatorValue to force handling of divergence #5496
Conversation
@IGI-111 : This PR isn't actually ready for review yet. I just opened it as a draft to trigger the CI checks. Sorry, I should have written it in the PR description. |
Yeah no problem, I understand it's not finished. I try to comment on drafts too so we waste no time in the proper review, but don't feel compelled by it if it's still WIP 😄 |
…iled-values-in-ir-conversion
…iled-values-in-ir-conversion
…o simplified compile_if
I've made a small change to |
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.
LGTM
Is this something we should be looking to fix in the future? Should we create an issue to track this improvement as well? |
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.
Awesome job!! The code is much more cleaner and robust now. Not to mention that the bugs are fixed 😄
Just a few comments worth addressing to avoid terminology clashes and confusions.
I think so. I actually thought there was an issue on it already, but I can't find it. I'll open one up. |
Description
This PR refactors how
Value
is used during IR conversion. The PR introducesTerminatorValue
which forces the converter to handle diverging expressions properly. There were checks for divergence scattered around the code before, but it's now been made more systematic and thus more robust.Additionally, this change allows for early returns from some functions. For instance, if the condition of a
while
diverges, then we don't need to generate code for the body of the loop. In fact, if an expression does diverge then the algorithm assumes that a terminator value (e.g., abranch
or areturn
) is returned, but this was not always the case, and led to a number of spurious checks that probably didn't quite work.The heavy lifting is done by the macro
return_on_termination_or_extract
, which acts as destructor ofTerminatorValue
s.Most changes are straightforward, but do review the functions
compile_lazy_op
,compile_fn_call
,compile_if
,compile_while_loop
,compile_var_decl
andcompile_array_expr
extra carefully, as they contain changes to the conversion algorithm. Mostly the changes are small, but they need an extra pair of eyes. In a few cases the algorithm was and still is a bit convoluted, but that's because the typechecker unhelpfully assignsUnknown
instead ofNever
to diverging expressions, so the first sub-expression needs to be compiled and divergence checked before we can generate IR for anything that relies on the type of the expression.Finally, I have taken the liberty of removing
Value::is_diverging()
and using its aliasValue::is_terminator()
everywhere. The concept of divergence lives in the source language, whereas the concept of terminators lives in the IR, sois_terminator
seems to be more appropriate at this stage of the compilation.Fixes #2051.
Partial fix of #5438 (the call to
deterministically_aborts()
is removed).Checklist
Breaking*
orNew Feature
labels where relevant.