Bug 1509848: Run clippy on Baldrdash; r=sunfish
authorBenjamin Bouvier <benj@benj.me>
Mon, 19 Nov 2018 17:23:41 +0100
changeset 504723 6c94d53b486c1140051607b71bf66c0e014c605c
parent 504722 fc064fbbcdf011cb2028f36b7afec810e64a865c
child 504724 dc298299ebadd4b20eb58ea1ee6404b416eed422
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssunfish
bugs1509848
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1509848: Run clippy on Baldrdash; r=sunfish
js/src/wasm/cranelift/src/baldrdash.rs
js/src/wasm/cranelift/src/compile.rs
js/src/wasm/cranelift/src/lib.rs
js/src/wasm/cranelift/src/wasm2clif.rs
--- a/js/src/wasm/cranelift/src/baldrdash.rs
+++ b/js/src/wasm/cranelift/src/baldrdash.rs
@@ -96,17 +96,17 @@ impl GlobalDesc {
     }
 
     /// Insert an instruction at `pos` that materialized the constant value.
     pub fn emit_constant(self, pos: &mut FuncCursor) -> ir::Value {
         unsafe {
             let v = baldrapi::global_constantValue(self.0);
             // Note that the floating point constants below
             match v.t {
-                TypeCode::I32 => pos.ins().iconst(ir::types::I32, v.u.i32 as i64),
+                TypeCode::I32 => pos.ins().iconst(ir::types::I32, i64::from(v.u.i32)),
                 TypeCode::I64 => pos.ins().iconst(ir::types::I64, v.u.i64),
                 TypeCode::F32 => pos.ins().f32const(Ieee32::with_bits(v.u.i32 as u32)),
                 TypeCode::F64 => pos.ins().f64const(Ieee64::with_bits(v.u.i64 as u64)),
                 _ => panic!("unexpected type"),
             }
         }
     }
 
@@ -186,11 +186,11 @@ impl<'a> ModuleEnvironment<'a> {
     }
     pub fn table(&self, table_index: TableIndex) -> TableDesc {
         TableDesc(unsafe { baldrapi::env_table(self.env, table_index.index()) })
     }
     pub fn global(&self, global_index: GlobalIndex) -> GlobalDesc {
         GlobalDesc(unsafe { baldrapi::env_global(self.env, global_index.index()) })
     }
     pub fn min_memory_length(&self) -> i64 {
-        self.env.min_memory_length as i64
+        i64::from(self.env.min_memory_length)
     }
 }
