← Back to Pull requests

[#33] Add InlineString<N>: fixed-capacity, owned, allocation-free string #43

Closed
unknown closed this pull request without merging on Sep 25, 2026 18:49 UTC
View on GitHub
unknown unknown commented on Sep 25, 2026 16:35 UTC
Author

Summary

Implements ADR-001 Decisions 1-2's replacement for std::string in the governed zone (mddlog-core), per #33 (after #31's contracts, in parallel with #32 which is already merged).

InlineString<N>: a std::array<char, N> plus a std::uint16_t length — constexpr, noexcept, trivially copyable, no allocation and no exception anywhere in the module.

  • N bounded at compile time: a requires clause rejects any N outside the uint16_t length's representable range. No compile-fail test harness exists in this project yet, so this is the documented fallback the issue's acceptance criteria allow.

  • assignExact() — identifier-kind semantics (ADR-001 Decision 2): stores the value only if it fits whole; otherwise leaves the object exactly as it was.

  • assignTruncating() — descriptive-text semantics: always stores, shortening to the longest prefix that never splits a well-formed UTF-8 sequence, and reports whether it did. Implements the algorithm ADR-001 Decision 2 documents, including the malformed-input backtrack-cap behavior for already-invalid input.

  • Comparison is by logical content (view()), not raw storage — two instances with different write histories but the same current value compare equal (a mistake an earlier revision of the memory-budget ADR work made and had to fix; guarded against here from the start).

  • Owned storage only: every assignment copies bytes into the object's own array; no view into caller-owned memory is ever retained.

  • Three consteval self-tests with static_assert, shipped in the module itself (not just the spec), prove constexpr evaluation of both assignment operations — the acceptance criterion's "at least one static_assert" plus a bit more, as a permanent regression guard.
  • Also adds tests/spec/InlineStringSpec.cpp (SpecLab), covering: empty/partial/exact-capacity for both assignment kinds, capacity+1 refusal leaving the prior value untouched, 2/3/4-byte UTF-8 sequences right at the truncation boundary (both "fits whole" and "gets dropped entirely" cases), already-malformed input's documented backtrack-cap behavior, trivial-copyability, and logical-content equality.

    InlineString<N> is not re-exported through the mddlog umbrella module at this stage — it's a governed-zone-only building block (ADR-001's full governed record doesn't exist yet); the spec imports mddlog.core.inlinestring directly.

    Invitation and contributor agreement

    Not applicable — this PR is the project steward's own change, made directly by the maintainer (ambroise-leclerc); there is no external contributor or CLA issue involved.

    Verification

  • Hand-traced the UTF-8 truncation-boundary algorithm against all six 2/3/4-byte-sequence scenarios in the spec (exact-fit and one-byte-short, for each length) before writing the code, to confirm the expected outputs the spec asserts.

  • Read through the module end-to-end for the acceptance criteria's "no allocation, no try/catch/throw" requirement — confirmed by inspection: only std::array, std::string_view, std::uint16_t/std::size_t, and std::copy_n are used.

  • Formatted with the locally available clang-format 18 (project config targets 21, documented as 18+-compatible).

  • Used octal escapes instead of hex for the non-ASCII byte literals in both the module's self-tests and the spec, to avoid a possible "hex escape sequence out of range" diagnostic under -Werror on a signed-char target.

  • Not locally build- or clang-tidy-verified. This sandbox's CMake/compiler versions are below the project's floors, and scripts/run-clang-tidy.sh requires the pinned clang-tidy-21 plus built Clang module interfaces neither of which this sandbox can produce. Named the UTF-8 bit-pattern literals as constants specifically to preempt cppcoreguidelines-avoid-magic-numbers, and replaced indexed-loop copies with std::copy_n to avoid cppcoreguidelines-pro-bounds-constant-array-index on the std::array member — best-effort against the enabled check set, not a substitute for CI actually running it.

  • CI ran clang-tidy-21 for real on the pushed commits and caught 4 findings not visible locally (magic-number and container-size-empty checks); all fixed and confirmed green.

  • Copilot review caught a real UTF-8 truncation-boundary bug (straddling sequence that fit whole after backtracking wasn't restoring the boundary); fixed with a two-phase rewrite plus a consteval self-test and a SpecLab regression scenario pinning the exact case reported.
  • Acceptance criteria (from #33)

  • Scénarios : capacité exacte, capacité+1, chaîne vide, séquences UTF-8 de 2, 3 et 4 octets à la frontière, entrée invalide — all covered in InlineStringSpec.cpp; CI green.

  • N hors plage rejeté à la compilation — enforced by the requires clause; documented rather than exercised by a non-compilation test, per the issue's own fallback.

  • Évaluation constexpr démontrée par au moins un static_assert — three consteval+static_assert pairs shipped in the module.

  • Aucun try/catch/throw ni allocation dans le module — confirmed by review (see Verification); tooled proof is explicitly out of scope for #33 (belongs to the boundary-controls batch).
  • <!-- This is an auto-generated comment: release notes by coderabbit.ai -->

    Summary by CodeRabbit

    New Features
    Added fixed-capacity string storage that avoids dynamic allocation.
    Strings can be assigned exactly, preserving their existing value if the input exceeds capacity, or assigned with truncation when needed.
    Truncation avoids splitting well-formed UTF-8 characters at the capacity boundary. The string also supports viewing its contents, checking its size and emptiness, and comparing values.
    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: ambroise-leclerc Review duration: 133m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #43"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%