From 02e34d1bf79722d2a219bec9977e8168069ec7d3 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Thu, 7 Jun 2018 15:06:31 -0700 Subject: [PATCH] Make `CtonError` parameterized on the result type. This makes it more consistent with other custom `Result` types. --- lib/codegen/src/binemit/relaxation.rs | 4 ++-- lib/codegen/src/context.rs | 34 +++++++++++++-------------- lib/codegen/src/isa/mod.rs | 4 ++-- lib/codegen/src/isa/x86/abi.rs | 10 ++++---- lib/codegen/src/isa/x86/mod.rs | 4 ++-- lib/codegen/src/regalloc/context.rs | 2 +- lib/codegen/src/result.rs | 2 +- lib/codegen/src/stack_layout.rs | 4 ++-- 8 files changed, 32 insertions(+), 32 deletions(-) diff --git a/lib/codegen/src/binemit/relaxation.rs b/lib/codegen/src/binemit/relaxation.rs index 7003df1eb0..299d0a1fb9 100644 --- a/lib/codegen/src/binemit/relaxation.rs +++ b/lib/codegen/src/binemit/relaxation.rs @@ -32,12 +32,12 @@ use cursor::{Cursor, FuncCursor}; use ir::{Function, InstructionData, Opcode}; use isa::{EncInfo, TargetIsa}; use iterators::IteratorExtras; -use result::CtonError; +use result::CtonResult; /// Relax branches and compute the final layout of EBB headers in `func`. /// /// Fill in the `func.offsets` table so the function is ready for binary emission. -pub fn relax_branches(func: &mut Function, isa: &TargetIsa) -> Result { +pub fn relax_branches(func: &mut Function, isa: &TargetIsa) -> CtonResult { let encinfo = isa.encoding_info(); // Clear all offsets so we can recognize EBBs that haven't been visited yet. diff --git a/lib/codegen/src/context.rs b/lib/codegen/src/context.rs index 83dd3d0368..5c33d56314 100644 --- a/lib/codegen/src/context.rs +++ b/lib/codegen/src/context.rs @@ -22,7 +22,7 @@ use nan_canonicalization::do_nan_canonicalization; use postopt::do_postopt; use preopt::do_preopt; use regalloc; -use result::{CtonError, CtonResult}; +use result::CtonResult; use settings::{FlagsOrIsa, OptLevel}; use simple_gvn::do_simple_gvn; use std::vec::Vec; @@ -95,7 +95,7 @@ impl Context { mem: &mut Vec, relocs: &mut RelocSink, traps: &mut TrapSink, - ) -> CtonResult { + ) -> CtonResult<()> { let code_size = self.compile(isa)?; let old_len = mem.len(); mem.resize(old_len + code_size as usize, 0); @@ -117,7 +117,7 @@ impl Context { /// code sink. /// /// Returns the size of the function's code. - pub fn compile(&mut self, isa: &TargetIsa) -> Result { + pub fn compile(&mut self, isa: &TargetIsa) -> CtonResult { let _tt = timing::compile(); self.verify_if(isa)?; @@ -179,7 +179,7 @@ impl Context { } /// Run the verifier only if the `enable_verifier` setting is true. - pub fn verify_if<'a, FOI: Into>>(&self, fisa: FOI) -> CtonResult { + pub fn verify_if<'a, FOI: Into>>(&self, fisa: FOI) -> CtonResult<()> { let fisa = fisa.into(); if fisa.flags.enable_verifier() { self.verify(fisa).map_err(Into::into) @@ -194,7 +194,7 @@ impl Context { } /// Run the locations verifier only if the `enable_verifier` setting is true. - pub fn verify_locations_if(&self, isa: &TargetIsa) -> CtonResult { + pub fn verify_locations_if(&self, isa: &TargetIsa) -> CtonResult<()> { if isa.flags().enable_verifier() { self.verify_locations(isa).map_err(Into::into) } else { @@ -203,27 +203,27 @@ impl Context { } /// Perform dead-code elimination on the function. - pub fn dce<'a, FOI: Into>>(&mut self, fisa: FOI) -> CtonResult { + pub fn dce<'a, FOI: Into>>(&mut self, fisa: FOI) -> CtonResult<()> { do_dce(&mut self.func, &mut self.domtree); self.verify_if(fisa)?; Ok(()) } /// Perform pre-legalization rewrites on the function. - pub fn preopt(&mut self, isa: &TargetIsa) -> CtonResult { + pub fn preopt(&mut self, isa: &TargetIsa) -> CtonResult<()> { do_preopt(&mut self.func); self.verify_if(isa)?; Ok(()) } /// Perform NaN canonicalizing rewrites on the function. - pub fn canonicalize_nans(&mut self, isa: &TargetIsa) -> CtonResult { + pub fn canonicalize_nans(&mut self, isa: &TargetIsa) -> CtonResult<()> { do_nan_canonicalization(&mut self.func); self.verify_if(isa) } /// Run the legalizer for `isa` on the function. - pub fn legalize(&mut self, isa: &TargetIsa) -> CtonResult { + pub fn legalize(&mut self, isa: &TargetIsa) -> CtonResult<()> { // Legalization invalidates the domtree and loop_analysis by mutating the CFG. // TODO: Avoid doing this when legalization doesn't actually mutate the CFG. self.domtree.clear(); @@ -233,7 +233,7 @@ impl Context { } /// Perform post-legalization rewrites on the function. - pub fn postopt(&mut self, isa: &TargetIsa) -> CtonResult { + pub fn postopt(&mut self, isa: &TargetIsa) -> CtonResult<()> { do_postopt(&mut self.func, isa); self.verify_if(isa)?; Ok(()) @@ -262,13 +262,13 @@ impl Context { } /// Perform simple GVN on the function. - pub fn simple_gvn<'a, FOI: Into>>(&mut self, fisa: FOI) -> CtonResult { + pub fn simple_gvn<'a, FOI: Into>>(&mut self, fisa: FOI) -> CtonResult<()> { do_simple_gvn(&mut self.func, &mut self.domtree); self.verify_if(fisa) } /// Perform LICM on the function. - pub fn licm<'a, FOI: Into>>(&mut self, fisa: FOI) -> CtonResult { + pub fn licm<'a, FOI: Into>>(&mut self, fisa: FOI) -> CtonResult<()> { do_licm( &mut self.func, &mut self.cfg, @@ -279,7 +279,7 @@ impl Context { } /// Perform unreachable code elimination. - pub fn eliminate_unreachable_code<'a, FOI>(&mut self, fisa: FOI) -> CtonResult + pub fn eliminate_unreachable_code<'a, FOI>(&mut self, fisa: FOI) -> CtonResult<()> where FOI: Into>, { @@ -288,13 +288,13 @@ impl Context { } /// Run the register allocator. - pub fn regalloc(&mut self, isa: &TargetIsa) -> CtonResult { + pub fn regalloc(&mut self, isa: &TargetIsa) -> CtonResult<()> { self.regalloc .run(isa, &mut self.func, &self.cfg, &mut self.domtree) } /// Insert prologue and epilogues after computing the stack frame layout. - pub fn prologue_epilogue(&mut self, isa: &TargetIsa) -> CtonResult { + pub fn prologue_epilogue(&mut self, isa: &TargetIsa) -> CtonResult<()> { assert!( self.func.stack_limit.is_none(), "stack_limit isn't implemented yet" @@ -306,7 +306,7 @@ impl Context { } /// Run the instruction shrinking pass. - pub fn shrink_instructions(&mut self, isa: &TargetIsa) -> CtonResult { + pub fn shrink_instructions(&mut self, isa: &TargetIsa) -> CtonResult<()> { shrink_instructions(&mut self.func, isa); self.verify_if(isa)?; self.verify_locations_if(isa)?; @@ -314,7 +314,7 @@ impl Context { } /// Run the branch relaxation pass and return the final code size. - pub fn relax_branches(&mut self, isa: &TargetIsa) -> Result { + pub fn relax_branches(&mut self, isa: &TargetIsa) -> CtonResult { let code_size = relax_branches(&mut self.func, isa)?; self.verify_if(isa)?; self.verify_locations_if(isa)?; diff --git a/lib/codegen/src/isa/mod.rs b/lib/codegen/src/isa/mod.rs index 34733b92f7..c042a42600 100644 --- a/lib/codegen/src/isa/mod.rs +++ b/lib/codegen/src/isa/mod.rs @@ -56,7 +56,7 @@ use flowgraph; use ir; use isa::enc_tables::Encodings; use regalloc; -use result; +use result::CtonResult; use settings; use settings::CallConv; use std::boxed::Box; @@ -281,7 +281,7 @@ pub trait TargetIsa: fmt::Display { /// Compute the stack layout and insert prologue and epilogue code into `func`. /// /// Return an error if the stack frame is too large. - fn prologue_epilogue(&self, func: &mut ir::Function) -> result::CtonResult { + fn prologue_epilogue(&self, func: &mut ir::Function) -> CtonResult<()> { let _tt = timing::prologue_epilogue(); // This default implementation is unlikely to be good enough. use ir::stackslot::{StackOffset, StackSize}; diff --git a/lib/codegen/src/isa/x86/abi.rs b/lib/codegen/src/isa/x86/abi.rs index d10f406ab3..264a45a137 100644 --- a/lib/codegen/src/isa/x86/abi.rs +++ b/lib/codegen/src/isa/x86/abi.rs @@ -10,7 +10,7 @@ use ir::{get_probestack_funcref, AbiParam, ArgumentExtension, ArgumentLoc, Argum InstBuilder, ValueLoc}; use isa::{RegClass, RegUnit, TargetIsa}; use regalloc::RegisterSet; -use result; +use result::CtonResult; use settings::CallConv; use stack_layout::layout_stack; use std::i32; @@ -257,7 +257,7 @@ fn callee_saved_gprs_used(isa: &TargetIsa, func: &ir::Function) -> RegisterSet { used } -pub fn prologue_epilogue(func: &mut ir::Function, isa: &TargetIsa) -> result::CtonResult { +pub fn prologue_epilogue(func: &mut ir::Function, isa: &TargetIsa) -> CtonResult<()> { match func.signature.call_conv { // For now, just translate fast and cold as system_v. CallConv::Fast | CallConv::Cold | CallConv::SystemV => { @@ -269,7 +269,7 @@ pub fn prologue_epilogue(func: &mut ir::Function, isa: &TargetIsa) -> result::Ct } } -pub fn baldrdash_prologue_epilogue(func: &mut ir::Function, isa: &TargetIsa) -> result::CtonResult { +pub fn baldrdash_prologue_epilogue(func: &mut ir::Function, isa: &TargetIsa) -> CtonResult<()> { debug_assert!( !isa.flags().probestack_enabled(), "baldrdash does not expect cretonne to emit stack probes" @@ -290,7 +290,7 @@ pub fn baldrdash_prologue_epilogue(func: &mut ir::Function, isa: &TargetIsa) -> /// Implementation of the fastcall-based Win64 calling convention described at [1] /// [1] https://msdn.microsoft.com/en-us/library/ms235286.aspx -pub fn fastcall_prologue_epilogue(func: &mut ir::Function, isa: &TargetIsa) -> result::CtonResult { +pub fn fastcall_prologue_epilogue(func: &mut ir::Function, isa: &TargetIsa) -> CtonResult<()> { if isa.triple().pointer_width().unwrap() != PointerWidth::U64 { panic!("TODO: windows-fastcall: x86-32 not implemented yet"); } @@ -362,7 +362,7 @@ pub fn fastcall_prologue_epilogue(func: &mut ir::Function, isa: &TargetIsa) -> r } /// Insert a System V-compatible prologue and epilogue. -pub fn system_v_prologue_epilogue(func: &mut ir::Function, isa: &TargetIsa) -> result::CtonResult { +pub fn system_v_prologue_epilogue(func: &mut ir::Function, isa: &TargetIsa) -> CtonResult<()> { // The original 32-bit x86 ELF ABI had a 4-byte aligned stack pointer, but // newer versions use a 16-byte aligned stack pointer. let stack_align = 16; diff --git a/lib/codegen/src/isa/x86/mod.rs b/lib/codegen/src/isa/x86/mod.rs index 6e2c035d38..cba7a640f9 100644 --- a/lib/codegen/src/isa/x86/mod.rs +++ b/lib/codegen/src/isa/x86/mod.rs @@ -13,7 +13,7 @@ use isa::enc_tables::{self as shared_enc_tables, lookup_enclist, Encodings}; use isa::Builder as IsaBuilder; use isa::{EncInfo, RegClass, RegInfo, TargetIsa}; use regalloc; -use result; +use result::CtonResult; use std::boxed::Box; use std::fmt; use target_lexicon::{PointerWidth, Triple}; @@ -129,7 +129,7 @@ impl TargetIsa for Isa { emit_function(func, binemit::emit_inst, sink) } - fn prologue_epilogue(&self, func: &mut ir::Function) -> result::CtonResult { + fn prologue_epilogue(&self, func: &mut ir::Function) -> CtonResult<()> { let _tt = timing::prologue_epilogue(); abi::prologue_epilogue(func, self) } diff --git a/lib/codegen/src/regalloc/context.rs b/lib/codegen/src/regalloc/context.rs index ce1d68a096..10f83b979d 100644 --- a/lib/codegen/src/regalloc/context.rs +++ b/lib/codegen/src/regalloc/context.rs @@ -72,7 +72,7 @@ impl Context { func: &mut Function, cfg: &ControlFlowGraph, domtree: &mut DominatorTree, - ) -> CtonResult { + ) -> CtonResult<()> { let _tt = timing::regalloc(); debug_assert!(domtree.is_valid()); diff --git a/lib/codegen/src/result.rs b/lib/codegen/src/result.rs index 1821c2e3b5..9d684dc172 100644 --- a/lib/codegen/src/result.rs +++ b/lib/codegen/src/result.rs @@ -32,7 +32,7 @@ pub enum CtonError { } /// A Cretonne compilation result. -pub type CtonResult = Result<(), CtonError>; +pub type CtonResult = Result; impl From for CtonError { fn from(e: VerifierError) -> Self { diff --git a/lib/codegen/src/stack_layout.rs b/lib/codegen/src/stack_layout.rs index cda2251900..6334f4d5ed 100644 --- a/lib/codegen/src/stack_layout.rs +++ b/lib/codegen/src/stack_layout.rs @@ -2,7 +2,7 @@ use ir::stackslot::{StackOffset, StackSize, StackSlotKind}; use ir::StackSlots; -use result::CtonError; +use result::{CtonError, CtonResult}; use std::cmp::{max, min}; /// Compute the stack frame layout. @@ -15,7 +15,7 @@ use std::cmp::{max, min}; /// Returns the total stack frame size which is also saved in `frame.frame_size`. /// /// If the stack frame is too big, returns an `ImplLimitExceeded` error. -pub fn layout_stack(frame: &mut StackSlots, alignment: StackSize) -> Result { +pub fn layout_stack(frame: &mut StackSlots, alignment: StackSize) -> CtonResult { // Each object and the whole stack frame must fit in 2 GB such that any relative offset within // the frame fits in a `StackOffset`. let max_size = StackOffset::max_value() as StackSize;