Skip to content

Commit

Permalink
clippy and comments
Browse files Browse the repository at this point in the history
comments and clippy
  • Loading branch information
faldor20 committed Mar 17, 2024
1 parent 089c499 commit 56481dc
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 38 deletions.
10 changes: 5 additions & 5 deletions crates/compiler/derive/src/decoding/record.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
20 changes: 6 additions & 14 deletions crates/compiler/derive/src/decoding/record/decodeWith.rs
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
31 changes: 20 additions & 11 deletions crates/compiler/derive/src/decoding/record/finalizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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

Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions crates/compiler/derive/src/decoding/record/stepField.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -646,6 +647,5 @@ fn state_record_update(
record_var: custom_callback_ret_var,
fields: fields_map,
}
};
branch_body
}
}
6 changes: 3 additions & 3 deletions crates/compiler/derive/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down

0 comments on commit 56481dc

Please sign in to comment.