From 56481dc724fcf3533720b43bf88d6104ed8fb32a Mon Sep 17 00:00:00 2001 From: faldor20 Date: Sun, 17 Mar 2024 18:16:39 +1000 Subject: [PATCH] clippy and comments comments and clippy --- crates/compiler/derive/src/decoding/record.rs | 10 +++--- .../derive/src/decoding/record/decodeWith.rs | 20 ++++-------- .../derive/src/decoding/record/finalizer.rs | 31 ++++++++++++------- .../derive/src/decoding/record/stepField.rs | 10 +++--- crates/compiler/derive/src/util.rs | 6 ++-- 5 files changed, 39 insertions(+), 38 deletions(-) diff --git a/crates/compiler/derive/src/decoding/record.rs b/crates/compiler/derive/src/decoding/record.rs index c06d23d7c6..6ae2142a38 100644 --- a/crates/compiler/derive/src/decoding/record.rs +++ b/crates/compiler/derive/src/decoding/record.rs @@ -1,20 +1,20 @@ use roc_can::expr::{ - AnnotatedMark, ClosureData, Expr, Field, Recursive, WhenBranch, WhenBranchPattern, + Expr, Field, }; -use roc_can::pattern::Pattern; + use roc_collections::SendMap; use roc_module::called_via::CalledVia; use roc_module::ident::Lowercase; use roc_module::symbol::Symbol; use roc_region::all::{Loc, Region}; use roc_types::subs::{ - Content, ExhaustiveMark, FlatType, LambdaSet, OptVariable, RecordFields, RedundantMark, - SubsSlice, TagExt, UnionLambdas, UnionTags, Variable, + Content, FlatType, RecordFields, + SubsSlice, TagExt, UnionTags, Variable, }; use roc_types::types::RecordField; use crate::synth_var; -use crate::util::{empty_list, ok_to_ok_branch, Env, ExtensionKind}; +use crate::util::{Env, ExtensionKind}; use self::finalizer::finalizer; use self::stepField::step_field; diff --git a/crates/compiler/derive/src/decoding/record/decodeWith.rs b/crates/compiler/derive/src/decoding/record/decodeWith.rs index 408790c9b4..41fa96bded 100644 --- a/crates/compiler/derive/src/decoding/record/decodeWith.rs +++ b/crates/compiler/derive/src/decoding/record/decodeWith.rs @@ -1,22 +1,14 @@ -use roc_can::expr::{ - AnnotatedMark, ClosureData, Expr, Field, Recursive, WhenBranch, WhenBranchPattern, -}; -use roc_can::pattern::Pattern; -use roc_collections::SendMap; +use roc_can::expr::Expr; + use roc_module::called_via::CalledVia; -use roc_module::ident::Lowercase; + use roc_module::symbol::Symbol; -use roc_region::all::{Loc, Region}; -use roc_types::subs::{ - Content, ExhaustiveMark, FlatType, LambdaSet, OptVariable, RecordFields, RedundantMark, - SubsSlice, TagExt, UnionLambdas, UnionTags, Variable, -}; +use roc_region::all::Loc; +use roc_types::subs::{Content, FlatType, RecordFields, SubsSlice, TagExt, UnionTags, Variable}; use roc_types::types::RecordField; use crate::synth_var; -use crate::util::{empty_list, ok_to_ok_branch, Env, ExtensionKind}; - -use super::wrap_in_decode_custom_decode_with; +use crate::util::Env; /// Makes the vars for decoding this particular field and decode format fn make_decode_with_vars( diff --git a/crates/compiler/derive/src/decoding/record/finalizer.rs b/crates/compiler/derive/src/decoding/record/finalizer.rs index aa49adc6cb..1e0c10397e 100644 --- a/crates/compiler/derive/src/decoding/record/finalizer.rs +++ b/crates/compiler/derive/src/decoding/record/finalizer.rs @@ -3,7 +3,7 @@ use roc_can::expr::{ }; use roc_can::pattern::Pattern; use roc_collections::SendMap; -use roc_module::called_via::CalledVia; + use roc_module::ident::Lowercase; use roc_module::symbol::Symbol; use roc_region::all::{Loc, Region}; @@ -17,13 +17,13 @@ use crate::synth_var; use crate::util::{empty_list, ok_to_ok_branch, Env, ExtensionKind}; use super::decodeWith::decode_with; -use super::wrap_in_decode_custom_decode_with; + // Example: // finalizer = \rec -> -// when rec.first is -// Ok first -> -// when rec.second is -// Ok second -> Ok {first, second} +// when rec.f0 is +// Ok f0 -> +// when rec.f1 is +// Ok f1 -> Ok {f0, f1} // Err NoField -> Err TooShort // Err NoField -> Err TooShort @@ -63,7 +63,7 @@ pub(super) fn finalizer( fields_map.insert(field_name.clone(), field); } - // The bottom of the happy path - return the decoded record {first: a, second: b} wrapped with + // The bottom of the happy path - return the decoded record {f0: a, f1: b} wrapped with // "Ok". let return_type_var; let mut body = { @@ -103,8 +103,8 @@ pub(super) fn finalizer( // Unwrap each result in the decoded state // - // when rec.first is - // Ok first -> ...happy path... + // when rec.f0 is + // Ok f0 -> ...happy path... // Err NoField -> Err TooShort for (((symbol, field_name), &field_var), &result_field_var) in pattern_symbols .iter() @@ -113,7 +113,7 @@ pub(super) fn finalizer( .zip(field_vars.iter().rev()) .zip(result_field_vars.iter().rev()) { - // [Ok field_var,Err DecodeError] + //[Ok field_var, Err DecodeError] // when rec.f0 is // Err _ -> // when Decode.decodeWith [] Decode.decoder fmt is @@ -172,6 +172,15 @@ pub(super) fn finalizer( redundant: RedundantMark::known_non_redundant(), }; + // when + // when stateRecord.f0 is + // Ok f0-> Ok f0 + // _ -> + // when Decode.decodeWith [] Decode.decoder fmt is + // decRec -> decRec.result + // is + // _-> TooShort + // Ok x-> expr body = Expr::When { loc_cond: Box::new(Loc::at_zero(attempt_empty_decode_expr)), cond_var: attempt_empty_decode_var, @@ -231,7 +240,7 @@ pub(super) fn finalizer( /// when rec.f0 is /// Err _ -> /// when Decode.decodeWith [] Decode.decoder fmt is -/// rec2 -> rec2.result +/// decRec-> decRec.result /// Ok a -> Ok a /// ``` /// Tries to decode the field with a zero byte input if it missing, diff --git a/crates/compiler/derive/src/decoding/record/stepField.rs b/crates/compiler/derive/src/decoding/record/stepField.rs index 9c173f5f99..304320ef82 100644 --- a/crates/compiler/derive/src/decoding/record/stepField.rs +++ b/crates/compiler/derive/src/decoding/record/stepField.rs @@ -14,10 +14,10 @@ use roc_types::subs::{ use roc_types::types::RecordField; use crate::synth_var; -use crate::util::{empty_list, ok_to_ok_branch, Env, ExtensionKind}; +use crate::util::{Env, ExtensionKind}; use super::decodeWith::decode_with; -use super::wrap_in_decode_custom_decode_with; + // Example: // stepField = \state, field -> // when field is @@ -496,7 +496,8 @@ fn state_record_update( decode_err_var: Variable, result_field_var: Variable, ) -> Expr { - let branch_body = { + + { // result: when rec.result is // Ok val -> Ok {state & first: Ok val}, // Err err -> Err err @@ -646,6 +647,5 @@ fn state_record_update( record_var: custom_callback_ret_var, fields: fields_map, } - }; - branch_body + } } diff --git a/crates/compiler/derive/src/util.rs b/crates/compiler/derive/src/util.rs index 153817b41b..214181e3ce 100644 --- a/crates/compiler/derive/src/util.rs +++ b/crates/compiler/derive/src/util.rs @@ -218,7 +218,8 @@ pub(crate) fn ok_to_ok_branch( symbol: &Symbol, env: &mut Env<'_>, ) -> WhenBranch { - let ok_branch = WhenBranch { + + WhenBranch { patterns: vec![WhenBranchPattern { pattern: Loc::at_zero(Pattern::AppliedTag { whole_var: pattern_var, @@ -236,8 +237,7 @@ pub(crate) fn ok_to_ok_branch( }), guard: None, redundant: RedundantMark::known_non_redundant(), - }; - ok_branch + } } /// `[]` /// Creates an empty list of the type provided