Commit Graph
45 Commits
Author SHA1 Message Date
Joe Savona 530231712f [be] Extract hooks helpers to separate file
This is a precursor to allowing the set of custom hooks (and their behavior) to 
be configurable.
2023-02-16 10:38:06 -08:00
Sathya Gunasekaran fb8f293c32 [hir] Add a DropMemoCall pass
This drops the memo hook calls from the IR
2023-02-14 23:07:19 +00:00
Sathya Gunasekaran 1dfd51cdb0 [hir] Add name field to Hook 2023-02-14 23:07:17 +00:00
Sathya Gunasekaran a65bf197d7 [hir] Add Memo hooks 2023-02-14 23:07:16 +00:00
Sathya Gunasekaran 12ca0ba61b [hir] Simplify HookKind 2023-02-14 23:07:16 +00:00
Joe Savona 5673588be4 [be] Tidy up some mutableRange logic 2023-02-13 15:26:07 -08:00
Joe Savona 6b67f597a6 Capturing a frozen value is a Read
If a value is known to be frozen (or potentially frozen), then it doesn't need 
to be considered 'captured' since no mutation can occur via aliasing.
2023-02-14 09:33:23 -08:00
Sathya Gunasekaran 31d8aad40e [hir] Check if defined before looking up ValueKind
This handles globals now without throwing
2023-02-13 16:32:50 +00:00
Sathya Gunasekaran b56f413e99 [hir] Mark ArrayExpression capturing a context ref as a context ref
A context ref capture is transitive.
2023-02-10 17:59:58 +00:00
Sathya Gunasekaran 343ebb47bd [hir] Mark ObjectExpression capturing a context ref as a context ref
A context ref capture is transitive.
2023-02-10 17:59:57 +00:00
Sathya Gunasekaran fa57551dd5 [hir] Introduce ValueKind.Context
This tracks whether a value is a context ref or generated from a context ref. 

This lets us track mutations to context refs and treat it separately as we want 
this to be more conservative than our existing inference. 

ValueKind.Context is exactly like ValueKind.Mutable but is more conservative.
2023-02-10 17:59:56 +00:00
Sathya Gunasekaran 199e284eda [hir] Mark Identifiers aliased as Effect.Capture 2023-02-10 17:26:21 +00:00
Sathya Gunasekaran 40a85432ed [hir] Move inference logic to Env.reference 2023-02-10 17:26:17 +00:00
Joe Savona 41f52b73c2 Change reference effects for hooks
I realized we hadn't updated InferReferenceEffects to match our latest thinking 
on hooks. Specifically, we will default to assuming that hooks can mutate their 
arguments and return mutable values — this works with our model since we don't 
treat hooks specially for reactive scope construction. Ie, first we figure out 
what variables construct together, then we create scopes, then we prune scopes 
that contain hooks. So changing the reference effects for hooks "just works". 

Note that it is helpful for our unit tests to have an example hook that we know 
_does_ freeze its input and return a frozen value, so i've temporarily added 
`useFreeze()` to the list of defined hooks. That is meant as a stopgap: the 
right solution is to allow some way to tell the compiler about specific custom 
hooks and their semantics.
2023-02-08 14:24:14 -08:00
Joe Savona 7f60f32118 Dont memoize scopes with hook calls 2023-02-08 14:07:01 -08:00
Sathya Gunasekaran 394666118d [hir] Lower function expressions into HIR 2023-02-08 17:45:33 +00:00
Sathya Gunasekaran 662b8d2ff3 [hir] Add lvalue effect for PropertyLoad and ComputedLoad 2023-02-08 16:01:36 +00:00
Sathya Gunasekaran d1dbb00790 [hir] Throw if Effect.Store is not handled 2023-02-07 16:59:37 +00:00
Sathya Gunasekaran 3df1ae66c0 [λ] Use Effect.Capture for mutating deps
Leverage Effect.Capture to differentiate between mutating and non mutating deps.
2023-02-07 16:59:36 +00:00
Sathya Gunasekaran 85c92bcfbe [aliasing] Introduce Effect.Capture
Effect.Capture is very similar to Effect.Read, but the only difference is that 
this reference is stored somewhere via a Effect.Store. 

Previously, any operand associated with a Effect.Store in the same instruction 
would get aliased -- so there was no need to explicitly differentiate between a 
"normal read" and "read that gets stored". 

This difference is now explicit with FunctionExpression where every dependency 
is "read" but only a few are "captured" for store (and mutation). In a follow up 
PR, the mutating deps will have an Effect.Capture to differentiate from the 
other non mutating deps (Effect.Read).
2023-02-07 16:59:35 +00:00
Sathya Gunasekaran 4e07b8a869 [hir] Do not alias Identifier as Store
Identifiers are never stored (Effect.Store), they are always mutated 
(Effect.Mutate) and aliased in the InferAlias pass.
2023-02-07 16:59:35 +00:00
Mofei Zhang e30a9e9258 [hir syntax] Handle TemplateLiteral syntax 2023-02-03 15:44:37 -05:00
Sathya Gunasekaran 4b55399fb8 [λ] Use context identifiers in inner functions
This threads through context identifiers to inner functions and also uses them 
as dependencies if they are mutated in the inner function.
2023-02-03 17:42:07 +00:00
Sathya Gunasekaran dc65e7c5a9 [aliasing] Make InferAliasForStores use the visitor infra
No need for InferAliasForStores to know about the semantics of each instruction 
anymore. It's just a simple pass that iterates over every operand and lvalue. 

The FunctionExpression is special cased because it's slightly different but I 
have a follow up that removes this special casing.
2023-02-02 17:41:35 +00:00
Sathya Gunasekaran 40f304392e [aliasing] Alias object loads to it's lvalue as well
This doesn't change codegen as the lvalue is unused but it lets us make this 
pass be semantically the same across all instructions -- "alias lvalue and 
operands of an instr".
2023-02-02 17:41:31 +00:00
Sathya Gunasekaran 018899d778 [aliasing] Make aliasing account for MutableRange.end being exclusive 2023-02-02 17:41:27 +00:00
Sathya Gunasekaran 98f67c407b [aliasing] Alias ComputedLoad operands 2023-02-02 15:45:16 +00:00
Sathya Gunasekaran 5e1929c002 [aliasing] Alias ComputedStore operands 2023-02-02 15:45:12 +00:00
Sathya Gunasekaran 7a92b2fe5d [be] Cleanup logic that matches mutatedId and mutatedDep 2023-02-02 14:05:37 +00:00
Sathya Gunasekaran 12274f30b9 [be] Inline buildMutatedDeps 2023-02-02 14:05:36 +00:00
Sathya Gunasekaran aa2403e068 [λ] Run analyseFunctions on inner func exprs
Previously we would skip out on calling analyseFunctions on inner function  
exprs so we missed out on catching aliased mutation in a different scope.
2023-02-02 14:05:35 +00:00
Sathya Gunasekaran 0522d5233b [λ] Store and define captured bindings as context
This lets us treat global references differently from captured references.
2023-02-02 14:05:34 +00:00
Joe Savona c2dda028fd Improve debugging for - errors 2023-02-01 09:42:46 -08:00
Joe Savona 2069269903 Support TypeCastExpression
Support TypeCastExpressions — `(x: TypeAnnotation)`. This is pretty 
straightforward, it's semantically identical to a raw identifier. 

One catch is that our prettier config is hard-coded to use the babel-ts parser, 
i wasn't sure how to make that dynamic based on the file extension so for now i 
just ignored .flow.js files in our pretter config.
2023-02-01 08:42:33 -08:00
Sathya Gunasekaran f83ff2feda [hir] Parse UnaryExpression 2023-01-25 11:11:16 -05:00
Sathya Gunasekaran 79d53f9117 [hir] Parse and codegen TaggedTemplateExpression
Basic support to parse relay fragments
2023-01-24 16:41:00 -05:00
Sathya Gunasekaran 19dd29707b [λ] Fix mutatedDep collection in AnalyseFunctions
Make sure to check free variables as well for mutations. Not just object 
properties.
2023-01-23 15:46:35 -05:00
Lauren Tan 1a3e269274 Rename InstructionValue.OtherStatement to UnsupportedNode
As discussed, this repurposes OtherStatement as a catch all variant for 
unsupported syntax or errors in the source. This also renames the previously 
added ErrorTerminal to UnsupportedTerminal for consistency (plus makes it a 
little bit less confusing that it's not an actual terminal representing an 
Error). 

Not loving the name but couldn't think of anything better, open to suggestions!
2023-01-20 11:47:08 -05:00
Sathya Gunasekaran c1c30889cc [hir] Lower function expressions into HIR 2023-01-20 14:01:51 +00:00
Sathya Gunasekaran 7c73f51139 [hir] Define function name only if it exists 2023-01-19 18:39:23 +00:00
Joe Savona edeaaaf38a Add PropertyCall/ComputedCall instructions
Adds `PropertyCall` and `ComputedCall`, which are a combination of 
CallExpression and PropertyLoad/ComputedLoad, respectively. The goal is to 
ensure that we correctly model the receiver of a call where the callee is a 
member expression, and also accurately record scope dependencies in for both the 
computed and non-computed (property) cases. 

An alternative that I tried first was to add a `receiver: Place | null` to 
CallExpression. That works well for HIR construction, but it's then very 
difficult at codegen time to correctly reconstruct the original call: if the 
receiver and callee share part of their structure then we can transform back to 
a non-computed member expression, otherwise it has to be computed. Eg we have to 
distinguish `a.b.c[d.foo]()` from `a.b.c[a.b.c.foo]()`. Given that our target is 
high-level code, it seems reasonable to have a higher-level representation for 
these cases. 

I'm open to feedback but this feels pretty reasonable in terms of complexity / 
precision of modeling.
2023-01-17 09:40:49 -08:00
Sathya Gunasekaran 6ea0b6a42e [alias] Don't alias primitives 2023-01-16 15:34:21 +00:00
Lauren Tan 325987d744 Delete old CompilerError module
This was a carryover from the old architecture; we can remove it now to get rid 
of the indirection.
2023-01-12 19:35:19 -05:00
Sathya Gunasekaran ce7cab4eee [hir] Parse and codegen FunctionExpression 2023-01-09 18:22:32 +00:00
Sathya Gunasekaran b8fd4680b1 [hir] Move inference passes to separate folder 2023-01-04 21:11:37 +00:00