Commit Graph
19463 Commits
Author SHA1 Message Date
Jan Kassens 379dd741e9 [www] set enableTrustedTypesIntegration to false (#25997)
This isn't configured to a dynamic value on www, so hardcode here to
false.
2023-01-13 16:02:24 -05:00
Sathya Gunasekaran b1eb22d941 [be] Don't show duplicate codegen tab
The JS tab and the codegen tab are the same.
2023-01-13 16:33:04 +00:00
Sathya Gunasekaran ddc135cf40 [be] Type CompilerPipeline as Generator 2023-01-13 16:26:09 +00:00
Sathya Gunasekaran d25c2d0d58 [be] Make ts emit ES2015
This gives allows us to use generators without failing type checking.
2023-01-13 16:26:04 +00:00
Lauren Tan 7c65f62c27 Collect bailouts in BuildHIR::lowerStatement
Remove invariants and collect all errors
2023-01-13 16:14:07 -05:00
Lauren Tan 73f09248fb Add Result
Adds a direct translation of Rust's Result type, for later use in BuildHIR and 
possibly other passes
2023-01-12 19:35:20 -05: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
Andrey Lunyov 489d00fa61 [cleanup] Remove warnAboutDeprecatedLifecycles feature flag (#25992)
This `warnAboutDeprecatedLifecycles` is always true, and should be safe
to remove.
2023-01-12 16:57:14 -05:00
Joe Savona 321d7b7d00 [be] Clean up public exports
Cleans up the public exports for the package itself: 

* `parseFunctions()` was only used in playground, so this moves the definition 
there. I had to update playground's dependencies to ensure the babel version 
matched. 

* Flattens away the `HIR` const in the export, and exports just 4 functions all 
at the top-level: `run()`, `compile()`, `printHIR()`, and 
`printReactiveFunction()`. 

This will make it very easy to split the core compiler into a separate package 
from the babel plugin, though i'm not sure it's worth doing that (yet).
2023-01-12 12:16:07 -08:00
Joe Savona bd7e19b85f Codegen is from ReactiveFunction->AST only
Other than BuildReactiveFunction (HIR -> ReactiveFunction), Codegen.ts was the 
only other remaining place that we use HIRTreeVisitor. However, we've already 
switched the compiler to use the new form of codegen, 
CodegenReactiveFunction.ts. This PR extracts the shared code from Codegen.ts 
into the latter, and deletes the unused bits of Codegen.ts which relied on the 
visitor API. 

This now frees us up to merge BuildReactiveFunction and HIRTreeVisitor, removing 
all the complexity of the visitor trait and type params. 

Note that the `ReactiveFunction` data type can represent non-reactive functions. 
So we can still compile non-React code after this change, the pipeline is `AST` 
-> (BuildHIR) -> `HIR` -> (BuildReactiveFunction) -> `ReactiveFunction` -> 
(CodegenReactiveFunction) -> `AST`. Which is the exact sequence I mapped out at 
the start of this project ;-) (happy that worked out!)
2023-01-12 11:49:47 -08:00
Joe Savona da21e9c525 Switch to new BuildReactiveFunction passes 2023-01-12 11:06:40 -08:00
Joe Savona a40ade1e61 Fixes, identical output in new version 2023-01-12 09:43:17 -08:00
Joe Savona 919f193934 MergeOverlappingScopes visits value block final values 2023-01-12 09:12:11 -08:00
Joe Savona 99dcf03852 AlignBlockScopes visits value block final values 2023-01-12 09:12:08 -08:00
Joe Savona 09246207c7 Value block final value has an InstrId 2023-01-12 09:12:01 -08:00
Joe Savona df8945b684 Visit terminal operands during alignment 2023-01-12 09:11:58 -08:00
Joe Savona 9e549e9417 Fork HIRTreeVisitor to specialize it for ReactiveFunction conversion 2023-01-12 09:11:54 -08:00
Sebastian Silbermann 555ece0cd1 Don't warn about concurrently rendering contexts if we finished rendering (#22797)
Closes https://github.com/facebook/react/issues/22796
2023-01-12 13:17:15 +01:00
Joe Savona 46024acb82 MergeOverlappingReactiveScopes (rewritten against ReactiveFunction)
See the background in #982. This PR reimplements part of InferReactiveScopes, 
merging overlapping reactive scopes, but against ReactiveFunction instead of the 
HIR.
2023-01-11 14:04:51 -08:00
Joe Savona 2358d9f01f AlignReactiveScopesToBlockScopes (rewritten against ReactiveFunction)
See the background in #982. This PR reimplements part of InferReactiveScopes, 
aligning reactive scopes to block boundaries, but against ReactiveFunction 
instead of the HIR.
2023-01-11 14:04:48 -08:00
Joe Savona 87d70b9129 BuildReactiveBlocks to construct scopes in ReactiveFunction
The primary goal of this stack is to change HIRTreeVisitor to make it easier to 
handle value blocks. That's complicated by the fact that the visitor is a 
general-purpose visitor, used in several analysis passes including 
BuildReactiveFunction (which translates HIR->ReactiveFunction while also 
grouping instructions into scopes) and InferReactiveScopes (which is actually 
two passes, one to align scopes to block boundaries, one to merge overlapping 
scopes). The long-term goal then is as follows: 

1. Make BuildReactiveFunction transform HIR->ReactiveFunction but _without_ 
reactive scopes. 

2. Align scopes to block boundaries, but rewritten to operate on 
ReactiveFunction 

3. Merge overlapping scopes, again rewritten to operate on ReactiveFunction 

4. Group statements within ReactiveFunction into ReactiveScopeBlocks (today this 
occurs when constructing the ReactiveFunction). 

This PR implements 1 and 4. Because the implementation is incomplete this would 
break the whole compiler, so for now both versions are still around. By default 
compilation uses the old pipeline, but if a feature flag is enabled we use the 
new version. The plan is to incrementally fix up the new version of the passes 
in this stack, and then cutover: removing the flag and the old version of the 
passes.
2023-01-11 14:04:45 -08:00
Jan Kassens 0fce6bb498 [cleanup] remove feature flags warnAboutDefaultPropsOnFunctionComponents and warnAboutStringRefs (#25980)
These feature flags are fully rolled out and easy to clean up. Let's
remove them!
2023-01-11 12:19:46 -05:00
Jan Kassens 7002a6743e [cleanup] remove unused values from ReactFeatureFlags.www-dynamic (#25575)
These values are never imported into `ReactFeatureFlags.www.js`, so
they're unused:
- `allowConcurrentByDefault`
- `consoleManagedByDevToolsDuringStrictMode`

These values are never set in the WWW module
(https://fburl.com/code/dsb2ohv8), so they're always `undefined` on www:
- `createRootStrictEffectsByDefault`
- `enableClientRenderFallbackOnTextMismatch`
2023-01-10 23:26:01 -05:00
Tianyu Yao fb324faf8a Test case for stack overflow in ReactFizzServer (#25971)
SSR currently stack overflows when the component tree is extremely large
2023-01-10 16:53:16 -08:00
Joe Savona a4fc975340 Scaffolding for LogicalTerminal 2023-01-10 13:49:57 -08:00
Sathya Gunasekaran f9ecc96bf3 [hir] Update mutable range of operands during LeaveSSA
It's not enough to only update the mutable range of the canonical id created 
instead of the phi but we need to update the mutable range of each of the 
operands of the phi as well to account for the fact that the phi could've been 
mutated later. 

The operands are updated only if the phi is mutated later. Otherwise these 
operands can be cached in their blocks. 

Fixes https://github.com/facebook/react-forget/issues/978
2023-01-11 15:17:14 +00:00
Sathya Gunasekaran 986c95bc09 [hir] Add test case for incorrect memoisation of mutated objects
In this case, x should not be cached within the if or else blocks as it is 
mutated later.
2023-01-11 15:17:13 +00:00
Sathya Gunasekaran ed63dba739 [hir] Print MutableRange in lvalue
This is admittedly a little noisy but super valuable when debugging.
2023-01-11 15:08:37 +00:00
Sathya Gunasekaran bbba752e98 [typer] Add type inference for Phis 2023-01-11 11:30:58 +00:00
Sathya Gunasekaran 1910ede500 [typer] Add PhiType to represent Phis 2023-01-11 11:30:58 +00:00
Sathya Gunasekaran 0c3cfbdd36 [typer] Add type to Phi 2023-01-11 11:30:57 +00:00
Jan Kassens a48e54f2b7 [cleanup] remove old feature flag warnAboutDeprecatedLifecycles (#25978)
This feature flag was always set to true, we can easily clean it up.
2023-01-10 15:30:42 -05:00
Joe Savona 27b37341e5 Playground uses run() to automatically sync w compiler passes
Changes playground to use the modified `run()` function of the compiler, polling 
the generator and building up a Map of tabs automatically based on the passes 
that the compiler runs. This means tabs are always derived from the current 
state of the compiler and we can never forget to add a pass. 

<img width="1497" alt="Screen Shot 2023-01-10 at 11 06 03 AM" 
src="https://user-images.githubusercontent.com/6425824/211639442-da421f73-e19e-4b63-9f33-0ce5a68cceb7.png"> 

Note the inclusion of some recently added passes that weren't added to the 
playground — which was my fault but only bc i intended to ship this PR soon :-)
2023-01-10 11:05:32 -08:00
Joe Savona 7751202433 Make CompilerPipeline a generator
Turns CompilerPipeline into two functions: 

* `run()` is a generator and yields values that are a disjoint union of either 
AST/HIR/ReactiveFunction along with a name for that step. The idea is to use 
this in the playground so that it always matches the exact steps for 
compilation. I'll update playground in a follow-up. 

* `compile()` is ast in, ast out, and uses `run()` under the hood.
2023-01-10 10:15:45 -08:00
Joe Savona f3168d020f Distinguish regular/value blocks 2023-01-10 09:37:33 -08:00
Jan Kassens 0f4a835966 Remove duplicate JSResourceReferenceImpl mock (#25976)
This mock exists in 2 directories (with identical implementation) and
Jest just picks one at random. This removes one which makes it at least
deterministic and fixes a Jest warning on startup.

It existed in these 2 places:
-
`packages/react-server-dom-relay/src/__mocks__/JSResourceReferenceImpl.js`
-
`packages/react-server-native-relay/src/__mocks__/JSResourceReferenceImpl.js`
(removed)
2023-01-10 10:32:59 -05:00
Jan Kassens c49131669b Remove unused Flow suppressions (#25977)
These suppressions are no longer required.

Generated using:
```sh
flow/tool update-suppressions .
```
followed by adding back 1 or 2 suppressions that were only triggered in
some configurations.
2023-01-10 10:32:42 -05:00
ChrisandJan Kassens afe6521e13 Refactor: remove useless parameter (#25923)
## Summary

I was reading the source code of `ReactFiberLane.js` and I found the
third parameter of the function markRootPinged was not used. So I think
we can remove it.

## How did you test this change?

There is no logic changed, so I think there is no need to add unit
tests. So I run `yarn test` and `yarn test --prod` locally and all tests
are passed.

Co-authored-by: Jan Kassens <jkassens@meta.com>
2023-01-09 23:25:02 -05:00
Hoikan 1253462ea4 Refactor: Reuse variable "remoteRepoDir" (#25740)
Reuse variable `remoteRepoDir` , same with `join(__dirname, 'remote-repo')`.
2023-01-09 22:59:38 -05:00
Joe Savona dce5371763 Constant propagation/folding
Implements constant propagation/constant folding for a conservative subset of 
the language. The approach is described in detail in the comments in the file 
itself, a key note here is that this pass currently emits what looks like 
garbage: 

``` 

// input 

const x = 1; 

const y = x + 1; 

// output 

const x = 1; 

2; // <---- you'll see a bunch of lines like this 

const y = 2; 

``` 

These useless lines occur where previously there was a temporary getting 
calculated that was used later (so we saved it until it was used), but now it 
isn't used later so we just emit it in-place. Dead code elimination (DCE) can 
eliminate these and other useless statements later. 

Note that a key motivation for implementing this pass is to reduce memoization 
blocks to what is strictly required for dynamic computations. Why memoize at 
runtime when we compute at build time?
2023-01-09 15:30:20 -08:00
Sathya Gunasekaran 6f9c9cf9ea [hir] Make lambdas dependencies be a list of Places
This lets HIR understand and rename dependencies correctly.
2023-01-10 16:06:55 +00:00
Jan Kassens 34464fb16c Upgrade to Flow 0.196.3 (#25974)
After the previous changes these upgrade are easy.

- removes config options that were removed
- object index access now requires an indexer key in the type, this
cause a handful of errors that were fixed
- undefined keys error in all places, this needed a few extra
suppressions for repeated undefined identifiers.

Flow's
[CHANGELOG.md](https://github.com/facebook/flow/blob/main/Changelog.md).
2023-01-09 17:52:42 -05:00
Jan Kassens e2424f33b3 [flow] enable exact_empty_objects (#25973)
This enables the "exact_empty_objects" setting for Flow which makes
empty objects exact instead of building up the type as properties are
added in code below. This is in preparation to Flow 191 which makes this
the default and removes the config.

More about the change in the Flow blog
[here](https://medium.com/flow-type/improved-handling-of-the-empty-object-in-flow-ead91887e40c).
2023-01-09 17:00:36 -05:00
Jan Kassens 0b4f443020 [flow] enable enforce_local_inference_annotations (#25921)
This setting is an incremental path to the next Flow version enforcing
type annotations on most functions (except some inline callbacks).

Used
```
node_modules/.bin/flow codemod annotate-functions-and-classes --write .
```
to add a majority of the types with some hand cleanup when for large
inferred objects that should just be `Fiber` or weird constructs
including `any`.

Suppressed the remaining issues.

Builds on #25918
2023-01-09 15:46:48 -05:00
Sathya Gunasekaran 346ecb27fe [hir] Gather dependencies for lambdas 2023-01-09 18:22:35 +00:00
Sathya Gunasekaran ce7cab4eee [hir] Parse and codegen FunctionExpression 2023-01-09 18:22:32 +00:00
Joe Savona 57ea3b7e8a Merge consecutive blocks
See the previous PR for context, this PR adds a new pass to merge consecutive 
blocks.
2023-01-09 13:04:33 -08:00
Joe Savona 7a7538920e Broken test for labeled statements
When we convert a LabeledStatement to HIR we can end up emitting "consecutive" 
blocks, ie where there are two blocks such that control flow will always go from 
from one block to the other, with no other way to reach the second block but 
through the first. Example: 

```javascript 

label: { 

foo(); 

break label; 

} 

bar(); 

``` 

Converts to 

``` 

bb0: 

foo() 

goto bb1: 

bb1: 

bar(); 

... 

``` 

Ideally in this case we would merge these into a single block: 

* When debugging, the extra goto makes it look like there is conditional control 
flow when there isn't. If the code is consecutive it's easier to understand that 
if it's a single block. 

* Conversion from HIR -> AST relies on consecutive code all being in a single 
block, so this breaks codegen (we never visit the goto target since all gotos 
are assumed to be safe to convert to a break or continue). 

This PR adds a failing test case, the next PR fixes it.
2023-01-09 13:04:30 -08:00
Joe Savona d8d5fe989c [be] Improvements to shrink/markInstructionIds 2023-01-09 10:06:03 -08:00
Joe Savona 0abc420c78 [be] Preds/phis use BlockId since blocks may change
Phi operands and Block predecessors currently use a `BasicBlock` reference 
rather than the BlockId. This diverges from other places (like terminals) where 
we use an id and not a direct object reference. Especially since blocks may get 
rewritten or pruned, it's a bit cleaner to use the block id in these places.
2023-01-09 09:22:43 -08:00