Skip to content

Remove ScopeTree::closure_tree #84343

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 0 additions & 31 deletions compiler/rustc_middle/src/middle/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,18 +235,6 @@ pub struct ScopeTree {
/// escape into 'static and should have no local cleanup scope.
rvalue_scopes: FxHashMap<hir::ItemLocalId, Option<Scope>>,

/// Encodes the hierarchy of fn bodies. Every fn body (including
/// closures) forms its own distinct region hierarchy, rooted in
/// the block that is the fn body. This map points from the ID of
/// that root block to the ID of the root block for the enclosing
/// fn, if any. Thus the map structures the fn bodies into a
/// hierarchy based on their lexical mapping. This is used to
/// handle the relationships between regions in a fn and in a
/// closure defined by that fn. See the "Modeling closures"
/// section of the README in infer::region_constraints for
/// more details.
closure_tree: FxHashMap<hir::ItemLocalId, hir::ItemLocalId>,

/// If there are any `yield` nested within a scope, this map
/// stores the `Span` of the last one and its index in the
/// postorder of the Visitor traversal on the HIR.
Expand Down Expand Up @@ -356,23 +344,6 @@ impl ScopeTree {
self.destruction_scopes.get(&n).cloned()
}

/// Records that `sub_closure` is defined within `sup_closure`. These IDs
/// should be the ID of the block that is the fn body, which is
/// also the root of the region hierarchy for that fn.
pub fn record_closure_parent(
&mut self,
sub_closure: hir::ItemLocalId,
sup_closure: hir::ItemLocalId,
) {
debug!(
"record_closure_parent(sub_closure={:?}, sup_closure={:?})",
sub_closure, sup_closure
);
assert!(sub_closure != sup_closure);
let previous = self.closure_tree.insert(sub_closure, sup_closure);
assert!(previous.is_none());
}

pub fn record_var_scope(&mut self, var: hir::ItemLocalId, lifetime: Scope) {
debug!("record_var_scope(sub={:?}, sup={:?})", var, lifetime);
assert!(var != lifetime.item_local_id());
Expand Down Expand Up @@ -474,7 +445,6 @@ impl<'a> HashStable<StableHashingContext<'a>> for ScopeTree {
ref var_map,
ref destruction_scopes,
ref rvalue_scopes,
ref closure_tree,
ref yield_in_scope,
} = *self;

Expand All @@ -488,7 +458,6 @@ impl<'a> HashStable<StableHashingContext<'a>> for ScopeTree {
var_map.hash_stable(hcx, hasher);
destruction_scopes.hash_stable(hcx, hasher);
rvalue_scopes.hash_stable(hcx, hasher);
closure_tree.hash_stable(hcx, hasher);
yield_in_scope.hash_stable(hcx, hasher);
}
}
15 changes: 1 addition & 14 deletions compiler/rustc_passes/src/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@ use std::mem;

#[derive(Debug, Copy, Clone)]
pub struct Context {
/// The root of the current region tree. This is typically the id
/// of the innermost fn body. Each fn forms its own disjoint tree
/// in the region hierarchy. These fn bodies are themselves
/// arranged into a tree. See the "Modeling closures" section of
/// the README in `rustc_trait_selection::infer::region_constraints`
/// for more details.
root_id: Option<hir::ItemLocalId>,

/// The scope that contains any new variables declared, plus its depth in
/// the scope tree.
var_parent: Option<(Scope, ScopeDepth)>,
Expand Down Expand Up @@ -743,11 +735,6 @@ impl<'tcx> Visitor<'tcx> for RegionResolutionVisitor<'tcx> {
let outer_pessimistic_yield = mem::replace(&mut self.pessimistic_yield, false);
self.terminating_scopes.insert(body.value.hir_id.local_id);

if let Some(root_id) = self.cx.root_id {
self.scope_tree.record_closure_parent(body.value.hir_id.local_id, root_id);
}
self.cx.root_id = Some(body.value.hir_id.local_id);

self.enter_scope(Scope { id: body.value.hir_id.local_id, data: ScopeData::CallSite });
self.enter_scope(Scope { id: body.value.hir_id.local_id, data: ScopeData::Arguments });

Expand Down Expand Up @@ -824,7 +811,7 @@ fn region_scope_tree(tcx: TyCtxt<'_>, def_id: DefId) -> &ScopeTree {
tcx,
scope_tree: ScopeTree::default(),
expr_and_pat_count: 0,
cx: Context { root_id: None, parent: None, var_parent: None },
cx: Context { parent: None, var_parent: None },
terminating_scopes: Default::default(),
pessimistic_yield: false,
fixup_scopes: vec![],
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_trait_selection/src/traits/object_safety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,7 @@ fn virtual_call_violation_for_method<'tcx>(
return Some(MethodViolationCode::WhereClauseReferencesSelf);
}

let receiver_ty =
tcx.liberate_late_bound_regions(method.def_id, sig.map_bound(|sig| sig.inputs()[0]));
let receiver_ty = tcx.liberate_late_bound_regions(method.def_id, sig.input(0));

// Until `unsized_locals` is fully implemented, `self: Self` can't be dispatched on.
// However, this is already considered object-safe. We allow it as a special case here.
Expand Down