Skip to content

Commit 7bb9ba2

Browse files
committed
Update base for Update on "compiler: super early exploration of instruction reordering"
See comments in InstructionReordering.ts. This needs substantial iteration before landing in some form, just putting up to share for discussion. [ghstack-poisoned]
2 parents a14945c + c4b433f commit 7bb9ba2

File tree

166 files changed

+6294
-1606
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

166 files changed

+6294
-1606
lines changed

.circleci/config.yml

+10
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,10 @@ workflows:
507507
- "-r=www-modern --env=production --variant=false"
508508
- "-r=www-modern --env=development --variant=true"
509509
- "-r=www-modern --env=production --variant=true"
510+
- "-r=xplat --env=development --variant=false"
511+
- "-r=xplat --env=development --variant=true"
512+
- "-r=xplat --env=production --variant=false"
513+
- "-r=xplat --env=production --variant=true"
510514

511515
# TODO: Test more persistent configurations?
512516
- '-r=stable --env=development --persistent'
@@ -552,6 +556,12 @@ workflows:
552556
# - "-r=www-modern --env=development --variant=true"
553557
# - "-r=www-modern --env=production --variant=true"
554558

559+
# TODO: Update test config to support xplat build tests
560+
# - "-r=xplat --env=development --variant=false"
561+
# - "-r=xplat --env=development --variant=true"
562+
# - "-r=xplat --env=production --variant=false"
563+
# - "-r=xplat --env=production --variant=true"
564+
555565
# TODO: Test more persistent configurations?
556566
- download_base_build_for_sizebot:
557567
filters:

.eslintrc.js

