Merge pull request #5327 from JTeeuwissen/symbol_tags

symbol_tag instead of layout_tag
This commit is contained in:
Folkert de Vries 2023-04-30 18:26:01 +02:00 committed by GitHub
commit 42f2a96a3a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -64,7 +64,7 @@ fn insert_reset_reuse_operations_proc<'a, 'i>(
} }
let mut env = ReuseEnvironment { let mut env = ReuseEnvironment {
layout_tags: MutMap::default(), symbol_tags: MutMap::default(),
reuse_tokens: MutMap::default(), reuse_tokens: MutMap::default(),
symbol_layouts: symbol_layout, symbol_layouts: symbol_layout,
joinpoint_reuse_tokens: MutMap::default(), joinpoint_reuse_tokens: MutMap::default(),
@ -128,7 +128,7 @@ fn insert_reset_reuse_operations_stmt<'a, 'i>(
} => { } => {
// The value of the tag is currently only used in the case of nullable recursive unions. // The value of the tag is currently only used in the case of nullable recursive unions.
// But for completeness we add every kind of union to the layout_tags. // But for completeness we add every kind of union to the layout_tags.
environment.add_layout_tag(layout, *tag_id); environment.add_symbol_tag(*binding, *tag_id);
// Check if the tag id for this layout can be reused at all. // Check if the tag id for this layout can be reused at all.
match can_reuse_union_layout_tag(tag_layout, Option::Some(*tag_id)) { match can_reuse_union_layout_tag(tag_layout, Option::Some(*tag_id)) {
@ -193,12 +193,12 @@ fn insert_reset_reuse_operations_stmt<'a, 'i>(
.map(|(tag_id, info, branch)| { .map(|(tag_id, info, branch)| {
let mut branch_env = environment.clone(); let mut branch_env = environment.clone();
if let BranchInfo::Constructor { if let BranchInfo::Constructor {
scrutinee,
tag_id: tag, tag_id: tag,
layout: branch_layout,
.. ..
} = info } = info
{ {
branch_env.add_layout_tag(branch_layout, *tag); branch_env.add_symbol_tag(*scrutinee, *tag);
} }
let new_branch = insert_reset_reuse_operations_stmt( let new_branch = insert_reset_reuse_operations_stmt(
@ -220,12 +220,12 @@ fn insert_reset_reuse_operations_stmt<'a, 'i>(
let mut branch_env = environment.clone(); let mut branch_env = environment.clone();
if let BranchInfo::Constructor { if let BranchInfo::Constructor {
scrutinee,
tag_id: tag, tag_id: tag,
layout: branch_layout,
.. ..
} = info } = info
{ {
branch_env.add_layout_tag(branch_layout, *tag); branch_env.add_symbol_tag(*scrutinee, *tag);
} }
let new_branch = insert_reset_reuse_operations_stmt( let new_branch = insert_reset_reuse_operations_stmt(
@ -355,7 +355,12 @@ fn insert_reset_reuse_operations_stmt<'a, 'i>(
match layout_option.clone() { match layout_option.clone() {
LayoutOption::Layout(layout) LayoutOption::Layout(layout)
if matches!( if matches!(
can_reuse_layout(layout_interner, environment, layout), symbol_layout_reusability(
layout_interner,
environment,
symbol,
layout
),
Reuse::Reusable Reuse::Reusable
) => ) =>
{ {
@ -590,7 +595,7 @@ fn insert_reset_reuse_operations_stmt<'a, 'i>(
// Create a new environment for the body. With everything but the jump reuse tokens. As those should be given by the jump. // Create a new environment for the body. With everything but the jump reuse tokens. As those should be given by the jump.
let mut first_pass_body_environment = ReuseEnvironment { let mut first_pass_body_environment = ReuseEnvironment {
layout_tags: environment.layout_tags.clone(), symbol_tags: environment.symbol_tags.clone(),
reuse_tokens: max_reuse_token_symbols.clone(), reuse_tokens: max_reuse_token_symbols.clone(),
symbol_layouts: environment.symbol_layouts.clone(), symbol_layouts: environment.symbol_layouts.clone(),
joinpoint_reuse_tokens: environment.joinpoint_reuse_tokens.clone(), joinpoint_reuse_tokens: environment.joinpoint_reuse_tokens.clone(),
@ -764,7 +769,7 @@ fn insert_reset_reuse_operations_stmt<'a, 'i>(
let (second_pass_body_environment, second_pass_body) = { let (second_pass_body_environment, second_pass_body) = {
// Create a new environment for the body. With everything but the jump reuse tokens. As those should be given by the jump. // Create a new environment for the body. With everything but the jump reuse tokens. As those should be given by the jump.
let mut body_environment = ReuseEnvironment { let mut body_environment = ReuseEnvironment {
layout_tags: environment.layout_tags.clone(), symbol_tags: environment.symbol_tags.clone(),
reuse_tokens: used_reuse_tokens.clone(), reuse_tokens: used_reuse_tokens.clone(),
symbol_layouts: environment.symbol_layouts.clone(), symbol_layouts: environment.symbol_layouts.clone(),
joinpoint_reuse_tokens: environment.joinpoint_reuse_tokens.clone(), joinpoint_reuse_tokens: environment.joinpoint_reuse_tokens.clone(),
@ -913,12 +918,6 @@ enum Reuse {
Nonreusable, Nonreusable,
} }
/**
Map containing the curren't known tag of a layout.
A layout with a tag will be inserted e.g. after pattern matching. where the tag is known.
*/
type LayoutTags<'a> = MutMap<&'a InLayout<'a>, Tag>;
/** /**
Map containing the reuse tokens of a layout. Map containing the reuse tokens of a layout.
A vec is used as a stack as we want to use the latest reuse token available. A vec is used as a stack as we want to use the latest reuse token available.
@ -976,7 +975,7 @@ enum JoinPointReuseTokens<'a> {
#[derive(Default, Clone)] #[derive(Default, Clone)]
struct ReuseEnvironment<'a> { struct ReuseEnvironment<'a> {
layout_tags: LayoutTags<'a>, symbol_tags: MutMap<Symbol, Tag>,
reuse_tokens: ReuseTokens<'a>, reuse_tokens: ReuseTokens<'a>,
symbol_layouts: SymbolLayout<'a>, symbol_layouts: SymbolLayout<'a>,
// A map containing the amount of reuse tokens a join point expects for each layout. // A map containing the amount of reuse tokens a join point expects for each layout.
@ -990,15 +989,15 @@ impl<'a> ReuseEnvironment<'a> {
Add the known tag for a layout. Add the known tag for a layout.
Used to optimize reuse of unions that are know to have a null pointer. Used to optimize reuse of unions that are know to have a null pointer.
*/ */
fn add_layout_tag(&mut self, layout: &'a InLayout<'a>, tag: Tag) { fn add_symbol_tag(&mut self, symbol: Symbol, tag: Tag) {
self.layout_tags.insert(layout, tag); self.symbol_tags.insert(symbol, tag);
} }
/** /**
Retrieve the known tag for a layout. Retrieve the known tag for a layout.
*/ */
fn get_layout_tag(&self, layout: &InLayout<'a>) -> Option<Tag> { fn get_symbol_tag(&self, symbol: &Symbol) -> Option<Tag> {
self.layout_tags.get(layout).copied() self.symbol_tags.get(symbol).copied()
} }
/** /**
@ -1128,14 +1127,15 @@ impl<'a> ReuseEnvironment<'a> {
/** /**
Check if a layout can be reused. by verifying if the layout is a union and if the tag is not nullable. Check if a layout can be reused. by verifying if the layout is a union and if the tag is not nullable.
*/ */
fn can_reuse_layout<'a>( fn symbol_layout_reusability<'a>(
layout_interner: &STLayoutInterner<'a>, layout_interner: &STLayoutInterner<'a>,
environment: &ReuseEnvironment<'a>, environment: &ReuseEnvironment<'a>,
symbol: &Symbol,
layout: &InLayout<'a>, layout: &InLayout<'a>,
) -> Reuse { ) -> Reuse {
match layout_interner.get(*layout) { match layout_interner.get(*layout) {
Layout::Union(union_layout) => { Layout::Union(union_layout) => {
can_reuse_union_layout_tag(&union_layout, environment.get_layout_tag(layout)) can_reuse_union_layout_tag(&union_layout, environment.get_symbol_tag(symbol))
} }
// Strings literals are constants. // Strings literals are constants.
// Arrays are probably given to functions and reused there. Little use to reuse them here. // Arrays are probably given to functions and reused there. Little use to reuse them here.