diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4f55a3a..12841e9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -36,7 +36,7 @@ repos: hooks: - id: cargo-fmt - id: cargo-clippy - args: ["--all-targets", "--all-features", "--", "-W", "clippy::pedantic", "-W", "clippy::nursery"] + args: ["--locked", "--all-targets", "--all-features", "--", "-D", "warnings", "-W", "clippy::pedantic", "-W", "clippy::nursery"] - id: cargo-test-doc args: ["--all-features"] - id: cargo-doc diff --git a/src/lib.rs b/src/lib.rs index b21aa19..f275f67 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -268,13 +268,13 @@ mod aux { ); } - pub(crate) struct ModuleFlags { + pub struct ModuleFlags { values: BTreeMap>, malformed: BTreeSet, } impl ModuleFlags { - pub(crate) fn get(&self, flag_name: &str) -> Option<&[String]> { + pub fn get(&self, flag_name: &str) -> Option<&[String]> { self.values.get(flag_name).map(Vec::as_slice) } @@ -283,7 +283,7 @@ mod aux { } } - pub(crate) fn collect_module_flags(module: &Module) -> ModuleFlags { + pub fn collect_module_flags(module: &Module) -> ModuleFlags { let mut values = BTreeMap::>::new(); let mut malformed = BTreeSet::new(); @@ -639,10 +639,10 @@ mod aux { "", ) } - .map_err(|e| format!("Failed to build GEP for qubit handle: {e}",))?; + .map_err(|e| format!("Failed to build GEP for qubit handle: {e}"))?; builder .build_load(i64_type, elem_ptr, "qbit") - .map_err(|e| format!("Failed to build load for qubit handle: {e}",))? + .map_err(|e| format!("Failed to build load for qubit handle: {e}"))? }; // Create ___lazy_measure call @@ -655,7 +655,7 @@ mod aux { let call = builder.build_call(meas_func, &[q_handle.into()], "meas"); let call_result = - call.map_err(|e| format!("Failed to build call for lazy measure function: {e}",))?; + call.map_err(|e| format!("Failed to build call for lazy measure function: {e}"))?; match call_result.try_as_basic_value() { inkwell::values::ValueKind::Basic(bv) => bv, inkwell::values::ValueKind::Instruction(_) => { @@ -698,7 +698,7 @@ mod aux { .ok_or_else(|| format!("{LOAD_QUBIT_FN} not found"))?; let idx_call = builder .build_call(idx_fn, &[qubit_ptr.into()], "qbit") - .map_err(|e| format!("Failed to build call to {LOAD_QUBIT_FN}: {e}",))?; + .map_err(|e| format!("Failed to build call to {LOAD_QUBIT_FN}: {e}"))?; let q_handle = match idx_call.try_as_basic_value() { inkwell::values::ValueKind::Basic(bv) => bv, inkwell::values::ValueKind::Instruction(_) => { @@ -1861,23 +1861,23 @@ attributes #0 = { "entry_point" "qir_profiles"="base_profile" "output_labeling_s let flags = collect_module_flags(&module); assert_eq!( - flags.get("qir_major_version").map(|values| values.to_vec()), + flags.get("qir_major_version").map(<[String]>::to_vec), Some(vec!["i32 2".to_string()]) ); assert_eq!( - flags.get("qir_minor_version").map(|values| values.to_vec()), + flags.get("qir_minor_version").map(<[String]>::to_vec), Some(vec!["i32 0".to_string()]) ); assert_eq!( flags .get("dynamic_qubit_management") - .map(|values| values.to_vec()), + .map(<[String]>::to_vec), Some(vec!["i1 false".to_string()]) ); assert_eq!( flags .get("dynamic_result_management") - .map(|values| values.to_vec()), + .map(<[String]>::to_vec), Some(vec!["i1 false".to_string()]) ); } diff --git a/src/opt.rs b/src/opt.rs index 1a37e58..9381406 100644 --- a/src/opt.rs +++ b/src/opt.rs @@ -82,27 +82,17 @@ fn get_target_machine(target: &str, opt_level: OptimizationLevel) -> Result Result<(), String> { - if opt_level > 0 { - return Err(format!( - "Optimized QIR-to-QIS conversion is currently unavailable on Windows with the LLVM 21 integration. Re-run with `opt_level=0` and preferably `target=\"native\"` (requested opt_level={opt_level}, target=\"{target}\")." - )); - } - Ok(()) -} - -#[cfg(not(windows))] -fn validate_windows_codegen_mode(_opt_level: u32, _target: &str) -> Result<(), String> { - Ok(()) -} - /// Optimize the given LLVM module using the specified optimization level and target architecture. /// /// # Errors /// Returns an error if module verification fails pub fn optimize(module: &Module, opt_level: u32, target: &str) -> Result<(), String> { - validate_windows_codegen_mode(opt_level, target)?; + #[cfg(windows)] + if opt_level > 0 { + return Err(format!( + "Optimized QIR-to-QIS conversion is currently unavailable on Windows with the LLVM 21 integration. Re-run with `opt_level=0` and preferably `target=\"native\"` (requested opt_level={opt_level}, target=\"{target}\")." + )); + } // O0 preserves semantics without running transformation passes. // Avoid creating a TargetMachine in this mode; TargetMachine teardown has