Recover from wrong use of get-info :reason-unknown (#2667)
authorAndres Noetzli <andres.noetzli@gmail.com>
Mon, 22 Oct 2018 16:12:47 +0000 (09:12 -0700)
committerGitHub <noreply@github.com>
Mon, 22 Oct 2018 16:12:47 +0000 (09:12 -0700)
Fixes #2584. Currently, we are immediately terminating CVC4 if the user
issues a `(get-info :reason-unknown)` command if it didn't succeed a
`(check-sat)` call returning `unknown`. This commit changes the behavior
to return an `(error ...)` but continue executing afterwards. It turns
the `ModalException` thrown in this case into a
`RecoverableModalException` and adds a check in
`GetInfoCommand::invoke()` to turn it into a
`CommandRecoverableFailure`, which solves the issue.

src/smt/command.cpp
src/smt/smt_engine.cpp
test/regress/CMakeLists.txt
test/regress/regress0/smtlib/reason-unknown.smt2 [new file with mode: 0644]

index 51cb6663fdf6b82bf83bc7f58b5e81ebdbb9d8cd..5198ea2d1ab8935e1e155f81467960bdd9e185fe 100644 (file)
@@ -2438,6 +2438,10 @@ void GetInfoCommand::invoke(SmtEngine* smtEngine)
   {
     d_commandStatus = new CommandUnsupported();
   }
+  catch (RecoverableModalException& e)
+  {
+    d_commandStatus = new CommandRecoverableFailure(e.what());
+  }
   catch (exception& e)
   {
     d_commandStatus = new CommandFailure(e.what());
index 149d8bb3571d53bbe4ec1be74b82830f5134afa7..9a0d969d8bc28d9fd030d40f3ec817bfb38f4a98 100644 (file)
@@ -2412,8 +2412,9 @@ CVC4::SExpr SmtEngine::getInfo(const std::string& key) const {
       transform(s.begin(), s.end(), s.begin(), ::tolower);
       return SExpr(SExpr::Keyword(s));
     } else {
-      throw ModalException("Can't get-info :reason-unknown when the "
-                           "last result wasn't unknown!");
+      throw RecoverableModalException(
+          "Can't get-info :reason-unknown when the "
+          "last result wasn't unknown!");
     }
   } else if(key == "assertion-stack-levels") {
     AlwaysAssert(d_userLevels.size() <=
index e489d2e216460475b614df3e406c3218a1f41b91..5aea954e3e6d87dfebdba4617c2c982b899f53ea 100644 (file)
@@ -801,6 +801,7 @@ set(regress_0_tests
   regress0/smallcnf.cvc
   regress0/smt2output.smt2
   regress0/smtlib/get-unsat-assumptions.smt2
+  regress0/smtlib/reason-unknown.smt2
   regress0/strings/bug001.smt2
   regress0/strings/bug002.smt2
   regress0/strings/bug612.smt2
diff --git a/test/regress/regress0/smtlib/reason-unknown.smt2 b/test/regress/regress0/smtlib/reason-unknown.smt2
new file mode 100644 (file)
index 0000000..a4eecf2
--- /dev/null
@@ -0,0 +1,5 @@
+; EXPECT: (error "Can't get-info :reason-unknown when the last result wasn't unknown!")
+; EXPECT: sat
+(set-logic QF_SAT)
+(get-info :reason-unknown)
+(check-sat)