Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion crates/vm/src/stdlib/_collections/ordered_dict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub(crate) mod ordered_dict {
last: Option<usize>,
nodes: Vec<Option<ODictNode>>,
free: Vec<usize>,
by_hash: HashMap<PyHash, Vec<usize>>,
by_hash: Box<HashMap<PyHash, Vec<usize>>>,
Comment thread
jiwahn marked this conversation as resolved.

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.

what's happening in wasi? since both Box and HashMap are indirection, this will cause double indirection, which is not very preferred. I'd like to understand how and why this broken in wasi

@jiwahn jiwahn Sep 29, 2026 •

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.

In wasi, Py<T> has 28 bytes header size and when the T is OrderedDict, the payload requires 8 byte alignment (but the base PyDict has 4 byte align). So accessing an OrderedDict through its PyDict base results to using the wrong payload addrress

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, we have to adjust alignment rather than adding a Box.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Opened #8905 as a follow-up to #7663 and the layout analysis here. It adds compile-time checks for native subclass payload offsets and object alignment, and aligns PyDict and _IOBase to eight bytes so the affected hierarchies satisfy them without adding a Box.

The original #7663 inherited-getter regression is included. The OrderedDict.get() reproducer passes on wasm32-wasip1 under Wasmtime.

AI assistance: Codex (GPT-6).

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.

It seems that #8905 fixes this so imma close this one

state: usize,
}

Expand Down Expand Up @@ -573,6 +573,7 @@ pub(crate) mod ordered_dict {
fn __sizeof__(&self) -> usize {
self.dict.__sizeof__()
+ core::mem::size_of::<ODictLinks>()
+ core::mem::size_of::<HashMap<PyHash, Vec<usize>>>()
+ self.links.lock().nodes.capacity() * core::mem::size_of::<Option<ODictNode>>()
}

Expand Down
Loading