Use Self instead of repeating the type name.

This commit is contained in:
Dan Gohman
2017-11-08 10:40:47 -08:00
parent b7f979a8be
commit 3ab4349c1b
41 changed files with 105 additions and 105 deletions

View File

@@ -35,8 +35,8 @@ struct TextSink {
impl TextSink {
/// Create a new empty TextSink.
pub fn new(isa: &TargetIsa) -> TextSink {
TextSink {
pub fn new(isa: &TargetIsa) -> Self {
Self {
rnames: isa.reloc_names(),
offset: 0,
text: String::new(),

View File

@@ -38,7 +38,7 @@ pub struct ConcurrentRunner {
impl ConcurrentRunner {
/// Create a new `ConcurrentRunner` with threads spun up.
pub fn new() -> ConcurrentRunner {
pub fn new() -> Self {
let (request_tx, request_rx) = channel();
let request_mutex = Arc::new(Mutex::new(request_rx));
let (reply_tx, reply_rx) = channel();
@@ -51,7 +51,7 @@ impl ConcurrentRunner {
})
.collect();
ConcurrentRunner {
Self {
request_tx: Some(request_tx),
reply_rx,
handles,

View File

@@ -81,8 +81,8 @@ pub struct TestRunner {
impl TestRunner {
/// Create a new blank TrstRunner.
pub fn new(verbose: bool) -> TestRunner {
TestRunner {
pub fn new(verbose: bool) -> Self {
Self {
verbose,
dir_stack: Vec::new(),
tests: Vec::new(),

View File

@@ -61,7 +61,7 @@ where
}
/// Construct a BitSet with the half-open range [lo,hi) filled in
pub fn from_range(lo: u8, hi: u8) -> BitSet<T> {
pub fn from_range(lo: u8, hi: u8) -> Self {
assert!(lo <= hi);
assert!((hi as usize) <= Self::bits());
let one: T = T::from(1);

View File

@@ -47,8 +47,8 @@ impl Context {
///
/// The returned instance should be reused for compiling multiple functions in order to avoid
/// needless allocator thrashing.
pub fn new() -> Context {
Context {
pub fn new() -> Self {
Self {
func: Function::new(),
cfg: ControlFlowGraph::new(),
domtree: DominatorTree::new(),

View File

@@ -204,8 +204,8 @@ impl DominatorTree {
impl DominatorTree {
/// Allocate a new blank dominator tree. Use `compute` to compute the dominator tree for a
/// function.
pub fn new() -> DominatorTree {
DominatorTree {
pub fn new() -> Self {
Self {
nodes: EntityMap::new(),
postorder: Vec::new(),
stack: Vec::new(),
@@ -214,8 +214,8 @@ impl DominatorTree {
}
/// Allocate and compute a dominator tree.
pub fn with_function(func: &Function, cfg: &ControlFlowGraph) -> DominatorTree {
let mut domtree = DominatorTree::new();
pub fn with_function(func: &Function, cfg: &ControlFlowGraph) -> Self {
let mut domtree = Self::new();
domtree.compute(func, cfg);
domtree
}

View File

@@ -12,8 +12,8 @@ pub struct Keys<K: EntityRef> {
impl<K: EntityRef> Keys<K> {
/// Create a `Keys` iterator that visits `count` entities starting from 0.
pub fn new(count: usize) -> Keys<K> {
Keys {
pub fn new(count: usize) -> Self {
Self {
pos: 0,
rev_pos: count,
unused: PhantomData,

View File

@@ -68,7 +68,7 @@ pub struct EntityList<T: EntityRef> {
/// Create an empty list.
impl<T: EntityRef> Default for EntityList<T> {
fn default() -> Self {
EntityList {
Self {
index: 0,
unused: PhantomData,
}
@@ -82,7 +82,7 @@ impl<T: EntityRef> Hash for EntityList<T> {
}
impl<T: EntityRef> PartialEq for EntityList<T> {
fn eq(&self, _: &EntityList<T>) -> bool {
fn eq(&self, _: &Self) -> bool {
panic!("eq called on EntityList");
}
}
@@ -121,8 +121,8 @@ fn is_sclass_min_length(len: usize) -> bool {
impl<T: EntityRef> ListPool<T> {
/// Create a new list pool.
pub fn new() -> ListPool<T> {
ListPool {
pub fn new() -> Self {
Self {
data: Vec::new(),
free: Vec::new(),
}
@@ -311,7 +311,7 @@ impl<T: EntityRef> EntityList<T> {
/// Take all elements from this list and return them as a new list. Leave this list empty.
///
/// This is the equivalent of `Option::take()`.
pub fn take(&mut self) -> EntityList<T> {
pub fn take(&mut self) -> Self {
mem::replace(self, Default::default())
}

View File

@@ -34,7 +34,7 @@ where
where
V: Default,
{
EntityMap {
Self {
elems: Vec::new(),
default: Default::default(),
unused: PhantomData,
@@ -45,7 +45,7 @@ where
///
/// This constructor does not require V to implement Default.
pub fn with_default(default: V) -> Self {
EntityMap {
Self {
elems: Vec::new(),
default: default,
unused: PhantomData,

View File

@@ -27,7 +27,7 @@ where
{
/// Create a new empty map.
pub fn new() -> Self {
PrimaryMap {
Self {
elems: Vec::new(),
unused: PhantomData,
}

View File

@@ -24,7 +24,7 @@ where
{
/// Create a new empty set.
pub fn new() -> Self {
EntitySet {
Self {
elems: Vec::new(),
len: 0,
unused: PhantomData,

View File

@@ -66,7 +66,7 @@ where
{
/// Create a new empty mapping.
pub fn new() -> Self {
SparseMap {
Self {
sparse: EntityMap::new(),
dense: Vec::new(),
}
@@ -215,7 +215,7 @@ impl<T> SparseMapValue<T> for T
where
T: EntityRef,
{
fn key(&self) -> T {
fn key(&self) -> Self {
*self
}
}

View File

@@ -51,16 +51,16 @@ pub struct ControlFlowGraph {
impl ControlFlowGraph {
/// Allocate a new blank control flow graph.
pub fn new() -> ControlFlowGraph {
ControlFlowGraph {
pub fn new() -> Self {
Self {
data: EntityMap::new(),
valid: false,
}
}
/// Allocate and compute the control flow graph for `func`.
pub fn with_function(func: &Function) -> ControlFlowGraph {
let mut cfg = ControlFlowGraph::new();
pub fn with_function(func: &Function) -> Self {
let mut cfg = Self::new();
cfg.compute(func);
cfg
}

View File

@@ -62,8 +62,8 @@ pub struct DataFlowGraph {
impl DataFlowGraph {
/// Create a new empty `DataFlowGraph`.
pub fn new() -> DataFlowGraph {
DataFlowGraph {
pub fn new() -> Self {
Self {
insts: PrimaryMap::new(),
results: EntityMap::new(),
ebbs: PrimaryMap::new(),
@@ -829,8 +829,8 @@ struct EbbData {
}
impl EbbData {
fn new() -> EbbData {
EbbData { params: ValueList::new() }
fn new() -> Self {
Self { params: ValueList::new() }
}
}

View File

@@ -38,8 +38,8 @@ pub struct Signature {
impl Signature {
/// Create a new blank signature.
pub fn new(call_conv: CallConv) -> Signature {
Signature {
pub fn new(call_conv: CallConv) -> Self {
Self {
params: Vec::new(),
returns: Vec::new(),
call_conv,
@@ -138,8 +138,8 @@ pub struct AbiParam {
impl AbiParam {
/// Create a parameter with default flags.
pub fn new(vt: Type) -> AbiParam {
AbiParam {
pub fn new(vt: Type) -> Self {
Self {
value_type: vt,
extension: ArgumentExtension::None,
purpose: ArgumentPurpose::Normal,
@@ -148,8 +148,8 @@ impl AbiParam {
}
/// Create a special-purpose parameter that is not (yet) bound to a specific register.
pub fn special(vt: Type, purpose: ArgumentPurpose) -> AbiParam {
AbiParam {
pub fn special(vt: Type, purpose: ArgumentPurpose) -> Self {
Self {
value_type: vt,
extension: ArgumentExtension::None,
purpose,
@@ -158,8 +158,8 @@ impl AbiParam {
}
/// Create a parameter for a special-purpose register.
pub fn special_reg(vt: Type, purpose: ArgumentPurpose, regunit: RegUnit) -> AbiParam {
AbiParam {
pub fn special_reg(vt: Type, purpose: ArgumentPurpose, regunit: RegUnit) -> Self {
Self {
value_type: vt,
extension: ArgumentExtension::None,
purpose,
@@ -168,18 +168,18 @@ impl AbiParam {
}
/// Convert `self` to a parameter with the `uext` flag set.
pub fn uext(self) -> AbiParam {
pub fn uext(self) -> Self {
debug_assert!(self.value_type.is_int(), "uext on {} arg", self.value_type);
AbiParam {
Self {
extension: ArgumentExtension::Uext,
..self
}
}
/// Convert `self` to a parameter type with the `sext` flag set.
pub fn sext(self) -> AbiParam {
pub fn sext(self) -> Self {
debug_assert!(self.value_type.is_int(), "sext on {} arg", self.value_type);
AbiParam {
Self {
extension: ArgumentExtension::Sext,
..self
}

View File

@@ -66,8 +66,8 @@ pub struct Function {
impl Function {
/// Create a function with the given name and signature.
pub fn with_name_signature(name: ExternalName, sig: Signature) -> Function {
Function {
pub fn with_name_signature(name: ExternalName, sig: Signature) -> Self {
Self {
name,
signature: sig,
stack_slots: StackSlots::new(),
@@ -99,7 +99,7 @@ impl Function {
}
/// Create a new empty, anonymous function with a native calling convention.
pub fn new() -> Function {
pub fn new() -> Self {
Self::with_name_signature(ExternalName::default(), Signature::new(CallConv::Native))
}

View File

@@ -262,7 +262,7 @@ pub struct VariableArgs(Vec<Value>);
impl VariableArgs {
/// Create an empty argument list.
pub fn new() -> VariableArgs {
pub fn new() -> Self {
VariableArgs(Vec::new())
}
@@ -314,8 +314,8 @@ impl Display for VariableArgs {
}
impl Default for VariableArgs {
fn default() -> VariableArgs {
VariableArgs::new()
fn default() -> Self {
Self::new()
}
}

View File

@@ -24,16 +24,16 @@ pub struct JumpTableData {
impl JumpTableData {
/// Create a new empty jump table.
pub fn new() -> JumpTableData {
JumpTableData {
pub fn new() -> Self {
Self {
table: Vec::new(),
holes: 0,
}
}
/// Create a new empty jump table with the specified capacity.
pub fn with_capacity(capacity: usize) -> JumpTableData {
JumpTableData {
pub fn with_capacity(capacity: usize) -> Self {
Self {
table: Vec::with_capacity(capacity),
holes: 0,
}

View File

@@ -42,8 +42,8 @@ pub struct Layout {
impl Layout {
/// Create a new empty `Layout`.
pub fn new() -> Layout {
Layout {
pub fn new() -> Self {
Self {
ebbs: EntityMap::new(),
insts: EntityMap::new(),
first_ebb: None,

View File

@@ -21,8 +21,8 @@ pub struct MemFlags {
impl MemFlags {
/// Create a new empty set of flags.
pub fn new() -> MemFlags {
MemFlags { bits: 0 }
pub fn new() -> Self {
Self { bits: 0 }
}
/// Read a flag bit.

View File

@@ -33,7 +33,7 @@ impl SourceLoc {
}
impl Default for SourceLoc {
fn default() -> SourceLoc {
fn default() -> Self {
SourceLoc(!0)
}
}

View File

@@ -172,8 +172,8 @@ pub struct StackSlots {
/// Stack slot manager functions that behave mostly like an entity map.
impl StackSlots {
/// Create an empty stack slot manager.
pub fn new() -> StackSlots {
StackSlots {
pub fn new() -> Self {
Self {
slots: PrimaryMap::new(),
outgoing: Vec::new(),
emergency: Vec::new(),

View File

@@ -321,7 +321,7 @@ impl Debug for Type {
}
impl Default for Type {
fn default() -> Type {
fn default() -> Self {
VOID
}
}

View File

@@ -214,7 +214,7 @@ impl fmt::Debug for RegClassData {
/// Within an ISA, register classes are uniquely identified by their index.
impl PartialEq for RegClassData {
fn eq(&self, other: &RegClassData) -> bool {
fn eq(&self, other: &Self) -> bool {
self.index == other.index
}
}

View File

@@ -42,8 +42,8 @@ impl LoopData {
impl LoopAnalysis {
/// Allocate a new blank loop analysis struct. Use `compute` to compute the loop analysis for
/// a function.
pub fn new() -> LoopAnalysis {
LoopAnalysis {
pub fn new() -> Self {
Self {
valid: false,
loops: PrimaryMap::new(),
ebb_loop_map: EntityMap::new(),

View File

@@ -37,8 +37,8 @@ impl AllocatableSet {
///
/// Note that this includes *all* registers. Query the `TargetIsa` object to get a set of
/// allocatable registers where reserved registers have been filtered out.
pub fn new() -> AllocatableSet {
AllocatableSet { avail: [!0; 3] }
pub fn new() -> Self {
Self { avail: [!0; 3] }
}
/// Returns `true` if the specified register is available.

View File

@@ -74,8 +74,8 @@ impl Node {
impl DomForest {
/// Create a new empty dominator forest.
pub fn new() -> DomForest {
DomForest {
pub fn new() -> Self {
Self {
values: Vec::new(),
stack: Vec::new(),
}
@@ -252,8 +252,8 @@ struct Context<'a> {
impl Coalescing {
/// Create a new coalescing pass.
pub fn new() -> Coalescing {
Coalescing {
pub fn new() -> Self {
Self {
forest: DomForest::new(),
values: Vec::new(),
split_values: Vec::new(),

View File

@@ -101,8 +101,8 @@ struct Context<'a> {
impl Coloring {
/// Allocate scratch space data structures for the coloring pass.
pub fn new() -> Coloring {
Coloring {
pub fn new() -> Self {
Self {
divert: RegDiversions::new(),
solver: Solver::new(),
}

View File

@@ -36,8 +36,8 @@ impl Context {
///
/// This context should be reused for multiple functions in order to avoid repeated memory
/// allocations.
pub fn new() -> Context {
Context {
pub fn new() -> Self {
Self {
liveness: Liveness::new(),
virtregs: VirtRegs::new(),
coalescing: Coalescing::new(),

View File

@@ -44,8 +44,8 @@ pub struct RegDiversions {
impl RegDiversions {
/// Create a new empty diversion tracker.
pub fn new() -> RegDiversions {
RegDiversions { current: Vec::new() }
pub fn new() -> Self {
Self { current: Vec::new() }
}
/// Clear the tracker, preparing for a new EBB.

View File

@@ -65,8 +65,8 @@ struct LiveValueVec {
}
impl LiveValueVec {
fn new() -> LiveValueVec {
LiveValueVec {
fn new() -> Self {
Self {
values: Vec::new(),
live_prefix: None,
}
@@ -124,8 +124,8 @@ impl LiveValueVec {
impl LiveValueTracker {
/// Create a new blank tracker.
pub fn new() -> LiveValueTracker {
LiveValueTracker {
pub fn new() -> Self {
Self {
live: LiveValueVec::new(),
idom_sets: HashMap::new(),
idom_pool: ListPool::new(),

View File

@@ -299,8 +299,8 @@ impl Liveness {
///
/// The memory allocated for this analysis can be reused for multiple functions. Use the
/// `compute` method to actually runs the analysis for a function.
pub fn new() -> Liveness {
Liveness {
pub fn new() -> Self {
Self {
ranges: LiveRangeSet::new(),
worklist: Vec::new(),
ebb_params: Vec::new(),

View File

@@ -46,8 +46,8 @@ struct Context<'a> {
impl Reload {
/// Create a new blank reload pass.
pub fn new() -> Reload {
Reload {
pub fn new() -> Self {
Self {
candidates: Vec::new(),
reloads: SparseMap::new(),
}

View File

@@ -502,8 +502,8 @@ pub struct Solver {
/// Interface for programming the constraints into the solver.
impl Solver {
/// Create a new empty solver.
pub fn new() -> Solver {
Solver {
pub fn new() -> Self {
Self {
assignments: SparseMap::new(),
vars: Vec::new(),
inputs_done: false,

View File

@@ -63,8 +63,8 @@ struct Context<'a> {
impl Spilling {
/// Create a new spilling data structure.
pub fn new() -> Spilling {
Spilling {
pub fn new() -> Self {
Self {
spills: Vec::new(),
reg_uses: Vec::new(),
}

View File

@@ -45,8 +45,8 @@ pub struct VirtRegs {
#[allow(dead_code)]
impl VirtRegs {
/// Create a new virtual register collection.
pub fn new() -> VirtRegs {
VirtRegs {
pub fn new() -> Self {
Self {
pool: ListPool::new(),
vregs: PrimaryMap::new(),
value_vregs: EntityMap::new(),

View File

@@ -26,8 +26,8 @@ pub struct TopoOrder {
impl TopoOrder {
/// Create a new empty topological order.
pub fn new() -> TopoOrder {
TopoOrder {
pub fn new() -> Self {
Self {
preferred: Vec::new(),
next: 0,
visited: SparseSet::new(),

View File

@@ -95,8 +95,8 @@ pub struct CheckerBuilder {
impl CheckerBuilder {
/// Create a new, blank `CheckerBuilder`.
pub fn new() -> CheckerBuilder {
CheckerBuilder {
pub fn new() -> Self {
Self {
directives: Vec::new(),
linerx: Regex::new(DIRECTIVE_RX).unwrap(),
}
@@ -146,8 +146,8 @@ pub struct Checker {
}
impl Checker {
fn new(directives: Vec<Directive>) -> Checker {
Checker { directives: directives }
fn new(directives: Vec<Directive>) -> Self {
Self { directives: directives }
}
/// An empty checker contains no directives, and will match any input string.

View File

@@ -54,8 +54,8 @@ impl Part {
impl Pattern {
/// Create a new blank pattern. Use the `FromStr` trait to generate Patterns with content.
fn new() -> Pattern {
Pattern {
fn new() -> Self {
Self {
parts: Vec::new(),
defs: Vec::new(),
}

View File

@@ -30,8 +30,8 @@ pub struct FuncTranslator {
impl FuncTranslator {
/// Create a new translator.
pub fn new() -> FuncTranslator {
FuncTranslator {
pub fn new() -> Self {
Self {
il_builder: ILBuilder::new(),
state: TranslationState::new(),
}

View File

@@ -126,8 +126,8 @@ pub struct TranslationState {
}
impl TranslationState {
pub fn new() -> TranslationState {
TranslationState {
pub fn new() -> Self {
Self {
stack: Vec::new(),
control_stack: Vec::new(),
phantom_unreachable_stack_depth: 0,