mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 13:29:12 +00:00
clear work tree
This commit is contained in:
parent
957f44966c
commit
1fa96257ed
1 changed files with 72 additions and 9 deletions
|
@ -5,20 +5,20 @@ use roc_collections::{all::WyHash, MutMap, MutSet};
|
|||
use roc_module::symbol::{IdentIds, ModuleId, Symbol};
|
||||
|
||||
use crate::{
|
||||
ir::{Expr, Proc, ProcLayout, Stmt, UpdateModeIds},
|
||||
ir::{Call, CallType, Expr, Proc, ProcLayout, Stmt, UpdateModeIds},
|
||||
layout::STLayoutInterner,
|
||||
};
|
||||
|
||||
pub fn insert_refcount_operations<'a>(
|
||||
arena: &'a Bump,
|
||||
layout_interner: &STLayoutInterner,
|
||||
module_id: ModuleId,
|
||||
home: ModuleId,
|
||||
ident_ids: &mut IdentIds,
|
||||
update_mode_ids: &mut UpdateModeIds,
|
||||
procedures: &mut HashMap<(Symbol, ProcLayout), Proc<'a>, BuildHasherDefault<WyHash>>,
|
||||
) -> () {
|
||||
for (_, proc) in procedures.iter_mut() {
|
||||
// TODO use params to fill environment.
|
||||
// TODO use params to fill environment. Probably should all be owned...
|
||||
let initial_environment = Environment {
|
||||
borrowed: MutSet::default(),
|
||||
owned: MutSet::default(),
|
||||
|
@ -35,6 +35,7 @@ type VariableMap = MutMap<Symbol, VarType>;
|
|||
type Variables = MutSet<Symbol>;
|
||||
|
||||
struct Environment {
|
||||
// The Koka implementation assumes everything that is not owned to be borrowed.
|
||||
borrowed: Variables,
|
||||
owned: Variables,
|
||||
}
|
||||
|
@ -52,12 +53,18 @@ fn insert_refcount_operations_stmt<'a>(
|
|||
stmt: &Stmt<'a>,
|
||||
) -> &'a Stmt<'a> {
|
||||
// TODO: Deal with potentially stack overflowing let chains with an explicit loop.
|
||||
// Koka has a list for let bindings.
|
||||
|
||||
match &stmt {
|
||||
// The expression borrows the values owned (used) by the continuation.
|
||||
Stmt::Let(binding, expr, layout, stmt) => {
|
||||
// TODO take into account that the bound variable might not be free in the continuation.
|
||||
// And as such, we can drop the value before continuing.
|
||||
|
||||
// TODO this is the implementation according to the paper.
|
||||
// But the Koka implementation (instead of calculating the owned environment beforehand)
|
||||
// First evaluates the continuation with the owned environment, setting the variables to dead (not alive).
|
||||
// And in the rest of the code, the dead variables are treated as borrowed (because not alive).
|
||||
let mut stmt_owned: Variables = {
|
||||
let mut free_variables = Stmt::free_variables(&stmt);
|
||||
|
||||
|
@ -98,9 +105,19 @@ fn insert_refcount_operations_stmt<'a>(
|
|||
default_branch,
|
||||
ret_layout,
|
||||
} => {
|
||||
return arena.alloc(Stmt::Switch {
|
||||
cond_symbol: *cond_symbol,
|
||||
cond_layout: *cond_layout,
|
||||
branches: branches.clone(),
|
||||
default_branch: default_branch.clone(),
|
||||
ret_layout: *ret_layout,
|
||||
});
|
||||
todo!()
|
||||
}
|
||||
Stmt::Ret(s) => {
|
||||
return arena.alloc(Stmt::Ret(*s));
|
||||
todo!()
|
||||
}
|
||||
Stmt::Ret(_) => todo!(),
|
||||
Stmt::Refcounting(_, _) => todo!(),
|
||||
_ => todo!(),
|
||||
}
|
||||
|
@ -112,23 +129,43 @@ fn insert_refcount_operations_expr<'a>(
|
|||
expr: &Expr<'a>,
|
||||
) -> Expr<'a> {
|
||||
match &expr {
|
||||
Expr::Literal(_) => todo!(),
|
||||
Expr::Call(_) => todo!(),
|
||||
Expr::Literal(lit) => {
|
||||
return Expr::Literal(lit.clone());
|
||||
todo!()
|
||||
}
|
||||
Expr::Call(call) => Expr::Call(insert_refcount_operations_expr_fun(call)),
|
||||
Expr::Tag {
|
||||
tag_layout,
|
||||
tag_id,
|
||||
arguments,
|
||||
} => todo!(),
|
||||
Expr::Struct(_) => todo!(),
|
||||
Expr::Struct(s) => {
|
||||
return Expr::Struct(s);
|
||||
todo!()
|
||||
}
|
||||
Expr::StructAtIndex {
|
||||
index,
|
||||
field_layouts,
|
||||
structure,
|
||||
} => todo!(),
|
||||
} => {
|
||||
return Expr::StructAtIndex {
|
||||
index: *index,
|
||||
field_layouts,
|
||||
structure: *structure,
|
||||
};
|
||||
todo!()
|
||||
}
|
||||
Expr::GetTagId {
|
||||
structure,
|
||||
union_layout,
|
||||
} => todo!(),
|
||||
} => {
|
||||
return Expr::GetTagId {
|
||||
structure: *structure,
|
||||
union_layout: *union_layout,
|
||||
};
|
||||
|
||||
todo!()
|
||||
}
|
||||
Expr::UnionAtIndex {
|
||||
structure,
|
||||
tag_id,
|
||||
|
@ -155,6 +192,30 @@ fn insert_refcount_operations_expr<'a>(
|
|||
}
|
||||
}
|
||||
|
||||
fn insert_refcount_operations_expr_fun<'a>(call: &Call<'a>) -> Call<'a> {
|
||||
// TODO Koka makes a distinction between top level and non top level definitions.
|
||||
match &call.call_type {
|
||||
CallType::ByName {
|
||||
name,
|
||||
ret_layout,
|
||||
arg_layouts,
|
||||
specialization_id,
|
||||
} => {
|
||||
return call.clone();
|
||||
todo!()
|
||||
}
|
||||
CallType::Foreign {
|
||||
foreign_symbol,
|
||||
ret_layout,
|
||||
} => todo!(),
|
||||
CallType::LowLevel { op, update_mode } => {
|
||||
return call.clone();
|
||||
todo!()
|
||||
}
|
||||
CallType::HigherOrder(_) => todo!(),
|
||||
}
|
||||
}
|
||||
|
||||
trait FreeVariables {
|
||||
fn free_variables(&self) -> Variables;
|
||||
}
|
||||
|
@ -162,6 +223,7 @@ trait FreeVariables {
|
|||
impl<'a> FreeVariables for Stmt<'a> {
|
||||
// Return the set of variables that are free in the statement.
|
||||
fn free_variables(&self) -> Variables {
|
||||
return MutSet::default();
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
@ -169,6 +231,7 @@ impl<'a> FreeVariables for Stmt<'a> {
|
|||
impl<'a> FreeVariables for Expr<'a> {
|
||||
// Return the set of variables that are free in the expression.
|
||||
fn free_variables(&self) -> Variables {
|
||||
return MutSet::default();
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue