Commit Graph

1596 Commits

Author SHA1 Message Date
Dominic Gannaway
829acd5f64 Properly handle defaultProps with creation of ReactElements
Summary:
Release notes: none

After discussions last night with sebmarkbage, I noticed that we apply defaultProps in the wrong place when the config is partial object or an abstract object. This now uses a helper function, which is injected once for the entire bundle, that handles `defaultProps` cases as a temporal function entry. Added a regression test too.
Closes https://github.com/facebook/prepack/pull/2036

Differential Revision: D8175799

Pulled By: trueadm

fbshipit-source-id: b6bb4f30ee07f0bd9ac07fc91018c26936696f4b
2018-05-26 10:30:33 -07:00
Dominic Gannaway
47f84b405a Re-factor of the React createElement logic
Summary:
Release notes: none

Now that we have snapshotting from Object.assign and ToObject for abstracts, we can now upgrade the ReactElement creation logic, simplifying a bunch of routes which actually resulted in a bunch of components inlining in tests where they didn't before. Furthermore, it allows us to tighten up the Flow typings in the React reconciler and tidy up some of the checks for `key`s or `ref`s logic, which was a bit hard to read before and didn't take into account objects with multiple values in their values domain. This also fixes a bug with abstract conditional component types not getting the deafultProps values correctly.
Closes https://github.com/facebook/prepack/pull/1996

Differential Revision: D8172083

Pulled By: trueadm

fbshipit-source-id: 0a8a1e0631883c92e914aba1308a109b3afda137
2018-05-25 18:34:12 -07:00
Nikolai Tillmann
62636d4b2a When havocing immutable bindings, keep around and later use the leaked value
Summary:
Release notes: None

Adding regression test.
While this really just does something for const bindings that we probably don't care much about,
this is leading up to a similar change for final objects which is much more relevant.

(And eventually, the last known value of a havoced mutable binding and havoced non-final objects in between external calls should be handled in this way as well.)
Closes https://github.com/facebook/prepack/pull/2031

Differential Revision: D8172560

Pulled By: NTillmann

fbshipit-source-id: 4e839113d7e5cd0f676e0017dd774da82b6dcdcf
2018-05-25 18:04:09 -07:00
Dominic Gannaway
531b4972da Better support indexOf and reverse on unknown arrays with numeric properties
Summary:
Release notes: support `indexOf` and `reverse` on unknown arrays with numeric properties

This PR aims to better support `indexOf` and `reverse` on unknown arrays with numeric properties. Previously, these two methods on the array would cause a FatalError in pure mode that would recover and havoc the array itself and the arguments. I don't believe this is necessary for these two methods in pure mode because they don't mutate the arguments passed. In pure mode we expect that calling `toString` on the arguments won't affect global scope, so these operations should be fine to be emitted as temporals with them being havoced.

I also added a TODO to an area I want to look at next week that I feel will unlock many more optimizations and inlining possibilities (with regards to handling conditional abstract objects as the context of the function call).
Closes https://github.com/facebook/prepack/pull/2033

Differential Revision: D8172837

Pulled By: trueadm

fbshipit-source-id: 846e28c0e0a6d0d475ad6ba6ef705bf0eae55b85
2018-05-25 17:25:18 -07:00
Dominic Gannaway
67b6c67ef7 Ensure react lazy initializer is in the top generator body
Summary:
Release notes: none

We need to ensure we emit the ReactElement lazy initializer is in the top generator body (the function body) of the React component render. If we emit it in a nested generator body, it may not get called in the right place after we've nested many components. This also renames a bunch of functions to optimized functions rather than additional functions.

I've got an issue tracking the progress on a follow up PR to add regression tests for this PR: https://github.com/facebook/prepack/issues/2027
Closes https://github.com/facebook/prepack/pull/2026

Differential Revision: D8172780

Pulled By: trueadm

fbshipit-source-id: 5d3457df467201b4a8ee7a0e9186fbc8ade7293b
2018-05-25 17:10:42 -07:00
Dominic Gannaway
3ec7ef254c Fix havoc bindings regression
Summary:
Release notes: none

Was a mistake on the original PR. Fixes https://github.com/facebook/prepack/issues/2032
Closes https://github.com/facebook/prepack/pull/2034

Differential Revision: D8172823

Pulled By: trueadm

