Rollup merge of #119592 - petrochenkov:unload, r=compiler-errors
resolve: Unload speculatively resolved crates before freezing cstore Name resolution sometimes loads additional crates to improve diagnostics (e.g. suggest imports). Not all of these diagnostics result in errors, sometimes they are just warnings, like in #117772. If additional crates loaded speculatively stay and gets listed by things like `query crates` then they may produce further errors like duplicated lang items, because lang items from speculatively loaded crates are as good as from non-speculatively loaded crates. They can probably do things like adding unintended impls from speculatively loaded crates to method resolution as well. The extra crates will also get into the crate's metadata as legitimate dependencies. In this PR I remove the speculative crates from cstore when name resolution is finished and cstore is frozen. This is better than e.g. filtering away speculative crates in `query crates` because things like `DefId`s referring to these crates and leaking to later compilation stages can produce ICEs much easier, allowing to detect them. The unloading could potentially be skipped if any errors were reported (to allow using `DefId`s from speculatively loaded crates for recovery), but I didn't do it in this PR because I haven't seen such cases of recovery. We can reconsider later if any relevant ICEs are reported. Unblocks https://github.com/rust-lang/rust/pull/117772.
This commit is contained in:
commit
4e11d03d0e
6 changed files with 52 additions and 16 deletions
|
@ -1629,6 +1629,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
self.tcx
|
||||
.sess
|
||||
.time("resolve_postprocess", || self.crate_loader(|c| c.postprocess(krate)));
|
||||
self.crate_loader(|c| c.unload_unused_crates());
|
||||
});
|
||||
|
||||
// Make sure we don't mutate the cstore from here on.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue