diff options
| author | Camille GILLOT <gillot.camille@gmail.com> | 2022-09-29 21:07:06 +0200 |
|---|---|---|
| committer | Camille GILLOT <gillot.camille@gmail.com> | 2022-10-01 16:22:40 +0200 |
| commit | d08669c4fa51a864a46438c2e4bc9047931e1033 (patch) | |
| tree | a815b3ba8cecfefb3032b4d3624c6c414ade1b0b /compiler/rustc_middle | |
| parent | 26e5fe9e8507f7dcb50c21e785515a7841e8cf55 (diff) | |
| download | rust-d08669c4fa51a864a46438c2e4bc9047931e1033.tar.gz rust-d08669c4fa51a864a46438c2e4bc9047931e1033.zip | |
Compute by owner instead of HirId.
Diffstat (limited to 'compiler/rustc_middle')
| -rw-r--r-- | compiler/rustc_middle/src/lint.rs | 25 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/query/mod.rs | 5 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/query.rs | 2 |
3 files changed, 23 insertions, 9 deletions
diff --git a/compiler/rustc_middle/src/lint.rs b/compiler/rustc_middle/src/lint.rs index aa02fc00eab..d65fa30450c 100644 --- a/compiler/rustc_middle/src/lint.rs +++ b/compiler/rustc_middle/src/lint.rs @@ -1,8 +1,9 @@ use std::cmp; use rustc_data_structures::fx::FxHashMap; +use rustc_data_structures::vec_map::VecMap; use rustc_errors::{Diagnostic, DiagnosticBuilder, DiagnosticId, DiagnosticMessage, MultiSpan}; -use rustc_hir::HirId; +use rustc_hir::{HirId, ItemLocalId}; use rustc_session::lint::{ builtin::{self, FORBIDDEN_LINT_GROUPS}, FutureIncompatibilityReason, Level, Lint, LintId, @@ -62,7 +63,7 @@ pub type LevelAndSource = (Level, LintLevelSource); /// by the attributes for *a single HirId*. #[derive(Default, Debug, HashStable)] pub struct ShallowLintLevelMap { - pub specs: FxHashMap<LintId, LevelAndSource>, + pub specs: VecMap<ItemLocalId, FxHashMap<LintId, LevelAndSource>>, } /// From an initial level and source, verify the effect of special annotations: @@ -116,19 +117,30 @@ impl ShallowLintLevelMap { /// Perform a deep probe in the HIR tree looking for the actual level for the lint. /// This lint level is not usable for diagnostics, it needs to be corrected by /// `reveal_actual_level` beforehand. + #[instrument(level = "trace", skip(self, tcx), ret)] fn probe_for_lint_level( &self, tcx: TyCtxt<'_>, id: LintId, start: HirId, ) -> (Option<Level>, LintLevelSource) { - if let Some(&(level, src)) = self.specs.get(&id) { + if let Some(map) = self.specs.get(&start.local_id) + && let Some(&(level, src)) = map.get(&id) + { return (Some(level), src); } + let mut owner = start.owner; + let mut specs = &self.specs; + for parent in tcx.hir().parent_id_iter(start) { - let specs = tcx.shallow_lint_levels_on(parent); - if let Some(&(level, src)) = specs.specs.get(&id) { + if parent.owner != owner { + owner = parent.owner; + specs = &tcx.shallow_lint_levels_on(owner).specs; + } + if let Some(map) = specs.get(&parent.local_id) + && let Some(&(level, src)) = map.get(&id) + { return (Some(level), src); } } @@ -137,6 +149,7 @@ impl ShallowLintLevelMap { } /// Fetch and return the user-visible lint level for the given lint at the given HirId. + #[instrument(level = "trace", skip(self, tcx), ret)] pub fn lint_level_id_at_node( &self, tcx: TyCtxt<'_>, @@ -154,7 +167,7 @@ impl ShallowLintLevelMap { impl TyCtxt<'_> { /// Fetch and return the user-visible lint level for the given lint at the given HirId. pub fn lint_level_at_node(self, lint: &'static Lint, id: HirId) -> (Level, LintLevelSource) { - self.shallow_lint_levels_on(id).lint_level_id_at_node(self, LintId::of(lint), id) + self.shallow_lint_levels_on(id.owner).lint_level_id_at_node(self, LintId::of(lint), id) } /// Walks upwards from `id` to find a node which might change lint levels with attributes. diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index 11f88d95ef6..cf5b365b27c 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -274,9 +274,10 @@ rustc_queries! { separate_provide_extern } - query shallow_lint_levels_on(key: HirId) -> rustc_middle::lint::ShallowLintLevelMap { + query shallow_lint_levels_on(key: hir::OwnerId) -> rustc_middle::lint::ShallowLintLevelMap { + eval_always // fetches `resolutions` arena_cache - desc { |tcx| "looking up lint levels for `{}`", key } + desc { |tcx| "looking up lint levels for `{}`", tcx.def_path_str(key.to_def_id()) } } query lint_expectations(_: ()) -> Vec<(LintExpectationId, LintExpectation)> { diff --git a/compiler/rustc_middle/src/ty/query.rs b/compiler/rustc_middle/src/ty/query.rs index b4a907d697b..b6cda34c51f 100644 --- a/compiler/rustc_middle/src/ty/query.rs +++ b/compiler/rustc_middle/src/ty/query.rs @@ -44,7 +44,7 @@ use rustc_errors::ErrorGuaranteed; use rustc_hir as hir; use rustc_hir::def::DefKind; use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, DefIdSet, LocalDefId}; -use rustc_hir::hir_id::{HirId, OwnerId}; +use rustc_hir::hir_id::OwnerId; use rustc_hir::lang_items::{LangItem, LanguageItems}; use rustc_hir::{Crate, ItemLocalId, TraitCandidate}; use rustc_index::{bit_set::FiniteBitSet, vec::IndexVec}; |
