Skip to content

Commit 6f96797

Browse files
authored
Return paths in PackageSourceMap deterministically (#2357)
in v1.220.0, specifically 28ea1a0, package source pathing was switched over to a helper utility. the `PackageSourceMap::paths` method looks very similar to the logic before, but has a very subtle difference: in order to avoid duplicate paths, it collects paths from each source map's source files into a `HashSet` and then returns an iterator over than (in contrast to before, which just presented a flat-mapped iterator over all source files directly). unfortunately, this means that iteration order is now random, which can produce non-deterministic compilation when wit-parser is used as part of the compilation macro, say for proc-macros like wasmtime-component macro. it's... difficult to notice this in ordinary cargo compilation, but it causes _extremely_ strange behavior in deterministic/caching build tooling like buck2: given a series of deps `outer -> inner -> [something that uses wasmtime-component-macro, like wasmtime-wasi]`, compiling `outer` will cause rustc to reject `wasmtime-wasi` on a hash mismatch, which will then surface as "unable to find crate "inner"` [^1] fixing this is relatively easy: since our input iteration order is deterministic, simply collecting into an `IndexMap` (already used elsewhere in the file for this purpose) instead of a `HashMap` gives us deterministic iteration order, and thus deterministic compilation. [^1]: i know this happens when compiling `outer` as a static-pic for library; i have not yet tested if it occurs in other compilation modes like binaries or shared libs.
1 parent b0d70e0 commit 6f96797

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

crates/wit-parser/src/resolve.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ impl PackageSourceMap {
168168
.iter()
169169
.flatten()
170170
.map(|path_buf| path_buf.as_ref())
171-
.collect::<HashSet<&Path>>()
171+
.collect::<IndexSet<&Path>>()
172172
.into_iter()
173173
}
174174

0 commit comments

Comments
 (0)