Skip to content

API/TaggedUnion: no default/fallback tag when discriminator field is omitted #146

Not planned

Description

@clockblocker

Part of #138
Popularity: 1/7 corpus consumers (cuda-quantum)

Problem

When evolving versioned configuration schemas with rfl::TaggedUnion<"version", V1, V2>, legacy documents routinely omit the discriminator field (version). Upstream reflect-cpp (v0.25.0) provides no way to declare a default/fallback tag when the discriminator key is absent, forcing consumers to bypass rfl::yaml::read(string), parse the raw DOM themselves with yaml-cpp, mutate the DOM node to inject the default discriminator, and call the two-argument rfl::yaml::read(InputVarType, yaml_str) overload.

Observed Downstream Workaround

NVIDIA/cuda-quantum (90e4aa08)

  • cudaq/lib/Target/Yaml/TargetConfigSchema.h#L22-L23:
    /// Unversioned YAML files are treated as v1.
    using TargetConfigSchema =
        rfl::TaggedUnion<"version", v1::TargetConfigV1, v2::TargetConfigV2>;
  • cudaq/lib/Target/Yaml/TargetConfigSchema.cpp#L31-L42: directly includes <yaml-cpp/yaml.h>, calls YAML::Load, mutates node["version"] = "1", and invokes the two-argument rfl::yaml::read:
    YAML::Node node;
    try {
      node = YAML::Load(substitutedYamlContent);
    } catch (const YAML::Exception &e) {
      throw std::runtime_error("Failed to parse target configuration YAML: " +
                               std::string(e.what()));
    }
    // Unversioned configurations are schema v1, permanently.
    if (node.IsMap() && !node["version"])
      node["version"] = "1";
    const auto parsed = rfl::yaml::read<TargetConfigSchema, YamlProcessors>(
        rfl::yaml::InputVarType(node), substitutedYamlContent);

Related Fork Work

Upstream Overlap

Activity

  1. added
    enhancement
    needs-triage
    known-downstream-workarounds
    on Nov 29, 2026
  2. added
    wontfix
    and removed
    needs-triage
    on Nov 29, 2026
  3. clockblocker commented on Nov 29, 2026

    @clockblocker
    OwnerAuthor

    Triage decision: closing as wontfix (not planned) for the upstream adoption track.

    Rationale: DefaultTag fallback for missing rfl::TaggedUnion discriminators is a valid single-repo convenience (cuda-quantum), not an adoption driver, and upstream munich-data-engineering/reflect-cpp#455 precedent favored std::variant<TaggedUnion<...>, Fallback>.

    Preserved prototype: Already prototyped in fork PR #129 (scored 60/100, below the >= 65 upstream cutline) and parked cleanly on discuss/ssot (see Draft PR #191 parked table).

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-workaroundswontfix

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions