Update to rustfmt-preview (#348)

* Update to rustfmt-preview.

* Run "cargo fmt --all" with rustfmt 0.4.1.

rustfmt 0.4.1 is the latest release of rustfmt-preview available on the
stable channel.

* Fix a long line that rustfmt 0.4.1 can't handle.

* Remove unneeded commas left behind by rustfmt.
This commit is contained in:
Dan Gohman
2018-05-25 11:38:38 -07:00
committed by GitHub
parent 99f6055c55
commit 6b88cd44a8
137 changed files with 1914 additions and 2380 deletions

View File

@@ -47,9 +47,7 @@ impl ConcurrentRunner {
heartbeat_thread(reply_tx.clone());
let handles = (0..num_cpus::get())
.map(|num| {
worker_thread(num, request_mutex.clone(), reply_tx.clone())
})
.map(|num| worker_thread(num, request_mutex.clone(), reply_tx.clone()))
.collect();
Self {
@@ -101,8 +99,10 @@ impl ConcurrentRunner {
fn heartbeat_thread(replies: Sender<Reply>) -> thread::JoinHandle<()> {
thread::Builder::new()
.name("heartbeat".to_string())
.spawn(move || while replies.send(Reply::Tick).is_ok() {
thread::sleep(Duration::from_secs(1));
.spawn(move || {
while replies.send(Reply::Tick).is_ok() {
thread::sleep(Duration::from_secs(1));
}
})
.unwrap()
}

View File

@@ -9,14 +9,9 @@
type_complexity,
// Rustfmt 0.9.0 is at odds with this lint:
block_in_if_condition_stmt))]
#![cfg_attr(feature="cargo-clippy", warn(
mut_mut,
nonminimal_bool,
option_map_unwrap_or,
option_map_unwrap_or_else,
unicode_not_nfc,
use_self,
))]
#![cfg_attr(feature = "cargo-clippy",
warn(mut_mut, nonminimal_bool, option_map_unwrap_or, option_map_unwrap_or_else,
unicode_not_nfc, use_self))]
#[macro_use(dbg)]
extern crate cretonne_codegen;

View File

