Repository navigation
Description
Part of #138
Popularity: 1/7 corpus consumers (slang-server)
Related issues
- Related issues: API/Enums: wire-name kebab-case transforms, strict non-numeric parsing, and allowed-values diagnostics force per-enum Reflector boilerplate #148 (
API/Enums: wire-name kebab-case transforms...), fork Prototype enum wire-name transform and per-enumerator rename hook #101 (Prototype enum wire-name transform and per-enumerator rename hook).
Observed Downstream Workaround (hudson-trading/slang-server @ 1b413a46)
slang-server uses integer-encoded enums for LSP wire types (e.g. MessageType, DiagnosticSeverity, CompletionItemKind, FileChangeType) and string-encoded enums for user-facing JSON config (Config::HoverConfig::DocCommentFormat).
Because reflect-cpp only offers rfl::UnderlyingEnums as a call-site processor (not a per-enum opt-in trait like rfl::config::enum_descriptions<E>), slang-server must thread <rfl::UnderlyingEnums> through 40+ separate read/write/to_generic/from_generic call sites:
include/lsp/JsonRpc.h#L59,include/lsp/JsonRpcServer.h#L53,#L81,#L99,#L132include/lsp/LspClient.h#L135-L198(9 repeated call sites)src/completions/MemberCompletions.cpp#L723,#L795,#L1004- Even
src/ast/WcpClient.cppdefensively passes<rfl::UnderlyingEnums>on 5 calls (#L255,#L373-L398) where the structs have no enums at all.
Concrete wire-encoding drift caused by call-site-only control:
- In
include/SlangLspClient.h#L124-L170, the exact sameInteractionSourceenum andActivateInstanceParamsstruct are serialized as a string inonActiveInstanceChanged(#L125:rfl::to_generic(params)) and inQuickPickParams::interactionSource(#L165:passArgs(...)->rfl::to_generic(...)), yet serialized as an integer inmakeActivateInstanceCommand(#L135) andQuickPickItem::value(#L154:rfl::to_generic<rfl::UnderlyingEnums>(ActivateInstanceParams{...})) — forcing tests (tests/cpp/CodeLensTests.cpp#L536-L551) to decode the outerQuickPickParamswithoutUnderlyingEnumsand its nesteditems[1].valuewithUnderlyingEnums. - Similarly,
include/lsp/LspServer.h#L45decodes command params withrfl::from_generic<P, rfl::UnderlyingEnums>while#L68encodes command results with plainrfl::to_generic(result).
Root Cause & Suggested Direction
Enum wire representation (string vs underlying integer) is almost always an intrinsic property of the enum type / protocol schema, not a per-call-site whim. Because reflect-cpp only provides a call-site processor (rfl::UnderlyingEnums), mixed-protocol codebases must manually remember the processor at every serialization boundary and cannot compose an integer-encoded enum with a string-encoded enum in the same object without writing custom Reflector<E> boilerplate.
Provide a lightweight per-enum opt-in trait (e.g., rfl::config::underlying_enum<E> = true alongside rfl::config::enum_descriptions<E>, or an enum wire-format policy trait unified with #101).
Upstream Overlap
- Proposal: rfl:UnderlyingEnum munich-data-engineering/reflect-cpp#130 /
rfl::UnderlyingEnumsmunich-data-engineering/reflect-cpp#186 (closed/wontfix on per-type/per-field design) —#130originally proposed per-fieldrfl::UnderlyingEnum<Color>, but maintainer@liuzicheng1987steered it to a call-site processor ("I would design it as a processor, though", merged in#186); a follow-up comment asking for per-field scoping went unaddressed. (Custom per-enumReflector<E>specializations were later enabled in Allows usage of custom Reflector for enums types munich-data-engineering/reflect-cpp#621, but no lightweight per-enumunderlying_enum<E>trait is filed.)
Activity
[-]API/Enums (slang-server): call-site-only rfl::UnderlyingEnums forces 40+ repetitions and causes mixed wire encodings for the same enum[/-][+]API/Enums: call-site-only rfl::UnderlyingEnums forces 40+ repetitions and causes mixed wire encodings for the same enum[/+]