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,
|
arena,
|
||||||
module_id,
|
module_id,
|
||||||
&mut ident_ids,
|
&mut ident_ids,
|
||||||
|
&mut update_mode_ids,
|
||||||
&mut state.procedures,
|
&mut state.procedures,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::borrow::{ParamMap, BORROWED, OWNED};
|
use crate::borrow::{ParamMap, BORROWED, OWNED};
|
||||||
use crate::ir::{
|
use crate::ir::{
|
||||||
BranchInfo, CallType, Expr, HigherOrderLowLevel, JoinPointId, ModifyRc, Param, Proc,
|
BranchInfo, CallType, Expr, HigherOrderLowLevel, JoinPointId, ModifyRc, Param, Proc,
|
||||||
ProcLayout, Stmt,
|
ProcLayout, Stmt, UpdateModeIds,
|
||||||
};
|
};
|
||||||
use crate::layout::Layout;
|
use crate::layout::Layout;
|
||||||
use bumpalo::collections::Vec;
|
use bumpalo::collections::Vec;
|
||||||
|
@ -481,8 +481,7 @@ impl<'a> Context<'a> {
|
||||||
|
|
||||||
fn visit_call<'i>(
|
fn visit_call<'i>(
|
||||||
&self,
|
&self,
|
||||||
home: ModuleId,
|
codegen: &mut CodegenTools<'i>,
|
||||||
ident_ids: &'i mut IdentIds,
|
|
||||||
z: Symbol,
|
z: Symbol,
|
||||||
call_type: crate::ir::CallType<'a>,
|
call_type: crate::ir::CallType<'a>,
|
||||||
arguments: &'a [Symbol],
|
arguments: &'a [Symbol],
|
||||||
|
@ -505,16 +504,9 @@ impl<'a> Context<'a> {
|
||||||
&*self.arena.alloc(Stmt::Let(z, v, l, b))
|
&*self.arena.alloc(Stmt::Let(z, v, l, b))
|
||||||
}
|
}
|
||||||
|
|
||||||
HigherOrder(lowlevel) => self.visit_higher_order_lowlevel(
|
HigherOrder(lowlevel) => {
|
||||||
home,
|
self.visit_higher_order_lowlevel(codegen, z, lowlevel, arguments, l, b, b_live_vars)
|
||||||
ident_ids,
|
}
|
||||||
z,
|
|
||||||
lowlevel,
|
|
||||||
arguments,
|
|
||||||
l,
|
|
||||||
b,
|
|
||||||
b_live_vars,
|
|
||||||
),
|
|
||||||
|
|
||||||
Foreign { .. } => {
|
Foreign { .. } => {
|
||||||
let ps = crate::borrow::foreign_borrow_signature(self.arena, arguments.len());
|
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>(
|
fn visit_higher_order_lowlevel<'i>(
|
||||||
&self,
|
&self,
|
||||||
home: ModuleId,
|
codegen: &mut CodegenTools<'i>,
|
||||||
ident_ids: &'i mut IdentIds,
|
|
||||||
z: Symbol,
|
z: Symbol,
|
||||||
lowlevel: &'a crate::ir::HigherOrderLowLevel,
|
lowlevel: &'a crate::ir::HigherOrderLowLevel,
|
||||||
arguments: &'a [Symbol],
|
arguments: &'a [Symbol],
|
||||||
|
@ -750,7 +741,8 @@ impl<'a> Context<'a> {
|
||||||
// elements have been consumed, must still consume the list itself
|
// elements have been consumed, must still consume the list itself
|
||||||
let mut stmt = b;
|
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
|
// unique branch
|
||||||
// (u64, BranchInfo<'a>, Stmt<'a>)
|
// (u64, BranchInfo<'a>, Stmt<'a>)
|
||||||
|
@ -776,7 +768,7 @@ impl<'a> Context<'a> {
|
||||||
|
|
||||||
let condition_call_type = CallType::LowLevel {
|
let condition_call_type = CallType::LowLevel {
|
||||||
op: roc_module::low_level::LowLevel::ListIsUnique,
|
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 {
|
let condition_call = crate::ir::Call {
|
||||||
|
@ -845,8 +837,7 @@ impl<'a> Context<'a> {
|
||||||
#[allow(clippy::many_single_char_names)]
|
#[allow(clippy::many_single_char_names)]
|
||||||
fn visit_variable_declaration<'i>(
|
fn visit_variable_declaration<'i>(
|
||||||
&self,
|
&self,
|
||||||
home: ModuleId,
|
codegen: &mut CodegenTools<'i>,
|
||||||
ident_ids: &'i mut IdentIds,
|
|
||||||
z: Symbol,
|
z: Symbol,
|
||||||
v: Expr<'a>,
|
v: Expr<'a>,
|
||||||
l: Layout<'a>,
|
l: Layout<'a>,
|
||||||
|
@ -878,7 +869,7 @@ impl<'a> Context<'a> {
|
||||||
Call(crate::ir::Call {
|
Call(crate::ir::Call {
|
||||||
call_type,
|
call_type,
|
||||||
arguments,
|
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, .. } => {
|
StructAtIndex { structure: x, .. } => {
|
||||||
let b = self.add_dec_if_needed(x, b, b_live_vars);
|
let b = self.add_dec_if_needed(x, b, b_live_vars);
|
||||||
|
@ -1041,8 +1032,7 @@ impl<'a> Context<'a> {
|
||||||
|
|
||||||
fn visit_stmt<'i>(
|
fn visit_stmt<'i>(
|
||||||
&self,
|
&self,
|
||||||
home: ModuleId,
|
codegen: &mut CodegenTools<'i>,
|
||||||
ident_ids: &'i mut IdentIds,
|
|
||||||
stmt: &'a Stmt<'a>,
|
stmt: &'a Stmt<'a>,
|
||||||
) -> (&'a Stmt<'a>, LiveVarSet) {
|
) -> (&'a Stmt<'a>, LiveVarSet) {
|
||||||
use Stmt::*;
|
use Stmt::*;
|
||||||
|
@ -1063,11 +1053,10 @@ impl<'a> Context<'a> {
|
||||||
for (symbol, expr, layout) in triples.iter() {
|
for (symbol, expr, layout) in triples.iter() {
|
||||||
ctx = ctx.update_var_info(**symbol, layout, expr);
|
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() {
|
for (symbol, expr, layout) in triples.into_iter().rev() {
|
||||||
let pair = ctx.visit_variable_declaration(
|
let pair = ctx.visit_variable_declaration(
|
||||||
home,
|
codegen,
|
||||||
ident_ids,
|
|
||||||
*symbol,
|
*symbol,
|
||||||
(*expr).clone(),
|
(*expr).clone(),
|
||||||
*layout,
|
*layout,
|
||||||
|
@ -1086,10 +1075,9 @@ impl<'a> Context<'a> {
|
||||||
match stmt {
|
match stmt {
|
||||||
Let(symbol, expr, layout, cont) => {
|
Let(symbol, expr, layout, cont) => {
|
||||||
let ctx = self.update_var_info(*symbol, layout, expr);
|
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(
|
ctx.visit_variable_declaration(
|
||||||
home,
|
codegen,
|
||||||
ident_ids,
|
|
||||||
*symbol,
|
*symbol,
|
||||||
expr.clone(),
|
expr.clone(),
|
||||||
*layout,
|
*layout,
|
||||||
|
@ -1109,7 +1097,7 @@ impl<'a> Context<'a> {
|
||||||
|
|
||||||
let (v, v_live_vars) = {
|
let (v, v_live_vars) = {
|
||||||
let ctx = self.update_var_info_with_params(xs);
|
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();
|
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);
|
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 {
|
ctx.arena.alloc(Join {
|
||||||
|
@ -1172,7 +1160,7 @@ impl<'a> Context<'a> {
|
||||||
branches.iter().map(|(label, info, branch)| {
|
branches.iter().map(|(label, info, branch)| {
|
||||||
// TODO should we use ctor info like Lean?
|
// TODO should we use ctor info like Lean?
|
||||||
let ctx = self.clone();
|
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);
|
let b = ctx.add_dec_for_alt(&case_live_vars, &alt_live_vars, b);
|
||||||
|
|
||||||
(*label, info.clone(), b.clone())
|
(*label, info.clone(), b.clone())
|
||||||
|
@ -1184,7 +1172,7 @@ impl<'a> Context<'a> {
|
||||||
let default_branch = {
|
let default_branch = {
|
||||||
// TODO should we use ctor info like Lean?
|
// TODO should we use ctor info like Lean?
|
||||||
let ctx = self.clone();
|
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(),
|
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);
|
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>(
|
pub fn visit_procs<'a, 'i>(
|
||||||
arena: &'a Bump,
|
arena: &'a Bump,
|
||||||
home: ModuleId,
|
home: ModuleId,
|
||||||
ident_ids: &'i mut IdentIds,
|
ident_ids: &'i mut IdentIds,
|
||||||
|
update_mode_ids: &'i mut UpdateModeIds,
|
||||||
param_map: &'a ParamMap<'a>,
|
param_map: &'a ParamMap<'a>,
|
||||||
procs: &mut MutMap<(Symbol, ProcLayout<'a>), Proc<'a>>,
|
procs: &mut MutMap<(Symbol, ProcLayout<'a>), Proc<'a>>,
|
||||||
) {
|
) {
|
||||||
let ctx = Context::new(arena, param_map);
|
let ctx = Context::new(arena, param_map);
|
||||||
|
|
||||||
|
let mut codegen = CodegenTools {
|
||||||
|
home,
|
||||||
|
ident_ids,
|
||||||
|
update_mode_ids,
|
||||||
|
};
|
||||||
|
|
||||||
for (key, proc) in procs.iter_mut() {
|
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>(
|
fn visit_proc<'a, 'i>(
|
||||||
arena: &'a Bump,
|
arena: &'a Bump,
|
||||||
home: ModuleId,
|
codegen: &mut CodegenTools<'i>,
|
||||||
ident_ids: &'i mut IdentIds,
|
|
||||||
param_map: &'a ParamMap<'a>,
|
param_map: &'a ParamMap<'a>,
|
||||||
ctx: &Context<'a>,
|
ctx: &Context<'a>,
|
||||||
proc: &mut Proc<'a>,
|
proc: &mut Proc<'a>,
|
||||||
|
@ -1364,7 +1364,7 @@ fn visit_proc<'a, 'i>(
|
||||||
|
|
||||||
let stmt = arena.alloc(proc.body.clone());
|
let stmt = arena.alloc(proc.body.clone());
|
||||||
let ctx = ctx.update_var_info_with_params(params);
|
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);
|
let b = ctx.add_dec_for_dead_params(params, b, &b_live_vars);
|
||||||
|
|
||||||
proc.body = b.clone();
|
proc.body = b.clone();
|
||||||
|
|
|
@ -393,11 +393,19 @@ impl<'a> Proc<'a> {
|
||||||
arena: &'a Bump,
|
arena: &'a Bump,
|
||||||
home: ModuleId,
|
home: ModuleId,
|
||||||
ident_ids: &'i mut IdentIds,
|
ident_ids: &'i mut IdentIds,
|
||||||
|
update_mode_ids: &'i mut UpdateModeIds,
|
||||||
procs: &mut MutMap<(Symbol, ProcLayout<'a>), Proc<'a>>,
|
procs: &mut MutMap<(Symbol, ProcLayout<'a>), Proc<'a>>,
|
||||||
) {
|
) {
|
||||||
let borrow_params = arena.alloc(crate::borrow::infer_borrow(arena, procs));
|
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>(
|
pub fn insert_reset_reuse_operations<'i>(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue