This repository has been archived by the owner on Aug 31, 2023. It is now read-only.
feat(rome_control_flow): introduce explicit exception control flow #2821
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR replaces the (temporary) initial implementation of try-catch-finally statements in the control flow analysis (based on the concept of multiple entry points) with a more complete modelling solution for the exception control flow. The
BasicBlock
struct that make up the control flow graph now also contain a list of "exception handlers" and "cleanup handlers": these handlers point to a set of blocks to be executed in order when an exception is thrown (either with an explicit throw instruction or as a possible side-effect of a statement) or when the function returns respectively.For JavaScript, the exceptions handlers of a block are all the
finally
clauses found going upward in the syntax tree until acatch
clause is found (the block corresponding to this clause is the last handler in the list), while the cleanup handlers are made of all thefinally
clauses going up to the root level of the function (and ignoring all catch clauses)The last change I've made is introducing a new
finally_fallthrough
flag onJump
instructions. This flag is used specifically to mark the implicit jump instruction inserted by the control flow generator at the end of afinally
block towards the next statement: when the finally clause gets executed as an exception or cleanup handler instead of going through the normal control flow the target block of this jump gets modified to the next handler in the chain if it exists, or as a return instruction otherwise.Test Plan
I've added additional test cases for
JsTryStatement
andJsTryFinallyStatement
under the snapshots for thenoDeadCode
rule