Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tket-qsystem/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 31 additions & 9 deletions tket-qsystem/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -117,6 +117,18 @@ 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::<HashSet<_>>();

self.lower_tk2().run(hugr)?;
if self.lazify {
self.replace_bools().run(hugr)?;
Expand All @@ -125,6 +137,16 @@ impl QSystemPass {
// 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::<Vec<_>>()
{
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
Expand Down
Loading