Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Another round of fixing warnings. #4888

Merged
merged 2 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sway-core/src/abi_generation/evm_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ pub fn abi_param_type(
}
}

pub(self) fn generate_abi_function(
fn generate_abi_function(
fn_decl: &TyFunctionDecl,
type_engine: &TypeEngine,
decl_engine: &DeclEngine,
Expand Down Expand Up @@ -230,7 +230,7 @@ pub(self) fn generate_abi_function(
})
}

pub(self) fn abi_str_type_arg(
fn abi_str_type_arg(
type_arg: &TypeArgument,
type_engine: &TypeEngine,
decl_engine: &DeclEngine,
Expand Down
2 changes: 1 addition & 1 deletion sway-core/src/asm_generation/fuel/data_section.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl Entry {
Datum::ByteArray(bs) if bs.len() % 8 == 0 => bs.clone(),
Datum::ByteArray(bs) => bs
.iter()
.chain(vec![0; 8].iter())
.chain([0; 8].iter())
.copied()
.take((bs.len() + 7) & 0xfffffff8_usize)
.collect(),
Expand Down
192 changes: 94 additions & 98 deletions sway-core/src/asm_generation/fuel/fuel_asm_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,11 @@ impl<'ir, 'eng> FuelAsmBuilder<'ir, 'eng> {
) -> Result<(), ErrorEmitted> {
let Some(instruction) = instr_val.get_instruction(self.context) else {
return Err(handler.emit_err(CompileError::Internal(
"Value not an instruction.",
self.md_mgr
.val_to_span(self.context, *instr_val)
.unwrap_or_else(Span::dummy), )));
"Value not an instruction.",
self.md_mgr
.val_to_span(self.context, *instr_val)
.unwrap_or_else(Span::dummy),
)));
};

// The only instruction whose compilation returns a Result itself is AsmBlock, which
Expand Down Expand Up @@ -697,101 +698,96 @@ impl<'ir, 'eng> FuelAsmBuilder<'ir, 'eng> {
// until then we can keep track of the constant values and add them once.

let base_reg = self.value_to_register(base_val)?;
let (base_reg, const_offs, _) =
indices
.iter()
.fold(Ok((base_reg, 0, base_type)), |acc, idx_val| {
// So we're folding to a Result, as unwrapping the constants can fail.
acc.and_then(|(reg, offs, elem_ty)| {
// If we find a constant index then we add its offset to `offs`. Otherwise we grab
// its value, which should be compiled already, and add it to reg.
if elem_ty.is_struct(self.context) {
// For structs the index must be a const uint.
unwrap_constant_uint(idx_val).map(|idx| {
let field_types = elem_ty.get_field_types(self.context);
let field_type = field_types[idx];
let field_offs_in_bytes = field_types
.iter()
.take(idx)
.map(|field_ty| ir_type_size_in_bytes(self.context, field_ty))
.sum::<u64>();
(reg, offs + field_offs_in_bytes, field_type)
})
} else if elem_ty.is_union(self.context) {
// For unions the index must also be a const uint.
unwrap_constant_uint(idx_val).map(|idx| {
let field_type = elem_ty.get_field_types(self.context)[idx];
let union_size_in_bytes =
ir_type_size_in_bytes(self.context, &elem_ty);
let field_size_in_bytes =
ir_type_size_in_bytes(self.context, &field_type);

// The union fields are at offset (union_size - variant_size) due to left padding.
(
reg,
offs + union_size_in_bytes - field_size_in_bytes,
field_type,
)
})
} else if elem_ty.is_array(self.context) {
// For arrays the index is a value. We need to fetch it and add it to
// the base.
let array_elem_ty =
elem_ty.get_array_elem_type(self.context).ok_or_else(|| {
CompileError::Internal(
"Failed to get elem type for known array",
owning_span.clone().unwrap_or_else(Span::dummy),
)
})?;
let array_elem_size =
ir_type_size_in_bytes(self.context, &array_elem_ty);
let size_reg = self.reg_seqr.next();
self.immediate_to_reg(
array_elem_size,
size_reg.clone(),
None,
"get size of element",
owning_span.clone(),
);

let index_reg = self.value_to_register(idx_val)?;
let offset_reg = self.reg_seqr.next();

self.cur_bytecode.push(Op {
opcode: Either::Left(VirtualOp::MUL(
offset_reg.clone(),
index_reg,
size_reg,
)),
comment: "get offset to array element".into(),
owning_span: owning_span.clone(),
});
self.cur_bytecode.push(Op {
opcode: Either::Left(VirtualOp::ADD(
offset_reg.clone(),
reg,
offset_reg.clone(),
)),
comment: "add to array base".into(),
owning_span: owning_span.clone(),
});
let member_type =
elem_ty.get_array_elem_type(self.context).ok_or_else(|| {
CompileError::Internal(
"Can't get array elem type for GEP.",
sway_types::span::Span::dummy(),
)
})?;

Ok((offset_reg, offs, member_type))
} else {
Err(CompileError::Internal(
"Cannot get element offset in non-aggregate.",
sway_types::span::Span::dummy(),
))
}
let (base_reg, const_offs, _) = indices.iter().try_fold(
(base_reg, 0, base_type),
|(reg, offs, elem_ty), idx_val| {
// So we're folding to a Result, as unwrapping the constants can fail.
// If we find a constant index then we add its offset to `offs`. Otherwise we grab
// its value, which should be compiled already, and add it to reg.
if elem_ty.is_struct(self.context) {
// For structs the index must be a const uint.
unwrap_constant_uint(idx_val).map(|idx| {
let field_types = elem_ty.get_field_types(self.context);
let field_type = field_types[idx];
let field_offs_in_bytes = field_types
.iter()
.take(idx)
.map(|field_ty| ir_type_size_in_bytes(self.context, field_ty))
.sum::<u64>();
(reg, offs + field_offs_in_bytes, field_type)
})
})?;
} else if elem_ty.is_union(self.context) {
// For unions the index must also be a const uint.
unwrap_constant_uint(idx_val).map(|idx| {
let field_type = elem_ty.get_field_types(self.context)[idx];
let union_size_in_bytes = ir_type_size_in_bytes(self.context, &elem_ty);
let field_size_in_bytes = ir_type_size_in_bytes(self.context, &field_type);

// The union fields are at offset (union_size - variant_size) due to left padding.
(
reg,
offs + union_size_in_bytes - field_size_in_bytes,
field_type,
)
})
} else if elem_ty.is_array(self.context) {
// For arrays the index is a value. We need to fetch it and add it to
// the base.
let array_elem_ty =
elem_ty.get_array_elem_type(self.context).ok_or_else(|| {
CompileError::Internal(
"Failed to get elem type for known array",
owning_span.clone().unwrap_or_else(Span::dummy),
)
})?;
let array_elem_size = ir_type_size_in_bytes(self.context, &array_elem_ty);
let size_reg = self.reg_seqr.next();
self.immediate_to_reg(
array_elem_size,
size_reg.clone(),
None,
"get size of element",
owning_span.clone(),
);

let index_reg = self.value_to_register(idx_val)?;
let offset_reg = self.reg_seqr.next();

self.cur_bytecode.push(Op {
opcode: Either::Left(VirtualOp::MUL(
offset_reg.clone(),
index_reg,
size_reg,
)),
comment: "get offset to array element".into(),
owning_span: owning_span.clone(),
});
self.cur_bytecode.push(Op {
opcode: Either::Left(VirtualOp::ADD(
offset_reg.clone(),
reg,
offset_reg.clone(),
)),
comment: "add to array base".into(),
owning_span: owning_span.clone(),
});
let member_type =
elem_ty.get_array_elem_type(self.context).ok_or_else(|| {
CompileError::Internal(
"Can't get array elem type for GEP.",
sway_types::span::Span::dummy(),
)
})?;

Ok((offset_reg, offs, member_type))
} else {
Err(CompileError::Internal(
"Cannot get element offset in non-aggregate.",
sway_types::span::Span::dummy(),
))
}
},
)?;

if const_offs == 0 {
// No need to add anything.
Expand Down
2 changes: 1 addition & 1 deletion sway-core/src/asm_generation/fuel/register_allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ pub(crate) fn create_interference_graph(
.fold(BTreeSet::new(), |mut tree, elem| {
let mut regs = elem.registers();
regs.retain(|&reg| reg.is_virtual());
tree.extend(regs.into_iter());
tree.extend(regs);
tree
})
.iter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ impl<'ir, 'eng> MidenVMAsmBuilder<'ir, 'eng> {

fn copy_contract_code_to_memory(
&self,
s: &mut MidenVMAsmSection,
s: &MidenVMAsmSection,
data_size: u32,
data_offset: u32,
) {
Expand Down
2 changes: 1 addition & 1 deletion sway-core/src/asm_generation/programs/abstract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl AbstractProgram {
.entries
.into_iter()
.map(|entry| entry.ops)
.chain(self.non_entries.into_iter())
.chain(self.non_entries)
.map(AbstractInstructionSet::optimize)
.map(AbstractInstructionSet::verify)
.collect::<Result<Vec<_>, _>>()?;
Expand Down
5 changes: 1 addition & 4 deletions sway-core/src/asm_generation/programs/final.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,7 @@ impl std::fmt::Display for FinalProgram {
.collect::<Vec<_>>();
separator.push_all(concretized_ops);

let basic_blocks = separator
.take()
.into_iter()
.chain(separator.finish().into_iter());
let basic_blocks = separator.take().into_iter().chain(separator.finish());

for block in basic_blocks {
let mut offset = block.offset;
Expand Down
4 changes: 2 additions & 2 deletions sway-core/src/decl_engine/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl<T> DeclId<T> {
impl<T> Copy for DeclId<T> {}
impl<T> Clone for DeclId<T> {
fn clone(&self) -> Self {
Self(self.0, PhantomData)
*self
}
}

Expand All @@ -46,7 +46,7 @@ impl<T> PartialEq for DeclId<T> {
}
impl<T> PartialOrd for DeclId<T> {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
self.0.partial_cmp(&other.0)
Some(self.cmp(other))
}
}
impl<T> Ord for DeclId<T> {
Expand Down
6 changes: 3 additions & 3 deletions sway-core/src/ir_generation/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,7 @@ impl<'eng> FnCompiler<'eng> {
.add_metadatum(context, span_md_idx);
compiled_args
.into_iter()
.zip(field_types.into_iter())
.zip(field_types)
.enumerate()
.for_each(|(insert_idx, (field_val, field_type))| {
let gep_val = self
Expand Down Expand Up @@ -2133,7 +2133,7 @@ impl<'eng> FnCompiler<'eng> {
// Fill it in.
insert_values
.into_iter()
.zip(field_types.into_iter())
.zip(field_types)
.enumerate()
.for_each(|(insert_idx, (insert_val, field_type))| {
let gep_val = self.current_block.ins(context).get_elem_ptr_with_idx(
Expand Down Expand Up @@ -2328,7 +2328,7 @@ impl<'eng> FnCompiler<'eng> {

init_values
.into_iter()
.zip(init_types.into_iter())
.zip(init_types)
.enumerate()
.for_each(|(insert_idx, (field_val, field_type))| {
let gep_val = self
Expand Down
4 changes: 2 additions & 2 deletions sway-core/src/language/parsed/expression/scrutinee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ impl Scrutinee {
_ => vec![],
})
.collect::<Vec<TypeInfo>>();
vec![name, fields].concat()
[name, fields].concat()
}
Scrutinee::EnumScrutinee {
call_path, value, ..
Expand All @@ -162,7 +162,7 @@ impl Scrutinee {
type_arguments: None,
}];
let value = value.gather_approximate_typeinfo_dependencies();
vec![name, value].concat()
[name, value].concat()
}
Scrutinee::Tuple { elems, .. } | Scrutinee::Or { elems, .. } => elems
.iter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,7 @@ impl UpdateConstantExpression for TyExpressionVariant {
fn find_const_decl_from_impl(
implementing_type: &TyDecl,
decl_engine: &DeclEngine,
const_decl: &mut Box<TyConstantDecl>,
const_decl: &TyConstantDecl,
) -> Option<TyConstantDecl> {
match implementing_type {
TyDecl::ImplTrait(ImplTrait { decl_id, .. }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ impl Pattern {
fields: struct_pattern
.fields
.iter()
.zip(args.into_iter())
.zip(args)
.map(|((name, _), arg)| (name.clone(), arg))
.collect::<Vec<_>>(),
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl ty::TyExpression {
let args_and_names = method
.parameters
.into_iter()
.zip(arguments.into_iter())
.zip(arguments)
.map(|(param, arg)| (param.name, arg))
.collect::<Vec<(_, _)>>();
let exp = ty::TyExpression {
Expand Down
2 changes: 1 addition & 1 deletion sway-core/src/semantic_analysis/namespace/trait_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ impl TraitMap {
Ok(pos) => self.trait_impls[pos]
.value
.trait_items
.extend(oe.value.trait_items.into_iter()),
.extend(oe.value.trait_items),
Err(pos) => self.trait_impls.insert(pos, oe),
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1599,7 +1599,7 @@ fn method_call_fields_to_method_application_expression(
.collect::<Result<_, _>>()?,
};
let arguments = iter::once(*target)
.chain(args.into_inner().into_iter())
.chain(args.into_inner())
.map(|expr| expr_to_expression(context, handler, engines, expr))
.collect::<Result<_, _>>()?;
Ok(Box::new(MethodApplicationExpression {
Expand Down Expand Up @@ -4140,7 +4140,7 @@ fn error_if_self_param_is_not_allowed(
/// Walks all the cfg attributes in a map, evaluating them
/// and returning false if any evaluated to false.
pub fn cfg_eval(
context: &mut Context,
context: &Context,
handler: &Handler,
attrs_map: &AttributesMap,
) -> Result<bool, ErrorEmitted> {
Expand Down
Loading