dillon1000/react

Commit

[hir] todo tests for lambda capture

--- 

(I'm not sure if these are already known issues. I found them while playing 
around with lambda captures. They are also reproducible on main / stable) 

I have some limited understanding of lambda captures after reading Sathya's 
posts -- please correct if/where this is incorrect 

``` 

function Component() { 

// instr1 

// instr2 

const func3 = function(...) { 

// func3instr1 

} 

} 

``` 

We currently determine effects of captured references in `AnalyzeFunctions`, 
before InferReferenceEffects. 

- i.e. for some function 

1. dependencies of all functions (func3.deps) 

2. prefix traversal of all instructions (e.g. instr1, instr2, func3.deps, 
func3instr1, ...) 

- is this just an implementation decision? i.e. what is stopping us from postfix 
traversal in InferReferenceEffects (e.g. instr1, instr2, func3instr1, 
func3.deps) 

As such, for each captured reference, `AnalyzeFunctions` needs to assign a 
reference effect. We currently check `MutableRange`, which seems to miss a few 
cases 

- We do not model assignments to primitives correctly, since primitives do not 
have a mutable range. 

- We're not able to model captured (but not mutated) values correctly. 

Would it be possible to consolidate `AnalyzeFunctions` into 
InferReferenceEffects, using some post-order traversal (iterating over a 
function's instructions to collect its dependencies + associated capture 
effects)? I definitely don't understand lambdas completely, so please tell me 
what I'm missing
Browse files
Changed paths8 files
First-parent comparison
A compiler/forget/src/__tests__/fixtures/compiler/_bug.lambda-capture-returned-alias.expect.md AddedA compiler/forget/src/__tests__/fixtures/compiler/_bug.lambda-capture-returned-alias.js AddedA compiler/forget/src/__tests__/fixtures/compiler/_bug.lambda-mutate-shadowed-object.expect.md AddedA compiler/forget/src/__tests__/fixtures/compiler/_bug.lambda-mutate-shadowed-object.js AddedA compiler/forget/src/__tests__/fixtures/compiler/_bug.lambda-reassign-primitive.expect.md AddedA compiler/forget/src/__tests__/fixtures/compiler/_bug.lambda-reassign-primitive.js AddedA compiler/forget/src/__tests__/fixtures/compiler/_bug.lambda-reassign-shadowed-primitive.expect.md AddedA compiler/forget/src/__tests__/fixtures/compiler/_bug.lambda-reassign-shadowed-primitive.js Added
Patch

Files changed

Rendering syntax-highlighted changes…