-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Fix hashing for windows paths containing a CurDir component #93697
Conversation
* the logic only checked for / but not for \ * verbatim paths shouldn't skip items at all since they don't get normalized * the extra branches get optimized out on unix since is_sep_byte is a trivial comparison and is_verbatim is always-false * tests lacked windows coverage for these cases That lead to equal paths not having equal hashes and to unnecessary collisions.
(rust-highfive has picked a reviewer for you, use r? to override) |
Lacking a windows machine (and too lazy to setup a VM) I haven't actually run the tests on windows. |
Equal paths not having equal hashes means that things like HashMap etc may be just broken today, right? Is this a recently introduced bug we should be backporting a fix for (IIRC, I may have approved a PR in this area somewhat recently). |
@bors r+ rollup=iffy In the meantime, this seems good to me. |
📌 Commit 45082b0 has been approved by |
Yes.
#90596 (1.58). |
I'm going to beta nominate then for backport to 1.59, since it seems plausible that folks could hit it in the wild. It might be worth considering running a fuzzer or similar against the old and new impls, maybe that could help uncover any other hidden bugs...? |
I'll take a stab at that, would be my first time using one and this looks like a good first test case. |
Just to be explicit, identical paths will hash fine. It's only some not-identical-but-equal paths, on windows, that would hash incorrectly. Which means one would have to put something under one such path into a hashmap and then construct a different path as lookup key. And one can't use |
@bors p=1 -- beta-backport accepted |
⌛ Testing commit 45082b0 with merge 84f41fa6091a72dd04fda915e16a37a4dc56cf60... |
This comment has been minimized.
This comment has been minimized.
💔 Test failed - checks-actions |
The failing test rust/src/test/ui/issues/issue-23036.rs Lines 1 to 10 in 6499c5e
Running it locally with the
An LLVM bug? |
Maybe. Could be a NodeJS/V8 parsing bug too. Not really sure what the best way to investigate is -- probably cross-compiling to wasm32 locally or otherwise getting that bytecode to try and run it against a newer NodeJS or perhaps load it up in a disassembler of some kind? It may be worth simplifying the test too, we probably just need to hash a path... |
My system nodejs is 17.3, that's fairly recent.
Replacing the test with the following makes it pass. let mut hasher = RandomState::new().build_hasher();
Path::new("a").hash(&mut hasher);
dbg!(hasher.finish()); |
Rebuilt LLVM with asserts enabled, now I get the same error as CI
|
Hm -- I wonder if we can figure out a small delta on the input code to land this PR and then follow up on the LLVM bug separately? At minimum, a minimal LLVM IR example would be good to poke LLVM folks with. |
The LLVM IR from the failing UI test: repro.ir.txt
|
Hm. Well, maybe let's file a rust-lang/rust bug with that and ping the LLVM group -- I would like to see this PR land ideally, but it sounds like that might be tough to have happen in a shortish time frame. I don't really have much expertise myself at digging in LLVM. |
If we want a fix for beta then another option is to revert #90596, file a LLVM bug and then try to reland the version from this PR when it is fixed. |
Yeah, that's probably the right approach. Let's go ahead and revert #90596 on master to avoid needing to remember beta backports as well, and then we can backport that. Once the LLVM bug is fixed we can re-land the work (in combination with this PR). |
A complete revert of #90596 also triggers this assert. I suspect this bug has been around for a while and is highly responsive to perturbations. My observations so far
We can conclude that the universe does not allow wasm and windows to exist simultaneously. Would it be ok to disable the test on wasm? It seems somewhat questionable since miscompilations of Path would be fairly serious. On the other hand the bug seems fragile in the first place. E.g. changing the test from map.insert(Path::new("a"), 0);
map.get(Path::new("a")); to map.insert(Path::new("a"), 0);
map[Path::new("a")]; or map.insert(Path::new("aa/./b"), 0);
map.get(Path::new("aa/b")); makes it pass. |
I think we should disable the test - wasm is not a tier 1 platform, windows is more important in that sense. |
A fix applied to std::Path::hash triggers a miscompilation/assert in LLVM in this test on wasm32. The miscompilation appears to pre-existing. Reverting some previous changes done std::Path also trigger it and slight modifications such as changing the test path from "a" to "ccccccccccc" also make it pass, indicating it's very flaky. Since the fix is for a higher-tier platform than wasm it takes precedence.
Disabled the test. Since the issue appears to be preexisting and just trigger unreliable it shouldn't affect the beta nomination but you might want to reevaluate that anyway. |
I think the beta backport likely still makes sense, I suspect this assert is not really related to this PR (or even the previous one), just triggering some latent state inside LLVM. @bors r+ |
📌 Commit 1d21ce7 has been approved by |
☀️ Test successful - checks-actions |
Finished benchmarking commit (9c3a3e3): comparison url. Summary: This benchmark run did not return any relevant results. If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. @rustbot label: -perf-regression |
…ulacrum [beta] backports This backports: * Complete removal of #[main] attribute from compiler rust-lang#93753 * Resolve lifetimes for const generic defaults rust-lang#93669 * backport llvm fix for issue 91671. rust-lang#93426 * Fix invalid special casing of the unreachable! macro rust-lang#93179 * Fix hashing for windows paths containing a CurDir component rust-lang#93697 r? `@Mark-Simulacrum`
That lead to equal paths not having equal hashes and to unnecessary collisions.