Skip to content

Commit 5c70dcd

Browse files
authored
Unrolled build for rust-lang#139047
Rollup merge of rust-lang#139047 - m-ou-se:remove-scope-depth, r=oli-obk Remove ScopeDepth The scope depth was tracked, but never seemed to be used for anything. Every single place that used `(Scope, ScopeDepth)`, matched it on `(p, _)`.
2 parents 2a06022 + deeac1c commit 5c70dcd

File tree

3 files changed

+18
-31
lines changed

3 files changed

+18
-31
lines changed

compiler/rustc_hir_analysis/src/check/region.rs

+14-25
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,11 @@ use tracing::debug;
2323

2424
#[derive(Debug, Copy, Clone)]
2525
struct Context {
26-
/// The scope that contains any new variables declared, plus its depth in
27-
/// the scope tree.
26+
/// The scope that contains any new variables declared.
2827
var_parent: Option<Scope>,
2928

30-
/// Region parent of expressions, etc., plus its depth in the scope tree.
31-
parent: Option<(Scope, ScopeDepth)>,
32-
}
33-
34-
impl Context {
35-
fn set_var_parent(&mut self) {
36-
self.var_parent = self.parent.map(|(p, _)| p);
37-
}
29+
/// Region parent of expressions, etc.
30+
parent: Option<Scope>,
3831
}
3932

4033
struct ScopeResolutionVisitor<'tcx> {
@@ -119,7 +112,7 @@ fn resolve_block<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, blk: &'tcx hi
119112
// itself has returned.
120113

121114
visitor.enter_node_scope_with_dtor(blk.hir_id.local_id);
122-
visitor.cx.set_var_parent();
115+
visitor.cx.var_parent = visitor.cx.parent;
123116

