Commit Graph

356 Commits

Author SHA1 Message Date
Lauren Tan 3da8d52a0f Consistency pass for error messages in BuildHIR 2023-01-24 12:44:51 -05:00
Sathya Gunasekaran 8f169574c7 [test262] Set language as typescript 2023-01-24 11:02:54 -05:00
Sathya Gunasekaran 8041b0b0d5 [λ] Parse and codegen concise arrow expressions 2023-01-24 10:47:49 -05:00
Sathya Gunasekaran 9aed0fc6b1 [babel] Add flow support
Check if there's a pragma to toggle flow parsing
2023-01-24 10:21:25 -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
Sathya Gunasekaran ee3a88f20f [λ] Parse and codegen arrow function exprs 2023-01-23 17:39:37 -05:00
mofeiZ 3ba90a7f9c Inline hasNode check (hack)
www currently on an older version of babel
2023-01-23 16:08:01 -05:00
mofeiZ 16169bec07 Redo patch prettier
reverts / redos #1055 

(accidentally merged changes from another PR in #1055)
2023-01-23 16:03:49 -05:00
mofeiZ 07cda62430 [prettier] Patch prettier to write modified TS files (#1055) 2023-01-23 15:57:11 -05:00
Sathya Gunasekaran 3927281fe4 [λ] Re run SSA on function expr
Functions can capture variables declared after the definition of the function. 
This re runs SSA to map the captured identifiers to the new SSA identifiers if 
available.
2023-01-23 13:20:33 -05:00
Sathya Gunasekaran 123d024af7 [λ] Add test for function expr passed to jsx
Function exprs become frozen when captured by jsx.
2023-01-20 19:44:32 +00:00
Sathya Gunasekaran 294b6c752d [plugin] Add default export to forget 2023-01-23 14:36:54 -05:00
Lauren Tan 8e08334a42 Specify sourceType "module" in hir-test and playground
This was preventing the playground and fixture tests from being able to compile 
an ExportDefaultDeclaration
2023-01-23 13:11:35 -05:00
Lauren Tan b44f507c92 [test262] Strip codeframes from Forget errors so results are grouped
correctly
2023-01-20 11:47:11 -05:00
Lauren Tan 44beb3c023 Collect bailouts in BuildHIR::lowerAssignment 2023-01-20 11:47:11 -05:00
Lauren Tan 9ed6977c48 Collect bailouts in BuildHIR::lowerJsxElement 2023-01-20 11:47:10 -05:00
Lauren Tan 4b3b498e37 Collect bailouts in BuildHIR::lowerJsxElementName 2023-01-20 11:47:10 -05:00
Lauren Tan 9697e15bd5 Collect bailouts in BuildHIR::lowerMemberExpression 2023-01-20 11:47:09 -05:00
Lauren Tan b2983571f2 Collect bailouts in BuildHIR::lowerExpression
Mostly mechanical changes to lowerExpression to push an error to HIRBuilder 
rather than invariant.
2023-01-20 11:47:09 -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
Lauren Tan b3fedd3273 Fix import path to ReactForgetBabelPlugin
This broke jest in watch mode
2023-01-19 13:33:32 -05:00
Sathya Gunasekaran 7c73f51139 [hir] Define function name only if it exists 2023-01-19 18:39:23 +00:00
Sathya Gunasekaran da6d372c3a [hir] Store env in HIRFunction
The env is specific to the HIR function anwyays. It's not very useful outside 
the HIRFunction.
2023-01-19 18:39:19 +00:00
Sathya Gunasekaran 0a60bf2071 [ts] Make ts emit source maps 2023-01-19 18:39:14 +00:00
Sathya Gunasekaran a5b245b17d [hir] Fix typescript warnings 2023-01-19 12:07:05 +00:00
Joe Savona d295bb4516 Fix scope merging in MergeOverlappingReactiveScopes
When `MergeOverlappingReactiveScopes` identified scopes to be merged, it was 
currently (oops, my bad) updating the _existing_ scope's id and range. Later, 
PropagateScopeDependencies marks outputs of a scope by updating that 
identifier's scope instance — so if that scope instance isn't shared, then the 
output is lost. This PR fixes MergeOverlappingReactiveScopes to correctly update 
all operands for a scope to have the same scope instance.
2023-01-19 10:10:21 -08:00
Joe Savona 7f7727d7e5 Consolidate logic in MergeOverlappingScopes prior to fix
Small refactor to consolidate visiting operands and their scopes, used in the 
follow-up PR.
2023-01-19 10:10:20 -08:00
Lauren Tan 6174c85ee9 [oops] Use correct import path in test262-preprocessor 2023-01-19 12:29:49 -05:00
Lauren Tan 40df4a8a86 [ez] Update test262-preprocessor to use the same config as hir-test 2023-01-19 11:37:50 -05:00
Lauren Tan 32a83374be Format CompilerErrors with Babel codeframes 2023-01-19 11:37:49 -05:00
Lauren Tan 60698e63c6 Re-emit unexpected hir-test error rather than a new one
Makes debugging a little easier as the previous console.error would be logged 
out of band with the jest error message. And the jest error would be missing the 
error stack.
2023-01-19 11:37:49 -05:00
Lauren Tan b98e87aa63 Use BabelPlugin in hir-test 2023-01-19 11:37:48 -05:00
Lauren Tan 717719b8ea Fix infinite loop in BabelPlugin
After some painful debugging I isolated the infinite loop when attempting to use 
the BabelPlugin in hir-test rather than manually parsing and traversing it. The 
issue is that in the BabelPlugin we were replacing the original 
FunctionDeclaration with a new one, which would add it to Babel's traversal 
queue. This would effectively create an infinite loop where we would try to 
optimize a function that was already compiled by Forget (aside: _should_ running 
the compiler multiple times on code work?). 

To get around this we can just call the handy `skip` method on the new 
FunctionDeclaration to tell Babel to stop traversing it. I'm also moving the 
scope check here because I'll remove it from hir-test in a later commit.
2023-01-19 10:10:56 -05:00
Sathya Gunasekaran f42c51b971 [λ] Support member expressions in lambdas
Lower member expression if the receiver is in scope. Skip the remaining path 
before capturing so we don't recurse down the identifiers in the member 
expression.
2023-01-19 12:13:35 +00:00
Sathya Gunasekaran ef5636c25d [λ] Use lowerExpression to create captured identifier 2023-01-19 12:13:34 +00:00
Lauren Tan 50d27c325a Allow tests to be skipped with @skip
Also remove old filename based test directive, since the comment based one is 
much easier to use
2023-01-18 10:58:50 -05:00
Lauren Tan 23a044e406 Record more errors in BuildHIR::lowerStatement
Captures other kinds of statements that we're lowering to OtherStatements as 
TODO errors
2023-01-18 10:58:50 -05:00
Joe Savona de83adc739 [be] Skip debug logging if content has not changed
Avoids printing debug information if it exactly matches what was last printed. 
This means when debug printing (eg with `@only`) you'll see things like: 

``` 

BuildReactiveFunctions: 

...debug view... 

FlattenReactiveLoops: (no change) 

PropagateScopeDependencies: 

...debug view... 

``` 

Which saves time figuring out if something changed in a given pass.
2023-01-17 16:00:42 -08:00
Joe Savona 8a15b65e1a [be] Reorder PruneUnusedLabels pass
This pass can run later, rather than right in between two passes that affect 
scope creation.
2023-01-17 16:00:39 -08:00
Joe Savona 0391405530 [be] Print implicit break/continue
When debug printing `ReactiveFunction`, clarifies which break/continue are 
implicit.
2023-01-17 16:00:36 -08:00
Joe Savona 2e501b0f01 Rename variables during BuildHIR
Per design discussion, this PR changes BuildHIR to maintain the invariant that, 
for each distinct variable in the input, that all references to that variable in 
the HIR will have the same unique `name` _and_ same unique `id`. Phrased 
differently: Identifiers with the same id will have the same name and 
vice-versa. 

This isn't an invariant we maintain throughout compilation — SSA form changes 
the `id`s — but crucially, ensuring that the `name` is also unique allows us to 
understand later which identifiers referred to the same original variable and 
which were different. 

Follow-up PRs will ensure that we maintain variable identifiers in the output as 
well, in all cases except shadowing (and for shadowing, we'll rewrite 
identifiers inside lambdas).
2023-01-17 09:40:50 -08: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
Joe Savona 4a70aa7faf Make implicit break/continue explicit in ReactiveFunction
Previously when converting from HIR -> ReactiveFunction we elided break/continue 
terminals in places where control would implicitly transfer to the 
break/continue target and therefore nothing has to be emitted. The one downside 
of this approach is that it makes scope analysis a bit trickier. We want to 
close scopes once we see an instruction id past the end of the scope's range, 
but these implicit breaks were causing us to miss some instruction ids. We 
compensated for this, but it's helpful to keep the representation explicit and 
discard these terminals later in codegen.
2023-01-17 09:40:48 -08:00
Joe Savona 2c95cdb431 Collapse BuildReactiveFunction/TreeVisitor
Collapses HIRTReeVisitor into BuildReactiveFunction, allowing us to remove the 
generic interface and simplify the code. Note that because the visitor was 
already not attempting to group instructions by scope anymore, the visitor code 
was very straightforward. This is mostly replacing calls to `appendBlock(block, 
instr)` with `block.push(instr)`.
2023-01-17 09:40:47 -08:00
Sathya Gunasekaran 39eb89f65e [hir] Use types to infer constant declarations 2023-01-16 15:34:24 +00:00
Sathya Gunasekaran 6ea0b6a42e [alias] Don't alias primitives 2023-01-16 15:34:21 +00:00
Sathya Gunasekaran ab6a1dbbd4 [λ] Add test for nested function declaration that captures a var 2023-01-14 10:19:40 +00:00
Sathya Gunasekaran 6af9c25300 [test] Run Forget only on top level functions 2023-01-14 10:19:40 +00:00
Sathya Gunasekaran 5fa3d41b22 [λ] Make function expr tests be reactive to input
This lets us memoize more and test function expressions better
2023-01-14 10:19:39 +00:00