-
Notifications
You must be signed in to change notification settings - Fork 47.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
compiler: Known hooks/nonescaping scopes dont count as pruned
There are two cases where it's legit/intended to remove scopes, and we can inline the scope rather than reify a "pruned" scope: * Scopes that contain a single instruction with a hook call. The fact that we create a scope in this case at all is just an artifact of it being simpler to do this and remove the scope later rather than try to avoid creating it in the first place. So for these scopes, we can just inline them. * Scopes that are provably non-escaping. Removing the scope is an optimization, not a case of us having to prune away something that should be there. So again, its fine to inline in this case. I found this from syncing the stack internally and looking at differences in compiled output. The latter case was most common but the first case is just an obvious improvement. ghstack-source-id: 75559d25ab3d3af6a330d91e69e4331006aa97c3 Pull Request resolved: #29820
- Loading branch information
1 parent
4fa8fa7
commit eed8c08
Showing
5 changed files
with
75 additions
and
11 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
46 changes: 46 additions & 0 deletions
46
...ler/nonreactive-noescaping-dependency-can-inline-into-consuming-scope.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,46 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
// @flow | ||
function Component() { | ||
return ( | ||
<div | ||
className={stylex( | ||
// this value is a) in its own scope, b) non-reactive, and c) non-escaping | ||
// its scope gets pruned bc it's non-escaping, but this doesn't mean we need to | ||
// create a temporary for it | ||
flags.feature("feature-name") ? styles.featureNameStyle : null | ||
)} | ||
></div> | ||
); | ||
} | ||
|
||
``` | ||
|
||
## Code | ||
|
||
```javascript | ||
import { c as _c } from "react/compiler-runtime"; | ||
function Component() { | ||
const $ = _c(1); | ||
let t0; | ||
if ($[0] === Symbol.for("react.memo_cache_sentinel")) { | ||
t0 = ( | ||
<div | ||
className={stylex( | ||
flags.feature("feature-name") ? styles.featureNameStyle : null, | ||
)} | ||
/> | ||
); | ||
$[0] = t0; | ||
} else { | ||
t0 = $[0]; | ||
} | ||
return t0; | ||
} | ||
|
||
``` | ||
### Eval output | ||
(kind: exception) Fixture not implemented |
13 changes: 13 additions & 0 deletions
13
...__/fixtures/compiler/nonreactive-noescaping-dependency-can-inline-into-consuming-scope.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,13 @@ | ||
// @flow | ||
function Component() { | ||
return ( | ||
<div | ||
className={stylex( | ||
// this value is a) in its own scope, b) non-reactive, and c) non-escaping | ||
// its scope gets pruned bc it's non-escaping, but this doesn't mean we need to | ||
// create a temporary for it | ||
flags.feature("feature-name") ? styles.featureNameStyle : null | ||
)} | ||
></div> | ||
); | ||
} |
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