Skip to content

Commit f8845fa

Browse files
committed
[compiler] Switch to track states by aliasing and id instead of identifier names
1 parent 2a290bb commit f8845fa

File tree

2 files changed

+36
-44
lines changed

2 files changed

+36
-44
lines changed

compiler/apps/playground/yarn.lock

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -854,23 +854,11 @@
854854
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.11.9.tgz#02d013de7058cea16d36168ef2fc653464cfbad4"
855855
integrity sha512-CRpX21/kGdzjOpFsZSkcrXMGIBWMGNIHXXBVFSH+ggkftxg+XYP20TESbh+zFvFj3EQOl5byk0HTRn1IL6hbqg==
856856

857-
"@types/react-dom@19.1.9":
858-
version "19.1.9"
859-
resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-19.1.9.tgz#5ab695fce1e804184767932365ae6569c11b4b4b"
860-
integrity sha512-qXRuZaOsAdXKFyOhRBg6Lqqc0yay13vN7KrIg4L7N4aaHN68ma9OK3NE1BoDFgFOTfM7zg+3/8+2n8rLUH3OKQ==
861-
862857
"@types/react-dom@19.2":
863858
version "19.2.2"
864859
resolved "https://registry.npmjs.org/@types/react-dom/-/react-dom-19.2.2.tgz#a4cc874797b7ddc9cb180ef0d5dc23f596fc2332"
865860
integrity sha512-9KQPoO6mZCi7jcIStSnlOWn2nEF3mNmyr3rIAsGnAbQKYbRLyqmeSc39EVgtxXVia+LMT8j3knZLAZAh+xLmrw==
866861

867-
"@types/react@19.1.12":
868-
version "19.1.12"
869-
resolved "https://registry.yarnpkg.com/@types/react/-/react-19.1.12.tgz#7bfaa76aabbb0b4fe0493c21a3a7a93d33e8937b"
870-
integrity sha512-cMoR+FoAf/Jyq6+Df2/Z41jISvGZZ2eTlnsaJRptmZ76Caldwy1odD4xTr/gNV9VLj0AWgg/nmkevIyUfIIq5w==
871-
dependencies:
872-
csstype "^3.0.2"
873-
874862
"@types/react@19.2":
875863
version "19.2.2"
876864
resolved "https://registry.npmjs.org/@types/react/-/react-19.2.2.tgz#ba123a75d4c2a51158697160a4ea2ff70aa6bf36"
@@ -3982,16 +3970,7 @@ stop-iteration-iterator@^1.1.0:
39823970
es-errors "^1.3.0"
39833971
internal-slot "^1.1.0"
39843972

3985-
"string-width-cjs@npm:string-width@^4.2.0":
3986-
version "4.2.3"
3987-
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
3988-
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
3989-
dependencies:
3990-
emoji-regex "^8.0.0"
3991-
is-fullwidth-code-point "^3.0.0"
3992-
strip-ansi "^6.0.1"
3993-
3994-
string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
3973+
"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
39953974
version "4.2.3"
39963975
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
39973976
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@@ -4095,14 +4074,7 @@ string.prototype.trimstart@^1.0.8:
40954074
define-properties "^1.2.1"
40964075
es-object-atoms "^1.0.0"
40974076

4098-
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
4099-
version "6.0.1"
4100-
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
4101-
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
4102-
dependencies:
4103-
ansi-regex "^5.0.1"
4104-
4105-
strip-ansi@^6.0.0, strip-ansi@^6.0.1:
4077+
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
41064078
version "6.0.1"
41074079
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
41084080
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
@@ -4523,16 +4495,7 @@ word-wrap@^1.2.5:
45234495
resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.5.tgz#d2c45c6dd4fbce621a66f136cbe328afd0410b34"
45244496
integrity sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==
45254497

4526-
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
4527-
version "7.0.0"
4528-
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
4529-
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
4530-
dependencies:
4531-
ansi-styles "^4.0.0"
4532-
string-width "^4.1.0"
4533-
strip-ansi "^6.0.0"
4534-
4535-
wrap-ansi@^7.0.0:
4498+
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
45364499
version "7.0.0"
45374500
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
45384501
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==

compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateNoDerivedComputationsInEffects_exp.ts

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,21 @@ type DerivationMetadata = {
3737
sourcesIds: Set<IdentifierId>;
3838
};
3939

40+
// type setStateKey = {
41+
// id: IdentifierId;
42+
// usageType: 'all' | 'effect';
43+
// };
44+
4045
type ValidationContext = {
4146
readonly functions: Map<IdentifierId, FunctionExpression>;
4247
readonly errors: CompilerError;
4348
readonly derivationCache: DerivationCache;
4449
readonly effects: Set<HIRFunction>;
4550
readonly setStateCache: Map<string | undefined | null, Array<Place>>;
4651
readonly effectSetStateCache: Map<string | undefined | null, Array<Place>>;
52+
// These should replace the setStateCache and effectSetStateCache once we have
53+
readonly setStateLoads: Map<IdentifierId, IdentifierId | null>;
54+
readonly setStateUsages: Map<IdentifierId, SourceLocation>;
4755
};
4856

4957
class DerivationCache {
@@ -189,13 +197,18 @@ export function validateNoDerivedComputationsInEffects_exp(
189197
Array<Place>
190198
> = new Map();
191199

200+
const setStateLoads: Map<IdentifierId, IdentifierId> = new Map();
201+
const setStateUsages: Map<IdentifierId, SourceLocation> = new Map();
202+
192203
const context: ValidationContext = {
193204
functions,
194205
errors,
195206
derivationCache,
196207
effects,
197208
setStateCache,
198209
effectSetStateCache,
210+
setStateLoads,
211+
setStateUsages,
199212
};
200213

201214
if (fn.fnType === 'Hook') {
@@ -242,10 +255,8 @@ export function validateNoDerivedComputationsInEffects_exp(
242255
validateEffect(effect, context);
243256
}
244257

245-
console.log(derivationCache.cache);
246-
if (errors.hasAnyErrors()) {
247-
throw errors;
248-
}
258+
console.log('SetStateLoads', context.setStateLoads);
259+
return errors.asResult();
249260
}
250261

251262
function recordPhiDerivations(
@@ -288,11 +299,29 @@ function joinValue(
288299
return 'fromPropsAndState';
289300
}
290301

302+
function maybeRecordSetState(instr: Instruction, context: ValidationContext) {
303+
for (const operand of eachInstructionLValue(instr)) {
304+
if (isSetStateType(operand.identifier)) {
305+
if (instr.value.kind === 'LoadLocal') {
306+
context.setStateLoads.set(
307+
operand.identifier.id,
308+
instr.value.place.identifier.id,
309+
);
310+
} else {
311+
context.setStateLoads.set(operand.identifier.id, null);
312+
}
313+
}
314+
}
315+
}
316+
291317
function recordInstructionDerivations(
292318
instr: Instruction,
293319
context: ValidationContext,
294320
isFirstPass: boolean,
295321
): void {
322+
// WIP
323+
maybeRecordSetState(instr, context);
324+
296325
let typeOfValue: TypeOfValue = 'ignored';
297326
const sources: Set<IdentifierId> = new Set();
298327
const {lvalue, value} = instr;

0 commit comments

Comments
 (0)