mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 07:14:46 +00:00
thread through an updatemodeids
This commit is contained in:
parent
cfa331be02
commit
8c3a00f7aa
3 changed files with 46 additions and 37 deletions
|
@ -2201,6 +2201,7 @@ fn update<'a>(
|
|||
arena,
|
||||
module_id,
|
||||
&mut ident_ids,
|
||||
&mut update_mode_ids,
|
||||
&mut state.procedures,
|
||||
);
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::borrow::{ParamMap, BORROWED, OWNED};
|
||||
use crate::ir::{
|
||||
BranchInfo, CallType, Expr, HigherOrderLowLevel, JoinPointId, ModifyRc, Param, Proc,
|
||||
ProcLayout, Stmt,
|
||||
ProcLayout, Stmt, UpdateModeIds,
|
||||
};
|
||||
use crate::layout::Layout;
|
||||
use bumpalo::collections::Vec;
|
||||
|
@ -481,8 +481,7 @@ impl<'a> Context<'a> {
|
|||
|
||||
fn visit_call<'i>(
|
||||
&self,
|
||||
home: ModuleId,
|
||||
ident_ids: &'i mut IdentIds,
|
||||
codegen: &mut CodegenTools<'i>,
|
||||
z: Symbol,
|
||||
call_type: crate::ir::CallType<'a>,
|
||||
arguments: &'a [Symbol],
|
||||
|
@ -505,16 +504,9 @@ impl<'a> Context<'a> {
|
|||
&*self.arena.alloc(Stmt::Let(z, v, l, b))
|
||||
}
|
||||
|
||||
HigherOrder(lowlevel) => self.visit_higher_order_lowlevel(
|
||||
home,
|
||||
ident_ids,
|
||||
z,
|
||||
lowlevel,
|
||||
arguments,
|
||||
l,
|
||||
b,
|
||||
b_live_vars,
|
||||
),
|
||||
HigherOrder(lowlevel) => {
|
||||
self.visit_higher_order_lowlevel(codegen, z, lowlevel, arguments, l, b, b_live_vars)
|
||||
}
|
||||
|
||||
Foreign { .. } => {
|
||||
let ps = crate::borrow::foreign_borrow_signature(self.arena, arguments.len());
|
||||
|
@ -557,8 +549,7 @@ impl<'a> Context<'a> {
|
|||
|
||||
fn visit_higher_order_lowlevel<'i>(
|
||||
&self,
|
||||
home: ModuleId,
|
||||
ident_ids: &'i mut IdentIds,
|
||||
codegen: &mut CodegenTools<'i>,
|
||||
z: Symbol,
|
||||
lowlevel: &'a crate::ir::HigherOrderLowLevel,
|
||||
arguments: &'a [Symbol],
|
||||
|
@ -750,7 +741,8 @@ impl<'a> Context<'a> {
|
|||
// elements have been consumed, must still consume the list itself
|
||||
let mut stmt = b;
|
||||
|
||||
let condition_symbol = Symbol::new(home, ident_ids.gen_unique());
|
||||
let condition_symbol =
|
||||
Symbol::new(codegen.home, codegen.ident_ids.gen_unique());
|
||||
|
||||
// unique branch
|
||||
// (u64, BranchInfo<'a>, Stmt<'a>)
|
||||
|
@ -776,7 +768,7 @@ impl<'a> Context<'a> {
|
|||
|
||||
let condition_call_type = CallType::LowLevel {
|
||||
op: roc_module::low_level::LowLevel::ListIsUnique,
|
||||
update_mode: crate::ir::UpdateModeId::BACKEND_DUMMY,
|
||||
update_mode: codegen.update_mode_ids.next_id(),
|
||||
};
|
||||
|
||||
let condition_call = crate::ir::Call {
|
||||
|
@ -845,8 +837,7 @@ impl<'a> Context<'a> {
|
|||
#[allow(clippy::many_single_char_names)]
|
||||
fn visit_variable_declaration<'i>(
|
||||
&self,
|
||||
home: ModuleId,
|
||||
ident_ids: &'i mut IdentIds,
|
||||
codegen: &mut CodegenTools<'i>,
|
||||
z: Symbol,
|
||||
v: Expr<'a>,
|
||||
l: Layout<'a>,
|
||||
|
@ -878,7 +869,7 @@ impl<'a> Context<'a> {
|
|||
Call(crate::ir::Call {
|
||||
call_type,
|
||||
arguments,
|
||||
}) => self.visit_call(home, ident_ids, z, call_type, arguments, l, b, b_live_vars),
|
||||
}) => self.visit_call(codegen, z, call_type, arguments, l, b, b_live_vars),
|
||||
|
||||
StructAtIndex { structure: x, .. } => {
|
||||
let b = self.add_dec_if_needed(x, b, b_live_vars);
|
||||
|
@ -1041,8 +1032,7 @@ impl<'a> Context<'a> {
|
|||
|
||||
fn visit_stmt<'i>(
|
||||
&self,
|
||||
home: ModuleId,
|
||||
ident_ids: &'i mut IdentIds,
|
||||
codegen: &mut CodegenTools<'i>,
|
||||
stmt: &'a Stmt<'a>,
|
||||
) -> (&'a Stmt<'a>, LiveVarSet) {
|
||||
use Stmt::*;
|
||||
|
@ -1063,11 +1053,10 @@ impl<'a> Context<'a> {
|
|||
for (symbol, expr, layout) in triples.iter() {
|
||||
ctx = ctx.update_var_info(**symbol, layout, expr);
|
||||
}
|
||||
let (mut b, mut b_live_vars) = ctx.visit_stmt(home, ident_ids, cont);
|
||||
let (mut b, mut b_live_vars) = ctx.visit_stmt(codegen, cont);
|
||||
for (symbol, expr, layout) in triples.into_iter().rev() {
|
||||
let pair = ctx.visit_variable_declaration(
|
||||
home,
|
||||
ident_ids,
|
||||
codegen,
|
||||
*symbol,
|
||||
(*expr).clone(),
|
||||
*layout,
|
||||
|
@ -1086,10 +1075,9 @@ impl<'a> Context<'a> {
|
|||
match stmt {
|
||||
Let(symbol, expr, layout, cont) => {
|
||||
let ctx = self.update_var_info(*symbol, layout, expr);
|
||||
let (b, b_live_vars) = ctx.visit_stmt(home, ident_ids, cont);
|
||||
let (b, b_live_vars) = ctx.visit_stmt(codegen, cont);
|
||||
ctx.visit_variable_declaration(
|
||||
home,
|
||||
ident_ids,
|
||||
codegen,
|
||||
*symbol,
|
||||
expr.clone(),
|
||||
*layout,
|
||||
|
@ -1109,7 +1097,7 @@ impl<'a> Context<'a> {
|
|||
|
||||
let (v, v_live_vars) = {
|
||||
let ctx = self.update_var_info_with_params(xs);
|
||||
ctx.visit_stmt(home, ident_ids, v)
|
||||
ctx.visit_stmt(codegen, v)
|
||||
};
|
||||
|
||||
let mut ctx = self.clone();
|
||||
|
@ -1117,7 +1105,7 @@ impl<'a> Context<'a> {
|
|||
|
||||
update_jp_live_vars(*j, xs, v, &mut ctx.jp_live_vars);
|
||||
|
||||
let (b, b_live_vars) = ctx.visit_stmt(home, ident_ids, b);
|
||||
let (b, b_live_vars) = ctx.visit_stmt(codegen, b);
|
||||
|
||||
(
|
||||
ctx.arena.alloc(Join {
|
||||
|
@ -1172,7 +1160,7 @@ impl<'a> Context<'a> {
|
|||
branches.iter().map(|(label, info, branch)| {
|
||||
// TODO should we use ctor info like Lean?
|
||||
let ctx = self.clone();
|
||||
let (b, alt_live_vars) = ctx.visit_stmt(home, ident_ids, branch);
|
||||
let (b, alt_live_vars) = ctx.visit_stmt(codegen, branch);
|
||||
let b = ctx.add_dec_for_alt(&case_live_vars, &alt_live_vars, b);
|
||||
|
||||
(*label, info.clone(), b.clone())
|
||||
|
@ -1184,7 +1172,7 @@ impl<'a> Context<'a> {
|
|||
let default_branch = {
|
||||
// TODO should we use ctor info like Lean?
|
||||
let ctx = self.clone();
|
||||
let (b, alt_live_vars) = ctx.visit_stmt(home, ident_ids, default_branch.1);
|
||||
let (b, alt_live_vars) = ctx.visit_stmt(codegen, default_branch.1);
|
||||
|
||||
(
|
||||
default_branch.0.clone(),
|
||||
|
@ -1326,24 +1314,36 @@ fn update_jp_live_vars(j: JoinPointId, ys: &[Param], v: &Stmt<'_>, m: &mut JPLiv
|
|||
m.insert(j, j_live_vars);
|
||||
}
|
||||
|
||||
struct CodegenTools<'i> {
|
||||
home: ModuleId,
|
||||
ident_ids: &'i mut IdentIds,
|
||||
update_mode_ids: &'i mut UpdateModeIds,
|
||||
}
|
||||
|
||||
pub fn visit_procs<'a, 'i>(
|
||||
arena: &'a Bump,
|
||||
home: ModuleId,
|
||||
ident_ids: &'i mut IdentIds,
|
||||
update_mode_ids: &'i mut UpdateModeIds,
|
||||
param_map: &'a ParamMap<'a>,
|
||||
procs: &mut MutMap<(Symbol, ProcLayout<'a>), Proc<'a>>,
|
||||
) {
|
||||
let ctx = Context::new(arena, param_map);
|
||||
|
||||
let mut codegen = CodegenTools {
|
||||
home,
|
||||
ident_ids,
|
||||
update_mode_ids,
|
||||
};
|
||||
|
||||
for (key, proc) in procs.iter_mut() {
|
||||
visit_proc(arena, home, ident_ids, param_map, &ctx, proc, key.1);
|
||||
visit_proc(arena, &mut codegen, param_map, &ctx, proc, key.1);
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_proc<'a, 'i>(
|
||||
arena: &'a Bump,
|
||||
home: ModuleId,
|
||||
ident_ids: &'i mut IdentIds,
|
||||
codegen: &mut CodegenTools<'i>,
|
||||
param_map: &'a ParamMap<'a>,
|
||||
ctx: &Context<'a>,
|
||||
proc: &mut Proc<'a>,
|
||||
|
@ -1364,7 +1364,7 @@ fn visit_proc<'a, 'i>(
|
|||
|
||||
let stmt = arena.alloc(proc.body.clone());
|
||||
let ctx = ctx.update_var_info_with_params(params);
|
||||
let (b, b_live_vars) = ctx.visit_stmt(home, ident_ids, stmt);
|
||||
let (b, b_live_vars) = ctx.visit_stmt(codegen, stmt);
|
||||
let b = ctx.add_dec_for_dead_params(params, b, &b_live_vars);
|
||||
|
||||
proc.body = b.clone();
|
||||
|
|
|
@ -393,11 +393,19 @@ impl<'a> Proc<'a> {
|
|||
arena: &'a Bump,
|
||||
home: ModuleId,
|
||||
ident_ids: &'i mut IdentIds,
|
||||
update_mode_ids: &'i mut UpdateModeIds,
|
||||
procs: &mut MutMap<(Symbol, ProcLayout<'a>), Proc<'a>>,
|
||||
) {
|
||||
let borrow_params = arena.alloc(crate::borrow::infer_borrow(arena, procs));
|
||||
|
||||
crate::inc_dec::visit_procs(arena, home, ident_ids, borrow_params, procs);
|
||||
crate::inc_dec::visit_procs(
|
||||
arena,
|
||||
home,
|
||||
ident_ids,
|
||||
update_mode_ids,
|
||||
borrow_params,
|
||||
procs,
|
||||
);
|
||||
}
|
||||
|
||||
pub fn insert_reset_reuse_operations<'i>(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue