mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 19:58:18 +00:00
auto clippy fixes
This commit is contained in:
parent
72c85efc83
commit
ef39bad7c6
146 changed files with 750 additions and 1005 deletions
|
@ -34,10 +34,7 @@ pub fn call_bitcode_fn<'ctx>(
|
|||
.try_as_basic_value()
|
||||
.left()
|
||||
.unwrap_or_else(|| {
|
||||
panic!(
|
||||
"LLVM error: Did not get return value from bitcode function {:?}",
|
||||
fn_name
|
||||
)
|
||||
panic!("LLVM error: Did not get return value from bitcode function {fn_name:?}")
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -49,7 +46,7 @@ pub fn call_void_bitcode_fn<'ctx>(
|
|||
call_bitcode_fn_help(env, args, fn_name)
|
||||
.try_as_basic_value()
|
||||
.right()
|
||||
.unwrap_or_else(|| panic!("LLVM error: Tried to call void bitcode function, but got return value from bitcode function, {:?}", fn_name))
|
||||
.unwrap_or_else(|| panic!("LLVM error: Tried to call void bitcode function, but got return value from bitcode function, {fn_name:?}"))
|
||||
}
|
||||
|
||||
fn call_bitcode_fn_help<'ctx>(
|
||||
|
@ -63,7 +60,7 @@ fn call_bitcode_fn_help<'ctx>(
|
|||
let fn_val = env
|
||||
.module
|
||||
.get_function(fn_name)
|
||||
.unwrap_or_else(|| panic!("Unrecognized builtin function: {:?} - if you're working on the Roc compiler, do you need to rebuild the bitcode? See compiler/builtins/bitcode/README.md", fn_name));
|
||||
.unwrap_or_else(|| panic!("Unrecognized builtin function: {fn_name:?} - if you're working on the Roc compiler, do you need to rebuild the bitcode? See compiler/builtins/bitcode/README.md"));
|
||||
|
||||
let call = env.builder.build_call(fn_val, &arguments, "call_builtin");
|
||||
|
||||
|
@ -378,9 +375,9 @@ fn build_rc_wrapper<'a, 'ctx>(
|
|||
.to_symbol_string(symbol, &env.interns);
|
||||
|
||||
let fn_name = match rc_operation {
|
||||
Mode::IncN => format!("{}_inc_n", fn_name),
|
||||
Mode::Inc => format!("{}_inc", fn_name),
|
||||
Mode::Dec => format!("{}_dec", fn_name),
|
||||
Mode::IncN => format!("{fn_name}_inc_n"),
|
||||
Mode::Inc => format!("{fn_name}_inc"),
|
||||
Mode::Dec => format!("{fn_name}_dec"),
|
||||
};
|
||||
|
||||
let function_value = match env.module.get_function(fn_name.as_str()) {
|
||||
|
|
|
@ -263,7 +263,7 @@ impl<'a, 'ctx, 'env> Env<'a, 'ctx, 'env> {
|
|||
let fn_val = self
|
||||
.module
|
||||
.get_function(intrinsic_name)
|
||||
.unwrap_or_else(|| panic!("Unrecognized intrinsic function: {}", intrinsic_name));
|
||||
.unwrap_or_else(|| panic!("Unrecognized intrinsic function: {intrinsic_name}"));
|
||||
|
||||
let mut arg_vals: Vec<BasicMetadataValueEnum> =
|
||||
Vec::with_capacity_in(args.len(), self.arena);
|
||||
|
@ -289,10 +289,7 @@ impl<'a, 'ctx, 'env> Env<'a, 'ctx, 'env> {
|
|||
let call = self.build_intrinsic_call(intrinsic_name, args);
|
||||
|
||||
call.try_as_basic_value().left().unwrap_or_else(|| {
|
||||
panic!(
|
||||
"LLVM error: Invalid call by name for intrinsic {}",
|
||||
intrinsic_name
|
||||
)
|
||||
panic!("LLVM error: Invalid call by name for intrinsic {intrinsic_name}")
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -498,17 +495,14 @@ pub fn module_from_builtins<'ctx>(
|
|||
} => {
|
||||
include_bytes!("../../../builtins/bitcode/builtins-windows-x86_64.bc")
|
||||
}
|
||||
_ => panic!(
|
||||
"The zig builtins are not currently built for this target: {:?}",
|
||||
target
|
||||
),
|
||||
_ => panic!("The zig builtins are not currently built for this target: {target:?}"),
|
||||
}
|
||||
};
|
||||
|
||||
let memory_buffer = MemoryBuffer::create_from_memory_range(bitcode_bytes, module_name);
|
||||
|
||||
let module = Module::parse_bitcode_from_buffer(&memory_buffer, ctx)
|
||||
.unwrap_or_else(|err| panic!("Unable to import builtins bitcode. LLVM error: {:?}", err));
|
||||
.unwrap_or_else(|err| panic!("Unable to import builtins bitcode. LLVM error: {err:?}"));
|
||||
|
||||
// Add LLVM intrinsics.
|
||||
add_intrinsics(ctx, &module);
|
||||
|
@ -766,7 +760,7 @@ pub fn build_exp_literal<'a, 'ctx>(
|
|||
LayoutRepr::Builtin(Builtin::Int(int_width)) => {
|
||||
int_with_precision(env, i128::from_ne_bytes(*bytes), int_width).into()
|
||||
}
|
||||
_ => panic!("Invalid layout for int literal = {:?}", layout),
|
||||
_ => panic!("Invalid layout for int literal = {layout:?}"),
|
||||
},
|
||||
|
||||
U128(bytes) => const_u128(env, u128::from_ne_bytes(*bytes)).into(),
|
||||
|
@ -775,7 +769,7 @@ pub fn build_exp_literal<'a, 'ctx>(
|
|||
LayoutRepr::Builtin(Builtin::Float(float_width)) => {
|
||||
float_with_precision(env, *float, float_width)
|
||||
}
|
||||
_ => panic!("Invalid layout for float literal = {:?}", layout),
|
||||
_ => panic!("Invalid layout for float literal = {layout:?}"),
|
||||
},
|
||||
|
||||
Decimal(bytes) => {
|
||||
|
@ -2056,7 +2050,7 @@ pub fn get_tag_id<'a, 'ctx>(
|
|||
|
||||
match union_layout {
|
||||
UnionLayout::NonRecursive(_) => {
|
||||
debug_assert!(argument.is_pointer_value(), "{:?}", argument);
|
||||
debug_assert!(argument.is_pointer_value(), "{argument:?}");
|
||||
|
||||
let argument_ptr = argument.into_pointer_value();
|
||||
get_tag_id_wrapped(env, layout_interner, *union_layout, argument_ptr)
|
||||
|
@ -3514,10 +3508,7 @@ fn build_switch_ir<'a, 'ctx>(
|
|||
layout_interner,
|
||||
layout_interner.get_repr(stored_layout)
|
||||
),
|
||||
"This switch matches on {:?}, but the matched-on symbol {:?} has layout {:?}",
|
||||
cond_layout,
|
||||
cond_symbol,
|
||||
stored_layout
|
||||
"This switch matches on {cond_layout:?}, but the matched-on symbol {cond_symbol:?} has layout {stored_layout:?}"
|
||||
);
|
||||
|
||||
let cont_block = context.append_basic_block(parent, "cont");
|
||||
|
@ -3623,7 +3614,7 @@ fn build_switch_ir<'a, 'ctx>(
|
|||
condition_int_type.const_int(*int, false)
|
||||
};
|
||||
|
||||
let block = context.append_basic_block(parent, format!("branch{}", int).as_str());
|
||||
let block = context.append_basic_block(parent, format!("branch{int}").as_str());
|
||||
|
||||
cases.push((int_val, block));
|
||||
}
|
||||
|
@ -4032,7 +4023,7 @@ fn expose_function_to_host_help_c_abi_gen_test<'a, 'ctx>(
|
|||
&[],
|
||||
);
|
||||
|
||||
let size_function_name: String = format!("roc__{}_size", ident_string);
|
||||
let size_function_name: String = format!("roc__{ident_string}_size");
|
||||
|
||||
let size_function = add_func(
|
||||
env.context,
|
||||
|
@ -4332,7 +4323,7 @@ fn expose_function_to_host_help_c_abi<'a, 'ctx>(
|
|||
roc_function,
|
||||
arguments,
|
||||
return_layout,
|
||||
&format!("{}_generic", c_function_name),
|
||||
&format!("{c_function_name}_generic"),
|
||||
);
|
||||
|
||||
let c_function = expose_function_to_host_help_c_abi_v2(
|
||||
|
@ -4351,7 +4342,7 @@ fn expose_function_to_host_help_c_abi<'a, 'ctx>(
|
|||
Some(env.context.i64_type().as_basic_type_enum()),
|
||||
&[],
|
||||
);
|
||||
let size_function_name: String = format!("{}_size", c_function_name);
|
||||
let size_function_name: String = format!("{c_function_name}_size");
|
||||
|
||||
let size_function = add_func(
|
||||
env.context,
|
||||
|
@ -4998,7 +4989,7 @@ pub fn build_procedures_expose_expects<'a>(
|
|||
let mut it = func_solutions.specs();
|
||||
let func_spec = match it.next() {
|
||||
Some(spec) => spec,
|
||||
None => panic!("no specialization for expect {}", symbol),
|
||||
None => panic!("no specialization for expect {symbol}"),
|
||||
};
|
||||
|
||||
debug_assert!(
|
||||
|
@ -5012,7 +5003,7 @@ pub fn build_procedures_expose_expects<'a>(
|
|||
|
||||
let name = roc_main_fn.get_name().to_str().unwrap();
|
||||
|
||||
let expect_name = &format!("Expect_{}", name);
|
||||
let expect_name = &format!("Expect_{name}");
|
||||
let expect_name = env.arena.alloc_str(expect_name);
|
||||
expect_names.push(&*expect_name);
|
||||
|
||||
|
@ -5024,7 +5015,7 @@ pub fn build_procedures_expose_expects<'a>(
|
|||
roc_main_fn,
|
||||
top_level.arguments,
|
||||
top_level.result,
|
||||
&format!("Expect_{}", name),
|
||||
&format!("Expect_{name}"),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -5051,7 +5042,7 @@ fn build_procedures_help<'a>(
|
|||
entry_point,
|
||||
it,
|
||||
) {
|
||||
Err(e) => panic!("Error in alias analysis: {}", e),
|
||||
Err(e) => panic!("Error in alias analysis: {e}"),
|
||||
Ok(solutions) => solutions,
|
||||
};
|
||||
|
||||
|
@ -5147,10 +5138,10 @@ fn func_spec_name<'a>(
|
|||
|
||||
let ident_string = symbol.as_str(interns);
|
||||
let module_string = interns.module_ids.get_name(symbol.module_id()).unwrap();
|
||||
write!(buf, "{}_{}_", module_string, ident_string).unwrap();
|
||||
write!(buf, "{module_string}_{ident_string}_").unwrap();
|
||||
|
||||
for byte in func_spec.0.iter() {
|
||||
write!(buf, "{:x?}", byte).unwrap();
|
||||
write!(buf, "{byte:x?}").unwrap();
|
||||
}
|
||||
|
||||
buf
|
||||
|
@ -5355,7 +5346,7 @@ fn build_closure_caller<'a, 'ctx>(
|
|||
// STEP 1: build function header
|
||||
|
||||
// e.g. `roc__mainForHost_0_caller` (def_name is `mainForHost_0`)
|
||||
let function_name = format!("roc__{}_caller", def_name);
|
||||
let function_name = format!("roc__{def_name}_caller");
|
||||
|
||||
let function_spec = FunctionSpec::cconv(env, CCReturn::Void, None, &argument_types);
|
||||
|
||||
|
@ -5467,9 +5458,9 @@ fn build_host_exposed_alias_size_help<'a, 'ctx>(
|
|||
let i64 = env.context.i64_type().as_basic_type_enum();
|
||||
let size_function_spec = FunctionSpec::cconv(env, CCReturn::Return, Some(i64), &[]);
|
||||
let size_function_name: String = if let Some(label) = opt_label {
|
||||
format!("roc__{}_{}_size", def_name, label)
|
||||
format!("roc__{def_name}_{label}_size")
|
||||
} else {
|
||||
format!("roc__{}_size", def_name,)
|
||||
format!("roc__{def_name}_size",)
|
||||
};
|
||||
|
||||
let size_function = add_func(
|
||||
|
@ -5604,10 +5595,7 @@ fn function_value_by_name_help<'a, 'ctx>(
|
|||
);
|
||||
eprintln!("Is the function defined? If so, maybe there is a problem with the layout");
|
||||
|
||||
panic!(
|
||||
"Unrecognized builtin function: {:?} (symbol: {:?})",
|
||||
fn_name, symbol,
|
||||
)
|
||||
panic!("Unrecognized builtin function: {fn_name:?} (symbol: {symbol:?})",)
|
||||
} else {
|
||||
// Unrecognized non-builtin function:
|
||||
eprintln!(
|
||||
|
@ -5618,10 +5606,7 @@ fn function_value_by_name_help<'a, 'ctx>(
|
|||
);
|
||||
eprintln!("Is the function defined? If so, maybe there is a problem with the layout");
|
||||
|
||||
panic!(
|
||||
"Unrecognized non-builtin function: {:?} (symbol: {:?})",
|
||||
fn_name, symbol,
|
||||
)
|
||||
panic!("Unrecognized non-builtin function: {fn_name:?} (symbol: {symbol:?})",)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -6282,7 +6267,7 @@ fn define_global_str_literal<'ctx>(
|
|||
message.hash(&mut hasher);
|
||||
let hash = hasher.finish();
|
||||
|
||||
format!("_str_literal_{}", hash)
|
||||
format!("_str_literal_{hash}")
|
||||
};
|
||||
|
||||
match module.get_global(&name) {
|
||||
|
@ -6383,7 +6368,7 @@ pub fn add_func<'ctx>(
|
|||
) -> FunctionValue<'ctx> {
|
||||
if cfg!(debug_assertions) {
|
||||
if let Some(func) = module.get_function(name) {
|
||||
panic!("Attempting to redefine LLVM function {}, which was already defined in this module as:\n\n{:#?}", name, func);
|
||||
panic!("Attempting to redefine LLVM function {name}, which was already defined in this module as:\n\n{func:#?}");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -329,8 +329,7 @@ fn build_neq<'a, 'ctx>(
|
|||
) -> BasicValueEnum<'ctx> {
|
||||
if lhs_layout != rhs_layout {
|
||||
panic!(
|
||||
"Inequality of different layouts; did you have a type mismatch?\n{:?} != {:?}",
|
||||
lhs_layout, rhs_layout
|
||||
"Inequality of different layouts; did you have a type mismatch?\n{lhs_layout:?} != {rhs_layout:?}"
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -789,7 +788,7 @@ fn build_struct_eq_help<'a, 'ctx>(
|
|||
.into_int_value()
|
||||
};
|
||||
|
||||
current = ctx.append_basic_block(parent, &format!("eq_step_{}", index));
|
||||
current = ctx.append_basic_block(parent, &format!("eq_step_{index}"));
|
||||
|
||||
env.builder
|
||||
.build_conditional_branch(are_equal, current, return_false);
|
||||
|
|
|
@ -2892,6 +2892,6 @@ fn load_symbol_and_lambda_set<'a, 'ctx>(
|
|||
let (ptr, layout) = scope.load_symbol_and_layout(symbol);
|
||||
match layout_interner.get_repr(layout) {
|
||||
LayoutRepr::LambdaSet(lambda_set) => (ptr, lambda_set),
|
||||
other => panic!("Not a lambda set: {:?}, {:?}", other, ptr),
|
||||
other => panic!("Not a lambda set: {other:?}, {ptr:?}"),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -132,7 +132,7 @@ impl<'ctx> PointerToRefcount<'ctx> {
|
|||
let block = env.builder.get_insert_block().expect("to be in a function");
|
||||
let di_location = env.builder.get_current_debug_location().unwrap();
|
||||
|
||||
let fn_name = &format!("decrement_refcounted_ptr_{}", alignment);
|
||||
let fn_name = &format!("decrement_refcounted_ptr_{alignment}");
|
||||
|
||||
let function = match env.module.get_function(fn_name) {
|
||||
Some(function_value) => function_value,
|
||||
|
@ -1398,7 +1398,7 @@ pub fn build_reset<'a, 'ctx>(
|
|||
let union_layout_repr = LayoutRepr::Union(union_layout);
|
||||
let layout_id = layout_ids.get(Symbol::DEC, &union_layout_repr);
|
||||
let fn_name = layout_id.to_symbol_string(Symbol::DEC, &env.interns);
|
||||
let fn_name = format!("{}_reset", fn_name);
|
||||
let fn_name = format!("{fn_name}_reset");
|
||||
|
||||
let dec_function = build_rec_union(env, layout_interner, layout_ids, Mode::Dec, union_layout);
|
||||
|
||||
|
|
|
@ -28,17 +28,14 @@ impl<'a, 'ctx> Scope<'a, 'ctx> {
|
|||
match self.symbols.get(symbol) {
|
||||
Some((_, ptr)) => *ptr,
|
||||
|
||||
None => panic!(
|
||||
"There was no entry for {:?} {} in scope {:?}",
|
||||
symbol, symbol, self
|
||||
),
|
||||
None => panic!("There was no entry for {symbol:?} {symbol} in scope {self:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn load_symbol_and_layout(&self, symbol: &Symbol) -> (BasicValueEnum<'ctx>, InLayout<'a>) {
|
||||
match self.symbols.get(symbol) {
|
||||
Some((layout, ptr)) => (*ptr, *layout),
|
||||
None => panic!("There was no entry for {:?} in scope {:?}", symbol, self),
|
||||
None => panic!("There was no entry for {symbol:?} in scope {self:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -126,7 +126,7 @@ fn index_struct_value<'a, 'ctx>(
|
|||
argument,
|
||||
index as _,
|
||||
env.arena
|
||||
.alloc(format!("struct_field_access_record_{}", index)),
|
||||
.alloc(format!("struct_field_access_record_{index}")),
|
||||
);
|
||||
|
||||
let field_layout = field_layouts[index as usize];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue