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

Merge side table into WASM module #730

Open
wants to merge 7 commits into
base: dev/fast-interp
Choose a base branch
from

Conversation

zhouwfang
Copy link
Member

@zhouwfang zhouwfang commented Feb 10, 2025

I'll debug in the meanwhile.

#46

@zhouwfang zhouwfang requested a review from ia0 as a code owner February 10, 2025 07:01
@zhouwfang zhouwfang changed the title Add merge() Merge side table into WASM module Feb 10, 2025
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.

Just did a quick review. I think we can also change next_branch_table to return Self::BranchTable<'a, 'm> instead of &'a mut Self::BranchTable<'m>. This will permit removing the branch_table_view field of SideTableView. Also I think we can split this PR:

  • One for the change above.
  • One for using [u8] instead of [u16].
  • One for serializing/deserializing the side-table.
  • One for adding and using merge.

The first 2 can be done in parallel.

@@ -26,6 +26,23 @@ use crate::toctou::*;
use crate::util::*;
use crate::*;

pub fn merge(binary: &[u8], side_table: Vec<MetadataEntry>) -> Vec<u8> {
Copy link
Member

Choose a reason for hiding this comment

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

We can take a slice: &[MetadataEntry].

let mut wasm = vec![];
wasm.extend_from_slice(&binary[0 .. 8]);
wasm.push(0);
wasm.extend_from_slice(&side_table.len().to_le_bytes());
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 needs to be leb128 since that's part of wasm spec.

wasm.push(0);
wasm.extend_from_slice(&side_table.len().to_le_bytes());
for entry in side_table {
wasm.extend_from_slice(&entry.type_idx.to_le_bytes());
Copy link
Member

Choose a reason for hiding this comment

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

We need to convert the usize to u16 first.

for entry in side_table {
wasm.extend_from_slice(&entry.type_idx.to_le_bytes());
wasm.extend_from_slice(&entry.parser_range.start.to_le_bytes());
wasm.extend_from_slice(&entry.parser_range.end.to_le_bytes());
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, usize has not a fixed size, and we expect a u32.

wasm.extend_from_slice(&binary[0 .. 8]);
wasm.push(0);
wasm.extend_from_slice(&side_table.len().to_le_bytes());
for entry in side_table {
Copy link
Member

Choose a reason for hiding this comment

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

We also need to serialize the indices. Below is just the metadata.

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