Commit 6f96797
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
1 file changed
+1
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
168 | 168 | | |
169 | 169 | | |
170 | 170 | | |
171 | | - | |
| 171 | + | |
172 | 172 | | |
173 | 173 | | |
174 | 174 | | |
| |||
0 commit comments