Skip to content

Commit

Permalink
Restore record printing functionality (OCamlPro#793)
Browse files Browse the repository at this point in the history
This got lost somewhere along the way as the conditions for model
generation changed.

Note that it is a bit weird that the accumulation of record accesses
happens in `models.ml` while the accumulation of array accesses happens
in `uf.ml`.  We should pick a single one for both (probably in `models`
but even better would be to expose the appropriate APIs so that each
theory can build its own model values), but for now this patch should
wrangle the `if`s properly and restore the existing functionality.
  • Loading branch information
bclement-ocp authored Sep 5, 2023
1 parent 0d3a4e2 commit 3fa9b54
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/lib/frontend/models.ml
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,13 @@ module SmtlibCounterExample = struct
else
reps_aux representants
in
print_fun_def fmt f xs_ty_named ty rep;
(* Only print declared (but not defined!) function symbols -- note
that we still need to *handle* other symbols without printing them
because they could be record accessors that must be added to the
`records` reference *)
match f with
| Sy.Name (_, _, false) -> print_fun_def fmt f xs_ty_named ty rep
| _ -> ()
) fprofs;
!records
end
Expand Down
4 changes: 3 additions & 1 deletion src/lib/reasoners/uf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,9 @@ let compute_concrete_model ({ make; _ } as env) =
ME.fold
(fun t _mk ((fprofs, cprofs, carrays, mrepr) as acc) ->
let { E.f; xs; ty; _ } = E.term_view t in
if X.is_solvable_theory_symbol f ty
(* Keep record constructors because models.ml expects them to be there *)
if (X.is_solvable_theory_symbol f ty
&& not (Shostak.Records.is_mine_symb f ty))
|| E.is_fresh t || E.is_fresh_skolem t
|| E.equal t E.vrai || E.equal t E.faux
then
Expand Down
25 changes: 25 additions & 0 deletions tests/dune.inc
Original file line number Diff line number Diff line change
Expand Up @@ -186828,6 +186828,31 @@
; Auto-generated part end
; File auto-generated by gentests

; Auto-generated part begin
(subdir models/records
(rule
(target record1.models_tableaux.output)
(deps (:input record1.models.smt2))
(package alt-ergo)
(action
(chdir %{workspace_root}
(with-stdout-to %{target}
(ignore-stderr
(with-accepted-exit-codes 0
(run %{bin:alt-ergo}
--output=smtlib2
--frontend dolmen
--timelimit=2
--sat-solver Tableaux
%{input})))))))
(rule
(alias runtest-quick)
(package alt-ergo)
(action
(diff record1.models.expected record1.models_tableaux.output))))
; Auto-generated part end
; File auto-generated by gentests

; Auto-generated part begin
(subdir models/uf
(rule
Expand Down
5 changes: 5 additions & 0 deletions tests/models/records/record1.models.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

unknown
(
(define-fun a () Pair (pair 5 0))
)
8 changes: 8 additions & 0 deletions tests/models/records/record1.models.smt2
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(set-logic ALL)
(set-option :produce-models true)
(declare-datatype Pair
((pair (first Int) (second Int))))
(declare-const a Pair)
(assert (= (first a) 5))
(check-sat)
(get-model)

0 comments on commit 3fa9b54

Please sign in to comment.