Summary:
There's a lot of code in function.js. Move it behind an interface so that it no longer forms part of the giant cycle.
Closes https://github.com/facebook/prepack/pull/1143
Differential Revision: D6333759
Pulled By: hermanventer
fbshipit-source-id: 26506e332e9d128d629a4c360ab08ca73641734c
Summary:
Release Note: enable lazy objects mode in test-runner.
Note: I will try hermanventer's suggestion to move all lazy objects creation to prelude and hydrate them after that in future PR for a better way to deal with lazy objects testing issue.
1. Enables lazy objects mode in test runner.
2. For JSON.stringify() and for...in constructs that hydrate lazy objects in global code, I added "force hydrate lazy objects" attribute in the generated code telling test-runner to hydrate the objects immediately
3. Disable lazy objects mode for 3 factorify tests and 4 abstract tests.
4. Skip lazy objects mode for react compiler, additional function tests.
5. Fix a bug which only shows up in lazy objects mode: a) if the target body is non-generator body and delay reason is generator body there is no need to wait for it. b) we should use targetBody instead of this._body in emitter if delayReason is a Value.
Closes https://github.com/facebook/prepack/pull/1147
Differential Revision: D6326474
Pulled By: yinghuitan
fbshipit-source-id: 84fd8d3550ea4685da418224c28247ad330da8bf
Summary:
After adding some tests, it turns out that logic to apply keys to arrays was un-needed. This was because, after running the same code through React, the same errors occur when keys are omitted from arrays. We don't need to do any clever tricks to add keys, as it might actually break logic on things that don't need them. I've added the relevant tests and removed the key adding logic, which should help us with the de-duping work (https://github.com/facebook/prepack/issues/1150).
Closes https://github.com/facebook/prepack/pull/1151
Differential Revision: D6323878
Pulled By: trueadm
fbshipit-source-id: ec3fa90c48332ef0715e94335c558570040ed81c
Summary:
Release note: Adds experimental React functional component folding optimizations
This PR is stacked upon PRs #1118 and #1117. Thus, those PRs should be merged before this PR is merged to reduce noise in the diff.
This PR adds a new React Reconciler into Prepack's serialization process, so that React components trees can be folded/inlined into a single component at build time. To fold a component tree, it must be explicitly done via `__registerReactComponentRoot(nameOfComponent)`.
This PR only attempts to fold React functional components, not React ES2015 class components (that will come in another PR at a later date). Furthermore, the `props` parameter on a root component must contain Flow type annotations (otherwise we will have no idea what the values might be). Support flow `propTypes` might also be an addition, but not for this PR.
If the reconciler comes across a component that it cannot fold/inline, it will "bail-out" and try and continue the process without that particular component being folded into the tree.
An example of how this all works (input):
```jsx
function App(props: {title: string}) {
return (
<div>
<ChildComponent title={props.title} />
</div>
);
}
function ChildComponent(props) {
return (
<span>
<SubChildComponent {...props} />
</span>
);
}
function SubChildComponent(props) {
return <span>{props.title.toString()}</span>
}
__registerReactComponentRoot(App);
global.App = App;
```
Output:
```jsx
(function () {
"use strict";
var _$1 = this;
var _0 = function (props) {
var _$0 = props.title;
return <div><span><span>{_$0}</span></span></div>;
};
_$1.App = _0;
}).call(this);
```
Closes https://github.com/facebook/prepack/pull/1120
Differential Revision: D6237333
Pulled By: trueadm
fbshipit-source-id: b58c7d8979ca79a766bb2ee2eb01a380d37c3101
Summary:
Release note: none
This PR adds the React/Jest testing infrastructure to Prepack and is stacked on the PR https://github.com/facebook/prepack/pull/1117. Thus, that PR should be merged before this PR is merged to reduce noise in the diff.
This will allow us to test various runtime outputs of React 16 when running original source vs Prepacked source to see if there are any issues/differences that might have an impact on applications. The primary reason for this is to track regressions for the component folding PRs that will land in the future.
Please note, this PR does not contain any reconciler changes, thus `__registerReactComponentRoot(App);` has been commented out of tests to ensure they don't prematurely fail. A follow up PR will enable them once the other React functional component folding PRs get landed.
This PR also adds some mock React globals to be used within tests (and maybe to be further integrated into folding at a future point too). The mocks include `React.Component` and `React.cloneElement` for now.
Furthermore, a `utils/json.js` utility file exists to help normalize the results from the React test renderer so that adjacent JSON text nodes get merged, which is something that may exist because of how the reconciler (once the PR lands) handles inlining of child nodes.
The command to run React tests is `yarn test-react`.
Closes https://github.com/facebook/prepack/pull/1118
Reviewed By: cblappert
Differential Revision: D6208263
Pulled By: trueadm
fbshipit-source-id: d54f3b0e1cc3240e1f142d3da08bc279e4153889
Summary:
Define two new flags for test-runner.js:
--repl <path> : If present the, the prepack sources of test are evaluated
using by piping to the process instead of in a new node context.
--es5 : run babel on tests, used if the repl does not support es6.
To further deal with es6 a new test header flag is introduced, es6. If a test is
not relevant in a non es6 world, the test is skipped if the es5 flag is also set.
This flag has been added to some tests.
Running subprocess for each test is obviously more expensive so the default
behavior is unchanged and still uses a new context.
Closes https://github.com/facebook/prepack/pull/1103
Differential Revision: D6192670
Pulled By: simonhj
fbshipit-source-id: 35e4b819d863634f3273a4da7984c7a71d8c4fb9
Summary:
Instead of delaying modules that throw conditionally, let the exception bubble up to the require call and then forget it (after emitting a warning). This allows more global state to be optimized and should be OK if it is understood that throwing an unhandled exception in module initialization code is not a supported scenario.
Probably, the temporal point where the require call happens should contain a conditional throw statement, which would be equivalent to current behavior. For now, this causes invariants to fire in the serializer, probably because of bugs in how the state at the time of the exception is restored and presented to the throw statement.
It is also an option to let the exception escape the require call itself and possibly bubble all the way to the top level. This would be more correct than the current behavior since it should match the runtime behavior of the unprepacked code. This too is currently buggy. It also a bit of performance concern because it uses much more saved state.
Closes https://github.com/facebook/prepack/pull/1104
Differential Revision: D6189032
Pulled By: hermanventer
fbshipit-source-id: 71c6352eddca4d88ae030fdcbfb76e7a39839e73
Summary: Adds new `test-coverage-all` command to `package.json` which will run and compose all test coverage information into one html.
Reviewed By: hermanventer
Differential Revision: D6052366
fbshipit-source-id: 208259fa79185267f6c7a51ca8baf08ffb707e97
Summary:
Release note: Generate code for uncaught exceptions
This is a high priority fix for a land blocking issue. Please review ASAP.
Exceptions that (conditionally or unconditionally) propagate to the top level program used to cause Prepack to fail.
The new behavior is to generate top level code that will (conditionally) throw the exceptions at runtime.
Closes https://github.com/facebook/prepack/pull/1083
Differential Revision: D6050038
Pulled By: hermanventer
fbshipit-source-id: 666c058befdebf2ed5f97bed74818db57b86f34b
Summary:
This seems to have been added to the standard since the last time a looked. Re-enable a test that was already looking for it. Mask "caller" for non strict functions, lest more tests fall over.
Closes https://github.com/facebook/prepack/pull/1049
Differential Revision: D5984228
Pulled By: hermanventer
fbshipit-source-id: 430a5c85b211cb0c5cfb8429c2713246892bebb5
Summary:
Updated todo comments with task numbers.
Not included in this list:
1) node related todos: Sebastian should do that
2) serializer related todos: Nikolai should do that
3) partial evaluator todos: I should do that, but it will take some time.
Closes https://github.com/facebook/prepack/pull/1024
Differential Revision: D5950510
Pulled By: hermanventer
fbshipit-source-id: 131601c18115d5bf8c1a4e1f6a87e45619acc0ba
Summary:
Currently works for all test cases except `noconflict-existantobject.js`.
There are a couple things that are dubious in the current implementation that I will address as I iterate on it:
* We don't visit things correctly in the visitor or the serializer -- we should be visiting only:
* generator entries in effects
* Bindings, PropertyBindings in effects not relating to CreatedObjects
* There is currently no way to emit to the main body after the main generator has been serialized -- we may need to if a value is only reachable from one of the additional functions.
* More thought needs to go into how this interacts with
* speculative initialization
* require optimization
* inlining
Closes https://github.com/facebook/prepack/pull/912
Differential Revision: D5859741
Pulled By: cblappert
fbshipit-source-id: 9fe7bd4429ad53629582f9fb7154a28971159554
Summary:
Issue: #520
Check if components of priorEffects are null when referenced.
Add a maximum stack depth with a default value of 225 and check stack size against this.
Allow the stack depth to be customizable via the command line.
Reran all tests via yarn validate.
Closes https://github.com/facebook/prepack/pull/960
Differential Revision: D5810838
Pulled By: JWZ2018
fbshipit-source-id: e676c3600d936411d9e82b2849912e60f6729eb9
Summary:
Treat `void 0` (and similar patterns) as a simple value that factorifyObject can operate on.
This slightly reduces code size with no adverse effects.
Closes https://github.com/facebook/prepack/pull/909
Differential Revision: D5675928
Pulled By: NTillmann
fbshipit-source-id: 399de8bc71e18ee4aa5aada8ca6e093bcb839fc5
Summary:
Set up an evaluation environment before parsing since the parse helper expects to be able to turn syntax errors into runtime errors.
Catch such errors and report them via handleError when not running eval.
Fixes issue: #900
Closes https://github.com/facebook/prepack/pull/916
Differential Revision: D5689361
Pulled By: hermanventer
fbshipit-source-id: b43a5c6b30e3e93d9e8fb3cc746cbb11f7951bae
Summary:
Internal data indicates that doing two passes to eliminate unneeded identifiers does not help performance or code size at the bytecode level.
Therefore, I swap the default, and rename the option.
--singlePass is no longer an option, and instead, the old two-pass behavior can be triggered via
--inlineExpressions.
Tweaked test runner to run all serialization tests with inline expressions and without,
marked one test that required inline expressions for its test objective.
This addresses #848.
Closes https://github.com/facebook/prepack/pull/894
Differential Revision: D5650410
Pulled By: NTillmann
fbshipit-source-id: 81d79ac042598d7fdc080a0f1798f68d97f8288b
Summary:
I needed this for an investigation and it seems like a useful thing to have.
Closes https://github.com/facebook/prepack/pull/896
Differential Revision: D5637604
Pulled By: hermanventer
fbshipit-source-id: 0abbc56ad3e84ac696a625b8d438c5ff4d8f45d7
Summary:
FunctionValues should not be compared with `===` from the model. Add an option to disable this invariant.
Closes https://github.com/facebook/prepack/pull/881
Differential Revision: D5626447
Pulled By: cblappert
fbshipit-source-id: 3f0bb71cd6dd0b556e46df85658c715798fa0204
Summary:
By allowing prepack CLI to prepack multiple files, user can specify separate model file together with source file. Also, it can allow pre-bundled files to be prepacked together.
I also removed prepackString() API to prefer prepackSources() because they are almost identical logic while prepackSources() API supports multiple files.
Closes https://github.com/facebook/prepack/pull/865
Differential Revision: D5566968
Pulled By: yinghuitan
fbshipit-source-id: ce00087e444b5cdf34b5cfb6913062fc0ee440b7
Summary:
- Clean up options and create new `prepack-options.js` file
- Add `PartialEvaluatorOptions` type which contains only `sourceMaps`
- Fix test code related to above change
https://github.com/facebook/prepack/issues/841
Closes https://github.com/facebook/prepack/pull/878
Reviewed By: NTillmann
Differential Revision: D5605347
Pulled By: cblappert
fbshipit-source-id: 024284a9904dff765417c2c849c4642e781affb3
Summary:
The rest runner did double counting that went awry when certain tests were either just ES5 or just ES6. I just go annoyed at the lack of precision while debugging test failures and this has been lying around on my machine for far too long.
Closes https://github.com/facebook/prepack/pull/874
Differential Revision: D5586527
Pulled By: hermanventer
fbshipit-source-id: 561743c545ec8c54b64a0b96d972b3de31807b3e
Summary:
Added more invariants calls to better enforce the global invariant requiring abstract values with non functional builders to have no arguments.
Also added a way to suppress extraneous errors that may arise while traversing additional function bodies to find read/write conflicts. Fixed the initial traversals to report errors and now pass in parameter needed to allow delayed requires inside these functions.
Fixed a bug in generator where it created an abstract value with a non functional builder and some arguments. Then fixed a bug in JSON.parse where it special cased abstract values produced the wrong way.
Added some logic to test-internal to invoke prepack with specified additional functions if the test case has a particular name. This test has to be run manually since it takes a rather long time to complete.
Added logic to populate CompilerDiagnostic objects with a callStack property so that it is easier to find the ultimate source of a prepack error.
Closes https://github.com/facebook/prepack/pull/869
Differential Revision: D5581023
Pulled By: hermanventer
fbshipit-source-id: 37d7cffe32135b95939b3da81de2a5b3c9df26c4
Summary:
Introspection errors no longer show up as completions, so any time we evaluate a node that might cause an introspection error, we should expect to catch and handle a FatalError.
Also tweaked package.json to allow longer stack traces when running test-serializer and tweaked test-internal to output error messages that do not have associated source locations. (The latter should not happen in practice but could happen when things go wrong.)
Closes https://github.com/facebook/prepack/pull/866
Differential Revision: D5563965
Pulled By: hermanventer
fbshipit-source-id: e2a74ec19314703526ebd35f7b8e694c19d82ab0
Summary:
`Date.now()` and `Math.random()` calls emitted into the generator now no longer get serialized if their results are not used. In principle this is safe for any pure definitions of AbstractValues emitted to the generator but that is too hard to determine for most cases.
Adds a test case verifying that extra `Date.now()` calls are eliminated.
See #543 for more detail.
Closes https://github.com/facebook/prepack/pull/822
Differential Revision: D5537430
Pulled By: cblappert
fbshipit-source-id: 4f3e12eee65fdbea7504d73399eddde5a1e93703
Summary:
Additional functions may be properties of global objects, so just parse the option string as an expression and evaluate it in the global environment.
Closes https://github.com/facebook/prepack/pull/858
Differential Revision: D5541434
Pulled By: hermanventer
fbshipit-source-id: b0b39f2b0ff072ebafeba3e33cd2cd1365dfd4b8
Summary:
If one additional function reads a property that is written by another additional function, it becomes potentially dependent on the other function running before it does. Additional functions are supposed to be independent of each other, so we now detect this and report errors.
Closes https://github.com/facebook/prepack/pull/850
Differential Revision: D5529672
Pulled By: hermanventer
fbshipit-source-id: f810d27d1fbf03d6538d70e61a1d9e7c0fe55309
Summary:
Introduce ECMAScriptFunctionValue and move many fields of FunctionValue down to ECMAScriptFunctionValue. FunctionValue becomes the abstract base class:
1. Use invariant(F instanceof ECMAScriptFunctionValue) if only ECMAScriptFunctionValue is valid in that code path to make flow happy.
2. Replace "F.getType() === FunctionValue" with Value.isTypeCompatibleWith(F.getType(), FunctionValue)
3. $ScriptOrModule may also be able to move down to ECMAScriptFunctionValue, but I am not 100% positive so leave it in FunctionValue for now.
Closes https://github.com/facebook/prepack/pull/824
Differential Revision: D5527976
Pulled By: yinghuitan
fbshipit-source-id: 017748d67c31aa121c35b28b43cef026e904a412
Summary:
Provide a new option to specify a number of additional functions to prepack (in addition to the global code "function", that is). These functions need to exist in the global scope, have no parameters, be well behaved (never throw an exception) and should not depend on each other (the order in which they get called should not matter).
At the moment there are checks only for existence, good behavior and no write-write conflicts. Also, the functions are not actually prepacked yet.
Closes https://github.com/facebook/prepack/pull/846
Differential Revision: D5514569
Pulled By: hermanventer
fbshipit-source-id: e2e343d9eed4772fc11810d91293facdafca8fcb
Summary:
That will allow to determine their perf implications.
Cleaned up --help text a bit.
Change serializer test runner to run each test twice, with delaying of initialization and without.
This also effectively re-enables fixed point check, as it is currently disabled whenever the
delaying of initializations kicks in. (See issue #835.)
Closes https://github.com/facebook/prepack/pull/842
Differential Revision: D5504808
Pulled By: NTillmann
fbshipit-source-id: e470d5b7d3b48b2e44819a4e859c48983a887d74
Summary:
If a test case fails but there were delayedValues it was previously failing
Closes https://github.com/facebook/prepack/pull/834
Differential Revision: D5494450
Pulled By: Kishore-B-Rao
fbshipit-source-id: 4dcacaa4384dd4febb57aa191ba122fd9aa6b416
Summary:
Update Babylon and adjust expected pass count to match what I see on my laptop.
The difference was due to my version of Babylon (which is the latest for some or other reason I don't understand) giving a syntax error that did not occur with the version on the CI machine. Updating the yarn lock file gets the CI machine in sync with my laptop with respect to those tests.
Note that some String.prototype tests only pass with recent versions of Node.
Closes https://github.com/facebook/prepack/pull/831
Differential Revision: D5489742
Pulled By: hermanventer
fbshipit-source-id: 5732e47718c53d9f20de04fd64c1389524f33309
Summary:
On a large internal program, this seems to make Prepack around 15% faster overall.
Closes https://github.com/facebook/prepack/pull/826
Differential Revision: D5484863
Pulled By: NTillmann
fbshipit-source-id: 3d8b7b8504645356d7901a4e19fa2e7e1d3f14be
Summary:
Two improvements:
1. The CI has 10340 ES6 tests passing so reflect the latest status in test runner.
2. Always show test failure groups summary even in success situation. This allows us to run the test locally and compare failure groups summary to the baseline summary in CI to find out which specific test group is failing. Saving much time in troubleshooting test failure!
Closes https://github.com/facebook/prepack/pull/820
Differential Revision: D5447438
Pulled By: yinghuitan
fbshipit-source-id: 87fa62693cb6e1365978e5cb635e3732fc2ded09
Summary:
If a module get's delayed because of a prepack error, we would like to notify developers about it, but not expose this to them as errors, which would be presumed to break the build.
Closes https://github.com/facebook/prepack/pull/814
Differential Revision: D5434272
Pulled By: cblappert
fbshipit-source-id: 6be27a30706c70b43a925603e62f1750ec395b3f
Summary:
Instead of throwing peculiarly behaving introspection error completions, we now report all errors via the error handler, using CompilerDiagnostic objects that are just normal host objects. Following a report, we always throw a FatalError.
Eventually all of the places where generic introspection errors are thrown will be replaced by specific errors and may have site specific error recovery logic.
Closes https://github.com/facebook/prepack/pull/812
Differential Revision: D5426046
Pulled By: hermanventer
fbshipit-source-id: c6e6121c2658b5005ea956143ea8dbdb9743165a
Summary:
An instance of this class is a single diagnostic message, so the plural just seems wrong.
Closes https://github.com/facebook/prepack/pull/811
Differential Revision: D5420522
Pulled By: hermanventer
fbshipit-source-id: c848911a27d2c445ba98ee04988f5c4afe261dc1
Summary:
Report errors rather than throw IntrospectionErrors. Added test cases to get 100% coverage of ForOfStatement.js. Fixed a few bug that came to light because of the new tests.
Closes https://github.com/facebook/prepack/pull/803
Differential Revision: D5411294
Pulled By: hermanventer
fbshipit-source-id: 818a5fb4c8112fc33c8531602eee5c0f6ecf25cb
Summary:
Adapt the test-internal script to combine separate files containing a model, a source bundle and a source map.
Also extend fixup_filenames to explicitly traverse comments because the default traverser does not do so.
Closes https://github.com/facebook/prepack/pull/789
Differential Revision: D5386836
Pulled By: hermanventer
fbshipit-source-id: da0499cd027ecf94dcde612d0ce831ea1fd4a98b
Summary:
This supersedes #760.
Additional changes over #760:
Pinning Prettier version to get some formatting always. (Different prettier versions were responsible for the observed flip-flopping of StringPrototype.js.)
Print output of prettier in wrapper script for better diagnosis / experience. (TODO: How to just pipe through console output? Couldn't get it to work.)
Updating problematic .js file for the last time.
Closes https://github.com/facebook/prepack/pull/787
Differential Revision: D5382336
Pulled By: NTillmann
fbshipit-source-id: 95ed988ef3f091493d2fb509b5481753d56901cd
Summary:
We usually need at least two files: 1) the environmental model and 2) the bundle to be Prepacked.
In general, there is no good reason to not allow as many files as the caller wants.
To make this not be a breaking chance, I've added a new API for this: prepackSources.
Further complications result from working around a bug in Babel and not increasing the module cycle length for Flow.
Closes https://github.com/facebook/prepack/pull/776
Differential Revision: D5366190
Pulled By: hermanventer
fbshipit-source-id: 74595b1b60e8e8a6d24cb974b5be10210d745266
Summary:
Except for the web site.
Also reorganized the API a bit and deprecated some calls.
Closes https://github.com/facebook/prepack/pull/763
Differential Revision: D5351215
Pulled By: hermanventer
fbshipit-source-id: c5da7f81138f7b0cb97d28da25c5e3fe8836ccb9