dillon1000/react

Commit

[hir] Add Load/StoreContext (1/n)

--- 

This PR adds LoadContext and StoreContext to handle reading and writing to 
context variables. 

A context variable is any variable that is declared within a Forget-compiled 
function and reassigned within a closure. Conceptually, we want to treat these 
variables as attributes of a `EnvironmentContext` variable (as most javascript 
VMs do). 

- context variables currently do not participate in type inference (i.e. we do 
not produce type equations for loads from context variables). In the future, we 
can try typing this as `Phi(assignment1Type, assignment2Type, ...)`. 

- context variables are always treated as `Effect.Mutable`. 

- context variables do not participate in SSA, or certain optimizing passes 
(e.g. dead code elimination, constant propagation, etc). 

There is some still follow ups: 

- From my understanding, we should introduce a `DeclareContext` instruction. 

- currently, declaring a context variable (without initializing it) is broken. 
This is because the declaration lowers to `DeclareLocal`, which assumes it is 
storing to a SSA-fied identifier. 

```js 

let x; 

x = 4; 

() => { x = {}; }; 

``` 

- DeclareContext will also make some initialization logic easier. In this PR, I 
added some hack-y code to handle initializing effects / mutable ranges / other 
inference state for the first StoreContext. 

- Handle or bail on stores to context variables through destructuring assignment 

- 

~~Next PR:~~ 

- ~~Change closures to track reassigned identifiers (to extend mutable range of 
primitives)~~
Browse files
Changed paths28 files
First-parent comparison
M compiler/forget/src/CompilerPipeline.ts ModifiedM compiler/forget/src/HIR/BuildHIR.ts ModifiedM compiler/forget/src/HIR/Environment.ts ModifiedA compiler/forget/src/HIR/FindContextIdentifiers.ts AddedM compiler/forget/src/HIR/HIR.ts ModifiedM compiler/forget/src/HIR/HIRBuilder.ts ModifiedM compiler/forget/src/HIR/PrintHIR.ts ModifiedM compiler/forget/src/HIR/visitors.ts ModifiedM compiler/forget/src/Inference/AnalyseFunctions.ts ModifiedM compiler/forget/src/Inference/InferAlias.ts ModifiedM compiler/forget/src/Inference/InferMutableLifetimes.ts ModifiedM compiler/forget/src/Inference/InferReferenceEffects.ts ModifiedM compiler/forget/src/Optimization/DeadCodeElimination.ts ModifiedM compiler/forget/src/ReactiveScopes/CodegenReactiveFunction.ts ModifiedM compiler/forget/src/ReactiveScopes/InferReactiveScopeVariables.ts ModifiedM compiler/forget/src/ReactiveScopes/PropagateScopeDependencies.ts ModifiedM compiler/forget/src/ReactiveScopes/PruneNonEscapingScopes.ts ModifiedM compiler/forget/src/TypeInference/InferTypes.ts ModifiedM compiler/forget/src/__tests__/fixtures/compiler/_bug.capturing-reference-changes-type.expect.md ModifiedA compiler/forget/src/__tests__/fixtures/compiler/_bug.destructure-to-local-global-variables.expect.md AddedA compiler/forget/src/__tests__/fixtures/compiler/_bug.destructure-to-local-global-variables.js AddedM compiler/forget/src/__tests__/fixtures/compiler/_bug.lambda-reassign-primitive.expect.md ModifiedM compiler/forget/src/__tests__/fixtures/compiler/_bug.lambda-reassign-shadowed-primitive.expect.md ModifiedM compiler/forget/src/__tests__/fixtures/compiler/capturing-function-alias-computed-load-3.expect.md ModifiedA compiler/forget/src/__tests__/fixtures/compiler/reassign-object-in-context.expect.md AddedA compiler/forget/src/__tests__/fixtures/compiler/reassign-object-in-context.js AddedA compiler/forget/src/__tests__/fixtures/compiler/reassign-primitive-in-context.expect.md AddedA compiler/forget/src/__tests__/fixtures/compiler/reassign-primitive-in-context.js Added
Patch

Files changed

Rendering syntax-highlighted changes…