Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
folkertdev committed Jun 28, 2023
1 parent 5d3f85a commit 544b41b
Showing 1 changed file with 13 additions and 33 deletions.
46 changes: 13 additions & 33 deletions crates/compiler/mono/src/reset_reuse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use std::hash::Hash;

use crate::borrow::Ownership;
use crate::ir::{
BranchInfo, Expr, JoinPointId, ModifyRc, Param, Proc, ProcLayout, Stmt, UpdateModeId,
UpdateModeIds,
BranchInfo, Expr, JoinPointId, ModifyRc, Param, Proc, ProcLayout, ReuseToken, Stmt,
UpdateModeId, UpdateModeIds,
};
use crate::layout::{InLayout, LayoutInterner, LayoutRepr, STLayoutInterner, UnionLayout};

Expand Down Expand Up @@ -153,16 +153,9 @@ fn insert_reset_reuse_operations_stmt<'a, 'i>(
)) {
// We have a reuse token for this layout, use it.
Some(TokenWithInLayout {
token: reuse_token,
token: mut reuse_token,
inlayout: layout_info,
}) => {
let reuse_token = crate::ir::ReuseToken {
symbol: reuse_token.symbol,
update_mode: reuse_token.update_mode_id,
// for now, always overwrite the tag ID just to be sure
update_tag_id: true,
};

if layout_info == layout {
// The reuse token layout is the same, we can use it without casting.
(
Expand All @@ -188,12 +181,8 @@ fn insert_reset_reuse_operations_stmt<'a, 'i>(
))
};

let reuse_token = crate::ir::ReuseToken {
symbol: new_symbol,
update_mode: reuse_token.update_mode,
// for now, always overwrite the tag ID just to be sure
update_tag_id: true,
};
// we now want to reuse the cast pointer
reuse_token.symbol = new_symbol;

(
Some(ptr_cast),
Expand Down Expand Up @@ -491,7 +480,9 @@ fn insert_reset_reuse_operations_stmt<'a, 'i>(

let reuse_token = ReuseToken {
symbol: reuse_symbol,
update_mode_id: update_mode_ids.next_id(),
update_mode: update_mode_ids.next_id(),
// for now, always overwrite the tag ID just to be sure
update_tag_id: true,
};

let owned_layout = **layout;
Expand Down Expand Up @@ -553,7 +544,7 @@ fn insert_reset_reuse_operations_stmt<'a, 'i>(
// a dec will be replaced by a reset.
let reset_expr = Expr::Reset {
symbol,
update_mode: reuse_token.update_mode_id,
update_mode: reuse_token.update_mode,
};

return arena.alloc(Stmt::Let(
Expand All @@ -567,7 +558,7 @@ fn insert_reset_reuse_operations_stmt<'a, 'i>(
// a decref will be replaced by a resetref.
let reset_expr = Expr::ResetRef {
symbol,
update_mode: reuse_token.update_mode_id,
update_mode: reuse_token.update_mode,
};

return arena.alloc(Stmt::Let(
Expand Down Expand Up @@ -753,7 +744,9 @@ fn insert_reset_reuse_operations_stmt<'a, 'i>(
tokens.iter().map(|token| TokenWithInLayout {
token: ReuseToken {
symbol: Symbol::new(home, ident_ids.gen_unique()),
update_mode_id: update_mode_ids.next_id(),
update_mode: update_mode_ids.next_id(),
// for now, always overwrite the tag ID just to be sure
update_tag_id: true,
},
inlayout: token.inlayout,
}),
Expand Down Expand Up @@ -1140,19 +1133,6 @@ struct TokenLayout {
alignment: u32,
}

/**
A reuse token is a symbol that is used to reset a layout.
Matches symbols that are pointers.
*/
#[derive(Clone, Copy, PartialEq, Eq)]
struct ReuseToken {
// The symbol of the reuse token.
symbol: Symbol,

// Index that can be used later to determine if in place mutation is possible.
update_mode_id: UpdateModeId,
}

/**
Combines a reuse token with it's possible layout info.
*/
Expand Down

0 comments on commit 544b41b

Please sign in to comment.