mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 14:54:47 +00:00
cleanup, and remove reset-reuse stuff for now
This commit is contained in:
parent
4522fe14fc
commit
85f290f9be
7 changed files with 8 additions and 446 deletions
|
@ -22,7 +22,7 @@ use inkwell::values::BasicValueEnum::{self, *};
|
|||
use inkwell::values::{BasicValue, FloatValue, FunctionValue, IntValue, PointerValue, StructValue};
|
||||
use inkwell::AddressSpace;
|
||||
use inkwell::{IntPredicate, OptimizationLevel};
|
||||
use roc_collections::all::{ImMap, MutMap, MutSet};
|
||||
use roc_collections::all::{ImMap, MutSet};
|
||||
use roc_module::low_level::LowLevel;
|
||||
use roc_module::symbol::{Interns, Symbol};
|
||||
use roc_mono::ir::{JoinPointId, Wrapped};
|
||||
|
@ -1446,7 +1446,7 @@ fn decrement_refcount_list<'a, 'ctx, 'env>(
|
|||
|
||||
fn increment_refcount_ptr<'a, 'ctx, 'env>(
|
||||
env: &Env<'a, 'ctx, 'env>,
|
||||
parent: FunctionValue<'ctx>,
|
||||
_parent: FunctionValue<'ctx>,
|
||||
layout: &Layout<'a>,
|
||||
field_ptr: PointerValue<'ctx>,
|
||||
) {
|
||||
|
|
|
@ -570,7 +570,6 @@ fn to_relevant_branch_help<'a>(
|
|||
AppliedTag {
|
||||
tag_name,
|
||||
arguments,
|
||||
union,
|
||||
layout,
|
||||
..
|
||||
} => {
|
||||
|
@ -935,18 +934,7 @@ pub fn optimize_when<'a>(
|
|||
)
|
||||
}
|
||||
|
||||
fn path_to_expr<'a>(
|
||||
env: &mut Env<'a, '_>,
|
||||
symbol: Symbol,
|
||||
path: &Path,
|
||||
layout: &Layout<'a>,
|
||||
) -> (StoresVec<'a>, Symbol) {
|
||||
let (symbol, stores, _) = path_to_expr_help2(env, symbol, path, layout.clone());
|
||||
|
||||
(stores, symbol)
|
||||
}
|
||||
|
||||
fn path_to_expr_help2<'a>(
|
||||
fn path_to_expr_help<'a>(
|
||||
env: &mut Env<'a, '_>,
|
||||
mut symbol: Symbol,
|
||||
mut path: &Path,
|
||||
|
@ -1031,7 +1019,7 @@ fn test_to_equality<'a>(
|
|||
test: Test<'a>,
|
||||
) -> (StoresVec<'a>, Symbol, Symbol, Layout<'a>) {
|
||||
let (rhs_symbol, mut stores, _layout) =
|
||||
path_to_expr_help2(env, cond_symbol, &path, cond_layout.clone());
|
||||
path_to_expr_help(env, cond_symbol, &path, cond_layout.clone());
|
||||
|
||||
match test {
|
||||
Test::IsCtor {
|
||||
|
@ -1360,7 +1348,7 @@ fn decide_to_branching<'a>(
|
|||
// switch on the tag discriminant (currently an i64 value)
|
||||
// NOTE the tag discriminant is not actually loaded, `cond` can point to a tag
|
||||
let (cond, cond_stores_vec, cond_layout) =
|
||||
path_to_expr_help2(env, cond_symbol, &path, cond_layout);
|
||||
path_to_expr_help(env, cond_symbol, &path, cond_layout);
|
||||
|
||||
let default_branch = decide_to_branching(
|
||||
env,
|
||||
|
|
|
@ -3541,16 +3541,6 @@ pub fn from_can_pattern<'a>(
|
|||
// sorted fields based on the type
|
||||
let sorted_fields = crate::layout::sort_record_fields(env.arena, *whole_var, env.subs);
|
||||
|
||||
let type_identifiers_by_key = sorted_fields
|
||||
.iter()
|
||||
.map(|(label, _)| label)
|
||||
.collect::<MutSet<_>>();
|
||||
|
||||
let destructs_by_key = destructs
|
||||
.iter()
|
||||
.map(|destruct| destruct.value.label.clone())
|
||||
.collect::<MutSet<_>>();
|
||||
|
||||
// sorted fields based on the destruct
|
||||
let mut mono_destructs = Vec::with_capacity_in(destructs.len(), env.arena);
|
||||
let mut destructs = destructs.clone();
|
||||
|
|
|
@ -15,8 +15,6 @@ pub mod borrow;
|
|||
pub mod inc_dec;
|
||||
pub mod ir;
|
||||
pub mod layout;
|
||||
pub mod live_vars;
|
||||
pub mod reset_reuse;
|
||||
pub mod tail_recursion;
|
||||
|
||||
// Temporary, while we can build up test cases and optimize the exhaustiveness checking.
|
||||
|
|
|
@ -1,162 +0,0 @@
|
|||
use crate::ir::{Expr, JoinPointId, Param, Proc, Stmt};
|
||||
use roc_collections::all::{MutMap, MutSet};
|
||||
use roc_module::symbol::Symbol;
|
||||
|
||||
pub fn collect_stmt(
|
||||
stmt: &Stmt<'_>,
|
||||
jp_live_var_map: MutMap<JoinPointId, MutSet<Symbol>>,
|
||||
) -> MutSet<Symbol> {
|
||||
let mut result = MutSet::default();
|
||||
|
||||
collect_stmt_help(stmt, jp_live_var_map, &mut result);
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
pub fn collect_expr(expr: &Expr<'_>, result: &mut MutSet<Symbol>) {
|
||||
use Expr::*;
|
||||
|
||||
match expr {
|
||||
FunctionPointer(symbol, _)
|
||||
| AccessAtIndex {
|
||||
structure: symbol, ..
|
||||
} => {
|
||||
result.insert(*symbol);
|
||||
}
|
||||
|
||||
FunctionCall { args, .. } => {
|
||||
// NOTE thouth the function name does occur, it is a static constant in the program
|
||||
// for liveness, it should not be included here.
|
||||
result.extend(args.iter().copied());
|
||||
}
|
||||
|
||||
Tag { arguments, .. }
|
||||
| Struct(arguments)
|
||||
| Array {
|
||||
elems: arguments, ..
|
||||
} => {
|
||||
result.extend(arguments.iter().copied());
|
||||
}
|
||||
Reuse {
|
||||
symbol, arguments, ..
|
||||
} => {
|
||||
result.extend(arguments.iter().copied());
|
||||
result.insert(*symbol);
|
||||
}
|
||||
Reset(x) => {
|
||||
result.insert(*x);
|
||||
}
|
||||
RunLowLevel(_, args) => {
|
||||
result.extend(args.iter());
|
||||
}
|
||||
|
||||
EmptyArray | RuntimeErrorFunction(_) | Literal(_) => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn collect_var(symbol: &Symbol, result: &mut MutSet<Symbol>) {
|
||||
result.insert(*symbol);
|
||||
}
|
||||
|
||||
fn collect_args(symbols: &[Symbol], result: &mut MutSet<Symbol>) {
|
||||
for s in symbols.iter() {
|
||||
result.insert(*s);
|
||||
}
|
||||
}
|
||||
|
||||
fn collect_jp(
|
||||
id: &JoinPointId,
|
||||
jp_live_var_map: MutMap<JoinPointId, MutSet<Symbol>>,
|
||||
result: &mut MutSet<Symbol>,
|
||||
) {
|
||||
match jp_live_var_map.get(id) {
|
||||
None => unreachable!("join point id {:?} is not known", id),
|
||||
Some(xs) => result.extend(xs),
|
||||
}
|
||||
}
|
||||
|
||||
fn bind_var(symbol: &Symbol, result: &mut MutSet<Symbol>) {
|
||||
result.remove(symbol);
|
||||
}
|
||||
|
||||
fn bind_params(params: &[Param], result: &mut MutSet<Symbol>) {
|
||||
for param in params.iter() {
|
||||
result.remove(¶m.symbol);
|
||||
}
|
||||
}
|
||||
|
||||
fn collect_stmt_help(
|
||||
stmt: &Stmt<'_>,
|
||||
jp_live_var_map: MutMap<JoinPointId, MutSet<Symbol>>,
|
||||
result: &mut MutSet<Symbol>,
|
||||
) {
|
||||
use crate::ir::Stmt::*;
|
||||
|
||||
match stmt {
|
||||
Let(x, v, _layout, b) => {
|
||||
collect_stmt_help(b, jp_live_var_map, result);
|
||||
bind_var(x, result);
|
||||
collect_expr(v, result);
|
||||
}
|
||||
|
||||
Join {
|
||||
id: j,
|
||||
parameters: ys,
|
||||
continuation: v,
|
||||
remainder: b,
|
||||
} => {
|
||||
let mut jp_live_vars = MutSet::default();
|
||||
collect_stmt_help(v, jp_live_var_map.clone(), &mut jp_live_vars);
|
||||
bind_params(ys, &mut jp_live_vars);
|
||||
|
||||
let mut jp_live_var_map = jp_live_var_map;
|
||||
jp_live_var_map.insert(*j, jp_live_vars);
|
||||
|
||||
collect_stmt_help(b, jp_live_var_map, result);
|
||||
}
|
||||
|
||||
Jump(j, xs) => {
|
||||
collect_args(xs, result);
|
||||
collect_jp(j, jp_live_var_map, result);
|
||||
}
|
||||
|
||||
Inc(x, b) | Dec(x, b) => {
|
||||
collect_stmt_help(b, jp_live_var_map, result);
|
||||
collect_var(x, result);
|
||||
}
|
||||
|
||||
Ret(x) => {
|
||||
collect_var(x, result);
|
||||
}
|
||||
|
||||
Switch {
|
||||
cond_symbol,
|
||||
branches,
|
||||
default_branch,
|
||||
..
|
||||
} => {
|
||||
collect_var(cond_symbol, result);
|
||||
|
||||
for (_, branch) in branches.iter() {
|
||||
collect_stmt_help(branch, jp_live_var_map.clone(), result);
|
||||
}
|
||||
collect_stmt_help(default_branch, jp_live_var_map, result);
|
||||
}
|
||||
|
||||
Cond {
|
||||
cond_symbol,
|
||||
branching_symbol,
|
||||
pass,
|
||||
fail,
|
||||
..
|
||||
} => {
|
||||
collect_var(cond_symbol, result);
|
||||
collect_var(branching_symbol, result);
|
||||
|
||||
collect_stmt_help(pass, jp_live_var_map.clone(), result);
|
||||
collect_stmt_help(fail, jp_live_var_map, result);
|
||||
}
|
||||
|
||||
RuntimeError(_) => {}
|
||||
}
|
||||
}
|
|
@ -1,252 +0,0 @@
|
|||
use crate::inc_dec::LocalContext;
|
||||
use crate::ir::{Expr, Literal, Stmt};
|
||||
use crate::layout::{Builtin, Layout};
|
||||
use crate::live_vars;
|
||||
|
||||
use bumpalo::collections::Vec;
|
||||
use bumpalo::Bump;
|
||||
use roc_collections::all::MutSet;
|
||||
use roc_module::symbol::Symbol;
|
||||
|
||||
struct Env<'a, 'b> {
|
||||
env: crate::ir::Env<'a, 'b>,
|
||||
ctx: LocalContext<'a>,
|
||||
}
|
||||
|
||||
fn may_reuse<'a>(x: Layout<'a>, y: Layout<'a>) -> bool {
|
||||
// a heuristic; we really only want the same "type" to be reused.
|
||||
// we could also compare actual stack size.
|
||||
x == y
|
||||
}
|
||||
|
||||
fn try_function_s<'a>(
|
||||
env: &mut Env<'a, '_>,
|
||||
x: Symbol,
|
||||
layout: Layout<'a>,
|
||||
stmt: &'a Stmt<'a>,
|
||||
) -> &'a Stmt<'a> {
|
||||
let arena = env.env.arena;
|
||||
|
||||
let w = env.env.unique_symbol();
|
||||
|
||||
match function_s(env, w, stmt) {
|
||||
None => stmt,
|
||||
Some(new) => arena.alloc(Stmt::Let(w, Expr::Reset(x), layout, new)),
|
||||
}
|
||||
}
|
||||
|
||||
fn function_s<'a>(env: &mut Env<'a, '_>, w: Symbol, stmt: &'a Stmt<'a>) -> Option<&'a Stmt<'a>> {
|
||||
use Stmt::*;
|
||||
|
||||
let arena = env.env.arena;
|
||||
|
||||
match stmt {
|
||||
_ => todo!(),
|
||||
}
|
||||
}
|
||||
|
||||
fn function_d_main<'a>(
|
||||
env: &mut Env<'a, '_>,
|
||||
x: Symbol,
|
||||
layout: Layout<'a>,
|
||||
stmt: &'a Stmt<'a>,
|
||||
) -> (Option<&'a Stmt<'a>>, bool) {
|
||||
/*
|
||||
let c = layout;
|
||||
|
||||
use Stmt::*;
|
||||
|
||||
let arena = env.env.arena;
|
||||
|
||||
match stmt {
|
||||
Switch {
|
||||
cond_symbol,
|
||||
cond_layout,
|
||||
branches,
|
||||
default_branch,
|
||||
ret_layout,
|
||||
} => {
|
||||
// TODO only conditionally re-build the expression
|
||||
let live = live_vars::collect_stmt(stmt, env.ctx)
|
||||
|
||||
let branches = Vec::from_iter_in(
|
||||
branches.iter().map(|(label, branch)| {
|
||||
let branch = function_r(env, branch).unwrap_or(branch);
|
||||
let branch = function_d(env, *cond_symbol, cond_layout.clone(), branch)
|
||||
.unwrap_or(branch);
|
||||
|
||||
(*label, branch.clone())
|
||||
}),
|
||||
arena,
|
||||
)
|
||||
.into_bump_slice();
|
||||
|
||||
let default_branch = function_r(env, default_branch).unwrap_or(default_branch);
|
||||
let default_branch = function_d(env, *cond_symbol, cond_layout.clone(), default_branch)
|
||||
.unwrap_or(default_branch);
|
||||
|
||||
let switch = Switch {
|
||||
cond_symbol: *cond_symbol,
|
||||
branches,
|
||||
default_branch,
|
||||
cond_layout: cond_layout.clone(),
|
||||
ret_layout: ret_layout.clone(),
|
||||
};
|
||||
|
||||
Some(arena.alloc(switch))
|
||||
}
|
||||
|
||||
Join { .. } => todo!(),
|
||||
|
||||
Ret(_) | Jump(_, _) | RuntimeError(_) => None,
|
||||
|
||||
Inc(x, b) => match function_r(env, b) {
|
||||
None => None,
|
||||
Some(new_b) => Some(arena.alloc(Inc(*x, new_b))),
|
||||
},
|
||||
|
||||
Dec(x, b) => match function_r(env, b) {
|
||||
None => None,
|
||||
Some(new_b) => Some(arena.alloc(Dec(*x, new_b))),
|
||||
},
|
||||
|
||||
Let(x, v, l, b) => match function_r(env, b) {
|
||||
None => None,
|
||||
Some(new_b) => Some(arena.alloc(Let(*x, v.clone(), l.clone(), new_b))),
|
||||
},
|
||||
|
||||
Cond {
|
||||
cond_symbol,
|
||||
cond_layout,
|
||||
branching_symbol,
|
||||
branching_layout,
|
||||
pass,
|
||||
fail,
|
||||
ret_layout,
|
||||
} => {
|
||||
// TODO only conditionally re-build the expression
|
||||
|
||||
let pass = function_r(env, pass).unwrap_or(pass);
|
||||
let pass = function_d(env, *cond_symbol, cond_layout.clone(), pass).unwrap_or(pass);
|
||||
|
||||
let fail = function_r(env, fail).unwrap_or(fail);
|
||||
let fail = function_d(env, *cond_symbol, cond_layout.clone(), fail).unwrap_or(fail);
|
||||
|
||||
let stmt = Cond {
|
||||
cond_symbol: *cond_symbol,
|
||||
cond_layout: cond_layout.clone(),
|
||||
branching_symbol: *branching_symbol,
|
||||
branching_layout: branching_layout.clone(),
|
||||
pass,
|
||||
fail,
|
||||
ret_layout: ret_layout.clone(),
|
||||
};
|
||||
|
||||
Some(arena.alloc(stmt))
|
||||
}
|
||||
}
|
||||
*/
|
||||
panic!();
|
||||
}
|
||||
|
||||
fn function_d<'a>(
|
||||
env: &mut Env<'a, '_>,
|
||||
x: Symbol,
|
||||
layout: Layout<'a>,
|
||||
stmt: &'a Stmt<'a>,
|
||||
) -> Option<&'a Stmt<'a>> {
|
||||
let c = layout;
|
||||
todo!();
|
||||
}
|
||||
|
||||
fn function_r<'a>(env: &mut Env<'a, '_>, stmt: &'a Stmt<'a>) -> Option<&'a Stmt<'a>> {
|
||||
use Stmt::*;
|
||||
|
||||
let arena = env.env.arena;
|
||||
|
||||
match stmt {
|
||||
Join { .. } => todo!(),
|
||||
|
||||
Ret(_) | Jump(_, _) | RuntimeError(_) => None,
|
||||
|
||||
Inc(x, b) => match function_r(env, b) {
|
||||
None => None,
|
||||
Some(new_b) => Some(arena.alloc(Inc(*x, new_b))),
|
||||
},
|
||||
|
||||
Dec(x, b) => match function_r(env, b) {
|
||||
None => None,
|
||||
Some(new_b) => Some(arena.alloc(Dec(*x, new_b))),
|
||||
},
|
||||
|
||||
Let(x, v, l, b) => match function_r(env, b) {
|
||||
None => None,
|
||||
Some(new_b) => Some(arena.alloc(Let(*x, v.clone(), l.clone(), new_b))),
|
||||
},
|
||||
|
||||
Cond {
|
||||
cond_symbol,
|
||||
cond_layout,
|
||||
branching_symbol,
|
||||
branching_layout,
|
||||
pass,
|
||||
fail,
|
||||
ret_layout,
|
||||
} => {
|
||||
// TODO only conditionally re-build the expression
|
||||
|
||||
let pass = function_r(env, pass).unwrap_or(pass);
|
||||
let pass = function_d(env, *cond_symbol, cond_layout.clone(), pass).unwrap_or(pass);
|
||||
|
||||
let fail = function_r(env, fail).unwrap_or(fail);
|
||||
let fail = function_d(env, *cond_symbol, cond_layout.clone(), fail).unwrap_or(fail);
|
||||
|
||||
let stmt = Cond {
|
||||
cond_symbol: *cond_symbol,
|
||||
cond_layout: cond_layout.clone(),
|
||||
branching_symbol: *branching_symbol,
|
||||
branching_layout: branching_layout.clone(),
|
||||
pass,
|
||||
fail,
|
||||
ret_layout: ret_layout.clone(),
|
||||
};
|
||||
|
||||
Some(arena.alloc(stmt))
|
||||
}
|
||||
Switch {
|
||||
cond_symbol,
|
||||
cond_layout,
|
||||
branches,
|
||||
default_branch,
|
||||
ret_layout,
|
||||
} => {
|
||||
// TODO only conditionally re-build the expression
|
||||
|
||||
let branches = Vec::from_iter_in(
|
||||
branches.iter().map(|(label, branch)| {
|
||||
let branch = function_r(env, branch).unwrap_or(branch);
|
||||
let branch = function_d(env, *cond_symbol, cond_layout.clone(), branch)
|
||||
.unwrap_or(branch);
|
||||
|
||||
(*label, branch.clone())
|
||||
}),
|
||||
arena,
|
||||
)
|
||||
.into_bump_slice();
|
||||
|
||||
let default_branch = function_r(env, default_branch).unwrap_or(default_branch);
|
||||
let default_branch = function_d(env, *cond_symbol, cond_layout.clone(), default_branch)
|
||||
.unwrap_or(default_branch);
|
||||
|
||||
let switch = Switch {
|
||||
cond_symbol: *cond_symbol,
|
||||
branches,
|
||||
default_branch,
|
||||
cond_layout: cond_layout.clone(),
|
||||
ret_layout: ret_layout.clone(),
|
||||
};
|
||||
|
||||
Some(arena.alloc(switch))
|
||||
}
|
||||
}
|
||||
}
|
|
@ -647,15 +647,15 @@ mod test_mono {
|
|||
case 1:
|
||||
let Test.9 = 1i64;
|
||||
jump Test.8 Test.9;
|
||||
|
||||
|
||||
case 2:
|
||||
let Test.10 = 2i64;
|
||||
jump Test.8 Test.10;
|
||||
|
||||
|
||||
default:
|
||||
let Test.11 = 3i64;
|
||||
jump Test.8 Test.11;
|
||||
|
||||
|
||||
joinpoint Test.8 Test.3:
|
||||
ret Test.3;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue