Rollup merge of #37296 - srinivasreddy:librustc_driver, r=nikomatsakis

run rustfmt on librustc_driver folder
This commit is contained in:
Guillaume Gomez
2016-11-01 16:15:51 +01:00
committed by GitHub
3 changed files with 191 additions and 188 deletions

View File

@@ -101,8 +101,8 @@ impl PpMode {
pub fn needs_analysis(&self) -> bool { pub fn needs_analysis(&self) -> bool {
match *self { match *self {
PpmMir | PpmMirCFG | PpmFlowGraph(_) => true, PpmMir | PpmMirCFG | PpmFlowGraph(_) => true,
_ => false, _ => false,
} }
} }
} }
@@ -233,14 +233,11 @@ impl PpSourceMode {
arenas, arenas,
id, id,
|tcx, _, _, _| { |tcx, _, _, _| {
let annotation = TypedAnnotation { let annotation = TypedAnnotation { tcx: tcx };
tcx: tcx,
};
let _ignore = tcx.dep_graph.in_ignore(); let _ignore = tcx.dep_graph.in_ignore();
f(&annotation, f(&annotation, payload, ast_map.forest.krate())
payload, }),
ast_map.forest.krate()) sess)
}), sess)
} }
_ => panic!("Should use call_with_pp_support"), _ => panic!("Should use call_with_pp_support"),
} }
@@ -281,9 +278,11 @@ trait HirPrinterSupport<'ast>: pprust_hir::PpAnn {
/// Computes an user-readable representation of a path, if possible. /// Computes an user-readable representation of a path, if possible.
fn node_path(&self, id: ast::NodeId) -> Option<String> { fn node_path(&self, id: ast::NodeId) -> Option<String> {
self.ast_map().and_then(|map| map.def_path_from_id(id)).map(|path| { self.ast_map().and_then(|map| map.def_path_from_id(id)).map(|path| {
path.data.into_iter().map(|elem| { path.data
elem.data.to_string() .into_iter()
}).collect::<Vec<_>>().join("::") .map(|elem| elem.data.to_string())
.collect::<Vec<_>>()
.join("::")
}) })
} }
} }
@@ -352,7 +351,8 @@ impl<'ast> pprust::PpAnn for IdentifiedAnnotation<'ast> {
} }
fn post(&self, s: &mut pprust::State, node: pprust::AnnNode) -> io::Result<()> { fn post(&self, s: &mut pprust::State, node: pprust::AnnNode) -> io::Result<()> {
match node { match node {
pprust::NodeIdent(_) | pprust::NodeName(_) => Ok(()), pprust::NodeIdent(_) |
pprust::NodeName(_) => Ok(()),
pprust::NodeItem(item) => { pprust::NodeItem(item) => {
pp::space(&mut s.s)?; pp::space(&mut s.s)?;
@@ -617,15 +617,14 @@ impl ReplaceBodyWithLoop {
impl fold::Folder for ReplaceBodyWithLoop { impl fold::Folder for ReplaceBodyWithLoop {
fn fold_item_kind(&mut self, i: ast::ItemKind) -> ast::ItemKind { fn fold_item_kind(&mut self, i: ast::ItemKind) -> ast::ItemKind {
match i { match i {
ast::ItemKind::Static(..) | ast::ItemKind::Const(..) => { ast::ItemKind::Static(..) |
ast::ItemKind::Const(..) => {
self.within_static_or_const = true; self.within_static_or_const = true;
let ret = fold::noop_fold_item_kind(i, self); let ret = fold::noop_fold_item_kind(i, self);
self.within_static_or_const = false; self.within_static_or_const = false;
return ret; return ret;
} }
_ => { _ => fold::noop_fold_item_kind(i, self),
fold::noop_fold_item_kind(i, self)
}
} }
} }
@@ -656,11 +655,15 @@ impl fold::Folder for ReplaceBodyWithLoop {
fn fold_block(&mut self, b: P<ast::Block>) -> P<ast::Block> { fn fold_block(&mut self, b: P<ast::Block>) -> P<ast::Block> {
fn expr_to_block(rules: ast::BlockCheckMode, e: Option<P<ast::Expr>>) -> P<ast::Block> { fn expr_to_block(rules: ast::BlockCheckMode, e: Option<P<ast::Expr>>) -> P<ast::Block> {
P(ast::Block { P(ast::Block {
stmts: e.map(|e| ast::Stmt { stmts: e.map(|e| {
id: ast::DUMMY_NODE_ID, ast::Stmt {
span: e.span, id: ast::DUMMY_NODE_ID,
node: ast::StmtKind::Expr(e), span: e.span,
}).into_iter().collect(), node: ast::StmtKind::Expr(e),
}
})
.into_iter()
.collect(),
rules: rules, rules: rules,
id: ast::DUMMY_NODE_ID, id: ast::DUMMY_NODE_ID,
span: syntax_pos::DUMMY_SP, span: syntax_pos::DUMMY_SP,
@@ -721,9 +724,7 @@ fn print_flowgraph<'a, 'tcx, W: Write>(variants: Vec<borrowck_dot::Variant>,
} }
blocks::FnLikeCode(fn_like) => { blocks::FnLikeCode(fn_like) => {
let (bccx, analysis_data) = let (bccx, analysis_data) =
borrowck::build_borrowck_dataflow_data_for_fn(tcx, borrowck::build_borrowck_dataflow_data_for_fn(tcx, fn_like.to_fn_parts(), &cfg);
fn_like.to_fn_parts(),
&cfg);
let lcfg = borrowck_dot::DataflowLabeller { let lcfg = borrowck_dot::DataflowLabeller {
inner: lcfg, inner: lcfg,
@@ -756,13 +757,13 @@ pub fn fold_crate(krate: ast::Crate, ppm: PpMode) -> ast::Crate {
fn get_source(input: &Input, sess: &Session) -> (Vec<u8>, String) { fn get_source(input: &Input, sess: &Session) -> (Vec<u8>, String) {
let src_name = driver::source_name(input); let src_name = driver::source_name(input);
let src = sess.codemap() let src = sess.codemap()
.get_filemap(&src_name) .get_filemap(&src_name)
.unwrap() .unwrap()
.src .src
.as_ref() .as_ref()
.unwrap() .unwrap()
.as_bytes() .as_bytes()
.to_vec(); .to_vec();
(src, src_name) (src, src_name)
} }
@@ -795,17 +796,18 @@ pub fn print_after_parsing(sess: &Session,
// Silently ignores an identified node. // Silently ignores an identified node.
let out: &mut Write = &mut out; let out: &mut Write = &mut out;
s.call_with_pp_support(sess, None, box out, |annotation, out| { s.call_with_pp_support(sess, None, box out, |annotation, out| {
debug!("pretty printing source code {:?}", s); debug!("pretty printing source code {:?}", s);
let sess = annotation.sess(); let sess = annotation.sess();
pprust::print_crate(sess.codemap(), pprust::print_crate(sess.codemap(),
sess.diagnostic(), sess.diagnostic(),
krate, krate,
src_name.to_string(), src_name.to_string(),
&mut rdr, &mut rdr,
out, out,
annotation.pp_ann(), annotation.pp_ann(),
false) false)
}).unwrap() })
.unwrap()
} else { } else {
unreachable!(); unreachable!();
}; };
@@ -828,8 +830,15 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
let _ignore = dep_graph.in_ignore(); let _ignore = dep_graph.in_ignore();
if ppm.needs_analysis() { if ppm.needs_analysis() {
print_with_analysis(sess, ast_map, analysis, resolutions, print_with_analysis(sess,
crate_name, arenas, ppm, opt_uii, ofile); ast_map,
analysis,
resolutions,
crate_name,
arenas,
ppm,
opt_uii,
ofile);
return; return;
} }
@@ -839,82 +848,82 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
let mut out = Vec::new(); let mut out = Vec::new();
match (ppm, opt_uii) { match (ppm, opt_uii) {
(PpmSource(s), _) => { (PpmSource(s), _) => {
// Silently ignores an identified node. // Silently ignores an identified node.
let out: &mut Write = &mut out; let out: &mut Write = &mut out;
s.call_with_pp_support(sess, Some(ast_map), box out, |annotation, out| { s.call_with_pp_support(sess, Some(ast_map), box out, |annotation, out| {
debug!("pretty printing source code {:?}", s); debug!("pretty printing source code {:?}", s);
let sess = annotation.sess(); let sess = annotation.sess();
pprust::print_crate(sess.codemap(), pprust::print_crate(sess.codemap(),
sess.diagnostic(), sess.diagnostic(),
krate, krate,
src_name.to_string(), src_name.to_string(),
&mut rdr, &mut rdr,
out, out,
annotation.pp_ann(), annotation.pp_ann(),
true) true)
}) })
} }
(PpmHir(s), None) => { (PpmHir(s), None) => {
let out: &mut Write = &mut out; let out: &mut Write = &mut out;
s.call_with_pp_support_hir(sess, s.call_with_pp_support_hir(sess,
ast_map, ast_map,
analysis, analysis,
resolutions, resolutions,
arenas, arenas,
crate_name, crate_name,
box out, box out,
|annotation, out, krate| { |annotation, out, krate| {
debug!("pretty printing source code {:?}", s); debug!("pretty printing source code {:?}", s);
let sess = annotation.sess(); let sess = annotation.sess();
pprust_hir::print_crate(sess.codemap(), pprust_hir::print_crate(sess.codemap(),
sess.diagnostic(), sess.diagnostic(),
krate, krate,
src_name.to_string(), src_name.to_string(),
&mut rdr, &mut rdr,
out, out,
annotation.pp_ann(), annotation.pp_ann(),
true) true)
}) })
} }
(PpmHir(s), Some(uii)) => { (PpmHir(s), Some(uii)) => {
let out: &mut Write = &mut out; let out: &mut Write = &mut out;
s.call_with_pp_support_hir(sess, s.call_with_pp_support_hir(sess,
ast_map, ast_map,
analysis, analysis,
resolutions, resolutions,
arenas, arenas,
crate_name, crate_name,
(out,uii), (out, uii),
|annotation, (out,uii), _| { |annotation, (out, uii), _| {
debug!("pretty printing source code {:?}", s); debug!("pretty printing source code {:?}", s);
let sess = annotation.sess(); let sess = annotation.sess();
let ast_map = annotation.ast_map().expect("--unpretty missing HIR map"); let ast_map = annotation.ast_map().expect("--unpretty missing HIR map");
let mut pp_state = let mut pp_state = pprust_hir::State::new_from_input(sess.codemap(),
pprust_hir::State::new_from_input(sess.codemap(), sess.diagnostic(),
sess.diagnostic(), src_name.to_string(),
src_name.to_string(), &mut rdr,
&mut rdr, box out,
box out, annotation.pp_ann(),
annotation.pp_ann(), true,
true, Some(ast_map.krate()));
Some(ast_map.krate())); for node_id in uii.all_matching_node_ids(ast_map) {
for node_id in uii.all_matching_node_ids(ast_map) { let node = ast_map.get(node_id);
let node = ast_map.get(node_id); pp_state.print_node(&node)?;
pp_state.print_node(&node)?; pp::space(&mut pp_state.s)?;
pp::space(&mut pp_state.s)?; let path = annotation.node_path(node_id)
let path = annotation.node_path(node_id) .expect("--unpretty missing node paths");
.expect("--unpretty missing node paths"); pp_state.synth_comment(path)?;
pp_state.synth_comment(path)?; pp::hardbreak(&mut pp_state.s)?;
pp::hardbreak(&mut pp_state.s)?; }
} pp::eof(&mut pp_state.s)
pp::eof(&mut pp_state.s) })
}) }
} _ => unreachable!(),
_ => unreachable!(), }
}.unwrap(); .unwrap();
write_output(out, ofile); write_output(out, ofile);
} }
@@ -955,27 +964,28 @@ fn print_with_analysis<'tcx, 'a: 'tcx>(sess: &'a Session,
let def_id = tcx.map.local_def_id(nodeid); let def_id = tcx.map.local_def_id(nodeid);
match ppm { match ppm {
PpmMir => write_mir_pretty(tcx, iter::once(def_id), &mut out), PpmMir => write_mir_pretty(tcx, iter::once(def_id), &mut out),
PpmMirCFG => { PpmMirCFG => write_mir_graphviz(tcx, iter::once(def_id), &mut out),
write_mir_graphviz(tcx, iter::once(def_id), &mut out)
}
_ => unreachable!(), _ => unreachable!(),
}?; }?;
} else { } else {
match ppm { match ppm {
PpmMir => write_mir_pretty(tcx, PpmMir => {
tcx.mir_map.borrow().keys().into_iter(), write_mir_pretty(tcx, tcx.mir_map.borrow().keys().into_iter(), &mut out)
&mut out), }
PpmMirCFG => write_mir_graphviz(tcx, PpmMirCFG => {
tcx.mir_map.borrow().keys().into_iter(), write_mir_graphviz(tcx,
&mut out), tcx.mir_map.borrow().keys().into_iter(),
&mut out)
}
_ => unreachable!(), _ => unreachable!(),
}?; }?;
} }
Ok(()) Ok(())
} }
PpmFlowGraph(mode) => { PpmFlowGraph(mode) => {
let nodeid = nodeid.expect("`pretty flowgraph=..` needs NodeId (int) or \ let nodeid =
unique path suffix (b::c::d)"); nodeid.expect("`pretty flowgraph=..` needs NodeId (int) or unique path \
suffix (b::c::d)");
let node = tcx.map.find(nodeid).unwrap_or_else(|| { let node = tcx.map.find(nodeid).unwrap_or_else(|| {
tcx.sess.fatal(&format!("--pretty flowgraph couldn't find id: {}", nodeid)) tcx.sess.fatal(&format!("--pretty flowgraph couldn't find id: {}", nodeid))
}); });
@@ -990,8 +1000,8 @@ fn print_with_analysis<'tcx, 'a: 'tcx>(sess: &'a Session,
print_flowgraph(variants, tcx, code, mode, out) print_flowgraph(variants, tcx, code, mode, out)
} }
None => { None => {
let message = format!("--pretty=flowgraph needs block, fn, or method; got \ let message = format!("--pretty=flowgraph needs block, fn, or method; \
{:?}", got {:?}",
node); node);
// Point to what was found, if there's an accessible span. // Point to what was found, if there's an accessible span.
@@ -1004,7 +1014,9 @@ fn print_with_analysis<'tcx, 'a: 'tcx>(sess: &'a Session,
} }
_ => unreachable!(), _ => unreachable!(),
} }
}), sess).unwrap(); }),
sess)
.unwrap();
write_output(out, ofile); write_output(out, ofile);
} }

View File

@@ -20,26 +20,11 @@ use libc::c_char;
// detection code will walk past the end of the feature array, // detection code will walk past the end of the feature array,
// leading to crashes. // leading to crashes.
const ARM_WHITELIST: &'static [&'static str] = &[ const ARM_WHITELIST: &'static [&'static str] = &["neon\0", "vfp2\0", "vfp3\0", "vfp4\0"];
"neon\0",
"vfp2\0",
"vfp3\0",
"vfp4\0",
];
const X86_WHITELIST: &'static [&'static str] = &[ const X86_WHITELIST: &'static [&'static str] = &["avx\0", "avx2\0", "bmi\0", "bmi2\0", "sse\0",
"avx\0", "sse2\0", "sse3\0", "sse4.1\0", "sse4.2\0",
"avx2\0", "ssse3\0", "tbm\0"];
"bmi\0",
"bmi2\0",
"sse\0",
"sse2\0",
"sse3\0",
"sse4.1\0",
"sse4.2\0",
"ssse3\0",
"tbm\0",
];
/// Add `target_feature = "..."` cfgs for a variety of platform /// Add `target_feature = "..."` cfgs for a variety of platform
/// specific features (SSE, NEON etc.). /// specific features (SSE, NEON etc.).
@@ -59,7 +44,7 @@ pub fn add_configuration(cfg: &mut ast::CrateConfig, sess: &Session) {
for feat in whitelist { for feat in whitelist {
assert_eq!(feat.chars().last(), Some('\0')); assert_eq!(feat.chars().last(), Some('\0'));
if unsafe { LLVMRustHasFeature(target_machine, feat.as_ptr() as *const c_char) } { if unsafe { LLVMRustHasFeature(target_machine, feat.as_ptr() as *const c_char) } {
cfg.push(attr::mk_name_value_item_str(tf.clone(), intern(&feat[..feat.len()-1]))) cfg.push(attr::mk_name_value_item_str(tf.clone(), intern(&feat[..feat.len() - 1])))
} }
} }
} }

