remove FunctionPointer completely

This commit is contained in:
Folkert 2021-06-19 14:53:18 +02:00
parent c776d98686
commit f2f9897187
12 changed files with 11 additions and 58 deletions

View file

@ -275,7 +275,6 @@ fn jit_to_ast_help<'a>(
} }
Layout::Closure(_, _, _) => Err(ToAstProblem::FunctionLayout), Layout::Closure(_, _, _) => Err(ToAstProblem::FunctionLayout),
Layout::FunctionPointer(_, _) => Err(ToAstProblem::FunctionLayout),
} }
} }

View file

@ -151,9 +151,6 @@ fn build_transform_caller_help<'a, 'ctx, 'env>(
} }
match closure_data_layout { match closure_data_layout {
Layout::FunctionPointer(_, _) => {
// do nothing
}
Layout::Closure(_, lambda_set, _) => { Layout::Closure(_, lambda_set, _) => {
if let Layout::Struct(&[]) = lambda_set.runtime_representation() { if let Layout::Struct(&[]) = lambda_set.runtime_representation() {
// do nothing // do nothing
@ -508,7 +505,6 @@ pub fn build_compare_wrapper<'a, 'ctx, 'env>(
let default = [value1, value2]; let default = [value1, value2];
let arguments_cast = match closure_data_layout { let arguments_cast = match closure_data_layout {
Layout::FunctionPointer(_, _) => &default,
Layout::Closure(_, lambda_set, _) => { Layout::Closure(_, lambda_set, _) => {
if let Layout::Struct(&[]) = lambda_set.runtime_representation() { if let Layout::Struct(&[]) = lambda_set.runtime_representation() {
&default &default

View file

@ -3627,13 +3627,6 @@ pub fn build_proc<'a, 'ctx, 'env>(
env, &fn_name, evaluator, name, arguments, closure, result, env, &fn_name, evaluator, name, arguments, closure, result,
) )
} }
Layout::FunctionPointer(arguments, result) => {
// define function size (equal to pointer size) and return value size, e.g.
//
// * roc__mainForHost_1_Update_size() -> i64
// * roc__mainForHost_1_Update_result_size() -> i64
build_function_caller(env, &fn_name, name, arguments, result)
}
Layout::Builtin(_) => {} Layout::Builtin(_) => {}
Layout::Struct(_) => {} Layout::Struct(_) => {}

View file

@ -88,7 +88,7 @@ fn build_hash_layout<'a, 'ctx, 'env>(
} }
}, },
Layout::FunctionPointer(_, _) | Layout::Closure(_, _, _) => { Layout::Closure(_, _, _) => {
unreachable!("the type system will guarantee these are never hashed") unreachable!("the type system will guarantee these are never hashed")
} }
} }

View file

@ -658,7 +658,7 @@ pub fn list_keep_errs<'a, 'ctx, 'env>(
) )
} }
pub fn list_keep_result<'a, 'ctx, 'env>( fn list_keep_result<'a, 'ctx, 'env>(
env: &Env<'a, 'ctx, 'env>, env: &Env<'a, 'ctx, 'env>,
layout_ids: &mut LayoutIds<'a>, layout_ids: &mut LayoutIds<'a>,
transform: FunctionValue<'ctx>, transform: FunctionValue<'ctx>,
@ -673,7 +673,6 @@ pub fn list_keep_result<'a, 'ctx, 'env>(
let builder = env.builder; let builder = env.builder;
let result_layout = match transform_layout { let result_layout = match transform_layout {
Layout::FunctionPointer(_, ret) => ret,
Layout::Closure(_, _, ret) => ret, Layout::Closure(_, _, ret) => ret,
_ => unreachable!("not a callable layout"), _ => unreachable!("not a callable layout"),
}; };

View file

@ -195,7 +195,7 @@ fn build_eq<'a, 'ctx, 'env>(
} }
}, },
Layout::FunctionPointer(_, _) | Layout::Closure(_, _, _) => { Layout::Closure(_, _, _) => {
unreachable!("the type system will guarantee these are never compared") unreachable!("the type system will guarantee these are never compared")
} }
} }
@ -336,7 +336,7 @@ fn build_neq<'a, 'ctx, 'env>(
unreachable!("recursion pointers should never be compared directly") unreachable!("recursion pointers should never be compared directly")
} }
Layout::FunctionPointer(_, _) | Layout::Closure(_, _, _) => { Layout::Closure(_, _, _) => {
unreachable!("the type system will guarantee these are never compared") unreachable!("the type system will guarantee these are never compared")
} }
} }

View file

@ -44,7 +44,6 @@ pub fn basic_type_from_layout<'a, 'ctx, 'env>(
use Layout::*; use Layout::*;
match layout { match layout {
FunctionPointer(args, ret_layout) => basic_type_from_function_layout(env, args, ret_layout),
Closure(_args, closure_layout, _ret_layout) => { Closure(_args, closure_layout, _ret_layout) => {
let closure_data_layout = closure_layout.runtime_representation(); let closure_data_layout = closure_layout.runtime_representation();
basic_type_from_layout(env, &closure_data_layout) basic_type_from_layout(env, &closure_data_layout)

View file

@ -750,8 +750,6 @@ fn modify_refcount_layout_build_function<'a, 'ctx, 'env>(
Some(function) Some(function)
} }
}, },
FunctionPointer(_, _) => None,
} }
} }

View file

@ -4080,14 +4080,14 @@ fn add_def_to_module<'a>(
if is_exposed { if is_exposed {
let annotation = def.expr_var; let annotation = def.expr_var;
let layout = match layout_cache.from_var( let top_level = match layout_cache.from_var(
mono_env.arena, mono_env.arena,
annotation, annotation,
mono_env.subs, mono_env.subs,
) { ) {
Ok(l) => { Ok(l) => {
// remember, this is a 0-argument thunk // remember, this is a 0-argument thunk
Layout::FunctionPointer(&[], mono_env.arena.alloc(l)) TopLevelFunctionLayout::new(mono_env.arena, &[], l)
} }
Err(LayoutProblem::Erroneous) => { Err(LayoutProblem::Erroneous) => {
let message = "top level function has erroneous type"; let message = "top level function has erroneous type";
@ -4108,7 +4108,7 @@ fn add_def_to_module<'a>(
procs.insert_exposed( procs.insert_exposed(
symbol, symbol,
TopLevelFunctionLayout::from_layout(mono_env.arena, layout), top_level,
mono_env.arena, mono_env.arena,
mono_env.subs, mono_env.subs,
def.annotation, def.annotation,

View file

@ -976,7 +976,6 @@ fn layout_spec(builder: &mut FuncDefBuilder, layout: &Layout) -> Result<TypeId>
} => worst_case_type(builder), } => worst_case_type(builder),
}, },
RecursivePointer => worst_case_type(builder), RecursivePointer => worst_case_type(builder),
FunctionPointer(_, _) => todo!(),
Closure(_, lambda_set, _) => layout_spec(builder, &lambda_set.runtime_representation()), Closure(_, lambda_set, _) => layout_spec(builder, &lambda_set.runtime_representation()),
} }
} }

View file

