-
Notifications
You must be signed in to change notification settings - Fork 46.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update base for Update on "[compiler] Optimize emission in normal (no…
…n-value) blocks" In #29863 I tried to find a clean way to share code for emitting instructions between value blocks and regular blocks. The catch is that value blocks have special meaning for their final instruction — that's the value of the block — so reordering can't change the last instruction. However, in finding a clean way to share code for these two categories of code, i also inadvertently reduced the effectiveness of the optimization. This PR updates to use different strategies for these two kinds of blocks: value blocks use the code from #29863 where we first emit all non-reorderable instructions in their original order, _then_ try to emit reorderable values. The reason this is suboptimal, though, is that we want to move instructions closer to their dependencies so that they can invalidate (merge) together. Emitting the reorderable values last prevents this. So for normal blocks, we now emit terminal operands first. This will invariably cause _some_ of the non-reorderable instructions to be emitted, but it will intersperse reoderable instructions in between, right after their dependencies. This maximizes our ability to merge scopes. I think the complexity cost of two strategies is worth the benefit, though i still need to double-check all the output changes. [ghstack-poisoned]
- Loading branch information
Showing
31 changed files
with
635 additions
and
246 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
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
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
100 changes: 100 additions & 0 deletions
100
.../__tests__/fixtures/compiler/meta-isms/repro-cx-assigned-to-temporary.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,100 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
// @compilationMode(infer) @enableAssumeHooksFollowRulesOfReact:false @customMacros(cx) | ||
import { identity } from "shared-runtime"; | ||
|
||
const DARK = "dark"; | ||
|
||
function Component() { | ||
const theme = useTheme(); | ||
return ( | ||
<div | ||
className={cx({ | ||
"styles/light": true, | ||
"styles/dark": theme.getTheme() === DARK, | ||
})} | ||
/> | ||
); | ||
} | ||
|
||
function cx(obj) { | ||
const classes = []; | ||
for (const [key, value] of Object.entries(obj)) { | ||
if (value) { | ||
classes.push(key); | ||
} | ||
} | ||
return classes.join(" "); | ||
} | ||
|
||
function useTheme() { | ||
return { | ||
getTheme() { | ||
return DARK; | ||
}, | ||
}; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [{}], | ||
}; | ||
|
||
``` | ||
|
||
## Code | ||
|
||
```javascript | ||
import { c as _c } from "react/compiler-runtime"; // @compilationMode(infer) @enableAssumeHooksFollowRulesOfReact:false @customMacros(cx) | ||
import { identity } from "shared-runtime"; | ||
|
||
const DARK = "dark"; | ||
|
||
function Component() { | ||
const $ = _c(2); | ||
const theme = useTheme(); | ||
|
||
const t0 = cx({ | ||
"styles/light": true, | ||
"styles/dark": theme.getTheme() === DARK, | ||
}); | ||
let t1; | ||
if ($[0] !== t0) { | ||
t1 = <div className={t0} />; | ||
$[0] = t0; | ||
$[1] = t1; | ||
} else { | ||
t1 = $[1]; | ||
} | ||
return t1; | ||
} | ||
|
||
function cx(obj) { | ||
const classes = []; | ||
for (const [key, value] of Object.entries(obj)) { | ||
if (value) { | ||
classes.push(key); | ||
} | ||
} | ||
return classes.join(" "); | ||
} | ||
|
||
function useTheme() { | ||
return { | ||
getTheme() { | ||
return DARK; | ||
}, | ||
}; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [{}], | ||
}; | ||
|
||
``` | ||
### Eval output | ||
(kind: ok) <div class="styles/light styles/dark"></div> |
Oops, something went wrong.