mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 08:34:33 +00:00
remove FunctionPointer completely
This commit is contained in:
parent
c776d98686
commit
f2f9897187
12 changed files with 11 additions and 58 deletions
|
@ -976,7 +976,6 @@ fn layout_spec(builder: &mut FuncDefBuilder, layout: &Layout) -> Result<TypeId>
|
|||
} => worst_case_type(builder),
|
||||
},
|
||||
RecursivePointer => worst_case_type(builder),
|
||||
FunctionPointer(_, _) => todo!(),
|
||||
Closure(_, lambda_set, _) => layout_spec(builder, &lambda_set.runtime_representation()),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2244,9 +2244,6 @@ fn build_specialized_proc_from_var<'a>(
|
|||
fn_var: Variable,
|
||||
) -> Result<SpecializedLayout<'a>, LayoutProblem> {
|
||||
match layout_cache.from_var(env.arena, fn_var, env.subs) {
|
||||
Ok(Layout::FunctionPointer(_, _)) => {
|
||||
unreachable!(r"layout generated by from_var should never by a function pointer")
|
||||
}
|
||||
Ok(Layout::Closure(pattern_layouts, closure_layout, ret_layout)) => {
|
||||
let mut pattern_layouts_vec = Vec::with_capacity_in(pattern_layouts.len(), env.arena);
|
||||
pattern_layouts_vec.extend_from_slice(pattern_layouts);
|
||||
|
@ -2550,7 +2547,6 @@ fn specialize_solved_type<'a>(
|
|||
RawFunctionLayout::Function(a, lambda_set, c)
|
||||
}
|
||||
}
|
||||
Layout::FunctionPointer(_, _) => unreachable!(),
|
||||
_ => RawFunctionLayout::ZeroArgumentThunk(attempted_layout),
|
||||
};
|
||||
|
||||
|
@ -2634,12 +2630,9 @@ impl<'a> TopLevelFunctionLayout<'a> {
|
|||
}
|
||||
pub fn from_layout(arena: &'a Bump, layout: Layout<'a>) -> Self {
|
||||
match layout {
|
||||
Layout::FunctionPointer(old_arguments, result) => {
|
||||
Self::new(arena, old_arguments, *result)
|
||||
}
|
||||
Layout::Closure(arguments, lambda_set, result) => {
|
||||
let full = lambda_set.extend_function_layout(arena, arguments, result);
|
||||
TopLevelFunctionLayout::from_layout(arena, full)
|
||||
let arguments = lambda_set.extend_argument_list(arena, arguments);
|
||||
TopLevelFunctionLayout::new(arena, arguments, *result)
|
||||
}
|
||||
_ => TopLevelFunctionLayout {
|
||||
arguments: &[],
|
||||
|
@ -2690,9 +2683,6 @@ fn specialize_naked_symbol<'a>(
|
|||
} else if env.is_imported_symbol(symbol) {
|
||||
match layout_cache.from_var(env.arena, variable, env.subs) {
|
||||
Err(e) => panic!("invalid layout {:?}", e),
|
||||
Ok(Layout::FunctionPointer(_, _)) => {
|
||||
unreachable!(r"layout generated by from_var should never by a function pointer")
|
||||
}
|
||||
Ok(_) => {
|
||||
// this is a 0-arity thunk
|
||||
let result = call_by_name(
|
||||
|
@ -6568,7 +6558,6 @@ fn call_by_name_module_thunk<'a>(
|
|||
|
||||
let top_level_layout = TopLevelFunctionLayout::new(env.arena, &[], *ret_layout);
|
||||
|
||||
// the layout without the `FunctionPointer(&[], ...)` wrapper
|
||||
let inner_layout = *ret_layout;
|
||||
|
||||
// If we've already specialized this one, no further work is needed.
|
||||
|
|
|
@ -57,7 +57,6 @@ pub enum Layout<'a> {
|
|||
RecursivePointer,
|
||||
|
||||
/// A function. The types of its arguments, then the type of its return value.
|
||||
FunctionPointer(&'a [Layout<'a>], &'a Layout<'a>),
|
||||
Closure(&'a [Layout<'a>], LambdaSet<'a>, &'a Layout<'a>),
|
||||
}
|
||||
|
||||
|
@ -204,16 +203,13 @@ impl<'a> LambdaSet<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn extend_function_layout(
|
||||
fn extend_function_layout(
|
||||
&self,
|
||||
arena: &'a Bump,
|
||||
argument_layouts: &'a [Layout<'a>],
|
||||
ret_layout: &'a Layout<'a>,
|
||||
) -> Layout<'a> {
|
||||
Layout::FunctionPointer(
|
||||
self.extend_argument_list(arena, argument_layouts),
|
||||
ret_layout,
|
||||
)
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub fn extend_argument_list(
|
||||
|
@ -526,10 +522,6 @@ impl<'a> Layout<'a> {
|
|||
}
|
||||
}
|
||||
}
|
||||
FunctionPointer(_, _) => {
|
||||
// Function pointers are immutable and can always be safely copied
|
||||
true
|
||||
}
|
||||
Closure(_, closure_layout, _) => closure_layout.safe_to_memcpy(),
|
||||
RecursivePointer => {
|
||||
// We cannot memcpy pointers, because then we would have the same pointer in multiple places!
|
||||
|
@ -581,7 +573,6 @@ impl<'a> Layout<'a> {
|
|||
}
|
||||
}
|
||||
Closure(_, lambda_set, _) => lambda_set.stack_size(pointer_size),
|
||||
FunctionPointer(_, _) => pointer_size,
|
||||
RecursivePointer => pointer_size,
|
||||
}
|
||||
}
|
||||
|
@ -613,7 +604,6 @@ impl<'a> Layout<'a> {
|
|||
}
|
||||
Layout::Builtin(builtin) => builtin.alignment_bytes(pointer_size),
|
||||
Layout::RecursivePointer => pointer_size,
|
||||
Layout::FunctionPointer(_, _) => pointer_size,
|
||||
Layout::Closure(_, captured, _) => {
|
||||
pointer_size.max(captured.alignment_bytes(pointer_size))
|
||||
}
|
||||
|
@ -668,7 +658,6 @@ impl<'a> Layout<'a> {
|
|||
}
|
||||
RecursivePointer => true,
|
||||
Closure(_, closure_layout, _) => closure_layout.contains_refcounted(),
|
||||
FunctionPointer(_, _) => false,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -692,14 +681,6 @@ impl<'a> Layout<'a> {
|
|||
}
|
||||
Union(union_layout) => union_layout.to_doc(alloc, parens),
|
||||
RecursivePointer => alloc.text("*self"),
|
||||
FunctionPointer(args, result) => {
|
||||
let args_doc = args.iter().map(|x| x.to_doc(alloc, Parens::InFunction));
|
||||
|
||||
alloc
|
||||
.intersperse(args_doc, ", ")
|
||||
.append(alloc.text(" -> "))
|
||||
.append(result.to_doc(alloc, Parens::InFunction))
|
||||
}
|
||||
Closure(args, closure_layout, result) => {
|
||||
let args_doc = args.iter().map(|x| x.to_doc(alloc, Parens::InFunction));
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue