mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 23:04:49 +00:00
remove Expr::FunctionPointer
This commit is contained in:
parent
3739f41cac
commit
16fe609464
5 changed files with 4 additions and 61 deletions
|
@ -1682,40 +1682,6 @@ pub fn build_exp_expr<'a, 'ctx, 'env>(
|
|||
|
||||
list_literal(env, inplace, scope, elem_layout, elems)
|
||||
}
|
||||
FunctionPointer(symbol, layout) => {
|
||||
match scope.top_level_thunks.get(symbol) {
|
||||
Some((_layout, function_value)) => {
|
||||
// this is a 0-argument thunk, evaluate it!
|
||||
let call =
|
||||
env.builder
|
||||
.build_call(*function_value, &[], "evaluate_top_level_thunk");
|
||||
|
||||
call.set_call_convention(FAST_CALL_CONV);
|
||||
|
||||
call.try_as_basic_value().left().unwrap()
|
||||
}
|
||||
None => {
|
||||
// this is a function pointer, store it
|
||||
let fn_name = layout_ids
|
||||
.get(*symbol, layout)
|
||||
.to_symbol_string(*symbol, &env.interns);
|
||||
|
||||
let function_value =
|
||||
env.module
|
||||
.get_function(fn_name.as_str())
|
||||
.unwrap_or_else(|| {
|
||||
panic!(
|
||||
"Could not get pointer to unknown function {:?} {:?}",
|
||||
fn_name, layout
|
||||
)
|
||||
});
|
||||
|
||||
let ptr = function_value.as_global_value().as_pointer_value();
|
||||
|
||||
BasicValueEnum::PointerValue(ptr)
|
||||
}
|
||||
}
|
||||
}
|
||||
RuntimeErrorFunction(_) => todo!(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -401,7 +401,6 @@ where
|
|||
self.set_last_seen(*sym, stmt);
|
||||
match expr {
|
||||
Expr::Literal(_) => {}
|
||||
Expr::FunctionPointer(sym, _) => self.set_last_seen(*sym, stmt),
|
||||
|
||||
Expr::Call(call) => self.scan_ast_call(call, stmt),
|
||||
|
||||
|
|
|
@ -471,7 +471,7 @@ impl<'a> BorrowInfState<'a> {
|
|||
|
||||
Call(call) => self.collect_call(z, call),
|
||||
|
||||
Literal(_) | FunctionPointer(_, _) | RuntimeErrorFunction(_) => {}
|
||||
Literal(_) | RuntimeErrorFunction(_) => {}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -547,18 +547,6 @@ impl<'a> BorrowInfState<'a> {
|
|||
self.collect_stmt(b);
|
||||
}
|
||||
|
||||
Let(x, Expr::FunctionPointer(fsymbol, layout), _, b) => {
|
||||
// ensure that the function pointed to is in the param map
|
||||
if let Some(params) = self.param_map.get_symbol(*fsymbol, *layout) {
|
||||
self.param_map
|
||||
.items
|
||||
.insert(Key::Declaration(*x, *layout), params);
|
||||
}
|
||||
|
||||
self.collect_stmt(b);
|
||||
self.preserve_tail_call(*x, &Expr::FunctionPointer(*fsymbol, *layout), b);
|
||||
}
|
||||
|
||||
Let(x, v, _, b) => {
|
||||
self.collect_stmt(b);
|
||||
self.collect_expr(*x, v);
|
||||
|
|
|
@ -103,8 +103,7 @@ pub fn occuring_variables_expr(expr: &Expr<'_>, result: &mut MutSet<Symbol>) {
|
|||
use Expr::*;
|
||||
|
||||
match expr {
|
||||
FunctionPointer(symbol, _)
|
||||
| AccessAtIndex {
|
||||
AccessAtIndex {
|
||||
structure: symbol, ..
|
||||
} => {
|
||||
result.insert(*symbol);
|
||||
|
@ -556,11 +555,7 @@ impl<'a> Context<'a> {
|
|||
arguments,
|
||||
}) => self.visit_call(z, call_type, arguments, l, b, b_live_vars),
|
||||
|
||||
EmptyArray
|
||||
| FunctionPointer(_, _)
|
||||
| Literal(_)
|
||||
| Reset(_)
|
||||
| RuntimeErrorFunction(_) => {
|
||||
EmptyArray | Literal(_) | Reset(_) | RuntimeErrorFunction(_) => {
|
||||
// EmptyArray is always stack-allocated
|
||||
// function pointers are persistent
|
||||
self.arena.alloc(Stmt::Let(z, v, l, b))
|
||||
|
|
|
@ -1095,7 +1095,6 @@ pub enum Expr<'a> {
|
|||
Literal(Literal<'a>),
|
||||
|
||||
// Functions
|
||||
FunctionPointer(Symbol, Layout<'a>),
|
||||
Call(Call<'a>),
|
||||
|
||||
Tag {
|
||||
|
@ -1193,10 +1192,6 @@ impl<'a> Expr<'a> {
|
|||
match self {
|
||||
Literal(lit) => lit.to_doc(alloc),
|
||||
|
||||
FunctionPointer(symbol, _) => alloc
|
||||
.text("FunctionPointer ")
|
||||
.append(symbol_to_doc(alloc, *symbol)),
|
||||
|
||||
Call(call) => call.to_doc(alloc),
|
||||
|
||||
Tag {
|
||||
|
@ -5392,7 +5387,7 @@ fn substitute_in_expr<'a>(
|
|||
use Expr::*;
|
||||
|
||||
match expr {
|
||||
Literal(_) | FunctionPointer(_, _) | EmptyArray | RuntimeErrorFunction(_) => None,
|
||||
Literal(_) | EmptyArray | RuntimeErrorFunction(_) => None,
|
||||
|
||||
Call(call) => substitute_in_call(arena, call, subs).map(Expr::Call),
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue