Skip to content

API/Defaults & Wrappers: all-or-nothing DefaultIfMissing and intrusive metadata wrappers force shadow structs, .value().value_or() churn, and drift static_asserts #147

Backlog

Description

@clockblocker

Part of #138
Popularity: 4/7 corpus consumers (cuda-quantum, moqx, wolf, slang-server)

Problem

Two tightly coupled ergonomic gaps around defaults and intrusive field wrappers appear across four independent production consumers:

  1. rfl::DefaultIfMissing is all-or-nothing across an entire deserialized object graph and requires every struct in the tree to be default-constructible (auto t = T{};). Enabling it silently defaults schema-required fields (even forcing dummy defaults on required TaggedUnion fields) and erases field presence (preventing partial HTTP PATCH updates or layered config merging). Conversely, omitting it forces consumers to wrap every optional field in rfl::DefaultVal<T> or maintain shadow Parsed* / Partial* structs.
  2. Intrusive metadata/field wrappers (rfl::Description, rfl::Deprecated, rfl::Rename, rfl::DefaultVal, rfl::Skip) alter the field's C++ type rather than attaching out-of-band traits. Consumers must either accept pervasive .value() / .value().value() / .value().value_or(...) double-unwrapping across the entire codebase, or quarantine reflect-cpp behind a full parallel shadow-struct hierarchy guarded by manual field-count drift static_asserts.

Observed Downstream Workarounds

NVIDIA/cuda-quantum (90e4aa08)

openmoq/moqx (60bab7f13925acbaf578670223e660d71e891547)

  1. Wrapper double-unwrap tax (rfl::Description<"...", std::optional<T>>):
    • src/config/loader/ParsedConfig.h#L20-L24:
      // Note: fields wrapped in rfl::Description<"...", T> expose a .value() accessor
      // that unwraps the Description wrapper — this is NOT std::optional::value().
      // For optional fields the type is rfl::Description<"...", std::optional<T>>,
      // so .value() returns the std::optional, and a second .value() or
      // .value_or() unwraps the optional itself.
    • docs/dev/config.md#L62: explicitly warns contributors about two-level .value().value() / .value().value_or() unwrapping.
    • Across src/config/ConfigResolver.cpp alone there are 333 .value() calls and 46 .value().value_or(...) double-unwraps (plus 75 .value() calls in test/config/LoaderTest.cpp#L143-L144 like l.tls.value().cert_file.value().value()).
  2. Full shadow struct hierarchy (ParsedConfig.h vs Config.h) & quarantine of reflect-cpp:
  3. 27 rfl::internal::num_fields drift-guard static_asserts + post-v0.22.0 internal-header break:
    • Because moqx_config stays rfl-free (and needs redaction of secrets for GET /config), moqx maintains a 446-line hand-written walker (src/config/ConfigSerializer.h) guarded by 27 static_assert(rfl::internal::num_fields<...> == N) assertions in test/config/ConfigSerializerTest.cpp#L14-L130:
      #include <rfl/internal/num_fields.hpp>
      
      // Drift guard: rfl reflects the field count of each resolved Config struct. If
      // you add or remove a field in Config.h, the matching assert fails and you must
      // bump the count *and* update serializeConfig() in ConfigSerializer.h.
      ...
      static_assert(rfl::internal::num_fields<Config> == 10, "Config changed — update serializeConfig()");
    • Note: even though docs/dev/config.md#L110 says rfl::num_fields, the code includes <rfl/internal/num_fields.hpp>. In newer reflect-cpp commits (C++26 reflection refactor, upstream PR #713), include/rfl/internal/num_fields.hpp was moved to include/rfl/internal/cpp20/num_fields.hpp without a forwarding shim, breaking downstream moqx builds until patched to <rfl/num_fields.hpp>.

games-on-whales/wolf (ac2461f6)

  1. Dummy AppCMD{} default on a required rfl::TaggedUnion field forced by rfl::DefaultIfMissing:
    src/moonlight-server/state/serialised_config.hpp#L119-L129 (used across 6 rfl::toml::load<WolfConfig, rfl::DefaultIfMissing>(...) calls in src/moonlight-server/state/configTOML.cpp#L218, #L250, #L423, #L439, #L463, #L476):
    struct BaseApp {
      std::string title;
      ...
      rfl::TaggedUnion<"type", AppCMD, AppDocker> runner =
          AppCMD{}; // We have to provide a default or rfl::DefaultIfMissing will fail
    };
  2. Parallel PartialClientSettings shadow struct + duplicated field-by-field merge for partial updates:
    src/moonlight-server/api/api.hpp#L54-L62 mirrors all 7 fields of wolf::config::ClientSettings wrapped in std::optional<...>:
    struct PartialClientSettings {
      std::optional<uint> run_uid;
      std::optional<uint> run_gid;
      std::optional<std::vector<wolf::config::ControllerType>> controllers_override;
      std::optional<float> mouse_acceleration;
      std::optional<float> v_scroll_acceleration;
      std::optional<float> h_scroll_acceleration;
      std::optional<wolf::config::ControllerType> motion_controller_override;
    };
    Every new field added to ClientSettings (e.g. motion_controller_override in commit 4ebbd98f) must be duplicated into PartialClientSettings and manually threaded through two separate .value_or(...) merge blocks: src/moonlight-server/api/endpoints.cpp#L424-L436 and #L572-L581.
  3. Double-unwrap on rfl::Description<..., std::optional<T>>:
    src/moonlight-server/api/api.hpp#L65-L70, #L124-L140 and src/moonlight-server/api/endpoints.cpp#L411, #L568-L571:
    auto client_settings = event.value().client_settings.value().value_or(PartialClientSettings{});
    ...
    auto new_settings = payload.settings.get().value_or(PartialClientSettings{});
    .app_state_folder = payload.app_state_folder.get().value_or(current_client->app_state_folder),

hudson-trading/slang-server (1b413a46)

  1. Pervasive .value() and chained .value().value_or(...) / *field.value() unwrapping on metadata-wrapped fields:
    Every field of Config and its nested structs (IndexConfig, HoverConfig, InlayHints, Build) is wrapped in rfl::Description<...>, rfl::Deprecated<...>, or rfl::Skip<...> (include/Config.h#L35-L196):
  2. Double-parsing every layered config file + manual Generic::Object presence tracking:
    Because rfl::DefaultIfMissing fills in missing fields with default-constructed values (erasing whether a field was explicitly provided vs omitted) and cannot merge partial layers into an existing Config struct, Config::fromFiles parses every JSONC file twice — first into Config purely for validation (discarding the result), then into rfl::Generic to manually merge arrays/maps/scalars and track explicit presence (e.g. buildPatternExplicit):
    • include/Config.h#L41 & #L90-L91:
      // all fields must be optional
      ...
      // This can't be defaulted because of how we paint configs over each other and append
      // lists together.
    • src/Config.cpp#L68-L140:
      // Validate against Config schema first
      auto fileConfig = rfl::json::read<Config, rfl::DefaultIfMissing>(jsonstr,
                                                                       CONFIG_READ_FLAGS);
      ...
      auto generic = rfl::json::read<rfl::Generic>(jsonstr, CONFIG_READ_FLAGS);
      ...
      auto finalConfig = rfl::from_generic<Config, rfl::DefaultIfMissing>(config);
      ...
      const bool buildPatternExplicit = hasField(workspaceObj, "buildPattern") ||
                                        hasField(userObj, "buildPattern") ||
                                        hasField(localObj, "buildPattern");

Related Fork Work

Upstream Overlap

Activity

  1. added
    enhancement
    needs-triage
    known-downstream-workarounds
    on Nov 29, 2026
  2. changed the title [-]API/Defaults & Wrappers: all-or-nothing DefaultIfMissing forces shadow structs, DefaultVal<T>, .value().value(), and drift static_asserts[/-] [+]API/Defaults & Wrappers: all-or-nothing DefaultIfMissing and intrusive metadata wrappers force shadow structs, .value().value_or() churn, and drift static_asserts[/+] on Nov 29, 2026
  3. clockblocker commented on Nov 29, 2026

    @clockblocker
    OwnerAuthor

    Tracking & PR Cross-Reference

    Status: Tier-2 (upstream discussion first) — existing prototypes are parked cleanly on discuss/ssot (all scored below the >= 65 cutline in Draft PR #209 without upstream design sign-off).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementknown-downstream-workaroundsneeds-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions