From 281bc94b55e1755839aff0490375d88cb7a3236a Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Tue, 8 Nov 2022 13:31:22 -0600 Subject: [PATCH] Remove FlatType::Erroneous --- crates/ast/src/solve_type.rs | 6 ++--- crates/compiler/can/src/copy.rs | 2 +- crates/compiler/can/src/exhaustive.rs | 1 - crates/compiler/derive_key/src/decoding.rs | 1 - crates/compiler/derive_key/src/encoding.rs | 1 - crates/compiler/derive_key/src/hash.rs | 1 - crates/compiler/mono/src/layout.rs | 3 +-- crates/compiler/mono/src/layout_soa.rs | 3 --- crates/compiler/solve/src/ability.rs | 7 ----- crates/compiler/solve/src/solve.rs | 12 ++------- crates/compiler/types/src/pretty_print.rs | 3 +-- crates/compiler/types/src/subs.rs | 31 ++++------------------ crates/glue/src/types.rs | 1 - 13 files changed, 12 insertions(+), 60 deletions(-) diff --git a/crates/ast/src/solve_type.rs b/crates/ast/src/solve_type.rs index b3338d6575..ec8c57bf0d 100644 --- a/crates/ast/src/solve_type.rs +++ b/crates/ast/src/solve_type.rs @@ -1455,8 +1455,6 @@ fn adjust_rank_content( rank } - - Erroneous(_) => group_rank, } } @@ -1595,7 +1593,7 @@ fn instantiate_rigids_help( } } - EmptyRecord | EmptyTagUnion | Erroneous(_) => {} + EmptyRecord | EmptyTagUnion => {} Record(fields, ext_var) => { for index in fields.iter_variables() { @@ -1775,7 +1773,7 @@ fn deep_copy_var_help( Func(arg_vars, new_closure_var, new_ret_var) } - same @ EmptyRecord | same @ EmptyTagUnion | same @ Erroneous(_) => same, + same @ EmptyRecord | same @ EmptyTagUnion => same, Record(fields, ext_var) => { let record_fields = { diff --git a/crates/compiler/can/src/copy.rs b/crates/compiler/can/src/copy.rs index b44952ce50..71c18ef9dc 100644 --- a/crates/compiler/can/src/copy.rs +++ b/crates/compiler/can/src/copy.rs @@ -844,7 +844,7 @@ fn deep_copy_type_vars( // Everything else is a mechanical descent. Structure(flat_type) => match flat_type { - EmptyRecord | EmptyTagUnion | Erroneous(_) => Structure(flat_type), + EmptyRecord | EmptyTagUnion => Structure(flat_type), Apply(symbol, arguments) => { descend_slice!(arguments); diff --git a/crates/compiler/can/src/exhaustive.rs b/crates/compiler/can/src/exhaustive.rs index 476fef14d1..229e9b9bfc 100644 --- a/crates/compiler/can/src/exhaustive.rs +++ b/crates/compiler/can/src/exhaustive.rs @@ -148,7 +148,6 @@ fn index_var( FlatType::Func(_, _, _) | FlatType::FunctionOrTagUnion(_, _, _) => { return Err(TypeError) } - FlatType::Erroneous(_) => return Err(TypeError), FlatType::Apply(Symbol::LIST_LIST, args) => { match (subs.get_subs_slice(*args), ctor) { ([elem_var], IndexCtor::List) => { diff --git a/crates/compiler/derive_key/src/decoding.rs b/crates/compiler/derive_key/src/decoding.rs index 6170499bc0..5063f1d985 100644 --- a/crates/compiler/derive_key/src/decoding.rs +++ b/crates/compiler/derive_key/src/decoding.rs @@ -72,7 +72,6 @@ impl FlatDecodable { Err(Underivable) // yet } // - FlatType::Erroneous(_) => Err(Underivable), FlatType::Func(..) => Err(Underivable), }, Content::Alias(sym, _, real_var, _) => match sym { diff --git a/crates/compiler/derive_key/src/encoding.rs b/crates/compiler/derive_key/src/encoding.rs index c4ec118687..4485a257c8 100644 --- a/crates/compiler/derive_key/src/encoding.rs +++ b/crates/compiler/derive_key/src/encoding.rs @@ -106,7 +106,6 @@ impl FlatEncodable { FlatType::EmptyRecord => Ok(Key(FlatEncodableKey::Record(vec![]))), FlatType::EmptyTagUnion => Ok(Key(FlatEncodableKey::TagUnion(vec![]))), // - FlatType::Erroneous(_) => Err(Underivable), FlatType::Func(..) => Err(Underivable), }, Content::Alias(sym, _, real_var, _) => match sym { diff --git a/crates/compiler/derive_key/src/hash.rs b/crates/compiler/derive_key/src/hash.rs index 01d68c28e6..94842e669f 100644 --- a/crates/compiler/derive_key/src/hash.rs +++ b/crates/compiler/derive_key/src/hash.rs @@ -103,7 +103,6 @@ impl FlatHash { FlatType::EmptyRecord => Ok(Key(FlatHashKey::Record(vec![]))), FlatType::EmptyTagUnion => Ok(Key(FlatHashKey::TagUnion(vec![]))), // - FlatType::Erroneous(_) => Err(Underivable), FlatType::Func(..) => Err(Underivable), }, Content::Alias(sym, _, real_var, _) => match sym { diff --git a/crates/compiler/mono/src/layout.rs b/crates/compiler/mono/src/layout.rs index 3b22bd379c..64e13f3bd2 100644 --- a/crates/compiler/mono/src/layout.rs +++ b/crates/compiler/mono/src/layout.rs @@ -1979,7 +1979,7 @@ fn lambda_set_size(subs: &Subs, var: Variable) -> (usize, usize, usize) { } stack.push((*ext, depth_any + 1, depth_lset)); } - FlatType::Erroneous(_) | FlatType::EmptyRecord | FlatType::EmptyTagUnion => {} + FlatType::EmptyRecord | FlatType::EmptyTagUnion => {} }, Content::FlexVar(_) | Content::RigidVar(_) @@ -3188,7 +3188,6 @@ fn layout_from_flat_type<'a>( layout_from_recursive_union(env, rec_var, &tags) } EmptyTagUnion => cacheable(Ok(Layout::VOID)), - Erroneous(_) => cacheable(Err(LayoutProblem::Erroneous)), EmptyRecord => cacheable(Ok(Layout::UNIT)), } } diff --git a/crates/compiler/mono/src/layout_soa.rs b/crates/compiler/mono/src/layout_soa.rs index e787ba5e44..b5504e5f36 100644 --- a/crates/compiler/mono/src/layout_soa.rs +++ b/crates/compiler/mono/src/layout_soa.rs @@ -189,8 +189,6 @@ impl FunctionLayout { }) } - FlatType::Erroneous(_) => Err(TypeError(())), - _ => todo!(), } } @@ -867,7 +865,6 @@ impl Layout { Ok(Layout::UnionRecursive(slices)) } - FlatType::Erroneous(_) => Err(TypeError(())), FlatType::EmptyRecord => Ok(Layout::UNIT), FlatType::EmptyTagUnion => Ok(Layout::VOID), } diff --git a/crates/compiler/solve/src/ability.rs b/crates/compiler/solve/src/ability.rs index fc85ba7b94..f335bf78bb 100644 --- a/crates/compiler/solve/src/ability.rs +++ b/crates/compiler/solve/src/ability.rs @@ -715,13 +715,6 @@ trait DerivableVisitor { } EmptyRecord => Self::visit_empty_record(var)?, EmptyTagUnion => Self::visit_empty_tag_union(var)?, - - Erroneous(_) => { - return Err(NotDerivable { - var, - context: NotDerivableContext::NoContext, - }) - } }, Alias( Symbol::NUM_NUM | Symbol::NUM_INTEGER | Symbol::NUM_FLOATINGPOINT, diff --git a/crates/compiler/solve/src/solve.rs b/crates/compiler/solve/src/solve.rs index 15a2543d20..dc12637ce4 100644 --- a/crates/compiler/solve/src/solve.rs +++ b/crates/compiler/solve/src/solve.rs @@ -1490,13 +1490,7 @@ fn solve( let branches_content = subs.get_content_without_compacting(branches_var); let already_have_error = matches!( (real_content, branches_content), - ( - Content::Error | Content::Structure(FlatType::Erroneous(_)), - _ - ) | ( - _, - Content::Error | Content::Structure(FlatType::Erroneous(_)) - ) + (Content::Error, _) | (_, Content::Error) ); let snapshot = subs.snapshot(); @@ -3826,8 +3820,6 @@ fn adjust_rank_content( rank } - - Erroneous(_) => group_rank, } } @@ -4076,7 +4068,7 @@ fn deep_copy_var_help( Func(new_arguments, new_closure_var, new_ret_var) } - same @ EmptyRecord | same @ EmptyTagUnion | same @ Erroneous(_) => same, + same @ EmptyRecord | same @ EmptyTagUnion => same, Record(fields, ext_var) => { let record_fields = { diff --git a/crates/compiler/types/src/pretty_print.rs b/crates/compiler/types/src/pretty_print.rs index bfe2126d98..b061130308 100644 --- a/crates/compiler/types/src/pretty_print.rs +++ b/crates/compiler/types/src/pretty_print.rs @@ -408,7 +408,7 @@ fn find_names_needed( find_under_alias, ); } - Error | Structure(Erroneous(_)) | Structure(EmptyRecord) | Structure(EmptyTagUnion) => { + Error | Structure(EmptyRecord) | Structure(EmptyTagUnion) => { // Errors and empty records don't need names. } } @@ -1284,7 +1284,6 @@ fn write_flat_type<'a>( ) }) } - Erroneous(problem) => write!(buf, "", problem).unwrap(), } } diff --git a/crates/compiler/types/src/subs.rs b/crates/compiler/types/src/subs.rs index 9b5f8a25d3..827530fa75 100644 --- a/crates/compiler/types/src/subs.rs +++ b/crates/compiler/types/src/subs.rs @@ -975,7 +975,6 @@ fn subs_fmt_flat_type(this: &FlatType, subs: &Subs, f: &mut fmt::Formatter) -> f write!(f, "]<{:?}> as <{:?}>", new_ext, rec) } - FlatType::Erroneous(e) => write!(f, "Erroneous({:?})", e), FlatType::EmptyRecord => write!(f, "EmptyRecord"), FlatType::EmptyTagUnion => write!(f, "EmptyTagUnion"), } @@ -2517,7 +2516,6 @@ pub enum FlatType { FunctionOrTagUnion(SubsSlice, SubsSlice, Variable), RecursiveTagUnion(Variable, UnionTags, Variable), - Erroneous(SubsIndex), EmptyRecord, EmptyTagUnion, } @@ -3274,7 +3272,7 @@ fn occurs( short_circuit_help(subs, root_var, &new_seen, *ext_var) } - EmptyRecord | EmptyTagUnion | Erroneous(_) => Ok(()), + EmptyRecord | EmptyTagUnion => Ok(()), } } Alias(_, args, _, _) => { @@ -3445,7 +3443,7 @@ fn explicit_substitute( subs.set_content(in_var, Structure(Record(vars_by_field, new_ext_var))); } - EmptyRecord | EmptyTagUnion | Erroneous(_) => {} + EmptyRecord | EmptyTagUnion => {} } in_var @@ -3628,9 +3626,7 @@ fn get_var_names( accum } - FlatType::EmptyRecord | FlatType::EmptyTagUnion | FlatType::Erroneous(_) => { - taken_names - } + FlatType::EmptyRecord | FlatType::EmptyTagUnion => taken_names, FlatType::Record(vars_by_field, ext_var) => { let mut accum = get_var_names(subs, ext_var, taken_names); @@ -4039,8 +4035,6 @@ fn flat_type_to_err_type( panic!("Tried to convert a recursive tag union extension to an error, but the tag union extension had the ErrorType of {:?}", other) } } - - Erroneous(_) => ErrorType::Error, } } @@ -4320,9 +4314,6 @@ impl StorageSubs { Self::offset_tag_union(offsets, *union_tags), Self::offset_variable(offsets, *ext), ), - FlatType::Erroneous(problem) => { - FlatType::Erroneous(Self::offset_problem(offsets, *problem)) - } FlatType::EmptyRecord => FlatType::EmptyRecord, FlatType::EmptyTagUnion => FlatType::EmptyTagUnion, } @@ -4606,7 +4597,7 @@ fn storage_copy_var_to_help(env: &mut StorageCopyVarToEnv<'_>, var: Variable) -> Func(new_arguments, new_closure_var, new_ret_var) } - same @ EmptyRecord | same @ EmptyTagUnion | same @ Erroneous(_) => same, + same @ EmptyRecord | same @ EmptyTagUnion => same, Record(fields, ext_var) => { let record_fields = { @@ -5024,13 +5015,6 @@ fn copy_import_to_help(env: &mut CopyImportEnv<'_>, max_rank: Rank, var: Variabl // We have already marked the variable as copied, so we // will not repeat this work or crawl this variable again. match desc.content { - Structure(Erroneous(_)) => { - // Make this into a flex var so that we don't have to copy problems across module - // boundaries - the error will be reported locally. - env.target.set(copy, make_descriptor(FlexVar(None))); - - copy - } Structure(flat_type) => { let new_flat_type = match flat_type { Apply(symbol, arguments) => { @@ -5061,8 +5045,6 @@ fn copy_import_to_help(env: &mut CopyImportEnv<'_>, max_rank: Rank, var: Variabl Func(new_arguments, new_closure_var, new_ret_var) } - Erroneous(_) => internal_error!("I thought this was handled above"), - same @ EmptyRecord | same @ EmptyTagUnion => same, Record(fields, ext_var) => { @@ -5435,8 +5417,6 @@ fn instantiate_rigids_help(subs: &mut Subs, max_rank: Rank, initial: Variable) { stack.push(ext_var); stack.push(rec_var); } - - Erroneous(_) => (), }, Alias(_, args, var, _) => { let var = *var; @@ -5539,7 +5519,7 @@ pub fn get_member_lambda_sets_at_region(subs: &Subs, var: Variable, target_regio ); stack.push(*ext); } - FlatType::Erroneous(_) | FlatType::EmptyRecord | FlatType::EmptyTagUnion => {} + FlatType::EmptyRecord | FlatType::EmptyTagUnion => {} }, Content::Alias(_, _, real_var, _) => { stack.push(*real_var); @@ -5606,7 +5586,6 @@ fn is_inhabited(subs: &Subs, var: Variable) -> bool { } } FlatType::FunctionOrTagUnion(_, _, _) => {} - FlatType::Erroneous(_) => {} FlatType::EmptyRecord => {} FlatType::EmptyTagUnion => { return false; diff --git a/crates/glue/src/types.rs b/crates/glue/src/types.rs index 317461d148..5084607a8d 100644 --- a/crates/glue/src/types.rs +++ b/crates/glue/src/types.rs @@ -866,7 +866,6 @@ fn add_type_help<'a>( Content::Structure(FlatType::FunctionOrTagUnion(_, _, _)) => { todo!() } - Content::Structure(FlatType::Erroneous(_)) => todo!(), Content::Structure(FlatType::EmptyRecord) => { types.add_anonymous(&env.layout_cache.interner, RocType::Unit, layout) }