diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2022-11-05 16:54:45 +0400 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2022-11-05 17:55:20 +0400 |
| commit | 43bea6cf69501dee3d71e4440d947182a67137a0 (patch) | |
| tree | 482cf0de03411f65220f4e522cb39cc0f9d54fe1 /compiler/rustc_middle/src | |
| parent | 448261a78a35026b3f5e855b705f35c916ecb19b (diff) | |
resolve: Fill effective visibilities for import def ids in a separate pass
This should result in less update calls than doing it repeatedly during the fix point iteration.
Diffstat (limited to 'compiler/rustc_middle/src')
| -rw-r--r-- | compiler/rustc_middle/src/middle/privacy.rs | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/compiler/rustc_middle/src/middle/privacy.rs b/compiler/rustc_middle/src/middle/privacy.rs index 11fbefefcc9..3a91522d362 100644 --- a/compiler/rustc_middle/src/middle/privacy.rs +++ b/compiler/rustc_middle/src/middle/privacy.rs @@ -113,8 +113,30 @@ impl EffectiveVisibilities { }) } - pub fn iter(&self) -> impl Iterator<Item = (&LocalDefId, &EffectiveVisibility)> { - self.map.iter() + // FIXME: Share code with `fn update`. + pub fn update_eff_vis( + &mut self, + def_id: LocalDefId, + eff_vis: &EffectiveVisibility, + tree: impl DefIdTree, + ) { + use std::collections::hash_map::Entry; + match self.map.entry(def_id) { + Entry::Occupied(mut occupied) => { + let old_eff_vis = occupied.get_mut(); + for l in Level::all_levels() { + let vis_at_level = eff_vis.at_level(l); + let old_vis_at_level = old_eff_vis.at_level_mut(l); + if vis_at_level != old_vis_at_level + && vis_at_level.is_at_least(*old_vis_at_level, tree) + { + *old_vis_at_level = *vis_at_level + } + } + old_eff_vis + } + Entry::Vacant(vacant) => vacant.insert(*eff_vis), + }; } pub fn set_public_at_level( @@ -185,6 +207,10 @@ impl EffectiveVisibilities { } impl<Id: Eq + Hash> EffectiveVisibilities<Id> { + pub fn iter(&self) -> impl Iterator<Item = (&Id, &EffectiveVisibility)> { + self.map.iter() + } + pub fn effective_vis(&self, id: Id) -> Option<&EffectiveVisibility> { self.map.get(&id) } |
