Skip to content

Commit b937a83

Browse files
committed
[compiler] Switch to track states by aliasing and id instead of identifier names
1 parent 98ea57b commit b937a83

File tree

2 files changed

+36
-40
lines changed

2 files changed

+36
-40
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-
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
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-
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
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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,21 @@ type DerivationMetadata = {
3636
sourcesIds: Set<IdentifierId>;
3737
};
3838

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

4856
class DerivationCache {
@@ -159,13 +167,18 @@ export function validateNoDerivedComputationsInEffects_exp(
159167
Array<Place>
160168
> = new Map();
161169

170+
const setStateLoads: Map<IdentifierId, IdentifierId> = new Map();
171+
const setStateUsages: Map<IdentifierId, SourceLocation> = new Map();
172+
162173
const context: ValidationContext = {
163174
functions,
164175
errors,
165176
derivationCache,
166177
effects,
167178
setStateCache,
168179
effectSetStateCache,
180+
setStateLoads,
181+
setStateUsages,
169182
};
170183

171184
if (fn.fnType === 'Hook') {
@@ -193,6 +206,7 @@ export function validateNoDerivedComputationsInEffects_exp(
193206

194207
let isFirstPass = true;
195208
do {
209+
console.log('NEW ------------------------------------------------------');
196210
for (const block of fn.body.blocks.values()) {
197211
recordPhiDerivations(block, context);
198212
for (const instr of block.instructions) {
@@ -207,6 +221,7 @@ export function validateNoDerivedComputationsInEffects_exp(
207221
validateEffect(effect, context);
208222
}
209223

224+
console.log('SetStateLoads', context.setStateLoads);
210225
return errors.asResult();
211226
}
212227

@@ -250,11 +265,29 @@ function joinValue(
250265
return 'fromPropsAndState';
251266
}
252267

268+
function maybeRecordSetState(instr: Instruction, context: ValidationContext) {
269+
for (const operand of eachInstructionLValue(instr)) {
270+
if (isSetStateType(operand.identifier)) {
271+
if (instr.value.kind === 'LoadLocal') {
272+
context.setStateLoads.set(
273+
operand.identifier.id,
274+
instr.value.place.identifier.id,
275+
);
276+
} else {
277+
context.setStateLoads.set(operand.identifier.id, null);
278+
}
279+
}
280+
}
281+
}
282+
253283
function recordInstructionDerivations(
254284
instr: Instruction,
255285
context: ValidationContext,
256286
isFirstPass: boolean,
257287
): void {
288+
// WIP
289+
maybeRecordSetState(instr, context);
290+
258291
let typeOfValue: TypeOfValue = 'ignored';
259292
const sources: Set<IdentifierId> = new Set();
260293
const {lvalue, value} = instr;

0 commit comments

Comments
 (0)