mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 23:31:12 +00:00
remove unneeded code
This commit is contained in:
parent
e27527b552
commit
9b949912d7
1 changed files with 88 additions and 98 deletions
|
@ -1504,14 +1504,9 @@ fn specialize_external<'a>(
|
|||
pattern_symbols
|
||||
};
|
||||
|
||||
let spec_proc =
|
||||
let (proc_args, opt_closure_layout, ret_layout) =
|
||||
build_specialized_proc_from_var(env, layout_cache, proc_name, pattern_symbols, fn_var)?;
|
||||
|
||||
match spec_proc {
|
||||
SpecializedLayout::EmptyClosure(_arg_layouts, _ret_layout) => {
|
||||
panic!("I don't think this should happen if things went well")
|
||||
}
|
||||
SpecializedLayout::Normal(proc_args, opt_closure_layout, ret_layout) => {
|
||||
let mut specialized_body = from_can(env, fn_var, body, procs, layout_cache);
|
||||
// unpack the closure symbols, if any
|
||||
if let CapturedSymbols::Captured(captured) = captured_symbols {
|
||||
|
@ -1540,8 +1535,7 @@ fn specialize_external<'a>(
|
|||
// layout is cached anyway, re-using the one found above leads to
|
||||
// issues (combining by-ref and by-move in pattern match
|
||||
let layout = layout_cache.from_var(env.arena, *variable, env.subs)?;
|
||||
specialized_body =
|
||||
Stmt::Let(*symbol, expr, layout, env.arena.alloc(specialized_body));
|
||||
specialized_body = Stmt::Let(*symbol, expr, layout, env.arena.alloc(specialized_body));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1591,17 +1585,12 @@ fn specialize_external<'a>(
|
|||
|
||||
Ok(proc)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum SpecializedLayout<'a> {
|
||||
Normal(
|
||||
type SpecializedLayout<'a> = (
|
||||
&'a [(Layout<'a>, Symbol)],
|
||||
Option<ClosureLayout<'a>>,
|
||||
Layout<'a>,
|
||||
),
|
||||
EmptyClosure(&'a [Layout<'a>], Layout<'a>),
|
||||
}
|
||||
);
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
fn build_specialized_proc_from_var<'a>(
|
||||
|
@ -1727,11 +1716,8 @@ fn build_specialized_proc<'a>(
|
|||
opt_closure_layout: Option<ClosureLayout<'a>>,
|
||||
ret_layout: Layout<'a>,
|
||||
) -> Result<SpecializedLayout<'a>, LayoutProblem> {
|
||||
use SpecializedLayout::*;
|
||||
|
||||
let mut proc_args = Vec::with_capacity_in(pattern_layouts.len(), arena);
|
||||
|
||||
let pattern_layouts_slice = pattern_layouts.clone().into_bump_slice();
|
||||
let pattern_layouts_len = pattern_layouts.len();
|
||||
|
||||
for (arg_layout, arg_name) in pattern_layouts.into_iter().zip(pattern_symbols.iter()) {
|
||||
|
@ -1770,7 +1756,7 @@ fn build_specialized_proc<'a>(
|
|||
|
||||
let proc_args = proc_args.into_bump_slice();
|
||||
|
||||
Ok(Normal(proc_args, Some(layout), ret_layout))
|
||||
Ok((proc_args, Some(layout), ret_layout))
|
||||
}
|
||||
Some(layout) => {
|
||||
// else if there is a closure layout, we're building the `f_closure` value
|
||||
|
@ -1785,7 +1771,7 @@ fn build_specialized_proc<'a>(
|
|||
let closure_layout =
|
||||
Layout::Struct(arena.alloc([function_ptr_layout, closure_data_layout]));
|
||||
|
||||
Ok(Normal(&[], None, closure_layout))
|
||||
Ok((&[], None, closure_layout))
|
||||
}
|
||||
None => {
|
||||
// else we're making a normal function, no closure problems to worry about
|
||||
|
@ -1794,14 +1780,18 @@ fn build_specialized_proc<'a>(
|
|||
// make sure there is not arg_closure argument without a closure layout
|
||||
debug_assert!(pattern_symbols.last() != Some(&Symbol::ARG_CLOSURE));
|
||||
|
||||
match pattern_layouts_len - pattern_symbols.len() {
|
||||
0 => {
|
||||
let diff = pattern_layouts_len - pattern_symbols.len();
|
||||
|
||||
if diff == 0 {
|
||||
let proc_args = proc_args.into_bump_slice();
|
||||
|
||||
Ok(Normal(proc_args, None, ret_layout))
|
||||
}
|
||||
1 => Ok(EmptyClosure(pattern_layouts_slice, ret_layout)),
|
||||
_ => panic!(),
|
||||
Ok((proc_args, None, ret_layout))
|
||||
} else if diff > 0 {
|
||||
// so far, the problem when hitting this branch was always somewhere else
|
||||
// I think this branch should not be reachable in a bugfree compiler
|
||||
panic!("more arguments (according to the layout) than argument symbols")
|
||||
} else {
|
||||
panic!("more argument symbols than arguments (according to the layout)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue