Unify more derived decoder things

This commit is contained in:
Richard Feldman 2022-08-12 12:32:20 -04:00 committed by Ayaz Hafiz
parent 33548874d3
commit bccfa55179
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58

View file

@ -214,6 +214,8 @@ fn decoder_step_field(
// } // }
// ) // )
let this_custom_callback_var;
let custom_callback_ret_var;
let custom_callback = { let custom_callback = {
// \bytes, fmt -> // \bytes, fmt ->
// # Uses a single-branch `when` because `let` is more expensive to monomorphize // # Uses a single-branch `when` because `let` is more expensive to monomorphize
@ -257,7 +259,7 @@ fn decoder_step_field(
synth_var(env.subs, Content::Structure(flat_type)) synth_var(env.subs, Content::Structure(flat_type))
}; };
let custom_callback_ret_var = { custom_callback_ret_var = {
let rest_field = RecordField::Required(Variable::LIST_U8); let rest_field = RecordField::Required(Variable::LIST_U8);
let result_field = RecordField::Required(when_expr_var); let result_field = RecordField::Required(when_expr_var);
let flat_type = FlatType::Record( let flat_type = FlatType::Record(
@ -491,24 +493,50 @@ fn decoder_step_field(
} }
}; };
let custom_closure_symbol = env.unique_symbol();
this_custom_callback_var = env.subs.fresh_unnamed_flex_var();
let custom_callback_lambda_set_var = {
let content = Content::LambdaSet(LambdaSet {
solved: UnionLambdas::insert_into_subs(
env.subs,
[(custom_closure_symbol, [state_record_var])],
),
recursion_var: OptVariable::NONE,
unspecialized: Default::default(),
ambient_function: this_custom_callback_var,
});
let custom_callback_lambda_set_var = synth_var(env.subs, content);
let subs_slice =
SubsSlice::insert_into_subs(env.subs, [bytes_arg_var, fmt_arg_var]);
env.subs.set_content(
this_custom_callback_var,
Content::Structure(FlatType::Func(
subs_slice,
custom_callback_lambda_set_var,
custom_callback_ret_var,
)),
);
custom_callback_lambda_set_var
};
// \bytes, fmt -> …
Expr::Closure(ClosureData { Expr::Closure(ClosureData {
function_type: Variable::NULL, // TODO function_type: this_custom_callback_var,
closure_type: Variable::NULL, // TODO closure_type: custom_callback_lambda_set_var,
return_type: Variable::NULL, // TODO return_type: custom_callback_ret_var,
name: env.unique_symbol(), name: custom_closure_symbol,
captured_symbols: vec![( captured_symbols: vec![(state_arg_symbol, state_record_var)],
state_arg_symbol,
Variable::NULL, // TODO
)],
recursive: Recursive::NotRecursive, recursive: Recursive::NotRecursive,
arguments: vec![ arguments: vec![
( (
Variable::NULL, // TODO bytes_arg_var,
AnnotatedMark::known_exhaustive(), AnnotatedMark::known_exhaustive(),
Loc::at_zero(Pattern::Identifier(bytes_arg_symbol)), Loc::at_zero(Pattern::Identifier(bytes_arg_symbol)),
), ),
( (
Variable::NULL, // TODO fmt_arg_var,
AnnotatedMark::known_exhaustive(), AnnotatedMark::known_exhaustive(),
Loc::at_zero(Pattern::Identifier(fmt_arg_symbol)), Loc::at_zero(Pattern::Identifier(fmt_arg_symbol)),
), ),
@ -518,28 +546,28 @@ fn decoder_step_field(
}; };
let decode_custom = { let decode_custom = {
// Decode.custom \bytes, fmt -> let decode_custom_var = env.import_builtin_symbol_var(Symbol::DECODE_CUSTOM);
// # Uses a single-branch `when` because `let` is more expensive to monomorphize let decode_custom_closure_var = env.subs.fresh_unnamed_flex_var();
// # due to checks for polymorphic expressions, and `rec` would be polymorphic. let decode_custom_ret_var = env.subs.fresh_unnamed_flex_var();
// when Decode.decodeWith bytes Decode.decoder fmt is let this_decode_custom_var = {
// rec -> let subs_slice = SubsSlice::insert_into_subs(env.subs, [this_custom_callback_var]);
// { let flat_type =
// rest: rec.rest, FlatType::Func(subs_slice, decode_custom_closure_var, decode_custom_ret_var);
// result: when rec.result is
// Ok val -> Ok {state & first: Ok val}, synth_var(env.subs, Content::Structure(flat_type))
// Err err -> Err err };
// }
env.unify(decode_custom_var, this_decode_custom_var);
// Decode.custom \bytes, fmt -> …
Expr::Call( Expr::Call(
Box::new(( Box::new((
Variable::NULL, // TODO this_decode_custom_var,
Loc::at_zero(Expr::Var(Symbol::DECODE_CUSTOM)), Loc::at_zero(Expr::Var(Symbol::DECODE_CUSTOM)),
Variable::NULL, // TODO decode_custom_closure_var,
Variable::NULL, // TODO decode_custom_ret_var,
)), )),
vec![( vec![(this_custom_callback_var, Loc::at_zero(custom_callback))],
Variable::NULL, // TODO
Loc::at_zero(custom_callback),
)],
CalledVia::Space, CalledVia::Space,
) )
}; };