Skip to content

Break expression handling #179

@jcbeyler

Description

@jcbeyler

Dear all,

As I was starting to handle more complex labeling, I was looking at the labels.wast case:

  (func $loop2 (result i32)
    (local $i i32)
    (set_local $i (i32.const 0))
    (loop $exit $cont
      (set_local $i (i32.add (get_local $i) (i32.const 1)))
      (if (i32.eq (get_local $i) (i32.const 5))
        (br $cont (i32.const -1))
      )
      (if (i32.eq (get_local $i) (i32.const 8))
        (br $exit (get_local $i))
      )
      (set_local $i (i32.add (get_local $i) (i32.const 1)))
      (br $cont)
    )
  )

I am especially interested in this break:
(br $cont (i32.const -1))

Is the idea behind this to say:

  • If I do branch back to the loop, execute the code of the expression before jumping (well here it would get DCE'd anyway but still)
    • So for example, if it was (unreachable) we would trap there instead of DCE-ing it
  • Even though I know no one will consume it afterwards (compared to a branch to an exit for example)

I read the design and it wasn't clear if this was or not the behavior that we were going for and I'd prefer checking.

Thanks!
Jc

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