Skip to content

Fix resolution of delegate labels - #1675

Merged
aheejin merged 2 commits into
WebAssembly:mainfrom
takikawa:fix-delegate-labels
Jun 29, 2021
Merged

aheejin merged 2 commits into
WebAssembly:mainfrom
takikawa:fix-delegate-labels

Conversation

@takikawa

@takikawa takikawa commented Jun 12, 2021 •

Copy link
Copy Markdown
Contributor

This PR has two commits for fixing bugs related to try-delegate labels.

One fixes the printing in certain cases (similar to #1609).

The other fixes the label resolution code. Example from the spec (https://github.com/WebAssembly/exception-handling/blob/master/proposals/exception-handling/Exceptions.md):

try $l1
  try
    call $foo
  delegate $l1  ;; (= delegate 0)
catch
  ...
catch_all
  ...
end

The label $l1 should resolve to 0 in the delegate target, which is 1 less than how typical block constructs work. The current code mis-resolves this to 1. It should also error in cases like the following:

try $l1
  nop
delegate $l1

Because it's not possible to represent the label $l1 in the binary format, as a try-delegate cannot target itself.

@aheejin aheejin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry for the late reply! Can we split the two fixes into two separate PRs?

Comment thread test/roundtrip/fold-try-delegate.txt Resolved
The labels for a try-delegate should start resolving one block
further out than usual. Example:

  try $l1
    try $l2
      call $foo
    delegate $l1  ;; (= delegate 0)
  end

Using $l2 is an error as try-delegate cannot target it.
@takikawa
takikawa force-pushed the fix-delegate-labels branch from a32df0c to 927c54f Compare June 29, 2021 00:51
@takikawa takikawa changed the title Fix printing and resolution of delegate labels Fix resolution of delegate labels Jun 29, 2021
@takikawa

Copy link
Copy Markdown
Contributor Author

Sorry for the late reply! Can we split the two fixes into two separate PRs?

No problem, I've split the printing fix out as #1685 now.

Comment thread src/resolve-names.cc
// immediately enclosing try block.
delegate_target->set_index(delegate_target->index() - 1);
}
// Pop the label here as a try-delegate has no `end` instruction.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Note: I added this line in the latest revision, as this was another bug in this resolution code. (it is sufficiently tested by the dump test case I added---without the pop the $try1 label was off because it came after another try-delegate.)

@takikawa

takikawa commented Jun 29, 2021 •

Copy link
Copy Markdown
Contributor Author

In order to make the two split PRs mergeable in any order, I changed the test addition in this PR. Instead of testing in roundtrip, this modifies dump/try-delegate.txt to ensure the label gets resolved correctly.

Comment thread src/resolve-names.cc Resolved

@aheejin aheejin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@aheejin
aheejin merged commit 6448318 into WebAssembly:main Jun 29, 2021
aheejin pushed a commit that referenced this pull request Jun 29, 2021
This is similar to a previous bug (#1609) for other kinds of block labels.

The tests check that 2+ adjacent try-delegate blocks will have labels that print correctly.

(split from #1675)
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.

2 participants