Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add val_cnt and pop_cnt in side table #649

Merged
merged 16 commits into from
Nov 18, 2024

Conversation

zhouwfang
Copy link
Member

There was an earlier review in zhouwfang#2.

#46

@zhouwfang zhouwfang requested a review from ia0 as a code owner October 23, 2024 05:30
@zhouwfang
Copy link
Member Author

zhouwfang commented Oct 23, 2024

The hw-host error says Internal:NotImplemented. What does it refer to?

Copy link
Member

@ia0 ia0 left a comment

Choose a reason for hiding this comment

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

Thanks! Going through I realized we probably want to store val_cnt in source branches already since that's an information available at that time. This is particularly relevant in br_label().

So I suggest:

  • Add result: usize to SideTableBranch which is always zero for target branches and represents val_cnt for source branches.
  • Make branch_source() take result: usize.
  • Refactor br_label() to match on the label kind before creating the source branch, returning (ResultType, Option<SideTableBranch>) which is the result of the function and the target branch (if it's a loop). Then create the source branch with the result length, match on the option to stitch or push, and return the result.

crates/interpreter/src/valid.rs Outdated Show resolved Hide resolved
crates/interpreter/src/valid.rs Outdated Show resolved Hide resolved
crates/interpreter/src/valid.rs Outdated Show resolved Hide resolved
crates/interpreter/src/valid.rs Outdated Show resolved Hide resolved
crates/interpreter/src/valid.rs Outdated Show resolved Hide resolved
crates/interpreter/src/valid.rs Outdated Show resolved Hide resolved
crates/interpreter/src/valid.rs Outdated Show resolved Hide resolved
crates/interpreter/src/valid.rs Outdated Show resolved Hide resolved
crates/interpreter/src/valid.rs Outdated Show resolved Hide resolved
crates/interpreter/src/valid.rs Show resolved Hide resolved
@ia0
Copy link
Member

ia0 commented Oct 23, 2024

The hw-host error says Internal:NotImplemented. What does it refer to?

Ideally we should #[cfg(feature = "debug")] eprintln!(""); before returning Unsupported such that we can easily debug with runner host --features=wasefire-interpreter/debug.

@zhouwfang zhouwfang requested a review from ia0 October 24, 2024 05:45
Copy link
Member

@ia0 ia0 left a comment

Choose a reason for hiding this comment

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

Ok, I think it should be mostly correct. It'll be easier to debug once we can run the test suite using the side table.

crates/interpreter/src/valid.rs Outdated Show resolved Hide resolved
crates/interpreter/src/valid.rs Outdated Show resolved Hide resolved
crates/interpreter/src/valid.rs Outdated Show resolved Hide resolved
crates/interpreter/src/valid.rs Outdated Show resolved Hide resolved
crates/interpreter/src/valid.rs Outdated Show resolved Hide resolved
crates/interpreter/src/valid.rs Outdated Show resolved Hide resolved
crates/interpreter/src/valid.rs Outdated Show resolved Hide resolved
crates/interpreter/src/valid.rs Outdated Show resolved Hide resolved
crates/interpreter/src/valid.rs Outdated Show resolved Hide resolved
crates/interpreter/src/valid.rs Outdated Show resolved Hide resolved
@zhouwfang zhouwfang requested a review from ia0 October 25, 2024 02:46
Copy link
Member

@ia0 ia0 left a comment

Choose a reason for hiding this comment

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

I tried to look into the tests and actually there are fundamental problems:

  • Since I added auto-skipping of unsupported behaviors, we may accidentally pass the test because everything is unsupported due to a bug. I need to fix the tests so that we can distinguish between really unsupported and unsupported by accident. Not completely sure yet how, probably just a counter of skipped tests due to unsupported, but I'd like to find something better.
  • We need to be very careful when we call branch_{source,target}() because it will save the stack. This matters particularly when we push a label, because we don't want to save the parameters of the label.

Sadly I don't have time at the moment to dig into this. I think the design is not there yet (for example, maybe we actually want to store the "val_cnt/result" in the target branch instead. Maybe it will help with capturing too much of the stack because we know val_cnt is included.

If you want to continue working on this until I get time to look into again, you can try to experiment on your own and run the test suite to test the invariants you come up with. The more asserts you can write that don't fail in the test suite, the better your understanding of the code will be.

crates/interpreter/src/valid.rs Outdated Show resolved Hide resolved
crates/interpreter/src/valid.rs Show resolved Hide resolved
@zhouwfang zhouwfang force-pushed the add-val-and-pop-cnt branch from 5c1c205 to cc29418 Compare October 28, 2024 03:58
@zhouwfang
Copy link
Member Author

With the commit cc29418 and #658, all the tests pass now.

In the meanwhile, I'm printing the side tables for some test cases in the test suite as a sanity check.

@zhouwfang zhouwfang requested a review from ia0 October 28, 2024 04:15
Copy link
Member

@ia0 ia0 left a comment

Choose a reason for hiding this comment

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

I don't mind merging this without thorough review such that you can start using the side table in exec.rs which is the important part to be able to debug. I think this PR needs a redesign and it's hard to tell unless the side table is actually used during execution. I'll do a proper review once we have everything working end-to-end.

But you can also use the side table in exec.rs in this PR if you want. As you prefer.

crates/interpreter/src/valid.rs Outdated Show resolved Hide resolved
crates/interpreter/src/valid.rs Outdated Show resolved Hide resolved
crates/interpreter/src/valid.rs Outdated Show resolved Hide resolved
crates/interpreter/src/valid.rs Outdated Show resolved Hide resolved
@zhouwfang
Copy link
Member Author

Thanks for the review. I plan to use val_cnt and pop_cnt in exec.rs in this PR.

@zhouwfang
Copy link
Member Author

@ia0 Could you merge main to dev/fast-interp again? Thanks.

@zhouwfang
Copy link
Member Author

zhouwfang commented Nov 17, 2024

Note: the side tables are now correct for the examples we discussed.

@@ -560,7 +585,8 @@ impl<'a, 'm> Expr<'a, 'm> {
Nop => (),
Block(b) => self.push_label(self.blocktype(&b)?, LabelKind::Block)?,
Loop(b) => {
self.push_label(self.blocktype(&b)?, LabelKind::Loop(self.branch_target()))?
let type_ = self.blocktype(&b)?;
self.push_label(type_, LabelKind::Loop(self.branch_target(type_.results.len())))?
Copy link
Member Author

Choose a reason for hiding this comment

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

For loop, I'm not sure whether I should use type_.results.len() (as in other cases) or type_.params.len() for val_cnt. But I suspect the latter is correct for the following reason: in exec.rs, the last arity values are kept which should be the same as val_cnt. By the definition of arity in exec.rs, the latter is used.

Copy link
Member

Choose a reason for hiding this comment

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

Exactly, it's params.

Copy link
Member Author

Choose a reason for hiding this comment

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

Let me know if my understanding about the reason why it is different for loop is correct: For loop, we jump to the beginning instead of the end. When we jump to the beginning, we need to look at the params. The result of the loop will be handled by the outer scope of 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.

Yes

@zhouwfang
Copy link
Member Author

zhouwfang commented Nov 18, 2024

After thinking more, it may be better to merge this PR first because using val_cnt and pop_cnt in exec.rs requires using delta_ip and delta_stp as a first step (need to be located at the right side table entry first). I'd like to have a separate PR for using delta_ip and delta_stp in exec.rs. WDYT?

Copy link
Member

@ia0 ia0 left a comment

Choose a reason for hiding this comment

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

Sounds good, let's merge this.

@@ -560,7 +585,8 @@ impl<'a, 'm> Expr<'a, 'm> {
Nop => (),
Block(b) => self.push_label(self.blocktype(&b)?, LabelKind::Block)?,
Loop(b) => {
self.push_label(self.blocktype(&b)?, LabelKind::Loop(self.branch_target()))?
let type_ = self.blocktype(&b)?;
self.push_label(type_, LabelKind::Loop(self.branch_target(type_.results.len())))?
Copy link
Member

Choose a reason for hiding this comment

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

Exactly, it's params.

@ia0 ia0 merged commit 24781ed into google:dev/fast-interp Nov 18, 2024
20 checks passed
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