Remove problems from error type API surface

This commit is contained in:
Ayaz Hafiz 2022-11-08 13:38:42 -06:00
parent b6322ff883
commit 09748aec48
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
5 changed files with 32 additions and 45 deletions

View file

@ -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,

View file

@ -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<Variable>,
) {
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);

View file

@ -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<Problem>) {
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<Problem>) {
) -> 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 {

View file

@ -419,25 +419,20 @@ fn unify_help<M: MetaCollector>(
ErrorTypeContext::None
};
let (type1, mut problems) =
env.subs
let type1 = env
.subs
.var_to_error_type_contextual(var1, error_context, observed_pol);
let (type2, problems2) =
env.subs
let type2 = env
.subs
.var_to_error_type_contextual(var2, error_context, observed_pol);
problems.extend(problems2);
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) =
let err_type =
env.subs
.var_to_error_type_contextual(var, error_context, observed_pol);
Some((err_type, ab))
@ -449,7 +444,6 @@ fn unify_help<M: MetaCollector>(
Unified::Failure(vars, type1, type2, do_not_implement_ability)
}
}
}
#[inline(always)]
#[must_use]

View file

@ -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)
});