ucsd-progsys / liquidhaskell

Liquid Types For Haskell
BSD 3-Clause "New" or "Revised" License
1.18k stars 134 forks source link

[question] how to see the formula that gets sent to the solver? #2259

Closed jwaldmann closed 7 months ago

jwaldmann commented 7 months ago

I want to show liquid Haskell as an application of constraint programming. You are using QF_UFLRA?

Is there an easy way to see the actual formula that gets sent to the backend solver? (and the answer). I guess I could put a fake z3 executable in my PATH that does some extra printing but I was hoping there is something more direct.

ranjitjhala commented 7 months ago

Hi @jwaldmann -- yes, there is an easy way:

So you can see the generated SMT queries in the latter file.

I should say though, that the latter is not terribly readable, owing to the various intermediate layers of abstractions introduced by GHC, the liquid type checking and the SMT translation!

If you like you may be interested in this stripped down version of LH

https://github.com/ranjitjhala/sprite-lang

which uses many of the same ideas, but where you can look at the constraints more easily, both as

  1. The "Horn Constraints" generated by refinement type checking, and
  2. The "SMTLIB" queries generated to solve the horn constraints (1).
jwaldmann commented 7 months ago

interesting! yes I only need small examples, readability is good. I can build and run "sprite".

facundominguez commented 7 months ago

@jwaldmann, is this issue good to close?

jwaldmann commented 7 months ago

Yeah it's fine. I just copy here a code snippet buried in another issue https://github.com/ucsd-progsys/liquidhaskell/issues/2261#issuecomment-1915945047 that shows how to call the constraint solver directly:

cat tests/neg/.liquid/Fail.hs.smt2 |sed -e 's/Str/String/g' -e 's/strLen/str.len/g' | z3 /dev/stdin 
unsat
sat