Skip to content

Simplify loop by removing second label#710

Closed
sunfishcode wants to merge 2 commits intomasterfrom
labels
Closed

Simplify loop by removing second label#710
sunfishcode wants to merge 2 commits intomasterfrom
labels

Conversation

@sunfishcode
Copy link
Member

This removes loop's top label and if/else's end label, simplifying them, according to @rossberg-chromium's suggestion in #652.

With this PR, the only constructs that introduce labels are block (label at the end), loop (label at the beginning), and the function body itself (label at the end) (since the current semantics are that the function body acts like an implicit block).

@titzer
Copy link

titzer commented Jun 17, 2016

As a simplification, this PR makes sense. However, we've gone back and forth on the label issue multiple times due to trying to serve different goals: either code density, performance, or implementation simplicity. While I'd be happy to make this change for simplification, I am not sure we should do that just yet without some data on the other goals. Specifically, implementing implicit blocks for if was quite a pain to get right, but was justified at the time that it would make sense for code size. It'd be a shame to remove them now for simplicity and then add them back later when we again want to optimize for code size.

@sunfishcode
Copy link
Member Author

Changing if wasn't in my original proposal, but in his oposition to that proposal, @rossberg-chromium requested we change if too because he is "confident that is a super-rare case".

AstSemantics.md Outdated
within the `block`'s body.
Branches may only reference labels defined by an outer *enclosing construct*,
which can be a `block` (with a label at the end), `loop` (with a label at the
beginning), or the function body (with a label at the end). This means that,
Copy link

Choose a reason for hiding this comment

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

'or the function body (with a label at the end)' - this seems a significant new change too? Could this be deferred to discussion in a separate issue. One concern is that this might require an interpretation of the break arguments as the return values when the multi-value support has not been determined yet - this interpretation might be ok but there are different ways this could go.

@lukewagner
Copy link
Member

I'm in favor of this PR too.

@rossberg
Copy link
Member

I'm fine with this patch, too (although it's a bit sad to see the nice return=break unification go -- I'd be fine with leaving that alone, although my own consistency argument speaks against it :) ).

If we do not make this change and keep all implicit labels, then I would at least propose to switch the order of the two loop labels. Then you can explain the design consistently by saying that all block-like expression sequences have an implicit label directly enclosing them.

This removes loop's bottom label.
@sunfishcode
Copy link
Member Author

Updated this PR to just remove the bottom label of loop.

AstSemantics.md Outdated

* `block`: yields either the value of the last expression in the block or the result of an inner branch that targeted the label of the block
* `loop`: yields either the value of the last expression in the loop or the result of an inner branch that targeted the end label of the loop
* `loop`: yields either the value of the last expression in the loop
Copy link
Member

Choose a reason for hiding this comment

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

nit: no "either"

@lukewagner lukewagner changed the title Simplify loop and if by removing labels. Simplify loop by removing second label Sep 14, 2016
Copy link

@titzer titzer left a comment

Choose a reason for hiding this comment

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

lgtm

@sunfishcode
Copy link
Member Author

Merged with lgtms above. This PR was against the master branch and github doesn't allow this to be changed, so I've now pushed the change directly to binary_0xc, and am closing this PR.

@sunfishcode sunfishcode deleted the labels branch September 15, 2016 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants