Make BastDoc owned: drop Bast* lifetimes (ADR-012 §2a, plan phase 3)

Every Bast* type drops <'a>: &'a str -> String, &'a Value -> Value
(deferred decision 1: plain String/Value — the tree is built once;
Arc<str> name-sharing needs a bench justification that doesn't exist).
BastDoc::new(&Value, &str) still takes references in and clones into
owned storage; the doc gains Clone. resolve_ref/resolve_typeref/
resolve_typeref_as_def return owned types.

- Engine ownership flip: AlkTypeEngine holds the owned BastDoc
  (replacing bast_doc: Value + root_name: String; root_name()
  delegates to the doc), killing its three per-call BastDoc::new
  re-parses (aligned validate_bytes, read_field, write_field — the
  review #004 M1 pattern removed by construction; phase 5 retires the
  lookup_leaf_field walk itself). New public accessor root_name()
  (additive). Engine Send + Sync with the owned doc, asserted in the
  existing thread-share test.
- Bonus cleanup: materialize_typeref_packed's dead _field param
  dropped (phase 2 left it dangling). Under ownership, keeping it
  would force a deep Value clone per array element / record value /
  union variant via dummy_field_for. The param, dummy_field_for, and
  ty_source are gone; no behavior change (the arg was already
  ignored). BastField::synthetic keeps an owned-signature
  #[allow(dead_code)] definition (no remaining callers today).
- Consumers adapted: OffsetMap::compute(&BastDoc),
  materialize_aligned(&BastDoc, ...) (no lifetime), BuildCtx/
  ComputeCtx hold &'d BastDoc, tunion/discriminator name borrows,
  lib.rs module doc. LayoutBuilder's doc_value re-parse cache is
  unchanged pending phase 4.

Verification: 465 tests pass with zero test-logic changes (bast.rs
suites exercise every parser path through the public API); clippy
-D warnings clean; cargo doc zero warnings; wasm32 release build
green.
This commit is contained in:
glm-5.3-flash committed 2026-09-02 08:31:58 +00:00
1 parent 1641dab505
commit c583762352
12 files changed
+299 -295

No files matched your search

+3 -3
View File
@@ -61,7 +61,7 @@ pub(crate) const DISCRIMINATOR_KEY: &str = "__discriminator";
/// constraint, or `Err(AlkTypeError::Schema(...))` if the BAST document
/// is malformed (a dangling `$ref`, a cyclic `$ref`, a missing `values`
/// array, etc.).
pub fn validate_value(doc: &BastDoc<'_>, value: &Value) -> Result<(), AlkTypeError> {
pub fn validate_value(doc: &BastDoc, value: &Value) -> Result<(), AlkTypeError> {
let plan = crate::validation_plan::ValidationPlan::compile(doc)?;
plan.validate(value)
}
@@ -85,7 +85,7 @@ mod tests {
use crate::read_plan::ReadPlan;
use serde_json::json;
fn doc_from<'a>(root: &'a Value, name: &'a str) -> BastDoc<'a> {
fn doc_from(root: &Value, name: &str) -> BastDoc {
BastDoc::new(root, name).expect("bast doc")
}
@@ -101,7 +101,7 @@ mod tests {
fn materialize_and_validate(
root: &Value,
doc: &BastDoc<'_>,
doc: &BastDoc,
buffer: &[u8],
) -> Result<(), AlkTypeError> {
let plan = ReadPlan::compile(root, doc.root_name())?;