fbshipit-source-id: 734c026331c78497f7261228f4c1995619fbc5bd
2018-05-25 17:10:42 -07:00
Dominic Gannaway
7a8dba42e9 Add Prepack __makeFinal global helper
Summary:
Release notes: adds a `__makeFinal` Prepack global helper

This is to be used in follow up PR tests.
Closes https://github.com/facebook/prepack/pull/2029

Differential Revision: D8164904

Pulled By: trueadm

fbshipit-source-id: 3f167ff683235e6e083467818ad6a489619205cc
2018-05-25 11:11:00 -07:00
Simon Jensen
637edf5216 Bump PrePack version to new alpha
Summary: Bump PrePack version to new alpha

Reviewed By: NTillmann

Differential Revision: D8162723

fbshipit-source-id: 13b374d62bfba4fe628c3591c9fd4a4dabb47674
2018-05-25 10:24:23 -07:00
Simon Jensen
be46107f84 PrePack weekly release: Bugfixes and improvements
Summary:
Fixing havocing of bindings.
adds support for ReactDOM.createPortal inlining
Stop using joinEffectsAndPromoteNested
opt out of optimizing a React component in a tree with `__doNotRender`
if left and right in createFromConditionalOp are equal, do early return
all serializer tests now get linted via ESlint for correct output
all globals emitted reference the global identifier
Support for --delayInitializations for optimized functions
Fix abstract values not being coerced into strings for the Error constructor

Reviewed By: NTillmann

Differential Revision: D8162599

fbshipit-source-id: e28495eeb4445d99cb93afc2dce331af077c4faf
2018-05-25 10:24:22 -07:00
Dominic Gannaway
99f13fd974 Allow havocing of final objects
Summary:
Release note: final objects can be havoced

After looking at the changes of https://github.com/facebook/prepack/pull/2023, it occurred to me that we have wrongly made the assertion that "final" objects cannot be havoced. Currently, the only objects to be make final are all part of the React ecosystem, so: state, props and ReactElements. If these objects cannot havoc, then it means we do not emit their properties like we do when we havoc other objects (see https://github.com/facebook/prepack/pull/2023). If we don't emit their properties, then enter an abstract function call, then the conditional properties that have dependencies get emitted after the function call rather than before the function call.

So rather than exclude final objects from being havoced – where we miss out on all the benefits from emitting properties as they havoc, we allow final objects to get havoced, with one single change to make them unique. When we try and use `OrdinaryGetOwnProperty` on them, we don't emit a temporal and allow the property get to continue as per normal. Given the objects that are final are immutable, then this is a safe operation to allow through.

I've got an issue tracking the progress on a follow up PR to add regression tests for this PR: https://github.com/facebook/prepack/issues/2027
Closes https://github.com/facebook/prepack/pull/2025

Differential Revision: D8162143

Pulled By: trueadm

fbshipit-source-id: 1de6979758c37fd6fb6a469d19f8b25d2768d98f
2018-05-25 09:27:15 -07:00
Dominic Gannaway
042d8a867d Ensure we wait for array length property if its abstract
Summary:
Release notes: none

When testing https://github.com/facebook/prepack/pull/2023, this bug crept up in our internal bundle.  We should have always been waiting for the `lenProperty` as it can be a conditional abstract and thus delay the serialization of the length until its dependencies have been serialized.

I've got an issue tracking the progress on a follow up PR to add regression tests for this PR: https://github.com/facebook/prepack/issues/2027
Closes https://github.com/facebook/prepack/pull/2024

Differential Revision: D8161871

Pulled By: trueadm

fbshipit-source-id: dc4d23fa267abc6922498fa3ac8c1987396fe2b1
2018-05-25 09:27:15 -07:00
Herman Venter
2d19ce3fe9 Stacking saved effects is no longer necessary, so make things simpler.
Summary:
Release note: none

Small simplification of the code, along with a comment and some invariants.
Closes https://github.com/facebook/prepack/pull/2022

Differential Revision: D8157398

Pulled By: hermanventer

fbshipit-source-id: 23c6af437ee30e51dba81649d5e0a65f0061e5cd
2018-05-24 22:04:10 -07:00
Nikolai Tillmann
01ab307aa8 Fixing binding value after havocing
Summary:
Release notes: Fixing havocing of bindings.

This fixes #1973 and it fixes #2003.

When havocing a binding,
the binding's value at that point in time would remain in the binding,
and participate in the whole value merging process,
which was meant to compute final values and caused issues.

To fix this, an explicit assignment is now emitted at binding havocing time with the current binding value, and afterwards, the current binding value, which is irrelevant from then on, is set to undefined.

This effectively fixes the issue for bindings, but the whole way binding havocing works is a bit inefficient (after havocing, Prepack effectively stops tracking that binding); even worse, similar problems that we observed here for bindings should exist for object properties as well; and the generated code looks a bit awful. I'll follow up creating separate issues for those, but they are out of scope for this change.

Adding regression tests.
Closes https://github.com/facebook/prepack/pull/2010

Differential Revision: D8153779

Pulled By: NTillmann

fbshipit-source-id: 9d64980e0bf2c8afe018ba0814907b90d19a9f77
2018-05-24 18:27:55 -07:00
Nikolai Tillmann
e24b90aeec Havoc all the bindings, deal with havoced bindings that get assigned to.
Summary:
Release notes: None

This fixes #2001: `let` bindings didn't get properly havoced,
and things could got generally wrong when dealing with havoced bindings that get assigned to.
This fixes those basic issues, strictly making things better.

However, havoced bindings in general remains a conceptually flawed feature
as described in #2007.

Adding a few regression tests.
Closes https://github.com/facebook/prepack/pull/2008

Differential Revision: D8148798

Pulled By: NTillmann

fbshipit-source-id: 34b821915bb5f0416ac55b4e347f956959ae0594
2018-05-24 12:35:25 -07:00
Wai Kit Koh
131a6a2cdc Add a name generator for __get_scope_binding_ functions
Summary:
Release Note: none

This uses a separate name generator for scope access functions.

This addresses #1084 and here is a sample output:
```javascript
(function () {
  var __scope_0 = new Array(2);

  var __get_scope_binding_0 = function (__selector) {
    var __captured;

    switch (__selector) {
      case 0:
        __captured = [5];
        break;

      case 1:
        __captured = [3];
        break;

      default:
        throw new Error("Unknown scope selector");
    }

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

  var _2 = function () {
    var __scope_3 = new Array(1);

    var __get_scope_binding_1 = function (__selector) {
      var __captured;

      switch (__selector) {
        case 0:
          __captured = [3];
          break;

        default:
          throw new Error("Unknown scope selector");
      }

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

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

      var __captured__scope_4 = __scope_3[0] || __get_scope_binding_1(0);

      --__captured__scope_1[0];
      return ++__captured__scope_4[0];
    };

    return _3;
  };

  var _0 = function () {
    return g();
  };

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

    var __captured__scope_2 = __scope_0[1] || __get_scope_binding_0(1);

    --__captured__scope_1[0];
    return ++__captured__scope_2[0];
  };

  f = _2;
  g = _1;
  inspect = _0;
})();
```
Closes https://github.com/facebook/prepack/pull/1978

Reviewed By: NTillmann

Differential Revision: D8126287

Pulled By: kwkit

fbshipit-source-id: 559f94370825fa7b53ac9a2981a688a82a63be5a
2018-05-24 11:29:18 -07:00
Dominic Gannaway
75dfdea8d2 Havoc unknown array values
Summary:
Release notes: none

This was missed off when we created unknown array values. This makes it so they can be havoced.
Closes https://github.com/facebook/prepack/pull/2016

Differential Revision: D8139928

Pulled By: trueadm

fbshipit-source-id: e0ec54fe573f6b6b7f4e44f04d08a2d23976ed0a
2018-05-24 06:24:56 -07:00
Dominic Gannaway
3d35fc8cbd Fix react tests
Summary:
Release notes: none

An test only was accidentally merged to master.
Closes https://github.com/facebook/prepack/pull/2014

Differential Revision: D8134882

Pulled By: trueadm

fbshipit-source-id: 55194aa25aea409b6163c04f3d222f77c42acc6c
2018-05-24 02:55:31 -07:00
Herman Venter
d1fd2972b4 Fix composePossiblyNormalCompletions to leave abrupt branches alone
Summary:
Release note: none

This pull out the parts of PR #1995 that seem obviously correct and that do not break anything.
Closes https://github.com/facebook/prepack/pull/2009

Differential Revision: D8130145

Pulled By: hermanventer

fbshipit-source-id: bcfeaa36d8c71ddcaa4490836916097cd4c4fd68
2018-05-23 17:38:53 -07:00
Dominic Gannaway
74ae4f86dd Add ReactDOM.createPortal inlining
Summary:
Release notes: adds support for ReactDOM.createPortal inlining

Allows the React reconciler to inline components passed to ReactDOM.createPortal.
Closes https://github.com/facebook/prepack/pull/2006

Differential Revision: D8125418

Pulled By: trueadm

fbshipit-source-id: a25a2c23d1dcaa2edaada6fecb39ef80bb829cff
2018-05-23 15:24:35 -07:00
Herman Venter
1cc12c7579 Stop using joinEffectsAndPromoteNested
Summary:
Release note: none

This removes the last uses of joinEffectsAndPromoteNested.
Closes https://github.com/facebook/prepack/pull/2005

Differential Revision: D8125078

Pulled By: hermanventer

fbshipit-source-id: 7016776d550413dad8b6075c688d7f5215db99d8
2018-05-23 14:08:32 -07:00
Dominic Gannaway
87591341b1 Add __doNotRender flag to React reconcilation
Summary:
Release notes: opt out of optimizing a React component in a tree with `__doNotRender`

This PR makes it possible to opt out of a single component in a React component tree by detecting a `__doNotRender` flag. For example:

```js
function MyComponent(props) {
   ...
}

MyComponent.__doNotRender = true;

class MyComponent extends React.Component {
  render() {
    ...
  }
}

MyComponent.__doNotRender = true;
```
Closes https://github.com/facebook/prepack/pull/2004

Differential Revision: D8123009

Pulled By: trueadm

fbshipit-source-id: d5fc54aea2ea1253e260e41c1fb7d4f2d4717ffd
2018-05-23 11:53:46 -07:00
Dominic Gannaway
f3582d0156 If left and right in createFromConditionalOp are equal, do early return
Summary:
Release notes: none

Do early return if both `left` and `right` values in `createFromConditionalOp` are equal. This improves performance quite a bit on some complex paths when running on our internal bundle.
Closes https://github.com/facebook/prepack/pull/2002

Differential Revision: D8117179

Pulled By: trueadm

fbshipit-source-id: c198d7270745447dba7c5523abc0907d693bcd45
2018-05-23 09:10:24 -07:00
Dominic Gannaway
cde1af298d Do not mutate arrays or ReactElements during React reconciliation
Summary:
Release notes: none

This fixes an issue that we were experiencing, that turned out to be the correct fix after looking at https://github.com/facebook/prepack/pull/1997. We shouldn't mutate arrays in the reconciliation process, instead we should create new ones when we have new values. Also, we should ensure that we don't mutate ReactElements during reconciliation too, instead we should just create new ones. Mutating existing objects and values breaks down completely when we enter nested effects that need to re-evaluate the same original values, so this fixes a bunch of internal issues we were seeing on our internal FB bundle.
Closes https://github.com/facebook/prepack/pull/1999

Differential Revision: D8105499

Pulled By: trueadm

fbshipit-source-id: 4e6ceb8b02c886c42156a8903c347765f101c840
2018-05-22 16:35:40 -07:00
Sapan Bhatia
373c6d917d Fix nit that crept through
Summary:
This line that refers to a missing variable slipped though a previous commit.
Closes https://github.com/facebook/prepack/pull/1988

Reviewed By: trueadm

Differential Revision: D8105162

Pulled By: sb98052

fbshipit-source-id: 6e35b882f0af94c2acd8096f955bd9ab7275ed77
2018-05-22 15:54:22 -07:00
Dominic Gannaway
393eba15ad Ensures all serializer test case output passes linting validation
Summary:
Release notes: all serializer tests now get linted via ESlint for correct output

This PR is pretty gigantic, but almost 99% of it is changing all the serializer tests so they pass the linting rules – which means that there must be no undefined variables or if they are, they are explicitly accesses via `global`. Furthermore, the linting also checks to ensure that all variables are defined before they are used.

Also I added a regression test `conditions3` that further validates some complex cases I was seeing fail in other cases. The ESlint config is also in its own module so it can be shared between `debug-fb-www`.
Closes https://github.com/facebook/prepack/pull/1998

Differential Revision: D8099445

Pulled By: trueadm

fbshipit-source-id: 4a03c57beb51e394bc7b334728090b9fc515eca8
2018-05-22 15:41:31 -07:00
Dominic Gannaway
195f68209a Always emit globals safe for strict mode
Summary:
Release notes: all globals emitted reference the global identifier

This is a PR to replace https://github.com/facebook/prepack/pull/1894 that fixes #1890. I found a much simpler fix was to ensure we always treat emitted globals as safe for strict mode regardless. I had to change a test that went against this assumption, but we end up with code that better conforms to strict mode without large changes under the hood to Prepack.
Closes https://github.com/facebook/prepack/pull/1911

Differential Revision: D8095772

Pulled By: trueadm

fbshipit-source-id: d4ed65ba8d52cdb0c8f2171d3f3c02bdd265c32d
2018-05-22 09:37:11 -07:00
Herman Venter
c83d8a350b Update build command to explictly invoke yarn build
Summary:
Release note: none

yarn install used to also invoke the build step. This changed a while ago, but this script was not updated accordingly. Apparently no-one noticed until now.
Closes https://github.com/facebook/prepack/pull/1990

Differential Revision: D8081630

Pulled By: hermanventer

fbshipit-source-id: 87a1f6b340010d27a76da39bb5569ffcb3f7a5b8
2018-05-22 04:31:58 -07:00
Dominic Gannaway
b3018aa6af Trigger invariant upon the React reconciler detecting an object without its bindings
Summary:
Release notes: none

During React reconciliation, detect objects whose bindings have not been correctly applied with the right effects and trigger an invariant as this will result in broken output.
Closes https://github.com/facebook/prepack/pull/1992

Differential Revision: D8088640

Pulled By: trueadm

fbshipit-source-id: 36e9ec74a513643f638f02c88d86b86068adb14b
2018-05-22 02:40:26 -07:00
Herman Venter
b6536991b0 Stack completion saved effects
Summary:
Release note: none

When forking the normal branch of a PossiblyNormalCompletion into yet another PossiblyNormalCompletion, push the current effects onto a stack of effects, rather than just continuing to use the currently active effects. Not doing so, causes mismatched undo operations.

The modified test case would fail and print 2 for y, without this change.
Closes https://github.com/facebook/prepack/pull/1993

Differential Revision: D8087175

Pulled By: hermanventer

fbshipit-source-id: 6b857b9885aa79a8e90b90e365a2b9688a34152d
2018-05-21 21:55:56 -07:00
Nikolai Tillmann
9c26f640ab Support for --delayInitializations for optimized functions
Summary:
Release notes: Support for --delayInitializations for optimized functions

Supporting this removes a TODO and is in response to #1973 (although more of a work-around than the actual fix).

Added tests.
Closes https://github.com/facebook/prepack/pull/1994

Differential Revision: D8087001

Pulled By: NTillmann

fbshipit-source-id: 572f41ffc024bef7954ebd88068f350fe08a84dc
2018-05-21 21:07:57 -07:00
Dominic Gannaway
73aa511413 Ensure unknown array values are emitted into the right target body
Summary:
Release notes: none

This adds some code that was missed from https://github.com/facebook/prepack/pull/1970 in regards to getting the right target body for unknown array values. This fixes a bug internally that I was unable to repro.
Closes https://github.com/facebook/prepack/pull/1991

Differential Revision: D8083045

Pulled By: trueadm

fbshipit-source-id: e5d0152b98a7026ec73e960af925c7d07ef07d9d
2018-05-21 15:58:33 -07:00
Tim Seckinger
dd63339992 fix: coerce abstract values into strings for the Error constructor
Summary:
Release Notes: Fix abstract values not being coerced into strings for the Error constructor

Fixes #1827 NTillmann
The exact example from the issue now prepacks to
```javascript
(function () {
  var _0 = function () {
    return 42;
  };

  inspect = _0;
})();
```

I'm new here, so if this approach is completely wrong, please do notify me and guide me the way to a better one ;)
Closes https://github.com/facebook/prepack/pull/1960

Differential Revision: D8043199

Pulled By: NTillmann

fbshipit-source-id: 9c67fc2ab882398a20e6313b2894b5357b5ef038
2018-05-21 15:58:33 -07:00
Herman Venter
21c19dac17 0.2.36-alpha.0
Summary: New Alpha version 0.2.36

Reviewed By: simonhj

Differential Revision: D8048556

fbshipit-source-id: c2b2c45949b80bd74845856693404ba195044e04
2018-05-21 13:09:48 -07:00
Herman Venter
87ab20e2c2 Weekly release v0.x.y: speed ups, new features, bug fixes
Summary:
Support switch statements where the switch value is abstract and one or more cases throw.
Fixed bug with implicitly converting unknown values to Object.
The React reconciler now throw a FatalError upon encountering side-effects in a render.
Fix while and for loops with unlabeled breaks
Removing --simpleClosures option.
Improve code generation in presence of exceptions.
Default to StrictMode when mixed StrictMode is serialized between function entries.
Better debug logging with --debugScopes
Allocate by using `new Array(n)`.
Fix problems with duplicated and missing statements.
Do not generate code for unreachable global code statements.
Simplify the ToObject serialization output.
Serialization outputFixes an issue with getOwnPropertyDescriptor when dealing with a native prototype function.
More compact code generation by avoiding introducing local variables for abstract values when possible.
Fixes problem with result of Array.filter (and similar) applied to arrays with unknown properties.
Adds support for spread syntax.
Speeding up Prepack by 22%, saving 8% memory.
Add reading wiki link to places.
Make some files flow strict.
Better crash logging.
Provide error feedback when timing out.
Implement const/let pattern declarations.
Adds support for more console methods.
More simplification rules.
Stop the prototype cycle check if an object (e.g. proxy) uses non-ordinary prototype methods.
Fix numerous problems with code ordering.

issues fixed

Reviewed By: simonhj

Differential Revision: D8048481

fbshipit-source-id: 36a464feb74233f68f3476c74f4070103e6a2584
2018-05-21 10:39:29 -07:00
Dominic Gannaway
3545cd8327 Render optimized react-dom/server renderToString ahead of time
Summary:
Release notes: adds experimental `react-dom/server` ahead-of-time rendering to string

This PR was part of a small 1-2 day hackathton to see the applicability of creating a server-side renderer based almost entirely to be a 1:1 of `ReactDOMServer` from `react-dom/server` package. This is by no means a full, complete server renderer but is the foundations for us to do further work on this path in the future. Currently, it consists of a single Jest test, to ensure the output of the Hacker News benchmark matches that of the current ReactDOMServer `renderToString` output.

The performance results look very promising (there are some `console.time` lines you can comment out in the test to see the performance for yourself). This implantation essentially compiles away `react` and `react-dom/server` and instead injects runtime helper functions that do things that cannot be statically determined ahead of time.

Lots of features are missing behind `invariant` TODOs. This was done intentionally.
Closes https://github.com/facebook/prepack/pull/1940

Differential Revision: D8075964

Pulled By: trueadm

fbshipit-source-id: 33b3c7ba26b41871ccd15ad8bde4ad257009fed6
2018-05-21 08:59:20 -07:00
Dominic Gannaway
e78c69c28a Skip check on elementTypes in CreateListFromArrayLike if parameter is default
Summary:
Release notes: none

When we create an array with `CreateListFromArrayLike`, if the `elementTypes` parameter is left undefined, then skip the check that might throw an invariant if the passed in value is abstract.
Closes https://github.com/facebook/prepack/pull/1986

Differential Revision: D8071410

Pulled By: trueadm

fbshipit-source-id: f5944ecfc928fb9efe9120153e102faec9d5e2b6
2018-05-20 13:59:03 -07:00
Dominic Gannaway
4dda80e5be Add no-use-before-define to debug-fb-www script
Summary:
Release notes: none

This adds the `no-use-before-define` rule to `debug-fb-www` script. `variables` and `functions` are set to false, which allows them to be skipped if defined in a parent scope or if the function is in the same scope (as it gets hoisted), see: https://github.com/eslint/eslint/pull/7948/files. With our current internal bundle and latest master, this brings about a new error that wasn't previously emitted: `'_$Fg' was used before it was defined. (5525:15)`.  Fixes https://github.com/facebook/prepack/issues/1982
Closes https://github.com/facebook/prepack/pull/1984

Differential Revision: D8055274