--- a/js/src/wasm/cranelift/src/compile.rs
+++ b/js/src/wasm/cranelift/src/compile.rs
@@ -160,17 +160,17 @@ impl<'a, 'b> BatchCompiler<'a, 'b> {
 
     /// Compute the `framePushed` argument to pass to `GenerateFunctionPrologue`. This is the
     /// number of frame bytes used by Cranelift, not counting the values pushed by the standard
     /// prologue generated by `GenerateFunctionPrologue`.
     fn frame_pushed(&self) -> StackSize {
         // Cranelift computes the total stack frame size including the pushed return address,
         // standard SM prologue pushes, and its own stack slots.
         let total = self.context.func.stack_slots.frame_size.expect("No frame");
-        let sm_pushed = self.isa.flags().baldrdash_prologue_words() as StackSize
+        let sm_pushed = StackSize::from(self.isa.flags().baldrdash_prologue_words())
             * mem::size_of::<usize>() as StackSize;
         total
             .checked_sub(sm_pushed)
             .expect("SpiderMonkey prologue pushes not counted")
     }
 
     /// Determine whether the current function may contain calls.
     fn contains_calls(&self) -> bool {
@@ -264,18 +264,18 @@ impl<'a, 'b> BatchCompiler<'a, 'b> {
 
         // This is a direct call, so the callee should be a non-imported wasm
         // function. We register both the call site *and* the target for relocation.
         let callee = match func.dfg[inst] {
             ir::InstructionData::Call { func_ref, .. } => &func.dfg.ext_funcs[func_ref].name,
             _ => panic!("Bad format for call"),
         };
 
-        let func_index = match callee {
-            &ir::ExternalName::User {
+        let func_index = match *callee {
+            ir::ExternalName::User {
                 namespace: 0,
                 index,
             } => FuncIndex::new(index as usize),
             _ => panic!("Direct call to {} unsupported", callee),
         };
 
         let srcloc = func.srclocs[inst];
         assert!(
@@ -437,32 +437,32 @@ impl<'a> RelocSink for EmitEnv<'a> {
     fn reloc_external(
         &mut self,
         offset: CodeOffset,
         _reloc: Reloc,
         name: &ir::ExternalName,
         _addend: Addend,
     ) {
         // Decode the function name.
-        match name {
-            &ir::ExternalName::User { namespace: 0, .. } => {
+        match *name {
+            ir::ExternalName::User { namespace: 0, .. } => {
                 // This is a direct function call handled by `emit_metadata` above.
             }
-            &ir::ExternalName::User {
+            ir::ExternalName::User {
                 namespace: 1,
                 index,
             } => {
                 // This is a symbolic function reference encoded by `symbolic_function_name()`.
                 let sym = index.into();
                 // The symbolic access patch address points *after* the stored pointer.
                 let offset = offset + native_pointer_size() as u32;
                 self.metadata
                     .push(bd::MetadataEntry::symbolic_access(offset, sym));
             }
-            &ir::ExternalName::LibCall(call) => {
+            ir::ExternalName::LibCall(call) => {
                 let sym = match call {
                     ir::LibCall::CeilF32 => bd::SymbolicAddress::CeilF32,
                     ir::LibCall::CeilF64 => bd::SymbolicAddress::CeilF64,
                     ir::LibCall::FloorF32 => bd::SymbolicAddress::FloorF32,
                     ir::LibCall::FloorF64 => bd::SymbolicAddress::FloorF64,
                     ir::LibCall::NearestF32 => bd::SymbolicAddress::NearestF32,
                     ir::LibCall::NearestF64 => bd::SymbolicAddress::NearestF64,
                     ir::LibCall::TruncF32 => bd::SymbolicAddress::TruncF32,
--- a/js/src/wasm/cranelift/src/lib.rs
+++ b/js/src/wasm/cranelift/src/lib.rs
@@ -45,65 +45,65 @@ pub extern "C" fn cranelift_initialize()
         }
     }
 }
 
 /// Allocate a compiler for a module environment and return an opaque handle.
 ///
 /// This is declared in `clifapi.h`.
 #[no_mangle]
-pub extern "C" fn cranelift_compiler_create<'a, 'b>(
+pub unsafe extern "C" fn cranelift_compiler_create<'a, 'b>(
     static_env: *const StaticEnvironment,
     env: *const baldrapi::CraneliftModuleEnvironment,
 ) -> *mut BatchCompiler<'a, 'b> {
-    let env = unsafe { env.as_ref().unwrap() };
-    let static_env = unsafe { static_env.as_ref().unwrap() };
+    let env = env.as_ref().unwrap();
+    let static_env = static_env.as_ref().unwrap();
     match BatchCompiler::new(static_env, ModuleEnvironment::new(env)) {
         Ok(compiler) => Box::into_raw(Box::new(compiler)),
         Err(err) => {
             error!("When constructing the batch compiler: {}", err);
             ptr::null_mut()
         }
     }
 }
 
 /// Deallocate compiler.
 ///
 /// This is declared in `clifapi.h`.
 #[no_mangle]
-pub extern "C" fn cranelift_compiler_destroy(compiler: *mut BatchCompiler) {
+pub unsafe extern "C" fn cranelift_compiler_destroy(compiler: *mut BatchCompiler) {
     assert!(
         !compiler.is_null(),
         "NULL pointer passed to cranelift_compiler_destroy"
     );
     // Convert the pointer back into the box it came from. Then drop it.
-    let _box = unsafe { Box::from_raw(compiler) };
+    let _box = Box::from_raw(compiler);
 }
 
 /// Compile a single function.
 ///
 /// This is declared in `clifapi.h`.
 #[no_mangle]
-pub extern "C" fn cranelift_compile_function(
+pub unsafe extern "C" fn cranelift_compile_function(
     compiler: *mut BatchCompiler,
     data: *const FuncCompileInput,
     result: *mut CompiledFunc,
 ) -> bool {
-    let compiler = unsafe { compiler.as_mut().unwrap() };
-    let data = unsafe { data.as_ref().unwrap() };
+    let compiler = compiler.as_mut().unwrap();
+    let data = data.as_ref().unwrap();
 
     if let Err(e) = compiler.translate_wasm(data) {
         error!("Wasm translation error: {}\n{}", e, compiler);
         return false;
     };
 
     if let Err(e) = compiler.compile() {
         error!("Cranelift compilation error: {}\n{}", e, compiler);
         return false;
     };
 
     // TODO(bbouvier) if destroy is called while one of these objects is alive, you're going to
     // have a bad time. Would be nice to be able to enforce lifetimes accross languages, somehow.
-    let result = unsafe { result.as_mut().unwrap() };
+    let result = result.as_mut().unwrap();
     result.reset(&compiler.current_func);
 
     true
 }
--- a/js/src/wasm/cranelift/src/wasm2clif.rs
+++ b/js/src/wasm/cranelift/src/wasm2clif.rs
@@ -786,11 +786,11 @@ impl TableInfo {
 
         TableInfo { global }
     }
 
     /// Get the size in bytes of each table entry.
     pub fn entry_size(&self) -> i64 {
         // Each entry is an `wasm::FunctionTableElem` which consists of the code pointer and a new
         // VM context pointer.
-        native_pointer_size() as i64 * 2
+        i64::from(native_pointer_size()) * 2
     }
 }