Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Excessive constraints generated by lemma applications #1944

Open
rybla opened this issue Feb 20, 2022 · 5 comments
Open

Excessive constraints generated by lemma applications #1944

rybla opened this issue Feb 20, 2022 · 5 comments

Comments

@rybla
Copy link

rybla commented Feb 20, 2022

Consider this schema:

{-@ measure r :: Int -> Bool @-}

{-@ assume lem :: x:{Int | r x} -> {r (x + 1)} @-}
lem :: Int -> ()
lem _ = ()

with :: a -> b -> a
with a _ = a

{-@
test :: x:{Int | r x} -> {r (x + N)}
@-}
test :: Int -> ()
test x = 
  lem x `with`
  lem (x + 1) `with`
  ...
  lem (x + (N - 1))

where N is some constant integer greater than 1.

I noticed that the number of constraints generated by this simple schema seems excessive. Here is some data, where "lemma applications" corresponds to the N above:

Lemma application constraint generation.pdf

Visual summary:
Lemma application constraint generation

The data covers a few variants:

"with TH" indicates that the imports

import Language.Haskell.TH
import Language.Haskell.TH.Quote
import Language.Haskell.TH.Syntax

were included at the beginning of the file.

"without TH" indicates that those imports were not included at the beginning of the file.

"monomorphic with" indicates that with was retyped to be with :: a -> a -> a.

So, why are so many constraints being generated (20,000+ for just 10 applications of the simple lemma!) and why does it depend on importing the TH modules (which are not used in the code) and whether with is monomorphic or not?

@facundominguez
Copy link
Collaborator

I can't reproduce very well with develop. I only get near 700 and 800 constraints at most in all cases. Are you testing with the latest liquidhaskell on hackage maybe?

Also, Proof is not in scope in the example. I replaced it with ().

If I use

with :: () -> () -> ()

then I get only 19 constraints checked.

Polymorphism is known to cause some explosions elsewhere.

@ranjitjhala
Copy link
Member

ranjitjhala commented Feb 20, 2022 via email

@rybla
Copy link
Author

rybla commented Feb 21, 2022

Yeah I think its the polymorphism that is responsible for the constraint explosions.

@rybla
Copy link
Author

rybla commented Feb 21, 2022

I am using liquidhaskell == 0.8.10.7

@rybla
Copy link
Author

rybla commented Feb 21, 2022

Any idea about the TH imports?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants