Skip to content

Commit 53d55df

Browse files
authored
Back-translate the SMTLIB unary minus, ignore models in "get-model" tests (#4033)
This is a bridge PR that we need before bumping Z3 to 4.13.0. - modify `test/rpc-server/runTests.py` to not compare the actual model from `"get-model"` responses, as it may be non-deterministic. Only compare the `"satisfiable"` field, i.e. model existence; - when back-translating the results of `"get-model"` from SMTLIB2 s-expression to Kore, allow unary minus.
1 parent 08dbeab commit 53d55df

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

kore/src/Kore/Rewrite/SMT/Translate.hs

+12-2
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,12 @@ backTranslateWith
533533
backTranslate (List xs)
534534
| null xs =
535535
throwError "backtranslate: empty list"
536+
-- special case for the unary minus, back-translating 'List ["-", "X"]' as '-X'
537+
| [Atom "-", arg] <- xs = do
538+
arg' <- backTranslate arg
539+
case arg' of
540+
InternalInt_ (InternalInt intSort n) -> pure . TermLike.mkInternalInt $ InternalInt intSort (negate n)
541+
other -> throwError $ "unable to translate negation of " <> show other
536542
-- everything is translated back using symbol declarations,
537543
-- not ML connectives (translating terms not predicates)
538544
| (fct@Atom{} : rest) <- xs
@@ -561,12 +567,16 @@ backTranslateWith
561567
Map.map symbolFrom
562568
. invert
563569
. Map.map AST.symbolData
564-
$ Map.filter (not . isBuiltin . AST.symbolDeclaration) symbols
570+
$ Map.filter ((\sym -> (not (isBuiltin sym) || isMinus sym)) . AST.symbolDeclaration) symbols
565571

566-
isBuiltin :: AST.KoreSymbolDeclaration a b -> Bool
572+
isBuiltin :: AST.KoreSymbolDeclaration SExpr SExpr -> Bool
567573
isBuiltin AST.SymbolBuiltin{} = True
568574
isBuiltin _other = False
569575

576+
isMinus :: AST.KoreSymbolDeclaration SExpr SExpr -> Bool
577+
isMinus (AST.SymbolBuiltin (AST.IndirectSymbolDeclaration{name})) = name == Atom "-"
578+
isMinus _other = False
579+
570580
symbolFrom :: Id -> Symbol
571581
symbolFrom name =
572582
Symbol

test/rpc-server/runTests.py

+33-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,34 @@ def checkGolden (resp, resp_golden_path):
103103
info(f"Golden file {red}not found{endred}")
104104
exit(1)
105105

106-
106+
def checkGoldenGetModel(resp, resp_golden_path):
107+
'''Almost exactly like checkGolden, but only compares the result->satisfiable field of the reponses'''
108+
if os.path.exists(resp_golden_path):
109+
debug("Checking against golden file...")
110+
with open(resp_golden_path, 'rb') as resp_golden_raw:
111+
golden_json = json.loads(resp_golden_raw.read())
112+
resp_json = json.loads(resp)
113+
if golden_json.get("result", {"IMPOSSIBLE": "IMPOSSIBLE"}).get("satisfiable", "IMPOSSIBLE") != resp_json.get("result", {}).get("satisfiable", ""):
114+
print(f"Test '{name}' {red}failed.{endred}")
115+
info(diff_strings(str(golden_json), str(resp)))
116+
if RECREATE_BROKEN_GOLDEN:
117+
with open(resp_golden_path, 'wb') as resp_golden_writer:
118+
resp_golden_writer.write(resp)
119+
else:
120+
info("Expected")
121+
info(golden_json)
122+
info("but got")
123+
info(resp)
124+
exit(1)
125+
else:
126+
info(f"Test '{name}' {green}passed{endgreen}")
127+
elif CREATE_MISSING_GOLDEN or RECREATE_BROKEN_GOLDEN:
128+
with open(resp_golden_path, 'wb') as resp_golden_writer:
129+
resp_golden_writer.write(resp)
130+
else:
131+
debug(resp)
132+
info(f"Golden file {red}not found{endred}")
133+
exit(1)
107134

108135
def runTest(def_path, req, resp_golden_path, smt_tactic = None):
109136
smt_options = ["--smt-tactic", str(smt_tactic)] if smt_tactic else []
@@ -122,7 +149,11 @@ def runTest(def_path, req, resp_golden_path, smt_tactic = None):
122149
debug(resp)
123150
process.kill()
124151

125-
checkGolden(resp, resp_golden_path)
152+
req_method = json.loads(req)["method"]
153+
if req_method == "get-model":
154+
checkGoldenGetModel(resp, resp_golden_path)
155+
else:
156+
checkGolden(resp, resp_golden_path)
126157

127158
print("Running execute tests:")
128159

0 commit comments

Comments
 (0)