From 78435b5a52428b21413418893f9e34e57092f37f Mon Sep 17 00:00:00 2001 From: Seyon Sivarajah Date: Fri, 22 Nov 2024 14:59:34 +0000 Subject: [PATCH] feat: export llvm test utilities under llvm-test feature (#1677) Closes #1673 --- .github/workflows/ci-rs.yml | 2 +- hugr-llvm/Cargo.toml | 29 +- hugr-llvm/src/emit.rs | 2 +- ...est_fns__diverse_cfg_children@llvm14.snap} | 0 ...erse_cfg_children@pre-mem2reg@llvm14.snap} | 0 ...est_fns__diverse_dfg_children@llvm14.snap} | 0 ...erse_dfg_children@pre-mem2reg@llvm14.snap} | 0 ..._fns__diverse_module_children@llvm14.snap} | 0 ...e_module_children@pre-mem2reg@llvm14.snap} | 0 ...est__test_fns__emit_hugr_call@llvm14.snap} | 0 ...s__emit_hugr_call@pre-mem2reg@llvm14.snap} | 0 ..._fns__emit_hugr_call_indirect@llvm14.snap} | 0 ...ugr_call_indirect@pre-mem2reg@llvm14.snap} | 0 ...st_fns__emit_hugr_conditional@llvm14.snap} | 0 ..._hugr_conditional@pre-mem2reg@llvm14.snap} | 0 ...test_fns__emit_hugr_custom_op@llvm14.snap} | 0 ...it_hugr_custom_op@pre-mem2reg@llvm14.snap} | 0 ...test__test_fns__emit_hugr_dfg@llvm14.snap} | 0 ...ns__emit_hugr_dfg@pre-mem2reg@llvm14.snap} | 0 ..._fns__emit_hugr_load_constant@llvm14.snap} | 0 ...ugr_load_constant@pre-mem2reg@llvm14.snap} | 0 ...test__test_fns__emit_hugr_tag@llvm14.snap} | 0 ...ns__emit_hugr_tag@pre-mem2reg@llvm14.snap} | 0 ...test__test_fns__load_function@llvm14.snap} | 0 ...ns__load_function@pre-mem2reg@llvm14.snap} | 0 hugr-llvm/src/emit/test.rs | 600 +++++++++--------- hugr-llvm/src/lib.rs | 2 +- hugr/Cargo.toml | 1 + 28 files changed, 338 insertions(+), 298 deletions(-) rename hugr-llvm/src/emit/snapshots/{hugr_llvm__emit__test__diverse_cfg_children@llvm14.snap => hugr_llvm__emit__test__test_fns__diverse_cfg_children@llvm14.snap} (100%) rename hugr-llvm/src/emit/snapshots/{hugr_llvm__emit__test__diverse_cfg_children@pre-mem2reg@llvm14.snap => hugr_llvm__emit__test__test_fns__diverse_cfg_children@pre-mem2reg@llvm14.snap} (100%) rename hugr-llvm/src/emit/snapshots/{hugr_llvm__emit__test__diverse_dfg_children@llvm14.snap => hugr_llvm__emit__test__test_fns__diverse_dfg_children@llvm14.snap} (100%) rename hugr-llvm/src/emit/snapshots/{hugr_llvm__emit__test__diverse_dfg_children@pre-mem2reg@llvm14.snap => hugr_llvm__emit__test__test_fns__diverse_dfg_children@pre-mem2reg@llvm14.snap} (100%) rename hugr-llvm/src/emit/snapshots/{hugr_llvm__emit__test__diverse_module_children@llvm14.snap => hugr_llvm__emit__test__test_fns__diverse_module_children@llvm14.snap} (100%) rename hugr-llvm/src/emit/snapshots/{hugr_llvm__emit__test__diverse_module_children@pre-mem2reg@llvm14.snap => hugr_llvm__emit__test__test_fns__diverse_module_children@pre-mem2reg@llvm14.snap} (100%) rename hugr-llvm/src/emit/snapshots/{hugr_llvm__emit__test__emit_hugr_call@llvm14.snap => hugr_llvm__emit__test__test_fns__emit_hugr_call@llvm14.snap} (100%) rename hugr-llvm/src/emit/snapshots/{hugr_llvm__emit__test__emit_hugr_call@pre-mem2reg@llvm14.snap => hugr_llvm__emit__test__test_fns__emit_hugr_call@pre-mem2reg@llvm14.snap} (100%) rename hugr-llvm/src/emit/snapshots/{hugr_llvm__emit__test__emit_hugr_call_indirect@llvm14.snap => hugr_llvm__emit__test__test_fns__emit_hugr_call_indirect@llvm14.snap} (100%) rename hugr-llvm/src/emit/snapshots/{hugr_llvm__emit__test__emit_hugr_call_indirect@pre-mem2reg@llvm14.snap => hugr_llvm__emit__test__test_fns__emit_hugr_call_indirect@pre-mem2reg@llvm14.snap} (100%) rename hugr-llvm/src/emit/snapshots/{hugr_llvm__emit__test__emit_hugr_conditional@llvm14.snap => hugr_llvm__emit__test__test_fns__emit_hugr_conditional@llvm14.snap} (100%) rename hugr-llvm/src/emit/snapshots/{hugr_llvm__emit__test__emit_hugr_conditional@pre-mem2reg@llvm14.snap => hugr_llvm__emit__test__test_fns__emit_hugr_conditional@pre-mem2reg@llvm14.snap} (100%) rename hugr-llvm/src/emit/snapshots/{hugr_llvm__emit__test__emit_hugr_custom_op@llvm14.snap => hugr_llvm__emit__test__test_fns__emit_hugr_custom_op@llvm14.snap} (100%) rename hugr-llvm/src/emit/snapshots/{hugr_llvm__emit__test__emit_hugr_custom_op@pre-mem2reg@llvm14.snap => hugr_llvm__emit__test__test_fns__emit_hugr_custom_op@pre-mem2reg@llvm14.snap} (100%) rename hugr-llvm/src/emit/snapshots/{hugr_llvm__emit__test__emit_hugr_dfg@llvm14.snap => hugr_llvm__emit__test__test_fns__emit_hugr_dfg@llvm14.snap} (100%) rename hugr-llvm/src/emit/snapshots/{hugr_llvm__emit__test__emit_hugr_dfg@pre-mem2reg@llvm14.snap => hugr_llvm__emit__test__test_fns__emit_hugr_dfg@pre-mem2reg@llvm14.snap} (100%) rename hugr-llvm/src/emit/snapshots/{hugr_llvm__emit__test__emit_hugr_load_constant@llvm14.snap => hugr_llvm__emit__test__test_fns__emit_hugr_load_constant@llvm14.snap} (100%) rename hugr-llvm/src/emit/snapshots/{hugr_llvm__emit__test__emit_hugr_load_constant@pre-mem2reg@llvm14.snap => hugr_llvm__emit__test__test_fns__emit_hugr_load_constant@pre-mem2reg@llvm14.snap} (100%) rename hugr-llvm/src/emit/snapshots/{hugr_llvm__emit__test__emit_hugr_tag@llvm14.snap => hugr_llvm__emit__test__test_fns__emit_hugr_tag@llvm14.snap} (100%) rename hugr-llvm/src/emit/snapshots/{hugr_llvm__emit__test__emit_hugr_tag@pre-mem2reg@llvm14.snap => hugr_llvm__emit__test__test_fns__emit_hugr_tag@pre-mem2reg@llvm14.snap} (100%) rename hugr-llvm/src/emit/snapshots/{hugr_llvm__emit__test__load_function@llvm14.snap => hugr_llvm__emit__test__test_fns__load_function@llvm14.snap} (100%) rename hugr-llvm/src/emit/snapshots/{hugr_llvm__emit__test__load_function@pre-mem2reg@llvm14.snap => hugr_llvm__emit__test__test_fns__load_function@pre-mem2reg@llvm14.snap} (100%) diff --git a/.github/workflows/ci-rs.yml b/.github/workflows/ci-rs.yml index ee590e4da..c7e3d8bec 100644 --- a/.github/workflows/ci-rs.yml +++ b/.github/workflows/ci-rs.yml @@ -242,7 +242,7 @@ jobs: tests-stable-llvm: needs: changes - if: ${{ ( needs.changes.outputs.llvm == 'true' && github.event_name == 'push' ) || needs.changes.outputs.override == 'true' }} + if: ${{ ( needs.changes.outputs.llvm == 'true' && github.event_name == 'push' ) || needs.changes.outputs.override == 'true' }} runs-on: ubuntu-latest name: tests hugr-llvm strategy: diff --git a/hugr-llvm/Cargo.toml b/hugr-llvm/Cargo.toml index 826b543fb..ce5cd278d 100644 --- a/hugr-llvm/Cargo.toml +++ b/hugr-llvm/Cargo.toml @@ -16,12 +16,23 @@ keywords = ["Quantum", "Quantinuum"] categories = ["compilers"] [features] +test-utils = [ + "insta", + "rstest", + "portgraph", + "pathsearch", + "serde_json", + "serde", + "typetag", +] + default = ["llvm14-0"] llvm14-0 = ["inkwell/llvm14-0"] + [dependencies] inkwell = { version = "0.4.0", default-features = false } -hugr-core = { path = "../hugr-core", version = "0.13.3"} +hugr-core = { path = "../hugr-core", version = "0.13.3" } anyhow = "1.0.83" itertools.workspace = true delegate.workspace = true @@ -30,11 +41,13 @@ lazy_static.workspace = true downcast-rs.workspace = true strum.workspace = true +insta = { workspace = true, optional = true } +rstest = { workspace = true, optional = true } +portgraph = { workspace = true, optional = true } +pathsearch = { workspace = true, optional = true } +serde_json = { workspace = true, optional = true } +serde = { workspace = true, optional = true } +typetag = { workspace = true, optional = true } + [dev-dependencies] -insta.workspace = true -rstest.workspace = true -portgraph.workspace = true -pathsearch.workspace = true -serde_json.workspace = true -serde.workspace = true -typetag.workspace = true +hugr-llvm = {"path" = ".", features = ["test-utils"]} diff --git a/hugr-llvm/src/emit.rs b/hugr-llvm/src/emit.rs index 2591a1fab..959838600 100644 --- a/hugr-llvm/src/emit.rs +++ b/hugr-llvm/src/emit.rs @@ -403,5 +403,5 @@ pub fn get_intrinsic<'c>( )) } -#[cfg(test)] +#[cfg(any(test, feature = "test-utils"))] pub mod test; diff --git a/hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__diverse_cfg_children@llvm14.snap b/hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__diverse_cfg_children@llvm14.snap similarity index 100% rename from hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__diverse_cfg_children@llvm14.snap rename to hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__diverse_cfg_children@llvm14.snap diff --git a/hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__diverse_cfg_children@pre-mem2reg@llvm14.snap b/hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__diverse_cfg_children@pre-mem2reg@llvm14.snap similarity index 100% rename from hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__diverse_cfg_children@pre-mem2reg@llvm14.snap rename to hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__diverse_cfg_children@pre-mem2reg@llvm14.snap diff --git a/hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__diverse_dfg_children@llvm14.snap b/hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__diverse_dfg_children@llvm14.snap similarity index 100% rename from hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__diverse_dfg_children@llvm14.snap rename to hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__diverse_dfg_children@llvm14.snap diff --git a/hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__diverse_dfg_children@pre-mem2reg@llvm14.snap b/hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__diverse_dfg_children@pre-mem2reg@llvm14.snap similarity index 100% rename from hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__diverse_dfg_children@pre-mem2reg@llvm14.snap rename to hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__diverse_dfg_children@pre-mem2reg@llvm14.snap diff --git a/hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__diverse_module_children@llvm14.snap b/hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__diverse_module_children@llvm14.snap similarity index 100% rename from hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__diverse_module_children@llvm14.snap rename to hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__diverse_module_children@llvm14.snap diff --git a/hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__diverse_module_children@pre-mem2reg@llvm14.snap b/hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__diverse_module_children@pre-mem2reg@llvm14.snap similarity index 100% rename from hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__diverse_module_children@pre-mem2reg@llvm14.snap rename to hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__diverse_module_children@pre-mem2reg@llvm14.snap diff --git a/hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__emit_hugr_call@llvm14.snap b/hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__emit_hugr_call@llvm14.snap similarity index 100% rename from hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__emit_hugr_call@llvm14.snap rename to hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__emit_hugr_call@llvm14.snap diff --git a/hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__emit_hugr_call@pre-mem2reg@llvm14.snap b/hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__emit_hugr_call@pre-mem2reg@llvm14.snap similarity index 100% rename from hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__emit_hugr_call@pre-mem2reg@llvm14.snap rename to hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__emit_hugr_call@pre-mem2reg@llvm14.snap diff --git a/hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__emit_hugr_call_indirect@llvm14.snap b/hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__emit_hugr_call_indirect@llvm14.snap similarity index 100% rename from hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__emit_hugr_call_indirect@llvm14.snap rename to hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__emit_hugr_call_indirect@llvm14.snap diff --git a/hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__emit_hugr_call_indirect@pre-mem2reg@llvm14.snap b/hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__emit_hugr_call_indirect@pre-mem2reg@llvm14.snap similarity index 100% rename from hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__emit_hugr_call_indirect@pre-mem2reg@llvm14.snap rename to hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__emit_hugr_call_indirect@pre-mem2reg@llvm14.snap diff --git a/hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__emit_hugr_conditional@llvm14.snap b/hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__emit_hugr_conditional@llvm14.snap similarity index 100% rename from hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__emit_hugr_conditional@llvm14.snap rename to hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__emit_hugr_conditional@llvm14.snap diff --git a/hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__emit_hugr_conditional@pre-mem2reg@llvm14.snap b/hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__emit_hugr_conditional@pre-mem2reg@llvm14.snap similarity index 100% rename from hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__emit_hugr_conditional@pre-mem2reg@llvm14.snap rename to hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__emit_hugr_conditional@pre-mem2reg@llvm14.snap diff --git a/hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__emit_hugr_custom_op@llvm14.snap b/hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__emit_hugr_custom_op@llvm14.snap similarity index 100% rename from hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__emit_hugr_custom_op@llvm14.snap rename to hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__emit_hugr_custom_op@llvm14.snap diff --git a/hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__emit_hugr_custom_op@pre-mem2reg@llvm14.snap b/hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__emit_hugr_custom_op@pre-mem2reg@llvm14.snap similarity index 100% rename from hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__emit_hugr_custom_op@pre-mem2reg@llvm14.snap rename to hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__emit_hugr_custom_op@pre-mem2reg@llvm14.snap diff --git a/hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__emit_hugr_dfg@llvm14.snap b/hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__emit_hugr_dfg@llvm14.snap similarity index 100% rename from hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__emit_hugr_dfg@llvm14.snap rename to hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__emit_hugr_dfg@llvm14.snap diff --git a/hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__emit_hugr_dfg@pre-mem2reg@llvm14.snap b/hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__emit_hugr_dfg@pre-mem2reg@llvm14.snap similarity index 100% rename from hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__emit_hugr_dfg@pre-mem2reg@llvm14.snap rename to hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__emit_hugr_dfg@pre-mem2reg@llvm14.snap diff --git a/hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__emit_hugr_load_constant@llvm14.snap b/hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__emit_hugr_load_constant@llvm14.snap similarity index 100% rename from hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__emit_hugr_load_constant@llvm14.snap rename to hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__emit_hugr_load_constant@llvm14.snap diff --git a/hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__emit_hugr_load_constant@pre-mem2reg@llvm14.snap b/hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__emit_hugr_load_constant@pre-mem2reg@llvm14.snap similarity index 100% rename from hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__emit_hugr_load_constant@pre-mem2reg@llvm14.snap rename to hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__emit_hugr_load_constant@pre-mem2reg@llvm14.snap diff --git a/hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__emit_hugr_tag@llvm14.snap b/hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__emit_hugr_tag@llvm14.snap similarity index 100% rename from hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__emit_hugr_tag@llvm14.snap rename to hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__emit_hugr_tag@llvm14.snap diff --git a/hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__emit_hugr_tag@pre-mem2reg@llvm14.snap b/hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__emit_hugr_tag@pre-mem2reg@llvm14.snap similarity index 100% rename from hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__emit_hugr_tag@pre-mem2reg@llvm14.snap rename to hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__emit_hugr_tag@pre-mem2reg@llvm14.snap diff --git a/hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__load_function@llvm14.snap b/hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__load_function@llvm14.snap similarity index 100% rename from hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__load_function@llvm14.snap rename to hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__load_function@llvm14.snap diff --git a/hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__load_function@pre-mem2reg@llvm14.snap b/hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__load_function@pre-mem2reg@llvm14.snap similarity index 100% rename from hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__load_function@pre-mem2reg@llvm14.snap rename to hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__load_function@pre-mem2reg@llvm14.snap diff --git a/hugr-llvm/src/emit/test.rs b/hugr-llvm/src/emit/test.rs index 1fc9077f2..03c0878a0 100644 --- a/hugr-llvm/src/emit/test.rs +++ b/hugr-llvm/src/emit/test.rs @@ -1,30 +1,16 @@ -use std::iter; - -use crate::custom::CodegenExtsBuilder; -use crate::extension::int::add_int_extensions; use crate::types::HugrFuncType; use crate::utils::fat::FatNode; use anyhow::{anyhow, Result}; -use hugr_core::builder::DataflowSubContainer; use hugr_core::builder::{ - BuildHandle, Container, DFGWrapper, Dataflow, HugrBuilder, ModuleBuilder, SubContainer, + BuildHandle, Container, DFGWrapper, HugrBuilder, ModuleBuilder, SubContainer, }; -use hugr_core::extension::prelude::{ConstUsize, BOOL_T, USIZE_T}; -use hugr_core::extension::{ExtensionRegistry, EMPTY_REG, PRELUDE_REGISTRY}; -use hugr_core::ops::constant::CustomConst; +use hugr_core::extension::{ExtensionRegistry, EMPTY_REG}; use hugr_core::ops::handle::FuncID; -use hugr_core::ops::{CallIndirect, Tag, Value}; -use hugr_core::std_extensions::arithmetic::int_ops::{self, INT_OPS_REGISTRY}; -use hugr_core::std_extensions::arithmetic::int_types::ConstInt; -use hugr_core::types::{Signature, Type, TypeRow}; -use hugr_core::{type_row, Hugr, HugrView}; +use hugr_core::types::TypeRow; +use hugr_core::{Hugr, HugrView}; use inkwell::module::Module; use inkwell::passes::PassManager; use inkwell::values::GenericValue; -use itertools::Itertools; -use rstest::rstest; - -use crate::test::*; use super::EmitHugr; @@ -170,6 +156,13 @@ impl Default for SimpleHugrConfig { } } +#[doc(hidden)] +pub use hugr_core; +#[doc(hidden)] +pub use inkwell; +#[doc(hidden)] +pub use insta; + /// A macro used to check the emission of a Hugr module, /// and to assert the correctness of the emitted LLVM IR using [insta]. /// @@ -185,11 +178,15 @@ impl Default for SimpleHugrConfig { macro_rules! check_emission { // Call the macro with a snapshot name. ($snapshot_name:expr, $hugr: ident, $test_ctx:ident) => {{ - let root = $crate::utils::fat::FatExt::fat_root::(&$hugr).unwrap(); + let root = + $crate::utils::fat::FatExt::fat_root::<$crate::emit::test::hugr_core::ops::Module>( + &$hugr, + ) + .unwrap(); let emission = $crate::emit::test::Emission::emit_hugr(root, $test_ctx.get_emit_hugr()).unwrap(); - let mut settings = insta::Settings::clone_current(); + let mut settings = $crate::emit::test::insta::Settings::clone_current(); let new_suffix = settings .snapshot_suffix() .map_or("pre-mem2reg".into(), |x| format!("pre-mem2reg@{x}")); @@ -197,25 +194,25 @@ macro_rules! check_emission { settings.bind(|| { let mod_str = emission.module().to_string(); if $snapshot_name == "" { - insta::assert_snapshot!(mod_str) + $crate::emit::test::insta::assert_snapshot!(mod_str) } else { - insta::assert_snapshot!($snapshot_name, mod_str) + $crate::emit::test::insta::assert_snapshot!($snapshot_name, mod_str) } }); emission.verify().unwrap(); emission.opt(|| { - let pb = inkwell::passes::PassManager::create(()); + let pb = $crate::emit::test::inkwell::passes::PassManager::create(()); pb.add_promote_memory_to_register_pass(); pb }); let mod_str = emission.module().to_string(); if $snapshot_name == "" { - insta::assert_snapshot!(mod_str) + $crate::emit::test::insta::assert_snapshot!(mod_str) } else { - insta::assert_snapshot!($snapshot_name, mod_str) + $crate::emit::test::insta::assert_snapshot!($snapshot_name, mod_str) } emission }}; @@ -225,297 +222,326 @@ macro_rules! check_emission { }; } -#[rstest] -fn emit_hugr_tag(llvm_ctx: TestContext) { - let hugr = SimpleHugrConfig::new() - .with_outs(Type::new_unit_sum(3)) - .finish(|mut builder: DFGW| { - let tag = builder - .add_dataflow_op( - Tag::new(1, vec![vec![].into(), vec![].into(), vec![].into()]), - builder.input_wires(), - ) - .unwrap(); - builder.finish_with_outputs(tag.outputs()).unwrap() - }); - let _ = check_emission!(hugr, llvm_ctx); -} - -#[rstest] -fn emit_hugr_dfg(llvm_ctx: TestContext) { - let hugr = SimpleHugrConfig::new() - .with_ins(Type::UNIT) - .with_outs(Type::UNIT) - .finish(|mut builder: DFGW| { - let dfg = { - let b = builder - .dfg_builder(HugrFuncType::new_endo(Type::UNIT), builder.input_wires()) +#[cfg(test)] +mod test_fns { + use super::*; + use crate::custom::CodegenExtsBuilder; + use crate::extension::int::add_int_extensions; + use crate::types::HugrFuncType; + + use hugr_core::builder::DataflowSubContainer; + use hugr_core::builder::{Container, Dataflow, HugrBuilder, ModuleBuilder, SubContainer}; + use hugr_core::extension::prelude::{ConstUsize, BOOL_T, USIZE_T}; + use hugr_core::extension::{EMPTY_REG, PRELUDE_REGISTRY}; + use hugr_core::ops::constant::CustomConst; + + use hugr_core::ops::{CallIndirect, Tag, Value}; + use hugr_core::std_extensions::arithmetic::int_ops::{self, INT_OPS_REGISTRY}; + use hugr_core::std_extensions::arithmetic::int_types::ConstInt; + use hugr_core::types::{Signature, Type, TypeRow}; + use hugr_core::{type_row, Hugr}; + + use itertools::Itertools; + use rstest::rstest; + use std::iter; + + use crate::test::*; + #[rstest] + fn emit_hugr_tag(llvm_ctx: TestContext) { + let hugr = SimpleHugrConfig::new() + .with_outs(Type::new_unit_sum(3)) + .finish(|mut builder: DFGW| { + let tag = builder + .add_dataflow_op( + Tag::new(1, vec![vec![].into(), vec![].into(), vec![].into()]), + builder.input_wires(), + ) .unwrap(); - let w = b.input_wires(); - b.finish_with_outputs(w).unwrap() - }; - builder.finish_with_outputs(dfg.outputs()).unwrap() - }); - check_emission!(hugr, llvm_ctx); -} - -#[rstest] -fn emit_hugr_conditional(llvm_ctx: TestContext) { - let hugr = { - let input_v_rows: Vec = (0..3).map(Type::new_unit_sum).map_into().collect_vec(); - let output_v_rows = { - let mut r = input_v_rows.clone(); - r.reverse(); - r - }; + builder.finish_with_outputs(tag.outputs()).unwrap() + }); + let _ = check_emission!(hugr, llvm_ctx); + } - SimpleHugrConfig::new() - .with_ins(vec![Type::new_sum(input_v_rows.clone()), Type::UNIT]) - .with_outs(vec![Type::new_sum(output_v_rows.clone()), Type::UNIT]) + #[rstest] + fn emit_hugr_dfg(llvm_ctx: TestContext) { + let hugr = SimpleHugrConfig::new() + .with_ins(Type::UNIT) + .with_outs(Type::UNIT) .finish(|mut builder: DFGW| { - let cond = { - let [sum_input, other_input] = builder.input_wires_arr(); - let mut cond_b = builder - .conditional_builder( - (input_v_rows.clone(), sum_input), - [(Type::UNIT, other_input)], - vec![Type::new_sum(output_v_rows.clone()), Type::UNIT].into(), - ) + let dfg = { + let b = builder + .dfg_builder(HugrFuncType::new_endo(Type::UNIT), builder.input_wires()) .unwrap(); - for i in 0..3 { - let mut case_b = cond_b.case_builder(i).unwrap(); - let [case_input, other_input] = case_b.input_wires_arr(); - let tag = case_b - .add_dataflow_op(Tag::new(2 - i, output_v_rows.clone()), [case_input]) - .unwrap(); - case_b - .finish_with_outputs([tag.out_wire(0), other_input]) - .unwrap(); - } - cond_b.finish_sub_container().unwrap() + let w = b.input_wires(); + b.finish_with_outputs(w).unwrap() }; - let [o1, o2] = cond.outputs_arr(); - builder.finish_with_outputs([o1, o2]).unwrap() - }) - }; - check_emission!(hugr, llvm_ctx); -} - -#[rstest] -fn emit_hugr_load_constant(mut llvm_ctx: TestContext) { - llvm_ctx.add_extensions(add_int_extensions); - let v = Value::tuple([ - Value::unit_sum(2, 4).unwrap(), - ConstInt::new_s(4, -24).unwrap().into(), - ]); - - let hugr = SimpleHugrConfig::new() - .with_outs(v.get_type()) - .with_extensions(INT_OPS_REGISTRY.to_owned()) - .finish(|mut builder: DFGW| { - let konst = builder.add_load_value(v); - builder.finish_with_outputs([konst]).unwrap() - }); - check_emission!(hugr, llvm_ctx); -} - -#[rstest] -fn emit_hugr_call(llvm_ctx: TestContext) { - fn build_recursive(mod_b: &mut ModuleBuilder, name: &str, io: TypeRow) { - let f_id = mod_b - .declare(name, HugrFuncType::new_endo(io).into()) - .unwrap(); - let mut func_b = mod_b.define_declaration(&f_id).unwrap(); - let call = func_b - .call(&f_id, &[], func_b.input_wires(), &EMPTY_REG) - .unwrap(); - func_b.finish_with_outputs(call.outputs()).unwrap(); + builder.finish_with_outputs(dfg.outputs()).unwrap() + }); + check_emission!(hugr, llvm_ctx); } - let mut mod_b = ModuleBuilder::new(); - build_recursive(&mut mod_b, "main_void", type_row![]); - build_recursive(&mut mod_b, "main_unary", type_row![BOOL_T]); - build_recursive(&mut mod_b, "main_binary", type_row![BOOL_T, BOOL_T]); - let hugr = mod_b.finish_hugr(&EMPTY_REG).unwrap(); - check_emission!(hugr, llvm_ctx); -} + #[rstest] + fn emit_hugr_conditional(llvm_ctx: TestContext) { + let hugr = { + let input_v_rows: Vec = + (0..3).map(Type::new_unit_sum).map_into().collect_vec(); + let output_v_rows = { + let mut r = input_v_rows.clone(); + r.reverse(); + r + }; -#[rstest] -fn emit_hugr_call_indirect(llvm_ctx: TestContext) { - fn build_recursive(mod_b: &mut ModuleBuilder, name: &str, io: TypeRow) { - let signature = HugrFuncType::new_endo(io); - let f_id = mod_b.declare(name, signature.clone().into()).unwrap(); - let mut func_b = mod_b.define_declaration(&f_id).unwrap(); - let func = func_b.load_func(&f_id, &[], &EMPTY_REG).unwrap(); - let inputs = iter::once(func).chain(func_b.input_wires()); - let call_indirect = func_b - .add_dataflow_op(CallIndirect { signature }, inputs) - .unwrap(); - func_b.finish_with_outputs(call_indirect.outputs()).unwrap(); + SimpleHugrConfig::new() + .with_ins(vec![Type::new_sum(input_v_rows.clone()), Type::UNIT]) + .with_outs(vec![Type::new_sum(output_v_rows.clone()), Type::UNIT]) + .finish(|mut builder: DFGW| { + let cond = { + let [sum_input, other_input] = builder.input_wires_arr(); + let mut cond_b = builder + .conditional_builder( + (input_v_rows.clone(), sum_input), + [(Type::UNIT, other_input)], + vec![Type::new_sum(output_v_rows.clone()), Type::UNIT].into(), + ) + .unwrap(); + for i in 0..3 { + let mut case_b = cond_b.case_builder(i).unwrap(); + let [case_input, other_input] = case_b.input_wires_arr(); + let tag = case_b + .add_dataflow_op( + Tag::new(2 - i, output_v_rows.clone()), + [case_input], + ) + .unwrap(); + case_b + .finish_with_outputs([tag.out_wire(0), other_input]) + .unwrap(); + } + cond_b.finish_sub_container().unwrap() + }; + let [o1, o2] = cond.outputs_arr(); + builder.finish_with_outputs([o1, o2]).unwrap() + }) + }; + check_emission!(hugr, llvm_ctx); } - let mut mod_b = ModuleBuilder::new(); - build_recursive(&mut mod_b, "main_void", type_row![]); - build_recursive(&mut mod_b, "main_unary", type_row![BOOL_T]); - build_recursive(&mut mod_b, "main_binary", type_row![BOOL_T, BOOL_T]); - let hugr = mod_b.finish_hugr(&EMPTY_REG).unwrap(); - check_emission!(hugr, llvm_ctx); -} + #[rstest] + fn emit_hugr_load_constant(mut llvm_ctx: TestContext) { + llvm_ctx.add_extensions(add_int_extensions); + let v = Value::tuple([ + Value::unit_sum(2, 4).unwrap(), + ConstInt::new_s(4, -24).unwrap().into(), + ]); + + let hugr = SimpleHugrConfig::new() + .with_outs(v.get_type()) + .with_extensions(INT_OPS_REGISTRY.to_owned()) + .finish(|mut builder: DFGW| { + let konst = builder.add_load_value(v); + builder.finish_with_outputs([konst]).unwrap() + }); + check_emission!(hugr, llvm_ctx); + } -#[rstest] -fn emit_hugr_custom_op(mut llvm_ctx: TestContext) { - llvm_ctx.add_extensions(add_int_extensions); - let v1 = ConstInt::new_s(4, -24).unwrap(); - let v2 = ConstInt::new_s(4, 24).unwrap(); - - let hugr = SimpleHugrConfig::new() - .with_outs(v1.get_type()) - .with_extensions(INT_OPS_REGISTRY.to_owned()) - .finish_with_exts(|mut builder: DFGW, ext_reg| { - let k1 = builder.add_load_value(v1); - let k2 = builder.add_load_value(v2); - let ext_op = int_ops::EXTENSION - .instantiate_extension_op("iadd", [4.into()], ext_reg) + #[rstest] + fn emit_hugr_call(llvm_ctx: TestContext) { + fn build_recursive(mod_b: &mut ModuleBuilder, name: &str, io: TypeRow) { + let f_id = mod_b + .declare(name, HugrFuncType::new_endo(io).into()) .unwrap(); - let add = builder.add_dataflow_op(ext_op, [k1, k2]).unwrap(); - builder.finish_with_outputs(add.outputs()).unwrap() - }); - check_emission!(hugr, llvm_ctx); -} + let mut func_b = mod_b.define_declaration(&f_id).unwrap(); + let call = func_b + .call(&f_id, &[], func_b.input_wires(), &EMPTY_REG) + .unwrap(); + func_b.finish_with_outputs(call.outputs()).unwrap(); + } -#[rstest] -fn get_external_func(llvm_ctx: TestContext) { - let emc = llvm_ctx.get_emit_module_context(); - let func_type1 = emc.iw_context().i32_type().fn_type(&[], false); - let func_type2 = emc.iw_context().f64_type().fn_type(&[], false); - let foo1 = emc.get_extern_func("foo", func_type1).unwrap(); - assert_eq!(foo1.get_name().to_str().unwrap(), "foo"); - let foo2 = emc.get_extern_func("foo", func_type1).unwrap(); - assert_eq!(foo1, foo2); - assert!(emc.get_extern_func("foo", func_type2).is_err()); -} + let mut mod_b = ModuleBuilder::new(); + build_recursive(&mut mod_b, "main_void", type_row![]); + build_recursive(&mut mod_b, "main_unary", type_row![BOOL_T]); + build_recursive(&mut mod_b, "main_binary", type_row![BOOL_T, BOOL_T]); + let hugr = mod_b.finish_hugr(&EMPTY_REG).unwrap(); + check_emission!(hugr, llvm_ctx); + } -#[rstest] -fn diverse_module_children(llvm_ctx: TestContext) { - let hugr = { - let mut builder = ModuleBuilder::new(); - let _ = { - let fbuilder = builder - .define_function("f1", HugrFuncType::new_endo(type_row![])) + #[rstest] + fn emit_hugr_call_indirect(llvm_ctx: TestContext) { + fn build_recursive(mod_b: &mut ModuleBuilder, name: &str, io: TypeRow) { + let signature = HugrFuncType::new_endo(io); + let f_id = mod_b.declare(name, signature.clone().into()).unwrap(); + let mut func_b = mod_b.define_declaration(&f_id).unwrap(); + let func = func_b.load_func(&f_id, &[], &EMPTY_REG).unwrap(); + let inputs = iter::once(func).chain(func_b.input_wires()); + let call_indirect = func_b + .add_dataflow_op(CallIndirect { signature }, inputs) .unwrap(); - fbuilder.finish_sub_container().unwrap() - }; - let _ = { - let fbuilder = builder - .define_function("f2", HugrFuncType::new_endo(type_row![])) - .unwrap(); - fbuilder.finish_sub_container().unwrap() - }; - let _ = builder.add_constant(Value::true_val()); - let _ = builder - .declare("decl", HugrFuncType::new_endo(type_row![]).into()) - .unwrap(); - builder.finish_hugr(&EMPTY_REG).unwrap() - }; - check_emission!(hugr, llvm_ctx); -} + func_b.finish_with_outputs(call_indirect.outputs()).unwrap(); + } -#[rstest] -fn diverse_dfg_children(llvm_ctx: TestContext) { - let hugr = SimpleHugrConfig::new() - .with_outs(BOOL_T) - .finish(|mut builder: DFGW| { - let [r] = { - let mut builder = builder - .dfg_builder(HugrFuncType::new(type_row![], BOOL_T), []) + let mut mod_b = ModuleBuilder::new(); + build_recursive(&mut mod_b, "main_void", type_row![]); + build_recursive(&mut mod_b, "main_unary", type_row![BOOL_T]); + build_recursive(&mut mod_b, "main_binary", type_row![BOOL_T, BOOL_T]); + let hugr = mod_b.finish_hugr(&EMPTY_REG).unwrap(); + check_emission!(hugr, llvm_ctx); + } + + #[rstest] + fn emit_hugr_custom_op(mut llvm_ctx: TestContext) { + llvm_ctx.add_extensions(add_int_extensions); + let v1 = ConstInt::new_s(4, -24).unwrap(); + let v2 = ConstInt::new_s(4, 24).unwrap(); + + let hugr = SimpleHugrConfig::new() + .with_outs(v1.get_type()) + .with_extensions(INT_OPS_REGISTRY.to_owned()) + .finish_with_exts(|mut builder: DFGW, ext_reg| { + let k1 = builder.add_load_value(v1); + let k2 = builder.add_load_value(v2); + let ext_op = int_ops::EXTENSION + .instantiate_extension_op("iadd", [4.into()], ext_reg) .unwrap(); - let konst = builder.add_constant(Value::false_val()); - let func = { - let mut builder = builder - .define_function("scoped_func", HugrFuncType::new(type_row![], BOOL_T)) - .unwrap(); - let w = builder.load_const(&konst); - builder.finish_with_outputs([w]).unwrap() - }; - let [r] = builder - .call(func.handle(), &[], [], &EMPTY_REG) - .unwrap() - .outputs_arr(); - builder.finish_with_outputs([r]).unwrap().outputs_arr() + let add = builder.add_dataflow_op(ext_op, [k1, k2]).unwrap(); + builder.finish_with_outputs(add.outputs()).unwrap() + }); + check_emission!(hugr, llvm_ctx); + } + + #[rstest] + fn get_external_func(llvm_ctx: TestContext) { + let emc = llvm_ctx.get_emit_module_context(); + let func_type1 = emc.iw_context().i32_type().fn_type(&[], false); + let func_type2 = emc.iw_context().f64_type().fn_type(&[], false); + let foo1 = emc.get_extern_func("foo", func_type1).unwrap(); + assert_eq!(foo1.get_name().to_str().unwrap(), "foo"); + let foo2 = emc.get_extern_func("foo", func_type1).unwrap(); + assert_eq!(foo1, foo2); + assert!(emc.get_extern_func("foo", func_type2).is_err()); + } + + #[rstest] + fn diverse_module_children(llvm_ctx: TestContext) { + let hugr = { + let mut builder = ModuleBuilder::new(); + let _ = { + let fbuilder = builder + .define_function("f1", HugrFuncType::new_endo(type_row![])) + .unwrap(); + fbuilder.finish_sub_container().unwrap() }; - builder.finish_with_outputs([r]).unwrap() - }); - check_emission!(hugr, llvm_ctx); -} + let _ = { + let fbuilder = builder + .define_function("f2", HugrFuncType::new_endo(type_row![])) + .unwrap(); + fbuilder.finish_sub_container().unwrap() + }; + let _ = builder.add_constant(Value::true_val()); + let _ = builder + .declare("decl", HugrFuncType::new_endo(type_row![]).into()) + .unwrap(); + builder.finish_hugr(&EMPTY_REG).unwrap() + }; + check_emission!(hugr, llvm_ctx); + } -#[rstest] -fn diverse_cfg_children(llvm_ctx: TestContext) { - let hugr = SimpleHugrConfig::new() - .with_outs(BOOL_T) - .finish(|mut builder: DFGW| { - let [r] = { - let mut builder = builder.cfg_builder([], type_row![BOOL_T]).unwrap(); - let konst = builder.add_constant(Value::false_val()); - let func = { - let mut builder = builder - .define_function("scoped_func", HugrFuncType::new(type_row![], BOOL_T)) - .unwrap(); - let w = builder.load_const(&konst); - builder.finish_with_outputs([w]).unwrap() - }; - let entry = { + #[rstest] + fn diverse_dfg_children(llvm_ctx: TestContext) { + let hugr = SimpleHugrConfig::new() + .with_outs(BOOL_T) + .finish(|mut builder: DFGW| { + let [r] = { let mut builder = builder - .entry_builder([type_row![]], type_row![BOOL_T]) + .dfg_builder(HugrFuncType::new(type_row![], BOOL_T), []) .unwrap(); - let control = builder.add_load_value(Value::unary_unit_sum()); + let konst = builder.add_constant(Value::false_val()); + let func = { + let mut builder = builder + .define_function("scoped_func", HugrFuncType::new(type_row![], BOOL_T)) + .unwrap(); + let w = builder.load_const(&konst); + builder.finish_with_outputs([w]).unwrap() + }; let [r] = builder .call(func.handle(), &[], [], &EMPTY_REG) .unwrap() .outputs_arr(); - builder.finish_with_outputs(control, [r]).unwrap() + builder.finish_with_outputs([r]).unwrap().outputs_arr() }; - let exit = builder.exit_block(); - builder.branch(&entry, 0, &exit).unwrap(); - builder.finish_sub_container().unwrap().outputs_arr() - }; - builder.finish_with_outputs([r]).unwrap() - }); - check_emission!(hugr, llvm_ctx); -} + builder.finish_with_outputs([r]).unwrap() + }); + check_emission!(hugr, llvm_ctx); + } -#[rstest] -fn load_function(llvm_ctx: TestContext) { - let hugr = { - let mut builder = ModuleBuilder::new(); - let target_sig = Signature::new_endo(type_row![]); - let target_func = builder - .declare("target_func", target_sig.clone().into()) - .unwrap(); - let _ = { - let mut builder = builder - .define_function( - "main", - Signature::new(type_row![], Type::new_function(target_sig)), - ) + #[rstest] + fn diverse_cfg_children(llvm_ctx: TestContext) { + let hugr = SimpleHugrConfig::new() + .with_outs(BOOL_T) + .finish(|mut builder: DFGW| { + let [r] = { + let mut builder = builder.cfg_builder([], type_row![BOOL_T]).unwrap(); + let konst = builder.add_constant(Value::false_val()); + let func = { + let mut builder = builder + .define_function("scoped_func", HugrFuncType::new(type_row![], BOOL_T)) + .unwrap(); + let w = builder.load_const(&konst); + builder.finish_with_outputs([w]).unwrap() + }; + let entry = { + let mut builder = builder + .entry_builder([type_row![]], type_row![BOOL_T]) + .unwrap(); + let control = builder.add_load_value(Value::unary_unit_sum()); + let [r] = builder + .call(func.handle(), &[], [], &EMPTY_REG) + .unwrap() + .outputs_arr(); + builder.finish_with_outputs(control, [r]).unwrap() + }; + let exit = builder.exit_block(); + builder.branch(&entry, 0, &exit).unwrap(); + builder.finish_sub_container().unwrap().outputs_arr() + }; + builder.finish_with_outputs([r]).unwrap() + }); + check_emission!(hugr, llvm_ctx); + } + + #[rstest] + fn load_function(llvm_ctx: TestContext) { + let hugr = { + let mut builder = ModuleBuilder::new(); + let target_sig = Signature::new_endo(type_row![]); + let target_func = builder + .declare("target_func", target_sig.clone().into()) .unwrap(); - let r = builder.load_func(&target_func, &[], &EMPTY_REG).unwrap(); - builder.finish_with_outputs([r]).unwrap() + let _ = { + let mut builder = builder + .define_function( + "main", + Signature::new(type_row![], Type::new_function(target_sig)), + ) + .unwrap(); + let r = builder.load_func(&target_func, &[], &EMPTY_REG).unwrap(); + builder.finish_with_outputs([r]).unwrap() + }; + builder.finish_hugr(&EMPTY_REG).unwrap() }; - builder.finish_hugr(&EMPTY_REG).unwrap() - }; - check_emission!(hugr, llvm_ctx); -} + check_emission!(hugr, llvm_ctx); + } -#[rstest] -fn test_exec(mut exec_ctx: TestContext) { - let hugr = SimpleHugrConfig::new() - .with_outs(USIZE_T) - .with_extensions(PRELUDE_REGISTRY.to_owned()) - .finish(|mut builder: DFGW| { - let konst = builder.add_load_value(ConstUsize::new(42)); - builder.finish_with_outputs([konst]).unwrap() - }); - exec_ctx.add_extensions(CodegenExtsBuilder::add_default_prelude_extensions); - assert_eq!(42, exec_ctx.exec_hugr_u64(hugr, "main")); + #[rstest] + fn test_exec(mut exec_ctx: TestContext) { + let hugr = SimpleHugrConfig::new() + .with_outs(USIZE_T) + .with_extensions(PRELUDE_REGISTRY.to_owned()) + .finish(|mut builder: DFGW| { + let konst = builder.add_load_value(ConstUsize::new(42)); + builder.finish_with_outputs([konst]).unwrap() + }); + exec_ctx.add_extensions(CodegenExtsBuilder::add_default_prelude_extensions); + assert_eq!(42, exec_ctx.exec_hugr_u64(hugr, "main")); + } } diff --git a/hugr-llvm/src/lib.rs b/hugr-llvm/src/lib.rs index 7328ff2b6..98c161658 100644 --- a/hugr-llvm/src/lib.rs +++ b/hugr-llvm/src/lib.rs @@ -75,7 +75,7 @@ pub fn llvm_version() -> &'static str { panic!("No recognised llvm feature") } -#[cfg(test)] +#[cfg(any(test, feature = "test-utils"))] pub mod test; pub use custom::{CodegenExtension, CodegenExtsBuilder}; diff --git a/hugr/Cargo.toml b/hugr/Cargo.toml index 96e17ea79..aa76c5859 100644 --- a/hugr/Cargo.toml +++ b/hugr/Cargo.toml @@ -26,6 +26,7 @@ extension_inference = ["hugr-core/extension_inference"] declarative = ["hugr-core/declarative"] model_unstable = ["hugr-core/model_unstable", "hugr-model"] llvm = ["hugr-llvm/llvm14-0"] +llvm-test = ["hugr-llvm/llvm14-0", "hugr-llvm/test-utils"] [dependencies] hugr-model = { path = "../hugr-model", optional = true, version = "0.14.0" }