Skip to content

Commit a3df91c

Browse files
committed
more minor changes
1 parent 39aad33 commit a3df91c

File tree

5 files changed

+16
-6
lines changed

5 files changed

+16
-6
lines changed

hugr-persistent/src/commit.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,9 @@ impl<'a> Commit<'a> {
294294
/// Change the lifetime of the commit.
295295
///
296296
/// This is unsafe because it cannot be guaranteed that the commit will
297-
/// live as long as the lifetime 'b.
298-
pub(crate) unsafe fn upgrade_lifetime<'b>(self) -> Commit<'b> {
297+
/// live as long as the lifetime 'b. The user must guuarantee that the
298+
/// rewrite space of `self` is valid as long as the lifetime 'b.
299+
pub unsafe fn upgrade_lifetime<'b>(self) -> Commit<'b> {
299300
Commit(self.0, PhantomData)
300301
}
301302
}

hugr-persistent/src/persistent_hugr.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,6 @@ impl PersistentHugr {
355355
pub fn apply_all(&self) -> (Hugr, HashMap<PatchNode, Node>) {
356356
let mut hugr = self.base_hugr().clone();
357357
let mut node_map = HashMap::from_iter(hugr.nodes().map(|n| (PatchNode(self.base(), n), n)));
358-
println!("\n\nstart apply_all");
359358
for commit_id in self.toposort_commits() {
360359
let Some(repl) = self.get_commit(commit_id).replacement() else {
361360
continue;

hugr-persistent/src/state_space.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ impl CommitStateSpace {
210210
/// Get the (unique) base commit of the state space.
211211
///
212212
/// Return `None` if `self` is empty.
213-
pub(crate) fn base_commit<'a>(&'a self) -> Option<Commit<'a>> {
213+
pub fn base_commit<'a>(&'a self) -> Option<Commit<'a>> {
214214
// get any commit
215215
let (_, relrc) = self.borrow().iter().next()?;
216216
// SAFETY: commit will be alive as long as the state space

hugr-persistent/src/trait_impls.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,19 @@ use hugr_core::{
1616
ops::OpType,
1717
};
1818

19+
use crate::CommitId;
20+
1921
use super::{
2022
InvalidCommit, PatchNode, PersistentHugr, PersistentReplacement, state_space::CommitData,
2123
};
2224

2325
impl Patch<PersistentHugr> for PersistentReplacement {
24-
type Outcome = ();
26+
type Outcome = CommitId;
2527
const UNCHANGED_ON_FAILURE: bool = true;
2628

2729
fn apply(self, h: &mut PersistentHugr) -> Result<Self::Outcome, Self::Error> {
2830
match h.try_add_replacement(self) {
29-
Ok(_) => Ok(()),
31+
Ok(commit) => Ok(commit),
3032
Err(
3133
InvalidCommit::UnknownParent(_)
3234
| InvalidCommit::IncompatibleHistory(_, _)

hugr-persistent/src/walker.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,14 @@ impl From<InvalidCommit> for PinNodeError {
496496
}
497497
}
498498

499+
impl<'w> hugr_core::hugr::views::NodesIter for Walker<'w> {
500+
type Node = PatchNode;
501+
502+
fn nodes(&self) -> impl Iterator<Item = Self::Node> + '_ {
503+
<PersistentHugr as HugrView>::nodes(self.as_hugr_view())
504+
}
505+
}
506+
499507
#[cfg(test)]
500508
mod tests {
501509
use std::collections::BTreeSet;

0 commit comments

Comments
 (0)