124117
{
125118
// This block should be kept approximately in sync with
@@ -138,7 +131,7 @@ fn resolve_block<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, blk: &'tcx hi
138131
local_id: blk.hir_id.local_id,
139132
data: ScopeData::Remainder(FirstStatementIndex::new(i)),
140133
});
141-
visitor.cx.set_var_parent();
134+
visitor.cx.var_parent = visitor.cx.parent;
142135
visitor.visit_stmt(statement);
143136
// We need to back out temporarily to the last enclosing scope
144137
// for the `else` block, so that even the temporaries receiving
@@ -163,7 +156,7 @@ fn resolve_block<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, blk: &'tcx hi
163156
local_id: blk.hir_id.local_id,
164157
data: ScopeData::Remainder(FirstStatementIndex::new(i)),
165158
});
166-
visitor.cx.set_var_parent();
159+
visitor.cx.var_parent = visitor.cx.parent;
167160
visitor.visit_stmt(statement)
168161
}
169162
hir::StmtKind::Item(..) => {
@@ -213,7 +206,7 @@ fn resolve_arm<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, arm: &'tcx hir:
213206
visitor.terminating_scopes.insert(arm.hir_id.local_id);
214207

215208
visitor.enter_node_scope_with_dtor(arm.hir_id.local_id);
216-
visitor.cx.set_var_parent();
209+
visitor.cx.var_parent = visitor.cx.parent;
217210

218211
if let Some(expr) = arm.guard
219212
&& !has_let_expr(expr)
@@ -490,7 +483,7 @@ fn resolve_expr<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, expr: &'tcx hi
490483
ScopeData::IfThen
491484
};
492485
visitor.enter_scope(Scope { local_id: then.hir_id.local_id, data });
493-
visitor.cx.set_var_parent();
486+
visitor.cx.var_parent = visitor.cx.parent;
494487
visitor.visit_expr(cond);
495488
visitor.visit_expr(then);
496489
visitor.cx = expr_cx;
@@ -505,7 +498,7 @@ fn resolve_expr<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, expr: &'tcx hi
505498
ScopeData::IfThen
506499
};
507500
visitor.enter_scope(Scope { local_id: then.hir_id.local_id, data });
508-
visitor.cx.set_var_parent();
501+
visitor.cx.var_parent = visitor.cx.parent;
509502
visitor.visit_expr(cond);
510503
visitor.visit_expr(then);
511504
visitor.cx = expr_cx;
@@ -545,7 +538,7 @@ fn resolve_expr<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, expr: &'tcx hi
545538
// Keep traversing up while we can.
546539
match visitor.scope_tree.parent_map.get(&scope) {
547540
// Don't cross from closure bodies to their parent.
548-
Some(&(superscope, _)) => match superscope.data {
541+
Some(&superscope) => match superscope.data {
549542
ScopeData::CallSite => break,
550543
_ => scope = superscope,
551544
},
@@ -781,20 +774,16 @@ fn resolve_local<'tcx>(
781774

782775
impl<'tcx> ScopeResolutionVisitor<'tcx> {
783776
/// Records the current parent (if any) as the parent of `child_scope`.
784-
/// Returns the depth of `child_scope`.
785-
fn record_child_scope(&mut self, child_scope: Scope) -> ScopeDepth {
777+
fn record_child_scope(&mut self, child_scope: Scope) {
786778
let parent = self.cx.parent;
787779
self.scope_tree.record_scope_parent(child_scope, parent);
788-
// If `child_scope` has no parent, it must be the root node, and so has
789-
// a depth of 1. Otherwise, its depth is one more than its parent's.
790-
parent.map_or(1, |(_p, d)| d + 1)
791780
}
792781

793782
/// Records the current parent (if any) as the parent of `child_scope`,
794783
/// and sets `child_scope` as the new current parent.
795784
fn enter_scope(&mut self, child_scope: Scope) {
796-
let child_depth = self.record_child_scope(child_scope);
797-
self.cx.parent = Some((child_scope, child_depth));
785+
self.record_child_scope(child_scope);
786+
self.cx.parent = Some(child_scope);
798787
}
799788

800789
fn enter_node_scope_with_dtor(&mut self, id: hir::ItemLocalId) {
@@ -855,7 +844,7 @@ impl<'tcx> Visitor<'tcx> for ScopeResolutionVisitor<'tcx> {
855844
self.enter_body(body.value.hir_id, |this| {
856845
if this.tcx.hir_body_owner_kind(owner_id).is_fn_or_closure() {
857846
// The arguments and `self` are parented to the fn.
858-
this.cx.set_var_parent();
847+
this.cx.var_parent = this.cx.parent;
859848
for param in body.params {
860849
this.visit_pat(param.pat);
861850
}

compiler/rustc_middle/src/middle/region.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,6 @@ impl Scope {
199199
}
200200
}
201201

202-
pub type ScopeDepth = u32;
203-
204202
/// The region scope tree encodes information about region relationships.
205203
#[derive(Default, Debug, HashStable)]
206204
pub struct ScopeTree {
@@ -213,7 +211,7 @@ pub struct ScopeTree {
213211
/// conditional expression or repeating block. (Note that the
214212
/// enclosing scope ID for the block associated with a closure is
215213
/// the closure itself.)
216-
pub parent_map: FxIndexMap<Scope, (Scope, ScopeDepth)>,
214+
pub parent_map: FxIndexMap<Scope, Scope>,
217215

218216
/// Maps from a variable or binding ID to the block in which that
219217
/// variable is declared.
@@ -328,7 +326,7 @@ pub struct YieldData {
328326
}
329327

330328
impl ScopeTree {
331-
pub fn record_scope_parent(&mut self, child: Scope, parent: Option<(Scope, ScopeDepth)>) {
329+
pub fn record_scope_parent(&mut self, child: Scope, parent: Option<Scope>) {
332330
debug!("{:?}.parent = {:?}", child, parent);
333331

334332
if let Some(p) = parent {
@@ -353,7 +351,7 @@ impl ScopeTree {
353351

354352
/// Returns the narrowest scope that encloses `id`, if any.
355353
pub fn opt_encl_scope(&self, id: Scope) -> Option<Scope> {
356-
self.parent_map.get(&id).cloned().map(|(p, _)| p)
354+
self.parent_map.get(&id).cloned()
357355
}
358356

359357
/// Returns the lifetime of the local variable `var_id`, if any.

compiler/rustc_middle/src/ty/rvalue_scopes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl RvalueScopes {
3838
let mut id = Scope { local_id: expr_id, data: ScopeData::Node };
3939
let mut backwards_incompatible = None;
4040

41-
while let Some(&(p, _)) = region_scope_tree.parent_map.get(&id) {
41+
while let Some(&p) = region_scope_tree.parent_map.get(&id) {
4242
match p.data {
4343
ScopeData::Destruction => {
4444
debug!("temporary_scope({expr_id:?}) = {id:?} [enclosing]");

0 commit comments

Comments
 (0)