Skip to content

disable do{...}while(false) optimisation#1534

Merged
alexlamsl merged 1 commit intomishoo:masterfrom
alexlamsl:issue-1532
Mar 2, 2017
Merged

disable do{...}while(false) optimisation#1534
alexlamsl merged 1 commit intomishoo:masterfrom
alexlamsl:issue-1532

Conversation

@alexlamsl
Copy link
Copy Markdown
Collaborator

fixes #1532

/cc @kzc

}
} else {
// self instanceof AST_Do
return self.body;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer being more explicit and keeping this else and have it return self;. At the very least it avoids the if below.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But removing those lines would be a clean revert. That return make_node(AST_For, self, self).transform(compressor); part from down below has always been there, just tucked away in OPT(AST_While) instead of here instead. So adding return self; would actually alter the flow.

See also #1534 (comment)

Copy link
Copy Markdown
Contributor

@kzc kzc Mar 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would } else { /* self instanceof AST_Do */ return self; } alter the flow? The following if (self instanceof AST_While) would not be triggered and then return self; would be called.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... good point. Sorry for being thick tonight 😅

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to leave this as-is, that's fine. I was trying to avoid an if for do-whiles but the cost is insignificant.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too late, I've done it your way 👻

@kzc
Copy link
Copy Markdown
Contributor

kzc commented Mar 2, 2017

This would fix the do-while case, but how much confidence do you have in the break and continue analysis of while loops in #1452?

@alexlamsl
Copy link
Copy Markdown
Collaborator Author

how much confidence do you have in the break and continue analysis of while loops in #1452?

I'm a bit confused here - the part that is kept intact from #1452 is moving what used to be OPT(AST_While) into OPT(AST_DWLoop) which should be functionally equivalent as before that PR.

@kzc
Copy link
Copy Markdown
Contributor

kzc commented Mar 2, 2017

I was referring to: #1452 (comment)

If you think it's okay, no problem.

@alexlamsl
Copy link
Copy Markdown
Collaborator Author

Ah, I see - sorry for the misunderstanding. I can just add that line back in if that makes everybody warm and fuzzy 😉

@alexlamsl
Copy link
Copy Markdown
Collaborator Author

if_break_in_loop() put back in - after this and #1535 I guess another release is warranted.

@kzc
Copy link
Copy Markdown
Contributor

kzc commented Mar 2, 2017

if_break_in_loop() put back in

I think we should either revert #1452 entirely or just fix the do-while-false case.

If you are confident that if_break_in_loop() is redundant, then don't reintroduce it. I'm just saying that I do not know.

@alexlamsl
Copy link
Copy Markdown
Collaborator Author

If you are confident that if_break_in_loop() is redundant, then don't reintroduce it.

I was when I looked at it, and currently I'm certain it does not cause #1532.

Will leave it out of this PR then.

- fails to handle `break` in body

fixes mishoo#1532
@alexlamsl
Copy link
Copy Markdown
Collaborator Author

So this ends up being an one-liner (excluding the new tests obviously)

@alexlamsl alexlamsl merged commit b49e142 into mishoo:master Mar 2, 2017
@alexlamsl alexlamsl deleted the issue-1532 branch March 2, 2017 16:54
@alexlamsl
Copy link
Copy Markdown
Collaborator Author

@kzc btw, I just checked my email and I noticed this:

would be more hyperlink friendly in github browsing.

Did I miss that or did you delete it before I had a chance to read? 😅

@kzc
Copy link
Copy Markdown
Contributor

kzc commented Mar 2, 2017

Nothing gets passed you. :-)

I deleted it when I realized github doesn't support that. I was thinking of a pre-git source control system I was using.

@kzc
Copy link
Copy Markdown
Contributor

kzc commented Mar 2, 2017

I guess another release is warranted.

Yes, #1534 and #1535 warrant a 2.8.5 release.

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.

Break statement left in function when uglifying do while loop

2 participants