dillon1000/react

Commit

While terminal and codegen

Adds a new 'while' terminal variant, which will be a model for other loop 
terminals, and adds support for the entire compilation pipeline through codegen. 
To understand the structure of the terminal consider this input: 

```javascript 

let x = 0; 

while (x) { 

x = foo(x); 

} 

return x; 

``` 

We currently lower this to ifs and gotos: 

``` 

bb0: precursor to loop 

let x = 0; 

goto(break) bb1; // <-- **The new terminal replaces this** 

bb1: test block, whether to (re-)enter the loop 

if (x) consequent=bb2 alternate=bb3; 

bb2: loop body 

x = foo(x); 

goto(continue) bb1; 

bb3: fallthrough after the loop 

return x 

``` 

This representation correctly models the semantics of while statements, but 
loses the high-level information that there was a loop. The new 'while' terminal 
replaces the first 'goto(break) bb1'. Conceptually, the 'while' terminal means 
"enter the starting point of a while loop". In this example the terminal would 
look like this: 

``` 

{ 

kind: 'while', 

testBlock: 'bb1', // the basic block that checks whether to enter the loop or 
not 

loop: 'bb2', // the block containing the loop body 

fallthrough: 'bb3' // the block that goes after the loop 

} 

``` 

Most passes will only look at 'testBlock', ie they will treat this terminal as a 
simple goto:testBlock. However, codegen uses the full information in the 
terminal to reconstruct the loop. My previous PR, #755, added a mechanism to be 
smart about when to emit or not emit `break` statements; this PR improves upon 
that to accurately emit the minimal break and continue statements: ie omitting 
entirely where they are extraneous, emitting unlabeled break/continue when 
sufficient, and falling back to labeled break/continue only where strictly 
necessary. The logic is very much analogous to IR construction.
Browse files
Changed paths21 files
First-parent comparison
M compiler/forget/src/HIR/BuildHIR.ts ModifiedM compiler/forget/src/HIR/Codegen.ts ModifiedM compiler/forget/src/HIR/HIR.ts ModifiedM compiler/forget/src/HIR/HIRBuilder.ts ModifiedM compiler/forget/src/HIR/PrintHIR.ts ModifiedM compiler/forget/src/HIR/visitors.ts ModifiedA compiler/forget/src/__tests__/fixtures/hir/complex-while.expect.md AddedA compiler/forget/src/__tests__/fixtures/hir/complex-while.js AddedM compiler/forget/src/__tests__/fixtures/hir/component.expect.md ModifiedM compiler/forget/src/__tests__/fixtures/hir/mutable-lifetime-loops.expect.md ModifiedM compiler/forget/src/__tests__/fixtures/hir/mutable-liverange-loop.expect.md ModifiedM compiler/forget/src/__tests__/fixtures/hir/ssa-for-of.expect.md ModifiedM compiler/forget/src/__tests__/fixtures/hir/ssa-for.expect.md ModifiedM compiler/forget/src/__tests__/fixtures/hir/ssa-nested-loops-no-reassign.expect.md ModifiedM compiler/forget/src/__tests__/fixtures/hir/ssa-nested-loops-no-reassign.js ModifiedM compiler/forget/src/__tests__/fixtures/hir/ssa-while-no-reassign.expect.md ModifiedM compiler/forget/src/__tests__/fixtures/hir/ssa-while.expect.md ModifiedA compiler/forget/src/__tests__/fixtures/hir/while-conditional-continue.expect.md AddedA compiler/forget/src/__tests__/fixtures/hir/while-conditional-continue.js AddedM compiler/forget/src/__tests__/hir-test.ts ModifiedM compiler/forget/src/__tests__/test-utils/generateTestsFromFixtures.ts Modified
Patch

Files changed

Rendering syntax-highlighted changes…