From aefe719e56a9a828a45df47ef377afd7c9cb6165 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 28 Nov 2021 14:25:51 +0100 Subject: [PATCH] hook up update mode for reset/reuse --- compiler/mono/src/ir.rs | 11 ++++++++++- compiler/mono/src/reset_reuse.rs | 31 +++++++++++++++++++++---------- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index c2bfe76538..52e54bd195 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -1512,6 +1512,7 @@ impl<'a> Expr<'a> { symbol, tag_name, arguments, + update_mode, .. } => { let doc_tag = match tag_name { @@ -1529,11 +1530,19 @@ impl<'a> Expr<'a> { .text("Reuse ") .append(symbol_to_doc(alloc, *symbol)) .append(alloc.space()) + .append(format!("{:?}", update_mode)) + .append(alloc.space()) .append(doc_tag) .append(alloc.space()) .append(alloc.intersperse(it, " ")) } - Reset { symbol, .. } => alloc.text("Reset ").append(symbol_to_doc(alloc, *symbol)), + Reset { + symbol, + update_mode, + } => alloc.text(format!( + "Reset {{ symbol: {:?}, id: {} }}", + symbol, update_mode.id + )), Struct(args) => { let it = args.iter().map(|s| symbol_to_doc(alloc, *s)); diff --git a/compiler/mono/src/reset_reuse.rs b/compiler/mono/src/reset_reuse.rs index 2cba3eb638..fc63890d73 100644 --- a/compiler/mono/src/reset_reuse.rs +++ b/compiler/mono/src/reset_reuse.rs @@ -1,5 +1,7 @@ use crate::inc_dec::{collect_stmt, occurring_variables_expr, JPLiveVarMap, LiveVarSet}; -use crate::ir::{BranchInfo, Call, Expr, ListLiteralElement, Proc, Stmt, UpdateModeIds}; +use crate::ir::{ + BranchInfo, Call, Expr, ListLiteralElement, Proc, Stmt, UpdateModeId, UpdateModeIds, +}; use crate::layout::{Layout, TagIdIntType, UnionLayout}; use bumpalo::collections::Vec; use bumpalo::Bump; @@ -67,7 +69,7 @@ impl<'a, 'i> Env<'a, 'i> { fn function_s<'a, 'i>( env: &mut Env<'a, 'i>, - w: Symbol, + w: Opportunity, c: &CtorInfo<'a>, stmt: &'a Stmt<'a>, ) -> &'a Stmt<'a> { @@ -85,12 +87,11 @@ fn function_s<'a, 'i>( } if may_reuse(*tag_layout, *tag_id, c) => { // for now, always overwrite the tag ID just to be sure let update_tag_id = true; - let update_mode = env.update_mode_ids.next_id(); let new_expr = Expr::Reuse { - symbol: w, + symbol: w.symbol, + update_mode: w.update_mode, update_tag_id, - update_mode, tag_layout: *tag_layout, tag_id: *tag_id, tag_name: tag_name.clone(), @@ -180,13 +181,22 @@ fn function_s<'a, 'i>( } } +#[derive(Clone, Copy)] +struct Opportunity { + symbol: Symbol, + update_mode: UpdateModeId, +} + fn try_function_s<'a, 'i>( env: &mut Env<'a, 'i>, x: Symbol, c: &CtorInfo<'a>, stmt: &'a Stmt<'a>, ) -> &'a Stmt<'a> { - let w = env.unique_symbol(); + let w = Opportunity { + symbol: env.unique_symbol(), + update_mode: env.update_mode_ids.next_id(), + }; let new_stmt = function_s(env, w, c, stmt); @@ -199,7 +209,7 @@ fn try_function_s<'a, 'i>( fn insert_reset<'a>( env: &mut Env<'a, '_>, - w: Symbol, + w: Opportunity, x: Symbol, union_layout: UnionLayout<'a>, mut stmt: &'a Stmt<'a>, @@ -226,15 +236,16 @@ fn insert_reset<'a>( } } - let update_mode = env.update_mode_ids.next_id(); let reset_expr = Expr::Reset { symbol: x, - update_mode, + update_mode: w.update_mode, }; let layout = Layout::Union(union_layout); - stmt = env.arena.alloc(Stmt::Let(w, reset_expr, layout, stmt)); + stmt = env + .arena + .alloc(Stmt::Let(w.symbol, reset_expr, layout, stmt)); for (symbol, expr, expr_layout) in stack.into_iter().rev() { stmt = env