-
Notifications
You must be signed in to change notification settings - Fork 20
Fix: Check non-exhaustible conditional returns using a goto mechanism
#75
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -597,6 +597,18 @@ fn compile_lines( | |
| location: *location, | ||
| }); | ||
| } | ||
| SimpleLine::Goto { label } => { | ||
| let goto_label = Label::Custom(label.clone()); | ||
| instructions.push(IntermediateInstruction::Jump { | ||
| dest: IntermediateValue::label(goto_label.clone()), | ||
| updated_fp: None, | ||
| }); | ||
|
|
||
| let remaining = | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After a GOTO intuitively there should not remain any lines to compile? So we could simply assert
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think one cannot assert that |
||
| compile_lines(&lines[i + 1..], compiler, final_jump, declared_vars)?; | ||
| compiler.bytecode.insert(goto_label, remaining); | ||
| return Ok(instructions); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -795,7 +807,8 @@ fn find_internal_vars(lines: &[SimpleLine]) -> BTreeSet<Var> { | |
| | SimpleLine::Print { .. } | ||
| | SimpleLine::FunctionRet { .. } | ||
| | SimpleLine::Precompile { .. } | ||
| | SimpleLine::LocationReport { .. } => {} | ||
| | SimpleLine::LocationReport { .. } | ||
| | SimpleLine::Goto { .. } => {} | ||
| } | ||
| } | ||
| internal_vars | ||
|
|
||
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 idea of "epilogue_label" looks promising. Currently you always put an epilogue_label when inlining but in some cases, when there is no instructions after the RETURN this is unnecessary (we can call such RETURNs "final"). But detecting it is not trivial. We would somehow need to peek at the following of the code (what comes after the RETURN), to see if it's terminal or not, if that makes sense
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 agree, you don't need to always put the label. But yeah finding where you don't need to is quite difficult. We'll need to have some context of what is final in the remainder of the scope.