Pulled By: trueadm

fbshipit-source-id: 93a672dd22bce8cd798ebbb7ed90536a847f9ecb
2018-05-18 02:16:46 -07:00
Herman Venter
21cb2b4da5 Avoid redundant conversions to object
Summary:
Release note: none

When debugging another issue, I noticed that member expressions do explicit conversions of abstract base objects to object and that call expressions obtain a temporal value for the function but then go ahead without it, leaving a useless assignment in the timeline.
Closes https://github.com/facebook/prepack/pull/1983

Reviewed By: trueadm

Differential Revision: D8055038

Pulled By: hermanventer

fbshipit-source-id: 4dd394bb0c4df2f9656be453b8feae57cc0db516
2018-05-18 01:19:22 -07:00
Dominic Gannaway
da243f5b48 Fix bug with arrays with widened numeric properties
Summary:
Release notes: none

This PR fixes a bug where prototype methods on unknown arrays with widened numeric properties were incorrectly being used instead of following the route to filter which methods were safe or not. The functionality and logic for this was pulled out, into its own function so it can be re-used in places and tidied up.
Closes https://github.com/facebook/prepack/pull/1981

Differential Revision: D8043347

Pulled By: trueadm

fbshipit-source-id: 05415e5bdcb85818681a72323df16711a89f7c5c
2018-05-17 14:22:26 -07:00
Herman Venter
529ea0d760 Don't rotate effects trees
Summary:
Release note: fix numerous problems with code ordering
Closes: #1914

We've been seeing an endless stream of bugs where code is either missing or in the wrong place. A lot of these were due to the complexity of joinEffectsAndPromoteNested and some more are due to a fundamental flaw in its algorithm: it rotates branches of the effects tree in order to group together all completions of a given type. That can cause generators to end up in the wrong place in the temporal sequence.

We also had a problem with generators being duplicated in the tree.

This pull request introduces a new algorithm for doing what joinEffectsAndPromoteNested does. This too is complicated and I spent days on debugging and fixing many subtle issues. So, for now, I'm only doing it for calls. More will come in later pull requests.

I am not super confident that I've found and addressed all subtle bugs. I think we can expect to run into quite a few more of those. I am, however, reasonably confident that we now have the right approach to dealing with abrupt control flow.

Please have a careful look, but let's get this landed as soon as possible because it is on the critical path.
Closes https://github.com/facebook/prepack/pull/1979

Differential Revision: D8044482

Pulled By: hermanventer

fbshipit-source-id: 317402c5601fdea7366c9daf7762af0217302b54
2018-05-17 11:45:18 -07:00
Dominic Gannaway
b9d43d5e7d Move React side-effect logic in to the ThrowCompletion
Summary:
Release notes: none

This moves the side-effect detection logic for React component renders into the ThrowCompletion itself.
Closes https://github.com/facebook/prepack/pull/1977

Differential Revision: D8031923

Pulled By: trueadm

fbshipit-source-id: 189a2c7b729276193344a926db8f5a747460a8da
2018-05-16 14:08:52 -07:00
Xun Li
1f02f31308 Fix issue #1841.
Summary:
When either name or msg of Error is abstract, we do not want to partially evaluate it because the checks on string emptiness can be overwhelming, and better done in the VM than in JS.
Added a test to check these cases.
(I messed up my previous pull request. Sending a new one here.)
Closes https://github.com/facebook/prepack/pull/1974

Differential Revision: D8028508

Pulled By: lxfind

fbshipit-source-id: 8e1d1f2151e0b08b519935387298d4ffcd579f9b
2018-05-16 11:56:50 -07:00
Tim Seckinger
5df51ac6f4 stop the prototype cycle check if an object uses non-ordinary prototype methods
Summary:
Release Notes: stop the prototype cycle check if an object (e.g. proxy) uses non-ordinary prototype methods

Fixes #1017
Closes https://github.com/facebook/prepack/pull/1976

Differential Revision: D8027102

Pulled By: NTillmann

fbshipit-source-id: 886e6ce474255dadf937662e30a65adbfac5a1f1
2018-05-16 11:06:51 -07:00
Dylan
9eefb43b42 Implement const/let pattern declarations (ES6 destructuring)
Summary:
This should resolve #415.

Relevant part of the spec here: https://www.ecma-international.org/ecma-262/6.0/#sec-let-and-const-declarations-runtime-semantics-evaluation

For `// 3. Let env be the running execution context’s LexicalEnvironment.`, I assumed that the `env` variable passed to the function already fulfills and it's not necessary to retrieve it here.

I've omitted the `ReturnIfAbrupt(Value)` steps from the spec, as this is also done for the rest of the implementation in this file.

test262 has one additional test pass as a result of this change, though somewhat surprisingly it's for `for`.
I've verified in the command line REPL that destructuring assignment works as expected in the basic case.
Closes https://github.com/facebook/prepack/pull/1967

Differential Revision: D8027013

Pulled By: NTillmann

fbshipit-source-id: 845527bcca55c845aca993fd2c97349efcbd5f59
2018-05-16 10:33:19 -07:00
Dominic Gannaway
f807a17b74 Further follow-up Array.from fixes
Summary:
Release notes: none

This is a follow up to the changes in https://github.com/facebook/prepack/pull/1926. This PR correctly fixes the derived values for waiting and ensures that the unknown array objects have their dependencies properly resolved. This fixes part of the issue in https://github.com/facebook/prepack/issues/1962, but it brought about another issue that this PR doesn't aim to solve – dependencies on an abstract function call's unbound/bound bindings.
Closes https://github.com/facebook/prepack/pull/1970

Differential Revision: D8024402

Pulled By: trueadm

fbshipit-source-id: b9f9e725b7b22241209ef5a6f3b29dc0f2eeddeb
2018-05-16 05:15:03 -07:00
Nikolai Tillmann
ea0624b108 Distribute conditionals in certain relational expressions
Summary:
Release notes: More simplification rules

The existing simplifier would never go into relational expressions
and distribute conditional expressions. It does now.

With this change, `AbstractValue.createFromBinaryOp` joins many other
value factory functions that may return non-abstract values.

This caused various changes downstream in types, and dealing with concrete
instead of abstract values.

Adding regression test.
Closes https://github.com/facebook/prepack/pull/1972

Differential Revision: D8023363

Pulled By: NTillmann

fbshipit-source-id: a3cd6f7752ba24d039c6085bec2ee93f7587af26
2018-05-15 23:56:32 -07:00
Nikolai Tillmann
1d8e2d935e Move evaluateWithAbstractConditional
Summary:
Release notes: None

All other evaluate... functions are in Realm, so this is moving evaluateWithAbstractConditional there.
Closes https://github.com/facebook/prepack/pull/1971

Differential Revision: D8018543

Pulled By: NTillmann

fbshipit-source-id: 4690cd6b85e3c8e3c7afa82d8b18908c4b36b46c
2018-05-15 16:54:57 -07:00
Victor Hom
62bbdd4aee update the --timeout error
Summary:
Release Note: none

this is to fix issue #1952 where the --timeout throws a fatal error without more information

Would need to add a new error number to the wiki, unless there is an existing one that I should use instead.
Closes https://github.com/facebook/prepack/pull/1966

Differential Revision: D8017667

Pulled By: NTillmann

fbshipit-source-id: 8978092c3d4b505463850a5598f5eeaabcbffe1b
2018-05-15 16:33:23 -07:00
Nikolai Tillmann
505aa2bb28 Better crash logging
Summary:
Release notes: None

Provide a more insightful way of logging rich abstract values
for debugging.
Closes https://github.com/facebook/prepack/pull/1964

Differential Revision: D8015093

Pulled By: NTillmann

fbshipit-source-id: 47d9b42470df79133e90f44fb1e23fd8bf40f254
2018-05-15 14:05:45 -07:00
Dominic Gannaway
41df8539d8 General clean up of React reconciler + serializer code
Summary:
Release notes: none

This is a tidy up of the React reconciler and optimization code. I've removed the React logic from `serializer/functions.js` and put it all in its own module so that it's easier to debug and read the React specific code from generic Prepack optimization code. Furthermore, I took some time to rename `render` in reconciler to `resolve` as it's not actually doing any "rendering".
Closes https://github.com/facebook/prepack/pull/1968

Differential Revision: D8010381

Pulled By: trueadm

fbshipit-source-id: c61bdfec91f250f898d54623d92c20a545b965d7
2018-05-15 09:38:44 -07:00