Commit Graph

402 Commits

Author SHA1 Message Date
Joe Savona 894eadfa67 [valueblocks] For.update is a proper value block 2023-01-31 13:39:39 -08:00
Joe Savona 6930b5f77e [valueblocks] For.test is a proper value block 2023-01-31 13:39:39 -08:00
Joe Savona 90e1265442 [valueblocks] While.test is a proper value block
Changes ReactiveWhileTerminal’s test to use the new value block representation. 
This means logical and condition expressions will work as while test values now.
2023-01-31 13:39:38 -08:00
Joe Savona 50f300bc92 [valueblocks] Update some passes to use the new visitor
Updates some passes from ReactiveScopes/ to use the visitor added in the 
previous PR. The +124/-354 line count on this diff tells the story  — the new 
visitor avoids a lot of boilerplate and helps focus on the logic not the 
traversal. 

Note that there are a few passes which transform the function such as 
adding/removing scopes. A follow-up will extend the visitor to support that and 
convert the remaining passes.
2023-01-31 13:39:38 -08:00
Joe Savona 400bf4588c [valueblocks] More general visitor for ReactiveFunctions
This adds a truly general-purpose visitor pattern for ReactiveFunction, modeled 
on what's worked well in Relay Compiler. All types of node that have children 
get a visitFoo/traverseFoo pair of functions. By default the visitFoo() function 
delegates to the traverseFoo() function, but the visit variant is meant to be 
overridden and can delegate to the traverseFoo() variant — this gives you 
precise control so that you can save/restore state before/after traversing 
children. 

Probably the only interesting thing is that visitLValue() does not call 
visitPlace() by default though it technically could. So far that is making sense 
in the passes i converted. 

Note that once all passes are updated to use this, i'll delete the other visitor 
helpers for ReactiveFunction.
2023-01-31 13:39:37 -08:00
Joe Savona 149353badb [valueblocks] Support sequence expressions (comma operator) 2023-01-31 13:39:37 -08:00
Joe Savona d6505572cb [valueblocks] Disallow AssignmentExpression in value blocks (temporarily)
There's a bug with assignment expression in normal value blocks due to LeaveSSA. 
Until that's resolved i'm temporarily distinguishing "loop" blocks and "value" 
blocks, and disallowing assignment expressions in value blocks specifically.
2023-01-31 13:39:36 -08:00
Joe Savona 8c13c91f27 [valueblocks] ternary tests showing assignment bug
A ternary that reassigns the same variable in both branches causes some 
weirdness with LeaveSSA, this PR just adds the failing case.
2023-01-31 13:39:36 -08:00
Joe Savona acd227440e [valueblocks] Support conditional expressions (ternary)
Support conditional expressions from AST -> HIR -> ReactiveFunction -> AST. This 
also helps make the patterns for value block handling more clear, so i was able 
to extract some reusable logic in the HIR -> ReactiveFunction conversion phase.
2023-01-31 13:39:35 -08:00
Joe Savona dc7ac6fea4 [valueblocks] Scaffolding for ternary terminals
Core representation for terminals, without the lowering and conversion logic.
2023-01-31 13:39:34 -08:00
Joe Savona aca0e27012 [valueblocks] split working test and aliasing bug case 2023-01-31 13:39:34 -08:00
Joe Savona 096482e5cb print mutable ranges on every place
useful for debugging
2023-01-31 13:39:33 -08:00
Joe Savona 95642c4421 [valueblocks] Printing for LogicalValue/SequenceValue 2023-01-31 13:39:33 -08:00
Joe Savona 86ffcde8ed [valueblocks] Handle compound RHS for logicals
The previous PR handled the case where the LHS of a logical was compound, but 
didn't handle compound RHS values. This is fixed now.
2023-01-31 13:39:32 -08:00
Joe Savona d4acc7efa6 [valueblocks] Convert logical terminal to ReactiveValue
Implements the conversion from LogicalTerminal into a ReactiveLogicalValue (and 
ReactiveSequenveValue if necessary). The implementation is a bit rough, i clean 
it up in subsequent PRs which revealed parts of the logic that could be shared w 
ternaries.
2023-01-31 13:39:32 -08:00
Joe Savona bb8ae86c24 [valueblocks] ReactiveFunction repr for logical expressions
Extends ReactiveInstruction's value type to be a regular InstructionValue *or* a 
LogicalValue. LogicalValue is operator, left, and right. It's really convenient 
that we've already distinguished Instruction/ReactiveInstruction now — while the 
_helpers_ here are updated to handle this new value type, the types ensure that 
HIR can never encounter a LogicalValue. 

