Coupon cutting

This commit is contained in:
Ayaz Hafiz 2022-05-04 17:49:42 -04:00 committed by ayazhafiz
parent a242a90416
commit c1b1f60630
4 changed files with 10 additions and 17 deletions

View file

@ -1843,6 +1843,7 @@ fn make_tag_union_recursive_help<'a, 'b>(
// NB: We need to collect the type arguments to shut off rustc's closure type // NB: We need to collect the type arguments to shut off rustc's closure type
// instantiator. Otherwise we get unfortunate errors like // instantiator. Otherwise we get unfortunate errors like
// reached the recursion limit while instantiating `make_tag_union_recursive_help::<...n/src/def.rs:1879:65: 1879:77]>>` // reached the recursion limit while instantiating `make_tag_union_recursive_help::<...n/src/def.rs:1879:65: 1879:77]>>`
#[allow(clippy::needless_collect)]
let type_arguments: Vec<&Type> = type_arguments.iter().map(|ta| &ta.typ).collect(); let type_arguments: Vec<&Type> = type_arguments.iter().map(|ta| &ta.typ).collect();
let recursive_alias = Loc::at_zero((symbol, type_arguments.into_iter())); let recursive_alias = Loc::at_zero((symbol, type_arguments.into_iter()));

View file

@ -4922,14 +4922,7 @@ fn get_specialization<'a>(
Some(member) => { Some(member) => {
let snapshot = env.subs.snapshot(); let snapshot = env.subs.snapshot();
instantiate_rigids(env.subs, member.signature_var); instantiate_rigids(env.subs, member.signature_var);
let this_f = env.subs.get_content_without_compacting(symbol_var);
let member_f = env
.subs
.get_content_without_compacting(member.signature_var);
use roc_types::subs::SubsFmtContent;
let this_f = SubsFmtContent(&this_f, env.subs);
let member_f = SubsFmtContent(&member_f, env.subs);
dbg!(symbol, this_f, member_f);
let (_, must_implement_ability) = unify( let (_, must_implement_ability) = unify(
env.subs, env.subs,
symbol_var, symbol_var,
@ -4938,6 +4931,7 @@ fn get_specialization<'a>(
) )
.expect_success("This typechecked previously"); .expect_success("This typechecked previously");
env.subs.rollback_to(snapshot); env.subs.rollback_to(snapshot);
let specializing_type = let specializing_type =
type_implementing_member(&must_implement_ability, member.parent_ability); type_implementing_member(&must_implement_ability, member.parent_ability);

View file

@ -170,15 +170,12 @@ pub fn type_implementing_member(
ability: Symbol, ability: Symbol,
) -> Symbol { ) -> Symbol {
debug_assert_eq!({ debug_assert_eq!({
let ability_implementations_for_specialization =
specialization_must_implement_constraints specialization_must_implement_constraints
.clone() .clone()
.get_unique() .get_unique()
.into_iter() .into_iter()
.filter(|mia| mia.ability == ability) .filter(|mia| mia.ability == ability)
.count(); .count()
ability_implementations_for_specialization
}, },
1, 1,
"Multiple variables bound to an ability - this is ambiguous and should have been caught in canonicalization: {:?}", "Multiple variables bound to an ability - this is ambiguous and should have been caught in canonicalization: {:?}",

View file

@ -327,6 +327,7 @@ impl Aliases {
} }
let old_type_variables = delayed_variables.type_variables(&mut self.variables); let old_type_variables = delayed_variables.type_variables(&mut self.variables);
#[allow(clippy::needless_collect)] // otherwise we borrow self.variables immutably twice
let variable_opt_abilities: Vec<_> = let variable_opt_abilities: Vec<_> =
old_type_variables.iter().map(|ov| ov.opt_ability).collect(); old_type_variables.iter().map(|ov| ov.opt_ability).collect();
let new_type_variables = &subs.variables[alias_variables.type_variables().indices()]; let new_type_variables = &subs.variables[alias_variables.type_variables().indices()];