Skip to content

Conversation

kripken
Copy link
Member

@kripken kripken commented Sep 21, 2016

As discussed in #343, this adds drop to br_ifs where necessary, and moves some stacky tests into stack.wast. With these changes, the "non-stacky" test files don't have stacky stuff, and binaryen can pass them (with just these disabled: stack, nop, typecheck).

;; TODO(stack): move this elsewhere
(module (func $type-break-num-vs-void
(block (i32.const 66) (br 0))
(block (drop (i32.const 66)) (br 0))
Copy link

Choose a reason for hiding this comment

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

It's not clear why this code needs changing, it would have worked with the AST without change. Could I ask why this is problematic for binaryen at present?

Copy link
Member Author

Choose a reason for hiding this comment

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

In the AST model, a value must be used or dropped. The 66 constant is not used, therefore it must be dropped.

Copy link

Choose a reason for hiding this comment

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

At one point at least the AST did support code such as (i32.add (i32.const 1) (br ...)) and (block (i32.const 1) (i32.const 2)) and 'statements' are consistent with an AST.

Copy link
Member Author

Choose a reason for hiding this comment

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

As I understand the AST, in your first example the 1 is used by the add. The second example was supported before explicit drop was decided, but after explicit drop the first of the two constants must be dropped.

Copy link

Choose a reason for hiding this comment

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

It seems ok for the AST apart from some constraint being assumed of 'explicit drop', but this constraint is overly restrictive as this code is valid with 'explicit drop'. I don't know your code, but might it just be a matter of relaxing a constraint, a simply matter to resolve in binaryen? This might not address all these cases, but perhaps a good number of them. If you could point me to the failing check then that might help me understand the challenge?

Copy link
Member Author

@kripken kripken Sep 22, 2016

Choose a reason for hiding this comment

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

It seems ok for the AST apart from some constraint being assumed of 'explicit drop'

Exactly. But explicit drop is what the wasm project decided, for better or for worse.

Copy link

Choose a reason for hiding this comment

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

As far as I am aware the 'explicit drop' constraints do not make these examples invalid, it's just binaryen, and we seem to agree that some of these are not incompatible with an AST either. I don't think these spec tests should be changed just to follow a more restrictive interpretation being made in binaryen.

The tests that would be incompatible with the binaryen AST for now are those that use an ordering that would demand first or lexical scoped constants. I think binaryen should work with the rest, relax the constraints, and just separate the remainder.

Copy link
Member

Choose a reason for hiding this comment

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

I think you can just remove this test here, it is superseded by the tests in unwind.wast (#344).

Copy link
Member

@rossberg rossberg left a comment

Choose a reason for hiding this comment

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

Thanks. It seems like all tests you moved to stack.wast are already subsumed by either nop.wast or will be by unwind.wast (#344), so I think it's fine to just delete them.

;; TODO(stack): move this elsewhere
(module (func $type-break-num-vs-void
(block (i32.const 66) (br 0))
(block (drop (i32.const 66)) (br 0))
Copy link
Member

Choose a reason for hiding this comment

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

I think you can just remove this test here, it is superseded by the tests in unwind.wast (#344).

)
(func (export "as-br_if-value-cond") (result i32)
(block i32 (br_if 0 (i32.const 6) (br 0 (i32.const 9))) (i32.const 7))
(block i32 (drop (br_if 0 (i32.const 6) (br 0 (i32.const 9)))) (i32.const 7))
Copy link
Member

Choose a reason for hiding this comment

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

He he, most of these are probably also fixed in #345.

"type mismatch"
)

;; TODO(stack): move these elsewhere
Copy link
Member

Choose a reason for hiding this comment

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

Equivalent tests exist in nop.wast, so you can just delete this.

"type mismatch"
)

;; TODO(stack): move these elsewhere
Copy link
Member

Choose a reason for hiding this comment

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

Same here, this can just go away.

)
;)

;; TODO(stack): move this elsewhere
Copy link
Member

Choose a reason for hiding this comment

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

This one is subsumed by unwind.wast (#344) as well.

"type mismatch"
)

;; TODO(stack): move these elsewhere
Copy link
Member

Choose a reason for hiding this comment

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

Same here.

)
(func (export "as-block-first-value") (param i32) (result i32)
(block i32 (br_if 0 (i32.const 10) (get_local 0)) (return (i32.const 11)))
(block i32 (drop (br_if 0 (i32.const 10) (get_local 0))) (return (i32.const 11)))
Copy link
Contributor

@titzer titzer Sep 22, 2016

Choose a reason for hiding this comment

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

I don't understand why a drop is required here, since br_if leaves its value on the stack in the false case, and then falls off the end of the block, and the block is annotated as i32.

Copy link
Member Author

Choose a reason for hiding this comment

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

The return is also in that block, i.e. with indentation it looks like this:

(block $block0 i32
  (br_if $block0
    (i32.const 10)
    (get_local $0)
  )
  (return
    (i32.const 11)
  )
)

@kripken
Copy link
Member Author

kripken commented Sep 23, 2016

@rossberg-chromium: ok, I pushed an update addressing your comments. also some fixes i noticed when running the tests.

@rossberg
Copy link
Member

LGTM

@rossberg rossberg merged commit bc4d747 into binary-0xc Oct 10, 2016
@kripken kripken deleted the stack-test-cleanup branch October 10, 2016 17:33
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.

3 participants