Alex Lam S.L
3276740779
fallthrough should not execute case expression ( #1683 )
...
- de-duplicate trailing cases only, avoid all potential side-effects
- enable switch statement fuzzing
fixes #1680
2017-03-26 16:52:38 +08:00
kzc
5509e51098
optimize conditional when condition symbol matches consequent ( #1684 )
2017-03-26 16:36:33 +08:00
Alex Lam S.L
94f84727ce
suppress switch branch de-duplication upon side effects ( #1682 )
...
fixes #1679
2017-03-26 13:32:43 +08:00
Alex Lam S.L
8a4f86528f
fix side-effects detection on switch statements ( #1678 )
...
extension of #1675
2017-03-26 12:05:44 +08:00
kzc
6a54de79b5
optimize trivial arrow functions with a return statement in braces ( #1681 )
...
fixes #1676
2017-03-26 12:03:11 +08:00
Alex Lam S.L
f83d370f57
improve switch optimisations ( #1677 )
...
- correctly determine reachability of (default) branches
- gracefully handle multiple default branches
- optimise branches with duplicate bodies
fixes #376
fixes #441
fixes #1674
2017-03-26 05:15:46 +08:00
Alex Lam S.L
b19aa58cff
fix has_side_effects() ( #1675 )
...
`AST_Try` is an `AST_Block`, so besides try block we also need to inspect catch and finally blocks for possible side effects.
Also extend this functionality to handle `AST_If` and `AST_LabeledStatement` while we are at it.
fixes #1673
2017-03-25 23:03:26 +08:00
Alex Lam S.L
0a65de89b9
fix reduce_vars on AST_Switch ( #1671 )
...
Take conditional nature of switch branches into account.
fixes #1670
2017-03-25 21:17:30 +08:00
Alex Lam S.L
6e86ee950d
fix typeof side-effects ( #1669 )
...
`has_side_effects()` does not take `typeof`'s magical power of not tripping over undeclared variable into account.
fixes #1668
2017-03-25 17:40:18 +08:00
Alex Lam S.L
8ca2401ebe
fix dead_code on AST_Switch ( #1667 )
...
Need to call `extract_declarations_from_unreachable_code()`.
fixes #1663
2017-03-25 16:21:42 +08:00
Alex Lam S.L
a30092e20f
fix invalid AST_For.init ( #1657 )
...
Turns out the only place in `Compressor` which can generate invalid `AST_For.init` is within `drop_unused()`, so focus the fix-up efforts.
supercedes #1652
fixes #1656
2017-03-25 03:18:36 +08:00
Alex Lam S.L
32283a0def
fix cascade of evaluate optimisation ( #1654 )
...
Operator has changed, so break out from rest of the rules.
fixes #1649
2017-03-24 22:09:19 +08:00
Alex Lam S.L
ac51d4c5a0
fix corner case in AST_For.init ( #1652 )
...
Enforce `null` as value for empty initialisation blocks.
fixes #1648
2017-03-24 19:31:17 +08:00
Alex Lam S.L
0432a7abb9
fix assignment extraction from conditional ( #1651 )
...
fixes #1645
fixes #1646
2017-03-24 18:52:48 +08:00
Alex Lam S.L
f3a1694a41
fix assignment substitution in sequences ( #1643 )
...
take side effects of binary boolean operations into account
fixes #1639
2017-03-24 14:30:31 +08:00
Alex Lam S.L
e918748d88
improve collapsible value detection ( #1638 )
...
- #1634 bars variables with cross-scope references in between to collapse
- but if assigned value is side-effect-free, no states can be modified, so it is safe to move
2017-03-24 02:55:32 +08:00
alexlamsl
97d0fc271d
Merge branch 'master' into harmony-v2.8.15
2017-03-23 15:28:17 +08:00
Alex Lam S.L
48ffbef51d
account for cross-scope modifications in collapse_vars ( #1634 )
...
mostly done by @kzc
fixes #1631
2017-03-23 07:17:34 +08:00
Alex Lam S.L
c0f3feae9f
introduce compressor.info() ( #1633 )
...
report the following only when `options.warnings = "verbose"`
- unused elements due to inlining
- collpased variables
2017-03-23 06:49:49 +08:00
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