Skip to content

Commit 488804a

Browse files
committed
Allow "-" when back-translating
Back-translate (wrongly) unary minus Special-case the test script for get-model Remove special case for "-" Special-case unary minus in a different way add comment
1 parent 08dbeab commit 488804a

File tree

2 files changed

+43
-4
lines changed

2 files changed

+43
-4
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,11 @@ 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 '0 - X'
537+
| [fct@(Atom "-"), arg] <- xs
538+
, Just koreSym <- Map.lookup fct reverseMetadata = do
539+
arg' <- backTranslate arg
540+
pure $ TermLike.mkApplySymbol koreSym [mkInternalInt (InternalInt (simpleSort "SortInt") 0), arg']
536541
-- everything is translated back using symbol declarations,
537542
-- not ML connectives (translating terms not predicates)
538543
| (fct@Atom{} : rest) <- xs
@@ -563,8 +568,11 @@ backTranslateWith
563568
. Map.map AST.symbolData
564569
$ Map.filter (not . isBuiltin . AST.symbolDeclaration) symbols
565570

566-
isBuiltin :: AST.KoreSymbolDeclaration a b -> Bool
567-
isBuiltin AST.SymbolBuiltin{} = True
571+
isBuiltin :: AST.KoreSymbolDeclaration SExpr SExpr -> Bool
572+
isBuiltin (AST.SymbolBuiltin (AST.IndirectSymbolDeclaration{name})) =
573+
case name of
574+
Atom "-" -> False
575+
_ -> True
568576
isBuiltin _other = False
569577

570578
symbolFrom :: Id -> Symbol

test/rpc-server/runTests.py

Lines changed: 33 additions & 2 deletions
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["result"]["satisfiable"] != resp_json["result"]["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)