Skip to content

Commit

Permalink
[compiler] Handle earlier creation of early return on scopes
Browse files Browse the repository at this point in the history
I'm experimenting with a new pass that sometimes creates scopes with early returns earlier in the pipeline, but there are a few passes that assume that can't happen. This PR is updating those passes just to be more resilient to help unblock experimentation.

ghstack-source-id: a9e348181ddad1a1e936ef023b5d5ee44aaf3d8c
Pull Request resolved: #30333
  • Loading branch information
josephsavona committed Jul 15, 2024
1 parent 8b08e99 commit cf133ba
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import { EARLY_RETURN_SENTINEL } from "./CodegenReactiveFunction";
import { ReactiveFunctionTransform, Transformed } from "./visitors";

/**
* TODO: Actualy propagate early return information, for now we throw a Todo bailout.
*
* This pass ensures that reactive blocks honor the control flow behavior of the
* original code including early return semantics. Specifically, if a reactive
* scope early returned during the previous execution and the inputs to that block
Expand Down Expand Up @@ -135,6 +133,14 @@ class Transform extends ReactiveFunctionTransform<State> {
scopeBlock: ReactiveScopeBlock,
parentState: State
): void {
/**
* Exit early if an earlier pass has already created an early return,
* which may happen in alternate compiler configurations.
*/
if (scopeBlock.scope.earlyReturnValue !== null) {
return;
}

const innerState: State = {
withinReactiveScope: true,
earlyReturnValue: parentState.earlyReturnValue,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -932,10 +932,14 @@ class PruneScopesTransform extends ReactiveFunctionTransform<
* is early-returned from within the scope. For now we intentionaly keep
* these scopes, and let them get pruned later by PruneUnusedScopes
* _after_ handling the early-return case in PropagateEarlyReturns.
*
* Also keep the scope if an early return was created by some earlier pass,
* which may happen in alternate compiler configurations.
*/
if (
scopeBlock.scope.declarations.size === 0 &&
scopeBlock.scope.reassignments.size === 0
(scopeBlock.scope.declarations.size === 0 &&
scopeBlock.scope.reassignments.size === 0) ||
scopeBlock.scope.earlyReturnValue !== null
) {
return { kind: "keep" };
}
Expand Down

0 comments on commit cf133ba

Please sign in to comment.