mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 12:18:19 +00:00
clippy and comments
comments and clippy
This commit is contained in:
parent
089c499fc6
commit
56481dc724
5 changed files with 39 additions and 38 deletions
|
@ -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;
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue