mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 13:29:12 +00:00
Make sure to clone lambda names in can/copy
This commit is contained in:
parent
987ebfa9d3
commit
7c2e806a02
1 changed files with 25 additions and 6 deletions
|
@ -2,7 +2,10 @@ use crate::{
|
||||||
def::Def,
|
def::Def,
|
||||||
expr::{AccessorData, ClosureData, Expr, Field, OpaqueWrapFunctionData, WhenBranch},
|
expr::{AccessorData, ClosureData, Expr, Field, OpaqueWrapFunctionData, WhenBranch},
|
||||||
};
|
};
|
||||||
use roc_module::ident::{Lowercase, TagName};
|
use roc_module::{
|
||||||
|
ident::{Lowercase, TagName},
|
||||||
|
symbol::Symbol,
|
||||||
|
};
|
||||||
use roc_types::{
|
use roc_types::{
|
||||||
subs::{
|
subs::{
|
||||||
self, AliasVariables, Descriptor, GetSubsSlice, OptVariable, RecordFields, Subs, SubsIndex,
|
self, AliasVariables, Descriptor, GetSubsSlice, OptVariable, RecordFields, Subs, SubsIndex,
|
||||||
|
@ -62,6 +65,8 @@ trait CopyEnv {
|
||||||
|
|
||||||
fn clone_tag_names(&mut self, tag_names: SubsSlice<TagName>) -> SubsSlice<TagName>;
|
fn clone_tag_names(&mut self, tag_names: SubsSlice<TagName>) -> SubsSlice<TagName>;
|
||||||
|
|
||||||
|
fn clone_lambda_names(&mut self, lambda_names: SubsSlice<Symbol>) -> SubsSlice<Symbol>;
|
||||||
|
|
||||||
fn clone_record_fields(
|
fn clone_record_fields(
|
||||||
&mut self,
|
&mut self,
|
||||||
record_fields: SubsSlice<RecordField<()>>,
|
record_fields: SubsSlice<RecordField<()>>,
|
||||||
|
@ -104,6 +109,11 @@ impl CopyEnv for Subs {
|
||||||
tag_names
|
tag_names
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
fn clone_lambda_names(&mut self, lambda_names: SubsSlice<Symbol>) -> SubsSlice<Symbol> {
|
||||||
|
lambda_names
|
||||||
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn clone_record_fields(
|
fn clone_record_fields(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
@ -160,6 +170,14 @@ impl<'a> CopyEnv for AcrossSubs<'a> {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
fn clone_lambda_names(&mut self, lambda_names: SubsSlice<Symbol>) -> SubsSlice<Symbol> {
|
||||||
|
SubsSlice::extend_new(
|
||||||
|
&mut self.target.closure_names,
|
||||||
|
self.source.get_subs_slice(lambda_names).iter().cloned(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn clone_record_fields(
|
fn clone_record_fields(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
@ -186,9 +204,9 @@ pub fn deep_copy_expr_across_subs(
|
||||||
target: &mut Subs,
|
target: &mut Subs,
|
||||||
var: Variable,
|
var: Variable,
|
||||||
expr: &Expr,
|
expr: &Expr,
|
||||||
) -> Option<(Variable, Expr)> {
|
) -> (Variable, Expr) {
|
||||||
let mut across_subs = AcrossSubs { source, target };
|
let mut across_subs = AcrossSubs { source, target };
|
||||||
deep_copy_type_vars_into_expr_help(&mut across_subs, var, expr)
|
deep_copy_type_vars_into_expr_help(&mut across_subs, var, expr).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Deep copies all type variables in [`expr`].
|
/// Deep copies all type variables in [`expr`].
|
||||||
|
@ -849,8 +867,10 @@ fn deep_copy_type_vars<C: CopyEnv>(
|
||||||
env.target().variable_slices[target_index] = new_variables;
|
env.target().variable_slices[target_index] = new_variables;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let new_solved_labels = env.clone_lambda_names(solved.labels());
|
||||||
|
|
||||||
let new_solved =
|
let new_solved =
|
||||||
UnionLambdas::from_slices(solved.labels(), new_variable_slices);
|
UnionLambdas::from_slices(new_solved_labels, new_variable_slices);
|
||||||
|
|
||||||
let new_unspecialized =
|
let new_unspecialized =
|
||||||
SubsSlice::reserve_uls_slice(env.target(), unspecialized.len());
|
SubsSlice::reserve_uls_slice(env.target(), unspecialized.len());
|
||||||
|
@ -1107,8 +1127,7 @@ mod test {
|
||||||
)],
|
)],
|
||||||
};
|
};
|
||||||
|
|
||||||
let (var, expr) =
|
let (var, expr) = deep_copy_expr_across_subs(&mut source, &mut target, var1, &expr);
|
||||||
deep_copy_expr_across_subs(&mut source, &mut target, var1, &expr).unwrap();
|
|
||||||
|
|
||||||
assert!(source.get_copy(var1).is_none());
|
assert!(source.get_copy(var1).is_none());
|
||||||
assert!(source.get_copy(var2).is_none());
|
assert!(source.get_copy(var2).is_none());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue