Move -Z maximal-hir-to-mir-coverage implementation to new maybe_new_source_scope
method
This commit is contained in:
parent
3bf7d88ef1
commit
d595884302
3 changed files with 44 additions and 42 deletions
|
@ -173,16 +173,6 @@ impl TyCtxt<'_> {
|
||||||
/// Walks upwards from `id` to find a node which might change lint levels with attributes.
|
/// Walks upwards from `id` to find a node which might change lint levels with attributes.
|
||||||
/// It stops at `bound` and just returns it if reached.
|
/// It stops at `bound` and just returns it if reached.
|
||||||
pub fn maybe_lint_level_root_bounded(self, mut id: HirId, bound: HirId) -> HirId {
|
pub fn maybe_lint_level_root_bounded(self, mut id: HirId, bound: HirId) -> HirId {
|
||||||
// Some consumers of rustc need to map MIR locations back to HIR nodes. Currently the
|
|
||||||
// the only part of rustc that tracks MIR -> HIR is the `SourceScopeLocalData::lint_root`
|
|
||||||
// field that tracks lint levels for MIR locations. Normally the number of source scopes
|
|
||||||
// is limited to the set of nodes with lint annotations. The -Zmaximal-hir-to-mir-coverage
|
|
||||||
// flag changes this behavior to maximize the number of source scopes, increasing the
|
|
||||||
// granularity of the MIR->HIR mapping.
|
|
||||||
if self.sess.opts.unstable_opts.maximal_hir_to_mir_coverage {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
let hir = self.hir();
|
let hir = self.hir();
|
||||||
loop {
|
loop {
|
||||||
if id == bound {
|
if id == bound {
|
||||||
|
|
|
@ -948,20 +948,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||||
original_source_scope: SourceScope,
|
original_source_scope: SourceScope,
|
||||||
pattern_span: Span,
|
pattern_span: Span,
|
||||||
) {
|
) {
|
||||||
let tcx = self.tcx;
|
let parent_id = self.source_scopes[original_source_scope]
|
||||||
let current_root = tcx.maybe_lint_level_root_bounded(arg_hir_id, self.hir_id);
|
.local_data
|
||||||
let parent_root = tcx.maybe_lint_level_root_bounded(
|
.as_ref()
|
||||||
self.source_scopes[original_source_scope]
|
.assert_crate_local()
|
||||||
.local_data
|
.lint_root;
|
||||||
.as_ref()
|
self.maybe_new_source_scope(pattern_span, None, arg_hir_id, parent_id);
|
||||||
.assert_crate_local()
|
|
||||||
.lint_root,
|
|
||||||
self.hir_id,
|
|
||||||
);
|
|
||||||
if current_root != parent_root {
|
|
||||||
self.source_scope =
|
|
||||||
self.new_source_scope(pattern_span, LintLevel::Explicit(current_root), None);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_unit_temp(&mut self) -> Place<'tcx> {
|
fn get_unit_temp(&mut self) -> Place<'tcx> {
|
||||||
|
|
|
@ -85,6 +85,7 @@ use std::mem;
|
||||||
|
|
||||||
use crate::build::{BlockAnd, BlockAndExtension, BlockFrame, Builder, CFG};
|
use crate::build::{BlockAnd, BlockAndExtension, BlockFrame, Builder, CFG};
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
|
use rustc_hir::HirId;
|
||||||
use rustc_index::vec::IndexVec;
|
use rustc_index::vec::IndexVec;
|
||||||
use rustc_middle::middle::region;
|
use rustc_middle::middle::region;
|
||||||
use rustc_middle::mir::*;
|
use rustc_middle::mir::*;
|
||||||
|
@ -567,25 +568,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||||
F: FnOnce(&mut Builder<'a, 'tcx>) -> BlockAnd<R>,
|
F: FnOnce(&mut Builder<'a, 'tcx>) -> BlockAnd<R>,
|
||||||
{
|
{
|
||||||
let source_scope = self.source_scope;
|
let source_scope = self.source_scope;
|
||||||
let tcx = self.tcx;
|
|
||||||
if let LintLevel::Explicit(current_hir_id) = lint_level {
|
if let LintLevel::Explicit(current_hir_id) = lint_level {
|
||||||
// Use `maybe_lint_level_root_bounded` with `root_lint_level` as a bound
|
let parent_id =
|
||||||
// to avoid adding Hir dependencies on our parents.
|
self.source_scopes[source_scope].local_data.as_ref().assert_crate_local().lint_root;
|
||||||
// We estimate the true lint roots here to avoid creating a lot of source scopes.
|
self.maybe_new_source_scope(region_scope.1.span, None, current_hir_id, parent_id);
|
||||||
|
|
||||||
let parent_root = tcx.maybe_lint_level_root_bounded(
|
|
||||||
self.source_scopes[source_scope].local_data.as_ref().assert_crate_local().lint_root,
|
|
||||||
self.hir_id,
|
|
||||||
);
|
|
||||||
let current_root = tcx.maybe_lint_level_root_bounded(current_hir_id, self.hir_id);
|
|
||||||
|
|
||||||
if parent_root != current_root {
|
|
||||||
self.source_scope = self.new_source_scope(
|
|
||||||
region_scope.1.span,
|
|
||||||
LintLevel::Explicit(current_root),
|
|
||||||
None,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
self.push_scope(region_scope);
|
self.push_scope(region_scope);
|
||||||
let mut block;
|
let mut block;
|
||||||
|
@ -758,6 +744,40 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Possibly creates a new source scope if `current_root` and `parent_root`
|
||||||
|
/// are different, or if -Zmaximal-hir-to-mir-coverage is enabled.
|
||||||
|
pub(crate) fn maybe_new_source_scope(
|
||||||
|
&mut self,
|
||||||
|
span: Span,
|
||||||
|
safety: Option<Safety>,
|
||||||
|
current_id: HirId,
|
||||||
|
parent_id: HirId,
|
||||||
|
) {
|
||||||
|
let (current_root, parent_root) =
|
||||||
|
if self.tcx.sess.opts.unstable_opts.maximal_hir_to_mir_coverage {
|
||||||
|
// Some consumers of rustc need to map MIR locations back to HIR nodes. Currently the
|
||||||
|
// the only part of rustc that tracks MIR -> HIR is the `SourceScopeLocalData::lint_root`
|
||||||
|
// field that tracks lint levels for MIR locations. Normally the number of source scopes
|
||||||
|
// is limited to the set of nodes with lint annotations. The -Zmaximal-hir-to-mir-coverage
|
||||||
|
// flag changes this behavior to maximize the number of source scopes, increasing the
|
||||||
|
// granularity of the MIR->HIR mapping.
|
||||||
|
(current_id, parent_id)
|
||||||
|
} else {
|
||||||
|
// Use `maybe_lint_level_root_bounded` with `self.hir_id` as a bound
|
||||||
|
// to avoid adding Hir dependencies on our parents.
|
||||||
|
// We estimate the true lint roots here to avoid creating a lot of source scopes.
|
||||||
|
(
|
||||||
|
self.tcx.maybe_lint_level_root_bounded(current_id, self.hir_id),
|
||||||
|
self.tcx.maybe_lint_level_root_bounded(parent_id, self.hir_id),
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
if current_root != parent_root {
|
||||||
|
let lint_level = LintLevel::Explicit(current_root);
|
||||||
|
self.source_scope = self.new_source_scope(span, lint_level, safety);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Creates a new source scope, nested in the current one.
|
/// Creates a new source scope, nested in the current one.
|
||||||
pub(crate) fn new_source_scope(
|
pub(crate) fn new_source_scope(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue