Upgrade to rustfmt 0.8.0.

Lots of changes this time.

Worked around what looks like a rustfmt bug in parse_inst_operands where
a large match was nested inside Ok().
This commit is contained in:
Jakob Stoklund Olesen
2017-03-14 10:48:05 -07:00
parent 477fb4d5da
commit 010861d58e
37 changed files with 462 additions and 377 deletions

View File

@@ -26,7 +26,8 @@ fn main() {
// Make sure we rebuild is this build script changes.
// I guess that won't happen if you have non-UTF8 bytes in your path names.
// The `build.py` script prints out its own dependencies.
println!("cargo:rerun-if-changed={}", crate_dir.join("build.rs").to_string_lossy());
println!("cargo:rerun-if-changed={}",
crate_dir.join("build.rs").to_string_lossy());
// Scripts are in `$crate_dir/meta`.
let meta_dir = crate_dir.join("meta");

View File

@@ -191,12 +191,14 @@ impl DominatorTree {
// Get an iterator with just the reachable predecessors to `ebb`.
// Note that during the first pass, `is_reachable` returns false for blocks that haven't
// been visited yet.
let mut reachable_preds =
cfg.get_predecessors(ebb).iter().cloned().filter(|&(ebb, _)| self.is_reachable(ebb));
let mut reachable_preds = cfg.get_predecessors(ebb)
.iter()
.cloned()
.filter(|&(ebb, _)| self.is_reachable(ebb));
// The RPO must visit at least one predecessor before this node.
let mut idom = reachable_preds.next()
.expect("EBB node must have one reachable predecessor");
let mut idom =
reachable_preds.next().expect("EBB node must have one reachable predecessor");
for pred in reachable_preds {
idom = self.common_dominator(idom, pred, layout);

View File

@@ -89,17 +89,17 @@ impl Display for IntCC {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
use self::IntCC::*;
f.write_str(match self {
&Equal => "eq",
&NotEqual => "ne",
&SignedGreaterThan => "sgt",
&SignedGreaterThanOrEqual => "sge",
&SignedLessThan => "slt",
&SignedLessThanOrEqual => "sle",
&UnsignedGreaterThan => "ugt",
&UnsignedGreaterThanOrEqual => "uge",
&UnsignedLessThan => "ult",
&UnsignedLessThanOrEqual => "ule",
})
&Equal => "eq",
&NotEqual => "ne",
&SignedGreaterThan => "sgt",
&SignedGreaterThanOrEqual => "sge",
&SignedLessThan => "slt",
&SignedLessThanOrEqual => "sle",
&UnsignedGreaterThan => "ugt",
&UnsignedGreaterThanOrEqual => "uge",
&UnsignedLessThan => "ult",
&UnsignedLessThanOrEqual => "ule",
})
}
}
@@ -220,21 +220,21 @@ impl Display for FloatCC {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
use self::FloatCC::*;
f.write_str(match self {
&Ordered => "ord",
&Unordered => "uno",
&Equal => "eq",
&NotEqual => "ne",
&OrderedNotEqual => "one",
&UnorderedOrEqual => "ueq",
&LessThan => "lt",
&LessThanOrEqual => "le",
&GreaterThan => "gt",
&GreaterThanOrEqual => "ge",
&UnorderedOrLessThan => "ult",
&UnorderedOrLessThanOrEqual => "ule",
&UnorderedOrGreaterThan => "ugt",
&UnorderedOrGreaterThanOrEqual => "uge",
})
&Ordered => "ord",
&Unordered => "uno",
&Equal => "eq",
&NotEqual => "ne",
&OrderedNotEqual => "one",
&UnorderedOrEqual => "ueq",
&LessThan => "lt",
&LessThanOrEqual => "le",
&GreaterThan => "gt",
&GreaterThanOrEqual => "ge",
&UnorderedOrLessThan => "ult",
&UnorderedOrLessThanOrEqual => "ule",
&UnorderedOrGreaterThan => "ugt",
&UnorderedOrGreaterThanOrEqual => "uge",
})
}
}

View File

@@ -180,19 +180,20 @@ impl DataFlowGraph {
for _ in 0..self.insts.len() {
v = self.resolve_aliases(match v.expand() {
Direct(inst) => {
match self[inst] {
InstructionData::Unary { opcode, arg, .. } => {
match opcode {
Opcode::Copy | Opcode::Spill | Opcode::Fill => arg,
_ => return v,
}
}
_ => return v,
}
}
_ => return v,
});
Direct(inst) => {
match self[inst] {
InstructionData::Unary { opcode, arg, .. } => {
match opcode {
Opcode::Copy | Opcode::Spill |
Opcode::Fill => arg,
_ => return v,
}
}
_ => return v,
}
}
_ => return v,
});
}
panic!("Copy loop detected for {}", value);
}
@@ -361,11 +362,11 @@ impl DataFlowGraph {
for res_idx in (0..var_results).rev() {
if let Some(ty) = first_type {
head = Some(self.make_value(ValueData::Inst {
ty: ty,
num: (total_results - rev_num) as u16,
inst: inst,
next: head.into(),
}));
ty: ty,
num: (total_results - rev_num) as u16,
inst: inst,
next: head.into(),
}));
rev_num += 1;
}
first_type = Some(self.signatures[sig].return_types[res_idx].value_type);
@@ -376,11 +377,11 @@ impl DataFlowGraph {
for res_idx in (0..fixed_results).rev() {
if let Some(ty) = first_type {
head = Some(self.make_value(ValueData::Inst {
ty: ty,
num: (total_results - rev_num) as u16,
inst: inst,
next: head.into(),
}));
ty: ty,
num: (total_results - rev_num) as u16,
inst: inst,
next: head.into(),
}));
rev_num += 1;
}
first_type = Some(constraints.result_type(res_idx, ctrl_typevar));
@@ -474,11 +475,11 @@ impl DataFlowGraph {
// Not a fixed result, try to extract a return type from the call signature.
self.call_signature(inst).and_then(|sigref| {
self.signatures[sigref]
.return_types
.get(result_idx - fixed_results)
.map(|&arg| arg.value_type)
})
self.signatures[sigref]
.return_types
.get(result_idx - fixed_results)
.map(|&arg| arg.value_type)
})
}
}
@@ -523,11 +524,11 @@ impl DataFlowGraph {
/// Append an argument with type `ty` to `ebb`.
pub fn append_ebb_arg(&mut self, ebb: Ebb, ty: Type) -> Value {
let val = self.make_value(ValueData::Arg {
ty: ty,
ebb: ebb,
num: 0,
next: None.into(),
});
ty: ty,
ebb: ebb,
num: 0,
next: None.into(),
});
self.put_ebb_arg(ebb, val);
val
}

View File

@@ -50,9 +50,11 @@ impl Signature {
let bytes = self.argument_types
.iter()
.filter_map(|arg| match arg.location {
ArgumentLoc::Stack(offset) => Some(offset + arg.value_type.bits() as u32 / 8),
_ => None,
})
ArgumentLoc::Stack(offset) => {
Some(offset + arg.value_type.bits() as u32 / 8)
}
_ => None,
})
.fold(0, cmp::max);
self.argument_bytes = Some(bytes);
}

View File

@@ -252,20 +252,20 @@ fn parse_float(s: &str, w: u8, t: u8) -> Result<u64, &'static str> {
if s2.starts_with("NaN:0x") {
// Quiet NaN with payload.
return match u64::from_str_radix(&s2[6..], 16) {
Ok(payload) if payload < quiet_bit => {
Ok(sign_bit | max_e_bits | quiet_bit | payload)
}
_ => Err("Invalid NaN payload"),
};
Ok(payload) if payload < quiet_bit => {
Ok(sign_bit | max_e_bits | quiet_bit | payload)
}
_ => Err("Invalid NaN payload"),
};
}
if s2.starts_with("sNaN:0x") {
// Signaling NaN with payload.
return match u64::from_str_radix(&s2[7..], 16) {
Ok(payload) if 0 < payload && payload < quiet_bit => {
Ok(sign_bit | max_e_bits | payload)
}
_ => Err("Invalid sNaN payload"),
};
Ok(payload) if 0 < payload && payload < quiet_bit => {
Ok(sign_bit | max_e_bits | payload)
}
_ => Err("Invalid sNaN payload"),
};
}
return Err("Float must be hexadecimal");

