This commit is contained in:
Anton-4 2024-04-15 16:50:44 +02:00
parent 4d9202ec6e
commit e4b814ce1c
No known key found for this signature in database
GPG key ID: 0971D718C0A9B937
8 changed files with 51 additions and 48 deletions

View file

@ -955,7 +955,7 @@ pub(crate) fn canonicalize_defs<'a>(
// there are opaques that implement an ability using a value symbol). But, value symbols might // there are opaques that implement an ability using a value symbol). But, value symbols might
// shadow symbols defined in a local ability def. // shadow symbols defined in a local ability def.
for (_, either_index) in loc_defs.tags.iter().enumerate() { for either_index in loc_defs.tags.iter() {
if let Ok(type_index) = either_index.split() { if let Ok(type_index) = either_index.split() {
let type_def = &loc_defs.type_defs[type_index.index()]; let type_def = &loc_defs.type_defs[type_index.index()];
let pending_type_def = to_pending_type_def(env, type_def, scope, pattern_type); let pending_type_def = to_pending_type_def(env, type_def, scope, pattern_type);

View file

@ -452,7 +452,7 @@ enum Match {
} }
fn check_for_match(branches: &[Branch]) -> Match { fn check_for_match(branches: &[Branch]) -> Match {
match branches.get(0) { match branches.first() {
Some(Branch { Some(Branch {
goal, goal,
patterns, patterns,

View file

@ -593,6 +593,9 @@ struct LockedGlobalInterner<'a, 'r> {
fn hash<V: std::hash::Hash>(val: V) -> u64 { fn hash<V: std::hash::Hash>(val: V) -> u64 {
let mut state = roc_collections::all::BuildHasher::default().build_hasher(); let mut state = roc_collections::all::BuildHasher::default().build_hasher();
val.hash(&mut state); val.hash(&mut state);
// clippy suggests a stylistic improvement but the suggested fix doesn't seem to work out
#[allow(clippy::manual_hash_one)]
state.finish() state.finish()
} }

View file

@ -322,43 +322,6 @@ pub fn fast_eat_until_control_character(bytes: &[u8]) -> usize {
simple_eat_until_control_character(&bytes[i..]) + i simple_eat_until_control_character(&bytes[i..]) + i
} }
#[cfg(test)]
mod tests {
use super::*;
use proptest::prelude::*;
#[test]
fn test_eat_whitespace_simple() {
let bytes = &[0, 0, 0, 0, 0, 0, 0, 0];
assert_eq!(simple_eat_whitespace(bytes), fast_eat_whitespace(bytes));
}
proptest! {
#[test]
fn test_eat_whitespace(bytes in proptest::collection::vec(any::<u8>(), 0..100)) {
prop_assert_eq!(simple_eat_whitespace(&bytes), fast_eat_whitespace(&bytes));
}
}
#[test]
fn test_eat_until_control_character_simple() {
let bytes = &[32, 0, 0, 0, 0, 0, 0, 0];
assert_eq!(
simple_eat_until_control_character(bytes),
fast_eat_until_control_character(bytes)
);
}
proptest! {
#[test]
fn test_eat_until_control_character(bytes in proptest::collection::vec(any::<u8>(), 0..100)) {
prop_assert_eq!(
simple_eat_until_control_character(&bytes),
fast_eat_until_control_character(&bytes));
}
}
}
pub fn space0_e<'a, E>( pub fn space0_e<'a, E>(
indent_problem: fn(Position) -> E, indent_problem: fn(Position) -> E,
) -> impl Parser<'a, &'a [CommentOrNewline<'a>], E> ) -> impl Parser<'a, &'a [CommentOrNewline<'a>], E>
@ -514,3 +477,40 @@ where
Ok((progress, state)) Ok((progress, state))
} }
#[cfg(test)]
mod tests {
use super::*;
use proptest::prelude::*;
#[test]
fn test_eat_whitespace_simple() {
let bytes = &[0, 0, 0, 0, 0, 0, 0, 0];
assert_eq!(simple_eat_whitespace(bytes), fast_eat_whitespace(bytes));
}
proptest! {
#[test]
fn test_eat_whitespace(bytes in proptest::collection::vec(any::<u8>(), 0..100)) {
prop_assert_eq!(simple_eat_whitespace(&bytes), fast_eat_whitespace(&bytes));
}
}
#[test]
fn test_eat_until_control_character_simple() {
let bytes = &[32, 0, 0, 0, 0, 0, 0, 0];
assert_eq!(
simple_eat_until_control_character(bytes),
fast_eat_until_control_character(bytes)
);
}
proptest! {
#[test]
fn test_eat_until_control_character(bytes in proptest::collection::vec(any::<u8>(), 0..100)) {
prop_assert_eq!(
simple_eat_until_control_character(&bytes),
fast_eat_until_control_character(&bytes));
}
}
}

View file

@ -958,7 +958,7 @@ fn sort_and_deduplicate<T>(tag_vars: &mut bumpalo::collections::Vec<(TagName, T)
fn find_tag_name_run(slice: &[TagName], subs: &mut Subs) -> Option<SubsSlice<TagName>> { fn find_tag_name_run(slice: &[TagName], subs: &mut Subs) -> Option<SubsSlice<TagName>> {
use std::cmp::Ordering; use std::cmp::Ordering;
let tag_name = slice.get(0)?; let tag_name = slice.first()?;
let mut result = None; let mut result = None;

View file

@ -2284,7 +2284,7 @@ fn tag_to_type<'a, D: Display>(
// this isn't recursive and there's 1 payload item, so it doesn't // this isn't recursive and there's 1 payload item, so it doesn't
// need its own struct - e.g. for `[Foo Str, Bar Str]` both of them // need its own struct - e.g. for `[Foo Str, Bar Str]` both of them
// can have payloads of plain old Str, no struct wrapper needed. // can have payloads of plain old Str, no struct wrapper needed.
let payload_var = payload_vars.get(0).unwrap(); let payload_var = payload_vars.first().unwrap();
let payload_layout = env let payload_layout = env
.layout_cache .layout_cache
.from_var(env.arena, *payload_var, env.subs) .from_var(env.arena, *payload_var, env.subs)

View file

@ -2999,14 +2999,14 @@ fn to_diff<'b>(
ErrorType::Type(Symbol::NUM_NUM, args) => { ErrorType::Type(Symbol::NUM_NUM, args) => {
matches!( matches!(
&args.get(0), &args.first(),
Some(ErrorType::Type(Symbol::NUM_INTEGER, _)) Some(ErrorType::Type(Symbol::NUM_INTEGER, _))
| Some(ErrorType::Alias(Symbol::NUM_INTEGER, _, _, _)) | Some(ErrorType::Alias(Symbol::NUM_INTEGER, _, _, _))
) )
} }
ErrorType::Alias(Symbol::NUM_NUM, args, _, _) => { ErrorType::Alias(Symbol::NUM_NUM, args, _, _) => {
matches!( matches!(
&args.get(0), &args.first(),
Some(ErrorType::Type(Symbol::NUM_INTEGER, _)) Some(ErrorType::Type(Symbol::NUM_INTEGER, _))
| Some(ErrorType::Alias(Symbol::NUM_INTEGER, _, _, _)) | Some(ErrorType::Alias(Symbol::NUM_INTEGER, _, _, _))
) )
@ -3019,7 +3019,7 @@ fn to_diff<'b>(
ErrorType::Type(Symbol::NUM_NUM, args) => { ErrorType::Type(Symbol::NUM_NUM, args) => {
matches!( matches!(
&args.get(0), &args.first(),
Some(ErrorType::Type(Symbol::NUM_FLOATINGPOINT, _)) Some(ErrorType::Type(Symbol::NUM_FLOATINGPOINT, _))
| Some(ErrorType::Alias(Symbol::NUM_FLOATINGPOINT, _, _, _)) | Some(ErrorType::Alias(Symbol::NUM_FLOATINGPOINT, _, _, _))
) )
@ -3027,7 +3027,7 @@ fn to_diff<'b>(
ErrorType::Alias(Symbol::NUM_NUM, args, _, _) => { ErrorType::Alias(Symbol::NUM_NUM, args, _, _) => {
matches!( matches!(
&args.get(0), &args.first(),
Some(ErrorType::Type(Symbol::NUM_FLOATINGPOINT, _)) Some(ErrorType::Type(Symbol::NUM_FLOATINGPOINT, _))
| Some(ErrorType::Alias(Symbol::NUM_FLOATINGPOINT, _, _, _)) | Some(ErrorType::Alias(Symbol::NUM_FLOATINGPOINT, _, _, _))
) )
@ -4360,7 +4360,7 @@ fn type_problem_to_pretty<'b>(
(FieldTypo(typo, possibilities), _) => { (FieldTypo(typo, possibilities), _) => {
let suggestions = suggest::sort(typo.as_str(), possibilities); let suggestions = suggest::sort(typo.as_str(), possibilities);
match suggestions.get(0) { match suggestions.first() {
None => alloc.nil(), None => alloc.nil(),
Some(nearest) => { Some(nearest) => {
let typo_str = format!("{typo}"); let typo_str = format!("{typo}");
@ -4412,7 +4412,7 @@ fn type_problem_to_pretty<'b>(
let typo_str = format!("{}", typo.as_ident_str()); let typo_str = format!("{}", typo.as_ident_str());
let suggestions = suggest::sort(&typo_str, possibilities); let suggestions = suggest::sort(&typo_str, possibilities);
match suggestions.get(0) { match suggestions.first() {
None => alloc.nil(), None => alloc.nil(),
Some(nearest) => { Some(nearest) => {
let nearest_str = format!("{nearest}"); let nearest_str = format!("{nearest}");

View file

@ -109,7 +109,7 @@ impl<K: Debug, V: Debug> Debug for RocDict<K, V> {
f.write_str("RocDict ")?; f.write_str("RocDict ")?;
f.debug_map() f.debug_map()
.entries(self.iter().map(|(k, v)| (k, v))) .entries(self.iter())
.finish() .finish()
} }
} }