This repository has been archived by the owner on Feb 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 421
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix havoced binding not in optimized function (#2420)
Summary: Fixes #2419 and #2386. I ran into this issue while testing an internal React Native bundle. This invariant assumes that all property bindings emitted in a pure scope are also in an optimized function. This is not true for `__evaluatePureFunction` which the React Compiler wraps around initialization code so that globals outside of the closure are not havoced. Pull Request resolved: #2420 Differential Revision: D9363247 Pulled By: calebmer fbshipit-source-id: 4f1634165b6fe15f95b5b7332432fccacc596821
- Loading branch information
1 parent
c18bd7e
commit 3eb1e8e
Showing
3 changed files
with
46 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
if (!global.__evaluatePureFunction) global.__evaluatePureFunction = f => f(); | ||
|
||
const havoc = global.__abstract ? global.__abstract("function", "(() => {})") : () => {}; | ||
|
||
const result = global.__evaluatePureFunction(() => { | ||
let x = 23; | ||
function incrementX() { | ||
x = x + 42; | ||
} | ||
if (global.__optimize) __optimize(incrementX); | ||
havoc(incrementX); | ||
return x; | ||
}); | ||
|
||
global.inspect = () => result; |
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,14 @@ | ||
if (!global.__evaluatePureFunction) global.__evaluatePureFunction = f => f(); | ||
|
||
const x = global.__evaluatePureFunction(() => { | ||
const x = { p: 42 }; | ||
|
||
const havoc = global.__abstract ? __abstract("function", "(() => {})") : () => {}; | ||
havoc(() => x); | ||
|
||
return x; | ||
}); | ||
|
||
global.inspect = () => { | ||
return JSON.stringify(x); | ||
}; |