@ -2244,9 +2244,6 @@ fn build_specialized_proc_from_var<'a>(
fn_var: Variable, fn_var: Variable,
) -> Result<SpecializedLayout<'a>, LayoutProblem> { ) -> Result<SpecializedLayout<'a>, LayoutProblem> {
match layout_cache.from_var(env.arena, fn_var, env.subs) { 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)) => { Ok(Layout::Closure(pattern_layouts, closure_layout, ret_layout)) => {
let mut pattern_layouts_vec = Vec::with_capacity_in(pattern_layouts.len(), env.arena); let mut pattern_layouts_vec = Vec::with_capacity_in(pattern_layouts.len(), env.arena);
pattern_layouts_vec.extend_from_slice(pattern_layouts); pattern_layouts_vec.extend_from_slice(pattern_layouts);
@ -2550,7 +2547,6 @@ fn specialize_solved_type<'a>(
RawFunctionLayout::Function(a, lambda_set, c) RawFunctionLayout::Function(a, lambda_set, c)
} }
} }
Layout::FunctionPointer(_, _) => unreachable!(),
_ => RawFunctionLayout::ZeroArgumentThunk(attempted_layout), _ => RawFunctionLayout::ZeroArgumentThunk(attempted_layout),
}; };
@ -2634,12 +2630,9 @@ impl<'a> TopLevelFunctionLayout<'a> {
} }
pub fn from_layout(arena: &'a Bump, layout: Layout<'a>) -> Self { pub fn from_layout(arena: &'a Bump, layout: Layout<'a>) -> Self {
match layout { match layout {
Layout::FunctionPointer(old_arguments, result) => {
Self::new(arena, old_arguments, *result)
}
Layout::Closure(arguments, lambda_set, result) => { Layout::Closure(arguments, lambda_set, result) => {
let full = lambda_set.extend_function_layout(arena, arguments, result); let arguments = lambda_set.extend_argument_list(arena, arguments);
TopLevelFunctionLayout::from_layout(arena, full) TopLevelFunctionLayout::new(arena, arguments, *result)
} }
_ => TopLevelFunctionLayout { _ => TopLevelFunctionLayout {
arguments: &[], arguments: &[],
@ -2690,9 +2683,6 @@ fn specialize_naked_symbol<'a>(
} else if env.is_imported_symbol(symbol) { } else if env.is_imported_symbol(symbol) {
match layout_cache.from_var(env.arena, variable, env.subs) { match layout_cache.from_var(env.arena, variable, env.subs) {
Err(e) => panic!("invalid layout {:?}", e), Err(e) => panic!("invalid layout {:?}", e),
Ok(Layout::FunctionPointer(_, _)) => {
unreachable!(r"layout generated by from_var should never by a function pointer")
}
Ok(_) => { Ok(_) => {
// this is a 0-arity thunk // this is a 0-arity thunk
let result = call_by_name( 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); let top_level_layout = TopLevelFunctionLayout::new(env.arena, &[], *ret_layout);
// the layout without the `FunctionPointer(&[], ...)` wrapper
let inner_layout = *ret_layout; let inner_layout = *ret_layout;
// If we've already specialized this one, no further work is needed. // If we've already specialized this one, no further work is needed.

View file

@ -57,7 +57,6 @@ pub enum Layout<'a> {
RecursivePointer, RecursivePointer,
/// A function. The types of its arguments, then the type of its return value. /// 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>), 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, &self,
arena: &'a Bump, arena: &'a Bump,
argument_layouts: &'a [Layout<'a>], argument_layouts: &'a [Layout<'a>],
ret_layout: &'a Layout<'a>, ret_layout: &'a Layout<'a>,
) -> Layout<'a> { ) -> Layout<'a> {
Layout::FunctionPointer( todo!()
self.extend_argument_list(arena, argument_layouts),
ret_layout,
)
} }
pub fn extend_argument_list( 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(), Closure(_, closure_layout, _) => closure_layout.safe_to_memcpy(),
RecursivePointer => { RecursivePointer => {
// We cannot memcpy pointers, because then we would have the same pointer in multiple places! // 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), Closure(_, lambda_set, _) => lambda_set.stack_size(pointer_size),
FunctionPointer(_, _) => pointer_size,
RecursivePointer => pointer_size, RecursivePointer => pointer_size,
} }
} }
@ -613,7 +604,6 @@ impl<'a> Layout<'a> {
} }
Layout::Builtin(builtin) => builtin.alignment_bytes(pointer_size), Layout::Builtin(builtin) => builtin.alignment_bytes(pointer_size),
Layout::RecursivePointer => pointer_size, Layout::RecursivePointer => pointer_size,
Layout::FunctionPointer(_, _) => pointer_size,
Layout::Closure(_, captured, _) => { Layout::Closure(_, captured, _) => {
pointer_size.max(captured.alignment_bytes(pointer_size)) pointer_size.max(captured.alignment_bytes(pointer_size))
} }
@ -668,7 +658,6 @@ impl<'a> Layout<'a> {
} }
RecursivePointer => true, RecursivePointer => true,
Closure(_, closure_layout, _) => closure_layout.contains_refcounted(), 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), Union(union_layout) => union_layout.to_doc(alloc, parens),
RecursivePointer => alloc.text("*self"), 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) => { Closure(args, closure_layout, result) => {
let args_doc = args.iter().map(|x| x.to_doc(alloc, Parens::InFunction)); let args_doc = args.iter().map(|x| x.to_doc(alloc, Parens::InFunction));