dillon1000/react
Commit
Browse files [new-architecture] Reassignment-safe frozenness inference
NOTE: this improves the equivalent of "ref kind inference" in the new architecture. I'd appreciate review here on the algorithm in particular, but in general my plan is to try to implement this on the current architecture. The previous InferMutability reference kind inference didn't properly handle capturing or reassignment combined with control flow. This is a new version (i'll clean up to delete InferMutability entirely) that is less ambitious but fully accurate (i hope, hence WIP): * Annotates all references of frozen variables as frozen. This includes following reassignment, so if you do `const x = props.x; foo(x);` we know that `x` is frozen because it derived from a frozen value. This even works conditionally, so if `x` is conditionally assigned to some value derived from eg props, and you later use `x`, that will be marked as frozen even if it could have other values at runtime (since it must conservatively assume a frozen value flowed in at runtime). * Annotates references that may mutate as mutable. * Annotates references that are not frozen, but not mutated _at this reference site_, as readonly. It's possible that a readonly usage is followed by a mutable usage, since we don't yet know the "lifetime" of the mutability. The notable difference from the previous attempt is that we do not attempt to find the point at which a formerly-mutable values becomes readonly (and therefore eligible for caching). That requires pointer analysis, let's discuss offline.
Changed paths36 files
First-parent comparisoncompiler/forget/src/HIR/BuildDefUseGraph.ts AddedM compiler/forget/src/HIR/BuildHIR.ts ModifiedM compiler/forget/src/HIR/HIRBuilder.ts ModifiedD compiler/forget/src/__tests__/fixtures/hir-svg/call.svg DeletedM compiler/forget/src/__tests__/fixtures/hir-svg/component.svg ModifiedD compiler/forget/src/__tests__/fixtures/hir-svg/conditional-break.svg DeletedD compiler/forget/src/__tests__/fixtures/hir-svg/conditional-on-mutable.svg DeletedD compiler/forget/src/__tests__/fixtures/hir-svg/constructor.svg DeletedD compiler/forget/src/__tests__/fixtures/hir-svg/hook-call.svg DeletedD compiler/forget/src/__tests__/fixtures/hir-svg/independent-across-if.svg DeletedD compiler/forget/src/__tests__/fixtures/hir-svg/independent.svg DeletedD compiler/forget/src/__tests__/fixtures/hir-svg/interdependent-across-if.svg DeletedD compiler/forget/src/__tests__/fixtures/hir-svg/interdependent.svg DeletedD compiler/forget/src/__tests__/fixtures/hir-svg/property-assignment.svg DeletedD compiler/forget/src/__tests__/fixtures/hir-svg/reassignment-conditional.svg DeletedD compiler/forget/src/__tests__/fixtures/hir-svg/reassignment.svg DeletedD compiler/forget/src/__tests__/fixtures/hir-svg/simple.svg DeletedM compiler/forget/src/__tests__/fixtures/hir-svg/switch.svg ModifiedM compiler/forget/src/__tests__/fixtures/hir/call.expect.md ModifiedM compiler/forget/src/__tests__/fixtures/hir/component.expect.md ModifiedM compiler/forget/src/__tests__/fixtures/hir/component.js ModifiedM compiler/forget/src/__tests__/fixtures/hir/conditional-break.expect.md ModifiedM compiler/forget/src/__tests__/fixtures/hir/conditional-on-mutable.expect.md ModifiedM compiler/forget/src/__tests__/fixtures/hir/constructor.expect.md ModifiedM compiler/forget/src/__tests__/fixtures/hir/hook-call.expect.md ModifiedM compiler/forget/src/__tests__/fixtures/hir/independent-across-if.expect.md ModifiedM compiler/forget/src/__tests__/fixtures/hir/independent.expect.md ModifiedM compiler/forget/src/__tests__/fixtures/hir/interdependent-across-if.expect.md ModifiedM compiler/forget/src/__tests__/fixtures/hir/interdependent.expect.md ModifiedM compiler/forget/src/__tests__/fixtures/hir/property-assignment.expect.md ModifiedM compiler/forget/src/__tests__/fixtures/hir/reassignment-conditional.expect.md ModifiedM compiler/forget/src/__tests__/fixtures/hir/reassignment.expect.md ModifiedM compiler/forget/src/__tests__/fixtures/hir/simple.expect.md ModifiedM compiler/forget/src/__tests__/fixtures/hir/switch.expect.md ModifiedM compiler/forget/src/__tests__/fixtures/hir/switch.js ModifiedM compiler/forget/src/__tests__/hir-test.ts ModifiedPatch
Files changed
Rendering syntax-highlighted changes…