Summary:
Release notes: None
Dumping happened before `processCollectedNestedOptimizedFunctions`,
which caused them to not be included. This is being fixed, plus some
minor refactoring to hide implementation details.
Pull Request resolved: https://github.com/facebook/prepack/pull/2568
Differential Revision: D10023363
Pulled By: NTillmann
fbshipit-source-id: 6abe2b5358f23705b501fc818536fb30d42a3b17
Summary:
Release notes: none
All these changes are only internal changes related to React.
This PR adds the `pe-functional-components` benchmark as tests to the React reconciler. The test was taken from: https://github.com/facebook/react/tree/master/scripts/bench/benchmarks/pe-functional-components.
In order to make the server side renderer test pass, a few TODOs had to be filled in (logic was missing) and the JSON logic has to be updated to account for empty strings in children that the compiler merges.
Pull Request resolved: https://github.com/facebook/prepack/pull/2560
Differential Revision: D10008375
Pulled By: trueadm
fbshipit-source-id: 3b39a3e6387e23e17532a2343bd84ebebb7ee9cd
Summary:
Release notes: None
There's no need to re-visit deep value chains in nested generators,
if a value was already visited in a parent generator.
This greatly speeds up certain internal RN scenarios.
Pull Request resolved: https://github.com/facebook/prepack/pull/2562
Differential Revision: D10001612
Pulled By: NTillmann
fbshipit-source-id: a4f66b1a4835121cef4e3bc424f507f5b2c843f9
Summary:
Release notes: None
To avoid all kinds of serialization issues, generators should form
a tree, and not a DAG. This is an attempt to establish that.
Pull Request resolved: https://github.com/facebook/prepack/pull/2434
Differential Revision: D9887684
Pulled By: NTillmann
fbshipit-source-id: c11c50c56dcd6eff02bd03448756bf79f6e2c820
Summary:
Release note: none
A large internal test case came up with a situation where an optimized function is rewritten with a version that early binds a yet to be declared value to one of its parameters.
This should probably never happen, so the if condition guarding this code path has been strengthened to prevent this.
Pull Request resolved: https://github.com/facebook/prepack/pull/2558
Reviewed By: trueadm
Differential Revision: D9967064
Pulled By: hermanventer
fbshipit-source-id: bf56872ea42ee8faefc347a6393cdcd9b3c518e9
Summary:
Release notes: none
This fixes#2555.
We were waiting on the wrong thing in the serializer.
Adding regression tests.
Pull Request resolved: https://github.com/facebook/prepack/pull/2556
Differential Revision: D9949808
Pulled By: NTillmann
fbshipit-source-id: a4ef5ece8c5dab6fa579a20dbb35ce7bf794bfc0
Summary:
Release Notes: None
Optimized functions will now be evaluated with the path condition at the time of function closure creation.
Resolves issue #2422
Pull Request resolved: https://github.com/facebook/prepack/pull/2537
Differential Revision: D9886282
Pulled By: cblappert
fbshipit-source-id: cae0282903d639ff0d94d0f4091c6f8ef9ef9a98
Summary:
Release Notes: None
Before, during referentialization, we would always default to the global scope if the value was accessed in more than one optimized function scope. Now we look for the outermost optimized function.
This logic already existed in ResidualHeapSerializer, so I refactored it out into `serializer/utils.js`.
Fixes#2428
Pull Request resolved: https://github.com/facebook/prepack/pull/2544
Differential Revision: D9926077
Pulled By: cblappert
fbshipit-source-id: c4ee6c07c7409534e9be14df25b582078a7ec77c
Summary:
This is a helper for inspecting values at a particular node in the AST. E.g.
```js
let n = global.__abstract ? __abstract("number", "10") : 10;
let x = {foo:1};
let y = {foo:2};
let c = __abstract("boolean", "c");
let i = 0;
let obj = {};
do {
i++;
obj.j = i;
obj.foo = c ? x : y;
} while (i < n);
__debugValue(obj); // Breaks with obj in context
inspect = function() {
return i + " " + obj.j;
};
```
Pull Request resolved: https://github.com/facebook/prepack/pull/2554
Differential Revision: D9922908
Pulled By: sb98052
fbshipit-source-id: dab9cae64a461283d8dec7f0bb7f8fae87a01c78
Summary:
The following test case currently fails:
```js
function F() {
this.a = 1;
this.b = 2;
if (global.__abstract) return global.__abstract(undefined, "undefined");
}
const result = new F();
global.inspect = () => JSON.stringify(result);
```
We hit this bug in our internal React Native bundle. I only added support for `base` construction kinds since the template for `derived` construction kinds would get more complicated.
Pull Request resolved: https://github.com/facebook/prepack/pull/2535
Differential Revision: D9906309
Pulled By: trueadm
fbshipit-source-id: 49a71ceaf30a851075879295e63e98ce7e1bbe2d
Summary: Now that babel 7 is stable we can use caret as we use from other tools (like Metro). `yarn.lock will make sure it does not get updated until we want
Reviewed By: pvdz
Differential Revision: D9861594
fbshipit-source-id: 9d27d9c91f2b4e28d8a3c914e9b578eb9f0dc90e
Summary:
Release notes: User-level stack overflows no longer crash Prepack.
This fixes#2552, and actually a bit more:
- We used to piggy-back on `pushContext` to count stack frames. However, there is no one-to-one correspondance of calls and context, so that wasn't a very good proxy. (In fact, there seem to be calls that don't push a context.) So we now count calls and constructs explicitly.
- Instead of just throwing a `FatalError` when the stack space is exceeded, which in turn causes an invariant violation since there must not be a `FatalError` thrown without a compiler diagnostics having beein issue. Now there is a regular error code PP0045.
Added error handler regression test.
Pull Request resolved: https://github.com/facebook/prepack/pull/2553
Differential Revision: D9889090
Pulled By: NTillmann
fbshipit-source-id: f6f863ee9ef73f258692f215ef75b63b737f5394
Summary:
This change ensures that the code generated via optimized array loop operators is correct in the InstantRender setting. It enables the optimization of such functions when the `--instantRender` option is set. Materialization is prevented by ensuring that post-optimization, objects that are reachable from the function are not mutated. Recoverable errors are issued. We also degrade all InstantRender bailouts to recoverable errors, to facilitate debugging. We add a constraint that optimized functions may not be reused.
Resolves#2451#2448
Pull Request resolved: https://github.com/facebook/prepack/pull/2547
Differential Revision: D9816268
Pulled By: sb98052
fbshipit-source-id: 2112b199de50b80a7a9852a794c082be3bf122e9
Summary:
In support of #2547. Sometimes, it is more desirable (less costly, better for debugging) to flag a warning for a possibly anomalous condition, than to assume that it is anomalous and enforce it as an error. This change exposes warnings that a user upgrades to errors, so that they can then be enforced as such.
Pull Request resolved: https://github.com/facebook/prepack/pull/2548
Differential Revision: D9884632
Pulled By: sb98052
fbshipit-source-id: c47b57a21aa047b0f3fa2672508f8fb23c04942a
Summary:
Release note: none
When a new path condition is added to an existing path conditions object, the negative caches must be cleared since the new condition might allow previously failed implications to now succeed. This was already done in one case, but a few others were missed. The clearing code is now centralized and all cases go through it.
While debugging the internal test case that failed because of the caching mistake, I also realized that PathConditions.implies and PathConditions.impliesNot can profitably deconstruct expressions of the form !x before doing the implication check. This also has the advantage that it eliminates a subtle endless recursion situation in a nicer way than the current code.
I've also added some comments in places that caught my eye during debugging.
Pull Request resolved: https://github.com/facebook/prepack/pull/2549
Differential Revision: D9883127
Pulled By: hermanventer
fbshipit-source-id: 06faa709dfecaa4f98b7d0ce5e1c7a9efb6b805f
Summary:
cc NTillmann
Following up https://github.com/facebook/prepack/issues/2285, website shows the generated coded even when there are some warnings.
Lot of changes because prettier wasn't applied to the files, but I basically only checked for the error buffer containing only items with `severity === 'Warning'` and create the `warning` result type to behave the same than `success` one.
Next step would be to show the code AND warning messages. Either using the same display than error messages or creating a variation of it (changing text color to yellow for example). I can do it if you want.
Let me know if this is what you were looking for.
Have a nice day !
P.S: not sure if this PR was supposed to be into `gh-pages` or `master`. Let me know if that needs to be changed.
Pull Request resolved: https://github.com/facebook/prepack/pull/2528
Differential Revision: D9882040
Pulled By: NTillmann
fbshipit-source-id: bc8266a673e6def023bfa65b93b94ea9c7ad5b1d
Summary:
Release Notes: None
This PR makes it so we no longer report conflicts for child optimized functions reading from values that their parents have written.
Couple of things for discussion:
- This creates somewhat confusing behavior because the child functions will take the concrete value after the parent functions' effects have been applied:
```javascript
(function () {
let obj = {p: 42};
function f() {
obj.p += 3;
function g() { return obj.p; } // Will optimize to `return 47;`
obj.p += 1;
__optimize(g);
obj.p += 1;
return g;
}
__optimize(f);
global.f = f;
})();
```
- This PR creates the Parent/Child relationship based off `AdditionalFunctionEffects.parentAdditionalFunction` which goes off of syntactic nesting of functions instead of nesting of `__optimize` calls as in the issue. I believe basing the nesting off of `__optimize` calls could lead to somewhat unintuitive results (especially considering we store `parentAdditionalFunction` in `AdditionalFunctionEffects` to be the syntactic parent).
I am not sure if it is needed by Instant Render NTillmann? If it is, we may want to consider changing `AdditionalFunctionEffects.parentAdditionalFunction` to be based off of `__optimize` call nesting as well for consistency.
As an example a slight modification on the example above:
```javascript
(function () {
let obj = {p: 42};
function g() { return obj.p; }
function f() {
obj.p += 3;
__optimize(g);
obj.p += 1;
return [g, obj];
}
__optimize(f);
global.f = f;
})();
```
With this PR, we report an error. Based off of `__optimize` nesting, we would optimize `g` to `return 46;`. I would expect to see `return 42;` `return 45;` or `return obj.p;` in this case.
- To resolve the above issues, in the future, we could make any values modified by parent optimized functions into abstract values during evaluation for child optimized functions to force their accesses to be recorded in generators .
Resolves#2351
Pull Request resolved: https://github.com/facebook/prepack/pull/2542
Differential Revision: D9803741
Pulled By: cblappert
fbshipit-source-id: baca233c8de81633332b25f0776ed1a9d6c95a60
Summary:
This can be a possible fix for https://github.com/facebook/prepack/issues/2509
I have removed the `invariant` method call and added a value check as used for the _invariantMode_ option.
`node lib/prepack-cli.js --debugDiagnosticSeverity foo`
will now generate
`Unsupported debugDiagnosticSeverity: foo`
Pull Request resolved: https://github.com/facebook/prepack/pull/2545
Differential Revision: D9800485
Pulled By: hermanventer
fbshipit-source-id: edc24b4a812b4e32f9c48e05a0799bf4af431991
Summary:
Release notes: None
Otherwise, this could cause issues, as path conditions get captured e.g. in generators.
Pull Request resolved: https://github.com/facebook/prepack/pull/2538
Reviewed By: hermanventer
Differential Revision: D9762541
Pulled By: NTillmann
fbshipit-source-id: 4d12681e3921d2c0f10f3c9f3f0702823a2b0d99
Summary:
Release notes: Fixes invariant violation regression when using webpack-prepack-plugin
This fixes#2540.
I didn't actually test it end-to-end webpack-prepack-plugin, would be great if someone could do that. We need some kind of end-to-end test for this to avoid regressions in the future.
Pull Request resolved: https://github.com/facebook/prepack/pull/2541
Differential Revision: D9756803
Pulled By: NTillmann
fbshipit-source-id: 2bded0dcb0a16369f3d3ff41c2f4d5181c75d67c
Summary:
Release note: none
Closes#2435Closes#1829
Join.composeWithEffects composes a forked completion with subsequent effects. When two or more forks could end normally, this could result in shallow copies of the subsequent effects. These were then joined together and applied, so it was mostly OK. The generator of the subsequent effects, however, ended up being joined with itself and thus transformed the generator tree to a DAG, which is not desirable for the serializer.
The new approach is to extract a join condition from the forked completion and using it to join the subsequent effects with a newly constructed empty effects. The condition ensures that the subsequent effects are applied only in situations where the forked completion is not abrupt.
Extracting this condition makes for complicated abstract expressions and this uncovered some existing bugs and limitations that are also addressed in this pull request. As a side effect, path conditions are now longer and the time to compile unrolled loops with conditional abrupt completions inside their bodies has gone up so much that the unroll limit had to be lowered.
Please note that the expected output React tests has changed because of re-ordering. I'm none too sure that this re-ordering is necessarily benign, so please review carefully.
Pull Request resolved: https://github.com/facebook/prepack/pull/2523
Differential Revision: D9623729
Pulled By: hermanventer
fbshipit-source-id: 737096bba54a7a2ad300dc29882ea1b7829ac745
Summary:
Release notes: providing __replaceFunctionImplementation_unsafe built-in
This new built-in allows replacing the method implementation (capture environment, body, ...) of source functions.
As a result, all method calls executed by the Prepack interpreter will be redirected,
and the replacement will carry over to the prepacked code.
Pull Request resolved: https://github.com/facebook/prepack/pull/2533
Reviewed By: hermanventer
Differential Revision: D9693654
Pulled By: NTillmann
fbshipit-source-id: bd28997965e641f58f89f7119fa477c535c0e539
Summary:
Release note: none
This attempts to reduce exponential blowup in the simplifier by doing more caching while computing implications and by imposing a depth limit on the number of simplify and implies calls.
It also tries to make implies and impliesNot more symmetrical, so that things are less ad-hoc.
Pull Request resolved: https://github.com/facebook/prepack/pull/2530
Differential Revision: D9664026
Pulled By: hermanventer
fbshipit-source-id: f7a9135b06298a2b77ad05bf377982a9b37e4ad1
Summary:
Release notes: none
Fixes a bug where `reactFailOnUnsupportedSideEffects` should evaluate to `false` if passed as false. Also fixes a lint issue on `master`.
Pull Request resolved: https://github.com/facebook/prepack/pull/2532
Differential Revision: D9662462
Pulled By: trueadm
fbshipit-source-id: 1ffeea55e55a2bde9f1d44c64ac85d7e1b1727cf
Summary:
- Fixed bugs that could cause generated code to throw
- Improved evaluation of abstract conditionals
- Added CLI options --warnaserror, --diagnosticaserror, --nodiagnostic
- Added full support for React.Children.map mock
- Support constructors that return an object but also throw
Reviewed By: yinghuitan
Differential Revision: D9660870
fbshipit-source-id: 49674fae56538809f6f962e49291be77f3617d2c
Summary:
Release notes:
This adds a `reactFailOnUnsupportedSideEffects` flag for React internal testing with `debug-fb-www` and ignores `try/catch` PP0021 errors for internal testing too. These are intended to be temporary changes purely for internal FB testing.
Pull Request resolved: https://github.com/facebook/prepack/pull/2531
Differential Revision: D9656578
Pulled By: trueadm
fbshipit-source-id: 9339dd8245e5a03d567ca2fd8e24e90152f1e22b
Summary:
Release notes: Fixed bugs that could cause generated code to throw
A refactor of my previous attempt to address #2327, which I had to abandon because it was incompatible with the current implementation of certain modeling primitives. Like the previous version, this PR is an intermediate fix that will be refined in a follow up PR. It consists of three changes:
1) It adds a new helper that discharges values from a union after deriving the abstract value in it if needed.
2) It makes conditionally temporal values safe using a helper called `convertToTemporalIfArgsAreTemporal`.
3) It makes the the abstract and concrete members explicit in the interface to Abstract Concrete Unions. Presently, two code sites make the assumption that the abstract member is the first element of `args`, while all others traverse the list to locate it.
Follow ups to come:
1) Update `convertToTemporalIfArgsAreTemporal` to produce a conditional value left to be simplified by the serializer.
2) Enforce the protocol *temporal args should imply temporal results* more generally (#2489).
Fixes#2327 and #2406
Pull Request resolved: https://github.com/facebook/prepack/pull/2513
Differential Revision: D9636173
Pulled By: sb98052
fbshipit-source-id: 22d63dfb9d0da4b1f6eba4e2f6f88760f5eb03ca
Summary:
Release notes: none
Currently, when don't really fully deal with abstract conditions fully throughout the Prepack codebase and we usually simply leak/emit a temporal to get around them. So this PR aims at tackling many of the code-sites where they are prevalent by using the internal React bundle to find most of them and address them – with the goal of improving evaluation in cases where we run into conditionals.
With this PR, we now try and resolve different parts of the condition, including conditionals such as `||` and `&&`. This allows us to evaluate potentially far more than before when it comes to product code where we inhabit many deep conditionals. These changes also impact `Object.assign` as it triggered an invariant with `getSnapshot` as it never expected a conditional there. This should also fix https://github.com/facebook/prepack/issues/2323.
I've added some tests to show this but here is an example of the output before and after:
```js
// Input
function fn(x, b) {
var a = x ? b : { a: 2 };
return a.a;
}
// Before
var _2 = function (x, b) {
var _3 = {};
_3.a = 2;
var _$0 = (x ? b : _3).a;
return _$0;
};
// After
var _2 = function (x, b) {
if (x) {
var _$0 = b.a;
}
return x ? _$0 : 2;
};
```
For conditional `Object.assign`, the output looks like this (note: we need materializing rather than leaking to better improve the output):
```js
// Input
function fn(x) {
var a = x ? { a: 1 } : { a: 2 };
return Object.assign({}, a, { b: 1 });
}
// Before
var _2 = function (x) {
var _$0 = {
a: 1
};
var _$1 = {
a: 2
};
({}).a = 1;
({}).a = 2;
var _$2 = {
b: 1
};
var _9 = {};
var _$3 = _$9(_9, x ? _$0 : _$1, _$2);
return _9;
};
// After
var _2 = function (x) {
return {
a: x ? 1 : 2,
b: 1
};
};
```
I also took the time to apply the same small changes to the existing code in `CallExpression` so the logic there could also handle `&&` and `||` cases too. Including is a React test that shows that we can now inline a component that we previously weren't able to do.
Pull Request resolved: https://github.com/facebook/prepack/pull/2503
Differential Revision: D9616500
Pulled By: trueadm
fbshipit-source-id: 3888a62da330c64b0395723f8764c3590adc8491
Summary:
Release notes: `test-internal-react` and `test-internal` now use `--max_old_space_size=32768`
As per the title, this increases the max memory allocation for Node to 32gb. `--max_old_space_size=32768`.
Pull Request resolved: https://github.com/facebook/prepack/pull/2524
Differential Revision: D9618037
Pulled By: trueadm
fbshipit-source-id: 6bd595410c6f93ccc5abbc116ee892e8de519eed
Summary:
Release notes: Adding CLI options --warnaserror, --diagnosticaserror, --nodiagnostic
This resolves#2517.
- --warnAsError: Turns all warnings into errors.
- --diagnosticAsError: Must be followed by a comma-separated list of non-fatal-error PPxxxx diagnostic codes that should get turned into (recoverable) errors.
- --noDiagnostic: Must be followed by a comma-separated list of non-fatal-error PPxxxx diagnostic codes that should get suppressed.
Adding tests.
Pull Request resolved: https://github.com/facebook/prepack/pull/2521
Differential Revision: D9616473
Pulled By: NTillmann
fbshipit-source-id: c66d7396005699d4d50f801a419fa4879bd8ffc4
Summary:
Release notes: none
The `React.Children.map` mock was not fully finished and had side-effects. This fixes that and adds a test to show it properly working.
Pull Request resolved: https://github.com/facebook/prepack/pull/2519
Differential Revision: D9614166
Pulled By: trueadm
fbshipit-source-id: b646d13cc46f3747b07a111dc5bc9de295e25212
Summary:
This PR implements a step of the way to getting leaked value analysis working for optimized Array operators. It is desirable to leak as little as possible, so that the operators can be specialized to take into account values in the environment in which they run. In the beginning, we are focusing on the narrow range of scenarios in which this is possible. We will start by enforcing the assumptions that we rely on, and make sure that the code that we generate is correct. Once we have correct code, we will start progressively relaxing the assumptions to increase coverage. The overall plan can be found here: #2452.
More specifically, this PR transitively materializes objects reachable via reads to bindings in the optimized function. This is necessary to snapshot the contents of those objects at specialization time.
Fixes#2405.
Pull Request resolved: https://github.com/facebook/prepack/pull/2456
Differential Revision: D9498939
Pulled By: sb98052
fbshipit-source-id: 16853f97dc781505dba29dce7f28996a0a4e7749
Summary:
Release notes: landing two previously reverted PRs
I found the issue.
Flow doesn't support optional fields in classes. This effectively becomes enforced with Babel 7 since it treats the type annotations as field initializers. Which means that these fields always gets created.
We happened to only use this newer plugin for class fields internally which broke our builds only there.
2b4546d Use `undefined` instead of missing to represent absent field in descriptors. Fixed all the callsites that checks for `hasOwnProperty` or `in` that I could find.
922d40c Fixes a Flow issue in the text printer.
I filed a [follow up issue for ObjectValue](https://github.com/facebook/prepack/issues/2510) since it has the same problem.
Pull Request resolved: https://github.com/facebook/prepack/pull/2511
Reviewed By: trueadm
Differential Revision: D9569949
Pulled By: sebmarkbage
fbshipit-source-id: f8bf84c4385de4f0ff6bcd45badacd3b8c88c533
Summary:
This fixes a bug it took me a while to track down. Unfortunately creating a repro was really difficult. I was observing the following invariant in `Reference` being triggered.
fddfc6f0c5/src/environment.js (L1425-L1431)
Digging in, the bad base was a deep conditional `AbstractValue` where all the leaf nodes were `EmptyValue` and `__bottomValue`. (Constructed from a number of `try`/`catch`/`throw`s.) This `AbstractValue` _should_ have simplified to just `EmptyValue` then `RequireObjectCoercible()` should have thrown a runtime `TypeError` after seeing the `EmptyValue`. This is what I observed in local tests when trying to reproduce this issue.
After looking at the error in the large React Native bundle I’m working in I discovered that the simplifier was throwing an error since the simplification count was exceeded. This is fine and normal. The issue was that `RequireObjectCoercible()` does not handle complex empty `AbstractValue`s well. If failing simplification is a normal part of Prepack operation we should make sure methods like `RequireObjectCoercible()` can handle complex `AbstractValue`s as well as simple ones.
This PR does that.
Pull Request resolved: https://github.com/facebook/prepack/pull/2515
Reviewed By: trueadm
Differential Revision: D9602146
Pulled By: calebmer
fbshipit-source-id: 359c74c646eeb619ba2e78b50eafe10b2e2fb133