mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 16:21:11 +00:00
Collect tags from extension variables during monomorphization
Fixes #2365
This commit is contained in:
parent
2b3f347eec
commit
b2f2fcd6a8
5 changed files with 194 additions and 85 deletions
|
@ -5118,41 +5118,42 @@ fn register_capturing_closure<'a>(
|
|||
|
||||
let is_self_recursive = !matches!(recursive, roc_can::expr::Recursive::NotRecursive);
|
||||
|
||||
// does this function capture any local values?
|
||||
let function_layout = layout_cache.raw_from_var(env.arena, function_type, env.subs);
|
||||
|
||||
let captured_symbols = match function_layout {
|
||||
Ok(RawFunctionLayout::Function(_, lambda_set, _)) => {
|
||||
if let Layout::Struct(&[]) = lambda_set.runtime_representation() {
|
||||
CapturedSymbols::None
|
||||
} else {
|
||||
let mut temp = Vec::from_iter_in(captured_symbols, env.arena);
|
||||
temp.sort();
|
||||
CapturedSymbols::Captured(temp.into_bump_slice())
|
||||
let captured_symbols = match *env.subs.get_content_without_compacting(function_type) {
|
||||
Content::Structure(FlatType::Func(_, closure_var, _)) => {
|
||||
match LambdaSet::from_var(env.arena, env.subs, closure_var, env.ptr_bytes) {
|
||||
Ok(lambda_set) => {
|
||||
if let Layout::Struct(&[]) = lambda_set.runtime_representation() {
|
||||
CapturedSymbols::None
|
||||
} else {
|
||||
let mut temp = Vec::from_iter_in(captured_symbols, env.arena);
|
||||
temp.sort();
|
||||
CapturedSymbols::Captured(temp.into_bump_slice())
|
||||
}
|
||||
}
|
||||
Err(_) => {
|
||||
// just allow this. see https://github.com/rtfeldman/roc/issues/1585
|
||||
if captured_symbols.is_empty() {
|
||||
CapturedSymbols::None
|
||||
} else {
|
||||
let mut temp = Vec::from_iter_in(captured_symbols, env.arena);
|
||||
temp.sort();
|
||||
CapturedSymbols::Captured(temp.into_bump_slice())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(RawFunctionLayout::ZeroArgumentThunk(_)) => {
|
||||
// top-level thunks cannot capture any variables
|
||||
_ => {
|
||||
// This is a value (zero-argument thunk); it cannot capture any variables.
|
||||
debug_assert!(
|
||||
captured_symbols.is_empty(),
|
||||
"{:?} with layout {:?} {:?} {:?}",
|
||||
&captured_symbols,
|
||||
function_layout,
|
||||
layout_cache.raw_from_var(env.arena, function_type, env.subs),
|
||||
env.subs,
|
||||
(function_type, closure_type, closure_ext_var),
|
||||
);
|
||||
CapturedSymbols::None
|
||||
}
|
||||
Err(_) => {
|
||||
// just allow this. see https://github.com/rtfeldman/roc/issues/1585
|
||||
if captured_symbols.is_empty() {
|
||||
CapturedSymbols::None
|
||||
} else {
|
||||
let mut temp = Vec::from_iter_in(captured_symbols, env.arena);
|
||||
temp.sort();
|
||||
CapturedSymbols::Captured(temp.into_bump_slice())
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let partial_proc = PartialProc::from_named_function(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue