From 26383b1e44990e88fd0d5d44e567d89d41365af6 Mon Sep 17 00:00:00 2001 From: Alan Lawrence Date: Wed, 24 Dec 2025 10:49:46 +0000 Subject: [PATCH 1/2] hide new public funcs --- Cargo.lock | 1 + tket-qsystem/Cargo.toml | 1 + tket-qsystem/src/lib.rs | 41 ++++++++++++++++++++++++++++++++--------- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c846d6f60..7fc738c3a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2746,6 +2746,7 @@ dependencies = [ "derive_more 2.1.1", "hugr", "hugr-cli", + "hugr-core", "indexmap 2.12.1", "itertools 0.14.0", "lazy_static", diff --git a/tket-qsystem/Cargo.toml b/tket-qsystem/Cargo.toml index 83af7de74..d3044a06f 100644 --- a/tket-qsystem/Cargo.toml +++ b/tket-qsystem/Cargo.toml @@ -24,6 +24,7 @@ required-features = ["cli"] [dependencies] hugr.workspace = true +hugr-core.workspace = true tket = { path = "../tket", version = "0.16.0" } tket-json-rs = { workspace = true } lazy_static.workspace = true diff --git a/tket-qsystem/src/lib.rs b/tket-qsystem/src/lib.rs index 7169760ea..e43805d8e 100644 --- a/tket-qsystem/src/lib.rs +++ b/tket-qsystem/src/lib.rs @@ -11,16 +11,16 @@ pub mod pytket; pub mod replace_bools; use derive_more::{Display, Error, From}; -use hugr::{ - Hugr, HugrView, Node, - algorithms::{ - ComposablePass as _, MonomorphizePass, RemoveDeadFuncsError, RemoveDeadFuncsPass, - const_fold::{ConstFoldError, ConstantFoldPass}, - force_order, - replace_types::ReplaceTypesError, - }, - hugr::{HugrError, hugrmut::HugrMut}, +use hugr::algorithms::const_fold::{ConstFoldError, ConstantFoldPass}; +use hugr::algorithms::{ + ComposablePass as _, MonomorphizePass, RemoveDeadFuncsError, RemoveDeadFuncsPass, force_order, + replace_types::ReplaceTypesError, }; +use hugr::hugr::{HugrError, hugrmut::HugrMut}; +use hugr::{Hugr, HugrView, Node, core::Visibility, ops::OpType}; +use hugr_core::hugr::internal::HugrMutInternals; +use std::collections::HashSet; + use lower_drops::LowerDropsPass; use replace_bools::{ReplaceBoolPass, ReplaceBoolPassError}; use tket::TketOp; @@ -117,14 +117,37 @@ impl QSystemPass { rdfp.run(hugr)? } + // ReplaceTypes steps (there are several below) can introduce new helper + // functions that are public to enable linking/sharing. We'll make these private + // once we're done so that LLVM is not forced to compile them as callable. + let pubfuncs = hugr + .children(hugr.module_root()) + .filter(|n| { + hugr.get_optype(*n) + .as_func_defn() + .is_some_and(|fd| fd.visibility() == &Visibility::Public) + }) + .collect::>(); + self.lower_tk2().run(hugr)?; if self.lazify { self.replace_bools().run(hugr)?; } + // We expect any Hugr will have *either* drop ops, or ValueArrays (without drops), // so only one of these passes will do anything; the order is thus immaterial. self.lower_drops().run(hugr)?; + for n in hugr + .children(hugr.module_root()) + .filter(|n| !pubfuncs.contains(n)) + .collect::>() + { + if let OpType::FuncDefn(fd) = hugr.optype_mut(n) { + *fd.visibility_mut() = Visibility::Private; + } + } + #[cfg(feature = "llvm")] { // TODO: We still want to run this as long as deserialized hugrs are allowed to contain Value::Function From 9a6c975ca16c88e36e095da708e7dd52ab2386b2 Mon Sep 17 00:00:00 2001 From: Alan Lawrence Date: Wed, 24 Dec 2025 11:24:57 +0000 Subject: [PATCH 2/2] reduce whitespace cange --- tket-qsystem/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/tket-qsystem/src/lib.rs b/tket-qsystem/src/lib.rs index e43805d8e..f2ba23a85 100644 --- a/tket-qsystem/src/lib.rs +++ b/tket-qsystem/src/lib.rs @@ -133,7 +133,6 @@ impl QSystemPass { if self.lazify { self.replace_bools().run(hugr)?; } - // We expect any Hugr will have *either* drop ops, or ValueArrays (without drops), // so only one of these passes will do anything; the order is thus immaterial. self.lower_drops().run(hugr)?;