alexlamsl
44d6b47bdc
Merge branch 'master' into harmony-v2.8.14
2017-03-19 15:31:18 +08:00
Alex Lam S.L
96f8befdd7
fix commit 88fb83a ( #1622 )
...
The following is wrong:
`a == (b ? a : c)` => `b`
Because:
- `b` may not be boolean
- `a` might have side effects
- `a == a` is not always `true` (think `NaN`)
- `a == c` is not always `false`
2017-03-19 11:59:42 +08:00
Alex Lam S.L
cd58635dcc
fix AST_Binary.lift_sequences() ( #1621 )
...
Commit eab99a1c fails to account for side effects from compound assignments.
2017-03-19 03:04:22 +08:00
Alex Lam S.L
274331d0ea
transform String.charAt() to index access ( #1620 )
...
Guarded by `unsafe` as `charAt()` can be overridden.
2017-03-19 02:17:15 +08:00
alexlamsl
75c3c8963f
Merge branch 'master' into harmony-v2.8.13
2017-03-18 02:52:45 +08:00
Alex Lam S.L
ac40301813
fix chained evaluation ( #1610 )
...
`reduce_vars` enables substitution of variables but did not clone the value's `AST_Node`.
This confuses `collapse_vars` and result in invalid AST and subsequent crash.
fixes #1609
2017-03-17 00:26:48 +08:00
Alex Lam S.L
5ae04b3545
make collapse_vars consistent with toplevel ( #1608 )
...
fixes #1605
2017-03-16 13:22:26 +08:00
Alex Lam S.L
a80b228d8b
fix hoist_vars on reduce_vars ( #1607 )
...
`hoist_vars` converts variable declarations into plain assignments, which then confuses `reduce_vars`
fixes #1606
2017-03-16 12:03:30 +08:00
Alex Lam S.L
cf4bf4ceb1
fix stack issues with AST_Node.evaluate() ( #1603 )
...
As patched in #1597 , `make_node_from_constant()` makes inconsistent and sometimes incorrect calls to `optimize()` and `transform()`.
Fix those issues properly by changing the semantics of `evaluate()` and `make_node_from_constant()`, with the side effect that `evaluate()` no longer eagerly converts constant to `AST_Node`.
2017-03-16 01:02:59 +08:00
Alex Lam S.L
8223b2e0db
fix AST_Node.optimize() ( #1602 )
...
Liberal use of `Compressor.transform()` and `AST_Node.optimize()` presents an issue for look-up operations like `TreeWalker.in_boolean_context()` and `TreeWalker.parent()`.
This is an incremental fix such that `AST_Node.optimize()` would now contain the correct stack information when called correctly.
2017-03-15 18:44:13 +08:00
Alex Lam S.L
381bd3836e
minor clean-ups ( #1600 )
...
- remove obsolete optimisation in `AST_Binary` after #1477
- improve `TreeWalker.has_directive()` readability and resilience against multiple visits
2017-03-14 13:19:05 +08:00
alexlamsl
8f7ab602e2
Merge branch 'master' into harmony-v2.8.12
2017-03-14 13:17:42 +08:00
Alex Lam S.L
1dd339f95e
fix unused crashes ( #1599 )
...
- `AST_DefaultAssign` on `keep_fargs`
- `AST_Expansion on` `keep_fargs`
- `AST_Destructuring` on top-level declarations without `toplevel`
2017-03-14 13:13:43 +08:00
Alex Lam S.L
e3a3db73ae
temporary fix for boolean bug ( #1597 )
...
fixes #1592
2017-03-11 04:59:55 +08:00
Alex Lam S.L
d9344f30b8
disallow parameter substitution for named IIFEs ( #1596 )
...
Self-referenced function has non-fixed values assigned to its parameters.
Let `unused` & `!keep_fnames` do the scanning, then apply `reduce_vars` only to unnamed functions.
fixes #1595
2017-03-11 03:34:55 +08:00
alexlamsl
f4a12b34f2
Merge branch 'master' into harmony-v2.8.11
2017-03-10 11:17:49 +08:00
Alex Lam S.L
b633706ce4
fix & improve function argument compression ( #1584 )
...
- one-use function call => IIFE should take `eval()` & `arguments` into account
- if unused parameter cannot be eliminated, replace it with `0`
fixes #1583
2017-03-09 19:11:05 +08:00
alexlamsl
8f4b45f4f8
Merge branch 'master' into harmony-v2.8.10
2017-03-09 06:02:28 +08:00
Alex Lam S.L
7e465d4a01
scan RHS of dropped assignments ( #1581 )
...
- similar case as #1578 but against #1450 instead
- fix `this` binding in #1450 as well
closes #1580
2017-03-09 05:22:27 +08:00
Alex Lam S.L
711f88dcb4
scan assignment value in drop_unused() ( #1578 )
...
those were not optimised for `unused` before, which made it necessary for `reduce_vars` to have separate steps for `keep_fnames`
docs update by @kzc
closes #1577
2017-03-08 18:37:32 +08:00
Alex Lam S.L
c7cdcf06a6
fix function name eliminiation ( #1576 )
...
Function expression can be assigned to a variable and be given a name. Ensure function name is the reduced variable before clearing it out.
fixes #1573
fixes #1575
2017-03-08 12:39:57 +08:00
Alex Lam S.L
bd6dee52ab
fix return from recursive IIFE ( #1570 )
...
`side-effects` did not account for IIFEs being able to reference itself thus making its return value potentially significant
2017-03-08 03:31:51 +08:00
alexlamsl
250b782b1e
Merge branch 'master' into harmony-v2.8.8
2017-03-07 20:25:52 +08:00
Alex Lam S.L
8153b7bd8a
transform function calls to IIFEs ( #1560 )
...
- expose function body to call sites for potential optimisations
- suppress substitution of variable used within `AST_Defun`
2017-03-07 15:37:52 +08:00
Alex Lam S.L
d787d70127
avoid substitution of global variables ( #1557 )
...
- unless `toplevel` is enabled
- global `const` works as before
2017-03-07 03:11:03 +08:00
kzc
3ac2421932
collapse_vars: do not replace a constant in loop condition or init ( #1562 )
2017-03-07 01:42:33 +08:00
alexlamsl
aa605495f8
Merge branch 'master' into harmony-v2.8.6
2017-03-05 21:42:34 +08:00
kzc
33a26d456b
patch up #1543 for harmony
...
fixes #1537
2017-03-05 21:39:31 +08:00
Alex Lam S.L
067e5a5762
fixup for #1553 ( #1555 )
...
- `++a` is the one that is foldable
- transform `a++` into `++a` for better optimisation
2017-03-05 17:15:37 +08:00
alexlamsl
49d9ac1c43
Merge branch 'master' into harmony-v2.8.6
2017-03-05 16:03:56 +08:00
Alex Lam S.L
35a849dc48
collapse assignment with adjacent subsequent usage ( #1553 )
...
- consolidate `cascade` optimisations
- support ++/-- postfixes
- remove redundant optimisation identified in #1460
fixes #368
2017-03-05 14:56:14 +08:00
Alex Lam S.L
b70591be1a
handle variable declaration within catch blocks ( #1546 )
...
accounts for IE8- scoping
2017-03-05 13:13:44 +08:00
Alex Lam S.L
b33e7f88e6
improve unsafe on undefined ( #1548 )
...
`unsafe` turns undefined keyword into a variable of the same name if found, but that interferes with other related optimisations.
Keep track of such transformations to ensure zero information loss in the process.
2017-03-05 13:09:27 +08:00
Alex Lam S.L
1f0333e9f1
stay safe with constants in IE8- ( #1547 )
...
- `undefined` etc. can be redefined at top-level for IE8-, so disable related optimisations
- fixed `--support-ie8` catch mangle bug
2017-03-05 12:51:11 +08:00
Alex Lam S.L
78d1bb92d4
fix a corner case in #1530 ( #1552 )
2017-03-05 12:12:59 +08:00
kzc
ce54c9ccee
disallow collapse_vars constant replacement in for-in statements ( #1543 )
2017-03-04 02:39:54 +08:00
Alex Lam S.L
07accd2fbb
process code with implicit return statement ( #1522 )
...
Bookmarklet for instance implicitedly assumes a "completion value" without using `return`.
The `expression` option now supports such use cases.
Optimisations on IIFEs also enhanced.
fixes #354
fixes #543
fixes #625
fixes #628
fixes #640
closes #1293
2017-03-03 18:13:07 +08:00
Alex Lam S.L
18059cc94f
compress numerical expressions ( #1513 )
...
safe operations
- `a === b` => `a == b`
- `a + -b` => `a - b`
- `-a + b` => `b - a`
- `a+ +b` => `+b+a`
associative operations
(bit-wise operations are safe, otherwise `unsafe_math`)
- `a + (b + c)` => `(a + b) + c`
- `(n + 2) + 3` => `5 + n`
- `(2 * n) * 3` => `6 * n`
- `(a | 1) | (2 | d)` => `(3 | a) | b`
fixes #412
2017-03-03 18:04:32 +08:00
alexlamsl
f704e9b65c
fix destructing crash in reduce_vars
...
fixes #1531
2017-03-03 07:23:46 +08:00
alexlamsl
0b77d861a8
Merge branch 'master' into harmony-v2.8.5
2017-03-03 07:17:52 +08:00
Alex Lam S.L
b5e0e8c203
facilitate fix for #1531 ( #1542 )
2017-03-03 07:12:24 +08:00
Alex Lam S.L
17b81350d4
fix chained assignment with unused ( #1540 )
...
When #1450 optimises `a=b=42`, it stops after the first variable even if both are unused.
fixes #1539
2017-03-03 04:45:20 +08:00
kzc
4d63d4f5b3
collapse_vars should not replace constant in for-in init section ( #1538 )
...
fixes #1537
2017-03-03 03:51:15 +08:00
Alex Lam S.L
70d72ad806
properly cover all cases of for-in loop variables ( #1536 )
2017-03-03 02:39:57 +08:00
Alex Lam S.L
fe9227a41b
fix reference marking in for-in loops ( #1535 )
...
fixes #1533
2017-03-03 00:56:06 +08:00
Alex Lam S.L
b49e142a26
disable do{...}while(false) optimisation ( #1534 )
...
- fails to handle `break` in body
fixes #1532
2017-03-03 00:54:41 +08:00
kzc
ee3b39b909
optimize trivial IIFEs returning constants ( #1530 )
2017-03-02 15:11:40 +08:00
Alex Lam S.L
9699ffb1af
trim unused invocation parameters ( #1526 )
2017-03-02 11:33:59 +08:00
Alex Lam S.L
fdc9b9413b
minor improvement to string optimisation ( #1514 )
...
- "" + "a" => "a"
- "" + a + "b" => a + "b"
- "a" + "" => "a" (improving on #45 )
2017-03-02 11:31:39 +08:00
alexlamsl
80f3ad3ce0
Merge branch 'master' into harmony-v2.8.4
2017-03-02 11:16:55 +08:00