Skip to content

Commit e8ebc90

Browse files
committed
Migrated some code out of dataflow::drop_flag_effects and into its parent module.
(This code is more general purpose than just supporting drop flag elaboration.)
1 parent 9f6ef66 commit e8ebc90

File tree

2 files changed

+71
-74
lines changed

2 files changed

+71
-74
lines changed

src/librustc_mir/dataflow/drop_flag_effects.rs

Lines changed: 2 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -8,84 +8,16 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use syntax::ast::{self, MetaItem};
1211
use syntax_pos::DUMMY_SP;
1312

14-
15-
use rustc::mir::{self, Mir, BasicBlock, Location};
16-
use rustc::session::Session;
13+
use rustc::mir::{self, Mir, Location};
1714
use rustc::ty::{self, TyCtxt};
1815
use util::elaborate_drops::DropFlagState;
19-
use rustc_data_structures::indexed_set::{IdxSet};
20-
21-
use std::fmt;
2216

23-
use super::{Dataflow, DataflowBuilder, DataflowAnalysis};
24-
use super::{BitDenotation, DataflowOperator, DataflowResults};
17+
use super::{MoveDataParamEnv};
2518
use super::indexes::MovePathIndex;
2619
use super::move_paths::{MoveData, LookupResult};
2720

28-
pub(crate) fn has_rustc_mir_with(attrs: &[ast::Attribute], name: &str) -> Option<MetaItem> {
29-
for attr in attrs {
30-
if attr.check_name("rustc_mir") {
31-
let items = attr.meta_item_list();
32-
for item in items.iter().flat_map(|l| l.iter()) {
33-
match item.meta_item() {
34-
Some(mi) if mi.check_name(name) => return Some(mi.clone()),
35-
_ => continue
36-
}
37-
}
38-
}
39-
}
40-
return None;
41-
}
42-
43-
pub struct MoveDataParamEnv<'tcx> {
44-
pub(crate) move_data: MoveData<'tcx>,
45-
pub(crate) param_env: ty::ParamEnv<'tcx>,
46-
}
47-
48-
pub(crate) fn do_dataflow<'a, 'tcx, BD, P>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
49-
mir: &Mir<'tcx>,
50-
node_id: ast::NodeId,
51-
attributes: &[ast::Attribute],
52-
dead_unwinds: &IdxSet<BasicBlock>,
53-
bd: BD,
54-
p: P)
55-
-> DataflowResults<BD>
56-
where BD: BitDenotation<Idx=MovePathIndex> + DataflowOperator,
57-
P: Fn(&BD, BD::Idx) -> &fmt::Debug
58-
{
59-
let name_found = |sess: &Session, attrs: &[ast::Attribute], name| -> Option<String> {
60-
if let Some(item) = has_rustc_mir_with(attrs, name) {
61-
if let Some(s) = item.value_str() {
62-
return Some(s.to_string())
63-
} else {
64-
sess.span_err(
65-
item.span,
66-
&format!("{} attribute requires a path", item.name()));
67-
return None;
68-
}
69-
}
70-
return None;
71-
};
72-
73-
let print_preflow_to =
74-
name_found(tcx.sess, attributes, "borrowck_graphviz_preflow");
75-
let print_postflow_to =
76-
name_found(tcx.sess, attributes, "borrowck_graphviz_postflow");
77-
78-
let mut mbcx = DataflowBuilder {
79-
node_id,
80-
print_preflow_to,
81-
print_postflow_to,
82-
flow_state: DataflowAnalysis::new(tcx, mir, dead_unwinds, bd),
83-
};
84-
85-
mbcx.dataflow(p);
86-
mbcx.flow_state.results()
87-
}
88-
8921
pub fn move_path_children_matching<'tcx, F>(move_data: &MoveData<'tcx>,
9022
path: MovePathIndex,
9123
mut cond: F)

src/librustc_mir/dataflow/mod.rs

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,17 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use syntax::ast;
11+
use syntax::ast::{self, MetaItem};
1212

1313
use rustc_data_structures::indexed_set::{IdxSet, IdxSetBuf};
1414
use rustc_data_structures::indexed_vec::Idx;
1515
use rustc_data_structures::bitslice::{bitwise, BitwiseOperator};
1616

17-
use rustc::ty::{TyCtxt};
18-
use rustc::mir::{self, Mir, Location};
17+
use rustc::ty::{self, TyCtxt};
18+
use rustc::mir::{self, Mir, BasicBlock, Location};
19+
use rustc::session::Session;
1920

20-
use std::fmt::Debug;
21+
use std::fmt::{self, Debug};
2122
use std::io;
2223
use std::mem;
2324
use std::path::PathBuf;
@@ -28,6 +29,9 @@ pub use self::impls::{DefinitelyInitializedLvals, MovingOutStatements};
2829
pub use self::impls::borrows::{Borrows, BorrowData, BorrowIndex};
2930
pub(crate) use self::drop_flag_effects::*;
3031

32+
use self::move_paths::MoveData;
33+
use self::indexes::MovePathIndex;
34+
3135
mod drop_flag_effects;
3236
mod graphviz;
3337
mod impls;
@@ -58,6 +62,67 @@ impl<'a, 'tcx: 'a, BD> Dataflow<BD> for DataflowBuilder<'a, 'tcx, BD>
5862
}
5963
}
6064

65+
pub(crate) fn has_rustc_mir_with(attrs: &[ast::Attribute], name: &str) -> Option<MetaItem> {
66+
for attr in attrs {
67+
if attr.check_name("rustc_mir") {
68+
let items = attr.meta_item_list();
69+
for item in items.iter().flat_map(|l| l.iter()) {
70+
match item.meta_item() {
71+
Some(mi) if mi.check_name(name) => return Some(mi.clone()),
72+
_ => continue
73+
}
74+
}
75+
}
76+
}
77+
return None;
78+
}
79+
80+
pub struct MoveDataParamEnv<'tcx> {
81+
pub(crate) move_data: MoveData<'tcx>,
82+
pub(crate) param_env: ty::ParamEnv<'tcx>,
83+
}
84+
85+
pub(crate) fn do_dataflow<'a, 'tcx, BD, P>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
86+
mir: &Mir<'tcx>,
87+
node_id: ast::NodeId,
88+
attributes: &[ast::Attribute],
89+
dead_unwinds: &IdxSet<BasicBlock>,
90+
bd: BD,
91+
p: P)
92+
-> DataflowResults<BD>
93+
where BD: BitDenotation<Idx=MovePathIndex> + DataflowOperator,
94+
P: Fn(&BD, BD::Idx) -> &fmt::Debug
95+
{
96+
let name_found = |sess: &Session, attrs: &[ast::Attribute], name| -> Option<String> {
97+
if let Some(item) = has_rustc_mir_with(attrs, name) {
98+
if let Some(s) = item.value_str() {
99+
return Some(s.to_string())
100+
} else {
101+
sess.span_err(
102+
item.span,
103+
&format!("{} attribute requires a path", item.name()));
104+
return None;
105+
}
106+
}
107+
return None;
108+
};
109+
110+
let print_preflow_to =
111+
name_found(tcx.sess, attributes, "borrowck_graphviz_preflow");
112+
let print_postflow_to =
113+
name_found(tcx.sess, attributes, "borrowck_graphviz_postflow");
114+
115+
let mut mbcx = DataflowBuilder {
116+
node_id,
117+
print_preflow_to,
118+
print_postflow_to,
119+
flow_state: DataflowAnalysis::new(tcx, mir, dead_unwinds, bd),
120+
};
121+
122+
mbcx.dataflow(p);
123+
mbcx.flow_state.results()
124+
}
125+
61126
struct PropagationContext<'b, 'a: 'b, 'tcx: 'a, O>
62127
where O: 'b + BitDenotation
63128
{

0 commit comments

Comments
 (0)