forked from facebook/react
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[compiler][rfc] Hacky retry pipeline for fire (facebook#32164)
Hacky retry pipeline for when transforming `fire(...)` calls encounters validation, todo, or memoization invariant bailouts. Would love feedback on how we implement this to be extensible to other compiler non-memoization features (e.g. inlineJSX) Some observations: - Compiler "front-end" passes (e.g. lower, type, effect, and mutability inferences) should be shared for all compiler features -- memo and otherwise - Many passes (anything dealing with reactive scope ranges, scope blocks / dependencies, and optimizations such as ReactiveIR facebook#31974) can be left out of the retry pipeline. This PR hackily skips memoization features by removing reactive scope creation, but we probably should restructure the pipeline to skip these entirely on a retry - We should maintain a canonical set of "validation flags" Note the newly added fixtures are prefixed with `bailout-...` when the retry fire pipeline is used. These fixture outputs contain correctly inserted `useFire` calls and no memoization.
- Loading branch information
Showing
21 changed files
with
617 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...res/compiler/transform-fire/bailout-retry/bailout-capitalized-fn-call.expect.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
// @validateNoCapitalizedCalls @enableFire | ||
import {fire} from 'react'; | ||
const CapitalizedCall = require('shared-runtime').sum; | ||
|
||
function Component({prop1, bar}) { | ||
const foo = () => { | ||
console.log(prop1); | ||
}; | ||
useEffect(() => { | ||
fire(foo(prop1)); | ||
fire(foo()); | ||
fire(bar()); | ||
}); | ||
|
||
return CapitalizedCall(); | ||
} | ||
|
||
``` | ||
|
||
## Code | ||
|
||
```javascript | ||
import { useFire } from "react/compiler-runtime"; // @validateNoCapitalizedCalls @enableFire | ||
import { fire } from "react"; | ||
const CapitalizedCall = require("shared-runtime").sum; | ||
|
||
function Component(t0) { | ||
const { prop1, bar } = t0; | ||
const foo = () => { | ||
console.log(prop1); | ||
}; | ||
const t1 = useFire(foo); | ||
const t2 = useFire(bar); | ||
|
||
useEffect(() => { | ||
t1(prop1); | ||
t1(); | ||
t2(); | ||
}); | ||
return CapitalizedCall(); | ||
} | ||
|
||
``` | ||
### Eval output | ||
(kind: exception) Fixture not implemented |
16 changes: 16 additions & 0 deletions
16
...c/__tests__/fixtures/compiler/transform-fire/bailout-retry/bailout-capitalized-fn-call.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// @validateNoCapitalizedCalls @enableFire | ||
import {fire} from 'react'; | ||
const CapitalizedCall = require('shared-runtime').sum; | ||
|
||
function Component({prop1, bar}) { | ||
const foo = () => { | ||
console.log(prop1); | ||
}; | ||
useEffect(() => { | ||
fire(foo(prop1)); | ||
fire(foo()); | ||
fire(bar()); | ||
}); | ||
|
||
return CapitalizedCall(); | ||
} |
55 changes: 55 additions & 0 deletions
55
...res/compiler/transform-fire/bailout-retry/bailout-eslint-suppressions.expect.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
// @enableFire | ||
import {useRef} from 'react'; | ||
|
||
function Component({props, bar}) { | ||
const foo = () => { | ||
console.log(props); | ||
}; | ||
useEffect(() => { | ||
fire(foo(props)); | ||
fire(foo()); | ||
fire(bar()); | ||
}); | ||
|
||
const ref = useRef(null); | ||
// eslint-disable-next-line react-hooks/rules-of-hooks | ||
ref.current = 'bad'; | ||
return <button ref={ref} />; | ||
} | ||
|
||
``` | ||
|
||
## Code | ||
|
||
```javascript | ||
import { useFire } from "react/compiler-runtime"; // @enableFire | ||
import { useRef } from "react"; | ||
|
||
function Component(t0) { | ||
const { props, bar } = t0; | ||
const foo = () => { | ||
console.log(props); | ||
}; | ||
const t1 = useFire(foo); | ||
const t2 = useFire(bar); | ||
|
||
useEffect(() => { | ||
t1(props); | ||
t1(); | ||
t2(); | ||
}); | ||
|
||
const ref = useRef(null); | ||
|
||
ref.current = "bad"; | ||
return <button ref={ref} />; | ||
} | ||
|
||
``` | ||
### Eval output | ||
(kind: exception) Fixture not implemented |
18 changes: 18 additions & 0 deletions
18
...c/__tests__/fixtures/compiler/transform-fire/bailout-retry/bailout-eslint-suppressions.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// @enableFire | ||
import {useRef} from 'react'; | ||
|
||
function Component({props, bar}) { | ||
const foo = () => { | ||
console.log(props); | ||
}; | ||
useEffect(() => { | ||
fire(foo(props)); | ||
fire(foo()); | ||
fire(bar()); | ||
}); | ||
|
||
const ref = useRef(null); | ||
// eslint-disable-next-line react-hooks/rules-of-hooks | ||
ref.current = 'bad'; | ||
return <button ref={ref} />; | ||
} |
Oops, something went wrong.