mirror of
https://github.com/roc-lang/roc.git
synced 2025-11-20 03:59:54 +00:00
Simplify ClosureInfo and enum lambda set switching, which never captures
This commit is contained in:
parent
d6572ef3b7
commit
c003b2d007
1 changed files with 7 additions and 50 deletions
|
|
@ -9361,7 +9361,6 @@ fn match_on_lambda_set<'a>(
|
||||||
let result = union_lambda_set_to_switch(
|
let result = union_lambda_set_to_switch(
|
||||||
env,
|
env,
|
||||||
lambda_set,
|
lambda_set,
|
||||||
Layout::Union(union_layout),
|
|
||||||
closure_tag_id_symbol,
|
closure_tag_id_symbol,
|
||||||
union_layout.tag_id_layout(),
|
union_layout.tag_id_layout(),
|
||||||
closure_data_symbol,
|
closure_data_symbol,
|
||||||
|
|
@ -9387,7 +9386,7 @@ fn match_on_lambda_set<'a>(
|
||||||
}
|
}
|
||||||
ClosureCallOptions::Struct {
|
ClosureCallOptions::Struct {
|
||||||
field_layouts,
|
field_layouts,
|
||||||
field_order_hash,
|
field_order_hash: _,
|
||||||
} => {
|
} => {
|
||||||
let function_symbol = match lambda_set.iter_set().next() {
|
let function_symbol = match lambda_set.iter_set().next() {
|
||||||
Some(function_symbol) => function_symbol,
|
Some(function_symbol) => function_symbol,
|
||||||
|
|
@ -9411,10 +9410,6 @@ fn match_on_lambda_set<'a>(
|
||||||
_ => ClosureInfo::Captures {
|
_ => ClosureInfo::Captures {
|
||||||
lambda_set,
|
lambda_set,
|
||||||
closure_data_symbol,
|
closure_data_symbol,
|
||||||
closure_data_layout: Layout::Struct {
|
|
||||||
field_layouts,
|
|
||||||
field_order_hash,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -9429,7 +9424,7 @@ fn match_on_lambda_set<'a>(
|
||||||
hole,
|
hole,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
ClosureCallOptions::UnwrappedCapture(layout) => {
|
ClosureCallOptions::UnwrappedCapture(_) => {
|
||||||
let function_symbol = lambda_set
|
let function_symbol = lambda_set
|
||||||
.iter_set()
|
.iter_set()
|
||||||
.next()
|
.next()
|
||||||
|
|
@ -9438,7 +9433,6 @@ fn match_on_lambda_set<'a>(
|
||||||
let closure_info = ClosureInfo::Captures {
|
let closure_info = ClosureInfo::Captures {
|
||||||
lambda_set,
|
lambda_set,
|
||||||
closure_data_symbol,
|
closure_data_symbol,
|
||||||
closure_data_layout: layout,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
union_lambda_set_branch_help(
|
union_lambda_set_branch_help(
|
||||||
|
|
@ -9461,7 +9455,6 @@ fn match_on_lambda_set<'a>(
|
||||||
lambda_set.iter_set(),
|
lambda_set.iter_set(),
|
||||||
closure_tag_id_symbol,
|
closure_tag_id_symbol,
|
||||||
Layout::Builtin(Builtin::Bool),
|
Layout::Builtin(Builtin::Bool),
|
||||||
ClosureInfo::DoesNotCapture,
|
|
||||||
argument_symbols,
|
argument_symbols,
|
||||||
argument_layouts,
|
argument_layouts,
|
||||||
return_layout,
|
return_layout,
|
||||||
|
|
@ -9477,7 +9470,6 @@ fn match_on_lambda_set<'a>(
|
||||||
lambda_set.iter_set(),
|
lambda_set.iter_set(),
|
||||||
closure_tag_id_symbol,
|
closure_tag_id_symbol,
|
||||||
Layout::Builtin(Builtin::Int(IntWidth::U8)),
|
Layout::Builtin(Builtin::Int(IntWidth::U8)),
|
||||||
ClosureInfo::DoesNotCapture,
|
|
||||||
argument_symbols,
|
argument_symbols,
|
||||||
argument_layouts,
|
argument_layouts,
|
||||||
return_layout,
|
return_layout,
|
||||||
|
|
@ -9494,7 +9486,6 @@ fn match_on_lambda_set<'a>(
|
||||||
fn union_lambda_set_to_switch<'a>(
|
fn union_lambda_set_to_switch<'a>(
|
||||||
env: &mut Env<'a, '_>,
|
env: &mut Env<'a, '_>,
|
||||||
lambda_set: LambdaSet<'a>,
|
lambda_set: LambdaSet<'a>,
|
||||||
closure_layout: Layout<'a>,
|
|
||||||
closure_tag_id_symbol: Symbol,
|
closure_tag_id_symbol: Symbol,
|
||||||
closure_tag_id_layout: Layout<'a>,
|
closure_tag_id_layout: Layout<'a>,
|
||||||
closure_data_symbol: Symbol,
|
closure_data_symbol: Symbol,
|
||||||
|
|
@ -9523,7 +9514,6 @@ fn union_lambda_set_to_switch<'a>(
|
||||||
ClosureInfo::Captures {
|
ClosureInfo::Captures {
|
||||||
lambda_set,
|
lambda_set,
|
||||||
closure_data_symbol,
|
closure_data_symbol,
|
||||||
closure_data_layout: closure_layout,
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -9597,8 +9587,6 @@ fn union_lambda_set_branch<'a>(
|
||||||
enum ClosureInfo<'a> {
|
enum ClosureInfo<'a> {
|
||||||
Captures {
|
Captures {
|
||||||
closure_data_symbol: Symbol,
|
closure_data_symbol: Symbol,
|
||||||
/// The layout of this closure variant
|
|
||||||
closure_data_layout: Layout<'a>,
|
|
||||||
/// The whole lambda set representation this closure is a variant of
|
/// The whole lambda set representation this closure is a variant of
|
||||||
lambda_set: LambdaSet<'a>,
|
lambda_set: LambdaSet<'a>,
|
||||||
},
|
},
|
||||||
|
|
@ -9620,7 +9608,6 @@ fn union_lambda_set_branch_help<'a>(
|
||||||
ClosureInfo::Captures {
|
ClosureInfo::Captures {
|
||||||
lambda_set,
|
lambda_set,
|
||||||
closure_data_symbol,
|
closure_data_symbol,
|
||||||
closure_data_layout: _,
|
|
||||||
} => {
|
} => {
|
||||||
if lambda_set.is_represented().is_none() {
|
if lambda_set.is_represented().is_none() {
|
||||||
(argument_layouts_slice, argument_symbols_slice)
|
(argument_layouts_slice, argument_symbols_slice)
|
||||||
|
|
@ -9666,13 +9653,14 @@ fn union_lambda_set_branch_help<'a>(
|
||||||
build_call(env, call, assigned, *return_layout, hole)
|
build_call(env, call, assigned, *return_layout, hole)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Switches over a enum lambda set, which may dispatch to different functions, none of which
|
||||||
|
/// capture.
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
fn enum_lambda_set_to_switch<'a>(
|
fn enum_lambda_set_to_switch<'a>(
|
||||||
env: &mut Env<'a, '_>,
|
env: &mut Env<'a, '_>,
|
||||||
lambda_set: impl ExactSizeIterator<Item = LambdaName<'a>>,
|
lambda_set: impl ExactSizeIterator<Item = LambdaName<'a>>,
|
||||||
closure_tag_id_symbol: Symbol,
|
closure_tag_id_symbol: Symbol,
|
||||||
closure_tag_id_layout: Layout<'a>,
|
closure_tag_id_layout: Layout<'a>,
|
||||||
closure_info: ClosureInfo<'a>,
|
|
||||||
argument_symbols: &'a [Symbol],
|
argument_symbols: &'a [Symbol],
|
||||||
argument_layouts: &'a [Layout<'a>],
|
argument_layouts: &'a [Layout<'a>],
|
||||||
return_layout: &'a Layout<'a>,
|
return_layout: &'a Layout<'a>,
|
||||||
|
|
@ -9690,7 +9678,6 @@ fn enum_lambda_set_to_switch<'a>(
|
||||||
env,
|
env,
|
||||||
join_point_id,
|
join_point_id,
|
||||||
lambda_name,
|
lambda_name,
|
||||||
closure_info,
|
|
||||||
argument_symbols,
|
argument_symbols,
|
||||||
argument_layouts,
|
argument_layouts,
|
||||||
return_layout,
|
return_layout,
|
||||||
|
|
@ -9726,14 +9713,14 @@ fn enum_lambda_set_to_switch<'a>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A branch for an enum lambda set branch dispatch, which never capture!
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
fn enum_lambda_set_branch<'a>(
|
fn enum_lambda_set_branch<'a>(
|
||||||
env: &mut Env<'a, '_>,
|
env: &mut Env<'a, '_>,
|
||||||
join_point_id: JoinPointId,
|
join_point_id: JoinPointId,
|
||||||
lambda_name: LambdaName<'a>,
|
lambda_name: LambdaName<'a>,
|
||||||
closure_info: ClosureInfo<'a>,
|
argument_symbols: &'a [Symbol],
|
||||||
argument_symbols_slice: &'a [Symbol],
|
argument_layouts: &'a [Layout<'a>],
|
||||||
argument_layouts_slice: &'a [Layout<'a>],
|
|
||||||
return_layout: &'a Layout<'a>,
|
return_layout: &'a Layout<'a>,
|
||||||
) -> Stmt<'a> {
|
) -> Stmt<'a> {
|
||||||
let result_symbol = env.unique_symbol();
|
let result_symbol = env.unique_symbol();
|
||||||
|
|
@ -9742,36 +9729,6 @@ fn enum_lambda_set_branch<'a>(
|
||||||
|
|
||||||
let assigned = result_symbol;
|
let assigned = result_symbol;
|
||||||
|
|
||||||
let (argument_layouts, argument_symbols) = match closure_info {
|
|
||||||
ClosureInfo::Captures {
|
|
||||||
closure_data_symbol,
|
|
||||||
closure_data_layout,
|
|
||||||
lambda_set,
|
|
||||||
} => {
|
|
||||||
if lambda_set.is_represented().is_none() {
|
|
||||||
(argument_layouts_slice, argument_symbols_slice)
|
|
||||||
} else {
|
|
||||||
// extend layouts with the layout of the closure environment
|
|
||||||
let mut argument_layouts =
|
|
||||||
Vec::with_capacity_in(argument_layouts_slice.len() + 1, env.arena);
|
|
||||||
argument_layouts.extend(argument_layouts_slice);
|
|
||||||
argument_layouts.push(closure_data_layout);
|
|
||||||
|
|
||||||
// extend symbols with the symbol of the closure environment
|
|
||||||
let mut argument_symbols =
|
|
||||||
Vec::with_capacity_in(argument_symbols_slice.len() + 1, env.arena);
|
|
||||||
argument_symbols.extend(argument_symbols_slice);
|
|
||||||
argument_symbols.push(closure_data_symbol);
|
|
||||||
|
|
||||||
(
|
|
||||||
argument_layouts.into_bump_slice(),
|
|
||||||
argument_symbols.into_bump_slice(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ClosureInfo::DoesNotCapture => (argument_layouts_slice, argument_symbols_slice),
|
|
||||||
};
|
|
||||||
|
|
||||||
let call = self::Call {
|
let call = self::Call {
|
||||||
call_type: CallType::ByName {
|
call_type: CallType::ByName {
|
||||||
name: lambda_name,
|
name: lambda_name,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue