remove PartialEq for a bunch of types that we should not compare

This commit is contained in:
Folkert 2022-04-20 16:30:20 +02:00
parent b59d33a1d5
commit 8b144c446d
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
15 changed files with 94 additions and 205 deletions

View file

@ -75,7 +75,7 @@ use crate::mem_pool::shallow_clone::ShallowClone;
// Ranks are used to limit the number of type variables considered for generalization. Only those inside
// of the let (so those used in inferring the type of `\x -> x`) are considered.
#[derive(PartialEq, Debug, Clone)]
#[derive(Debug, Clone)]
pub enum TypeError {
BadExpr(Region, Category, ErrorType, Expected<ErrorType>),
BadPattern(Region, PatternCategory, ErrorType, PExpected<ErrorType>),

View file

@ -1,6 +1,6 @@
use crate::env::Env;
use crate::scope::Scope;
use roc_collections::{ImMap, MutMap, MutSet, SendMap, VecSet};
use roc_collections::{ImMap, MutMap, MutSet, SendMap, VecMap, VecSet};
use roc_module::ident::{Ident, Lowercase, TagName};
use roc_module::symbol::{IdentIds, ModuleId, Symbol};
use roc_parse::ast::{AssignedField, ExtractSpaces, Pattern, Tag, TypeAnnotation, TypeHeader};
@ -11,7 +11,7 @@ use roc_types::types::{
Alias, AliasCommon, AliasKind, LambdaSet, Problem, RecordField, Type, TypeExtension,
};
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug)]
pub struct Annotation {
pub typ: Type,
pub introduced_variables: IntroducedVariables,
@ -53,14 +53,14 @@ pub struct AbleVariable {
pub first_seen: Region,
}
#[derive(Clone, Debug, PartialEq, Default)]
#[derive(Clone, Debug, Default)]
pub struct IntroducedVariables {
pub wildcards: Vec<Loc<Variable>>,
pub lambda_sets: Vec<Variable>,
pub inferred: Vec<Loc<Variable>>,
pub named: VecSet<NamedVariable>,
pub able: VecSet<AbleVariable>,
pub host_exposed_aliases: MutMap<Symbol, Variable>,
pub host_exposed_aliases: VecMap<Symbol, Variable>,
}
impl IntroducedVariables {

View file

@ -601,7 +601,7 @@ impl Constraints {
roc_error_macros::assert_sizeof_default!(Constraint, 3 * 8);
#[derive(Clone, PartialEq)]
#[derive(Clone)]
pub enum Constraint {
Eq(
EitherIndex<Type, Variable>,
@ -643,13 +643,13 @@ pub enum Constraint {
),
}
#[derive(Debug, Clone, Copy, PartialEq, Default)]
#[derive(Debug, Clone, Copy, Default)]
pub struct DefTypes {
pub types: Slice<Type>,
pub loc_symbols: Slice<(Symbol, Region)>,
}
#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone)]
pub struct LetConstraint {
pub rigid_vars: Slice<Variable>,
pub flex_vars: Slice<Variable>,
@ -657,7 +657,7 @@ pub struct LetConstraint {
pub defs_and_ret_constraint: Index<(Constraint, Constraint)>,
}
#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone)]
pub struct IncludesTag {
pub type_index: Index<Type>,
pub tag_name: TagName,

View file

@ -29,7 +29,7 @@ use std::collections::HashMap;
use std::fmt::Debug;
use ven_graph::{strongly_connected_components, topological_sort};
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug)]
pub struct Def {
pub loc_pattern: Loc<Pattern>,
pub loc_expr: Loc<Expr>,
@ -38,7 +38,7 @@ pub struct Def {
pub annotation: Option<Annotation>,
}
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug)]
pub struct Annotation {
pub signature: Type,
pub introduced_variables: IntroducedVariables,
@ -56,7 +56,7 @@ pub struct CanDefs {
/// A Def that has had patterns and type annnotations canonicalized,
/// but no Expr canonicalization has happened yet. Also, it has had spaces
/// and nesting resolved, and knows whether annotations are standalone or not.
#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone)]
enum PendingValueDef<'a> {
/// A standalone annotation with no body
AnnotationOnly(
@ -79,7 +79,7 @@ enum PendingValueDef<'a> {
),
}
#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone)]
enum PendingTypeDef<'a> {
/// A structural or opaque type alias, e.g. `Ints : List Int` or `Age := U32` respectively.
Alias {
@ -105,7 +105,7 @@ enum PendingTypeDef<'a> {
}
// See github.com/rtfeldman/roc/issues/800 for discussion of the large_enum_variant check.
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug)]
#[allow(clippy::large_enum_variant)]
pub enum Declaration {
Declare(Def),

View file

@ -2,7 +2,7 @@ use crate::pattern::Pattern;
use roc_region::all::{Loc, Region};
use roc_types::types::{AnnotationSource, PReason, Reason};
#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone)]
pub enum Expected<T> {
NoExpectation(T),
FromAnnotation(Loc<Pattern>, usize, AnnotationSource, T),
@ -10,7 +10,7 @@ pub enum Expected<T> {
}
/// Like Expected, but for Patterns.
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone)]
pub enum PExpected<T> {
NoExpectation(T),
ForReason(PReason, T, Region),

View file

@ -9,7 +9,7 @@ use crate::num::{
use crate::pattern::{canonicalize_pattern, Pattern};
use crate::procedure::References;
use crate::scope::Scope;
use roc_collections::{MutMap, MutSet, SendMap, VecSet};
use roc_collections::{MutMap, MutSet, SendMap, VecMap, VecSet};
use roc_module::called_via::CalledVia;
use roc_module::ident::{ForeignSymbol, Lowercase, TagName};
use roc_module::low_level::LowLevel;
@ -23,12 +23,12 @@ use roc_types::types::{Alias, LambdaSet, Type};
use std::fmt::{Debug, Display};
use std::{char, u32};
#[derive(Clone, Default, Debug, PartialEq)]
#[derive(Clone, Default, Debug)]
pub struct Output {
pub references: References,
pub tail_call: Option<Symbol>,
pub introduced_variables: IntroducedVariables,
pub aliases: SendMap<Symbol, Alias>,
pub aliases: VecMap<Symbol, Alias>,
pub non_closures: VecSet<Symbol>,
}
@ -62,7 +62,7 @@ impl Display for IntValue {
}
}
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug)]
pub enum Expr {
// Literals
@ -194,7 +194,7 @@ pub enum Expr {
// Compiles, but will crash if reached
RuntimeError(RuntimeError),
}
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug)]
pub struct ClosureData {
pub function_type: Variable,
pub closure_type: Variable,
@ -271,7 +271,7 @@ impl AccessorData {
}
}
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug)]
pub struct Field {
pub var: Variable,
// The region of the full `foo: f bar`, rather than just `f bar`
@ -286,7 +286,7 @@ pub enum Recursive {
TailRecursive = 2,
}
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug)]
pub struct WhenBranch {
pub patterns: Vec<Loc<Pattern>>,
pub value: Loc<Expr>,

View file

@ -17,7 +17,7 @@ use roc_types::types::{LambdaSet, Type};
/// A pattern, including possible problems (e.g. shadowing) so that
/// codegen can generate a runtime error if this pattern is reached.
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug)]
pub enum Pattern {
Identifier(Symbol),
AppliedTag {
@ -82,7 +82,7 @@ pub enum Pattern {
MalformedPattern(MalformedPatternProblem, Region),
}
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug)]
pub struct RecordDestruct {
pub var: Variable,
pub label: Lowercase,
@ -90,7 +90,7 @@ pub struct RecordDestruct {
pub typ: DestructType,
}
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug)]
pub enum DestructType {
Required,
Optional(Variable, Loc<Expr>),

View file

@ -5,7 +5,7 @@ use roc_module::symbol::Symbol;
use roc_region::all::{Loc, Region};
use roc_types::subs::Variable;
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug)]
pub struct Procedure {
pub name: Option<Box<str>>,
pub is_self_tail_recursive: bool,

View file

@ -1,110 +0,0 @@
#[macro_use]
extern crate pretty_assertions;
#[macro_use]
extern crate indoc;
extern crate bumpalo;
extern crate roc_can;
extern crate roc_parse;
extern crate roc_region;
mod helpers;
#[cfg(test)]
mod can_inline {
use crate::helpers::{can_expr_with, test_home};
use bumpalo::Bump;
use roc_can::expr::inline_calls;
use roc_can::expr::Expr::{self, *};
use roc_can::scope::Scope;
use roc_types::subs::VarStore;
fn assert_inlines_to(input: &str, expected: Expr, var_store: &mut VarStore) {
let arena = Bump::new();
let scope = &mut Scope::new(test_home(), var_store);
let actual_out = can_expr_with(&arena, test_home(), input);
let actual = inline_calls(var_store, scope, actual_out.loc_expr.value);
assert_eq!(actual, expected);
}
#[test]
fn inline_empty_record() {
// fn inline_list_len() {
let var_store = &mut VarStore::default();
assert_inlines_to(
indoc!(
r#"
{}
"#
),
EmptyRecord,
var_store,
);
// TODO testing with hardcoded variables is very brittle.
// Should find a better way to test this!
// (One idea would be to traverse both Exprs and zero out all the Variables,
// so they always pass equality.)
// let aliases = SendMap::default();
// assert_inlines_to(
// indoc!(
// r#"
// Int.isZero 5
// "#
// ),
// LetNonRec(
// Box::new(Def {
// loc_pattern: Located {
// region: Region::zero(),
// value: Pattern::Identifier(Symbol::ARG_1),
// },
// pattern_vars: SendMap::default(),
// loc_expr: Located {
// region: Region::new(0, 0, 11, 12),
// value: Num(unsafe { Variable::unsafe_test_debug_variable(7) }, 5),
// },
// expr_var: unsafe { Variable::unsafe_test_debug_variable(8) },
// annotation: None,
// }),
// Box::new(Located {
// region: Region::zero(),
// value: Expr::Call(
// Box::new((
// unsafe { Variable::unsafe_test_debug_variable(138) },
// Located {
// region: Region::zero(),
// value: Expr::Var(Symbol::BOOL_EQ),
// },
// unsafe { Variable::unsafe_test_debug_variable(139) },
// )),
// vec![
// (
// unsafe { Variable::unsafe_test_debug_variable(140) },
// Located {
// region: Region::zero(),
// value: Var(Symbol::ARG_1),
// },
// ),
// (
// unsafe { Variable::unsafe_test_debug_variable(141) },
// Located {
// region: Region::zero(),
// value: Int(
// unsafe { Variable::unsafe_test_debug_variable(137) },
// 0,
// ),
// },
// ),
// ],
// CalledVia::Space,
// ),
// }),
// unsafe { Variable::unsafe_test_debug_variable(198) },
// aliases,
// ),
// var_store,
// )
}
}

View file

@ -20,11 +20,32 @@ mod test_can {
use roc_region::all::{Position, Region};
use std::{f64, i64};
fn assert_can(input: &str, expected: Expr) {
fn assert_can_runtime_error(input: &str, expected: RuntimeError) {
let arena = Bump::new();
let actual_out = can_expr_with(&arena, test_home(), input);
assert_eq!(actual_out.loc_expr.value, expected);
match actual_out.loc_expr.value {
Expr::RuntimeError(actual) => {
assert_eq!(expected, actual);
}
actual => {
panic!("Expected a Float, but got: {:?}", actual);
}
}
}
fn assert_can_string(input: &str, expected: &str) {
let arena = Bump::new();
let actual_out = can_expr_with(&arena, test_home(), input);
match actual_out.loc_expr.value {
Expr::Str(actual) => {
assert_eq!(expected, &*actual);
}
actual => {
panic!("Expected a Float, but got: {:?}", actual);
}
}
}
fn assert_can_float(input: &str, expected: f64) {
@ -69,10 +90,6 @@ mod test_can {
}
}
fn expr_str(contents: &str) -> Expr {
Expr::Str(contents.into())
}
// NUMBER LITERALS
#[test]
@ -81,14 +98,14 @@ mod test_can {
let string = "340_282_366_920_938_463_463_374_607_431_768_211_456".to_string();
assert_can(
assert_can_runtime_error(
&string.clone(),
RuntimeError(RuntimeError::InvalidInt(
RuntimeError::InvalidInt(
IntErrorKind::Overflow,
Base::Decimal,
Region::zero(),
string.into_boxed_str(),
)),
),
);
}
@ -98,14 +115,14 @@ mod test_can {
let string = "-170_141_183_460_469_231_731_687_303_715_884_105_729".to_string();
assert_can(
assert_can_runtime_error(
&string.clone(),
RuntimeError(RuntimeError::InvalidInt(
RuntimeError::InvalidInt(
IntErrorKind::Underflow,
Base::Decimal,
Region::zero(),
string.into(),
)),
),
);
}
@ -114,13 +131,9 @@ mod test_can {
let string = format!("{}1.0", f64::MAX);
let region = Region::zero();
assert_can(
assert_can_runtime_error(
&string.clone(),
RuntimeError(RuntimeError::InvalidFloat(
FloatErrorKind::PositiveInfinity,
region,
string.into(),
)),
RuntimeError::InvalidFloat(FloatErrorKind::PositiveInfinity, region, string.into()),
);
}
@ -129,13 +142,9 @@ mod test_can {
let string = format!("{}1.0", f64::MIN);
let region = Region::zero();
assert_can(
assert_can_runtime_error(
&string.clone(),
RuntimeError(RuntimeError::InvalidFloat(
FloatErrorKind::NegativeInfinity,
region,
string.into(),
)),
RuntimeError::InvalidFloat(FloatErrorKind::NegativeInfinity, region, string.into()),
);
}
@ -144,13 +153,9 @@ mod test_can {
let string = "1.1.1";
let region = Region::zero();
assert_can(
assert_can_runtime_error(
string.clone(),
RuntimeError(RuntimeError::InvalidFloat(
FloatErrorKind::Error,
region,
string.into(),
)),
RuntimeError::InvalidFloat(FloatErrorKind::Error, region, string.into()),
);
}
@ -1582,27 +1587,27 @@ mod test_can {
#[test]
fn string_with_valid_unicode_escapes() {
assert_can(r#""x\u(00A0)x""#, expr_str("x\u{00A0}x"));
assert_can(r#""x\u(101010)x""#, expr_str("x\u{101010}x"));
assert_can_string(r#""x\u(00A0)x""#, "x\u{00A0}x");
assert_can_string(r#""x\u(101010)x""#, "x\u{101010}x");
}
#[test]
fn block_string() {
assert_can(
assert_can_string(
r#"
"""foobar"""
"#,
expr_str("foobar"),
"foobar",
);
assert_can(
assert_can_string(
indoc!(
r#"
"""foo
bar"""
"#
),
expr_str("foo\nbar"),
"foo\nbar",
);
}

View file

@ -4,7 +4,9 @@
pub mod all;
pub mod soa;
mod vec_map;
mod vec_set;
pub use all::{default_hasher, BumpMap, ImEntry, ImMap, ImSet, MutMap, MutSet, SendMap};
pub use vec_map::VecMap;
pub use vec_set::VecSet;

View file

@ -112,13 +112,11 @@ mod test_load {
));
}
assert_eq!(
loaded_module
assert!(loaded_module
.type_problems
.remove(&home)
.unwrap_or_default(),
Vec::new()
);
.unwrap_or_default()
.is_empty(),);
Ok(loaded_module)
}
@ -208,13 +206,11 @@ mod test_load {
loaded_module.can_problems.remove(&home).unwrap_or_default(),
Vec::new()
);
assert_eq!(
loaded_module
assert!(loaded_module
.type_problems
.remove(&home)
.unwrap_or_default(),
Vec::new()
);
.unwrap_or_default()
.is_empty());
let expected_name = loaded_module
.interns
@ -261,13 +257,11 @@ mod test_load {
loaded_module.can_problems.remove(&home).unwrap_or_default(),
Vec::new()
);
assert_eq!(
loaded_module
assert!(loaded_module
.type_problems
.remove(&home)
.unwrap_or_default(),
Vec::new()
);
.unwrap_or_default()
.is_empty());
for decl in loaded_module.declarations_by_id.remove(&home).unwrap() {
match decl {
@ -365,13 +359,11 @@ mod test_load {
loaded_module.can_problems.remove(&home).unwrap_or_default(),
Vec::new()
);
assert_eq!(
loaded_module
assert!(loaded_module
.type_problems
.remove(&home)
.unwrap_or_default(),
Vec::new()
);
.unwrap_or_default()
.is_empty(),);
let def_count: usize = loaded_module
.declarations_by_id

View file

@ -108,7 +108,7 @@ pub struct EntryPoint<'a> {
#[derive(Clone, Copy, Debug)]
pub struct PartialProcId(usize);
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug)]
pub struct PartialProcs<'a> {
/// maps a function name (symbol) to an index
symbols: Vec<'a, Symbol>,
@ -190,7 +190,7 @@ impl<'a> PartialProcs<'a> {
}
}
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug)]
pub struct PartialProc<'a> {
pub annotation: Variable,
pub pattern_symbols: &'a [Symbol],

View file

@ -79,7 +79,7 @@ pub struct IncompleteAbilityImplementation {
pub missing_members: Vec<Loc<Symbol>>,
}
#[derive(PartialEq, Debug, Clone)]
#[derive(Debug, Clone)]
pub enum TypeError {
BadExpr(Region, Category, ErrorType, Expected<ErrorType>),
BadPattern(Region, PatternCategory, ErrorType, PExpected<ErrorType>),

View file

@ -129,7 +129,7 @@ fn compiles_to_ir(test_name: &str, src: &str) {
println!("Ignoring {} canonicalization problems", can_problems.len());
}
assert_eq!(type_problems, Vec::new());
assert!(type_problems.is_empty());
assert_eq!(mono_problems, Vec::new());
debug_assert_eq!(exposed_to_host.values.len(), 1);