Skip to content

Commit 9ff7b73

Browse files
committed
Update region_scope_tree
1 parent c136050 commit 9ff7b73

File tree

11 files changed

+52
-14
lines changed

11 files changed

+52
-14
lines changed

src/librustc/hir/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ mod item_local_id_inner {
135135
}
136136
}
137137

138+
impl_defer_dellocs_for_no_drop_type!([] ItemLocalId);
139+
138140
pub use self::item_local_id_inner::ItemLocalId;
139141

140142
/// The `HirId` corresponding to CRATE_NODE_ID and CRATE_DEF_INDEX
@@ -1269,6 +1271,8 @@ pub struct BodyId {
12691271
pub node_id: NodeId,
12701272
}
12711273

1274+
impl_defer_dellocs_for_no_drop_type!([] BodyId);
1275+
12721276
/// The body of a function, closure, or constant value. In the case of
12731277
/// a function, the body contains not only the function body itself
12741278
/// (which is an expression), but also the argument patterns, since

src/librustc/middle/region.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use ty;
2222

2323
use std::mem;
2424
use std::fmt;
25-
use rustc_data_structures::sync::Lrc;
2625
use syntax::source_map;
2726
use syntax::ast;
2827
use syntax_pos::{Span, DUMMY_SP};
@@ -34,6 +33,7 @@ use hir::Node;
3433
use hir::def_id::DefId;
3534
use hir::intravisit::{self, Visitor, NestedVisitorMap};
3635
use hir::{Block, Arm, Pat, PatKind, Stmt, Expr, Local};
36+
use rustc_data_structures::defer_deallocs::{DeferDeallocs, DeferredDeallocs};
3737
use rustc_data_structures::indexed_vec::Idx;
3838
use rustc_data_structures::stable_hasher::{HashStable, StableHasher,
3939
StableHasherResult};
@@ -106,6 +106,8 @@ pub struct Scope {
106106
pub data: ScopeData,
107107
}
108108

109+
impl_defer_dellocs_for_no_drop_type!([] Scope);
110+
109111
impl fmt::Debug for Scope {
110112
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
111113
match self.data {
@@ -349,6 +351,18 @@ pub struct ScopeTree {
349351
body_expr_count: FxHashMap<hir::BodyId, usize>,
350352
}
351353

354+
unsafe impl DeferDeallocs for ScopeTree {
355+
fn defer(&self, deferred: &mut DeferredDeallocs) {
356+
self.parent_map.defer(deferred);
357+
self.var_map.defer(deferred);
358+
self.destruction_scopes.defer(deferred);
359+
self.rvalue_scopes.defer(deferred);
360+
self.closure_tree.defer(deferred);
361+
self.yield_in_scope.defer(deferred);
362+
self.body_expr_count.defer(deferred);
363+
}
364+
}
365+
352366
#[derive(Debug, Copy, Clone)]
353367
pub struct Context {
354368
/// the root of the current region tree. This is typically the id
@@ -1329,7 +1343,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RegionResolutionVisitor<'a, 'tcx> {
13291343
}
13301344

13311345
fn region_scope_tree<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId)
1332-
-> Lrc<ScopeTree>
1346+
-> &'tcx ScopeTree
13331347
{
13341348
let closure_base_def_id = tcx.closure_base_def_id(def_id);
13351349
if closure_base_def_id != def_id {
@@ -1371,7 +1385,7 @@ fn region_scope_tree<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId)
13711385
ScopeTree::default()
13721386
};
13731387

1374-
Lrc::new(scope_tree)
1388+
tcx.promote(scope_tree)
13751389
}
13761390

13771391
pub fn provide(providers: &mut Providers<'_>) {

src/librustc/ty/query/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ define_queries! { <'tcx>
330330

331331
/// Per-body `region::ScopeTree`. The `DefId` should be the owner-def-id for the body;
332332
/// in the case of closures, this will be redirected to the enclosing function.
333-
[] fn region_scope_tree: RegionScopeTree(DefId) -> Lrc<region::ScopeTree>,
333+
[] fn region_scope_tree: RegionScopeTree(DefId) -> &'tcx region::ScopeTree,
334334

335335
[] fn mir_shims: mir_shim_dep_node(ty::InstanceDef<'tcx>) -> &'tcx mir::Mir<'tcx>,
336336

src/librustc_borrowck/borrowck/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ pub struct BorrowckCtxt<'a, 'tcx: 'a> {
253253
// Some in `borrowck_fn` and cleared later
254254
tables: &'a ty::TypeckTables<'tcx>,
255255

256-
region_scope_tree: Lrc<region::ScopeTree>,
256+
region_scope_tree: &'tcx region::ScopeTree,
257257

258258
owner_def_id: DefId,
259259

src/librustc_data_structures/defer_deallocs.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,30 @@ unsafe impl<T: DeferDeallocs> DeferDeallocs for Vec<T> {
7575
}
7676
}
7777

78+
impl_defer_dellocs_for_no_drop_type!([] usize);
79+
impl_defer_dellocs_for_no_drop_type!([] u32);
7880
impl_defer_dellocs_for_no_drop_type!([] u64);
7981
impl_defer_dellocs_for_no_drop_type!([<T>] BuildHasherDefault<T>);
8082

83+
unsafe impl<T: DeferDeallocs> DeferDeallocs for Option<T> {
84+
#[inline]
85+
fn defer(&self, deferred: &mut DeferredDeallocs) {
86+
self.as_ref().map(|v| v.defer(deferred));
87+
}
88+
}
89+
90+
unsafe impl<
91+
T1: DeferDeallocs,
92+
T2: DeferDeallocs,
93+
> DeferDeallocs
94+
for (T1, T2) {
95+
#[inline]
96+
fn defer(&self, deferred: &mut DeferredDeallocs) {
97+
self.0.defer(deferred);
98+
self.1.defer(deferred);
99+
}
100+
}
101+
81102
unsafe impl<
82103
K: DeferDeallocs + Eq + Hash,
83104
V: DeferDeallocs,

src/librustc_mir/borrow_check/error_reporting.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ use rustc::ty::{self, DefIdTree};
2525
use rustc::util::ppaux::with_highlight_region_for_bound_region;
2626
use rustc_data_structures::fx::FxHashSet;
2727
use rustc_data_structures::indexed_vec::Idx;
28-
use rustc_data_structures::sync::Lrc;
2928
use rustc_errors::{Applicability, DiagnosticBuilder};
3029
use syntax_pos::Span;
3130

@@ -668,7 +667,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
668667
&mut self,
669668
context: Context,
670669
name: &str,
671-
scope_tree: &Lrc<ScopeTree>,
670+
scope_tree: &'tcx ScopeTree,
672671
borrow: &BorrowData<'tcx>,
673672
drop_span: Span,
674673
borrow_spans: UseSpans,
@@ -851,7 +850,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
851850
fn report_temporary_value_does_not_live_long_enough(
852851
&mut self,
853852
context: Context,
854-
scope_tree: &Lrc<ScopeTree>,
853+
scope_tree: &'tcx ScopeTree,
855854
borrow: &BorrowData<'tcx>,
856855
drop_span: Span,
857856
borrow_spans: UseSpans,

src/librustc_mir/hair/cx/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ use syntax::ast;
3030
use syntax::attr;
3131
use syntax::symbol::Symbol;
3232
use rustc::hir;
33-
use rustc_data_structures::sync::Lrc;
3433
use hair::constant::{lit_to_const, LitToConstError};
3534

3635
#[derive(Clone)]
@@ -44,7 +43,7 @@ pub struct Cx<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
4443
/// Identity `Substs` for use with const-evaluation.
4544
pub identity_substs: &'gcx Substs<'gcx>,
4645

47-
pub region_scope_tree: Lrc<region::ScopeTree>,
46+
pub region_scope_tree: &'gcx region::ScopeTree,
4847
pub tables: &'a ty::TypeckTables<'gcx>,
4948

5049
/// This is `Constness::Const` if we are compiling a `static`,

src/librustc_typeck/check/generator_interior.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@ use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap};
1818
use rustc::hir::{self, Pat, PatKind, Expr};
1919
use rustc::middle::region;
2020
use rustc::ty::{self, Ty};
21-
use rustc_data_structures::sync::Lrc;
2221
use syntax_pos::Span;
2322
use super::FnCtxt;
2423
use util::nodemap::FxHashMap;
2524

2625
struct InteriorVisitor<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
2726
fcx: &'a FnCtxt<'a, 'gcx, 'tcx>,
2827
types: FxHashMap<Ty<'tcx>, usize>,
29-
region_scope_tree: Lrc<region::ScopeTree>,
28+
region_scope_tree: &'gcx region::ScopeTree,
3029
expr_count: usize,
3130
}
3231

src/librustc_typeck/check/regionck.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ use rustc::ty::{self, Ty};
9696

9797
use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor};
9898
use rustc::hir::{self, PatKind};
99-
use rustc_data_structures::sync::Lrc;
10099
use std::mem;
101100
use std::ops::Deref;
102101
use std::rc::Rc;
@@ -206,7 +205,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
206205
pub struct RegionCtxt<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
207206
pub fcx: &'a FnCtxt<'a, 'gcx, 'tcx>,
208207

209-
pub region_scope_tree: Lrc<region::ScopeTree>,
208+
pub region_scope_tree: &'gcx region::ScopeTree,
210209

211210
outlives_environment: OutlivesEnvironment<'tcx>,
212211

src/libsyntax_pos/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ use rustc_data_structures::stable_hasher::StableHasher;
3939
use rustc_data_structures::sync::{Lrc, Lock};
4040

4141
extern crate arena;
42+
#[macro_use]
4243
extern crate rustc_data_structures;
4344

4445
#[macro_use]

0 commit comments

Comments
 (0)