Skip to main content

antecedent_data/
materialize.rs

1//! Explicit materialization / copy diagnostics.
2//!
3//! SPDX-License-Identifier: MIT OR Apache-2.0
4
5use antecedent_core::{Diagnostic, DiagnosticKind, DiagnosticSeverity};
6
7/// Why a buffer was materialized.
8#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
9pub enum MaterializationReason {
10    /// Caller requested an owned contiguous copy.
11    ExplicitCopy,
12    /// Layout incompatible with the requested kernel (e.g. non-contiguous).
13    LayoutIncompatible,
14    /// Arrow / foreign buffer could not be borrowed zero-copy.
15    ForeignBufferIncompatible,
16}
17
18/// Record a materialization as an execution diagnostic.
19#[must_use]
20pub fn materialization_diagnostic(reason: MaterializationReason, bytes: u64) -> Diagnostic {
21    let code = match reason {
22        MaterializationReason::ExplicitCopy => "exec.materialize.explicit_copy",
23        MaterializationReason::LayoutIncompatible => "exec.materialize.layout",
24        MaterializationReason::ForeignBufferIncompatible => "exec.materialize.foreign",
25    };
26    let mut d = Diagnostic::new(
27        code,
28        DiagnosticKind::Execution,
29        DiagnosticSeverity::Info,
30        format!("materialized {bytes} bytes ({reason:?})"),
31    );
32    d.fields = std::sync::Arc::from([(
33        std::sync::Arc::<str>::from("bytes"),
34        std::sync::Arc::<str>::from(bytes.to_string()),
35    )]);
36    d
37}