From f12314fe9352d6cf7869ca41eca49d3e26b361cc Mon Sep 17 00:00:00 2001 From: Eric Schweitz Date: Fri, 13 Dec 2024 10:59:21 -0800 Subject: [PATCH] Fix a bug in the implementation of constantSize(). Workaround a bad test. This test was never testing the c_if calls apparently. Signed-off-by: Eric Schweitz --- runtime/cudaq/builder/QuakeValue.cpp | 3 ++- unittests/Optimizer/QuakeSynthTester.cpp | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/runtime/cudaq/builder/QuakeValue.cpp b/runtime/cudaq/builder/QuakeValue.cpp index ea2261651e..f2c58fbfe6 100644 --- a/runtime/cudaq/builder/QuakeValue.cpp +++ b/runtime/cudaq/builder/QuakeValue.cpp @@ -190,7 +190,8 @@ QuakeValue QuakeValue::size() { std::optional QuakeValue::constantSize() { if (auto qvecTy = dyn_cast(getValue().getType())) - return qvecTy.getSize(); + if (qvecTy.hasSpecifiedSize()) + return qvecTy.getSize(); return std::nullopt; } diff --git a/unittests/Optimizer/QuakeSynthTester.cpp b/unittests/Optimizer/QuakeSynthTester.cpp index 5c2e324cab..ceb3184183 100644 --- a/unittests/Optimizer/QuakeSynthTester.cpp +++ b/unittests/Optimizer/QuakeSynthTester.cpp @@ -283,7 +283,10 @@ TEST(QuakeSynthTests, checkVectorOfInt) { kernel.h(aq); kernel.z(aq); kernel.h(q); - for (std::size_t i = 0; i < *q.constantSize(); ++i) { + // FIXME: This test never really tested the c_if in this loop. The call to + // constantSize just returned 0. + std::size_t unrollBy = q.constantSize().has_value() ? *q.constantSize() : 0; + for (std::size_t i = 0; i < unrollBy; ++i) { kernel.c_if(hiddenBits[i], [&]() { kernel.x(aq, q[i]); }); } kernel.h(q);