Skip to main content

miden_protocol/
package.rs

1use alloc::sync::Arc;
2
3use miden_mast_package::debug_info::PackageDebugInfo;
4use miden_mast_package::{Package, PackageDebugInfoError};
5use miden_processor::LoadedMastForest;
6
7use crate::MastForest;
8
9// Temporary bridge while package debug loading is split between protocol and VM APIs. These helpers
10// should move to miden-vm once the VM owns package-backed host libraries and debug info loading.
11
12/// Returns package-owned debug info when it can be decoded from trusted package sections.
13pub fn package_debug_info(package: &Package) -> Option<Arc<PackageDebugInfo>> {
14    match package.debug_info() {
15        Ok(debug_info) => debug_info.map(Arc::new),
16        Err(PackageDebugInfoError::UntrustedSections) => None,
17        Err(_) => None,
18    }
19}
20
21/// Builds a loaded MAST forest from a MAST forest and package-owned debug info.
22pub fn loaded_mast_forest(
23    mast: Arc<MastForest>,
24    package_debug_info: Option<Arc<PackageDebugInfo>>,
25) -> LoadedMastForest {
26    match package_debug_info {
27        Some(package_debug_info) => {
28            LoadedMastForest::with_package_debug_info(mast, Ok(Some((*package_debug_info).clone())))
29        },
30        None => LoadedMastForest::new(mast),
31    }
32}
33
34/// Builds a loaded MAST forest from a package, including package-owned debug info when trusted.
35pub fn loaded_mast_forest_from_package(package: &Package) -> LoadedMastForest {
36    loaded_mast_forest(package.mast_forest().clone(), package_debug_info(package))
37}