The actual conversion of logical terminals into this value is complex and is 
later in the stack.
2023-01-31 13:39:31 -08:00
Joe Savona c6a066af83 [valueblocks] Lower logical expressions into logical terminals
Changes the lowering for LogicalExpression to use the new 'logical' terminal. 
Whereas before we tried to more directly model the semantics of `??` by 
generating an `if (<lhs> != null)`, we now generate a branch terminal that looks 
at the lhs. 

The HIR -> ReactiveFunction construction for logical and branch terminals are 
placeholders while I refactor the ReactiveFunction representation to support 
value blocks.
2023-01-31 13:39:31 -08:00
Joe Savona b1548100d1 [be] Clarify type of value block final value before change
Makes the type of the final value of a ValueBlock more precise, prior to 
changing it
2023-01-31 13:39:30 -08:00
Lauren Tan e48b615598 [playground] Fix header when horizontal scrolling
Fixes a minor annoyance 

Before 

![Screenshot 2023-01-31 at 10 39 06 
AM](https://user-images.githubusercontent.com/1390709/215806108-f3b084d3-c693-404b-a9b3-785d0f15c332.png) 

After 

![Screenshot 2023-01-31 at 10 33 15 
AM](https://user-images.githubusercontent.com/1390709/215804818-c94a5905-e278-4380-af44-6ab34ac95ff3.png)
2023-01-31 10:36:31 -05:00
Lauren Tan 3b4f41b58d [ez] Make dev mode more obvious in playground
It's easy to confuse your local browser tab with main, this modifies a 

few colors and labels to make it more obvious 

![Screenshot 2023-01-30 at 5 05 18 
PM](https://user-images.githubusercontent.com/1390709/215606089-78e5c874-263e-46e9-a99d-3d863bdc4432.png)
2023-01-30 17:03:59 -05:00
Lauren Tan 213ed2d6d0 [ez] Wrap output cols to prevent nested h-scroll
![Screenshot 2023-01-30 at 1 03 46 
PM](https://user-images.githubusercontent.com/1390709/215558010-49d3ddf4-3dee-418e-9595-790e720bad22.png)
2023-01-30 13:04:39 -05:00
Sathya Gunasekaran 04fb507876 [hir] Remove broken support for ForOf, ForIn, DoWhile 2023-01-30 19:12:43 +00:00
Lauren Tan 019f069778 Fix not being able to scroll horizontally 2023-01-30 11:37:28 -05:00
Lauren Tan f0d64064a9 Support partial compilation in playground
This adds support in the playground for best effort compilation: if any 

passes have errors, we'll try to render as many successful tabs leading 

up to the pass with an error. 

Also contains some styling updates 

![Screenshot 2023-01-27 at 2 18 06 
PM](https://user-images.githubusercontent.com/1390709/215222635-59b42555-f1f3-4fc0-b1cd-3959946df6da.png) 

![Screenshot 2023-01-27 at 2 18 54 
PM](https://user-images.githubusercontent.com/1390709/215222636-4c0275fd-a95b-4f0f-946a-258ad8b27722.png) 

![Screenshot 2023-01-27 at 5 03 02 
PM](https://user-images.githubusercontent.com/1390709/215222637-92a8e459-173a-41ae-be9f-0cc0d54479d0.png)
2023-01-30 10:36:35 -05:00
Lauren Tan be4058057c Bailout TaggedTemplateExpressions instead of invariant 2023-01-30 10:36:34 -05:00
Lauren Tan 545e53c428 Use CompilerErrors to record errors
This moves the bailout recording mechanism into a separate CompilerErrors class 
instead of repurposing HIRBuilder. This is to allow other passes to also record 
errors instead of immediately throwing.
2023-01-30 10:29:14 -05:00
Sathya Gunasekaran c803558b2a [hir] Parse object pattern params 2023-01-26 16:40:08 -05:00
Sathya Gunasekaran 41e8088e8c [hir] Try to resolve a dep into a property load only if it's a temporary. 2023-01-26 16:40:07 -05:00
Sathya Gunasekaran 978215eae6 [test] Add test that resolves property loads to expanded places incorrectly
Ideally this should happen only for temporary places containing property loads.
2023-01-26 13:38:55 -05:00
Lauren Tan 98cb9eff92 Fix playground tabs always showing the same HIR or reactive function
Previously we were storing a pointer to the HIR or ReactiveFunction 

prior to printing, so when we printed them it would always print the 

results of the last pass. This commit changes it so we print them to 

strings when iterating through the compiler pipeline so each snapshot is 

correctly preserved 

![Screenshot 2023-01-26 at 4 34 23 
PM](https://user-images.githubusercontent.com/1390709/214955701-67f4da1e-b12c-432a-ba47-1a29afd91312.png)
2023-01-26 16:33:56 -05:00
Lauren Tan d44538ad96 Stop passing NodePaths to CompilerError
This was causing issues in various places where errors would be stringified. 
Because the inner detail objects would contain a NodePath with circular 
structures this would cause a JSON.stringify error in code outside of our 
control. This change makes it so we always print the codeframe from the NodePath 
and then passing the string.
2023-01-26 13:58:56 -05:00
Joe Savona 4ab8cc6ae9 [valueblocks] Use branch terminal for if/for test blocks
Updates `while` and `for` to use the new branch terminal as their test block 
terminal (IfTerminal is now only meant for if statements).
2023-01-25 17:05:23 -05:00
Joe Savona f88fa006e7 [valueblocks] Scaffolding for branch terminal
Scaffolding for a new 'branch' terminal, which is the lower-level form of 'if' 
meant for use in value blocks. See design at 
https://fb.quip.com/b7N6AjkDcl2a#temp:C:bAO904b0cf06f154de4a7287af6d
2023-01-25 17:05:22 -05:00
Joe Savona 1014727d41 [valueblocks] Specify block type at creation
We need to know the kind of each block (regular or value). Rather than specify 
the kind when closing the block — when we've lost context about why the block 
was created — it's simpler and more accurate to specify the kind when 
creating/reserving the block.
2023-01-25 17:05:22 -05:00
Lauren Tan 840bb6fec2 Add colors to debug logging 2023-01-25 16:15:12 -05:00
Sathya Gunasekaran e6b4988b1e [hir] Infer UnaryExpression as non allocating 2023-01-25 11:11:16 -05:00
Sathya Gunasekaran 9eb9071aed [typer] Add type inference for unary expr 2023-01-25 11:11:16 -05:00
mofeiZ 9bd67099d7 [prettier] detect changed files from relative dir
Previously, `yarn prettier` didn't write changed files since `glob` produced 
paths relative to cwd and `git diff --name-only` produced paths relative to git 
root directory. 

This changes `git diff --name-only` to `git diff --name-only --relative`
2023-01-25 15:16:39 -05:00
Sathya Gunasekaran f83ff2feda [hir] Parse UnaryExpression 2023-01-25 11:11:16 -05:00
mofeiZ b00963ffde [playground] Handle invariant violation errors
playground currently hard crashes when we hit an invariant violation 

<img width="1104" alt="image" 
src="https://user-images.githubusercontent.com/34200447/214615036-dbe307d8-132d-4186-a8ab-6fcaf69801d1.png"> 

[playground 
link](https://0xeac7-forget.vercel.app/#eyJzb3VyY2UiOiJcbmZ1bmN0aW9uIHVzZUJhcihwcm9wcykge1xuICBwcm9wcyA9IG51bGw7XG4gIGxldCB5LCB6O1xuXG4gIGlmIChwcm9wcy54KSB7XG4gICAgbGV0IHkgPSB1c2VGb28ocHJvcHMuYS5iKTtcbiAgICB3aGlsZSAoYmFyKCkpIHtcbiAgICAgIGlmIChwcm9wcy55KSB7XG4gICAgICAgIHogPSBiYXooKTtcbiAgICAgIH1cbiAgICB9XG4gIH1cblxuICByZXR1cm4gW3ksIHpdXG59In0=) 

This should fix that
2023-01-25 11:23:09 -05:00
Lauren Tan 47da50dfe8 [ez] Fix typo 2023-01-25 10:20:53 -05:00
mofeiZ 62b7526929 [hir] Handle OptionalMemberExpression syntax
(Implemented as per discussions with @gsathya ) 

Handle OptionalMemberExpression by adding an 'optional' flag to `PropertyLoad` 
instruction, which is set during `BuildHIR` and read during 
`CodegenReactiveFunction`.
2023-01-25 10:16:21 -05:00
Sathya Gunasekaran 79d53f9117 [hir] Parse and codegen TaggedTemplateExpression
Basic support to parse relay fragments
2023-01-24 16:41:00 -05:00
Lauren Tan cd45341920 yarn install 2023-01-24 14:05:14 -05:00
Lauren Tan 9d935db383 Render error markers in playground
Additionally with this commit we now support multiple top level 

functions 

![Screenshot 2023-01-24 at 12 01 34 
PM](https://user-images.githubusercontent.com/1390709/214359278-7160b612-094d-4498-918d-944d30d61366.png) 

![Screenshot 2023-01-24 at 12 01 21 
PM](https://user-images.githubusercontent.com/1390709/214359275-d776c416-badb-4989-8952-dec1b1f3f7ed.png)
2023-01-24 12:44:51 -05:00
Lauren Tan 109d7ba980 Refactor CompilerError
This commit repurposes CompilerError to represent an aggregate of error details 
accumulated during HIR lowering. It also fixes the playground to correctly 
render errors again.
2023-01-24 12:44:51 -05:00
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