View File

@@ -40,7 +40,7 @@ use syntax_pos::DUMMY_SP;
use rustc::hir; use rustc::hir;
struct Env<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { struct Env<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
infcx: &'a infer::InferCtxt<'a, 'gcx, 'tcx>, infcx: &'a infer::InferCtxt<'a, 'gcx, 'tcx>,
} }
@@ -86,8 +86,7 @@ impl Emitter for ExpectErrorEmitter {
fn errors(msgs: &[&str]) -> (Box<Emitter + Send>, usize) { fn errors(msgs: &[&str]) -> (Box<Emitter + Send>, usize) {
let v = msgs.iter().map(|m| m.to_string()).collect(); let v = msgs.iter().map(|m| m.to_string()).collect();
(box ExpectErrorEmitter { messages: v } as Box<Emitter + Send>, (box ExpectErrorEmitter { messages: v } as Box<Emitter + Send>, msgs.len())
msgs.len())
} }
fn test_env<F>(source_string: &str, fn test_env<F>(source_string: &str,
@@ -103,8 +102,12 @@ fn test_env<F>(source_string: &str,
let dep_graph = DepGraph::new(false); let dep_graph = DepGraph::new(false);
let _ignore = dep_graph.in_ignore(); let _ignore = dep_graph.in_ignore();
let cstore = Rc::new(CStore::new(&dep_graph)); let cstore = Rc::new(CStore::new(&dep_graph));
let sess = session::build_session_(options, &dep_graph, None, diagnostic_handler, let sess = session::build_session_(options,
Rc::new(CodeMap::new()), cstore.clone()); &dep_graph,
None,
diagnostic_handler,
Rc::new(CodeMap::new()),
cstore.clone());
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess)); rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
let input = config::Input::Str { let input = config::Input::Str {
name: driver::anon_src(), name: driver::anon_src(),
@@ -112,9 +115,15 @@ fn test_env<F>(source_string: &str,
}; };
let krate = driver::phase_1_parse_input(&sess, &input).unwrap(); let krate = driver::phase_1_parse_input(&sess, &input).unwrap();
let driver::ExpansionResult { defs, resolutions, mut hir_forest, .. } = { let driver::ExpansionResult { defs, resolutions, mut hir_forest, .. } = {
driver::phase_2_configure_and_expand( driver::phase_2_configure_and_expand(&sess,
&sess, &cstore, krate, None, "test", None, MakeGlobMap::No, |_| Ok(()), &cstore,
).expect("phase 2 aborted") krate,
None,
"test",
None,
MakeGlobMap::No,
|_| Ok(()))
.expect("phase 2 aborted")
}; };
let _ignore = dep_graph.in_ignore(); let _ignore = dep_graph.in_ignore();
@@ -167,14 +176,22 @@ impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> {
let node = ast::NodeId::from_u32; let node = ast::NodeId::from_u32;
let dscope = self.infcx let dscope = self.infcx
.tcx .tcx
.region_maps .region_maps
.intern_code_extent(CodeExtentData::DestructionScope(node(1)), .intern_code_extent(CodeExtentData::DestructionScope(node(1)),
region::ROOT_CODE_EXTENT); region::ROOT_CODE_EXTENT);
self.create_region_hierarchy(&RH { self.create_region_hierarchy(&RH {
id: node(1), id: node(1),
sub: &[RH { id: node(10), sub: &[] }, RH { id: node(11), sub: &[] }], sub: &[RH {
}, dscope); id: node(10),
sub: &[],
},
RH {
id: node(11),
sub: &[],
}],
},
dscope);
} }
#[allow(dead_code)] // this seems like it could be useful, even if we don't use it now #[allow(dead_code)] // this seems like it could be useful, even if we don't use it now
@@ -213,22 +230,16 @@ impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> {
hir::ItemStatic(..) | hir::ItemStatic(..) |
hir::ItemFn(..) | hir::ItemFn(..) |
hir::ItemForeignMod(..) | hir::ItemForeignMod(..) |
hir::ItemTy(..) => { hir::ItemTy(..) => None,
None
}
hir::ItemEnum(..) | hir::ItemEnum(..) |
hir::ItemStruct(..) | hir::ItemStruct(..) |
hir::ItemUnion(..) | hir::ItemUnion(..) |
hir::ItemTrait(..) | hir::ItemTrait(..) |
hir::ItemImpl(..) | hir::ItemImpl(..) |
hir::ItemDefaultImpl(..) => { hir::ItemDefaultImpl(..) => None,
None
}
hir::ItemMod(ref m) => { hir::ItemMod(ref m) => search_mod(this, m, idx, names),
search_mod(this, m, idx, names)
}
}; };
} }
} }
@@ -281,10 +292,7 @@ impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> {
self.infcx.tcx.mk_param(index, token::intern(&name[..])) self.infcx.tcx.mk_param(index, token::intern(&name[..]))
} }
pub fn re_early_bound(&self, pub fn re_early_bound(&self, index: u32, name: &'static str) -> &'tcx ty::Region {
index: u32,
name: &'static str)
-> &'tcx ty::Region {
let name = token::intern(name); let name = token::intern(name);
self.infcx.tcx.mk_region(ty::ReEarlyBound(ty::EarlyBoundRegion { self.infcx.tcx.mk_region(ty::ReEarlyBound(ty::EarlyBoundRegion {
index: index, index: index,
@@ -292,7 +300,9 @@ impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> {
})) }))
} }
pub fn re_late_bound_with_debruijn(&self, id: u32, debruijn: ty::DebruijnIndex) pub fn re_late_bound_with_debruijn(&self,
id: u32,
debruijn: ty::DebruijnIndex)
-> &'tcx ty::Region { -> &'tcx ty::Region {
self.infcx.tcx.mk_region(ty::ReLateBound(debruijn, ty::BrAnon(id))) self.infcx.tcx.mk_region(ty::ReLateBound(debruijn, ty::BrAnon(id)))
} }
@@ -394,9 +404,7 @@ impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> {
self.assert_eq(t, t_lub); self.assert_eq(t, t_lub);
} }
Err(ref e) => { Err(ref e) => panic!("unexpected error in LUB: {}", e),
panic!("unexpected error in LUB: {}", e)
}
} }
} }
@@ -404,9 +412,7 @@ impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> {
pub fn check_glb(&self, t1: Ty<'tcx>, t2: Ty<'tcx>, t_glb: Ty<'tcx>) { pub fn check_glb(&self, t1: Ty<'tcx>, t2: Ty<'tcx>, t_glb: Ty<'tcx>) {
debug!("check_glb(t1={}, t2={}, t_glb={})", t1, t2, t_glb); debug!("check_glb(t1={}, t2={}, t_glb={})", t1, t2, t_glb);
match self.glb(t1, t2) { match self.glb(t1, t2) {
Err(e) => { Err(e) => panic!("unexpected error computing LUB: {:?}", e),
panic!("unexpected error computing LUB: {:?}", e)
}
Ok(InferOk { obligations, value: t }) => { Ok(InferOk { obligations, value: t }) => {
// FIXME(#32730) once obligations are being propagated, assert the right thing. // FIXME(#32730) once obligations are being propagated, assert the right thing.
assert!(obligations.is_empty()); assert!(obligations.is_empty());