Bug 1509848: Reenable warnings in Baldrdash and fix them; r=sunfish
authorBenjamin Bouvier <benj@benj.me>
Mon, 19 Nov 2018 15:27:46 +0100
changeset 507501 ecf218f8c16a46fecbcf7e24c2e862b726a0c020
parent 507500 9fcec7e5baa7e044e0a403d70ded222dc4d7bb1f
child 507502 fc064fbbcdf011cb2028f36b7afec810e64a865c
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [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: Reenable warnings in Baldrdash and fix them; r=sunfish
js/src/wasm/cranelift/src/baldrapi.rs
js/src/wasm/cranelift/src/baldrdash.rs
js/src/wasm/cranelift/src/compile.rs
js/src/wasm/cranelift/src/cpu.rs
js/src/wasm/cranelift/src/lib.rs
js/src/wasm/cranelift/src/utils.rs
js/src/wasm/cranelift/src/wasm2clif.rs
--- a/js/src/wasm/cranelift/src/baldrapi.rs
+++ b/js/src/wasm/cranelift/src/baldrapi.rs
@@ -18,17 +18,17 @@
 //! The Baldr API consists of a set of C functions and some associated types.
 
 #![allow(non_upper_case_globals)]
 #![allow(non_camel_case_types)]
 #![allow(non_snake_case)]
 
 use cranelift_codegen::binemit::CodeOffset;
 use cranelift_codegen::entity::EntityRef;
-use cranelift_codegen::ir;
+use cranelift_codegen::ir::SourceLoc;
 use cranelift_wasm::FuncIndex;
 
 use compile::CompiledFunc;
 
 include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
 
 impl CraneliftFuncCompileInput {
     pub fn bytecode(&self) -> &[u8] {
@@ -46,44 +46,44 @@ impl CraneliftCompiledFunc {
         self.containsCalls = compiled_func.contains_calls;
 
         self.code = compiled_func.code_buffer.as_ptr();
         self.codeSize = compiled_func.code_buffer.len();
     }
 }
 
 impl CraneliftMetadataEntry {
-    pub fn direct_call(offset: CodeOffset, func_index: FuncIndex, srcloc: ir::SourceLoc) -> Self {
+    pub fn direct_call(offset: CodeOffset, func_index: FuncIndex, srcloc: SourceLoc) -> Self {
         Self {
             which: CraneliftMetadataEntry_Which_DirectCall,
             offset,
             srcLoc: srcloc.bits(),
             extra: func_index.index(),
         }
     }
 
-    pub fn indirect_call(offset: CodeOffset, srcloc: ir::SourceLoc) -> Self {
+    pub fn indirect_call(offset: CodeOffset, srcloc: SourceLoc) -> Self {
         Self {
             which: CraneliftMetadataEntry_Which_IndirectCall,
             offset,
             srcLoc: srcloc.bits(),
             extra: 0,
         }
     }
 
-    pub fn trap(offset: CodeOffset, srcloc: ir::SourceLoc, which: Trap) -> Self {
+    pub fn trap(offset: CodeOffset, srcloc: SourceLoc, which: Trap) -> Self {
         Self {
             which: CraneliftMetadataEntry_Which_Trap,
             offset,
             srcLoc: srcloc.bits(),
             extra: which as usize,
         }
     }
 
-    pub fn memory_access(offset: CodeOffset, srcloc: ir::SourceLoc) -> Self {
+    pub fn memory_access(offset: CodeOffset, srcloc: SourceLoc) -> Self {
         Self {
             which: CraneliftMetadataEntry_Which_MemoryAccess,
             offset,
             srcLoc: srcloc.bits(),
             extra: 0,
         }
     }
 
--- a/js/src/wasm/cranelift/src/baldrdash.rs
+++ b/js/src/wasm/cranelift/src/baldrdash.rs
@@ -12,46 +12,36 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 // Safe wrappers to the low-level ABI.  This re-exports all types in
 // baldrapi but none of the functions.
 
 use baldrapi::CraneliftModuleEnvironment;
-use cranelift_codegen::binemit::CodeOffset;
-use cranelift_codegen::cursor::{Cursor, FuncCursor};
+use cranelift_codegen::cursor::FuncCursor;
 use cranelift_codegen::entity::EntityRef;
 use cranelift_codegen::ir::immediates::{Ieee32, Ieee64};
-use cranelift_codegen::ir::stackslot::StackSize;
 use cranelift_codegen::ir::{self, InstBuilder};
-use cranelift_codegen::{CodegenError, CodegenResult};
 use cranelift_wasm::{FuncIndex, GlobalIndex, SignatureIndex, TableIndex};
 use std::mem;
 use std::slice;
 
 use baldrapi;
 
 pub use baldrapi::BD_SymbolicAddress as SymbolicAddress;
 pub use baldrapi::BD_ValType as ValType;
 pub use baldrapi::CraneliftCompiledFunc as CompiledFunc;
 pub use baldrapi::CraneliftFuncCompileInput as FuncCompileInput;
 pub use baldrapi::CraneliftMetadataEntry as MetadataEntry;
 pub use baldrapi::CraneliftStaticEnvironment as StaticEnvironment;
 pub use baldrapi::FuncTypeIdDescKind;
 pub use baldrapi::Trap;
 pub use baldrapi::TypeCode;
 
-pub enum ConstantValue {
-    I32(i32),
-    I64(i64),
-    F32(f32),
-    F64(f64),
-}
-
 /// Convert a `TypeCode` into the equivalent Cranelift type.
 ///
 /// We expect Cranelift's `VOID` type to go away in the future, so use `None` to represent a
 /// function without a return value.
 impl Into<Option<ir::Type>> for TypeCode {
     fn into(self) -> Option<ir::Type> {
         match self {
             TypeCode::I32 => Some(ir::types::I32),
--- a/js/src/wasm/cranelift/src/compile.rs
+++ b/js/src/wasm/cranelift/src/compile.rs
@@ -15,28 +15,24 @@
 
 //! Cranelift WebAssembly function compiler.
 //!
 //! This module defines the `compile()` function which uses Cranelift to compile a single
 //! WebAssembly function.
 
 use baldrdash as bd;
 use cpu::make_isa;
-use cranelift_codegen::binemit::{Addend, CodeOffset, NullTrapSink, Reloc, RelocSink, TrapSink};
-use cranelift_codegen::cursor::{Cursor, FuncCursor};
+use cranelift_codegen::binemit::{Addend, CodeOffset, NullTrapSink, Reloc, RelocSink};
 use cranelift_codegen::entity::EntityRef;
+use cranelift_codegen::ir;
 use cranelift_codegen::ir::stackslot::StackSize;
-use cranelift_codegen::ir::{InstBuilder, SourceLoc, TrapCode};
 use cranelift_codegen::isa::TargetIsa;
-use cranelift_codegen::settings::Flags;
-use cranelift_codegen::{self, ir};
-use cranelift_codegen::{CodegenError, CodegenResult};
-use cranelift_wasm::{
-    self, FuncIndex, GlobalIndex, MemoryIndex, SignatureIndex, TableIndex, WasmResult,
-};
+use cranelift_codegen::CodegenResult;
+use cranelift_codegen::Context;
+use cranelift_wasm::{FuncIndex, FuncTranslator, WasmResult};
 use std::fmt;
 use std::mem;
 use utils::DashResult;
 use wasm2clif::{init_sig, native_pointer_size, TransEnv};
 
 /// The result of a function's compilation: code + metadata.
 pub struct CompiledFunc {
     pub frame_pushed: StackSize,
@@ -65,33 +61,33 @@ impl CompiledFunc {
 }
 
 /// A batch compiler holds on to data structures that can be recycled for multiple function
 /// compilations.
 pub struct BatchCompiler<'a, 'b> {
     static_environ: &'a bd::StaticEnvironment,
     environ: bd::ModuleEnvironment<'b>,
     isa: Box<TargetIsa>,
-    context: cranelift_codegen::Context,
-    trans: cranelift_wasm::FuncTranslator,
+    context: Context,
+    trans: FuncTranslator,
     pub current_func: CompiledFunc,
 }
 
 impl<'a, 'b> BatchCompiler<'a, 'b> {
     pub fn new(
         static_environ: &'a bd::StaticEnvironment,
         environ: bd::ModuleEnvironment<'b>,
     ) -> DashResult<Self> {
         // TODO: The target ISA could be shared by multiple batch compilers across threads.
         Ok(BatchCompiler {
             static_environ,
             environ,
             isa: make_isa(static_environ)?,
-            context: cranelift_codegen::Context::new(),
-            trans: cranelift_wasm::FuncTranslator::new(),
+            context: Context::new(),
+            trans: FuncTranslator::new(),
             current_func: CompiledFunc::new(),
         })
     }
 
     pub fn compile(&mut self) -> CodegenResult<()> {
         let size = self.context.compile(&*self.isa)?;
         self.binemit(size as usize)
     }
@@ -141,21 +137,17 @@ impl<'a, 'b> BatchCompiler<'a, 'b> {
             let current_size = self.current_func.code_buffer.len();
             // There's no way to do a proper uninitialized reserve, so first reserve and then
             // unsafely set the final size.
             self.current_func.code_buffer.reserve(size - current_size);
             unsafe { self.current_func.code_buffer.set_len(size) };
         }
 
         {
-            let eenv = &mut EmitEnv::new(
-                &self.context.func,
-                &self.environ,
-                &mut self.current_func.metadata,
-            );
+            let eenv = &mut EmitEnv::new(&mut self.current_func.metadata);
             let mut trap_sink = NullTrapSink {};
             unsafe {
                 let code_buffer = &mut self.current_func.code_buffer;
                 self.context.emit_to_memory(
                     &*self.isa,
                     code_buffer.as_mut_ptr(),
                     eenv,
                     &mut trap_sink,
@@ -422,54 +414,41 @@ pub fn wasm_function_name(func: FuncInde
 pub fn symbolic_function_name(sym: bd::SymbolicAddress) -> ir::ExternalName {
     ir::ExternalName::User {
         namespace: 1,
         index: sym as u32,
     }
 }
 
 /// References joined so we can implement `RelocSink`.
-struct EmitEnv<'a, 'b, 'c> {
-    func: &'a ir::Function,
-    env: &'b bd::ModuleEnvironment<'b>,
-    metadata: &'c mut Vec<bd::MetadataEntry>,
+struct EmitEnv<'a> {
+    metadata: &'a mut Vec<bd::MetadataEntry>,
 }
 
-impl<'a, 'b, 'c> EmitEnv<'a, 'b, 'c> {
-    pub fn new(
-        func: &'a ir::Function,
-        env: &'b bd::ModuleEnvironment,
-        metadata: &'c mut Vec<bd::MetadataEntry>,
-    ) -> EmitEnv<'a, 'b, 'c> {
-        EmitEnv {
-            func,
-            env,
-            metadata,
-        }
+impl<'a> EmitEnv<'a> {
+    pub fn new(metadata: &'a mut Vec<bd::MetadataEntry>) -> EmitEnv<'a> {
+        EmitEnv { metadata }
     }
 }
 
-impl<'a, 'b, 'c> RelocSink for EmitEnv<'a, 'b, 'c> {
+impl<'a> RelocSink for EmitEnv<'a> {
     fn reloc_ebb(&mut self, _offset: CodeOffset, _reloc: Reloc, _ebb_offset: CodeOffset) {
         unimplemented!();
     }
 
     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,
-                index,
-            } => {
+            &ir::ExternalName::User { namespace: 0, .. } => {
                 // This is a direct function call handled by `emit_metadata` above.
             }
             &ir::ExternalName::User {
                 namespace: 1,
                 index,
             } => {
                 // This is a symbolic function reference encoded by `symbolic_function_name()`.
                 let sym = index.into();
--- a/js/src/wasm/cranelift/src/cpu.rs
+++ b/js/src/wasm/cranelift/src/cpu.rs
@@ -18,20 +18,17 @@
 //! This module deals with the configuration of Cranelift to generate code for the current CPU that
 //! is compatible with the SpiderMonkey JIT.
 //!
 //! The main entry point is the `make_isa()` function which allocates a configured `TargetISA`
 //! object.
 
 use cranelift_codegen::isa;
 use cranelift_codegen::settings::{self, Configurable};
-use std::error;
-use std::mem;
 use std::str::FromStr;
-use target_lexicon;
 use utils::{BasicError, DashResult};
 
 use baldrdash::StaticEnvironment;
 
 impl From<isa::LookupError> for BasicError {
     fn from(err: isa::LookupError) -> BasicError {
         BasicError::new(err.to_string())
     }
--- a/js/src/wasm/cranelift/src/lib.rs
+++ b/js/src/wasm/cranelift/src/lib.rs
@@ -8,19 +8,16 @@
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
-#![allow(unused)]
-#![warn(unused_must_use)]
-
 extern crate cranelift_codegen;
 extern crate cranelift_wasm;
 #[macro_use]
 extern crate target_lexicon;
 #[macro_use]
 extern crate log;
 extern crate env_logger;
 
--- a/js/src/wasm/cranelift/src/utils.rs
+++ b/js/src/wasm/cranelift/src/utils.rs
@@ -9,17 +9,16 @@
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 /// Helpers common to other source files here.
-use std;
 use std::error;
 use std::fmt;
 
 type DashError = Box<error::Error>;
 pub type DashResult<T> = Result<T, DashError>;
 
 /// A simple error type that contains a string message, used to wrap raw Cranelift error types
 /// which don't implement std::error::Error.
--- a/js/src/wasm/cranelift/src/wasm2clif.rs
+++ b/js/src/wasm/cranelift/src/wasm2clif.rs
@@ -22,22 +22,21 @@ use baldrdash as bd;
 use compile::{symbolic_function_name, wasm_function_name};
 use cranelift_codegen::cursor::{Cursor, FuncCursor};
 use cranelift_codegen::entity::{EntityRef, PrimaryMap, SecondaryMap};
 use cranelift_codegen::ir;
 use cranelift_codegen::ir::condcodes::IntCC;
 use cranelift_codegen::ir::InstBuilder;
 use cranelift_codegen::isa::{CallConv, TargetFrontendConfig, TargetIsa};
 use cranelift_codegen::packed_option::PackedOption;
-use cranelift_codegen::settings::Flags;
 use cranelift_wasm::{
-    self, FuncIndex, GlobalIndex, MemoryIndex, ReturnMode, SignatureIndex, TableIndex, WasmResult,
+    FuncEnvironment, FuncIndex, GlobalIndex, GlobalVariable, MemoryIndex, ReturnMode,
+    SignatureIndex, TableIndex, WasmResult,
 };
 use std::collections::HashMap;
-use target_lexicon::Triple;
 
 /// Get the integer type used for representing pointers on this platform.
 fn native_pointer_type() -> ir::Type {
     if cfg!(target_pointer_width = "64") {
         ir::types::I64
     } else {
         ir::types::I32
     }
@@ -368,38 +367,34 @@ impl<'a, 'b, 'c> TransEnv<'a, 'b, 'c> {
             gv_addr,
             offset32(self.static_env.realmFuncImportTlsOffset),
         );
         pos.ins()
             .store(flags, realm, cx, offset32(self.static_env.realmCxOffset));
     }
 }
 
-impl<'a, 'b, 'c> cranelift_wasm::FuncEnvironment for TransEnv<'a, 'b, 'c> {
+impl<'a, 'b, 'c> FuncEnvironment for TransEnv<'a, 'b, 'c> {
     fn target_config(&self) -> TargetFrontendConfig {
         self.isa.frontend_config()
     }
 
     fn pointer_type(&self) -> ir::Type {
         native_pointer_type()
     }
 
-    fn make_global(
-        &mut self,
-        func: &mut ir::Function,
-        index: GlobalIndex,
-    ) -> cranelift_wasm::GlobalVariable {
+    fn make_global(&mut self, func: &mut ir::Function, index: GlobalIndex) -> GlobalVariable {
         let global = self.env.global(index);
         if global.is_constant() {
             // Constant globals have a known value at compile time. We insert an instruction to
             // materialize the constant at the front of the entry block.
             let mut pos = FuncCursor::new(func);
             pos.next_ebb().expect("empty function");
             pos.next_inst();
-            cranelift_wasm::GlobalVariable::Const(global.emit_constant(&mut pos))
+            GlobalVariable::Const(global.emit_constant(&mut pos))
         } else {
             // This is a global variable. Here we don't care if it is mutable or not.
             let offset = global.tls_offset();
             let mut gv = self.get_vmctx_gv(func);
 
             // Some globals are represented as a pointer to the actual data, in which case we
             // must do an extra dereference to get to them.
             if global.is_indirect() {
@@ -414,17 +409,17 @@ impl<'a, 'b, 'c> cranelift_wasm::FuncEnv
                     base: gv,
                     offset: imm64(offset),
                     global_type: native_pointer_type(),
                 });
             }
 
             // Create a Cranelift global variable. We don't need to remember the reference, the
             // function translator does that for us.
-            cranelift_wasm::GlobalVariable::Memory {
+            GlobalVariable::Memory {
                 gv,
                 ty: global.value_type().into(),
             }
         }
     }
 
     fn make_heap(&mut self, func: &mut ir::Function, index: MemoryIndex) -> ir::Heap {
         assert_eq!(index.index(), 0, "Only one WebAssembly memory supported");
@@ -684,33 +679,32 @@ impl<'a, 'b, 'c> cranelift_wasm::FuncEnv
                 .Call(ir::Opcode::Call, ir::types::INVALID, callee, args)
                 .0)
         }
     }
 
     fn translate_memory_grow(
         &mut self,
         mut pos: FuncCursor,
-        index: MemoryIndex,
-        heap: ir::Heap,
+        _index: MemoryIndex,
+        _heap: ir::Heap,
         val: ir::Value,
     ) -> WasmResult<ir::Value> {
-        use cranelift_codegen::ir::types::I32;
         // We emit a call to `uint32_t growMemory_i32(Instance* instance, uint32_t delta)` via a
         // stub.
         let (fnref, sigref) =
             self.symbolic_funcref(pos.func, bd::SymbolicAddress::GrowMemory, || {
                 let mut sig = ir::Signature::new(CallConv::Baldrdash);
                 sig.params.push(ir::AbiParam::new(native_pointer_type()));
-                sig.params.push(ir::AbiParam::new(I32).uext());
+                sig.params.push(ir::AbiParam::new(ir::types::I32).uext());
                 sig.params.push(ir::AbiParam::special(
                     native_pointer_type(),
                     ir::ArgumentPurpose::VMContext,
                 ));
-                sig.returns.push(ir::AbiParam::new(I32).uext());
+                sig.returns.push(ir::AbiParam::new(ir::types::I32).uext());
                 sig
             });
 
         // Get the instance pointer needed by `growMemory_i32`.
         let instance = self.load_instance(&mut pos);
         let vmctx = pos
             .func
             .special_param(ir::ArgumentPurpose::VMContext)
@@ -723,30 +717,29 @@ impl<'a, 'b, 'c> cranelift_wasm::FuncEnv
             .call_indirect(sigref, addr, &[instance, val, vmctx]);
         self.switch_to_wasm_tls_realm(&mut pos);
         Ok(pos.func.dfg.first_result(call))
     }
 
     fn translate_memory_size(
         &mut self,
         mut pos: FuncCursor,
-        index: MemoryIndex,
-        heap: ir::Heap,
+        _index: MemoryIndex,
+        _heap: ir::Heap,
     ) -> WasmResult<ir::Value> {
-        use cranelift_codegen::ir::types::I32;
         // We emit a call to `uint32_t currentMemory_i32(Instance* instance)` via a stub.
         let (fnref, sigref) =
             self.symbolic_funcref(pos.func, bd::SymbolicAddress::CurrentMemory, || {
                 let mut sig = ir::Signature::new(CallConv::Baldrdash);
                 sig.params.push(ir::AbiParam::new(native_pointer_type()));
                 sig.params.push(ir::AbiParam::special(
                     native_pointer_type(),
                     ir::ArgumentPurpose::VMContext,
                 ));
-                sig.returns.push(ir::AbiParam::new(I32).uext());
+                sig.returns.push(ir::AbiParam::new(ir::types::I32).uext());
                 sig
             });
 
         // Get the instance pointer needed by `currentMemory_i32`.
         let instance = self.load_instance(&mut pos);
         let vmctx = pos
             .func
             .special_param(ir::ArgumentPurpose::VMContext)
@@ -790,30 +783,15 @@ impl TableInfo {
             base: vmctx,
             offset,
             global_type: native_pointer_type(),
         });
 
         TableInfo { global }
     }
 
-    /// Load the table length.
-    pub fn load_length(&self, pos: &mut FuncCursor, addr: ir::Value) -> ir::Value {
-        pos.ins().load(ir::types::I32, ir::MemFlags::new(), addr, 0)
-    }
-
-    /// Load the table base.
-    pub fn load_base(&self, pos: &mut FuncCursor, addr: ir::Value) -> ir::Value {
-        pos.ins().load(
-            native_pointer_type(),
-            ir::MemFlags::new(),
-            addr,
-            native_pointer_size(),
-        )
-    }
-
     /// 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
     }
 }