Skip to content

Commit

Permalink
Clippy fixes (#692)
Browse files Browse the repository at this point in the history
  • Loading branch information
XAMPPRocky authored and sunfishcode committed Dec 24, 2019
1 parent 6c97cfe commit 907e7aa
Show file tree
Hide file tree
Showing 35 changed files with 391 additions and 418 deletions.
8 changes: 5 additions & 3 deletions crates/api/src/externals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl Func {
} else {
panic!("expected function export")
};
let callable = WasmtimeFn::new(store, instance_handle, export.clone());
let callable = WasmtimeFn::new(store, instance_handle, export);
Func::from_wrapped(store, ty, Rc::new(callable))
}
}
Expand Down Expand Up @@ -435,8 +435,10 @@ impl Memory {
}
}

// Marked unsafe due to posibility that wasmtime can resize internal memory
// from other threads.
/// Returns a mutable slice the current memory.
/// # Safety
/// Marked unsafe due to posibility that wasmtime can resize internal memory
/// from other threads.
pub unsafe fn data(&self) -> &mut [u8] {
let definition = &*self.wasmtime_memory_definition();
slice::from_raw_parts_mut(definition.base, definition.current_length)
Expand Down
8 changes: 5 additions & 3 deletions crates/api/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn into_memory_type(mt: wasmparser::MemoryType) -> MemoryType {
MemoryType::new(Limits::new(mt.limits.initial, mt.limits.maximum))
}

fn into_global_type(gt: &wasmparser::GlobalType) -> GlobalType {
fn into_global_type(gt: wasmparser::GlobalType) -> GlobalType {
let mutability = if gt.mutable {
Mutability::Var
} else {
Expand All @@ -24,6 +24,8 @@ fn into_global_type(gt: &wasmparser::GlobalType) -> GlobalType {
GlobalType::new(into_valtype(&gt.content_type), mutability)
}

// `into_valtype` is used for `map` which requires `&T`.
#[allow(clippy::trivially_copy_pass_by_ref)]
fn into_valtype(ty: &wasmparser::Type) -> ValType {
use wasmparser::Type::*;
match ty {
Expand Down Expand Up @@ -91,7 +93,7 @@ fn read_imports_and_exports(binary: &[u8]) -> Result<(Box<[ImportType]>, Box<[Ex
let section = section.get_global_section_reader()?;
globals.reserve_exact(section.get_count() as usize);
for entry in section {
globals.push(into_global_type(&entry?.ty));
globals.push(into_global_type(entry?.ty));
}
}
SectionCode::Table => {
Expand Down Expand Up @@ -123,7 +125,7 @@ fn read_imports_and_exports(binary: &[u8]) -> Result<(Box<[ImportType]>, Box<[Ex
ExternType::Memory(memory)
}
ImportSectionEntryType::Global(gt) => {
let global = into_global_type(&gt);
let global = into_global_type(gt);
globals.push(global.clone());
ExternType::Global(global)
}
Expand Down
16 changes: 7 additions & 9 deletions crates/api/src/trampoline/create_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,14 @@ pub(crate) fn create_handle(

// Compute indices into the shared signature table.
let signatures = signature_registry
.and_then(|mut signature_registry| {
Some(
module
.signatures
.values()
.map(|sig| signature_registry.register_wasmtime_signature(sig))
.collect::<PrimaryMap<_, _>>(),
)
.map(|mut signature_registry| {
module
.signatures
.values()
.map(|sig| signature_registry.register_wasmtime_signature(sig))
.collect::<PrimaryMap<_, _>>()
})
.unwrap_or_else(|| PrimaryMap::new());
.unwrap_or_else(PrimaryMap::new);

Ok(InstanceHandle::new(
Rc::new(module),
Expand Down
6 changes: 3 additions & 3 deletions crates/api/src/trampoline/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ unsafe extern "C" fn stub_fn(vmctx: *mut VMContext, call_id: u32, values_vec: *m

match func.call(&args, &mut returns) {
Ok(()) => {
for i in 0..returns_len {
for (i, r#return) in returns.iter_mut().enumerate() {
// TODO check signature.returns[i].value_type ?
returns[i].write_value_to(values_vec.add(i));
r#return.write_value_to(values_vec.add(i));
}
0
}
Expand Down Expand Up @@ -172,7 +172,7 @@ fn make_trampoline(

let callee_args = vec![vmctx_ptr_val, call_id_val, values_vec_ptr_val];

let new_sig = builder.import_signature(stub_sig.clone());
let new_sig = builder.import_signature(stub_sig);

let callee_value = builder
.ins()
Expand Down
6 changes: 3 additions & 3 deletions crates/api/src/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ impl Callable for wasm_func_callback_t {
let mut out_results = vec![wasm_val_t::default(); results.len()];
let func = self.expect("wasm_func_callback_t fn");
let out = unsafe { func(params.as_ptr(), out_results.as_mut_ptr()) };
if out != ptr::null_mut() {
if !out.is_null() {
let trap: Box<wasm_trap_t> = unsafe { Box::from_raw(out) };
return Err((*trap).into());
}
Expand Down Expand Up @@ -579,7 +579,7 @@ impl Callable for CallbackWithEnv {
let mut out_results = vec![wasm_val_t::default(); results.len()];
let func = self.callback.expect("wasm_func_callback_with_env_t fn");
let out = unsafe { func(self.env, params.as_ptr(), out_results.as_mut_ptr()) };
if out != ptr::null_mut() {
if !out.is_null() {
let trap: Box<wasm_trap_t> = unsafe { Box::from_raw(out) };
return Err((*trap).into());
}
Expand Down Expand Up @@ -827,7 +827,7 @@ pub unsafe extern "C" fn wasm_func_new_with_env(
#[no_mangle]
pub unsafe extern "C" fn wasm_val_copy(out: *mut wasm_val_t, source: *const wasm_val_t) {
*out = match into_valtype((*source).kind) {
ValType::I32 | ValType::I64 | ValType::F32 | ValType::F64 => (*source).clone(),
ValType::I32 | ValType::I64 | ValType::F32 | ValType::F64 => *source,
_ => unimplemented!("wasm_val_copy arg"),
};
}
Expand Down
4 changes: 2 additions & 2 deletions crates/debug/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl SymbolResolver for FunctionRelocResolver {
pub fn emit_debugsections(
obj: &mut Artifact,
vmctx_info: &ModuleVmctxInfo,
target_config: &TargetFrontendConfig,
target_config: TargetFrontendConfig,
debuginfo_data: &DebugInfoData,
at: &ModuleAddressMap,
ranges: &ValueLabelsRanges,
Expand All @@ -53,7 +53,7 @@ impl<'a> SymbolResolver for ImageRelocResolver<'a> {

pub fn emit_debugsections_image(
triple: Triple,
target_config: &TargetFrontendConfig,
target_config: TargetFrontendConfig,
debuginfo_data: &DebugInfoData,
vmctx_info: &ModuleVmctxInfo,
at: &ModuleAddressMap,
Expand Down
7 changes: 2 additions & 5 deletions crates/debug/src/transform/address_transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,8 @@ fn build_function_lookup(
active_ranges.push(range_index);
continue;
}
if last_wasm_pos.is_some() {
index.insert(
last_wasm_pos.unwrap(),
active_ranges.clone().into_boxed_slice(),
);
if let Some(position) = last_wasm_pos {
index.insert(position, active_ranges.clone().into_boxed_slice());
}
active_ranges.retain(|r| ranges[*r].wasm_end.cmp(&wasm_start) != std::cmp::Ordering::Less);
active_ranges.push(range_index);
Expand Down
4 changes: 2 additions & 2 deletions crates/debug/src/transform/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ where
}
found_expr
};
if found_single_expr.is_some() {
write::AttributeValue::Exprloc(found_single_expr.unwrap())
if let Some(expr) = found_single_expr {
write::AttributeValue::Exprloc(expr)
} else if is_exprloc_to_loclist_allowed(attr.name()) {
// Converting exprloc to loclist.
let mut locs = Vec::new();
Expand Down
8 changes: 4 additions & 4 deletions crates/debug/src/transform/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ where
assert_eq!(ty, 0);
let index = pc.read_sleb128()?;
pc.read_u8()?; // consume 159
if code_chunk.len() > 0 {
if !code_chunk.is_empty() {
parts.push(CompiledExpressionPart::Code(code_chunk));
code_chunk = Vec::new();
}
Expand All @@ -338,7 +338,7 @@ where
need_deref = false;
}
Operation::Deref { .. } => {
if code_chunk.len() > 0 {
if !code_chunk.is_empty() {
parts.push(CompiledExpressionPart::Code(code_chunk));
code_chunk = Vec::new();
}
Expand All @@ -353,14 +353,14 @@ where
}
}

if code_chunk.len() > 0 {
if !code_chunk.is_empty() {
parts.push(CompiledExpressionPart::Code(code_chunk));
}

if base_len > 0 && base_len + 1 < parts.len() {
// see if we can glue two code chunks
if let [CompiledExpressionPart::Code(cc1), CompiledExpressionPart::Code(cc2)] =
&parts[base_len..base_len + 1]
&parts[base_len..=base_len]
{
let mut combined = cc1.clone();
combined.extend_from_slice(cc2);
Expand Down
2 changes: 1 addition & 1 deletion crates/debug/src/transform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ where
}

pub fn transform_dwarf(
target_config: &TargetFrontendConfig,
target_config: TargetFrontendConfig,
di: &DebugInfoData,
at: &ModuleAddressMap,
vmctx_info: &ModuleVmctxInfo,
Expand Down
6 changes: 3 additions & 3 deletions crates/debug/src/transform/range_info_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ impl RangeInfoBuilder {
result.push((range.begin, range.end));
}

Ok(if result.len() > 0 {
RangeInfoBuilder::Ranges(result)
} else {
Ok(if result.is_empty() {
RangeInfoBuilder::Undefined
} else {
RangeInfoBuilder::Ranges(result)
})
}

Expand Down
58 changes: 26 additions & 32 deletions crates/debug/src/transform/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,37 +51,34 @@ where
R: Reader,
{
// FIXME remove recursion.
match type_entry.attr_value(gimli::DW_AT_type)? {
Some(AttributeValue::UnitRef(ref offset)) => {
let mut entries = unit.entries_at_offset(*offset)?;
entries.next_entry()?;
if let Some(die) = entries.current() {
if let Some(AttributeValue::DebugStrRef(str_offset)) =
die.attr_value(gimli::DW_AT_name)?
{
return Ok(String::from(
context.debug_str.get_str(str_offset)?.to_string()?,
));
if let Some(AttributeValue::UnitRef(ref offset)) = type_entry.attr_value(gimli::DW_AT_type)? {
let mut entries = unit.entries_at_offset(*offset)?;
entries.next_entry()?;
if let Some(die) = entries.current() {
if let Some(AttributeValue::DebugStrRef(str_offset)) =
die.attr_value(gimli::DW_AT_name)?
{
return Ok(String::from(
context.debug_str.get_str(str_offset)?.to_string()?,
));
}
match die.tag() {
gimli::DW_TAG_const_type => {
return Ok(format!("const {}", get_base_type_name(die, unit, context)?));
}
gimli::DW_TAG_pointer_type => {
return Ok(format!("{}*", get_base_type_name(die, unit, context)?));
}
match die.tag() {
gimli::DW_TAG_const_type => {
return Ok(format!("const {}", get_base_type_name(die, unit, context)?));
}
gimli::DW_TAG_pointer_type => {
return Ok(format!("{}*", get_base_type_name(die, unit, context)?));
}
gimli::DW_TAG_reference_type => {
return Ok(format!("{}&", get_base_type_name(die, unit, context)?));
}
gimli::DW_TAG_array_type => {
return Ok(format!("{}[]", get_base_type_name(die, unit, context)?));
}
_ => (),
gimli::DW_TAG_reference_type => {
return Ok(format!("{}&", get_base_type_name(die, unit, context)?));
}
gimli::DW_TAG_array_type => {
return Ok(format!("{}[]", get_base_type_name(die, unit, context)?));
}
_ => (),
}
}
_ => (),
};
}
Ok(String::from("??"))
}

Expand Down Expand Up @@ -121,11 +118,8 @@ where
gimli::DW_AT_type,
write::AttributeValue::ThisUnitEntryRef(wp_die_id),
);
match entry.attr_value(gimli::DW_AT_type)? {
Some(AttributeValue::UnitRef(ref offset)) => {
pending_die_refs.push((p_die_id, gimli::DW_AT_type, *offset))
}
_ => (),
if let Some(AttributeValue::UnitRef(ref offset)) = entry.attr_value(gimli::DW_AT_type)? {
pending_die_refs.push((p_die_id, gimli::DW_AT_type, *offset))
}

let m_die_id = comp_unit.add(die_id, gimli::DW_TAG_member);
Expand Down
13 changes: 7 additions & 6 deletions crates/environ/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ struct ModuleCacheEntryInner<'config, 'worker> {
worker: &'worker Worker,
}

/// Cached compilation data of a Wasm module.
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)]
pub struct ModuleCacheData {
compilation: Compilation,
Expand All @@ -66,7 +67,8 @@ pub struct ModuleCacheData {
traps: Traps,
}

type ModuleCacheDataTupleType = (
/// A type alias over the module cache data as a tuple.
pub type ModuleCacheDataTupleType = (
Compilation,
Relocations,
ModuleAddressMap,
Expand Down Expand Up @@ -102,7 +104,7 @@ impl<'config, 'worker> ModuleCacheEntry<'config, 'worker> {
}

#[cfg(test)]
fn from_inner<'data>(inner: ModuleCacheEntryInner<'config, 'worker>) -> Self {
fn from_inner(inner: ModuleCacheEntryInner<'config, 'worker>) -> Self {
Self(Some(inner))
}

Expand All @@ -119,10 +121,9 @@ impl<'config, 'worker> ModuleCacheEntry<'config, 'worker> {

pub fn update_data(&self, data: &ModuleCacheData) {
if let Some(inner) = &self.0 {
inner.update_data(data).map(|val| {
if inner.update_data(data).is_some() {
inner.worker.on_cache_update_async(&inner.mod_cache_path); // call on success
val
});
}
}
}
}
Expand Down Expand Up @@ -236,7 +237,7 @@ impl ModuleCacheData {
}
}

pub fn to_tuple(self) -> ModuleCacheDataTupleType {
pub fn into_tuple(self) -> ModuleCacheDataTupleType {
(
self.compilation,
self.relocations,
Expand Down
4 changes: 2 additions & 2 deletions crates/environ/src/cache/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ pub fn create_new_config<P: AsRef<Path> + Debug>(
)?;

if config_file.exists() {
Err(format!(
return Err(format!(
"Specified config file already exists! Path: {}",
config_file.display()
))?;
));
}

let parent_dir = config_file
Expand Down
Loading

0 comments on commit 907e7aa

Please sign in to comment.