@@ -40,15 +40,13 @@ impl Display for QueueEntry {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let p = self.path.to_string_lossy();
match self.state {
State::Done(Ok(dur)) => {
write!(
f,
"{}.{:03} {}",
dur.as_secs(),
dur.subsec_nanos() / 1_000_000,
p
)
}
State::Done(Ok(dur)) => write!(
f,
"{}.{:03} {}",
dur.as_secs(),
dur.subsec_nanos() / 1_000_000,
p
),
State::Done(Err(ref e)) => write!(f, "FAIL {}: {}", p, e),
_ => write!(f, "{}", p),
}
@@ -180,7 +178,11 @@ impl TestRunner {
/// Report on the next in-order job, if it's done.
fn report_job(&self) -> bool {
let jobid = self.reported_tests;
if let Some(&QueueEntry { state: State::Done(ref result), .. }) = self.tests.get(jobid) {
if let Some(&QueueEntry {
state: State::Done(ref result),
..
}) = self.tests.get(jobid)
{
if self.verbose || result.is_err() {
println!("{}", self.tests[jobid]);
}
@@ -283,7 +285,10 @@ impl TestRunner {
let mut times = self.tests
.iter()
.filter_map(|entry| match *entry {
QueueEntry { state: State::Done(Ok(dur)), .. } => Some(dur),
QueueEntry {
state: State::Done(Ok(dur)),
..
} => Some(dur),
_ => None,
})
.collect::<Vec<_>>();
@@ -312,10 +317,12 @@ impl TestRunner {
}
for t in self.tests.iter().filter(|entry| match **entry {
QueueEntry { state: State::Done(Ok(dur)), .. } => dur > cut,
QueueEntry {
state: State::Done(Ok(dur)),
..
} => dur > cut,
_ => false,
})
{
}) {
println!("slow: {}", t)
}
}

View File

@@ -129,15 +129,11 @@ fn run_one_test<'a>(
// Should we run the verifier before this test?
if !context.verified && test.needs_verifier() {
verify_function(&func, context.flags_or_isa()).map_err(
|e| {
pretty_verifier_error(&func, isa, &e)
},
)?;
verify_function(&func, context.flags_or_isa())
.map_err(|e| pretty_verifier_error(&func, isa, &e))?;
context.verified = true;
}
test.run(func, context).map_err(
|e| format!("{}: {}", name, e),
)
test.run(func, context)
.map_err(|e| format!("{}: {}", name, e))
}

View File

@@ -70,16 +70,16 @@ pub trait SubTest {
/// Run filecheck on `text`, using directives extracted from `context`.
pub fn run_filecheck(text: &str, context: &Context) -> Result<()> {
let checker = build_filechecker(context)?;
if checker.check(text, NO_VARIABLES).map_err(|e| {
format!("filecheck: {}", e)
})?
if checker
.check(text, NO_VARIABLES)
.map_err(|e| format!("filecheck: {}", e))?
{
Ok(())
} else {
// Filecheck mismatch. Emit an explanation as output.
let (_, explain) = checker.explain(text, NO_VARIABLES).map_err(|e| {
format!("explain: {}", e)
})?;
let (_, explain) = checker
.explain(text, NO_VARIABLES)
.map_err(|e| format!("explain: {}", e))?;
Err(format!("filecheck failed:\n{}{}", checker, explain))
}
}
@@ -89,14 +89,14 @@ pub fn build_filechecker(context: &Context) -> Result<Checker> {
let mut builder = CheckerBuilder::new();
// Preamble comments apply to all functions.
for comment in context.preamble_comments {
builder.directive(comment.text).map_err(|e| {
format!("filecheck: {}", e)
})?;
builder
.directive(comment.text)
.map_err(|e| format!("filecheck: {}", e))?;
}
for comment in &context.details.comments {
builder.directive(comment.text).map_err(|e| {
format!("filecheck: {}", e)
})?;
builder
.directive(comment.text)
.map_err(|e| format!("filecheck: {}", e))?;
}
Ok(builder.finish())
}

View File

@@ -138,9 +138,9 @@ impl SubTest for TestBinEmit {
&func.dfg[inst],
func.dfg.ctrl_typevar(inst),
).filter(|e| {
let recipe_constraints = &encinfo.constraints[e.recipe()];
recipe_constraints.satisfied(inst, &divert, &func)
});
let recipe_constraints = &encinfo.constraints[e.recipe()];
recipe_constraints.satisfied(inst, &divert, &func)
});
if opt_level == OptLevel::Best {
// Get the smallest legal encoding
@@ -149,8 +149,7 @@ impl SubTest for TestBinEmit {
// If not optimizing, just use the first encoding.
legal_encodings.next()
}
}
{
} {
func.encodings[inst] = enc;
}
}
@@ -159,9 +158,8 @@ impl SubTest for TestBinEmit {
}
// Relax branches and compute EBB offsets based on the encodings.
let code_size = binemit::relax_branches(&mut func, isa).map_err(|e| {
pretty_error(&func, context.isa, e)
})?;
let code_size = binemit::relax_branches(&mut func, isa)
.map_err(|e| pretty_error(&func, context.isa, e))?;
// Collect all of the 'bin:' directives on instructions.
let mut bins = HashMap::new();
@@ -181,8 +179,7 @@ impl SubTest for TestBinEmit {
_ => {
return Err(format!(
"'bin:' directive on non-inst {}: {}",
comment.entity,
comment.text
comment.entity, comment.text
))
}
}
@@ -198,8 +195,7 @@ impl SubTest for TestBinEmit {
divert.clear();
// Correct header offsets should have been computed by `relax_branches()`.
assert_eq!(
sink.offset,
func.offsets[ebb],
sink.offset, func.offsets[ebb],
"Inconsistent {} header offset",
ebb
);
@@ -211,9 +207,10 @@ impl SubTest for TestBinEmit {
// Send legal encodings into the emitter.
if enc.is_legal() {
// Generate a better error message if output locations are not specified.
if let Some(&v) = func.dfg.inst_results(inst).iter().find(|&&v| {
!func.locations[v].is_assigned()
})
if let Some(&v) = func.dfg
.inst_results(inst)
.iter()
.find(|&&v| !func.locations[v].is_assigned())
{
return Err(format!(
"Missing register/stack slot for {} in {}",
@@ -239,9 +236,10 @@ impl SubTest for TestBinEmit {
if !enc.is_legal() {
// A possible cause of an unencoded instruction is a missing location for
// one of the input operands.
if let Some(&v) = func.dfg.inst_args(inst).iter().find(|&&v| {
!func.locations[v].is_assigned()
})
if let Some(&v) = func.dfg
.inst_args(inst)
.iter()
.find(|&&v| !func.locations[v].is_assigned())
{
return Err(format!(
"Missing register/stack slot for {} in {}",
@@ -287,8 +285,7 @@ impl SubTest for TestBinEmit {
if sink.offset != code_size {
return Err(format!(
"Expected code size {}, got {}",
code_size,
sink.offset
code_size, sink.offset
));
}

View File

@@ -3,8 +3,8 @@
//! The `compile` test command runs each function through the full code generator pipeline
use cretonne_codegen;
use cretonne_codegen::{binemit, ir};
use cretonne_codegen::print_errors::pretty_error;
use cretonne_codegen::{binemit, ir};
use cretonne_reader::TestCommand;
use std::borrow::Cow;
use std::fmt::Write;
@@ -41,9 +41,9 @@ impl SubTest for TestCompile {
let mut comp_ctx = cretonne_codegen::Context::new();
comp_ctx.func = func.into_owned();
let code_size = comp_ctx.compile(isa).map_err(|e| {
pretty_error(&comp_ctx.func, context.isa, e)
})?;
let code_size = comp_ctx
.compile(isa)
.map_err(|e| pretty_error(&comp_ctx.func, context.isa, e))?;
dbg!(
"Generated {} bytes of code:\n{}",
@@ -62,15 +62,13 @@ impl SubTest for TestCompile {
if sink.offset != code_size {
return Err(format!(
"Expected code size {}, got {}",
code_size,
sink.offset
code_size, sink.offset
));
}
// Run final code through filecheck.
let mut text = String::new();
write!(&mut text, "{}", &comp_ctx.func.display(Some(isa)))
.map_err(|e| e.to_string())?;
write!(&mut text, "{}", &comp_ctx.func.display(Some(isa))).map_err(|e| e.to_string())?;
run_filecheck(&text, context)
}
}

View File

@@ -40,14 +40,12 @@ impl SubTest for TestDCE {
comp_ctx.flowgraph();
comp_ctx.compute_loop_analysis();
comp_ctx.dce(context.flags_or_isa()).map_err(|e| {
pretty_error(&comp_ctx.func, context.isa, Into::into(e))
})?;
comp_ctx
.dce(context.flags_or_isa())
.map_err(|e| pretty_error(&comp_ctx.func, context.isa, Into::into(e)))?;
let mut text = String::new();
write!(&mut text, "{}", &comp_ctx.func).map_err(
|e| e.to_string(),
)?;
write!(&mut text, "{}", &comp_ctx.func).map_err(|e| e.to_string())?;
run_filecheck(&text, context)
}
}

View File

@@ -55,8 +55,7 @@ impl SubTest for TestDomtree {
_ => {
return Err(format!(
"annotation on non-inst {}: {}",
comment.entity,
comment.text
comment.entity, comment.text
))
}
};
@@ -77,17 +76,14 @@ impl SubTest for TestDomtree {
return Err(format!(
"mismatching idoms for {}:\n\
want: {}, got: {}",
src_ebb,
inst,
got_inst
src_ebb, inst, got_inst
));
}
None => {
return Err(format!(
"mismatching idoms for {}:\n\
want: {}, got: unreachable",
src_ebb,
inst
src_ebb, inst
));
}
_ => {}
@@ -98,16 +94,16 @@ impl SubTest for TestDomtree {
// Now we know that everything in `expected` is consistent with `domtree`.
// All other EBB's should be either unreachable or the entry block.
for ebb in func.layout.ebbs().skip(1).filter(
|ebb| !expected.contains_key(ebb),
)
for ebb in func.layout
.ebbs()
.skip(1)
.filter(|ebb| !expected.contains_key(ebb))
{
if let Some(got_inst) = domtree.idom(ebb) {
return Err(format!(
"mismatching idoms for renumbered {}:\n\
want: unrechable, got: {}",
ebb,
got_inst
ebb, got_inst
));
}
}

View File

@@ -41,13 +41,12 @@ impl SubTest for TestLegalizer {
let isa = context.isa.expect("legalizer needs an ISA");
comp_ctx.compute_cfg();
comp_ctx.legalize(isa).map_err(|e| {
pretty_error(&comp_ctx.func, context.isa, e)
})?;
comp_ctx
.legalize(isa)
.map_err(|e| pretty_error(&comp_ctx.func, context.isa, e))?;
let mut text = String::new();
write!(&mut text, "{}", &comp_ctx.func.display(Some(isa)))
.map_err(|e| e.to_string())?;
write!(&mut text, "{}", &comp_ctx.func.display(Some(isa))).map_err(|e| e.to_string())?;
run_filecheck(&text, context)
}
}

View File

@@ -40,14 +40,12 @@ impl SubTest for TestLICM {
comp_ctx.flowgraph();
comp_ctx.compute_loop_analysis();
comp_ctx.licm(context.flags_or_isa()).map_err(|e| {
pretty_error(&comp_ctx.func, context.isa, Into::into(e))
})?;
comp_ctx
.licm(context.flags_or_isa())
.map_err(|e| pretty_error(&comp_ctx.func, context.isa, Into::into(e)))?;
let mut text = String::new();
write!(&mut text, "{}", &comp_ctx.func).map_err(
|e| e.to_string(),
)?;
write!(&mut text, "{}", &comp_ctx.func).map_err(|e| e.to_string())?;
run_filecheck(&text, context)
}
}

View File

@@ -37,14 +37,12 @@ impl SubTest for TestPostopt {
let isa = context.isa.expect("postopt needs an ISA");
comp_ctx.flowgraph();
comp_ctx.postopt(isa).map_err(|e| {
pretty_error(&comp_ctx.func, context.isa, Into::into(e))
})?;
comp_ctx
.postopt(isa)
.map_err(|e| pretty_error(&comp_ctx.func, context.isa, Into::into(e)))?;
let mut text = String::new();
write!(&mut text, "{}", &comp_ctx.func).map_err(
|e| e.to_string(),
)?;
write!(&mut text, "{}", &comp_ctx.func).map_err(|e| e.to_string())?;
run_filecheck(&text, context)
}
}

View File

@@ -37,14 +37,12 @@ impl SubTest for TestPreopt {
let isa = context.isa.expect("preopt needs an ISA");
comp_ctx.flowgraph();
comp_ctx.preopt(isa).map_err(|e| {
pretty_error(&comp_ctx.func, context.isa, Into::into(e))
})?;
comp_ctx
.preopt(isa)
.map_err(|e| pretty_error(&comp_ctx.func, context.isa, Into::into(e)))?;
let mut text = String::new();
write!(&mut text, "{}", &comp_ctx.func).map_err(
|e| e.to_string(),
)?;
write!(&mut text, "{}", &comp_ctx.func).map_err(|e| e.to_string())?;
run_filecheck(&text, context)
}
}

View File

@@ -46,17 +46,16 @@ impl SubTest for TestRegalloc {
comp_ctx.compute_cfg();
// TODO: Should we have an option to skip legalization?
comp_ctx.legalize(isa).map_err(|e| {
pretty_error(&comp_ctx.func, context.isa, e)
})?;
comp_ctx
.legalize(isa)
.map_err(|e| pretty_error(&comp_ctx.func, context.isa, e))?;
comp_ctx.compute_domtree();
comp_ctx.regalloc(isa).map_err(|e| {
pretty_error(&comp_ctx.func, context.isa, e)
})?;
comp_ctx
.regalloc(isa)
.map_err(|e| pretty_error(&comp_ctx.func, context.isa, e))?;
let mut text = String::new();
write!(&mut text, "{}", &comp_ctx.func.display(Some(isa)))
.map_err(|e| e.to_string())?;
write!(&mut text, "{}", &comp_ctx.func.display(Some(isa))).map_err(|e| e.to_string())?;
run_filecheck(&text, context)
}
}

View File

@@ -39,14 +39,12 @@ impl SubTest for TestSimpleGVN {
comp_ctx.func = func.into_owned();
comp_ctx.flowgraph();
comp_ctx.simple_gvn(context.flags_or_isa()).map_err(|e| {
pretty_error(&comp_ctx.func, context.isa, Into::into(e))
})?;
comp_ctx
.simple_gvn(context.flags_or_isa())
.map_err(|e| pretty_error(&comp_ctx.func, context.isa, Into::into(e)))?;
let mut text = String::new();
write!(&mut text, "{}", &comp_ctx.func).map_err(
|e| e.to_string(),
)?;
write!(&mut text, "{}", &comp_ctx.func).map_err(|e| e.to_string())?;
run_filecheck(&text, context)
}
}

View File

@@ -54,29 +54,24 @@ impl SubTest for TestVerifier {
}
match verify_function(func, context.flags_or_isa()) {
Ok(_) => {
match expected {
None => Ok(()),
Some((_, msg)) => Err(format!("passed, expected error: {}", msg)),
}
}
Err(got) => {
match expected {
None => Err(format!("verifier pass, got {}", got)),
Some((want_loc, want_msg)) if got.message.contains(want_msg) => {
if want_loc == got.location {
Ok(())
} else {
Err(format!(
"correct error reported on {}, but wanted {}",
got.location,
want_loc
))
}
Ok(_) => match expected {
None => Ok(()),
Some((_, msg)) => Err(format!("passed, expected error: {}", msg)),
},
Err(got) => match expected {
None => Err(format!("verifier pass, got {}", got)),
Some((want_loc, want_msg)) if got.message.contains(want_msg) => {
if want_loc == got.location {
Ok(())
} else {
Err(format!(
"correct error reported on {}, but wanted {}",
got.location, want_loc
))
}
Some(_) => Err(format!("mismatching error: {}", got)),
}
}
Some(_) => Err(format!("mismatching error: {}", got)),
},
}
}
}