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

Short-circuiting conditionals (&&, ||) #78

Closed
kg opened this issue May 20, 2015 · 8 comments
Closed

Short-circuiting conditionals (&&, ||) #78

kg opened this issue May 20, 2015 · 8 comments

Comments

@kg
Copy link
Contributor

kg commented May 20, 2015

In a discussion about control flow it came up that asm.js currently doesn't support && or ||. The resulting control flow trees are pretty complicated sometimes. I think we should make sure short-circuiting boolean logic is expressible in webasm so that the resulting AST is denser and shallower. Thoughts?

EDITED: clarity

@jfbastien
Copy link
Member

+1

I also suggested that the polyfill should use short-circuit. This implies either adding them to asm.js (I remember discussing this with @sunfishcode and @kripken, but can't recall the outcome), or having the polyfill not be strictly asm.js.

@lukewagner
Copy link
Member

Polyfill isn't a problem because a && b === a ? b : 0 and a || b === a ? 1 : b, which is what Emscripten generates instead. Given ?:, the question of whether to add && and || goes back to the same directness vs. minimality question we're having in the other PRs. FWIW, in FF, those ternary forms are optimized to produce the expected control flow.

@kg
Copy link
Contributor Author

kg commented May 20, 2015

Ah, so ternaries work in asm.js but not && or ||? Interesting, less problematic.

@sunfishcode
Copy link
Member

Also worth noting is that when we implement the CFG structuring technique described in #44, the problem of complicated control flow will be reduced in general.

@titzer
Copy link

titzer commented Oct 22, 2015

Consensus is that we have statements = expressions, so building short-circuiting conditionals can be done pretty easilly.

@titzer titzer closed this as completed Oct 22, 2015
@kripken
Copy link
Member

kripken commented Oct 22, 2015

Where is the discussion leading to statements = expressions? I must have missed it.

@lukewagner
Copy link
Member

Even without stmts=exprs, AstSemantics.md currently has a ternary. asm.js does not have short-circuiting because ternary was sufficient.

@kripken
Copy link
Member

kripken commented Oct 22, 2015

More generally, we have an open issue on statements =?= expressions, #223, which does not have any conclusion, nor any activity for almost 4 months. That's why I'm surprised to hear @titzer say "Consensus is that we have statements = expressions".

(No concerns from me on closing this particular issue about && and ||.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants