Skip to content

Add val_cnt and pop_cnt in side table#2

Closed
zhouwfang wants to merge 7 commits into
add-delta-ipfrom
add-val-and-pop-cnt
Closed

Add val_cnt and pop_cnt in side table#2
zhouwfang wants to merge 7 commits into
add-delta-ipfrom
add-val-and-pop-cnt

Conversation

@zhouwfang

@zhouwfang zhouwfang commented Oct 20, 2024

Copy link
Copy Markdown
Owner

I follow

fn push_label(&mut self, type_: FuncType<'m>, kind: LabelKind<'m>) {
let arity = match kind {
LabelKind::Block | LabelKind::If => type_.results.len(),
LabelKind::Loop(_) => type_.params.len(),
};
let label = Label { arity, kind, values_cnt: type_.params.len() };
self.label().values_cnt -= label.values_cnt;
self.labels().push(label);
}

google#46

@zhouwfang zhouwfang changed the title Add val_cnt and pop_cnt Add val_cnt and pop_cnt in side table Oct 20, 2024

@ia0 ia0 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks! I think the main changes would be:

  • self.stitch() needs to take val_cnt
  • self.branch() doesn't take any argument and compute stack from the total number of values in the labels.

Comment thread crates/interpreter/src/valid.rs Outdated
struct SideTableBranch<'m> {
parser: &'m [u8],
side_table: usize,
val_cnt: u32,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I don't think we need this.

Comment thread crates/interpreter/src/valid.rs Outdated
parser: &'m [u8],
side_table: usize,
val_cnt: u32,
pop_cnt: u32,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This should probably be something like

Suggested change
pop_cnt: u32,
stack: usize,

And be initialized by stack.len() (like side_table is initialized with side_table.len()).

We probably need a function to compute the stack length (going through all labels). We don't need to compute across functions because we can only jump within a function. We could try to memoize the sum of previous label in each label.

@zhouwfang zhouwfang Oct 22, 2024

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Is the stack similar to the Label::values_cnt in exec.rs?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Yes, that's the value stack. There's one difference though, is that in exec.rs it's the value stack of the thread (i.e. function and label stack). Here we only need the value stack of the function (i.e. label stack).

Comment thread crates/interpreter/src/valid.rs Outdated
@@ -793,45 +805,52 @@ impl<'a, 'm> Expr<'a, 'm> {
}

fn stitch(&mut self, source: SideTableBranch, target: SideTableBranch) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

We probably need to take val_cnt as argument.

Comment thread crates/interpreter/src/valid.rs Outdated
val_cnt: 0,
pop_cnt: 0,
val_cnt,
pop_cnt,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think this should just be (source.stack - target.stack) as u32 or something like that. We should actually check that the subtraction and the cast are not overflowing, and return Unsupported otherwise.

We should probably also remove val_cnt from source.stack (again checking for overflow).

@zhouwfang
zhouwfang force-pushed the add-val-and-pop-cnt branch from d9d837a to a9318f6 Compare October 22, 2024 04:46
@zhouwfang
zhouwfang force-pushed the add-val-and-pop-cnt branch from a9318f6 to 39dfe61 Compare October 23, 2024 05:07
@zhouwfang zhouwfang closed this Oct 23, 2024
@zhouwfang zhouwfang reopened this Oct 23, 2024
@zhouwfang
zhouwfang force-pushed the add-val-and-pop-cnt branch from 39dfe61 to 6890972 Compare October 23, 2024 05:28
@zhouwfang zhouwfang closed this Oct 23, 2024
ia0 added a commit to google/wasefire that referenced this pull request Nov 18, 2024
There was an earlier review in
zhouwfang#2.

#46

---------

Co-authored-by: Julien Cretin <[email protected]>
Co-authored-by: Zhou Fang <[email protected]>
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