View File

@@ -66,7 +66,10 @@ impl JumpTableData {
///
/// This returns an iterator that skips any empty slots in the table.
pub fn entries<'a>(&'a self) -> Entries {
Entries(self.table.iter().cloned().enumerate())
Entries(self.table
.iter()
.cloned()
.enumerate())
}
/// Access the whole table as a mutable slice.
@@ -101,7 +104,10 @@ impl Display for JumpTableData {
Some(first) => write!(fmt, "jump_table {}", first)?,
}
for dest in self.table.iter().skip(1).map(|e| e.expand()) {
for dest in self.table
.iter()
.skip(1)
.map(|e| e.expand()) {
match dest {
None => write!(fmt, ", 0")?,
Some(ebb) => write!(fmt, ", {}", ebb)?,

View File

@@ -125,10 +125,7 @@ impl Layout {
/// Get the last sequence number in `ebb`.
fn last_ebb_seq(&self, ebb: Ebb) -> SequenceNumber {
// Get the seq of the last instruction if it exists, otherwise use the EBB header seq.
self.ebbs[ebb]
.last_inst
.map(|inst| self.insts[inst].seq)
.unwrap_or(self.ebbs[ebb].seq)
self.ebbs[ebb].last_inst.map(|inst| self.insts[inst].seq).unwrap_or(self.ebbs[ebb].seq)
}
/// Assign a valid sequence number to `ebb` such that the numbers are still monotonic. This may
@@ -439,8 +436,8 @@ impl Layout {
/// Insert `inst` before the instruction `before` in the same EBB.
pub fn insert_inst(&mut self, inst: Inst, before: Inst) {
assert_eq!(self.inst_ebb(inst), None);
let ebb = self.inst_ebb(before)
.expect("Instruction before insertion point not in the layout");
let ebb =
self.inst_ebb(before).expect("Instruction before insertion point not in the layout");
let after = self.insts[before].prev;
{
let inst_node = self.insts.ensure(inst);
@@ -488,8 +485,8 @@ impl Layout {
/// i4
/// ```
pub fn split_ebb(&mut self, new_ebb: Ebb, before: Inst) {
let old_ebb = self.inst_ebb(before)
.expect("The `before` instruction must be in the layout");
let old_ebb =
self.inst_ebb(before).expect("The `before` instruction must be in the layout");
assert!(!self.is_ebb_inserted(new_ebb));
// Insert new_ebb after old_ebb.

View File

@@ -348,7 +348,12 @@ mod tests {
assert_eq!(big.bits(), 64 * 256);
assert_eq!(big.half_vector().unwrap().to_string(), "f64x128");
assert_eq!(B1.by(2).unwrap().half_vector().unwrap().to_string(), "b1");
assert_eq!(B1.by(2)
.unwrap()
.half_vector()
.unwrap()
.to_string(),
"b1");
assert_eq!(I32.half_vector(), None);
assert_eq!(VOID.half_vector(), None);
@@ -378,7 +383,12 @@ mod tests {
assert_eq!(B1.by(8).unwrap().to_string(), "b1x8");
assert_eq!(B8.by(1).unwrap().to_string(), "b8");
assert_eq!(B16.by(256).unwrap().to_string(), "b16x256");
assert_eq!(B32.by(4).unwrap().by(2).unwrap().to_string(), "b32x8");
assert_eq!(B32.by(4)
.unwrap()
.by(2)
.unwrap()
.to_string(),
"b32x8");
assert_eq!(B64.by(8).unwrap().to_string(), "b64x8");
assert_eq!(I8.by(64).unwrap().to_string(), "i8x64");
assert_eq!(F64.by(2).unwrap().to_string(), "f64x2");

View File

@@ -34,10 +34,10 @@ fn isa_constructor(shared_flags: shared_settings::Flags,
&enc_tables::LEVEL1_A32[..]
};
Box::new(Isa {
isa_flags: settings::Flags::new(&shared_flags, builder),
shared_flags: shared_flags,
cpumode: level1,
})
isa_flags: settings::Flags::new(&shared_flags, builder),
shared_flags: shared_flags,
cpumode: level1,
})
}
impl TargetIsa for Isa {
@@ -58,13 +58,13 @@ impl TargetIsa for Isa {
inst.opcode(),
self.cpumode,
&enc_tables::LEVEL2[..])
.and_then(|enclist_offset| {
general_encoding(enclist_offset,
&enc_tables::ENCLISTS[..],
|instp| enc_tables::check_instp(inst, instp),
|isap| self.isa_flags.numbered_predicate(isap as usize))
.ok_or(Legalize::Expand)
})
.and_then(|enclist_offset| {
general_encoding(enclist_offset,
&enc_tables::ENCLISTS[..],
|instp| enc_tables::check_instp(inst, instp),
|isap| self.isa_flags.numbered_predicate(isap as usize))
.ok_or(Legalize::Expand)
})
}
fn recipe_names(&self) -> &'static [&'static str] {

View File

@@ -28,9 +28,9 @@ fn isa_constructor(shared_flags: shared_settings::Flags,
builder: &shared_settings::Builder)
-> Box<TargetIsa> {
Box::new(Isa {
isa_flags: settings::Flags::new(&shared_flags, builder),
shared_flags: shared_flags,
})
isa_flags: settings::Flags::new(&shared_flags, builder),
shared_flags: shared_flags,
})
}
impl TargetIsa for Isa {
@@ -51,13 +51,13 @@ impl TargetIsa for Isa {
inst.opcode(),
&enc_tables::LEVEL1_A64[..],
&enc_tables::LEVEL2[..])
.and_then(|enclist_offset| {
general_encoding(enclist_offset,
&enc_tables::ENCLISTS[..],
|instp| enc_tables::check_instp(inst, instp),
|isap| self.isa_flags.numbered_predicate(isap as usize))
.ok_or(Legalize::Expand)
})
.and_then(|enclist_offset| {
general_encoding(enclist_offset,
&enc_tables::ENCLISTS[..],
|instp| enc_tables::check_instp(inst, instp),
|isap| self.isa_flags.numbered_predicate(isap as usize))
.ok_or(Legalize::Expand)
})
}
fn recipe_names(&self) -> &'static [&'static str] {

View File

@@ -34,10 +34,10 @@ fn isa_constructor(shared_flags: shared_settings::Flags,
&enc_tables::LEVEL1_I32[..]
};
Box::new(Isa {
isa_flags: settings::Flags::new(&shared_flags, builder),
shared_flags: shared_flags,
cpumode: level1,
})
isa_flags: settings::Flags::new(&shared_flags, builder),
shared_flags: shared_flags,
cpumode: level1,
})
}
impl TargetIsa for Isa {
@@ -58,13 +58,13 @@ impl TargetIsa for Isa {
inst.opcode(),
self.cpumode,
&enc_tables::LEVEL2[..])
.and_then(|enclist_offset| {
general_encoding(enclist_offset,
&enc_tables::ENCLISTS[..],
|instp| enc_tables::check_instp(inst, instp),
|isap| self.isa_flags.numbered_predicate(isap as usize))
.ok_or(Legalize::Expand)
})
.and_then(|enclist_offset| {
general_encoding(enclist_offset,
&enc_tables::ENCLISTS[..],
|instp| enc_tables::check_instp(inst, instp),
|isap| self.isa_flags.numbered_predicate(isap as usize))
.ok_or(Legalize::Expand)
})
}
fn recipe_names(&self) -> &'static [&'static str] {

View File

@@ -67,10 +67,10 @@ impl RegBank {
}
}
.and_then(|offset| if offset < self.units {
Some(offset + self.first_unit)
} else {
None
})
Some(offset + self.first_unit)
} else {
None
})
}
/// Write `regunit` to `w`, assuming that it belongs to this bank.
@@ -199,7 +199,10 @@ impl RegInfo {
/// Try to parse a regunit name. The name is not expected to begin with `%`.
pub fn parse_regunit(&self, name: &str) -> Option<RegUnit> {
self.banks.iter().filter_map(|b| b.parse_regunit(name)).next()
self.banks
.iter()
.filter_map(|b| b.parse_regunit(name))
.next()
}
/// Make a temporary object that can display a register unit.

View File

@@ -35,10 +35,10 @@ fn isa_constructor(shared_flags: shared_settings::Flags,
&enc_tables::LEVEL1_RV32[..]
};
Box::new(Isa {
isa_flags: settings::Flags::new(&shared_flags, builder),
shared_flags: shared_flags,
cpumode: level1,
})
isa_flags: settings::Flags::new(&shared_flags, builder),
shared_flags: shared_flags,
cpumode: level1,
})
}
impl TargetIsa for Isa {
@@ -59,13 +59,13 @@ impl TargetIsa for Isa {
inst.opcode(),
self.cpumode,
&enc_tables::LEVEL2[..])
.and_then(|enclist_offset| {
general_encoding(enclist_offset,
&enc_tables::ENCLISTS[..],
|instp| enc_tables::check_instp(inst, instp),
|isap| self.isa_flags.numbered_predicate(isap as usize))
.ok_or(Legalize::Expand)
})
.and_then(|enclist_offset| {
general_encoding(enclist_offset,
&enc_tables::ENCLISTS[..],
|instp| enc_tables::check_instp(inst, instp),
|isap| self.isa_flags.numbered_predicate(isap as usize))
.ok_or(Legalize::Expand)
})
}
fn recipe_names(&self) -> &'static [&'static str] {

View File

@@ -35,7 +35,10 @@ mod tests {
fn check(x: &[u32], want: &[u32]) {
assert_eq!(x.len(), want.len());
let want_count = want.iter().cloned().filter(|&x| x % 10 == 0).count();
let want_count = want.iter()
.cloned()
.filter(|&x| x % 10 == 0)
.count();
let mut v = Vec::new();
v.extend(x.iter().cloned());
let count = partition_slice(&mut v[..], |&x| x % 10 == 0);

View File

@@ -118,21 +118,21 @@ mod tests {
// Register classes for testing.
const GPR: RegClass = &RegClassData {
name: "GPR",
index: 0,
width: 1,
first: 28,
subclasses: 0,
mask: [0xf0000000, 0x0000000f, 0],
};
name: "GPR",
index: 0,
width: 1,
first: 28,
subclasses: 0,
mask: [0xf0000000, 0x0000000f, 0],
};
const DPR: RegClass = &RegClassData {
name: "DPR",
index: 0,
width: 2,
first: 28,
subclasses: 0,
mask: [0x50000000, 0x0000000a, 0],
};
name: "DPR",
index: 0,
width: 2,
first: 28,
subclasses: 0,
mask: [0x50000000, 0x0000000a, 0],
};
#[test]
fn put_and_take() {

View File

@@ -200,7 +200,10 @@ impl<'a> Context<'a> {
for lv in liveins {
let value = lv.value;
let affinity = self.liveness.get(value).expect("No live range for live-in").affinity;
let affinity = self.liveness
.get(value)
.expect("No live range for live-in")
.affinity;
if let Affinity::Reg(rc_index) = affinity {
let regclass = self.reginfo.rc(rc_index);
match func.locations[value] {

View File

@@ -69,10 +69,10 @@ impl LiveValueVec {
/// Add a new live value to `values`.
fn push(&mut self, value: Value, endpoint: Inst, affinity: Affinity) {
self.values.push(LiveValue {
value: value,
endpoint: endpoint,
affinity: affinity,
});
value: value,
endpoint: endpoint,
affinity: affinity,
});
}
/// Remove all elements.
@@ -167,8 +167,7 @@ impl LiveValueTracker {
self.idom_sets.get(&idom).expect("No stored live set for dominator");
// Get just the values that are live-in to `ebb`.
for &value in idom_live_list.as_slice(&self.idom_pool) {
let lr = liveness.get(value)
.expect("Immediate dominator value has no live range");
let lr = liveness.get(value).expect("Immediate dominator value has no live range");
// Check if this value is live-in here.
if let Some(endpoint) = lr.livein_local_end(ebb, program_order) {
@@ -260,13 +259,16 @@ impl LiveValueTracker {
/// Save the current set of live values so it is associated with `idom`.
fn save_idom_live_set(&mut self, idom: Inst) {
let values = self.live.values.iter().map(|lv| lv.value);
let values = self.live
.values
.iter()
.map(|lv| lv.value);
let pool = &mut self.idom_pool;
// If there already is a set saved for `idom`, just keep it.
self.idom_sets.entry(idom).or_insert_with(|| {
let mut list = ValueList::default();
list.extend(values, pool);
list
});
let mut list = ValueList::default();
list.extend(values, pool);
list
});
}
}

View File

@@ -315,8 +315,10 @@ impl Liveness {
let recipe = func.encodings[inst].recipe();
// Iterator of constraints, one per value operand.
// TODO: Should we fail here if the instruction doesn't have a valid encoding?
let mut operand_constraints =
recipe_constraints.get(recipe).map(|c| c.ins).unwrap_or(&[]).iter();
let mut operand_constraints = recipe_constraints.get(recipe)
.map(|c| c.ins)
.unwrap_or(&[])
.iter();
for &arg in func.dfg[inst].arguments(&func.dfg.value_lists) {
// Get the live range, create it as a dead range if necessary.

View File

@@ -221,16 +221,14 @@ impl LiveRange {
/// Return `Ok(n)` if `liveins[n]` already contains `ebb`.
/// Otherwise, return `Err(n)` with the index where such an interval should be inserted.
fn find_ebb_interval<PO: ProgramOrder>(&self, ebb: Ebb, order: &PO) -> Result<usize, usize> {
self.liveins
.binary_search_by(|intv| order.cmp(intv.begin, ebb))
.or_else(|n| {
// The interval at `n-1` may cover `ebb`.
if n > 0 && order.cmp(self.liveins[n - 1].end, ebb) == Ordering::Greater {
Ok(n - 1)
} else {
Err(n)
}
})
self.liveins.binary_search_by(|intv| order.cmp(intv.begin, ebb)).or_else(|n| {
// The interval at `n-1` may cover `ebb`.
if n > 0 && order.cmp(self.liveins[n - 1].end, ebb) == Ordering::Greater {
Ok(n - 1)
} else {
Err(n)
}
})
}
/// Extend the local interval for `ebb` so it reaches `to` which must belong to `ebb`.

View File

@@ -157,9 +157,8 @@ impl<'a> Verifier<'a> {
let fixed_results = inst_data.opcode().constraints().fixed_results();
// var_results is 0 if we aren't a call instruction
let var_results = dfg.call_signature(inst)
.map(|sig| dfg.signatures[sig].return_types.len())
.unwrap_or(0);
let var_results =
dfg.call_signature(inst).map(|sig| dfg.signatures[sig].return_types.len()).unwrap_or(0);
let total_results = fixed_results + var_results;
if total_results == 0 {
@@ -247,7 +246,10 @@ impl<'a> Verifier<'a> {
}
fn verify_sig_ref(&self, inst: Inst, s: SigRef) -> Result<()> {
if !self.func.dfg.signatures.is_valid(s) {
if !self.func
.dfg
.signatures
.is_valid(s) {
err!(inst, "invalid signature reference {}", s)
} else {
Ok(())
@@ -255,7 +257,10 @@ impl<'a> Verifier<'a> {
}
fn verify_func_ref(&self, inst: Inst, f: FuncRef) -> Result<()> {
if !self.func.dfg.ext_funcs.is_valid(f) {
if !self.func
.dfg
.ext_funcs
.is_valid(f) {
err!(inst, "invalid function reference {}", f)
} else {
Ok(())
@@ -330,9 +335,9 @@ mod tests {
let ebb0 = func.dfg.make_ebb();
func.layout.append_ebb(ebb0);
let nullary_with_bad_opcode = func.dfg.make_inst(InstructionData::Nullary {
opcode: Opcode::Jump,
ty: types::VOID,
});
opcode: Opcode::Jump,
ty: types::VOID,
});
func.layout.append_inst(nullary_with_bad_opcode, ebb0);
let verifier = Verifier::new(&func);
assert_err_with_msg!(verifier.run(), "instruction format");

View File

@@ -188,7 +188,11 @@ fn write_instruction(w: &mut Write,
for r in func.dfg.inst_results(inst) {
write!(s,
",{}",
func.locations.get(r).cloned().unwrap_or_default().display(&regs))?
func.locations
.get(r)
.cloned()
.unwrap_or_default()
.display(&regs))?
}
}
write!(s, "]")?;