+1
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@ module.exports = {
486486
$ReadOnlyArray: 'readonly',
487487
$ArrayBufferView: 'readonly',
488488
$Shape: 'readonly',
489+
CallSite: 'readonly',
489490
ConsoleTask: 'readonly', // TOOD: Figure out what the official name of this will be.
490491
ReturnType: 'readonly',
491492
AnimationFrameID: 'readonly',

.github/ISSUE_TEMPLATE/config.yml

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
blank_issues_enabled: false
12
contact_links:
23
- name: 📃 Documentation Issue
34
url: https://github.com/reactjs/react.dev/issues/new/choose

.github/workflows/commit_artifacts.yml

+128-8
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,36 @@ jobs:
1010
outputs:
1111
www_branch_count: ${{ steps.check_branches.outputs.www_branch_count }}
1212
fbsource_branch_count: ${{ steps.check_branches.outputs.fbsource_branch_count }}
13+
last_version_classic: ${{ steps.get_last_version_www.outputs.last_version_classic }}
14+
last_version_modern: ${{ steps.get_last_version_www.outputs.last_version_modern }}
15+
last_version_rn: ${{ steps.get_last_version_rn.outputs.last_version_rn }}
16+
current_version_classic: ${{ steps.get_current_version.outputs.current_version_classic }}
17+
current_version_modern: ${{ steps.get_current_version.outputs.current_version_modern }}
18+
current_version_rn: ${{ steps.get_current_version.outputs.current_version_rn }}
1319
steps:
20+
- uses: actions/checkout@v4
21+
with:
22+
ref: builds/facebook-www
23+
- name: "Get last version string for www"
24+
id: get_last_version_www
25+
run: |
26+
# Empty checks only needed for backwards compatibility,can remove later.
27+
VERSION_CLASSIC=$( [ -f ./compiled/facebook-www/VERSION_CLASSIC ] && cat ./compiled/facebook-www/VERSION_CLASSIC || echo '' )
28+
VERSION_MODERN=$( [ -f ./compiled/facebook-www/VERSION_MODERN ] && cat ./compiled/facebook-www/VERSION_MODERN || echo '' )
29+
echo "Last classic version is $VERSION_CLASSIC"
30+
echo "Last modern version is $VERSION_MODERN"
31+
echo "last_version_classic=$VERSION_CLASSIC" >> "$GITHUB_OUTPUT"
32+
echo "last_version_modern=$VERSION_MODERN" >> "$GITHUB_OUTPUT"
33+
- uses: actions/checkout@v4
34+
with:
35+
ref: builds/facebook-fbsource
36+
- name: "Get last version string for rn"
37+
id: get_last_version_rn
38+
run: |
39+
# Empty checks only needed for backwards compatibility,can remove later.
40+
VERSION_NATIVE_FB=$( [ -f ./compiled-rn/VERSION_NATIVE_FB ] && cat ./compiled-rn/VERSION_NATIVE_FB || echo '' )
41+
echo "Last rn version is $VERSION_NATIVE_FB"
42+
echo "last_version_rn=$VERSION_NATIVE_FB" >> "$GITHUB_OUTPUT"
1443
- uses: actions/checkout@v4
1544
- name: "Check branches"
1645
id: check_branches
@@ -147,7 +176,7 @@ jobs:
147176
mkdir -p ${BASE_FOLDER}/react-native-github/Libraries/Renderer/
148177
mkdir -p ${BASE_FOLDER}/RKJSModules/vendor/react/{scheduler,react,react-is,react-test-renderer}/
149178
150-
# Move React Native renderer
179+
# Move React Native renderer
151180
mv build/react-native/implementations/ $BASE_FOLDER/react-native-github/Libraries/Renderer/
152181
mv build/react-native/shims/ $BASE_FOLDER/react-native-github/Libraries/Renderer/
153182
mv build/facebook-react-native/scheduler/cjs/ $BASE_FOLDER/RKJSModules/vendor/react/scheduler/
@@ -160,11 +189,27 @@ jobs:
160189
rm $RENDERER_FOLDER/ReactFabric-{dev,prod,profiling}.js
161190
rm $RENDERER_FOLDER/ReactNativeRenderer-{dev,prod,profiling}.js
162191
163-
ls -R ./compiled
164-
- name: Add REVISION file
192+
# Move React Native version file
193+
mv build/facebook-react-native/VERSION_NATIVE_FB ./compiled-rn/VERSION_NATIVE_FB
194+
195+
ls -R ./compiled-rn
196+
- name: Add REVISION files
165197
run: |
166198
echo ${{ github.sha }} >> ./compiled/facebook-www/REVISION
199+
cp ./compiled/facebook-www/REVISION ./compiled/facebook-www/REVISION_TRANSFORMS
167200
echo ${{ github.sha }} >> ./compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/REVISION
201+
- name: "Get current version string"
202+
id: get_current_version
203+
run: |
204+
VERSION_CLASSIC=$(cat ./compiled/facebook-www/VERSION_CLASSIC)
205+
VERSION_MODERN=$(cat ./compiled/facebook-www/VERSION_MODERN)
206+
VERSION_NATIVE_FB=$(cat ./compiled-rn/VERSION_NATIVE_FB)
207+
echo "Current classic version is $VERSION_CLASSIC"
208+
echo "Current modern version is $VERSION_MODERN"
209+
echo "Current rn version is $VERSION_NATIVE_FB"
210+
echo "current_version_classic=$VERSION_CLASSIC" >> "$GITHUB_OUTPUT"
211+
echo "current_version_modern=$VERSION_MODERN" >> "$GITHUB_OUTPUT"
212+
echo "current_version_rn=$VERSION_NATIVE_FB" >> "$GITHUB_OUTPUT"
168213
- uses: actions/upload-artifact@v3
169214
with:
170215
name: compiled
@@ -188,15 +233,58 @@ jobs:
188233
with:
189234
name: compiled
190235
path: compiled/
191-
- run: git status -u
236+
- name: Revert version changes
237+
if: needs.download_artifacts.outputs.last_version_classic != '' && needs.download_artifacts.outputs.last_version_modern != ''
238+
env:
239+
CURRENT_VERSION_CLASSIC: ${{ needs.download_artifacts.outputs.current_version_classic }}
240+
CURRENT_VERSION_MODERN: ${{ needs.download_artifacts.outputs.current_version_modern }}
241+
LAST_VERSION_CLASSIC: ${{ needs.download_artifacts.outputs.last_version_classic }}
242+
LAST_VERSION_MODERN: ${{ needs.download_artifacts.outputs.last_version_modern }}
243+
run: |
244+
echo "Reverting $CURRENT_VERSION_CLASSIC to $LAST_VERSION_CLASSIC"
245+
grep -rl "$CURRENT_VERSION_CLASSIC" ./compiled || echo "No files found with $CURRENT_VERSION_CLASSIC"
246+
grep -rl "$CURRENT_VERSION_CLASSIC" ./compiled | xargs -r sed -i -e "s/$CURRENT_VERSION_CLASSIC/$LAST_VERSION_CLASSIC/g"
247+
grep -rl "$CURRENT_VERSION_CLASSIC" ./compiled || echo "Classic version reverted"
248+
echo "===================="
249+
echo "Reverting $CURRENT_VERSION_MODERN to $LAST_VERSION_MODERN"
250+
grep -rl "$CURRENT_VERSION_MODERN" ./compiled || echo "No files found with $CURRENT_VERSION_MODERN"
251+
grep -rl "$CURRENT_VERSION_MODERN" ./compiled | xargs -r sed -i -e "s/$CURRENT_VERSION_MODERN/$LAST_VERSION_MODERN/g"
252+
grep -rl "$CURRENT_VERSION_MODERN" ./compiled || echo "Modern version reverted"
192253
- name: Check if only the REVISION file has changed
193254
id: check_should_commit
194255
run: |
195-
if git status --porcelain | grep -qv '/REVISION$'; then
256+
echo "Full git status"
257+
git status
258+
echo "===================="
259+
if git status --porcelain | grep -qv '/REVISION'; then
260+
echo "Changes detected"
196261
echo "should_commit=true" >> "$GITHUB_OUTPUT"
197262
else
263+
echo "No Changes detected"
198264
echo "should_commit=false" >> "$GITHUB_OUTPUT"
199265
fi
266+
- name: Re-apply version changes
267+
if: steps.check_should_commit.outputs.should_commit == 'true' && needs.download_artifacts.outputs.last_version_classic != '' && needs.download_artifacts.outputs.last_version_modern != ''
268+
env:
269+
CURRENT_VERSION_CLASSIC: ${{ needs.download_artifacts.outputs.current_version_classic }}
270+
CURRENT_VERSION_MODERN: ${{ needs.download_artifacts.outputs.current_version_modern }}
271+
LAST_VERSION_CLASSIC: ${{ needs.download_artifacts.outputs.last_version_classic }}
272+
LAST_VERSION_MODERN: ${{ needs.download_artifacts.outputs.last_version_modern }}
273+
run: |
274+
echo "Re-applying $LAST_VERSION_CLASSIC to $CURRENT_VERSION_CLASSIC"
275+
grep -rl "$LAST_VERSION_CLASSIC" ./compiled || echo "No files found with $LAST_VERSION_CLASSIC"
276+
grep -rl "$LAST_VERSION_CLASSIC" ./compiled | xargs -r sed -i -e "s/$LAST_VERSION_CLASSIC/$CURRENT_VERSION_CLASSIC/g"
277+
grep -rl "$LAST_VERSION_CLASSIC" ./compiled || echo "Classic version re-applied"
278+
echo "===================="
279+
echo "Re-applying $LAST_VERSION_MODERN to $CURRENT_VERSION_MODERN"
280+
grep -rl "$LAST_VERSION_MODERN" ./compiled || echo "No files found with $LAST_VERSION_MODERN"
281+
grep -rl "$LAST_VERSION_MODERN" ./compiled | xargs -r sed -i -e "s/$LAST_VERSION_MODERN/$CURRENT_VERSION_MODERN/g"
282+
grep -rl "$LAST_VERSION_MODERN" ./compiled || echo "Classic version re-applied"
283+
- name: Will commit these changes
284+
if: steps.check_should_commit.outputs.should_commit == 'true'
285+
run: |
286+
echo ":"
287+
git status -u
200288
- name: Commit changes to branch
201289
if: steps.check_should_commit.outputs.should_commit == 'true'
202290
uses: stefanzweifel/git-auto-commit-action@v4
@@ -219,20 +307,52 @@ jobs:
219307
with:
220308
ref: builds/facebook-fbsource
221309
- name: Ensure clean directory
222-
run: rm -rf compiled
310+
run: rm -rf compiled-rn
223311
- uses: actions/download-artifact@v3
224312
with:
225313
name: compiled-rn
226314
path: compiled-rn/
227-
- run: git status -u
315+
- name: Revert version changes
316+
if: needs.download_artifacts.outputs.last_version_rn != ''
317+
env:
318+
CURRENT_VERSION: ${{ needs.download_artifacts.outputs.current_version_rn }}
319+
LAST_VERSION: ${{ needs.download_artifacts.outputs.last_version_rn }}
320+
run: |
321+
echo "Reverting $CURRENT_VERSION to $LAST_VERSION"
322+
grep -rl "$CURRENT_VERSION" ./compiled-rn || echo "No files found with $CURRENT_VERSION"
323+
grep -rl "$CURRENT_VERSION" ./compiled-rn | xargs -r sed -i -e "s/$CURRENT_VERSION/$LAST_VERSION/g"
324+
grep -rl "$CURRENT_VERSION" ./compiled-rn || echo "Version reverted"
228325
- name: Check if only the REVISION file has changed
229326
id: check_should_commit
230327
run: |
231-
if git status --porcelain | grep -qv '/REVISION$'; then
328+
echo "Full git status"
329+
git status
330+
echo "===================="
331+
echo "Checking for changes"
332+
# Check if there are changes in the files other than REVISION or @generated headers
333+
# We also filter out the file name lines with "---" and "+++".
334+
if git diff -- . ':(exclude)*REVISION' | grep -vE "^(@@|diff|index|\-\-\-|\+\+\+|@generated SignedSource)" | grep "^[+-]" > /dev/null; then
335+
echo "Changes detected"
232336
echo "should_commit=true" >> "$GITHUB_OUTPUT"
233337
else
338+
echo "No Changes detected"
234339
echo "should_commit=false" >> "$GITHUB_OUTPUT"
235340
fi
341+
- name: Re-apply version changes
342+
if: steps.check_should_commit.outputs.should_commit == 'true' && needs.download_artifacts.outputs.last_version_rn != ''
343+
env:
344+
CURRENT_VERSION: ${{ needs.download_artifacts.outputs.current_version_rn }}
345+
LAST_VERSION: ${{ needs.download_artifacts.outputs.last_version_rn }}
346+
run: |
347+
echo "Re-applying $LAST_VERSION to $CURRENT_VERSION"
348+
grep -rl "$LAST_VERSION" ./compiled-rn || echo "No files found with $LAST_VERSION"
349+
grep -rl "$LAST_VERSION" ./compiled-rn | xargs -r sed -i -e "s/$LAST_VERSION/$CURRENT_VERSION/g"
350+
grep -rl "$LAST_VERSION" ./compiled-rn || echo "Version re-applied"
351+
- name: Will commit these changes
352+
if: steps.check_should_commit.outputs.should_commit == 'true'
353+
run: |
354+
echo ":"
355+
git status -u
236356
- name: Commit changes to branch
237357
if: steps.check_should_commit.outputs.should_commit == 'true'
238358
uses: stefanzweifel/git-auto-commit-action@v4

ReactVersions.js

+5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ const ReactVersion = '19.0.0';
2828
// npm dist tags used during publish, refer to .circleci/config.yml.
2929
const canaryChannelLabel = 'rc';
3030

31+
// If the canaryChannelLabel is "rc", the build pipeline will use this to build
32+
// an RC version of the packages.
33+
const rcNumber = 0;
34+
3135
const stablePackages = {
3236
'eslint-plugin-react-hooks': '5.1.0',
3337
'jest-react': '0.16.0',
@@ -53,6 +57,7 @@ const experimentalPackages = [];
5357
module.exports = {
5458
ReactVersion,
5559
canaryChannelLabel,
60+
rcNumber,
5661
stablePackages,
5762
experimentalPackages,
5863
};

compiler/packages/babel-plugin-react-compiler/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "babel-plugin-react-compiler",
3-
"version": "0.0.0-experimental-487cb0e-20240529",
3+
"version": "0.0.0-experimental-938cd9a-20240601",
44
"description": "Babel plugin for React Compiler.",
55
"main": "dist/index.js",
66
"license": "MIT",

compiler/packages/babel-plugin-react-compiler/src/Babel/BabelPlugin.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,16 @@ export default function BabelPluginReactCompiler(
3030
*/
3131
Program(prog, pass): void {
3232
let opts = parsePluginOptions(pass.opts);
33-
if (pipelineUsesReanimatedPlugin(pass.file.opts.plugins)) {
33+
const isDev =
34+
(typeof __DEV__ !== "undefined" && __DEV__ === true) ||
35+
process.env["NODE_ENV"] === "development";
36+
if (
37+
opts.enableReanimatedCheck === true &&
38+
pipelineUsesReanimatedPlugin(pass.file.opts.plugins)
39+
) {
3440
opts = injectReanimatedFlag(opts);
3541
}
36-
if (process.env["NODE_ENV"] === "development") {
42+
if (isDev) {
3743
opts = {
3844
...opts,
3945
environment: {

compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Options.ts

+7
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ export type PluginOptions = {
111111
ignoreUseNoForget: boolean;
112112

113113
sources?: Array<string> | ((filename: string) => boolean) | null;
114+
115+
/**
116+
* The compiler has customized support for react-native-reanimated, intended as a temporary workaround.
117+
* Set this flag (on by default) to automatically check for this library and activate the support.
118+
*/
119+
enableReanimatedCheck: boolean;
114120
};
115121

116122
const CompilationModeSchema = z.enum([
@@ -188,6 +194,7 @@ export const defaultOptions: PluginOptions = {
188194
sources: (filename) => {
189195
return filename.indexOf("node_modules") === -1;
190196
},
197+
enableReanimatedCheck: true,
191198
} as const;
192199

193200
export function parsePluginOptions(obj: unknown): PluginOptions {

compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Pipeline.ts

+18-2
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ import {
9191
validatePreservedManualMemoization,
9292
validateUseMemo,
9393
} from "../Validation";
94+
import pruneInitializationDependencies from "../ReactiveScopes/PruneInitializationDependencies";
9495

9596
export type CompilerPipelineValue =
9697
| { kind: "ast"; name: string; value: CodegenFunction }
@@ -147,8 +148,14 @@ function* runWithEnvironment(
147148
validateContextVariableLValues(hir);
148149
validateUseMemo(hir);
149150

150-
dropManualMemoization(hir);
151-
yield log({ kind: "hir", name: "DropManualMemoization", value: hir });
151+
if (
152+
!env.config.enablePreserveExistingManualUseMemo &&
153+
!env.config.disableMemoizationForDebugging &&
154+
!env.config.enableChangeDetectionForDebugging
155+
) {
156+
dropManualMemoization(hir);
157+
yield log({ kind: "hir", name: "DropManualMemoization", value: hir });
158+
}
152159

153160
inlineImmediatelyInvokedFunctionExpressions(hir);
154161
yield log({
@@ -373,6 +380,15 @@ function* runWithEnvironment(
373380
value: reactiveFunction,
374381
});
375382

383+
if (env.config.enableChangeDetectionForDebugging != null) {
384+
pruneInitializationDependencies(reactiveFunction);
385+
yield log({
386+
kind: "reactive",
387+
name: "PruneInitializationDependencies",
388+
value: reactiveFunction,
389+
});
390+
}
391+
376392
propagateEarlyReturns(reactiveFunction);
377393
yield log({
378394
kind: "reactive",

compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts

+7
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,13 @@ export function compileProgram(
421421
);
422422
externalFunctions.push(enableEmitHookGuards);
423423
}
424+
425+
if (options.environment?.enableChangeDetectionForDebugging != null) {
426+
const enableChangeDetectionForDebugging = tryParseExternalFunction(
427+
options.environment.enableChangeDetectionForDebugging
428+
);
429+
externalFunctions.push(enableChangeDetectionForDebugging);
430+
}
424431
} catch (err) {
425432
handleError(err, pass, null);
426433
return;

compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export function lower(
124124
) {
125125
const place: Place = {
126126
kind: "Identifier",
127-
identifier: builder.makeTemporary(),
127+
identifier: builder.makeTemporary(param.node.loc ?? GeneratedSource),
128128
effect: Effect.Unknown,
129129
reactive: false,
130130
loc: param.node.loc ?? GeneratedSource,
@@ -141,7 +141,7 @@ export function lower(
141141
} else if (param.isRestElement()) {
142142
const place: Place = {
143143
kind: "Identifier",
144-
identifier: builder.makeTemporary(),
144+
identifier: builder.makeTemporary(param.node.loc ?? GeneratedSource),
145145
effect: Effect.Unknown,
146146
reactive: false,
147147
loc: param.node.loc ?? GeneratedSource,
@@ -1256,7 +1256,9 @@ function lowerStatement(
12561256
if (hasNode(handlerBindingPath)) {
12571257
const place: Place = {
12581258
kind: "Identifier",
1259-
identifier: builder.makeTemporary(),
1259+
identifier: builder.makeTemporary(
1260+
handlerBindingPath.node.loc ?? GeneratedSource
1261+
),
12601262
effect: Effect.Unknown,
12611263
reactive: false,
12621264
loc: handlerBindingPath.node.loc ?? GeneratedSource,
@@ -3301,7 +3303,7 @@ function lowerIdentifier(
33013303
function buildTemporaryPlace(builder: HIRBuilder, loc: SourceLocation): Place {
33023304
const place: Place = {
33033305
kind: "Identifier",
3304-
identifier: builder.makeTemporary(),
3306+
identifier: builder.makeTemporary(loc),
33053307
effect: Effect.Unknown,
33063308
reactive: false,
33073309
loc,

0 commit comments

Comments
 (0)