mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[hir] Validate globals are equal before propagating
Make sure the value of the globals in phi operands are the same before constant propagating them.
This commit is contained in:
+13
@@ -206,6 +206,19 @@ function evaluatePhi(phi: Phi, constants: Constants): Constant | null {
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "LoadGlobal": {
|
||||
CompilerError.invariant(value.kind === "LoadGlobal", {
|
||||
reason: "value kind expected to be LoadGlobal",
|
||||
loc: null,
|
||||
suggestions: null,
|
||||
});
|
||||
|
||||
// different global values, can't constant propogate
|
||||
if (operandValue.name !== value.name) {
|
||||
return null;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
function Test() {
|
||||
const { tab } = useFoo();
|
||||
const currentTab = tab === WAT ? WAT : WAT;
|
||||
|
||||
return <Foo value={currentTab} />;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
## Code
|
||||
|
||||
```javascript
|
||||
import { unstable_useMemoCache as useMemoCache } from "react";
|
||||
function Test() {
|
||||
const $ = useMemoCache(1);
|
||||
const { tab } = useFoo();
|
||||
tab === WAT ? WAT : WAT;
|
||||
let t0;
|
||||
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
||||
t0 = <Foo value={WAT} />;
|
||||
$[0] = t0;
|
||||
} else {
|
||||
t0 = $[0];
|
||||
}
|
||||
return t0;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
function Test() {
|
||||
const { tab } = useFoo();
|
||||
const currentTab = tab === WAT ? WAT : WAT;
|
||||
|
||||
return <Foo value={currentTab} />;
|
||||
}
|
||||
Reference in New Issue
Block a user