mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 00:24:34 +00:00
Fix broken ability implementation
This commit is contained in:
parent
2aac2e01f8
commit
30b8a1407d
11 changed files with 130 additions and 132 deletions
|
@ -130,12 +130,12 @@ hash_dict = \hasher, dict -> Hash.hash_unordered(hasher, to_list(dict), List.wal
|
||||||
|
|
||||||
to_inspector_dict : Dict k v -> Inspector f where k implements Inspect & Hash & Eq, v implements Inspect, f implements InspectFormatter
|
to_inspector_dict : Dict k v -> Inspector f where k implements Inspect & Hash & Eq, v implements Inspect, f implements InspectFormatter
|
||||||
to_inspector_dict = \dict ->
|
to_inspector_dict = \dict ->
|
||||||
Inspect.custom \fmt ->
|
Inspect.custom(\fmt ->
|
||||||
Inspect.apply(Inspect.dict(dict, walk, Inspect.to_inspector, Inspect.to_inspector) fmt)
|
Inspect.apply(Inspect.dict(dict, walk, Inspect.to_inspector, Inspect.to_inspector), fmt))
|
||||||
|
|
||||||
## Return an empty dictionary.
|
## Return an empty dictionary.
|
||||||
## ```roc
|
## ```roc
|
||||||
## emptyDict = Dict.empty({})
|
## empty_dict = Dict.empty({})
|
||||||
## ```
|
## ```
|
||||||
empty : {} -> Dict * *
|
empty : {} -> Dict * *
|
||||||
empty = \{} ->
|
empty = \{} ->
|
||||||
|
@ -376,7 +376,7 @@ keep_if_help : Dict k v, ((k, v) -> Bool), U64, U64 -> Dict k v
|
||||||
keep_if_help = \@Dict(dict), predicate, index, length ->
|
keep_if_help = \@Dict(dict), predicate, index, length ->
|
||||||
if index < length then
|
if index < length then
|
||||||
(key, value) = list_get_unsafe(dict.data, index)
|
(key, value) = list_get_unsafe(dict.data, index)
|
||||||
if predicate(key, value) then
|
if predicate((key, value)) then
|
||||||
keep_if_help(@Dict(dict), predicate, Num.add_wrap(index, 1), length)
|
keep_if_help(@Dict(dict), predicate, Num.add_wrap(index, 1), length)
|
||||||
else
|
else
|
||||||
keep_if_help(Dict.remove(@Dict(dict), key), predicate, index, Num.sub_wrap(length, 1))
|
keep_if_help(Dict.remove(@Dict(dict), key), predicate, index, Num.sub_wrap(length, 1))
|
||||||
|
@ -426,7 +426,7 @@ contains : Dict k v, k -> Bool
|
||||||
contains = \dict, key ->
|
contains = \dict, key ->
|
||||||
find(dict, key)
|
find(dict, key)
|
||||||
|> .result
|
|> .result
|
||||||
|> Result.isOk
|
|> Result.is_ok
|
||||||
|
|
||||||
## Insert a value into the dictionary at a specified key.
|
## Insert a value into the dictionary at a specified key.
|
||||||
## ```roc
|
## ```roc
|
||||||
|
@ -791,7 +791,7 @@ find_helper = \buckets, bucket_index, dist_and_fingerprint, data, key ->
|
||||||
|
|
||||||
remove_bucket : Dict k v, U64 -> Dict k v
|
remove_bucket : Dict k v, U64 -> Dict k v
|
||||||
remove_bucket = \@Dict({ buckets: buckets0, data: data0, max_bucket_capacity, max_load_factor, shifts }), bucket_index0 ->
|
remove_bucket = \@Dict({ buckets: buckets0, data: data0, max_bucket_capacity, max_load_factor, shifts }), bucket_index0 ->
|
||||||
data_index_to_remove = list_get_unsafe(buckets0, bucket_index0).data_index
|
data_index_to_remove = list_get_unsafe(buckets0, bucket_index0) |> .data_index
|
||||||
data_index_to_remove_u64 = Num.to_u64(data_index_to_remove)
|
data_index_to_remove_u64 = Num.to_u64(data_index_to_remove)
|
||||||
|
|
||||||
(buckets1, bucket_index1) = remove_bucket_helper(buckets0, bucket_index0)
|
(buckets1, bucket_index1) = remove_bucket_helper(buckets0, bucket_index0)
|
||||||
|
@ -859,7 +859,7 @@ increase_size = \@Dict({ data, max_bucket_capacity, max_load_factor, shifts }) -
|
||||||
shifts: new_shifts,
|
shifts: new_shifts,
|
||||||
})
|
})
|
||||||
else
|
else
|
||||||
crash("Dict hit limit of $(Num.toStr(max_bucket_count)) elements. Unable to grow more.")
|
crash("Dict hit limit of $(Num.to_str(max_bucket_count)) elements. Unable to grow more.")
|
||||||
|
|
||||||
alloc_buckets_from_shift : U8, F32 -> (List Bucket, U64)
|
alloc_buckets_from_shift : U8, F32 -> (List Bucket, U64)
|
||||||
alloc_buckets_from_shift = \shifts, max_load_factor ->
|
alloc_buckets_from_shift = \shifts, max_load_factor ->
|
||||||
|
@ -1418,7 +1418,7 @@ wymix = \a, b ->
|
||||||
|
|
||||||
wymum : U64, U64 -> { lower : U64, upper : U64 }
|
wymum : U64, U64 -> { lower : U64, upper : U64 }
|
||||||
wymum = \a, b ->
|
wymum = \a, b ->
|
||||||
r = Num.mul_wrap(Num.toU128(a), Num.toU128(b))
|
r = Num.mul_wrap(Num.to_u128(a), Num.to_u128(b))
|
||||||
lower = Num.to_u64(r)
|
lower = Num.to_u64(r)
|
||||||
upper = Num.shift_right_zf_by(r, 64) |> Num.to_u64
|
upper = Num.shift_right_zf_by(r, 64) |> Num.to_u64
|
||||||
|
|
||||||
|
@ -1691,7 +1691,7 @@ expect
|
||||||
|> Dict.insert("Alice", 17)
|
|> Dict.insert("Alice", 17)
|
||||||
|> Dict.insert("Bob", 18)
|
|> Dict.insert("Bob", 18)
|
||||||
|> Dict.insert("Charlie", 19)
|
|> Dict.insert("Charlie", 19)
|
||||||
|> Dict.keep_if(\(k, _v) -> Str.endsWith(k, "e"))
|
|> Dict.keep_if(\(k, _v) -> Str.ends_with(k, "e"))
|
||||||
|
|
||||||
d2 =
|
d2 =
|
||||||
Dict.empty({})
|
Dict.empty({})
|
||||||
|
|
|
@ -220,7 +220,7 @@ dbg_tuple = \fields ->
|
||||||
custom(\f0 ->
|
custom(\f0 ->
|
||||||
dbg_write(f0, "(")
|
dbg_write(f0, "(")
|
||||||
|> \f1 ->
|
|> \f1 ->
|
||||||
(List.walk, fields, (f1, Bool.false), (\(f2, prepend_sep), inspector ->
|
List.walk(fields, (f1, Bool.false), (\(f2, prepend_sep), inspector ->
|
||||||
f3 =
|
f3 =
|
||||||
if prepend_sep then
|
if prepend_sep then
|
||||||
dbg_write(f2, ", ")
|
dbg_write(f2, ", ")
|
||||||
|
|
|
@ -847,8 +847,8 @@ fn canonicalize_opaque<'a>(
|
||||||
// Did the user claim this implementation for a specialization of a different
|
// Did the user claim this implementation for a specialization of a different
|
||||||
// type? e.g.
|
// type? e.g.
|
||||||
//
|
//
|
||||||
// A implements [Hash {hash: myHash}]
|
// A implements [Hash {hash: my_hash}]
|
||||||
// B implements [Hash {hash: myHash}]
|
// B implements [Hash {hash: my_hash}]
|
||||||
//
|
//
|
||||||
// If so, that's an error and we drop the impl for this opaque type.
|
// If so, that's an error and we drop the impl for this opaque type.
|
||||||
let member_impl = match scope.abilities_store.impl_key(impl_symbol) {
|
let member_impl = match scope.abilities_store.impl_key(impl_symbol) {
|
||||||
|
|
|
@ -30,11 +30,11 @@ fn to_encoder<'a>(env: &mut Env<'a>, at_opaque: &'a str) -> ast::Expr<'a> {
|
||||||
ast::PatternApplyStyle::Whitespace,
|
ast::PatternApplyStyle::Whitespace,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Encode.toEncoder payload
|
// Encode.to_encoder(payload)
|
||||||
let call_member = alloc_expr(ast::Expr::Apply(
|
let call_member = alloc_expr(ast::Expr::Apply(
|
||||||
alloc_expr(ast::Expr::Var {
|
alloc_expr(ast::Expr::Var {
|
||||||
module_name: "Encode",
|
module_name: "Encode",
|
||||||
ident: "toEncoder",
|
ident: "to_encoder",
|
||||||
}),
|
}),
|
||||||
&*env.arena.alloc([&*alloc_expr(ast::Expr::Var {
|
&*env.arena.alloc([&*alloc_expr(ast::Expr::Var {
|
||||||
module_name: "",
|
module_name: "",
|
||||||
|
@ -43,7 +43,7 @@ fn to_encoder<'a>(env: &mut Env<'a>, at_opaque: &'a str) -> ast::Expr<'a> {
|
||||||
roc_module::called_via::CalledVia::Space,
|
roc_module::called_via::CalledVia::Space,
|
||||||
));
|
));
|
||||||
|
|
||||||
// \@Opaq payload -> Encode.toEncoder payload
|
// \@Opaq payload -> Encode.to_encoder(payload)
|
||||||
ast::Expr::Closure(
|
ast::Expr::Closure(
|
||||||
env.arena
|
env.arena
|
||||||
.alloc([Loc::at(DERIVED_REGION, opaque_apply_pattern)]),
|
.alloc([Loc::at(DERIVED_REGION, opaque_apply_pattern)]),
|
||||||
|
@ -58,11 +58,11 @@ fn decoder<'a>(env: &mut Env<'a>, at_opaque: &'a str) -> ast::Expr<'a> {
|
||||||
let bytes = "#bytes";
|
let bytes = "#bytes";
|
||||||
let fmt = "#fmt";
|
let fmt = "#fmt";
|
||||||
|
|
||||||
// Decode.decodeWith bytes Decode.decoder fmt
|
// Decode.decode_with(bytes, Decode.decoder, fmt)
|
||||||
let call_decode_with = ast::Expr::Apply(
|
let call_decode_with = ast::Expr::Apply(
|
||||||
alloc_expr(ast::Expr::Var {
|
alloc_expr(ast::Expr::Var {
|
||||||
module_name: "Decode",
|
module_name: "Decode",
|
||||||
ident: "decodeWith",
|
ident: "decode_with",
|
||||||
}),
|
}),
|
||||||
env.arena.alloc([
|
env.arena.alloc([
|
||||||
&*alloc_expr(ast::Expr::Var {
|
&*alloc_expr(ast::Expr::Var {
|
||||||
|
@ -81,11 +81,11 @@ fn decoder<'a>(env: &mut Env<'a>, at_opaque: &'a str) -> ast::Expr<'a> {
|
||||||
CalledVia::Space,
|
CalledVia::Space,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Decode.mapResult (Decode.decodeWith bytes Decode.decoder fmt) @Opaq
|
// Decode.map_result(Decode.decode_with(bytes, Decode.decoder, fmt), @Opaq)
|
||||||
let call_map_result = ast::Expr::Apply(
|
let call_map_result = ast::Expr::Apply(
|
||||||
alloc_expr(ast::Expr::Var {
|
alloc_expr(ast::Expr::Var {
|
||||||
module_name: "Decode",
|
module_name: "Decode",
|
||||||
ident: "mapResult",
|
ident: "map_result",
|
||||||
}),
|
}),
|
||||||
env.arena.alloc([
|
env.arena.alloc([
|
||||||
&*alloc_expr(call_decode_with),
|
&*alloc_expr(call_decode_with),
|
||||||
|
@ -95,7 +95,7 @@ fn decoder<'a>(env: &mut Env<'a>, at_opaque: &'a str) -> ast::Expr<'a> {
|
||||||
);
|
);
|
||||||
|
|
||||||
// \bytes, fmt ->
|
// \bytes, fmt ->
|
||||||
// Decode.mapResult (Decode.decodeWith bytes Decode.decoder fmt) @Opaq
|
// Decode.map_result(Decode.decode_with(bytes, Decode.decoder, fmt), @Opaq)
|
||||||
let custom_closure = ast::Expr::Closure(
|
let custom_closure = ast::Expr::Closure(
|
||||||
env.arena.alloc([
|
env.arena.alloc([
|
||||||
Loc::at(DERIVED_REGION, ast::Pattern::Identifier { ident: bytes }),
|
Loc::at(DERIVED_REGION, ast::Pattern::Identifier { ident: bytes }),
|
||||||
|
@ -136,7 +136,7 @@ fn hash<'a>(env: &mut Env<'a>, at_opaque: &'a str) -> ast::Expr<'a> {
|
||||||
PatternApplyStyle::Whitespace,
|
PatternApplyStyle::Whitespace,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Hash.hash hasher payload
|
// Hash.hash(hasher, payload)
|
||||||
let call_member = alloc_expr(ast::Expr::Apply(
|
let call_member = alloc_expr(ast::Expr::Apply(
|
||||||
alloc_expr(ast::Expr::Var {
|
alloc_expr(ast::Expr::Var {
|
||||||
module_name: "Hash",
|
module_name: "Hash",
|
||||||
|
@ -155,7 +155,7 @@ fn hash<'a>(env: &mut Env<'a>, at_opaque: &'a str) -> ast::Expr<'a> {
|
||||||
roc_module::called_via::CalledVia::Space,
|
roc_module::called_via::CalledVia::Space,
|
||||||
));
|
));
|
||||||
|
|
||||||
// \hasher, @Opaq payload -> Hash.hash hasher payload
|
// \hasher, @Opaq payload -> Hash.hash(hasher, payload)
|
||||||
ast::Expr::Closure(
|
ast::Expr::Closure(
|
||||||
env.arena.alloc([
|
env.arena.alloc([
|
||||||
Loc::at(DERIVED_REGION, ast::Pattern::Identifier { ident: hasher }),
|
Loc::at(DERIVED_REGION, ast::Pattern::Identifier { ident: hasher }),
|
||||||
|
@ -192,11 +192,11 @@ fn is_eq<'a>(env: &mut Env<'a>, at_opaque: &'a str) -> ast::Expr<'a> {
|
||||||
PatternApplyStyle::Whitespace,
|
PatternApplyStyle::Whitespace,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Bool.isEq payload1 payload2
|
// Bool.is_eq(payload1, payload2)
|
||||||
let call_member = alloc_expr(ast::Expr::Apply(
|
let call_member = alloc_expr(ast::Expr::Apply(
|
||||||
alloc_expr(ast::Expr::Var {
|
alloc_expr(ast::Expr::Var {
|
||||||
module_name: "Bool",
|
module_name: "Bool",
|
||||||
ident: "isEq",
|
ident: "is_eq",
|
||||||
}),
|
}),
|
||||||
&*env.arena.alloc([
|
&*env.arena.alloc([
|
||||||
&*alloc_expr(ast::Expr::Var {
|
&*alloc_expr(ast::Expr::Var {
|
||||||
|
@ -211,7 +211,7 @@ fn is_eq<'a>(env: &mut Env<'a>, at_opaque: &'a str) -> ast::Expr<'a> {
|
||||||
roc_module::called_via::CalledVia::Space,
|
roc_module::called_via::CalledVia::Space,
|
||||||
));
|
));
|
||||||
|
|
||||||
// \@Opaq payload1, @Opaq payload2 -> Bool.isEq payload1 payload2
|
// \@Opaq payload1, @Opaq payload2 -> Bool.is_eq(payload1, payload2)
|
||||||
ast::Expr::Closure(
|
ast::Expr::Closure(
|
||||||
env.arena.alloc([
|
env.arena.alloc([
|
||||||
Loc::at(DERIVED_REGION, opaque1),
|
Loc::at(DERIVED_REGION, opaque1),
|
||||||
|
@ -239,11 +239,11 @@ fn to_inspector<'a>(env: &mut Env<'a>, at_opaque: &'a str) -> ast::Expr<'a> {
|
||||||
PatternApplyStyle::Whitespace,
|
PatternApplyStyle::Whitespace,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Inspect.toInspector payload
|
// Inspect.to_inspector(payload)
|
||||||
let to_inspector_payload = alloc_expr(ast::Expr::Apply(
|
let to_inspector_payload = alloc_expr(ast::Expr::Apply(
|
||||||
alloc_expr(ast::Expr::Var {
|
alloc_expr(ast::Expr::Var {
|
||||||
module_name: "Inspect",
|
module_name: "Inspect",
|
||||||
ident: "toInspector",
|
ident: "to_inspector",
|
||||||
}),
|
}),
|
||||||
&*env.arena.alloc([&*alloc_expr(ast::Expr::Var {
|
&*env.arena.alloc([&*alloc_expr(ast::Expr::Var {
|
||||||
module_name: "",
|
module_name: "",
|
||||||
|
@ -252,7 +252,7 @@ fn to_inspector<'a>(env: &mut Env<'a>, at_opaque: &'a str) -> ast::Expr<'a> {
|
||||||
roc_module::called_via::CalledVia::Space,
|
roc_module::called_via::CalledVia::Space,
|
||||||
));
|
));
|
||||||
|
|
||||||
// Inspect.tag "@opaque" [Inspect.toInspector payload]
|
// Inspect.tag("@opaque", [Inspect.to_inspector(payload)])
|
||||||
let to_inspector_list = alloc_expr(ast::Expr::List(Collection::with_items(
|
let to_inspector_list = alloc_expr(ast::Expr::List(Collection::with_items(
|
||||||
&*env.arena.alloc([&*to_inspector_payload]),
|
&*env.arena.alloc([&*to_inspector_payload]),
|
||||||
)));
|
)));
|
||||||
|
@ -269,7 +269,7 @@ fn to_inspector<'a>(env: &mut Env<'a>, at_opaque: &'a str) -> ast::Expr<'a> {
|
||||||
|
|
||||||
let fmt = "#fmt";
|
let fmt = "#fmt";
|
||||||
|
|
||||||
// \fmt -> Inspect.apply opaqueInspector fmt
|
// \fmt -> Inspect.apply(opaque_inspector, fmt)
|
||||||
let apply_opaque_inspector = alloc_expr(ast::Expr::Apply(
|
let apply_opaque_inspector = alloc_expr(ast::Expr::Apply(
|
||||||
alloc_expr(ast::Expr::Var {
|
alloc_expr(ast::Expr::Var {
|
||||||
module_name: "Inspect",
|
module_name: "Inspect",
|
||||||
|
@ -325,14 +325,14 @@ pub(crate) fn synthesize_member_impl<'a>(
|
||||||
|
|
||||||
let (impl_name, def_body): (String, ast::Expr<'a>) = match ability_member {
|
let (impl_name, def_body): (String, ast::Expr<'a>) = match ability_member {
|
||||||
Symbol::ENCODE_TO_ENCODER => (
|
Symbol::ENCODE_TO_ENCODER => (
|
||||||
format!("#{opaque_name}_toEncoder"),
|
format!("#{opaque_name}_to_encoder"),
|
||||||
to_encoder(env, at_opaque),
|
to_encoder(env, at_opaque),
|
||||||
),
|
),
|
||||||
Symbol::DECODE_DECODER => (format!("#{opaque_name}_decoder"), decoder(env, at_opaque)),
|
Symbol::DECODE_DECODER => (format!("#{opaque_name}_decoder"), decoder(env, at_opaque)),
|
||||||
Symbol::HASH_HASH => (format!("#{opaque_name}_hash"), hash(env, at_opaque)),
|
Symbol::HASH_HASH => (format!("#{opaque_name}_hash"), hash(env, at_opaque)),
|
||||||
Symbol::BOOL_IS_EQ => (format!("#{opaque_name}_isEq"), is_eq(env, at_opaque)),
|
Symbol::BOOL_IS_EQ => (format!("#{opaque_name}_is_eq"), is_eq(env, at_opaque)),
|
||||||
Symbol::INSPECT_TO_INSPECTOR => (
|
Symbol::INSPECT_TO_INSPECTOR => (
|
||||||
format!("#{opaque_name}_toInspector"),
|
format!("#{opaque_name}_to_inspector"),
|
||||||
to_inspector(env, at_opaque),
|
to_inspector(env, at_opaque),
|
||||||
),
|
),
|
||||||
other => internal_error!("{:?} is not a derivable ability member!", other),
|
other => internal_error!("{:?} is not a derivable ability member!", other),
|
||||||
|
|
|
@ -1608,16 +1608,16 @@ fn binop_to_function(binop: BinOp) -> (&'static str, &'static str) {
|
||||||
Caret => (ModuleName::NUM, "pow"),
|
Caret => (ModuleName::NUM, "pow"),
|
||||||
Star => (ModuleName::NUM, "mul"),
|
Star => (ModuleName::NUM, "mul"),
|
||||||
Slash => (ModuleName::NUM, "div"),
|
Slash => (ModuleName::NUM, "div"),
|
||||||
DoubleSlash => (ModuleName::NUM, "divTrunc"),
|
DoubleSlash => (ModuleName::NUM, "div_trunc"),
|
||||||
Percent => (ModuleName::NUM, "rem"),
|
Percent => (ModuleName::NUM, "rem"),
|
||||||
Plus => (ModuleName::NUM, "add"),
|
Plus => (ModuleName::NUM, "add"),
|
||||||
Minus => (ModuleName::NUM, "sub"),
|
Minus => (ModuleName::NUM, "sub"),
|
||||||
Equals => (ModuleName::BOOL, "isEq"),
|
Equals => (ModuleName::BOOL, "is_eq"),
|
||||||
NotEquals => (ModuleName::BOOL, "isNotEq"),
|
NotEquals => (ModuleName::BOOL, "is_not_eq"),
|
||||||
LessThan => (ModuleName::NUM, "isLt"),
|
LessThan => (ModuleName::NUM, "is_lt"),
|
||||||
GreaterThan => (ModuleName::NUM, "isGt"),
|
GreaterThan => (ModuleName::NUM, "is_gt"),
|
||||||
LessThanOrEq => (ModuleName::NUM, "isLte"),
|
LessThanOrEq => (ModuleName::NUM, "is_lte"),
|
||||||
GreaterThanOrEq => (ModuleName::NUM, "isGte"),
|
GreaterThanOrEq => (ModuleName::NUM, "is_gte"),
|
||||||
And => (ModuleName::BOOL, "and"),
|
And => (ModuleName::BOOL, "and"),
|
||||||
Or => (ModuleName::BOOL, "or"),
|
Or => (ModuleName::BOOL, "or"),
|
||||||
Pizza => unreachable!("Cannot desugar the |> operator"),
|
Pizza => unreachable!("Cannot desugar the |> operator"),
|
||||||
|
|
|
@ -30,19 +30,19 @@ use super::wrap_in_decode_custom_decode_with;
|
||||||
/// ```roc
|
/// ```roc
|
||||||
/// decoder : Decoder {first: a, second: b} fmt where a implements Decoding, b implements Decoding, fmt implements DecoderFormatting
|
/// decoder : Decoder {first: a, second: b} fmt where a implements Decoding, b implements Decoding, fmt implements DecoderFormatting
|
||||||
/// decoder =
|
/// decoder =
|
||||||
/// initialState : {f0: Result a [NoField], f1: Result b [NoField]}
|
/// initial_state : {f0: Result a [NoField], f1: Result b [NoField]}
|
||||||
/// initialState = {f0: Err NoField, f1: Err NoField}
|
/// initial_state = {f0: Err NoField, f1: Err NoField}
|
||||||
///
|
///
|
||||||
/// stepField = \state, field ->
|
/// step_field = \state, field ->
|
||||||
/// when field is
|
/// when field is
|
||||||
/// "first" ->
|
/// "first" ->
|
||||||
/// Keep (Decode.custom \bytes, fmt ->
|
/// Keep (Decode.custom \bytes, fmt ->
|
||||||
/// when Decode.decodeWith bytes Decode.decoder fmt is
|
/// when Decode.decode_with bytes Decode.decoder fmt is
|
||||||
/// {result, rest} ->
|
/// {result, rest} ->
|
||||||
/// {result: Result.map result \val -> {state & f0: Ok val}, rest})
|
/// {result: Result.map result \val -> {state & f0: Ok val}, rest})
|
||||||
/// "second" ->
|
/// "second" ->
|
||||||
/// Keep (Decode.custom \bytes, fmt ->
|
/// Keep (Decode.custom \bytes, fmt ->
|
||||||
/// when Decode.decodeWith bytes Decode.decoder fmt is
|
/// when Decode.decode_with bytes Decode.decoder fmt is
|
||||||
/// {result, rest} ->
|
/// {result, rest} ->
|
||||||
/// {result: Result.map result \val -> {state & f1: Ok val}, rest})
|
/// {result: Result.map result \val -> {state & f1: Ok val}, rest})
|
||||||
/// _ -> Skip
|
/// _ -> Skip
|
||||||
|
@ -51,7 +51,7 @@ use super::wrap_in_decode_custom_decode_with;
|
||||||
/// when
|
/// when
|
||||||
/// when rec.f0 is
|
/// when rec.f0 is
|
||||||
/// Err NoField ->
|
/// Err NoField ->
|
||||||
/// when Decode.decodeWith [] Decode.decoder fmt is
|
/// when Decode.decode_with [] Decode.decoder fmt is
|
||||||
/// rec2 -> rec2.result
|
/// rec2 -> rec2.result
|
||||||
/// Ok a -> Ok a
|
/// Ok a -> Ok a
|
||||||
/// is
|
/// is
|
||||||
|
@ -59,7 +59,7 @@ use super::wrap_in_decode_custom_decode_with;
|
||||||
/// when
|
/// when
|
||||||
/// when rec.f1 is
|
/// when rec.f1 is
|
||||||
/// Err NoField ->
|
/// Err NoField ->
|
||||||
/// when Decode.decodeWith [] Decode.decoder fmt is
|
/// when Decode.decode_with [] Decode.decoder fmt is
|
||||||
/// rec2 -> rec2.result
|
/// rec2 -> rec2.result
|
||||||
/// Ok a -> Ok a
|
/// Ok a -> Ok a
|
||||||
/// is
|
/// is
|
||||||
|
@ -67,7 +67,7 @@ use super::wrap_in_decode_custom_decode_with;
|
||||||
/// Err _ -> Err TooShort
|
/// Err _ -> Err TooShort
|
||||||
/// Err _ -> Err TooShort
|
/// Err _ -> Err TooShort
|
||||||
///
|
///
|
||||||
/// Decode.custom \bytes, fmt -> Decode.decodeWith bytes (Decode.record initialState stepField finalizer) fmt
|
/// Decode.custom \bytes, fmt -> Decode.decode_with bytes (Decode.record initial_state step_field finalizer) fmt
|
||||||
///```
|
///```
|
||||||
pub(crate) fn decoder(
|
pub(crate) fn decoder(
|
||||||
env: &mut Env,
|
env: &mut Env,
|
||||||
|
@ -79,7 +79,7 @@ pub(crate) fn decoder(
|
||||||
// The type of each field in the decoding state, e.g. {first: Result a [NoField], second: Result b [NoField]}
|
// The type of each field in the decoding state, e.g. {first: Result a [NoField], second: Result b [NoField]}
|
||||||
let mut result_field_vars = Vec::with_capacity(fields.len());
|
let mut result_field_vars = Vec::with_capacity(fields.len());
|
||||||
|
|
||||||
// initialState = ...
|
// initial_state = ...
|
||||||
let (initial_state_var, initial_state) =
|
let (initial_state_var, initial_state) =
|
||||||
initial_state(env, &fields, &mut field_vars, &mut result_field_vars);
|
initial_state(env, &fields, &mut field_vars, &mut result_field_vars);
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ pub(crate) fn decoder(
|
||||||
&result_field_vars,
|
&result_field_vars,
|
||||||
);
|
);
|
||||||
|
|
||||||
// stepField = ...
|
// step_field = ...
|
||||||
let (step_field, step_var) = step_field(
|
let (step_field, step_var) = step_field(
|
||||||
env,
|
env,
|
||||||
fields,
|
fields,
|
||||||
|
@ -120,7 +120,7 @@ pub(crate) fn decoder(
|
||||||
|
|
||||||
env.unify(decode_record_var, this_decode_record_var);
|
env.unify(decode_record_var, this_decode_record_var);
|
||||||
|
|
||||||
// Decode.record initialState stepField finalizer
|
// Decode.record initial_state step_field finalizer
|
||||||
let call_decode_record = Expr::Call(
|
let call_decode_record = Expr::Call(
|
||||||
Box::new((
|
Box::new((
|
||||||
this_decode_record_var,
|
this_decode_record_var,
|
||||||
|
@ -161,13 +161,13 @@ pub(crate) fn decoder(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Example:
|
// Example:
|
||||||
// stepField = \state, field ->
|
// step_field = \state, field ->
|
||||||
// when field is
|
// when field is
|
||||||
// "first" ->
|
// "first" ->
|
||||||
// Keep (Decode.custom \bytes, fmt ->
|
// Keep (Decode.custom \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
|
||||||
// # due to checks for polymorphic expressions, and `rec` would be polymorphic.
|
// # due to checks for polymorphic expressions, and `rec` would be polymorphic.
|
||||||
// when Decode.decodeWith bytes Decode.decoder fmt is
|
// when Decode.decode_with bytes Decode.decoder fmt is
|
||||||
// rec ->
|
// rec ->
|
||||||
// {
|
// {
|
||||||
// rest: rec.rest,
|
// rest: rec.rest,
|
||||||
|
@ -178,7 +178,7 @@ pub(crate) fn decoder(
|
||||||
//
|
//
|
||||||
// "second" ->
|
// "second" ->
|
||||||
// Keep (Decode.custom \bytes, fmt ->
|
// Keep (Decode.custom \bytes, fmt ->
|
||||||
// when Decode.decodeWith bytes Decode.decoder fmt is
|
// when Decode.decode_with bytes Decode.decoder fmt is
|
||||||
// rec ->
|
// rec ->
|
||||||
// {
|
// {
|
||||||
// rest: rec.rest,
|
// rest: rec.rest,
|
||||||
|
@ -196,7 +196,7 @@ pub(super) fn step_field(
|
||||||
state_record_var: Variable,
|
state_record_var: Variable,
|
||||||
decode_err_var: Variable,
|
decode_err_var: Variable,
|
||||||
) -> (Expr, Variable) {
|
) -> (Expr, Variable) {
|
||||||
let state_arg_symbol = env.new_symbol("stateRecord");
|
let state_arg_symbol = env.new_symbol("state_record");
|
||||||
let field_arg_symbol = env.new_symbol("field");
|
let field_arg_symbol = env.new_symbol("field");
|
||||||
|
|
||||||
// +1 because of the default branch.
|
// +1 because of the default branch.
|
||||||
|
@ -228,7 +228,7 @@ pub(super) fn step_field(
|
||||||
// Keep (Decode.custom \bytes, fmt ->
|
// Keep (Decode.custom \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
|
||||||
// # due to checks for polymorphic expressions, and `rec` would be polymorphic.
|
// # due to checks for polymorphic expressions, and `rec` would be polymorphic.
|
||||||
// when Decode.decodeWith bytes Decode.decoder fmt is
|
// when Decode.decode_with bytes Decode.decoder fmt is
|
||||||
// rec ->
|
// rec ->
|
||||||
// {
|
// {
|
||||||
// rest: rec.rest,
|
// rest: rec.rest,
|
||||||
|
@ -254,7 +254,7 @@ pub(super) fn step_field(
|
||||||
|
|
||||||
let keep = {
|
let keep = {
|
||||||
// Keep (Decode.custom \bytes, fmt ->
|
// Keep (Decode.custom \bytes, fmt ->
|
||||||
// when Decode.decodeWith bytes Decode.decoder fmt is
|
// when Decode.decode_with bytes Decode.decoder fmt is
|
||||||
// rec ->
|
// rec ->
|
||||||
// {
|
// {
|
||||||
// rest: rec.rest,
|
// rest: rec.rest,
|
||||||
|
@ -274,7 +274,7 @@ pub(super) fn step_field(
|
||||||
let branch = {
|
let branch = {
|
||||||
// "first" ->
|
// "first" ->
|
||||||
// Keep (Decode.custom \bytes, fmt ->
|
// Keep (Decode.custom \bytes, fmt ->
|
||||||
// when Decode.decodeWith bytes Decode.decoder fmt is
|
// when Decode.decode_with bytes Decode.decoder fmt is
|
||||||
// rec ->
|
// rec ->
|
||||||
// {
|
// {
|
||||||
// rest: rec.rest,
|
// rest: rec.rest,
|
||||||
|
@ -326,7 +326,7 @@ pub(super) fn step_field(
|
||||||
exhaustive: ExhaustiveMark::known_exhaustive(),
|
exhaustive: ExhaustiveMark::known_exhaustive(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let step_field_closure = env.new_symbol("stepField");
|
let step_field_closure = env.new_symbol("step_field");
|
||||||
let function_type = env.subs.fresh_unnamed_flex_var();
|
let function_type = env.subs.fresh_unnamed_flex_var();
|
||||||
let closure_type = {
|
let closure_type = {
|
||||||
let lambda_set = LambdaSet {
|
let lambda_set = LambdaSet {
|
||||||
|
@ -395,7 +395,7 @@ struct DecodingFieldArgs {
|
||||||
/// Decode.custom \bytes, fmt ->
|
/// Decode.custom \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
|
||||||
/// # due to checks for polymorphic expressions, and `rec` would be polymorphic.
|
/// # due to checks for polymorphic expressions, and `rec` would be polymorphic.
|
||||||
/// when Decode.decodeWith bytes Decode.decoder fmt is
|
/// when Decode.decode_with bytes Decode.decoder fmt is
|
||||||
/// rec ->
|
/// rec ->
|
||||||
/// {
|
/// {
|
||||||
/// rest: rec.rest,
|
/// rest: rec.rest,
|
||||||
|
@ -444,7 +444,7 @@ fn custom_decoder(env: &mut Env<'_>, args: DecodingFieldArgs) -> (Variable, Expr
|
||||||
|
|
||||||
/// ```roc
|
/// ```roc
|
||||||
/// \bytes, fmt ->
|
/// \bytes, fmt ->
|
||||||
/// when Decode.decodeWith bytes Decode.decoder fmt is
|
/// when Decode.decode_with bytes Decode.decoder fmt is
|
||||||
/// rec ->
|
/// rec ->
|
||||||
/// {
|
/// {
|
||||||
/// rest: rec.rest,
|
/// rest: rec.rest,
|
||||||
|
@ -467,7 +467,7 @@ fn custom_decoder_lambda(env: &mut Env<'_>, args: DecodingFieldArgs) -> (Variabl
|
||||||
let custom_callback_ret_var;
|
let custom_callback_ret_var;
|
||||||
|
|
||||||
// \bytes, fmt ->
|
// \bytes, fmt ->
|
||||||
// when Decode.decodeWith bytes Decode.decoder fmt is
|
// when Decode.decode_with bytes Decode.decoder fmt is
|
||||||
// rec ->
|
// rec ->
|
||||||
// {
|
// {
|
||||||
// rest: rec.rest,
|
// rest: rec.rest,
|
||||||
|
@ -507,7 +507,7 @@ fn custom_decoder_lambda(env: &mut Env<'_>, args: DecodingFieldArgs) -> (Variabl
|
||||||
synth_var(env.subs, Content::Structure(flat_type))
|
synth_var(env.subs, Content::Structure(flat_type))
|
||||||
};
|
};
|
||||||
|
|
||||||
// Decode.decodeWith bytes Decode.decoder fmt
|
// Decode.decode_with bytes Decode.decoder fmt
|
||||||
let (condition_expr, rec_var, rec_dot_result) = decode_with(
|
let (condition_expr, rec_var, rec_dot_result) = decode_with(
|
||||||
env,
|
env,
|
||||||
field_var,
|
field_var,
|
||||||
|
@ -519,7 +519,7 @@ fn custom_decoder_lambda(env: &mut Env<'_>, args: DecodingFieldArgs) -> (Variabl
|
||||||
|
|
||||||
// # Uses a single-branch `when` because `let` is more expensive to monomorphize
|
// # Uses a single-branch `when` because `let` is more expensive to monomorphize
|
||||||
// # due to checks for polymorphic expressions, and `rec` would be polymorphic.
|
// # due to checks for polymorphic expressions, and `rec` would be polymorphic.
|
||||||
// when Decode.decodeWith bytes Decode.decoder fmt is
|
// when Decode.decode_with bytes Decode.decoder fmt is
|
||||||
// rec ->
|
// rec ->
|
||||||
// {
|
// {
|
||||||
// rest: rec.rest,
|
// rest: rec.rest,
|
||||||
|
@ -556,7 +556,7 @@ fn custom_decoder_lambda(env: &mut Env<'_>, args: DecodingFieldArgs) -> (Variabl
|
||||||
redundant: RedundantMark::known_non_redundant(),
|
redundant: RedundantMark::known_non_redundant(),
|
||||||
};
|
};
|
||||||
|
|
||||||
// when Decode.decodeWith bytes Decode.decoder fmt is
|
// when Decode.decode_with bytes Decode.decoder fmt is
|
||||||
// ...
|
// ...
|
||||||
Expr::When {
|
Expr::When {
|
||||||
loc_cond: Box::new(Loc::at_zero(condition_expr)),
|
loc_cond: Box::new(Loc::at_zero(condition_expr)),
|
||||||
|
@ -806,7 +806,7 @@ fn state_record_update(
|
||||||
/// when
|
/// when
|
||||||
/// when rec.f0 is
|
/// when rec.f0 is
|
||||||
/// Err NoField ->
|
/// Err NoField ->
|
||||||
/// when Decode.decodeWith [] Decode.decoder fmt is
|
/// when Decode.decode_with [] Decode.decoder fmt is
|
||||||
/// rec2 -> rec2.result
|
/// rec2 -> rec2.result
|
||||||
/// Ok a -> Ok a
|
/// Ok a -> Ok a
|
||||||
/// is
|
/// is
|
||||||
|
@ -814,7 +814,7 @@ fn state_record_update(
|
||||||
/// when
|
/// when
|
||||||
/// when rec.f1 is
|
/// when rec.f1 is
|
||||||
/// Err NoField ->
|
/// Err NoField ->
|
||||||
/// when Decode.decodeWith [] Decode.decoder fmt is
|
/// when Decode.decode_with [] Decode.decoder fmt is
|
||||||
/// rec2 -> rec2.result
|
/// rec2 -> rec2.result
|
||||||
/// Ok a -> Ok a
|
/// Ok a -> Ok a
|
||||||
/// is
|
/// is
|
||||||
|
@ -828,7 +828,7 @@ pub(super) fn finalizer(
|
||||||
field_vars: &[Variable],
|
field_vars: &[Variable],
|
||||||
result_field_vars: &[Variable],
|
result_field_vars: &[Variable],
|
||||||
) -> (Expr, Variable, Variable) {
|
) -> (Expr, Variable, Variable) {
|
||||||
let state_arg_symbol = env.new_symbol("stateRecord");
|
let state_arg_symbol = env.new_symbol("state_record");
|
||||||
|
|
||||||
let mut fields_map = SendMap::default();
|
let mut fields_map = SendMap::default();
|
||||||
let mut pattern_symbols = Vec::with_capacity(fields.len());
|
let mut pattern_symbols = Vec::with_capacity(fields.len());
|
||||||
|
@ -909,7 +909,7 @@ pub(super) fn finalizer(
|
||||||
// [Ok field_var, Err DecodeError]
|
// [Ok field_var, Err DecodeError]
|
||||||
// when rec.f0 is
|
// when rec.f0 is
|
||||||
// Err _ ->
|
// Err _ ->
|
||||||
// when Decode.decodeWith [] Decode.decoder fmt is
|
// when Decode.decode_with [] Decode.decoder fmt is
|
||||||
// rec2 -> rec2.result
|
// rec2 -> rec2.result
|
||||||
// Ok a -> Ok a
|
// Ok a -> Ok a
|
||||||
let (attempt_empty_decode_expr, attempt_empty_decode_var) = attempt_empty_decode_if_missing(
|
let (attempt_empty_decode_expr, attempt_empty_decode_var) = attempt_empty_decode_if_missing(
|
||||||
|
@ -968,11 +968,11 @@ pub(super) fn finalizer(
|
||||||
};
|
};
|
||||||
|
|
||||||
// when
|
// when
|
||||||
// when stateRecord.f0 is
|
// when state_record.f0 is
|
||||||
// Ok f0 -> Ok f0
|
// Ok f0 -> Ok f0
|
||||||
// _ ->
|
// _ ->
|
||||||
// when Decode.decodeWith [] Decode.decoder fmt is
|
// when Decode.decode_with [] Decode.decoder fmt is
|
||||||
// decRec -> decRec.result
|
// dec_rec -> dec_rec.result
|
||||||
// is
|
// is
|
||||||
// _-> TooShort
|
// _-> TooShort
|
||||||
// Ok x -> expr
|
// Ok x -> expr
|
||||||
|
@ -1037,8 +1037,8 @@ pub(super) fn finalizer(
|
||||||
/// ```roc
|
/// ```roc
|
||||||
/// when rec.f0 is
|
/// when rec.f0 is
|
||||||
/// Err _ ->
|
/// Err _ ->
|
||||||
/// when Decode.decodeWith [] Decode.decoder fmt is
|
/// when Decode.decode_with [] Decode.decoder fmt is
|
||||||
/// decRec-> decRec.result
|
/// dec_rec-> dec_rec.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,
|
||||||
|
@ -1070,7 +1070,7 @@ fn attempt_empty_decode_if_missing(
|
||||||
decode_err_var,
|
decode_err_var,
|
||||||
);
|
);
|
||||||
let decode_when = {
|
let decode_when = {
|
||||||
let decoder_rec_symb = env.new_symbol("decRec");
|
let decoder_rec_symb = env.new_symbol("dec_rec");
|
||||||
|
|
||||||
let branch = WhenBranch {
|
let branch = WhenBranch {
|
||||||
patterns: vec![WhenBranchPattern {
|
patterns: vec![WhenBranchPattern {
|
||||||
|
@ -1088,7 +1088,7 @@ fn attempt_empty_decode_if_missing(
|
||||||
redundant: RedundantMark::known_non_redundant(),
|
redundant: RedundantMark::known_non_redundant(),
|
||||||
};
|
};
|
||||||
|
|
||||||
// when Decode.decodeWith bytes Decode.decoder fmt is
|
// when Decode.decode_with bytes Decode.decoder fmt is
|
||||||
Expr::When {
|
Expr::When {
|
||||||
loc_cond: Box::new(Loc::at_zero(decode_expr)),
|
loc_cond: Box::new(Loc::at_zero(decode_expr)),
|
||||||
cond_var: rec_result,
|
cond_var: rec_result,
|
||||||
|
@ -1112,7 +1112,7 @@ fn attempt_empty_decode_if_missing(
|
||||||
// Example: `Ok x -> Ok x`
|
// Example: `Ok x -> Ok x`
|
||||||
let ok_branch = ok_to_ok_branch(result_field_var, rec_dot_result, field_var, symbol, env);
|
let ok_branch = ok_to_ok_branch(result_field_var, rec_dot_result, field_var, symbol, env);
|
||||||
|
|
||||||
// Example: `Err NoField -> when decodeWith [] decoder #Derived.fmt is`
|
// Example: `Err NoField -> when decode_with [] decoder #Derived.fmt is`
|
||||||
let no_field_label = "NoField";
|
let no_field_label = "NoField";
|
||||||
let union_tags = UnionTags::tag_without_arguments(env.subs, no_field_label.into());
|
let union_tags = UnionTags::tag_without_arguments(env.subs, no_field_label.into());
|
||||||
let no_field_var = synth_var(
|
let no_field_var = synth_var(
|
||||||
|
@ -1159,8 +1159,8 @@ fn attempt_empty_decode_if_missing(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Example:
|
// Example:
|
||||||
// initialState : {first: Result a [NoField], second: Result b [NoField]}
|
// initial_state : {first: Result a [NoField], second: Result b [NoField]}
|
||||||
// initialState = {first: Err NoField, second: Err NoField}
|
// initial_state = {first: Err NoField, second: Err NoField}
|
||||||
fn initial_state(
|
fn initial_state(
|
||||||
env: &mut Env<'_>,
|
env: &mut Env<'_>,
|
||||||
field_names: &[Lowercase],
|
field_names: &[Lowercase],
|
||||||
|
@ -1237,16 +1237,16 @@ fn initial_state(
|
||||||
}
|
}
|
||||||
|
|
||||||
struct DecodeWithVars {
|
struct DecodeWithVars {
|
||||||
/// Type of the record returned by `Decode.decodeWith`
|
/// Type of the record returned by `Decode.decode_with`
|
||||||
/// `rec : { rest: List U8, result: (typeof rec.result) }`
|
/// `rec : { rest: List U8, result: (typeof rec.result) }`
|
||||||
rec_var: Variable,
|
rec_var: Variable,
|
||||||
/// type of the result field of the record returned by `Decode.decodeWith`
|
/// type of the result field of the record returned by `Decode.decode_with`
|
||||||
rec_dot_result: Variable,
|
rec_dot_result: Variable,
|
||||||
/// type of `Decode.decoder`
|
/// type of `Decode.decoder`
|
||||||
decoder_var: Variable,
|
decoder_var: Variable,
|
||||||
/// lambda set for `Decode.decodeWith` call
|
/// lambda set for `Decode.decode_with` call
|
||||||
lambda_set_var: Variable,
|
lambda_set_var: Variable,
|
||||||
/// specialised type of this specific call to `Decode.decodeWith`
|
/// specialised type of this specific call to `Decode.decode_with`
|
||||||
this_decode_with_var: Variable,
|
this_decode_with_var: Variable,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1314,9 +1314,9 @@ fn make_decode_with_vars(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `Decode.decodeWith bytes Decode.decoder fmt`
|
/// `Decode.decode_with bytes Decode.decoder fmt`
|
||||||
///
|
///
|
||||||
/// Generates a call to decodeWith, returns that expression,
|
/// Generates a call to decode_with, returns that expression,
|
||||||
/// the variable of the return value `{ rest: List U8, result: (typeof rec.result) }`,
|
/// the variable of the return value `{ rest: List U8, result: (typeof rec.result) }`,
|
||||||
/// and the variable of the result field of the return value `[Ok field_var, Err DecodeError]`.
|
/// and the variable of the result field of the return value `[Ok field_var, Err DecodeError]`.
|
||||||
pub(super) fn decode_with(
|
pub(super) fn decode_with(
|
||||||
|
|
|
@ -109,7 +109,7 @@ pub(crate) fn derive_to_inspector(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_inspector_list(env: &mut Env<'_>, fn_name: Symbol) -> (Expr, Variable) {
|
fn to_inspector_list(env: &mut Env<'_>, fn_name: Symbol) -> (Expr, Variable) {
|
||||||
// Build \lst -> list, List.walk, (\elem -> Inspect.toInspector elem)
|
// Build \lst -> list, List.walk, (\elem -> Inspect.to_inspector elem)
|
||||||
|
|
||||||
use Expr::*;
|
use Expr::*;
|
||||||
|
|
||||||
|
@ -124,7 +124,7 @@ fn to_inspector_list(env: &mut Env<'_>, fn_name: Symbol) -> (Expr, Variable) {
|
||||||
Content::Structure(FlatType::Apply(Symbol::LIST_LIST, elem_var_slice)),
|
Content::Structure(FlatType::Apply(Symbol::LIST_LIST, elem_var_slice)),
|
||||||
);
|
);
|
||||||
|
|
||||||
// build `toInspector elem` type
|
// build `to_inspector elem` type
|
||||||
// val -[uls]-> Inspector fmt where fmt implements InspectorFormatter
|
// val -[uls]-> Inspector fmt where fmt implements InspectorFormatter
|
||||||
let to_inspector_fn_var = env.import_builtin_symbol_var(Symbol::INSPECT_TO_INSPECTOR);
|
let to_inspector_fn_var = env.import_builtin_symbol_var(Symbol::INSPECT_TO_INSPECTOR);
|
||||||
|
|
||||||
|
@ -145,7 +145,7 @@ fn to_inspector_list(env: &mut Env<'_>, fn_name: Symbol) -> (Expr, Variable) {
|
||||||
// ~ elem -[clos]-> t1
|
// ~ elem -[clos]-> t1
|
||||||
env.unify(to_inspector_fn_var, elem_to_inspector_fn_var);
|
env.unify(to_inspector_fn_var, elem_to_inspector_fn_var);
|
||||||
|
|
||||||
// toInspector : (typeof rcd.a) -[clos]-> Inspector fmt where fmt implements InspectorFormatter
|
// to_inspector : (typeof rcd.a) -[clos]-> Inspector fmt where fmt implements InspectorFormatter
|
||||||
let to_inspector_var =
|
let to_inspector_var =
|
||||||
AbilityMember(Symbol::INSPECT_TO_INSPECTOR, None, elem_to_inspector_fn_var);
|
AbilityMember(Symbol::INSPECT_TO_INSPECTOR, None, elem_to_inspector_fn_var);
|
||||||
let to_inspector_fn = Box::new((
|
let to_inspector_fn = Box::new((
|
||||||
|
@ -156,14 +156,14 @@ fn to_inspector_list(env: &mut Env<'_>, fn_name: Symbol) -> (Expr, Variable) {
|
||||||
Variable::PURE,
|
Variable::PURE,
|
||||||
));
|
));
|
||||||
|
|
||||||
// toInspector elem
|
// to_inspector elem
|
||||||
let to_inspector_call = Call(
|
let to_inspector_call = Call(
|
||||||
to_inspector_fn,
|
to_inspector_fn,
|
||||||
vec![(elem_var, Loc::at_zero(Var(elem_sym, elem_var)))],
|
vec![(elem_var, Loc::at_zero(Var(elem_sym, elem_var)))],
|
||||||
CalledVia::Space,
|
CalledVia::Space,
|
||||||
);
|
);
|
||||||
|
|
||||||
// elem -[to_elem_inspector]-> toInspector elem
|
// elem -[to_elem_inspector]-> to_inspector elem
|
||||||
let to_elem_inspector_sym = env.new_symbol("to_elem_inspector");
|
let to_elem_inspector_sym = env.new_symbol("to_elem_inspector");
|
||||||
|
|
||||||
// Create fn_var for ambient capture; we fix it up below.
|
// Create fn_var for ambient capture; we fix it up below.
|
||||||
|
@ -181,7 +181,7 @@ fn to_inspector_list(env: &mut Env<'_>, fn_name: Symbol) -> (Expr, Variable) {
|
||||||
ambient_function: to_elem_inspector_fn_var,
|
ambient_function: to_elem_inspector_fn_var,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
// elem -[to_elem_inspector]-> toInspector elem
|
// elem -[to_elem_inspector]-> to_inspector elem
|
||||||
env.subs.set_content(
|
env.subs.set_content(
|
||||||
to_elem_inspector_fn_var,
|
to_elem_inspector_fn_var,
|
||||||
Content::Structure(FlatType::Func(
|
Content::Structure(FlatType::Func(
|
||||||
|
@ -192,7 +192,7 @@ fn to_inspector_list(env: &mut Env<'_>, fn_name: Symbol) -> (Expr, Variable) {
|
||||||
)),
|
)),
|
||||||
);
|
);
|
||||||
|
|
||||||
// \elem -> toInspector elem
|
// \elem -> to_inspector elem
|
||||||
let to_elem_inspector = Closure(ClosureData {
|
let to_elem_inspector = Closure(ClosureData {
|
||||||
function_type: to_elem_inspector_fn_var,
|
function_type: to_elem_inspector_fn_var,
|
||||||
closure_type: to_elem_inspector_lset,
|
closure_type: to_elem_inspector_lset,
|
||||||
|
@ -210,7 +210,7 @@ fn to_inspector_list(env: &mut Env<'_>, fn_name: Symbol) -> (Expr, Variable) {
|
||||||
loc_body: Box::new(Loc::at_zero(to_inspector_call)),
|
loc_body: Box::new(Loc::at_zero(to_inspector_call)),
|
||||||
});
|
});
|
||||||
|
|
||||||
// build `Inspect.list lst (\elem -> Inspect.toInspector elem)` type
|
// build `Inspect.list lst (\elem -> Inspect.to_inspector elem)` type
|
||||||
// List e, (e -> Inspector fmt) -[uls]-> Inspector fmt where fmt implements InspectorFormatter
|
// List e, (e -> Inspector fmt) -[uls]-> Inspector fmt where fmt implements InspectorFormatter
|
||||||
let inspect_list_fn_var = env.import_builtin_symbol_var(Symbol::INSPECT_LIST);
|
let inspect_list_fn_var = env.import_builtin_symbol_var(Symbol::INSPECT_LIST);
|
||||||
|
|
||||||
|
@ -268,7 +268,7 @@ fn to_inspector_list(env: &mut Env<'_>, fn_name: Symbol) -> (Expr, Variable) {
|
||||||
list_var,
|
list_var,
|
||||||
);
|
);
|
||||||
|
|
||||||
// \lst -> Inspect.list lst (\elem -> Inspect.toInspector elem)
|
// \lst -> Inspect.list lst (\elem -> Inspect.to_inspector elem)
|
||||||
// Create fn_var for ambient capture; we fix it up below.
|
// Create fn_var for ambient capture; we fix it up below.
|
||||||
let fn_var = synth_var(env.subs, Content::Error);
|
let fn_var = synth_var(env.subs, Content::Error);
|
||||||
|
|
||||||
|
@ -295,7 +295,7 @@ fn to_inspector_list(env: &mut Env<'_>, fn_name: Symbol) -> (Expr, Variable) {
|
||||||
)),
|
)),
|
||||||
);
|
);
|
||||||
|
|
||||||
// \lst -[fn_name]-> Inspect.list lst (\elem -> Inspect.toInspector elem)
|
// \lst -[fn_name]-> Inspect.list lst (\elem -> Inspect.to_inspector elem)
|
||||||
let clos = Closure(ClosureData {
|
let clos = Closure(ClosureData {
|
||||||
function_type: fn_var,
|
function_type: fn_var,
|
||||||
closure_type: fn_clos_var,
|
closure_type: fn_clos_var,
|
||||||
|
@ -325,8 +325,8 @@ fn to_inspector_record(
|
||||||
// Suppose rcd = { a: t1, b: t2 }. Build
|
// Suppose rcd = { a: t1, b: t2 }. Build
|
||||||
//
|
//
|
||||||
// \rcd -> Inspect.record [
|
// \rcd -> Inspect.record [
|
||||||
// { key: "a", value: Inspect.toInspector rcd.a },
|
// { key: "a", value: Inspect.to_inspector rcd.a },
|
||||||
// { key: "b", value: Inspect.toInspector rcd.b },
|
// { key: "b", value: Inspect.to_inspector rcd.b },
|
||||||
// ]
|
// ]
|
||||||
|
|
||||||
let rcd_sym = env.new_symbol("rcd");
|
let rcd_sym = env.new_symbol("rcd");
|
||||||
|
@ -360,7 +360,7 @@ fn to_inspector_record(
|
||||||
field: field_name,
|
field: field_name,
|
||||||
};
|
};
|
||||||
|
|
||||||
// build `toInspector rcd.a` type
|
// build `to_inspector rcd.a` type
|
||||||
// val -[uls]-> Inspector fmt where fmt implements InspectorFormatter
|
// val -[uls]-> Inspector fmt where fmt implements InspectorFormatter
|
||||||
let to_inspector_fn_var = env.import_builtin_symbol_var(Symbol::INSPECT_TO_INSPECTOR);
|
let to_inspector_fn_var = env.import_builtin_symbol_var(Symbol::INSPECT_TO_INSPECTOR);
|
||||||
|
|
||||||
|
@ -381,7 +381,7 @@ fn to_inspector_record(
|
||||||
// ~ (typeof rcd.a) -[clos]-> t1
|
// ~ (typeof rcd.a) -[clos]-> t1
|
||||||
env.unify(to_inspector_fn_var, this_to_inspector_fn_var);
|
env.unify(to_inspector_fn_var, this_to_inspector_fn_var);
|
||||||
|
|
||||||
// toInspector : (typeof rcd.a) -[clos]-> Inspector fmt where fmt implements InspectorFormatter
|
// to_inspector : (typeof rcd.a) -[clos]-> Inspector fmt where fmt implements InspectorFormatter
|
||||||
let to_inspector_var =
|
let to_inspector_var =
|
||||||
AbilityMember(Symbol::INSPECT_TO_INSPECTOR, None, to_inspector_fn_var);
|
AbilityMember(Symbol::INSPECT_TO_INSPECTOR, None, to_inspector_fn_var);
|
||||||
let to_inspector_fn = Box::new((
|
let to_inspector_fn = Box::new((
|
||||||
|
@ -392,21 +392,21 @@ fn to_inspector_record(
|
||||||
Variable::PURE,
|
Variable::PURE,
|
||||||
));
|
));
|
||||||
|
|
||||||
// toInspector rcd.a
|
// to_inspector rcd.a
|
||||||
let to_inspector_call = Call(
|
let to_inspector_call = Call(
|
||||||
to_inspector_fn,
|
to_inspector_fn,
|
||||||
vec![(field_var, Loc::at_zero(field_access))],
|
vec![(field_var, Loc::at_zero(field_access))],
|
||||||
CalledVia::Space,
|
CalledVia::Space,
|
||||||
);
|
);
|
||||||
|
|
||||||
// value: toInspector rcd.a
|
// value: to_inspector rcd.a
|
||||||
let value_field = Field {
|
let value_field = Field {
|
||||||
var: inspector_var,
|
var: inspector_var,
|
||||||
region: Region::zero(),
|
region: Region::zero(),
|
||||||
loc_expr: Box::new(Loc::at_zero(to_inspector_call)),
|
loc_expr: Box::new(Loc::at_zero(to_inspector_call)),
|
||||||
};
|
};
|
||||||
|
|
||||||
// { key: "a", value: toInspector rcd.a }
|
// { key: "a", value: to_inspector rcd.a }
|
||||||
let mut kv = SendMap::default();
|
let mut kv = SendMap::default();
|
||||||
kv.insert("key".into(), key_field);
|
kv.insert("key".into(), key_field);
|
||||||
kv.insert("value".into(), value_field);
|
kv.insert("value".into(), value_field);
|
||||||
|
@ -542,8 +542,8 @@ fn to_inspector_tuple(
|
||||||
// Suppose tup = (t1, t2). Build
|
// Suppose tup = (t1, t2). Build
|
||||||
//
|
//
|
||||||
// \tup -> Inspect.tuple [
|
// \tup -> Inspect.tuple [
|
||||||
// Inspect.toInspector tup.0,
|
// Inspect.to_inspector tup.0,
|
||||||
// Inspect.toInspector tup.1,
|
// Inspect.to_inspector tup.1,
|
||||||
// ]
|
// ]
|
||||||
|
|
||||||
let tup_sym = env.new_symbol("tup");
|
let tup_sym = env.new_symbol("tup");
|
||||||
|
@ -570,7 +570,7 @@ fn to_inspector_tuple(
|
||||||
index,
|
index,
|
||||||
};
|
};
|
||||||
|
|
||||||
// build `toInspector tup.0` type
|
// build `to_inspector tup.0` type
|
||||||
// val -[uls]-> Inspector fmt where fmt implements InspectorFormatter
|
// val -[uls]-> Inspector fmt where fmt implements InspectorFormatter
|
||||||
let to_inspector_fn_var = env.import_builtin_symbol_var(Symbol::INSPECT_TO_INSPECTOR);
|
let to_inspector_fn_var = env.import_builtin_symbol_var(Symbol::INSPECT_TO_INSPECTOR);
|
||||||
|
|
||||||
|
@ -591,7 +591,7 @@ fn to_inspector_tuple(
|
||||||
// ~ (typeof tup.0) -[clos]-> t1
|
// ~ (typeof tup.0) -[clos]-> t1
|
||||||
env.unify(to_inspector_fn_var, this_to_inspector_fn_var);
|
env.unify(to_inspector_fn_var, this_to_inspector_fn_var);
|
||||||
|
|
||||||
// toInspector : (typeof tup.0) -[clos]-> Inspector fmt where fmt implements InspectorFormatter
|
// to_inspector : (typeof tup.0) -[clos]-> Inspector fmt where fmt implements InspectorFormatter
|
||||||
let to_inspector_var =
|
let to_inspector_var =
|
||||||
AbilityMember(Symbol::INSPECT_TO_INSPECTOR, None, to_inspector_fn_var);
|
AbilityMember(Symbol::INSPECT_TO_INSPECTOR, None, to_inspector_fn_var);
|
||||||
let to_inspector_fn = Box::new((
|
let to_inspector_fn = Box::new((
|
||||||
|
@ -602,7 +602,7 @@ fn to_inspector_tuple(
|
||||||
Variable::PURE,
|
Variable::PURE,
|
||||||
));
|
));
|
||||||
|
|
||||||
// toInspector tup.0
|
// to_inspector tup.0
|
||||||
let to_inspector_call = Call(
|
let to_inspector_call = Call(
|
||||||
to_inspector_fn,
|
to_inspector_fn,
|
||||||
vec![(elem_var, Loc::at_zero(tuple_access))],
|
vec![(elem_var, Loc::at_zero(tuple_access))],
|
||||||
|
@ -616,7 +616,7 @@ fn to_inspector_tuple(
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
// typeof [ toInspector tup.0, toInspector tup.1 ]
|
// typeof [ to_inspector tup.0, to_inspector tup.1 ]
|
||||||
let whole_inspector_in_list_var_slice =
|
let whole_inspector_in_list_var_slice =
|
||||||
env.subs.insert_into_vars(once(whole_inspector_in_list_var));
|
env.subs.insert_into_vars(once(whole_inspector_in_list_var));
|
||||||
let elem_inspectors_list_var = synth_var(
|
let elem_inspectors_list_var = synth_var(
|
||||||
|
@ -627,13 +627,13 @@ fn to_inspector_tuple(
|
||||||
)),
|
)),
|
||||||
);
|
);
|
||||||
|
|
||||||
// [ toInspector tup.0, toInspector tup.1 ]
|
// [ to_inspector tup.0, to_inspector tup.1 ]
|
||||||
let elem_inspectors_list = List {
|
let elem_inspectors_list = List {
|
||||||
elem_var: whole_inspector_in_list_var,
|
elem_var: whole_inspector_in_list_var,
|
||||||
loc_elems: elem_inspectors_list,
|
loc_elems: elem_inspectors_list,
|
||||||
};
|
};
|
||||||
|
|
||||||
// build `Inspect.tuple [ toInspector tup.0, toInspector tup.1 ]` type
|
// build `Inspect.tuple [ to_inspector tup.0, to_inspector tup.1 ]` type
|
||||||
// List (Inspector fmt) -[uls]-> Inspector fmt where fmt implements InspectorFormatter
|
// List (Inspector fmt) -[uls]-> Inspector fmt where fmt implements InspectorFormatter
|
||||||
let inspect_tuple_fn_var = env.import_builtin_symbol_var(Symbol::INSPECT_TUPLE);
|
let inspect_tuple_fn_var = env.import_builtin_symbol_var(Symbol::INSPECT_TUPLE);
|
||||||
|
|
||||||
|
@ -732,8 +732,8 @@ fn to_inspector_tag_union(
|
||||||
// Suppose tag = [ A t1 t2, B t3 ]. Build
|
// Suppose tag = [ A t1 t2, B t3 ]. Build
|
||||||
//
|
//
|
||||||
// \tag -> when tag is
|
// \tag -> when tag is
|
||||||
// A v1 v2 -> Inspect.tag "A" [ Inspect.toInspector v1, Inspect.toInspector v2 ]
|
// A v1 v2 -> Inspect.tag "A" [ Inspect.to_inspector v1, Inspect.to_inspector v2 ]
|
||||||
// B v3 -> Inspect.tag "B" [ Inspect.toInspector v3 ]
|
// B v3 -> Inspect.tag "B" [ Inspect.to_inspector v3 ]
|
||||||
|
|
||||||
let tag_sym = env.new_symbol("tag");
|
let tag_sym = env.new_symbol("tag");
|
||||||
let whole_tag_inspectors_var = env.subs.fresh_unnamed_flex_var(); // type of the Inspect.tag ... calls in the branch bodies
|
let whole_tag_inspectors_var = env.subs.fresh_unnamed_flex_var(); // type of the Inspect.tag ... calls in the branch bodies
|
||||||
|
@ -769,13 +769,13 @@ fn to_inspector_tag_union(
|
||||||
degenerate: false,
|
degenerate: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
// whole type of the elements in [ Inspect.toInspector v1, Inspect.toInspector v2 ]
|
// whole type of the elements in [ Inspect.to_inspector v1, Inspect.to_inspector v2 ]
|
||||||
let whole_payload_inspectors_var = env.subs.fresh_unnamed_flex_var();
|
let whole_payload_inspectors_var = env.subs.fresh_unnamed_flex_var();
|
||||||
// [ Inspect.toInspector v1, Inspect.toInspector v2 ]
|
// [ Inspect.to_inspector v1, Inspect.to_inspector v2 ]
|
||||||
let payload_to_inspectors = (payload_syms.iter())
|
let payload_to_inspectors = (payload_syms.iter())
|
||||||
.zip(payload_vars.iter())
|
.zip(payload_vars.iter())
|
||||||
.map(|(&sym, &sym_var)| {
|
.map(|(&sym, &sym_var)| {
|
||||||
// build `toInspector v1` type
|
// build `to_inspector v1` type
|
||||||
// expected: val -[uls]-> Inspector fmt where fmt implements InspectorFormatter
|
// expected: val -[uls]-> Inspector fmt where fmt implements InspectorFormatter
|
||||||
let to_inspector_fn_var =
|
let to_inspector_fn_var =
|
||||||
env.import_builtin_symbol_var(Symbol::INSPECT_TO_INSPECTOR);
|
env.import_builtin_symbol_var(Symbol::INSPECT_TO_INSPECTOR);
|
||||||
|
@ -798,7 +798,7 @@ fn to_inspector_tag_union(
|
||||||
// ~ t1 -[clos]-> t'
|
// ~ t1 -[clos]-> t'
|
||||||
env.unify(to_inspector_fn_var, this_to_inspector_fn_var);
|
env.unify(to_inspector_fn_var, this_to_inspector_fn_var);
|
||||||
|
|
||||||
// toInspector : t1 -[clos]-> Inspector fmt where fmt implements InspectorFormatter
|
// to_inspector : t1 -[clos]-> Inspector fmt where fmt implements InspectorFormatter
|
||||||
let to_inspector_var =
|
let to_inspector_var =
|
||||||
AbilityMember(Symbol::INSPECT_TO_INSPECTOR, None, this_to_inspector_fn_var);
|
AbilityMember(Symbol::INSPECT_TO_INSPECTOR, None, this_to_inspector_fn_var);
|
||||||
let to_inspector_fn = Box::new((
|
let to_inspector_fn = Box::new((
|
||||||
|
@ -809,7 +809,7 @@ fn to_inspector_tag_union(
|
||||||
Variable::PURE,
|
Variable::PURE,
|
||||||
));
|
));
|
||||||
|
|
||||||
// toInspector rcd.a
|
// to_inspector rcd.a
|
||||||
let to_inspector_call = Call(
|
let to_inspector_call = Call(
|
||||||
to_inspector_fn,
|
to_inspector_fn,
|
||||||
vec![(sym_var, Loc::at_zero(Var(sym, sym_var)))],
|
vec![(sym_var, Loc::at_zero(Var(sym, sym_var)))],
|
||||||
|
@ -823,7 +823,7 @@ fn to_inspector_tag_union(
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
// typeof [ Inspect.toInspector v1, Inspect.toInspector v2 ]
|
// typeof [ Inspect.to_inspector v1, Inspect.to_inspector v2 ]
|
||||||
let whole_inspectors_var_slice =
|
let whole_inspectors_var_slice =
|
||||||
env.subs.insert_into_vars([whole_payload_inspectors_var]);
|
env.subs.insert_into_vars([whole_payload_inspectors_var]);
|
||||||
let payload_inspectors_list_var = synth_var(
|
let payload_inspectors_list_var = synth_var(
|
||||||
|
@ -834,7 +834,7 @@ fn to_inspector_tag_union(
|
||||||
)),
|
)),
|
||||||
);
|
);
|
||||||
|
|
||||||
// [ Inspect.toInspector v1, Inspect.toInspector v2 ]
|
// [ Inspect.to_inspector v1, Inspect.to_inspector v2 ]
|
||||||
let payload_inspectors_list = List {
|
let payload_inspectors_list = List {
|
||||||
elem_var: whole_payload_inspectors_var,
|
elem_var: whole_payload_inspectors_var,
|
||||||
loc_elems: payload_to_inspectors,
|
loc_elems: payload_to_inspectors,
|
||||||
|
@ -874,13 +874,13 @@ fn to_inspector_tag_union(
|
||||||
Variable::PURE,
|
Variable::PURE,
|
||||||
));
|
));
|
||||||
|
|
||||||
// Inspect.tag "A" [ Inspect.toInspector v1, Inspect.toInspector v2 ]
|
// Inspect.tag "A" [ Inspect.to_inspector v1, Inspect.to_inspector v2 ]
|
||||||
let inspect_tag_call = Call(
|
let inspect_tag_call = Call(
|
||||||
inspect_tag_fn,
|
inspect_tag_fn,
|
||||||
vec![
|
vec![
|
||||||
// (Str, "A")
|
// (Str, "A")
|
||||||
(Variable::STR, Loc::at_zero(Str(tag_name.0.as_str().into()))),
|
(Variable::STR, Loc::at_zero(Str(tag_name.0.as_str().into()))),
|
||||||
// (List (Inspector fmt), [ Inspect.toInspector v1, Inspect.toInspector v2 ])
|
// (List (Inspector fmt), [ Inspect.to_inspector v1, Inspect.to_inspector v2 ])
|
||||||
(
|
(
|
||||||
payload_inspectors_list_var,
|
payload_inspectors_list_var,
|
||||||
Loc::at_zero(payload_inspectors_list),
|
Loc::at_zero(payload_inspectors_list),
|
||||||
|
@ -890,7 +890,7 @@ fn to_inspector_tag_union(
|
||||||
);
|
);
|
||||||
|
|
||||||
// NOTE: must be done to unify the lambda sets under `inspector_var`
|
// NOTE: must be done to unify the lambda sets under `inspector_var`
|
||||||
// Inspect.tag "A" [ Inspect.toInspector v1, Inspect.toInspector v2 ] ~ whole_inspectors
|
// Inspect.tag "A" [ Inspect.to_inspector v1, Inspect.to_inspector v2 ] ~ whole_inspectors
|
||||||
env.unify(this_inspector_var, whole_tag_inspectors_var);
|
env.unify(this_inspector_var, whole_tag_inspectors_var);
|
||||||
|
|
||||||
WhenBranch {
|
WhenBranch {
|
||||||
|
@ -903,8 +903,8 @@ fn to_inspector_tag_union(
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
// when tag is
|
// when tag is
|
||||||
// A v1 v2 -> Inspect.tag "A" [ Inspect.toInspector v1, Inspect.toInspector v2 ]
|
// A v1 v2 -> Inspect.tag "A" [ Inspect.to_inspector v1, Inspect.to_inspector v2 ]
|
||||||
// B v3 -> Inspect.tag "B" [ Inspect.toInspector v3 ]
|
// B v3 -> Inspect.tag "B" [ Inspect.to_inspector v3 ]
|
||||||
let when_branches = When {
|
let when_branches = When {
|
||||||
loc_cond: Box::new(Loc::at_zero(Var(tag_sym, tag_union_var))),
|
loc_cond: Box::new(Loc::at_zero(Var(tag_sym, tag_union_var))),
|
||||||
cond_var: tag_union_var,
|
cond_var: tag_union_var,
|
||||||
|
@ -953,8 +953,8 @@ fn to_inspector_tag_union(
|
||||||
// \tag ->
|
// \tag ->
|
||||||
// Inspect.custom \fmt -> Inspect.apply (
|
// Inspect.custom \fmt -> Inspect.apply (
|
||||||
// when tag is
|
// when tag is
|
||||||
// A v1 v2 -> Inspect.tag "A" [ Inspect.toInspector v1, Inspect.toInspector v2 ]
|
// A v1 v2 -> Inspect.tag "A" [ Inspect.to_inspector v1, Inspect.to_inspector v2 ]
|
||||||
// B v3 -> Inspect.tag "B" [ Inspect.toInspector v3 ])
|
// B v3 -> Inspect.tag "B" [ Inspect.to_inspector v3 ])
|
||||||
// fmt
|
// fmt
|
||||||
let clos = Closure(ClosureData {
|
let clos = Closure(ClosureData {
|
||||||
function_type: fn_var,
|
function_type: fn_var,
|
||||||
|
|
|
@ -48,10 +48,10 @@ pub enum DeriveKey {
|
||||||
impl DeriveKey {
|
impl DeriveKey {
|
||||||
pub fn debug_name(&self) -> String {
|
pub fn debug_name(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
DeriveKey::ToEncoder(key) => format!("toEncoder_{}", key.debug_name()),
|
DeriveKey::ToEncoder(key) => format!("to_encoder_{}", key.debug_name()),
|
||||||
DeriveKey::Decoder(key) => format!("decoder_{}", key.debug_name()),
|
DeriveKey::Decoder(key) => format!("decoder_{}", key.debug_name()),
|
||||||
DeriveKey::Hash(key) => format!("hash_{}", key.debug_name()),
|
DeriveKey::Hash(key) => format!("hash_{}", key.debug_name()),
|
||||||
DeriveKey::ToInspector(key) => format!("toInspector_{}", key.debug_name()),
|
DeriveKey::ToInspector(key) => format!("to_inspector_{}", key.debug_name()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,8 +29,6 @@ const MODULES: &[(ModuleId, &str)] = &[
|
||||||
];
|
];
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
panic!("Fail now to avoid infinite loading.");
|
|
||||||
|
|
||||||
for (module_id, filename) in MODULES {
|
for (module_id, filename) in MODULES {
|
||||||
write_subs_for_module(*module_id, filename);
|
write_subs_for_module(*module_id, filename);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1383,7 +1383,7 @@ impl DerivableVisitor for DeriveEq {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn visit_ranged_number(_var: Variable, _range: NumericRange) -> Result<(), NotDerivable> {
|
fn visit_ranged_number(_var: Variable, _range: NumericRange) -> Result<(), NotDerivable> {
|
||||||
// Ranged numbers are allowed, because they are always possibly ints - floats can not have
|
// Ranged numbers are allowed, because they are always possibly ints - floats can not have
|
||||||
// `isEq` derived, but if something were to be a float, we'd see it exactly as a float.
|
// `is_eq` derived, but if something were to be a float, we'd see it exactly as a float.
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1282,9 +1282,9 @@ fn extract_specialization_lambda_set<M: MetaCollector>(
|
||||||
// lambda set does not line up with one required by the ability member prototype.
|
// lambda set does not line up with one required by the ability member prototype.
|
||||||
// As an example, consider
|
// As an example, consider
|
||||||
//
|
//
|
||||||
// Q := [ F (Str -> Str) ] implements [Eq {isEq}]
|
// Q := [ F (Str -> Str) ] implements [Eq {is_eq}]
|
||||||
//
|
//
|
||||||
// isEq = \@Q _, @Q _ -> Bool.false
|
// is_eq = \@Q _, @Q _ -> Bool.false
|
||||||
//
|
//
|
||||||
// here the lambda set of `F`'s payload is part of the specialization signature, but it is
|
// here the lambda set of `F`'s payload is part of the specialization signature, but it is
|
||||||
// irrelevant to the specialization. As such, I believe it is safe to drop the
|
// irrelevant to the specialization. As such, I believe it is safe to drop the
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue