Expand description
The value an F# member takes when the stream does not carry it.
Table 9 of DDS-XTypes 1.3, as F# — deliberately a further derivation
and not a call into any sibling’s, for the reason default_zig.rs’s
own documentation gives: the columns are compared against each other
and a shared helper would make them agree about a mistake.
§Two uses, and only one of them needs a generated function
default_expr answers Table 9’s value as one expression, and
crates/lang-rules/src/adapter/fsharp.rs calls it directly to give
every fsharp::ClassField::default its value at the moment a class
is declared — no function needed there, because the value is written
once, at the declaration, and never repeated.
crates/lang-rules/src/emit/fsharp.rs’s crate::emit::Routine
carries no Ast and no Id<TypeNode> — only the already-materialised
fsharp::Type — so a decoder’s own starting value cannot call
default_expr directly the way the adapter does; it needs a
name it can build a call to, exactly the shape
default_zig.rs’s defaulter_from_decoder answers for Zig and for
the same reason. defaulter_name, defaulter_from_decoder,
fsharp_defaulters_over and fsharp_defaulters_called_by are
that machinery, generating let zd_def_X () : T = <Table 9's value>
— a unit -> T function and not a plain value, because a plain
let zd_def_X : T = Pose() would construct one Pose at module
load and hand every caller the same mutable object; every one of
crates/lang-rules/src/emit/fsharp.rs’s three call sites —
crate::emit::CodecTarget::routine’s decode start,
crate::emit::CodecTarget::default_into and
crate::emit::CodecTarget::member_default’s implicit branch — call
zd_def_X () and expect a fresh one each time.
What makes this machinery shorter than default_zig.rs’s own copy of
it is the body each generated function answers with: for an
aggregate it is T(), one call, because
crates/lang-cst/src/fsharp/mod.rs’s module documentation is where
the design that makes T() already Table 9’s value is argued — Zig
has to build a whole struct literal there and this column does not.
Functions§
- default_
expr - DDS-XTypes 1.3 Table 9’s value for
id, as an F# expression. - defaulter_
from_ decoder - The defaulter that goes with a decoder, by name.
- defaulter_
name - The defaulter function name for a type, keyed the way the decoder is:
by the IDL kind for a primitive and by the codec tag for everything
else —
default_zig.rs’sdefaulter_nameread onto this column’s tag function. - discriminator_
default - A union discriminator’s own Table 9 default, in the discriminator’s
F# form: the enumerator for an enumeration, the boolean literal for
a
boolean, and the number for everything else — acharand awchardiscriminator hold their code unit as an integer here, asdefault_zig.rs’sdiscriminant_literaldoes for Zig. - fsharp_
defaulters_ called_ by - The defaulters
declscall, and exactly those — read off the emitted calls rather than derived a second time from the model, the same reachability walkdefault_zig.rs’szig_defaulters_called_byruns. - fsharp_
defaulters_ over - Build the defaulter for each of
types, once per name:let zd_def_X () : T = <Table 9's value>, aunit -> Tfunction so every caller gets a fresh, unaliased value — the module documentation says why a plain value would be wrong for a mutable class. - member_
value - One member’s default: its
@default, or its type’s Table 9 value. §7.2.2.4.4.4.9 puts the explicit one first.