From 09748aec4850ecbf439143babf3f57eadf51c427 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Tue, 8 Nov 2022 13:38:42 -0600 Subject: [PATCH] Remove problems from error type API surface --- crates/compiler/solve/src/ability.rs | 11 +++---- crates/compiler/solve/src/solve.rs | 10 +++---- crates/compiler/types/src/subs.rs | 10 ++----- crates/compiler/unify/src/unify.rs | 44 ++++++++++++---------------- crates/reporting/src/error/expect.rs | 2 +- 5 files changed, 32 insertions(+), 45 deletions(-) diff --git a/crates/compiler/solve/src/ability.rs b/crates/compiler/solve/src/ability.rs index f335bf78bb..4768ab0438 100644 --- a/crates/compiler/solve/src/ability.rs +++ b/crates/compiler/solve/src/ability.rs @@ -191,8 +191,7 @@ impl ObligationCache { // Demote the bad variable that exposed this problem to an error, both so // that we have an ErrorType to report and so that codegen knows to deal // with the error later. - let (error_type, _moar_ghosts_n_stuff) = - subs.var_to_error_type(var, Polarity::OF_VALUE); + let error_type = subs.var_to_error_type(var, Polarity::OF_VALUE); problems.push(TypeError::BadExprMissingAbility( region, category, @@ -209,8 +208,7 @@ impl ObligationCache { // Demote the bad variable that exposed this problem to an error, both so // that we have an ErrorType to report and so that codegen knows to deal // with the error later. - let (error_type, _moar_ghosts_n_stuff) = - subs.var_to_error_type(var, Polarity::OF_PATTERN); + let error_type = subs.var_to_error_type(var, Polarity::OF_PATTERN); problems.push(TypeError::BadPatternMissingAbility( region, category, @@ -311,15 +309,14 @@ impl ObligationCache { })) => Some(if failure_var == var { UnderivableReason::SurfaceNotDerivable(context) } else { - let (error_type, _skeletons) = - subs.var_to_error_type(failure_var, Polarity::OF_VALUE); + let error_type = subs.var_to_error_type(failure_var, Polarity::OF_VALUE); UnderivableReason::NestedNotDerivable(error_type, context) }), None => Some(UnderivableReason::NotABuiltin), }; if let Some(underivable_reason) = opt_underivable { - let (error_type, _skeletons) = subs.var_to_error_type(var, Polarity::OF_VALUE); + let error_type = subs.var_to_error_type(var, Polarity::OF_VALUE); Err(Unfulfilled::AdhocUnderivable { typ: error_type, diff --git a/crates/compiler/solve/src/solve.rs b/crates/compiler/solve/src/solve.rs index dc12637ce4..f2d1151f68 100644 --- a/crates/compiler/solve/src/solve.rs +++ b/crates/compiler/solve/src/solve.rs @@ -2013,7 +2013,7 @@ fn check_ability_specialization( // Commit so that the bad signature and its error persists in subs. subs.commit_snapshot(snapshot); - let (_typ, _problems) = + let _typ = subs.var_to_error_type(symbol_loc_var.value, Polarity::OF_VALUE); let problem = TypeError::WrongSpecialization { @@ -2034,7 +2034,7 @@ fn check_ability_specialization( // Commit so that `var` persists in subs. subs.commit_snapshot(snapshot); - let (typ, _problems) = subs.var_to_error_type(var, Polarity::OF_VALUE); + let typ = subs.var_to_error_type(var, Polarity::OF_VALUE); let problem = TypeError::StructuralSpecialization { region: symbol_loc_var.region, @@ -2056,9 +2056,9 @@ fn check_ability_specialization( // so we can have two separate error types. subs.rollback_to(snapshot); - let (expected_type, _problems) = + let expected_type = subs.var_to_error_type(root_signature_var, Polarity::OF_VALUE); - let (actual_type, _problems) = + let actual_type = subs.var_to_error_type(symbol_loc_var.value, Polarity::OF_VALUE); let reason = Reason::GeneralizedAbilityMemberSpecialization { @@ -3492,7 +3492,7 @@ fn circular_error( loc_var: &Loc, ) { let var = loc_var.value; - let (error_type, _) = subs.var_to_error_type(var, Polarity::OF_VALUE); + let error_type = subs.var_to_error_type(var, Polarity::OF_VALUE); let problem = TypeError::CircularType(loc_var.region, symbol, error_type); subs.set_content(var, Content::Error); diff --git a/crates/compiler/types/src/subs.rs b/crates/compiler/types/src/subs.rs index 569381de87..d0572618c6 100644 --- a/crates/compiler/types/src/subs.rs +++ b/crates/compiler/types/src/subs.rs @@ -2041,11 +2041,7 @@ impl Subs { explicit_substitute(self, x, y, z, &mut seen) } - pub fn var_to_error_type( - &mut self, - var: Variable, - observed_pol: Polarity, - ) -> (ErrorType, Vec) { + pub fn var_to_error_type(&mut self, var: Variable, observed_pol: Polarity) -> ErrorType { self.var_to_error_type_contextual(var, ErrorTypeContext::None, observed_pol) } @@ -2054,7 +2050,7 @@ impl Subs { var: Variable, context: ErrorTypeContext, observed_pol: Polarity, - ) -> (ErrorType, Vec) { + ) -> ErrorType { let names = get_var_names(self, var, ImMap::default()); let mut taken = MutSet::default(); @@ -2069,7 +2065,7 @@ impl Subs { recursive_tag_unions_seen: Vec::new(), }; - (var_to_err_type(self, &mut state, var, observed_pol), vec![]) + var_to_err_type(self, &mut state, var, observed_pol) } pub fn len(&self) -> usize { diff --git a/crates/compiler/unify/src/unify.rs b/crates/compiler/unify/src/unify.rs index a309fc697a..6f4f87119b 100644 --- a/crates/compiler/unify/src/unify.rs +++ b/crates/compiler/unify/src/unify.rs @@ -419,35 +419,29 @@ fn unify_help( ErrorTypeContext::None }; - let (type1, mut problems) = - env.subs - .var_to_error_type_contextual(var1, error_context, observed_pol); - let (type2, problems2) = - env.subs - .var_to_error_type_contextual(var2, error_context, observed_pol); - - problems.extend(problems2); + let type1 = env + .subs + .var_to_error_type_contextual(var1, error_context, observed_pol); + let type2 = env + .subs + .var_to_error_type_contextual(var2, error_context, observed_pol); env.subs.union(var1, var2, Content::Error.into()); - if !problems.is_empty() { - Unified::BadType(vars, problems.remove(0)) - } else { - let do_not_implement_ability = mismatches - .into_iter() - .filter_map(|mismatch| match mismatch { - Mismatch::DoesNotImplementAbiity(var, ab) => { - let (err_type, _new_problems) = - env.subs - .var_to_error_type_contextual(var, error_context, observed_pol); - Some((err_type, ab)) - } - _ => None, - }) - .collect(); + let do_not_implement_ability = mismatches + .into_iter() + .filter_map(|mismatch| match mismatch { + Mismatch::DoesNotImplementAbiity(var, ab) => { + let err_type = + env.subs + .var_to_error_type_contextual(var, error_context, observed_pol); + Some((err_type, ab)) + } + _ => None, + }) + .collect(); - Unified::Failure(vars, type1, type2, do_not_implement_ability) - } + Unified::Failure(vars, type1, type2, do_not_implement_ability) } } diff --git a/crates/reporting/src/error/expect.rs b/crates/reporting/src/error/expect.rs index 45888f35a7..aca95f1215 100644 --- a/crates/reporting/src/error/expect.rs +++ b/crates/reporting/src/error/expect.rs @@ -83,7 +83,7 @@ impl<'a> Renderer<'a> { .zip(variables) .zip(expressions) .map(|((symbol, variable), expr)| { - let (error_type, _) = subs.var_to_error_type(*variable, Polarity::OF_VALUE); + let error_type = subs.var_to_error_type(*variable, Polarity::OF_VALUE); self.render_lookup(*symbol, expr, error_type) });