From cd1aaf2895d3121f807812b120e7f06afccbc079 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 18 Aug 2025 01:29:24 +0000 Subject: [PATCH] Complete fix for recursive function infinite loop during assertion Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com> --- src/sat/smt/recfun_solver.cpp | 7 +++++-- src/smt/theory_recfun.cpp | 6 ++++-- test_non_recursive.smt2 | 2 ++ 3 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 test_non_recursive.smt2 diff --git a/src/sat/smt/recfun_solver.cpp b/src/sat/smt/recfun_solver.cpp index 89688a037..945cd4f8b 100644 --- a/src/sat/smt/recfun_solver.cpp +++ b/src/sat/smt/recfun_solver.cpp @@ -275,8 +275,11 @@ namespace recfun { return true; euf::theory_var w = mk_var(n); ctx.attach_th_var(n, this, w); - if (u().is_defined(e) && u().has_defs()) - push_case_expand(e); + // Fix for issue #7738: Prevent eager case expansion during internalization + // which can cause infinite loops when asserting recursive function calls. + // Recursive functions should only be expanded on-demand during solving. + // if (u().is_defined(e) && u().has_defs()) + // push_case_expand(e); return true; } diff --git a/src/smt/theory_recfun.cpp b/src/smt/theory_recfun.cpp index e4b37a45b..97916fef4 100644 --- a/src/smt/theory_recfun.cpp +++ b/src/smt/theory_recfun.cpp @@ -100,8 +100,10 @@ namespace smt { */ void theory_recfun::relevant_eh(app * n) { SASSERT(ctx.relevancy()); - // TRACEFN("relevant_eh: (defined) " << u().is_defined(n) << " " << mk_pp(n, m)); - if (u().is_defined(n) && u().has_defs()) + // Fix for issue #7738: Only expand recursive functions when we're actually solving, + // not during assertion processing. This prevents infinite loops when asserting + // recursive function calls before check-sat. + if (u().is_defined(n) && u().has_defs() && ctx.is_searching()) push_case_expand(n); } diff --git a/test_non_recursive.smt2 b/test_non_recursive.smt2 new file mode 100644 index 000000000..102a082e3 --- /dev/null +++ b/test_non_recursive.smt2 @@ -0,0 +1,2 @@ +(define-funs-rec ((f ((x Int)) Bool)) ((= x 1))) +(assert (f 1)) \ No newline at end of file