fix clippy complaints

This commit is contained in:
Folkert 2020-08-06 21:39:55 +02:00
parent 9dbce40a55
commit 0fbcfc7431
4 changed files with 45 additions and 146 deletions

View file

@ -4,7 +4,6 @@ use inkwell::module::Linkage;
use inkwell::passes::PassManager; use inkwell::passes::PassManager;
use inkwell::types::BasicType; use inkwell::types::BasicType;
use inkwell::OptimizationLevel; use inkwell::OptimizationLevel;
use roc_collections::all::ImMap;
use roc_gen::layout_id::LayoutIds; use roc_gen::layout_id::LayoutIds;
use roc_gen::llvm::build::{ use roc_gen::llvm::build::{
build_proc, build_proc_header, get_call_conventions, module_from_builtins, OptLevel, build_proc, build_proc_header, get_call_conventions, module_from_builtins, OptLevel,

View file

@ -20,7 +20,7 @@ use roc_collections::all::ImMap;
use roc_module::low_level::LowLevel; use roc_module::low_level::LowLevel;
use roc_module::symbol::{Interns, Symbol}; use roc_module::symbol::{Interns, Symbol};
use roc_mono::ir::JoinPointId; use roc_mono::ir::JoinPointId;
use roc_mono::layout::{Builtin, Layout, Ownership}; use roc_mono::layout::{Builtin, Layout};
use target_lexicon::CallingConvention; use target_lexicon::CallingConvention;
/// This is for Inkwell's FunctionValue::verify - we want to know the verification /// This is for Inkwell's FunctionValue::verify - we want to know the verification
@ -193,9 +193,6 @@ pub fn add_passes(fpm: &PassManager<FunctionValue<'_>>, opt_level: OptLevel) {
pub fn build_exp_literal<'a, 'ctx, 'env>( pub fn build_exp_literal<'a, 'ctx, 'env>(
env: &Env<'a, 'ctx, 'env>, env: &Env<'a, 'ctx, 'env>,
layout_ids: &mut LayoutIds<'a>,
scope: &Scope<'a, 'ctx>,
parent: FunctionValue<'ctx>,
literal: &roc_mono::ir::Literal<'a>, literal: &roc_mono::ir::Literal<'a>,
) -> BasicValueEnum<'ctx> { ) -> BasicValueEnum<'ctx> {
use roc_mono::ir::Literal::*; use roc_mono::ir::Literal::*;
@ -258,20 +255,9 @@ pub fn build_exp_expr<'a, 'ctx, 'env>(
use roc_mono::ir::Expr::*; use roc_mono::ir::Expr::*;
match expr { match expr {
Literal(literal) => build_exp_literal(env, layout_ids, scope, parent, literal), Literal(literal) => build_exp_literal(env, literal),
Alias(symbol) => load_symbol(env, scope, symbol), Alias(symbol) => load_symbol(env, scope, symbol),
RunLowLevel(op, symbols) => { RunLowLevel(op, symbols) => run_low_level(env, scope, parent, *op, symbols),
let mut args = Vec::with_capacity_in(symbols.len(), env.arena);
for symbol in symbols.iter() {
match scope.get(symbol) {
Some((layout, _)) => args.push(*symbol),
None => panic!("There was no entry for {:?} in scope {:?}", symbol, scope),
}
}
run_low_level(env, layout_ids, scope, parent, *op, args.into_bump_slice())
}
FunctionCall { FunctionCall {
call_type: ByName(name), call_type: ByName(name),
@ -284,7 +270,7 @@ pub fn build_exp_expr<'a, 'ctx, 'env>(
arg_tuples.push(load_symbol(env, scope, symbol)); arg_tuples.push(load_symbol(env, scope, symbol));
} }
call_with_args_ir( call_with_args(
env, env,
layout_ids, layout_ids,
layout, layout,
@ -296,7 +282,7 @@ pub fn build_exp_expr<'a, 'ctx, 'env>(
FunctionCall { FunctionCall {
call_type: ByPointer(name), call_type: ByPointer(name),
layout, layout: _,
args, args,
} => { } => {
let sub_expr = load_symbol(env, scope, name); let sub_expr = load_symbol(env, scope, name);
@ -392,7 +378,7 @@ pub fn build_exp_expr<'a, 'ctx, 'env>(
let mut field_types = Vec::with_capacity_in(num_fields, env.arena); let mut field_types = Vec::with_capacity_in(num_fields, env.arena);
let mut field_vals = Vec::with_capacity_in(num_fields, env.arena); let mut field_vals = Vec::with_capacity_in(num_fields, env.arena);
for (field_symbol) in it { for field_symbol in it {
let (val, field_layout) = load_symbol_and_layout(env, scope, field_symbol); let (val, field_layout) = load_symbol_and_layout(env, scope, field_symbol);
// Zero-sized fields have no runtime representation. // Zero-sized fields have no runtime representation.
// The layout of the struct expects them to be dropped! // The layout of the struct expects them to be dropped!
@ -590,9 +576,7 @@ pub fn build_exp_expr<'a, 'ctx, 'env>(
.expect("desired field did not decode") .expect("desired field did not decode")
} }
EmptyArray => empty_polymorphic_list(env), EmptyArray => empty_polymorphic_list(env),
Array { elem_layout, elems } => { Array { elem_layout, elems } => list_literal(env, scope, elem_layout, elems),
list_literal(env, layout_ids, scope, parent, elem_layout, elems)
}
FunctionPointer(symbol, layout) => { FunctionPointer(symbol, layout) => {
let fn_name = layout_ids let fn_name = layout_ids
.get(*symbol, layout) .get(*symbol, layout)
@ -830,6 +814,7 @@ fn refcount_is_one_comparison<'ctx>(
) )
} }
#[allow(dead_code)]
fn list_get_refcount_ptr<'a, 'ctx, 'env>( fn list_get_refcount_ptr<'a, 'ctx, 'env>(
env: &Env<'a, 'ctx, 'env>, env: &Env<'a, 'ctx, 'env>,
list_wrapper: StructValue<'ctx>, list_wrapper: StructValue<'ctx>,
@ -861,6 +846,7 @@ fn list_get_refcount_ptr<'a, 'ctx, 'env>(
) )
} }
#[allow(dead_code)]
fn increment_refcount_list<'a, 'ctx, 'env>( fn increment_refcount_list<'a, 'ctx, 'env>(
env: &Env<'a, 'ctx, 'env>, env: &Env<'a, 'ctx, 'env>,
original_wrapper: StructValue<'ctx>, original_wrapper: StructValue<'ctx>,
@ -889,6 +875,7 @@ fn increment_refcount_list<'a, 'ctx, 'env>(
body body
} }
#[allow(dead_code)]
fn decrement_refcount_list<'a, 'ctx, 'env>( fn decrement_refcount_list<'a, 'ctx, 'env>(
env: &Env<'a, 'ctx, 'env>, env: &Env<'a, 'ctx, 'env>,
parent: FunctionValue<'ctx>, parent: FunctionValue<'ctx>,
@ -942,7 +929,7 @@ fn load_symbol<'a, 'ctx, 'env>(
symbol: &Symbol, symbol: &Symbol,
) -> BasicValueEnum<'ctx> { ) -> BasicValueEnum<'ctx> {
match scope.get(symbol) { match scope.get(symbol) {
Some((layout, ptr)) => env Some((_, ptr)) => env
.builder .builder
.build_load(*ptr, symbol.ident_string(&env.interns)), .build_load(*ptr, symbol.ident_string(&env.interns)),
None => panic!("There was no entry for {:?} in scope {:?}", symbol, scope), None => panic!("There was no entry for {:?} in scope {:?}", symbol, scope),
@ -1534,49 +1521,9 @@ fn list_repeat<'a, 'ctx, 'env>(
) )
} }
// #[allow(clippy::cognitive_complexity)]
#[inline(always)] #[inline(always)]
#[allow(clippy::cognitive_complexity)]
fn call_with_args<'a, 'ctx, 'env>( fn call_with_args<'a, 'ctx, 'env>(
env: &Env<'a, 'ctx, 'env>,
layout_ids: &mut LayoutIds<'a>,
layout: &Layout<'a>,
symbol: Symbol,
_parent: FunctionValue<'ctx>,
args: &[(BasicValueEnum<'ctx>, &'a Layout<'a>)],
) -> BasicValueEnum<'ctx> {
let fn_name = layout_ids
.get(symbol, layout)
.to_symbol_string(symbol, &env.interns);
let fn_val = env
.module
.get_function(fn_name.as_str())
.unwrap_or_else(|| {
if symbol.is_builtin() {
panic!("Unrecognized builtin function: {:?}", symbol)
} else {
panic!("Unrecognized non-builtin function: {:?}", symbol)
}
});
let mut arg_vals: Vec<BasicValueEnum> = Vec::with_capacity_in(args.len(), env.arena);
for (arg, _layout) in args.iter() {
arg_vals.push(*arg);
}
let call = env
.builder
.build_call(fn_val, arg_vals.into_bump_slice(), "call");
call.set_call_convention(fn_val.get_call_conventions());
call.try_as_basic_value()
.left()
.unwrap_or_else(|| panic!("LLVM error: Invalid call by name for name {:?}", symbol))
}
#[inline(always)]
#[allow(clippy::cognitive_complexity)]
fn call_with_args_ir<'a, 'ctx, 'env>(
env: &Env<'a, 'ctx, 'env>, env: &Env<'a, 'ctx, 'env>,
layout_ids: &mut LayoutIds<'a>, layout_ids: &mut LayoutIds<'a>,
layout: &Layout<'a>, layout: &Layout<'a>,
@ -1597,15 +1544,8 @@ fn call_with_args_ir<'a, 'ctx, 'env>(
panic!("Unrecognized non-builtin function: {:?}", symbol) panic!("Unrecognized non-builtin function: {:?}", symbol)
} }
}); });
let mut arg_vals: Vec<BasicValueEnum> = Vec::with_capacity_in(args.len(), env.arena);
for (arg) in args.iter() { let call = env.builder.build_call(fn_val, args, "call");
arg_vals.push(*arg);
}
let call = env
.builder
.build_call(fn_val, arg_vals.into_bump_slice(), "call");
call.set_call_convention(fn_val.get_call_conventions()); call.set_call_convention(fn_val.get_call_conventions());
@ -1764,9 +1704,7 @@ fn empty_polymorphic_list<'a, 'ctx, 'env>(env: &Env<'a, 'ctx, 'env>) -> BasicVal
fn list_literal<'a, 'ctx, 'env>( fn list_literal<'a, 'ctx, 'env>(
env: &Env<'a, 'ctx, 'env>, env: &Env<'a, 'ctx, 'env>,
layout_ids: &mut LayoutIds<'a>,
scope: &Scope<'a, 'ctx>, scope: &Scope<'a, 'ctx>,
parent: FunctionValue<'ctx>,
elem_layout: &Layout<'a>, elem_layout: &Layout<'a>,
elems: &&[Symbol], elems: &&[Symbol],
) -> BasicValueEnum<'ctx> { ) -> BasicValueEnum<'ctx> {
@ -2008,7 +1946,6 @@ pub static COLD_CALL_CONV: u32 = 9;
fn run_low_level<'a, 'ctx, 'env>( fn run_low_level<'a, 'ctx, 'env>(
env: &Env<'a, 'ctx, 'env>, env: &Env<'a, 'ctx, 'env>,
layout_ids: &mut LayoutIds<'a>,
scope: &Scope<'a, 'ctx>, scope: &Scope<'a, 'ctx>,
parent: FunctionValue<'ctx>, parent: FunctionValue<'ctx>,
op: LowLevel, op: LowLevel,
@ -2202,7 +2139,7 @@ fn run_low_level<'a, 'ctx, 'env>(
} }
} }
} }
ListAppend => list_append(env, layout_ids, scope, parent, args), ListAppend => list_append(env, scope, parent, args),
ListPush => { ListPush => {
// List.push List elem, elem -> List elem // List.push List elem, elem -> List elem
debug_assert_eq!(args.len(), 2); debug_assert_eq!(args.len(), 2);
@ -2422,7 +2359,6 @@ fn build_int_binop<'a, 'ctx, 'env>(
fn list_append<'a, 'ctx, 'env>( fn list_append<'a, 'ctx, 'env>(
env: &Env<'a, 'ctx, 'env>, env: &Env<'a, 'ctx, 'env>,
layout_ids: &mut LayoutIds<'a>,
scope: &Scope<'a, 'ctx>, scope: &Scope<'a, 'ctx>,
parent: FunctionValue<'ctx>, parent: FunctionValue<'ctx>,
args: &[Symbol], args: &[Symbol],

View file

@ -1,7 +1,6 @@
use crate::exhaustive::{Ctor, RenderAs, TagId, Union}; use crate::exhaustive::{Ctor, RenderAs, TagId, Union};
use crate::ir::{DestructType, Env, Expr, JoinPointId, Literal, Pattern, Stmt}; use crate::ir::{DestructType, Env, Expr, JoinPointId, Literal, Pattern, Stmt};
use crate::layout::{Builtin, Layout}; use crate::layout::{Builtin, Layout};
use bumpalo::Bump;
use roc_collections::all::{MutMap, MutSet}; use roc_collections::all::{MutMap, MutSet};
use roc_module::ident::TagName; use roc_module::ident::TagName;
use roc_module::low_level::LowLevel; use roc_module::low_level::LowLevel;
@ -879,7 +878,6 @@ enum Choice<'a> {
Jump(Label), Jump(Label),
} }
type Stores<'a> = &'a [(Symbol, Layout<'a>, Expr<'a>)];
type StoresVec<'a> = bumpalo::collections::Vec<'a, (Symbol, Layout<'a>, Expr<'a>)>; type StoresVec<'a> = bumpalo::collections::Vec<'a, (Symbol, Layout<'a>, Expr<'a>)>;
pub fn optimize_when<'a>( pub fn optimize_when<'a>(
@ -1176,11 +1174,7 @@ fn decide_to_branching<'a>(
let fail = &*env.arena.alloc(fail_expr); let fail = &*env.arena.alloc(fail_expr);
let pass = &*env.arena.alloc(pass_expr); let pass = &*env.arena.alloc(pass_expr);
// TODO totally wrong
let condition = Expr::Literal(Literal::Int(42));
let branching_symbol = env.unique_symbol(); let branching_symbol = env.unique_symbol();
let branching_layout = Layout::Builtin(Builtin::Int1); let branching_layout = Layout::Builtin(Builtin::Int1);
let mut cond = Stmt::Cond { let mut cond = Stmt::Cond {
@ -1273,7 +1267,7 @@ fn decide_to_branching<'a>(
current_symbol = accum; current_symbol = accum;
} }
for ((new_stores, lhs, rhs, layout), accum) in tests.into_iter().rev().zip(accum_it) { for ((new_stores, lhs, rhs, _layout), accum) in tests.into_iter().rev().zip(accum_it) {
let test_symbol = env.unique_symbol(); let test_symbol = env.unique_symbol();
let test = Expr::RunLowLevel( let test = Expr::RunLowLevel(
LowLevel::Eq, LowLevel::Eq,

View file

@ -1,8 +1,6 @@
use self::InProgressProc::*; use self::InProgressProc::*;
use crate::exhaustive::{Ctor, Guard, RenderAs, TagId}; use crate::exhaustive::{Ctor, Guard, RenderAs, TagId};
use crate::layout::{ use crate::layout::{Builtin, Layout, LayoutCache, LayoutProblem, Ownership};
list_layout_from_elem, Builtin, Layout, LayoutCache, LayoutProblem, Ownership,
};
use bumpalo::collections::Vec; use bumpalo::collections::Vec;
use bumpalo::Bump; use bumpalo::Bump;
use roc_collections::all::{default_hasher, MutMap, MutSet}; use roc_collections::all::{default_hasher, MutMap, MutSet};
@ -60,7 +58,7 @@ impl<'a> Proc<'a> {
.append(alloc.intersperse(args_doc, ", ")) .append(alloc.intersperse(args_doc, ", "))
.append("):") .append("):")
.append(alloc.hardline()) .append(alloc.hardline())
.append(self.body.to_doc(alloc, false).indent(4)) .append(self.body.to_doc(alloc).indent(4))
} }
pub fn to_pretty(&self, width: usize) -> String { pub fn to_pretty(&self, width: usize) -> String {
@ -104,7 +102,7 @@ impl<'a> Procs<'a> {
loc_body: Located<roc_can::expr::Expr>, loc_body: Located<roc_can::expr::Expr>,
ret_var: Variable, ret_var: Variable,
) { ) {
match patterns_to_when(env, self, layout_cache, loc_args, ret_var, loc_body) { match patterns_to_when(env, layout_cache, loc_args, ret_var, loc_body) {
Ok((_, pattern_symbols, body)) => { Ok((_, pattern_symbols, body)) => {
// a named closure. Since these aren't specialized by the surrounding // a named closure. Since these aren't specialized by the surrounding
// context, we can't add pending specializations for them yet. // context, we can't add pending specializations for them yet.
@ -148,7 +146,7 @@ impl<'a> Procs<'a> {
ret_var: Variable, ret_var: Variable,
layout_cache: &mut LayoutCache<'a>, layout_cache: &mut LayoutCache<'a>,
) -> Result<Layout<'a>, RuntimeError> { ) -> Result<Layout<'a>, RuntimeError> {
match patterns_to_when(env, self, layout_cache, loc_args, ret_var, loc_body) { match patterns_to_when(env, layout_cache, loc_args, ret_var, loc_body) {
Ok((pattern_vars, pattern_symbols, body)) => { Ok((pattern_vars, pattern_symbols, body)) => {
// an anonymous closure. These will always be specialized already // an anonymous closure. These will always be specialized already
// by the surrounding context, so we can add pending specializations // by the surrounding context, so we can add pending specializations
@ -422,7 +420,7 @@ pub enum Expr<'a> {
} }
impl<'a> Literal<'a> { impl<'a> Literal<'a> {
pub fn to_doc<'b, D, A>(&'b self, alloc: &'b D, parens: bool) -> DocBuilder<'b, D, A> pub fn to_doc<'b, D, A>(&'b self, alloc: &'b D) -> DocBuilder<'b, D, A>
where where
D: DocAllocator<'b, A>, D: DocAllocator<'b, A>,
D::Doc: Clone, D::Doc: Clone,
@ -459,7 +457,7 @@ where
} }
impl<'a> Expr<'a> { impl<'a> Expr<'a> {
pub fn to_doc<'b, D, A>(&'b self, alloc: &'b D, parens: bool) -> DocBuilder<'b, D, A> pub fn to_doc<'b, D, A>(&'b self, alloc: &'b D) -> DocBuilder<'b, D, A>
where where
D: DocAllocator<'b, A>, D: DocAllocator<'b, A>,
D::Doc: Clone, D::Doc: Clone,
@ -468,7 +466,7 @@ impl<'a> Expr<'a> {
use Expr::*; use Expr::*;
match self { match self {
Literal(lit) => lit.to_doc(alloc, false), Literal(lit) => lit.to_doc(alloc),
Alias(symbol) => alloc.text("alias ").append(symbol_to_doc(alloc, *symbol)), Alias(symbol) => alloc.text("alias ").append(symbol_to_doc(alloc, *symbol)),
FunctionPointer(symbol, _) => symbol_to_doc(alloc, *symbol), FunctionPointer(symbol, _) => symbol_to_doc(alloc, *symbol),
@ -555,7 +553,7 @@ impl<'a> Stmt<'a> {
from_can(env, can_expr, procs, &mut layout_cache) from_can(env, can_expr, procs, &mut layout_cache)
} }
pub fn to_doc<'b, D, A>(&'b self, alloc: &'b D, parens: bool) -> DocBuilder<'b, D, A> pub fn to_doc<'b, D, A>(&'b self, alloc: &'b D) -> DocBuilder<'b, D, A>
where where
D: DocAllocator<'b, A>, D: DocAllocator<'b, A>,
D::Doc: Clone, D::Doc: Clone,
@ -568,10 +566,10 @@ impl<'a> Stmt<'a> {
.text("let ") .text("let ")
.append(symbol_to_doc(alloc, *symbol)) .append(symbol_to_doc(alloc, *symbol))
.append(" = ") .append(" = ")
.append(expr.to_doc(alloc, false)) .append(expr.to_doc(alloc))
.append(";") .append(";")
.append(alloc.hardline()) .append(alloc.hardline())
.append(cont.to_doc(alloc, false)), .append(cont.to_doc(alloc)),
Ret(symbol) => alloc Ret(symbol) => alloc
.text("ret ") .text("ret ")
@ -587,7 +585,7 @@ impl<'a> Stmt<'a> {
let default_doc = alloc let default_doc = alloc
.text("default:") .text("default:")
.append(alloc.hardline()) .append(alloc.hardline())
.append(default_branch.to_doc(alloc, false).indent(4)) .append(default_branch.to_doc(alloc).indent(4))
.indent(4); .indent(4);
let branches_docs = branches let branches_docs = branches
@ -596,7 +594,7 @@ impl<'a> Stmt<'a> {
alloc alloc
.text(format!("case {}:", tag)) .text(format!("case {}:", tag))
.append(alloc.hardline()) .append(alloc.hardline())
.append(expr.to_doc(alloc, false).indent(4)) .append(expr.to_doc(alloc).indent(4))
.indent(4) .indent(4)
}) })
.chain(std::iter::once(default_doc)); .chain(std::iter::once(default_doc));
@ -618,11 +616,11 @@ impl<'a> Stmt<'a> {
} => alloc } => alloc
.text(format!("if {} then", branching_symbol)) .text(format!("if {} then", branching_symbol))
.append(alloc.hardline()) .append(alloc.hardline())
.append(pass.to_doc(alloc, false).indent(4)) .append(pass.to_doc(alloc).indent(4))
.append(alloc.hardline()) .append(alloc.hardline())
.append(alloc.text("else")) .append(alloc.text("else"))
.append(alloc.hardline()) .append(alloc.hardline())
.append(fail.to_doc(alloc, false).indent(4)), .append(fail.to_doc(alloc).indent(4)),
RuntimeError(s) => alloc.text(format!("Error {}", s)), RuntimeError(s) => alloc.text(format!("Error {}", s)),
Join { Join {
@ -635,14 +633,14 @@ impl<'a> Stmt<'a> {
alloc.intersperse( alloc.intersperse(
vec![ vec![
remainder.to_doc(alloc, false), remainder.to_doc(alloc),
alloc alloc
.text("joinpoint ") .text("joinpoint ")
.append(join_point_to_doc(alloc, *id)) .append(join_point_to_doc(alloc, *id))
.append(" ".repeat(arguments.len().min(1))) .append(" ".repeat(arguments.len().min(1)))
.append(alloc.intersperse(it, alloc.space())) .append(alloc.intersperse(it, alloc.space()))
.append(":"), .append(":"),
continuation.to_doc(alloc, false).indent(4), continuation.to_doc(alloc).indent(4),
], ],
alloc.hardline(), alloc.hardline(),
) )
@ -669,7 +667,7 @@ impl<'a> Stmt<'a> {
pub fn to_pretty(&self, width: usize) -> String { pub fn to_pretty(&self, width: usize) -> String {
let allocator = BoxAllocator; let allocator = BoxAllocator;
let mut w = std::vec::Vec::new(); let mut w = std::vec::Vec::new();
self.to_doc::<_, ()>(&allocator, false) self.to_doc::<_, ()>(&allocator)
.1 .1
.render(width, &mut w) .render(width, &mut w)
.unwrap(); .unwrap();
@ -690,7 +688,6 @@ impl<'a> Stmt<'a> {
#[allow(clippy::type_complexity)] #[allow(clippy::type_complexity)]
fn patterns_to_when<'a>( fn patterns_to_when<'a>(
env: &mut Env<'a, '_>, env: &mut Env<'a, '_>,
procs: &mut Procs<'a>,
layout_cache: &mut LayoutCache<'a>, layout_cache: &mut LayoutCache<'a>,
patterns: std::vec::Vec<(Variable, Located<roc_can::pattern::Pattern>)>, patterns: std::vec::Vec<(Variable, Located<roc_can::pattern::Pattern>)>,
body_var: Variable, body_var: Variable,
@ -1049,10 +1046,6 @@ pub fn with_hole<'a>(
// A bit ugly, but it does the job // A bit ugly, but it does the job
match hole { match hole {
Stmt::Jump(id, _) => Stmt::Jump(*id, env.arena.alloc([symbol])), Stmt::Jump(id, _) => Stmt::Jump(*id, env.arena.alloc([symbol])),
Stmt::Ret(s) => {
//
Stmt::Ret(symbol)
}
_ => { _ => {
// if you see this, there is variable aliasing going on // if you see this, there is variable aliasing going on
Stmt::Ret(symbol) Stmt::Ret(symbol)
@ -1147,7 +1140,7 @@ pub fn with_hole<'a>(
} }
Wrapped(sorted_tag_layouts) => { Wrapped(sorted_tag_layouts) => {
let union_size = sorted_tag_layouts.len() as u8; let union_size = sorted_tag_layouts.len() as u8;
let (tag_id, (_, argument_layouts)) = sorted_tag_layouts let (tag_id, (_, _)) = sorted_tag_layouts
.iter() .iter()
.enumerate() .enumerate()
.find(|(_, (key, _))| key == &tag_name) .find(|(_, (key, _))| key == &tag_name)
@ -1165,8 +1158,6 @@ pub fn with_hole<'a>(
} }
} }
let layout_it = argument_layouts.iter();
let mut layouts: Vec<&'a [Layout<'a>]> = let mut layouts: Vec<&'a [Layout<'a>]> =
Vec::with_capacity_in(sorted_tag_layouts.len(), env.arena); Vec::with_capacity_in(sorted_tag_layouts.len(), env.arena);
@ -1221,8 +1212,6 @@ pub fn with_hole<'a>(
mut fields, mut fields,
.. ..
} => { } => {
let arena = env.arena;
let sorted_fields = crate::layout::sort_record_fields( let sorted_fields = crate::layout::sort_record_fields(
env.arena, env.arena,
record_var, record_var,
@ -1238,13 +1227,13 @@ pub fn with_hole<'a>(
field_layouts.push(layout); field_layouts.push(layout);
let field = fields.remove(&label).unwrap(); let field = fields.remove(&label).unwrap();
let field_symbol = if let roc_can::expr::Expr::Var(symbol) = field.loc_expr.value { if let roc_can::expr::Expr::Var(symbol) = field.loc_expr.value {
field_symbols.push(symbol); field_symbols.push(symbol);
can_fields.push(None); can_fields.push(None);
} else { } else {
field_symbols.push(env.unique_symbol()); field_symbols.push(env.unique_symbol());
can_fields.push(Some(field)); can_fields.push(Some(field));
}; }
} }
// creating a record from the var will unpack it if it's just a single field. // creating a record from the var will unpack it if it's just a single field.
@ -1280,8 +1269,6 @@ pub fn with_hole<'a>(
branches, branches,
final_else, final_else,
} => { } => {
let arena = env.arena;
let ret_layout = layout_cache let ret_layout = layout_cache
.from_var(env.arena, branch_var, env.subs, env.pointer_size) .from_var(env.arena, branch_var, env.subs, env.pointer_size)
.expect("invalid ret_layout"); .expect("invalid ret_layout");
@ -1440,7 +1427,7 @@ pub fn with_hole<'a>(
stmt stmt
} }
LetRec(_, _, _, _) | LetNonRec(_, _, _, _) => todo!("lets"), LetRec(_, _, _, _) => todo!("lets"),
Access { Access {
record_var, record_var,
@ -1449,8 +1436,6 @@ pub fn with_hole<'a>(
loc_expr, loc_expr,
.. ..
} => { } => {
let arena = env.arena;
let sorted_fields = crate::layout::sort_record_fields( let sorted_fields = crate::layout::sort_record_fields(
env.arena, env.arena,
record_var, record_var,
@ -1488,7 +1473,7 @@ pub fn with_hole<'a>(
let mut stmt = Stmt::Let(assigned, expr, layout, hole); let mut stmt = Stmt::Let(assigned, expr, layout, hole);
if let roc_can::expr::Expr::Var(symbol) = loc_expr.value { if let roc_can::expr::Expr::Var(_) = loc_expr.value {
// do nothing // do nothing
} else { } else {
stmt = with_hole( stmt = with_hole(
@ -1728,7 +1713,7 @@ pub fn from_can<'a>(
from_can(env, cont.value, procs, layout_cache) from_can(env, cont.value, procs, layout_cache)
} }
LetNonRec(def, cont, xvar, _) => { LetNonRec(def, cont, _, _) => {
if let roc_can::pattern::Pattern::Identifier(symbol) = &def.loc_pattern.value { if let roc_can::pattern::Pattern::Identifier(symbol) = &def.loc_pattern.value {
if let Closure(_, _, _, _, _) = &def.loc_expr.value { if let Closure(_, _, _, _, _) = &def.loc_expr.value {
// Now that we know for sure it's a closure, get an owned // Now that we know for sure it's a closure, get an owned
@ -1799,7 +1784,7 @@ pub fn from_can<'a>(
let mut stores = Vec::new_in(env.arena); let mut stores = Vec::new_in(env.arena);
let outer_symbol = env.unique_symbol(); let outer_symbol = env.unique_symbol();
store_pattern(env, &mono_pattern, outer_symbol, layout, &mut stores); store_pattern(env, &mono_pattern, outer_symbol, layout, &mut stores).unwrap();
// convert the continuation // convert the continuation
let mut stmt = from_can(env, cont.value, procs, layout_cache); let mut stmt = from_can(env, cont.value, procs, layout_cache);
@ -1831,11 +1816,8 @@ pub fn from_can<'a>(
fn to_opt_branches<'a>( fn to_opt_branches<'a>(
env: &mut Env<'a, '_>, env: &mut Env<'a, '_>,
cond_var: Variable,
expr_var: Variable,
region: Region, region: Region,
cond_symbol: Symbol, branches: std::vec::Vec<roc_can::expr::WhenBranch>,
mut branches: std::vec::Vec<roc_can::expr::WhenBranch>,
layout_cache: &mut LayoutCache<'a>, layout_cache: &mut LayoutCache<'a>,
) -> std::vec::Vec<( ) -> std::vec::Vec<(
Pattern<'a>, Pattern<'a>,
@ -1844,10 +1826,6 @@ fn to_opt_branches<'a>(
)> { )> {
debug_assert!(!branches.is_empty()); debug_assert!(!branches.is_empty());
let cond_layout = layout_cache
.from_var(env.arena, cond_var, env.subs, env.pointer_size)
.unwrap_or_else(|err| panic!("TODO turn this into a RuntimeError {:?}", err));
let mut loc_branches = std::vec::Vec::new(); let mut loc_branches = std::vec::Vec::new();
let mut opt_branches = std::vec::Vec::new(); let mut opt_branches = std::vec::Vec::new();
@ -1935,15 +1913,7 @@ fn from_can_when<'a>(
// We can't know what to return! // We can't know what to return!
return Stmt::RuntimeError("Hit a 0-branch when expression"); return Stmt::RuntimeError("Hit a 0-branch when expression");
} }
let opt_branches = to_opt_branches( let opt_branches = to_opt_branches(env, region, branches, layout_cache);
env,
cond_var,
expr_var,
region,
cond_symbol,
branches,
layout_cache,
);
let cond_layout = layout_cache let cond_layout = layout_cache
.from_var(env.arena, cond_var, env.subs, env.pointer_size) .from_var(env.arena, cond_var, env.subs, env.pointer_size)
@ -2188,10 +2158,10 @@ fn call_by_name<'a>(
} }
let field_symbols = field_symbols.into_bump_slice(); let field_symbols = field_symbols.into_bump_slice();
for (var, loc_arg) in loc_args.clone() { for (var, _) in &loc_args {
match layout_cache.from_var(&env.arena, var, &env.subs, env.pointer_size) { match layout_cache.from_var(&env.arena, *var, &env.subs, env.pointer_size) {
Ok(layout) => { Ok(_) => {
pattern_vars.push(var); pattern_vars.push(*var);
} }
Err(_) => { Err(_) => {
// One of this function's arguments code gens to a runtime error, // One of this function's arguments code gens to a runtime error,