← Back to Pull requests

Borrow typed heap payloads with Value::get_as #1425

Closed
unknown closed this pull request without merging on Nov 26, 2026 12:06 UTC
View on GitHub
unknown unknown commented on Nov 24, 2026 15:55 UTC
Author

Summary

value.get_as::<T>(heap) borrows a payload directly from the heap. For example, list indexing can use if let Some(slice) = key.get_as::<Slice>(vm.heap) to read the slice bounds. The result is tied to the heap borrow, and the lookup uses the existing Heap::get without creating a reader guard.

This extracts the borrowed accessor from #1024 on top of #1421. The payload registry supplies the match for inline and boxed payloads. With the current untagged references, immediate values return None before a heap lookup, and heap references need one lookup to check their payload type. The caller migrations cover single-type reads. Multi-type dispatch can continue matching several variants on a single heap lookup.

Tests

Added a unit test that borrows bytes stored inline in a heap slot and a boxed named tuple. It also checks a mismatched heap payload and an immediate value. Ran the Monty tests and interpreter fixtures with memory-model-checks, the workspace Rust lints, formatting, and the 32-bit WASI build check.

<!-- This is an auto-generated description by cubic. -->
---

Summary by cubic


Adds Value::get_as::<T>(heap) to borrow a typed heap payload directly, while Value absorbs borrowed accessors for bytes, strings, and long ints so call sites no longer match Value::Ref against HeapData variants by hand.

  • get_as reuses the existing Heap::get lookup via the payload registry's new from_heap_data, checking the payload type for heap references and returning None for immediate values.

  • Value::as_bytes, as_str, as_long_int, and try_as_str (renamed from try_to_str) replace local helpers like value_as_bytes, str_of, buffer, and the is_long_int/long_int wrappers; codec inputs now borrow byte slices directly instead of copying through value_to_owned_bytes.

  • base16 and base32 decoders fold ASCII case and translate digits while decoding, so casefold=True accepts mixed-case input; altchars translate before strict padding checks, and invalid digits take precedence over odd-length errors.

  • Ascii85 decoding with a custom ignorechars now charges the session for the input copy it makes during decoding.

  • base64 encoders now raise the standard bytes-like TypeError; CPython prefixes that message with memoryview: for b32encode, b32hexencode, b85encode, z85encode and a85encode.

  • Unit tests cover inline and boxed payloads, mismatched heap payloads, immediate values, and interned versus heap-allocated bytes.
  • <sup>Written for commit ac80c7dd8385cdc33831a4f14640c7c49917094c. Summary will update on new commits.</sup>

    <a href="https://cubic.dev/pr/pydantic/monty/pull/1425?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="View guided diff" src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a>

    <!-- End of auto-generated description by cubic. -->

    Diff: 394 lines (+295 / -99) across 4 files Reviewer: davidhewitt Review duration: 2651m
    All Vouch review confidence checks passed
    Residual risk 0.26 = Change Risk (0.66) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.66 · 394 lines diff across 4 files
    0.66
    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.358
    Shallow Review Depth shallow_review_depth
    0.289
    Sensitive Paths sensitive_paths
    0.066
    Real PR Conversation Timeline
    1 comments
    "Review active on #1425"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed sensitive_module
    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: 66.3% (HIGH) · Higher = larger blast radius
    66.3%
    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: 26.2% · Safe to merge
    26.2%
    Repository