mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 13:59:08 +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::{
|
use roc_can::expr::{
|
||||||
AnnotatedMark, ClosureData, Expr, Field, Recursive, WhenBranch, WhenBranchPattern,
|
Expr, Field,
|
||||||
};
|
};
|
||||||
use roc_can::pattern::Pattern;
|
|
||||||
use roc_collections::SendMap;
|
use roc_collections::SendMap;
|
||||||
use roc_module::called_via::CalledVia;
|
use roc_module::called_via::CalledVia;
|
||||||
use roc_module::ident::Lowercase;
|
use roc_module::ident::Lowercase;
|
||||||
use roc_module::symbol::Symbol;
|
use roc_module::symbol::Symbol;
|
||||||
use roc_region::all::{Loc, Region};
|
use roc_region::all::{Loc, Region};
|
||||||
use roc_types::subs::{
|
use roc_types::subs::{
|
||||||
Content, ExhaustiveMark, FlatType, LambdaSet, OptVariable, RecordFields, RedundantMark,
|
Content, FlatType, RecordFields,
|
||||||
SubsSlice, TagExt, UnionLambdas, UnionTags, Variable,
|
SubsSlice, TagExt, UnionTags, Variable,
|
||||||
};
|
};
|
||||||
use roc_types::types::RecordField;
|
use roc_types::types::RecordField;
|
||||||
|
|
||||||
use crate::synth_var;
|
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::finalizer::finalizer;
|
||||||
use self::stepField::step_field;
|
use self::stepField::step_field;
|
||||||
|
|
|
@ -1,22 +1,14 @@
|
||||||
use roc_can::expr::{
|
use roc_can::expr::Expr;
|
||||||
AnnotatedMark, ClosureData, Expr, Field, Recursive, WhenBranch, WhenBranchPattern,
|
|
||||||
};
|
|
||||||
use roc_can::pattern::Pattern;
|
|
||||||
use roc_collections::SendMap;
|
|
||||||
use roc_module::called_via::CalledVia;
|
use roc_module::called_via::CalledVia;
|
||||||
use roc_module::ident::Lowercase;
|
|
||||||
use roc_module::symbol::Symbol;
|
use roc_module::symbol::Symbol;
|
||||||
use roc_region::all::{Loc, Region};
|
use roc_region::all::Loc;
|
||||||
use roc_types::subs::{
|
use roc_types::subs::{Content, FlatType, RecordFields, SubsSlice, TagExt, UnionTags, Variable};
|
||||||
Content, ExhaustiveMark, FlatType, LambdaSet, OptVariable, RecordFields, RedundantMark,
|
|
||||||
SubsSlice, TagExt, UnionLambdas, UnionTags, Variable,
|
|
||||||
};
|
|
||||||
use roc_types::types::RecordField;
|
use roc_types::types::RecordField;
|
||||||
|
|
||||||
use crate::synth_var;
|
use crate::synth_var;
|
||||||
use crate::util::{empty_list, ok_to_ok_branch, Env, ExtensionKind};
|
use crate::util::Env;
|
||||||
|
|
||||||
use super::wrap_in_decode_custom_decode_with;
|
|
||||||
|
|
||||||
/// Makes the vars for decoding this particular field and decode format
|
/// Makes the vars for decoding this particular field and decode format
|
||||||
fn make_decode_with_vars(
|
fn make_decode_with_vars(
|
||||||
|
|
|
@ -3,7 +3,7 @@ use roc_can::expr::{
|
||||||
};
|
};
|
||||||
use roc_can::pattern::Pattern;
|
use roc_can::pattern::Pattern;
|
||||||
use roc_collections::SendMap;
|
use roc_collections::SendMap;
|
||||||
use roc_module::called_via::CalledVia;
|
|
||||||
use roc_module::ident::Lowercase;
|
use roc_module::ident::Lowercase;
|
||||||
use roc_module::symbol::Symbol;
|
use roc_module::symbol::Symbol;
|
||||||
use roc_region::all::{Loc, Region};
|
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 crate::util::{empty_list, ok_to_ok_branch, Env, ExtensionKind};
|
||||||
|
|
||||||
use super::decodeWith::decode_with;
|
use super::decodeWith::decode_with;
|
||||||
use super::wrap_in_decode_custom_decode_with;
|
|
||||||
// Example:
|
// Example:
|
||||||
// finalizer = \rec ->
|
// finalizer = \rec ->
|
||||||
// when rec.first is
|
// when rec.f0 is
|
||||||
// Ok first ->
|
// Ok f0 ->
|
||||||
// when rec.second is
|
// when rec.f1 is
|
||||||
// Ok second -> Ok {first, second}
|
// Ok f1 -> Ok {f0, f1}
|
||||||
// Err NoField -> Err TooShort
|
// Err NoField -> Err TooShort
|
||||||
// Err NoField -> Err TooShort
|
// Err NoField -> Err TooShort
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ pub(super) fn finalizer(
|
||||||
fields_map.insert(field_name.clone(), field);
|
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".
|
// "Ok".
|
||||||
let return_type_var;
|
let return_type_var;
|
||||||
let mut body = {
|
let mut body = {
|
||||||
|
@ -103,8 +103,8 @@ pub(super) fn finalizer(
|
||||||
|
|
||||||
// Unwrap each result in the decoded state
|
// Unwrap each result in the decoded state
|
||||||
//
|
//
|
||||||
// when rec.first is
|
// when rec.f0 is
|
||||||
// Ok first -> ...happy path...
|
// Ok f0 -> ...happy path...
|
||||||
// Err NoField -> Err TooShort
|
// Err NoField -> Err TooShort
|
||||||
for (((symbol, field_name), &field_var), &result_field_var) in pattern_symbols
|
for (((symbol, field_name), &field_var), &result_field_var) in pattern_symbols
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -172,6 +172,15 @@ pub(super) fn finalizer(
|
||||||
redundant: RedundantMark::known_non_redundant(),
|
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 {
|
body = Expr::When {
|
||||||
loc_cond: Box::new(Loc::at_zero(attempt_empty_decode_expr)),
|
loc_cond: Box::new(Loc::at_zero(attempt_empty_decode_expr)),
|
||||||
cond_var: attempt_empty_decode_var,
|
cond_var: attempt_empty_decode_var,
|
||||||
|
@ -231,7 +240,7 @@ pub(super) fn finalizer(
|
||||||
/// when rec.f0 is
|
/// when rec.f0 is
|
||||||
/// Err _ ->
|
/// Err _ ->
|
||||||
/// when Decode.decodeWith [] Decode.decoder fmt is
|
/// when Decode.decodeWith [] Decode.decoder fmt is
|
||||||
/// rec2 -> rec2.result
|
/// decRec-> decRec.result
|
||||||
/// Ok a -> Ok a
|
/// Ok a -> Ok a
|
||||||
/// ```
|
/// ```
|
||||||
/// Tries to decode the field with a zero byte input if it missing,
|
/// 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 roc_types::types::RecordField;
|
||||||
|
|
||||||
use crate::synth_var;
|
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::decodeWith::decode_with;
|
||||||
use super::wrap_in_decode_custom_decode_with;
|
|
||||||
// Example:
|
// Example:
|
||||||
// stepField = \state, field ->
|
// stepField = \state, field ->
|
||||||
// when field is
|
// when field is
|
||||||
|
@ -496,7 +496,8 @@ fn state_record_update(
|
||||||
decode_err_var: Variable,
|
decode_err_var: Variable,
|
||||||
result_field_var: Variable,
|
result_field_var: Variable,
|
||||||
) -> Expr {
|
) -> Expr {
|
||||||
let branch_body = {
|
|
||||||
|
{
|
||||||
// result: when rec.result is
|
// result: when rec.result is
|
||||||
// Ok val -> Ok {state & first: Ok val},
|
// Ok val -> Ok {state & first: Ok val},
|
||||||
// Err err -> Err err
|
// Err err -> Err err
|
||||||
|
@ -646,6 +647,5 @@ fn state_record_update(
|
||||||
record_var: custom_callback_ret_var,
|
record_var: custom_callback_ret_var,
|
||||||
fields: fields_map,
|
fields: fields_map,
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
branch_body
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -218,7 +218,8 @@ pub(crate) fn ok_to_ok_branch(
|
||||||
symbol: &Symbol,
|
symbol: &Symbol,
|
||||||
env: &mut Env<'_>,
|
env: &mut Env<'_>,
|
||||||
) -> WhenBranch {
|
) -> WhenBranch {
|
||||||
let ok_branch = WhenBranch {
|
|
||||||
|
WhenBranch {
|
||||||
patterns: vec![WhenBranchPattern {
|
patterns: vec![WhenBranchPattern {
|
||||||
pattern: Loc::at_zero(Pattern::AppliedTag {
|
pattern: Loc::at_zero(Pattern::AppliedTag {
|
||||||
whole_var: pattern_var,
|
whole_var: pattern_var,
|
||||||
|
@ -236,8 +237,7 @@ pub(crate) fn ok_to_ok_branch(
|
||||||
}),
|
}),
|
||||||
guard: None,
|
guard: None,
|
||||||
redundant: RedundantMark::known_non_redundant(),
|
redundant: RedundantMark::known_non_redundant(),
|
||||||
};
|
}
|
||||||
ok_branch
|
|
||||||
}
|
}
|
||||||
/// `[]`
|
/// `[]`
|
||||||
/// Creates an empty list of the type provided
|
/// Creates an empty list of the type provided
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue