Skip to content

Document behavior of label name reuse. #210

Closed

Description

@mbebenita

Currently, the spec does not say if label name reuse is allowed or not:

f3015ed#diff-d372e456aea857e846293c5f4add7c81R156

I'm not sure what the current implemented behavior is, but I suppose there are only two options:

  1. Not allowed.
  2. Allowed, but scoped (not allowed if ambiguous).

Activity

  1. changed the title [-]Document behavior of label reuse. [/-] [+]Document behavior of label name reuse.[/+] on Jan 20, 2016
  2. binji commented on Jan 20, 2016

    @binji
    Member

    Just tested this with the spec interpreter:

    (module
      (export "f" $f)
      (func $f
        (loop $foo $foo
          (block $foo
            (block $foo
              (br $foo))))
    ))
    

    No error. It seems that the spec interpreter just uses the first label it finds.

  3. mbebenita commented on Jan 21, 2016

    @mbebenita
    ContributorAuthor

    What about:

    (loop $foo $foo
      (br $foo))
    

    Is this a break or continue?

  4. mbebenita commented on Jan 21, 2016

    @mbebenita
    ContributorAuthor

    If this is the behavior we want, then I guess we should spec the label search order. I feel that relying on search order is kind of error prone.

  5. mbebenita commented on Jan 21, 2016

    @mbebenita
    ContributorAuthor

    @JSStats I was under the impression that the loop blocks are just blocks with an additional label. So it effectively has two labels, and they are both outer labels as far as the (br $foo) is concerned. Am I missing something here?

    (block $foo
      (br $foo) ;; break
    )
    
    (loop $foo %bar
      (br $foo) ;; continue
      (br $bar) ;; break
    )
    
    (loop $foo %foo
      (br $foo) ;; continue or break?
    )
    
  6. kripken commented on Jan 21, 2016

    @kripken
    Member

    I'm in favor of disallowing the ambiguous cases (1 or 2 in the first comment).

  7. binji commented on Jan 21, 2016

    @binji
    Member
    (loop $foo $bar ...)
    

    is sugar for

    (block $foo (loop $bar ...))
    

    See https://github.com/WebAssembly/spec/blob/master/ml-proto/README.md#s-expression-syntax.

    Testing this in ml-proto:

    (module
      (export "f" $f)
      (func $f
        (loop $foo $foo
          (br $foo))
    ))
    (invoke "f")
    

    is an infinite loop.

    So the search order is from "outward".

  8. mbebenita commented on Jan 21, 2016

    @mbebenita
    ContributorAuthor

    @kripken option 2 is consistent with JS semantics, so I'd favor that as well.

  9. mbebenita commented on Jan 21, 2016

    @mbebenita
    ContributorAuthor

    @binji ah, I see, that makes sense.

  10. rossberg commented on Jan 21, 2016

    @rossberg
    Member

    Labels have standard lexical scoping behaviour. That is, they scope over the labelled expression, and can be shadowed within their scope. The loop case is defined by its desugaring.

    We could disallow shadowing, but I don't see a strong reason for that. Everything regarding names is not part of the "official" spec semantics anyway.

  11. kg commented on Jan 21, 2016

    @kg
    Contributor

    We could disallow shadowing, but I don't see a strong reason for that.

    What is the advantage? From my perspective this has disadvantages because it is unusual and mostly creates an opportunity for confusion.

    Everything regarding names is not part of the "official" spec semantics anyway.

    This doesn't match our design history, and it feels like a semantic trick. In the context of tableswitch and a bunch of cases, the best way to describe the numbering of the br targets for the cases would be labels where the names are arbitrary compiler-assigned numbers.

  12. rossberg commented on Jan 22, 2016

    @rossberg
    Member

    On 21 January 2016 at 18:14, Katelyn Gadd [email protected] wrote:

    We could disallow shadowing, but I don't see a strong reason for that.

    What is the advantage? From my perspective this has disadvantages because
    it is unusual and mostly creates an opportunity for confusion.

    Allowing shadowing ensures locality and compositionality: without it, you
    cannot syntactically insert a piece of code into another piece and expect
    it to keep working. At least in general language design, that is a very
    useful modularity property. Not saying it's super-important here, but I
    also don't see the opposite.

    Everything regarding names is not part of the "official" spec semantics

    anyway.

    This doesn't match our design history,

    Not sure why you're saying that. The AST semantics never had names, AFAIR.

    and it feels like a semantic trick. In the context of tableswitch and a

    bunch of cases, the best way to describe the numbering of the br targets
    for the cases would be labels where the names are arbitrary
    compiler-assigned numbers.

    —
    Reply to this email directly or view it on GitHub
    #210 (comment).

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions