Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

evaluate AST_SymbolRef as parameter #1477

Closed
wants to merge 1 commit into from

Conversation

alexlamsl
Copy link
Collaborator

@kzc this addresses the quirk you've mentioned in #1473 (comment)

@alexlamsl
Copy link
Collaborator Author

(Travis CI timed out.)

@alexlamsl alexlamsl closed this Feb 9, 2017
@alexlamsl alexlamsl reopened this Feb 9, 2017
@kzc
Copy link
Contributor

kzc commented Feb 9, 2017

Nice.

LGTM

@alexlamsl alexlamsl changed the title evaluate AST_SymbolRef as parameter [WIP] evaluate AST_SymbolRef as parameter Feb 9, 2017
@alexlamsl
Copy link
Collaborator Author

Discovered bug while testing with test/benchmark.js - investigating.

@kzc
Copy link
Contributor

kzc commented Feb 9, 2017

It would be good to run uglifyjs -c -m on well known benchmarks that verify their results.

This one uses real life code rather than synthetic and/or unit tests:

http://browserbench.org/JetStream/

@alexlamsl
Copy link
Collaborator Author

alexlamsl commented Feb 9, 2017

So I stepped on a landmine which is make_node_from_constant() calling AST_Node.optimize() without any regards for the compressor's context 😅

Given the intertwined nature of this bug, I guess I should fix it alongside this PR. If I'm correct, it will also trigger in the case of [].join() optimisation as well.

@alexlamsl alexlamsl changed the title [WIP] evaluate AST_SymbolRef as parameter evaluate AST_SymbolRef as parameter Feb 9, 2017
@alexlamsl
Copy link
Collaborator Author

Phew, I think this is sorted and ready to go now 😉

fix invalid boolean conversion now exposed in `make_node_from_constant()`
@alexlamsl
Copy link
Collaborator Author

alexlamsl commented Feb 9, 2017

It would be good to run uglifyjs -c -m on well known benchmarks that verify their results.

I couldn't find those files in a VCS repository - should I just download a copy of everything from http://browserbench.org/JetStream/in-depth.html and work from there?

Edit: #1479

@kzc
Copy link
Contributor

kzc commented Feb 9, 2017

I see you've changed optimize() to transform() in a few places - what's the difference?

Also, you've dropped optimize() altogether in some spots? ¿Qué pasa?

@kzc
Copy link
Contributor

kzc commented Feb 9, 2017

I couldn't find those files in a VCS repository - should I just download a copy of everything from http://browserbench.org/JetStream/in-depth.html and work from there?

I tried running Jetstream locally with node but errored out because it can't find the source for the function BenchmarkSuite, nor could I find a source repo. Then I gave up.

@alexlamsl
Copy link
Collaborator Author

AST_Node.optimize(compressor) does not reset TreeWalker.stack and just continue from where make_node_from_constant() is called - so when you tried to evaluate() AST_Call.args and the call happens to be in a Boolean context, e.g. c(a) ? 1 : 2, a would be told to be safe to transform into AST_Boolean. Obviously bad things then happen.

AST_Node.transform(compressor) start a fresh tree transformation so this won't be an issue. I basically took out the AST_Constant calls to .optimize(compressor) where there are no transformation defined within compress.js, then convert the ones that do to .transform(compressor) to avoid the aforementioned issue.

@kzc
Copy link
Contributor

kzc commented Feb 9, 2017

@alexlamsl Regarding your explanation above - were you able to create a such a failing test case against uglify-js@2.7.5?

@alexlamsl
Copy link
Collaborator Author

@kzc the cases I run into where .in_boolean_context() would cause confusion applies to AST_Array, AST_Object and AST_RegExp. The other place I spotted this to have a context mismatch, [].join(), only calls make_node_from_string() that will hit the AST_String path.

I could continue to investigate further to see if other evaluate() / make_node_from_constant() cases would have this issue, but so far I haven't got any other cases where this would lead to incorrect results on master yet.

This was referenced Feb 11, 2017
alexlamsl added a commit to alexlamsl/UglifyJS that referenced this pull request Feb 18, 2017
fix invalid boolean conversion now exposed in `make_node_from_constant()`

closes mishoo#1477
@alexlamsl alexlamsl closed this in 974247c Feb 23, 2017
@alexlamsl alexlamsl deleted the evaluate-fargs branch February 24, 2017 00:25
alexlamsl added a commit to alexlamsl/UglifyJS that referenced this pull request Mar 10, 2017
alexlamsl added a commit to alexlamsl/UglifyJS that referenced this pull request Mar 10, 2017
Given the current `OPT()` node:
- `optimize(compressor)` works on the same level, and will only `descend()` if returned instance is different
- `transform(compressor)` works on child nodes, and will always `descend()`

Other fixes
- `loopcontrol_target()` should compare against `compressor.self()` since the current node may have already been displaced
- remove obsolete optimisation in `AST_Binary` after mishoo#1477

fixes mishoo#1592
alexlamsl added a commit to alexlamsl/UglifyJS that referenced this pull request Mar 14, 2017
- remove obsolete optimisation in `AST_Binary` after mishoo#1477
- improve `TreeWalker.has_directive()` readability and resilience against multiple visits
@alexlamsl alexlamsl mentioned this pull request Mar 14, 2017
alexlamsl added a commit that referenced this pull request Mar 14, 2017
- remove obsolete optimisation in `AST_Binary` after #1477
- improve `TreeWalker.has_directive()` readability and resilience against multiple visits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants