Skip to content

Commit f196536

Browse files
committed
Temp: Cleanup 2 (SourceInfo)
1 parent b6a2ae9 commit f196536

File tree

1 file changed

+14
-30
lines changed

1 file changed

+14
-30
lines changed

src/librustc_mir/build/scope.rs

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ struct Scope {
132132
struct DropData {
133133
/// The `Span` where drop obligation was incurred (typically where place was
134134
/// declared)
135-
span: Span,
135+
source_info: SourceInfo,
136136

137137
/// local to drop
138138
local: Local,
@@ -177,8 +177,7 @@ const CONTINUE_NODE: DropIdx = DropIdx::from_u32_const(1);
177177
// TODO say some more.
178178
#[derive(Debug)]
179179
struct DropTree {
180-
/// The next item to drop, if there is one.
181-
// TODO actual comment
180+
/// Drops in the tree.
182181
drops: IndexVec<DropIdx, (DropData, DropIdx)>,
183182
/// Map for finding the inverse of the `next_drop` relation:
184183
///
@@ -191,14 +190,6 @@ struct DropTree {
191190
}
192191

193192
impl Scope {
194-
/// Given a span and this scope's source scope, make a SourceInfo.
195-
fn source_info(&self, span: Span) -> SourceInfo {
196-
SourceInfo {
197-
span,
198-
scope: self.source_scope
199-
}
200-
}
201-
202193
/// Whether there's anything to do for the cleanup path, that is,
203194
/// when unwinding through this scope. This includes destructors,
204195
/// but not StorageDead statements, which don't get emitted at all
@@ -220,7 +211,12 @@ impl Scope {
220211

221212
impl DropTree {
222213
fn new(num_roots: usize) -> Self {
223-
let fake_data = DropData { span: DUMMY_SP, local: Local::MAX, kind: DropKind::Storage };
214+
let fake_source_info = SourceInfo { span: DUMMY_SP, scope: OUTERMOST_SOURCE_SCOPE };
215+
let fake_data = DropData {
216+
source_info: fake_source_info,
217+
local: Local::MAX,
218+
kind: DropKind::Storage,
219+
};
224220
let drop_idx = DropIdx::MAX;
225221
let drops = IndexVec::from_elem_n((fake_data, drop_idx), num_roots);
226222
Self {
@@ -290,10 +286,6 @@ impl<'tcx> Scopes<'tcx> {
290286
fn topmost(&self) -> region::Scope {
291287
self.scopes.last().expect("topmost_scope: no scopes present").region_scope
292288
}
293-
294-
// fn source_info(&self, index: usize, span: Span) -> SourceInfo {
295-
// self.scopes[self.len() - index].source_info(span)
296-
// }
297289
}
298290

299291
impl<'a, 'tcx> Builder<'a, 'tcx> {
@@ -495,7 +487,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
495487
self.cfg.start_new_block().unit()
496488
}
497489

498-
// TODO: use in pop_top_scope.
499490
crate fn exit_top_scope(
500491
&mut self,
501492
mut block: BasicBlock,
@@ -678,7 +669,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
678669
let scope_end = self.hir.tcx().sess.source_map().end_point(region_scope_span);
679670

680671
scope.drops.push(DropData {
681-
span: scope_end,
672+
source_info: SourceInfo { span: scope_end, scope: scope.source_scope },
682673
local,
683674
kind: drop_kind,
684675
});
@@ -791,7 +782,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
791782
bug!("Drop scheduled on top of condition variable")
792783
}
793784
DropKind::Storage => {
794-
let source_info = top_scope.source_info(top_drop_data.span);
785+
let source_info = top_drop_data.source_info;
795786
let local = top_drop_data.local;
796787
assert_eq!(local, cond_temp, "Drop scheduled on top of condition");
797788
self.cfg.push(
@@ -933,7 +924,7 @@ fn build_scope_drops<'tcx>(
933924
// `diverge_cleanup_gen`.
934925

935926
for drop_data in scope.drops.iter().rev() {
936-
let source_info = scope.source_info(drop_data.span);
927+
let source_info = drop_data.source_info;
937928
let local = drop_data.local;
938929

939930
match drop_data.kind {
@@ -1127,13 +1118,6 @@ impl<'a, 'tcx: 'a> Builder<'a, 'tcx> {
11271118
}
11281119
}
11291120

1130-
fn source_info(span: Span) -> SourceInfo {
1131-
SourceInfo {
1132-
span,
1133-
scope: OUTERMOST_SOURCE_SCOPE,
1134-
}
1135-
}
1136-
11371121
fn build_drop_tree<'tcx, T: DropTreeBuilder<'tcx>>(
11381122
cfg: &mut CFG<'tcx>,
11391123
drops: &mut DropTree,
@@ -1207,7 +1191,7 @@ fn build_drop_tree<'tcx, T: DropTreeBuilder<'tcx>>(
12071191
};
12081192
cfg.terminate(
12091193
blocks[drop_idx].unwrap(),
1210-
source_info(drop_data.0.span),
1194+
drop_data.0.source_info,
12111195
terminator,
12121196
);
12131197
}
@@ -1216,14 +1200,14 @@ fn build_drop_tree<'tcx, T: DropTreeBuilder<'tcx>>(
12161200
DropKind::Storage => {
12171201
let block = blocks[drop_idx].unwrap();
12181202
let stmt = Statement {
1219-
source_info: source_info(drop_data.0.span),
1203+
source_info: drop_data.0.source_info,
12201204
kind: StatementKind::StorageDead(drop_data.0.local),
12211205
};
12221206
cfg.push(block, stmt);
12231207
let target = blocks[drop_data.1].unwrap();
12241208
if target != block {
12251209
let terminator = TerminatorKind::Goto { target };
1226-
cfg.terminate(block, source_info(drop_data.0.span), terminator);
1210+
cfg.terminate(block, drop_data.0.source_info, terminator);
12271211
}
12281212
}
12291213
}

0 commit comments

Comments
 (0)