Commit Graph

1376 Commits

Author SHA1 Message Date
Herman Venter
7aa5455148 Update test262 submodule hash
Summary: Update the test262 submodule to the latest version.

Reviewed By: cblappert

Differential Revision: D8753974

fbshipit-source-id: 6ba4904969dbe3c529dd73e1d20d227bf6e5c226
2018-07-06 14:25:54 -07:00
Herman Venter
1034e4a5cf New Alpha
Summary: 0.2.43-alpha.0

Reviewed By: simonhj

Differential Revision: D8739217

fbshipit-source-id: eeb42cfb6741aa14fde21f806a39fbaca4335153
2018-07-05 14:39:38 -07:00
Herman Venter
244f2525f8 Weekly release v0.2.42: Debugability, speed, bug fixes
Summary:
Improved source location information
Only havoc abstract value args when really necessary
Debugger recognizes sourcemaps and opens the correct file/line when debugging in Nuclide.
Make React tests fast
Special case an expression simplification for Instant Render
Fix temporal assignments to intrinsics that happen inside non deterministic loops
Enhanced handling of Array.map applied to abstract arrays
Support dynamic invariants via __assume
We got a logo!
Add React Native mocks to Prepack

Reviewed By: simonhj

Differential Revision: D8739156

fbshipit-source-id: d535dfe0c5bcbee4aaed28f75d45cbedcc51344b
2018-07-05 14:39:38 -07:00
Sapan Bhatia
92c4db7483 Narrow type of PropertyBinding.object and eliminate unnecessary checks (#2208)
Summary:
Release notes: None

This came about as an offshoot of #2185. PropertyBinding.object cannot be of type AbstractObjectValue. This change narrows its type to ObjectValue, and eliminates checks that become unnecessary.

Outcome of a manual search via Grasp: PropertyBinding.object is assigned at two points - in methods/properties.js and react/util.js. There are also invariants at two places to guard this condition (object instanceof ObjectValue.) yarn flow does not report errors.
Closes https://github.com/facebook/prepack/pull/2208

Differential Revision: D8738889

Pulled By: sb98052

fbshipit-source-id: 52807e28a699b95934b8d53f0c81ccc6b06a79bb
2018-07-05 14:11:26 -07:00
Dominic Gannaway
3cd3dd8431 Reduce React bloat on equivalent objects with similar temporal alias trees (#2193)
Summary:
Release notes: none

In an attempt to pull out some of the work from https://github.com/facebook/prepack/pull/2148 to make things easier to consume and review. This PR is one part, where we check the temporal alias values (if an object value has it) and see if we can dedupe the trees. Example below:
Closes https://github.com/facebook/prepack/pull/2193

Differential Revision: D8732542

Pulled By: trueadm

fbshipit-source-id: 352d0048acfef69b5a257c0fe280435fa7baaa7f
2018-07-05 05:09:30 -07:00
Dominic Gannaway
ef7e1873fa Support React keys in array branches, fixes #2139 (#2157)
Summary:
Release notes: none

Add logic to support adding keys when inlining arrays. Fixes https://github.com/facebook/prepack/issues/2139.
Closes https://github.com/facebook/prepack/pull/2157

Differential Revision: D8732339

Pulled By: trueadm

fbshipit-source-id: cfb1fe8725522e3eba5e1061832ddba8359484bb
2018-07-04 08:23:26 -07:00
Dominic Gannaway
2c79cb103d Ensure we handle numeric properties on $GetPartial path (#2205)
Summary:
Release notes: none

We were missing logic for handling abstract arrays with unknown numeric properties when we attempt to get a partial value on the array. I've added a regression test too.
Closes https://github.com/facebook/prepack/pull/2205

Differential Revision: D8732181

Pulled By: trueadm

fbshipit-source-id: 6002eac4b7d4d0b842407a3bb9ea9bcec19f486b
2018-07-04 07:39:05 -07:00
Dominic Gannaway
8b6307a121 Add fb-www Jest testing config/dependencies to do local snapshot testing (#2202)
Summary:
Release notes: none

Make it easier to do local development testing of our internal bundle without having to hack the settings each time.
Closes https://github.com/facebook/prepack/pull/2202

Differential Revision: D8731922

Pulled By: trueadm

fbshipit-source-id: 71d92c3b90f448667c4a9ada1f1b0848ece5003b
2018-07-04 05:38:38 -07:00
Dominic Gannaway
5f444abbda @allow-large-files [prepack][PR] Adds React native mocks (#2096)
Summary:
Release notes: adds React Native mocks to Prepack

This adds React Native mocks to Prepack and a few basic tests to demonstrate inlining of `View` and `Text`.
Closes https://github.com/facebook/prepack/pull/2096

Differential Revision: D8723932

Pulled By: NTillmann

fbshipit-source-id: 38bd265cd8935ebdf30266ec337378b4ea5b09d6
2018-07-03 14:44:41 -07:00
Nikolai Tillmann
c9fc143f5b Adding raw Prepack Logo assets (#2189)
Summary:
Release notes: We got a logo!

Updating README to include logo.
Will create an issue to update website accordingly.
Closes https://github.com/facebook/prepack/pull/2189

Differential Revision: D8725906

Pulled By: NTillmann

fbshipit-source-id: 2f9b3b1d4afbd4fc42f137fcda9e4edac390d272
2018-07-03 12:45:47 -07:00
Sapan Bhatia
e9ef64da0e Support injection of residual statements. Support dynamic invariants. (#2195)
Summary:
Release notes: Support dynamic invariants via __assume

Resolves #2171. Implements an __assume primitive that injects dynamic invariants into the code.

Source:
```js
x = __abstract("number", "5");
__invariant(x==5, "x should be 5");
```

Generated:
```js
(function () {
  var _$0 = this;
  var _0 = 5;
  _$0.x = _0;

  var _1 = _0 == 5;
  if (!_1) {
    throw new Error("x should be 5");
  }
}).call(this);
```
Closes https://github.com/facebook/prepack/pull/2195

Reviewed By: hermanventer

Differential Revision: D8725726

Pulled By: sb98052

fbshipit-source-id: 28db3272199cdb9ae669062344eb82f0ef619bd4
2018-07-03 12:09:49 -07:00
Guru107
2f470b319c Add the right command in README to generate prepack.min.js (#2200)
Summary:
Release note: none

`yarn build-bundle` needs `lib` directory present else it breaks.
Closes https://github.com/facebook/prepack/pull/2200

Differential Revision: D8725631

Pulled By: hermanventer

fbshipit-source-id: d577b4cf6de2b29a2f5fc7a8b1ba2dc36694c9db
2018-07-03 11:56:09 -07:00
Dominic Gannaway
8e37b36191 Removes temporalAliasArgs for an existing approach using the preludeGenerator (#2199)
Summary:
Release notes: none

As pointed out by Herman in https://github.com/facebook/prepack/pull/2193#discussion_r199628160. We don't need `temporalAliasArgs`, so this PR removes it from the codebase and uses the existing way via the preludeGenerator.

This also adds a helper function to make it easier to relate derived abstract values to their temporal args. Furthermore, `derivedIds` now stores the `TemporalBuildNodeEntryArgs` rather than `Array<Value>`, as the follow up PRs for doing the React related logic need to access more than just the array of args, it also needs access to `isPure`, `skipInvariant` etc so it can properly clone derived abstract values.
Closes https://github.com/facebook/prepack/pull/2199

Differential Revision: D8724017

Pulled By: trueadm

fbshipit-source-id: 3ad72d3b230f1d2dc7f81c2a8d07dd33d0c7aa5c
2018-07-03 08:09:47 -07:00
Herman Venter
f12e0369f0 Do not always give up when running Array.map over an abstract array. (#2173)
Summary:
Release note: Enhanced handling of Array.map applied to abstract arrays

Fixes #2169.

If an abstract array is the join or a few concrete arrays, we apply the map over all of the concrete arrays and join the results. This is a bit of a hack, much like what we have for switch statements. The code from the latter has been factored out and reused for this.
Closes https://github.com/facebook/prepack/pull/2173

Differential Revision: D8721507

Pulled By: hermanventer

fbshipit-source-id: e08f2dc1d7e78c7b59f9ff7c76ad54b398b8afe9
2018-07-02 19:23:38 -07:00
Herman Venter
b6ce555f37 Ensure temporal assignments are not lost when the value does not change. (#2197)
Summary:
Release note: Fix temporal assignments to intrinsics that happen inside non deterministic loops

Tweak the property set logic to not short circuit when the target object is intrinsic and the RH value is the same as the current (tracked) property value.

Also fix the code generator for loop bodies to not get upset when the lh side is temporal, but rh side is not widened (because it is a constant).
Closes https://github.com/facebook/prepack/pull/2197

Differential Revision: D8721001

Pulled By: hermanventer

fbshipit-source-id: d38565a40fa7ab8b4e30596f0e1dcfc655a4fb5e
2018-07-02 17:55:04 -07:00
Herman Venter
466d19ddfd Special case "x === undefined || x === null" kind of expressions (#2188)
Summary:
Release note: special case expression simplification for Instant Render

When instant render is enabled turn x === undefined || x === null into __cannotBecomeObject(x) so that Instant Render can easily compile it down to a single byte code.
Closes https://github.com/facebook/prepack/pull/2188

Differential Revision: D8716594

Pulled By: hermanventer

fbshipit-source-id: bbcb25462f79852d8deac29bfed62e86745e5589
2018-07-02 13:39:35 -07:00
Dominic Gannaway
67a47fd48f Improve fb-www mocks objectWithoutProperties value by ensuring we store known values (#2194)
Summary:
Release notes: none

When the `objectWithoutProperties` mock was originally created, my knowledge of Prepack's internals wasn't as good as it was now. Now that I understand how AbstractObjectValues work, we can safely add the known values in `objectWithoutProperties` to the abstract backing object. The backing object was missing these values before and was an empty empty that was partial. This should give more data and value on our internal bundle, where before the values would be lost unnecessarily.
Closes https://github.com/facebook/prepack/pull/2194

Differential Revision: D8716289

Pulled By: trueadm

fbshipit-source-id: 451065473ea09943831f75c0bc15490e73c8d947
2018-07-02 13:11:28 -07:00
Dan Abramov
5159b0d832 Make React tests fast (#2187)
Summary:
Currently we have a single giant file with all tests, and a giant snapshot. This is both slow, and hard to work with and iterate on.

In this PR I will refactor our test setup.

- [x] Split it up into multiple files (gets the test running from 45s to 27s)
- [x] Run Prettier on test files
- [x] Split tests further for better performance
- [x] Make it possible to run one test file
- [x] Fix the issue with double test re-runs in watch mode on changes in the test file
- [x] Refactor error handling
- [x] Run Prettier on fixtures
- [x] Add a fast mode with `yarn test-react-fast <Filename>`
- [x] Fix double reruns on failure

Potential followups:
- [x] Figure out why test interruption broke (need https://github.com/facebook/jest/issues/6599 and https://github.com/facebook/jest/issues/6598 fixed)
- [x] Revisit weird things like `this['React']` assignment with a funny comment in every test
Closes https://github.com/facebook/prepack/pull/2187

Differential Revision: D8713639

Pulled By: gaearon

fbshipit-source-id: 5edbfa4e61610ecafff17c0e5e7f84d44cd51168
2018-07-02 11:25:58 -07:00
David Cai
e79def7cd2 Debugger sourcemaps (#2154)
Summary:
Release Notes:
- Debugger recognizes sourcemaps and opens the correct file/line when debugging in Nuclide.
    - Explanation of how sourcemap translation works in [this Quip](https://fb.quip.com/0uQCAtkuPAHF). This is probably useful to read before attempting to read the changes to `Debugger.js` and `PathNormalizer.js`.
- Removed unnecessary abstractions in `IsStatement` and `DebuggerOptions`.
- Refactored multi-file support to conform to Nuclide initialization protocol
- Refactored `DebuggerConfigArguments` so as to pass sourceFiles without increase Flow cycle length.

Example of FatalError on FB4A: https://www.dropbox.com/s/ig8vrlpcazbygo3/Prepack%20Fatal%20Diagnostic%20on%20FB4A.mov?dl=0

NOTE: Apologies for the large number of commits -- I incorrectly pulled in some from master when rebasing
Closes https://github.com/facebook/prepack/pull/2154

Differential Revision: D8707082

Pulled By: caiismyname

fbshipit-source-id: 812610c0345536a1ad9b480449c16f34018040c3
2018-06-29 20:24:59 -07:00
Sebastian Markbage
3240eae91b Only havoc abstract value args when really necessary (#2184)
Summary:
Fixes #2179

In #2179 I describe why we might need to havoc some args to abstract values sometimes. This adds an invariant to ensure that we always have args in the cases we need to havoc.

If this abstract value cannot be an object, then we don't need to havoc since there's nothing that can be mutated.

If this has a known values domain, then we know the possible objects. We only need to havoc those, not the args.
Closes https://github.com/facebook/prepack/pull/2184

Differential Revision: D8701601

Pulled By: sebmarkbage

fbshipit-source-id: d5fecbed4cff8013bc768cb6e277094d9ff16d9c
2018-06-29 15:10:22 -07:00
Herman Venter
3deb5e2885 Fix problem with stack location entries (#2183)
Summary:
Release note: Improve source location information

Changes to make sure that the source location of the call expression appears in the corresponding execution context record. Also emit execution records with no source location from stack traces. These are due to calls to internal helper methods for iterating over objects and arrays for argument destructuring.

Finally fix a CompilerDiagnostic construction call to include a source location.
Closes https://github.com/facebook/prepack/pull/2183

Differential Revision: D8698271

Pulled By: hermanventer

fbshipit-source-id: 10f77f718db645a4784723c3eca4bd4e06eb43f8
2018-06-29 11:56:22 -07:00
Dan Abramov
0e09f6f986 Increasing version number
Summary: The usual.

Reviewed By: trueadm

Differential Revision: D8694035

fbshipit-source-id: 7ceb3359f3a6729a7d08f3e2fd4841121b163edd
2018-06-29 07:24:14 -07:00
Dan Abramov
03cd572617 Weekly release v0.2.41
Summary:
- Bugfixes
- Improve `switch` evaluation performance
- Don't emit unnecessary calls

Reviewed By: trueadm

Differential Revision: D8694028

fbshipit-source-id: f43138b799905f98c11af1ebeaf82ff0216ab30b
2018-06-29 07:24:14 -07:00
Nikolai Tillmann
2e2b92eec0 Adding --instantRender mode. (#2178)
Summary:
Release notes: None

Tweaking some behaviors to help with Instant Render automation.
This leaves behind some TODOs in the code, but unblock me for now.
Closes https://github.com/facebook/prepack/pull/2178

Differential Revision: D8689796

Pulled By: NTillmann

fbshipit-source-id: f919a8b6bbfb63513bb9467027676e0ba7d4230e
2018-06-28 20:53:43 -07:00
Chris Blappert
bb49439adf Fix require/define detection (#2168)
Summary:
Release Notes: None

It is okay for a define call to happen within a require call so long as the define call has happened by the time the require call has returned (since all define calls should have the same effect and only happen once). Previously if we encountered a module required before it was defined (or defined in a nested partial evaluation scope), we would not record it in ModuleTracer logic.
Closes https://github.com/facebook/prepack/pull/2168

Differential Revision: D8688788

Pulled By: cblappert

fbshipit-source-id: 6696ea54ed9ae7a3d7e8a944c45e14feccf3139b
2018-06-28 18:39:26 -07:00
Dominic Gannaway
9905f613d6 Fixes nested evaluatePure calls and React nested optimized closure side-effect detection (#2166)
Summary:
Release notes: none

Fixes nested `evaluatePure` calls, where before they would collide and overwrite one another. Also ensure React reconciler uses side-effect detection on nested optimized closures. This fixes a React test which should have been failing before, but wasn't.
Closes https://github.com/facebook/prepack/pull/2166

Differential Revision: D8681422

Pulled By: trueadm

fbshipit-source-id: 8941812407d1bda5af0343a09210aeff24a36cff
2018-06-28 13:26:00 -07:00
Dominic Gannaway
7c63a7cd42 Add mutatesOnly feature the generator entries (#2132)
Summary:
Release notes: adds `mutatesOnly` to generator entries to better allow for DCE

This PR adds a new option that can be passed as an optional arg to `generator.deriveAbstract` called `mutatesOnly `. See https://github.com/facebook/prepack/pull/2132#pullrequestreview-130509488 for details. With it, we can better dead-code eliminate generator entries when the value entries that are flagged as mutating are dead code.

The test showing this is below:

Input:
```js
global.f = function() {
  var x = global.__abstract ? global.__abstract({}, "({})") : {};
  global.__makeSimple && __makeSimple(x);
  Object.assign({}, x);
  return 1;
};

if (global.__optimize) __optimize(f);
```

Output (with master):
```js
  var _$2 = this;

  var _$3 = _$2.Object;
  var _$4 = _$3.assign;

  var _0 = function () {
    var _$0 = _$4({}, {});

    return 1;
  };
```

Output (with the changes in this PR):
```js
  var _0 = function () {
    return 1;
  };

  var _2 = function () {
    return global.f();
  };
```
Closes https://github.com/facebook/prepack/pull/2132

Differential Revision: D8667764

Pulled By: trueadm

fbshipit-source-id: 5121da7d73330befeb5a39ea50d7b773256d70bc
2018-06-27 13:09:30 -07:00
Herman Venter
fa4b52f573 Distribute equality checks if that allows simplification (#2174)
Summary:
Release note: More simplification of equality expressions

Resolves issue: #2172

Expressions like (c ? x : y) === null can sometimes be simplified by first rewriting them as (c ? x === null : y === null). Add such a case to the simplifier.
Closes https://github.com/facebook/prepack/pull/2174

Differential Revision: D8666251

Pulled By: hermanventer

fbshipit-source-id: 5b0d56fb091e25bfcdf879be3403cb5a982375ae
2018-06-27 12:10:01 -07:00
Peter van der Zee
30f07ead22 Upgrade Prettier to 1.13.6 on fbsource
Reviewed By: zertosh

Differential Revision: D8638504

fbshipit-source-id: c6991b2e884e14868ddc1d9047a78191219d673f
2018-06-27 03:40:12 -07:00
Chris Blappert
938a9dc241 Fix inefficient loop in switch statements (#2161)
Summary:
Release Notes: None

Dan Caspi's change to internal test case created a giant switch statement, increasing evaluation time from 5.9s > 224s. This change brings it down to 6.2s by using `push` instead of `concat` in 2 places.
Closes https://github.com/facebook/prepack/pull/2161

Differential Revision: D8649236

Pulled By: cblappert

fbshipit-source-id: a0af4a7c4eaff30e6e8a7708006d84773a25517f
2018-06-26 13:25:13 -07:00
Dominic Gannaway
b66b3f5056 Add missing isPure to abstract temporal (#2167)
Summary:
Release notes: none

This should have been added to my previous PR https://github.com/facebook/prepack/pull/2097 but I must have missed it.
Closes https://github.com/facebook/prepack/pull/2167

Differential Revision: D8641050

Pulled By: trueadm

fbshipit-source-id: c1a07c904bf8e6eed0af566a2ce6ff27f0863909
2018-06-26 10:12:04 -07:00
Herman Venter
8554d2d1ee Fix test runner and don't swallow invariant failures (#2155)
Summary:
Release note: Fix test runner and don't swallow invariant failures

The recent changes to make the serializer test runner deal with promises, caused it to list every test that follows a failing test as also failing.

I've also noticed that invariant failures can get swallowed. And as a result of that some test cases that should have failed with false invariants showed up as passing.

Those failures were recently introduced by PR #2134. It boils down to a single line fix, which is also included with this.
Closes https://github.com/facebook/prepack/pull/2155

Differential Revision: D8629298

Pulled By: hermanventer

fbshipit-source-id: 467f7efdf119ea9d29083d4e41054e583b38a1ff
2018-06-25 18:41:59 -07:00
Dominic Gannaway
bfffc7ac38 Tidy up React logic, pulled from #2096 (#2163)
Summary:
Release notes: none

To make https://github.com/facebook/prepack/pull/2096 easier to review, this pulls out the tidy ups from that PR.

- fix typo on function name `mergeAdjacentJSONTextNodes`
- move ReactDOM mock logic into its own file
Closes https://github.com/facebook/prepack/pull/2163

Differential Revision: D8625051

Pulled By: trueadm

fbshipit-source-id: 5345cc26f5c613b4afbb1c768213fd84caf5ebab
2018-06-25 16:00:58 -07:00
Nikolai Tillmann
af010a78db Reviewed all uses of t.memberEpression (#2162)
Summary:
Release notes: None

We used to find random bugs where the `computed` flag wasn't set right.
But even if it's set correctly, we sometimes generated suboptimal code,
e.g. `a["0"]` for an array access.

I reviewed all occurrences of `t.memberExpression`, and redirected all that involve
potentially interesting computations to a new helper function `memberExpressionHelper`
which does "the right thing". This function should always be used.

Added regression test for an array access that used to be suboptimal (observed in InstantRender).
Closes https://github.com/facebook/prepack/pull/2162

Differential Revision: D8625006

Pulled By: NTillmann

fbshipit-source-id: f9211260c08d9195a9f4cc48502cba0794fe84f9
2018-06-25 15:24:19 -07:00
Dominic Gannaway
228c39edf9 Support basic arrow function serialization (#1650)
Summary:
Release notes: adds basic ES2015 arrow function serialization

This allows Prepack to serialize back to arrow functions and also traverse them correctly when understanding `this`.
Closes https://github.com/facebook/prepack/pull/1650

Differential Revision: D8623368

Pulled By: trueadm

fbshipit-source-id: 9be7849770148b67e5f17eee88a633aac906b6e2
2018-06-25 14:09:57 -07:00
Herman Venter
f9e102c0d2 Purge some local bindings that are not captured in closures. (#2152)
Summary:
Release note: none

This reverses PR #2136, which Dan has noted to lead to a 3x slowdown for an internal bundle. In order to fix the problem that Nikolai's PR addressed, the original code has been modified to not purge any local bindings that could possibly have been captured in a closure.

I expect that most effects will not be in a context that contains a closure, so this should help. It would be nice, however, to get some feedback on whether this is actually the case.
Closes https://github.com/facebook/prepack/pull/2152

Differential Revision: D8617877

Pulled By: hermanventer

fbshipit-source-id: 8e907ba1dded0428388fd42132658555e3b8e82e
2018-06-25 11:39:50 -07:00
Dominic Gannaway
5a5a100483 Provide a basic recovery mechanism for for and while loops (#2118)
Summary:
Release notes: standard for loops and while loops have a recovery mechanism in pure scope

This PR provides a bail-out recovery mechanism in pure scope for FatalErrors thrown and caught from for/while loops. Until now, if a FatalError occurs from trying to evaluate abstract for/while loops, we'd have to recover at a higher point in the callstack, which wasn't always possible (the loop may be at the root of a function/component).

The ideal long-term strategy is to properly model out the different cases for loops, but this is a complex and time-consuming process. This PR adds a recovery mechanism that serializes out the original for loop, but within a newly created wrapper function containing the loop logic and a function call to that newly created function wrapper. This allows us to still run the same code at runtime, where we were unable to evaluate and optimize it at build time.

For now, this PR only adds recovery support for standard `for` and `while` loops (as they go through the same code path). We already have some basic evaluation for `do while` loops, but trying to adapt that code to work with the failing test case (https://github.com/facebook/prepack/issues/2055) didn't work for me – we have so many strange problems to deal with first before we can properly handle that issue.

In cases where the loop uses `this`, the context is found and correctly called with the wrapper function. In cases of usage of `return`, `arguments` and labelled `break/continue` we bail out again as this is not currently supported in the scope of this PR (can be added in a follow up PR, but I wanted to keep the scope of this PR limited).

For example, take this failing case on master:

```js
function fn(props, splitPoint) {
  var text = props.text || "";

  text = text.replace(/\s*$/, "");

  if (splitPoint !== null) {
    while (text[splitPoint - 1] === "\n") {
      splitPoint--;
    }
  }
  return splitPoint;
}
```

This serializes out to:

```js
  var _0 = function (props, splitPoint) {
    var __scope_0 = new Array(1);

    var __get_scope_binding_0 = function (__selector) {
      var __captured;

      switch (__selector) {
        case 0:
          __captured = [_G, _E];
          break;
      }

      __scope_0[__selector] = __captured;
      return __captured;
    };

    var _C = function () {
      var __captured__scope_1 = __scope_0[0] || __get_scope_binding_0(0);

      for (; __captured__scope_1[1][__captured__scope_1[0] - 1] === "\n";) {
        __captured__scope_1[0]--;
      }
    };

    var _$0 = props.text;

    var _$2 = (_$0 || "").replace(/\s*$/, "");

    var _6 = splitPoint !== null;

    var _G = _6 ? void 0 : splitPoint;

    var _E = _6 ? void 0 : _$2;

    if (_6) {
      (__scope_0[0] || __get_scope_binding_0(0))[0] = splitPoint;
      (__scope_0[0] || __get_scope_binding_0(0))[1] = _$2;

      var _$5 = _C();
    }

    var _$6 = (__scope_0[0] || __get_scope_binding_0(0))[0];

    return _$6;
  };
```

Furthermore, an idea that might be a good follow up PR would be to break the wrapper function into two functions, depending on some heuristics. If we can detect that the loop body does not have any unsupported side-effects like writing to variables that are havoced etc, we can then tell Prepack to optimize the inner function wrapper for the loop body. That way, at least some parts of the loop get optimized (the outer bindings will be havoced before this point, so it should work okay). I think I suggested this in person with hermanventer and sebmarkbage in Seattle as a potential way to optimize complex loops that we can't compute the fixed point for right now.

Fixes #2055
Closes https://github.com/facebook/prepack/pull/2118

Differential Revision: D8410341

Pulled By: trueadm

fbshipit-source-id: ee7e6b1bc1feadf0c924e4f82506ca32ca1dadc9
2018-06-25 11:09:37 -07:00
Dominic Gannaway
38392a5499 Slice argument list to fix abstract recovery bug (#2156)
Summary:
Release notes: none

Fixes a bug where the argument list gets mutated and padded with undefined values, so instead we slice it a copy of it so we don't mutate the same array and pass the mutated array instead. Fixes https://github.com/facebook/prepack/issues/2153.
Closes https://github.com/facebook/prepack/pull/2156

Differential Revision: D8610746

Pulled By: trueadm

fbshipit-source-id: 1b6f37693323c813d60f43ab7e9977a99f86ff47
2018-06-25 05:42:27 -07:00
Herman Venter
cc1e081854 Update Flow version and fix newly reported Flow errors. (#2150)
Summary:
Release note: update Flow version

Require latest Flow version and fix newly reported type errors.
Closes https://github.com/facebook/prepack/pull/2150

Differential Revision: D8592311

Pulled By: hermanventer

fbshipit-source-id: 98b7a7de81a1aae18973ccc858cacfaa02d43f8e
2018-06-22 11:25:50 -07:00
Dominic Gannaway
93cd9a1d63 setState within componentWillMount uses internal property update (#2149)
Summary:
Release notes: none

As we're updating state on a final object, in this case `state`, ensure we use `hardModifyReactObjectPropertyBinding`. Unblocks https://github.com/facebook/prepack/pull/2137.
Closes https://github.com/facebook/prepack/pull/2149

Reviewed By: hermanventer

Differential Revision: D8584676

Pulled By: trueadm

fbshipit-source-id: f23c77a5091b7c1023a48a5d29353bf9cdc06d65
2018-06-21 18:53:28 -07:00
Dominic Gannaway
18e69904d5 Allow Object.assign to continue evaluation in pure scope (#2068)
Summary:
Release notes: in pure mode, allow Object.assign to continue evaluation rather than throwing FatalErrors

This PR adds bail-out support of `Object.assign` sources within the `Object.assign` implementation. This allows us to continue evaluation in pure scope without bailing out of the Object.assign entirely (like we currently do) upon a FatalError occurring. Given we have snapshotting in `Object.assign`, we don't need to havoc the sources.

This allows us to inline and evaluate far more within our internal bundles. Fixes https://github.com/facebook/prepack/issues/2064
Closes https://github.com/facebook/prepack/pull/2068

Differential Revision: D8579441

Pulled By: trueadm

fbshipit-source-id: 0e97b54e0c8af63f1e3cd08fca6c7f375ee3c615
2018-06-21 16:10:40 -07:00
Dan Abramov
6c16a53fa2 Link to Prepack introduction from website (#2147)
Summary:
I haven't written the next parts yet but I figured let's put a link on the website so this doesn't get lost.
I think even the details there are useful enough for users and new contributors.

<img width="1513" alt="screen shot 2018-06-21 at 3 57 52 pm" src="https://user-images.githubusercontent.com/810438/41727325-f9ba32da-756b-11e8-94f0-c83b71df859b.png">

I put it at the top of Getting Started because IMO you'll want to read this (or at least see it) before trying to run Prepack.

I initially planned to put it in the docs themselves but only today realized there's no build process. I don't want to convert the guide to HTML so I'd rather keep it as a gist (and update it if necessary) in the meantime.
Closes https://github.com/facebook/prepack/pull/2147

Differential Revision: D8577403

Pulled By: gaearon

fbshipit-source-id: 2f7f64a0a4413066739b12c50b4d21779a16a568
2018-06-21 13:12:22 -07:00
Dominic Gannaway
c12fbbe19a Follow up fixes for 2138 (#2146)
Summary:
Release notes: none

This PR contains some fixes and small tidy ups that would have been in #2138. There was a bug to do with the React props equivalence system and snapshots that was found when https://github.com/facebook/prepack/pull/2137 was merged (along with the fix I commented to on that PR). This PR unblocks https://github.com/facebook/prepack/pull/2137 to land as it should now pass our internal bundle test.
Closes https://github.com/facebook/prepack/pull/2146

Differential Revision: D8556958

Pulled By: trueadm

fbshipit-source-id: dd774de76059e00af1dff305dd3618c3bfed06ea
2018-06-20 18:54:31 -07:00
David Cai
9486a4c4e0 Multiple File support in debugger (#2130)
Summary:
Release Notes: Add support for multiple input files for the debugger, in both debugger-cli and prepack-cli (used by debugger when launched from Nuclide).
Closes https://github.com/facebook/prepack/pull/2130

Differential Revision: D8554746

Pulled By: caiismyname

fbshipit-source-id: ffba51d0bc6f2b7fa171072a358bdfc5c911a2d7
2018-06-20 18:17:34 -07:00
Nikolai Tillmann
5af00f1ed0 Increasing version number
Summary: Increasing Prepack version number

Reviewed By: hermanventer

Differential Revision: D8548827

fbshipit-source-id: 159697dd0bbbe37fc72665aedd2c38c31172b025
2018-06-20 18:17:34 -07:00
Nikolai Tillmann
4435ec0d8b Weekly Prepack release 0.40
Summary: Lots of bug fixes.

Reviewed By: hermanventer

Differential Revision: D8548728

fbshipit-source-id: a03ae279b5c0448abf3043d2aec7c3a8c98038f1
2018-06-20 18:17:32 -07:00
David Cai
6e869a33be Fixed a DebugAdapter error check bug (#2144)
Summary:
Release notes: Reversed an !== undefined check so the check behaves as intended
Closes https://github.com/facebook/prepack/pull/2144

Differential Revision: D8553142

Pulled By: caiismyname

fbshipit-source-id: ca808323ac96d0d3a0b6496106bd04988293249a
2018-06-20 16:24:23 -07:00
Nikolai Tillmann
d781c5b8ea Leaked declarative bindings are effectively serialized as simple variables (#2125)
Summary:
Release notes: Fixes to leaked declarative bindings

Leaked declarative bindings need to be accessed out-of-band as far
as the serializer is concerned which otherwise only puts final
values into locations.

To make that work, whenever two states are merged where a
declarative binding in one has been leaked but not in the other,
this now gets harmonized by also recording the materialization
side effect into the generator of the other.

The result is that a binding always ends up being fully leaked or not.
For leaked mutable bindings, the tracked value becomes irrelevant, and
is now truly made unavailable. For leaked immutable bindings, the last
value is retained, and we no longer need the strange `leakedImmutableValue` field.

Leaked bindings are now referentialized as simple variables, bypassing the
delayed captured-scope logic. This produces nicer more efficient code, but,
at least for now, has the downside that it rules out sharing of function bodies.

This change is a step towards the (to be publicly documented)
long-term plan to clean up Prepack's handling of leaking and havocing.
(Similar to what this change does for declarative bindings, we'll also must
revisit what happens for leaked object properties. But that's for later.)

This fixes #2122 (issue havocing value in conditional) and adds regression test.
This fixes #2007 (Conceptual issue with havoced bindings) and adds regression test.
Closes https://github.com/facebook/prepack/pull/2125

Differential Revision: D8549299

Pulled By: NTillmann

fbshipit-source-id: 28c3681beafd3890668b72a828f59582c636a6c9
2018-06-20 14:39:53 -07:00
Dominic Gannaway
0cdafba476 Refactor of ReactElement React Props equivalence logic (#2138)
Summary:
Release notes: none

After studying the issues in https://github.com/facebook/prepack/pull/2137, I understood that we currently make some assumptions in terms of the ReactElement equivalence system that are incompatible with what we want from Prepack going forward. This PR aims at fixing those assumptions so they fall more into line with the changes https://github.com/facebook/prepack/pull/2137.

This PR makes the following changes:
- All React equivalence is now handled explicitly in the ReactSet/ReactElementSet/ReactPropsSet to ensure all the logic is located together as one and not sprinkled around the codebase.
- We use `hardModifyReactObjectPropertyBinding` to modify final objects that React controls rather than `Properties.Set`. This function bypasses the normal route of putting the property changes on the effects – thus making it so the property changes are permanent and cannot be reverted. Given the object is immutable, there should never be a case where the property may change anyway – we only change the property as part of the equivalence phase and during reconciliation where the React internals are at play. This is only safe for objects explicitly created by React and marked as final by React – no other object can go through this codepath. Any attempt to use this dangerous function on a non-final object will result in an invariant.
-  Various bug fixes were fixed that were found when #2137 was merged and existing tests failed.
- Removed all the logic around `makeNotFinal` and use `hardModifyReactObjectPropertyBinding` instead.
Closes https://github.com/facebook/prepack/pull/2138

Reviewed By: gaearon

Differential Revision: D8547558

Pulled By: trueadm

fbshipit-source-id: 192da9169947adadc41f43997dfbe0adb73cec3b
2018-06-20 14:24:33 -07:00
Manas
958fa43d6c test-runner now supports promises (#2115)
Summary:
Release note: none

Attempts adding support for promises in test-runner.js. `inspect` can now return Promises, which will be resolved before checking it value.
Closes https://github.com/facebook/prepack/pull/2115

Differential Revision: D8550825

Pulled By: hermanventer

fbshipit-source-id: 3f9781f6e34016dcb61bd436400a1bfb51932452
2018-06-20 13:55:18 -07:00