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

Question: how are specs communicated between modules? #2392

Closed
gergoerdi opened this issue Oct 17, 2024 · 3 comments
Closed

Question: how are specs communicated between modules? #2392

gergoerdi opened this issue Oct 17, 2024 · 3 comments

Comments

@gergoerdi
Copy link
Contributor

gergoerdi commented Oct 17, 2024

I'm looking for an explanation of how LH manages the inter-module flow of information.

For example, suppose I have one module that looks like this:

module Liquid.Prelude where

{-@
embed Bool as bool
assume True  :: {v:Bool | v     }
assume False :: {v:Bool | (~ v) }
@-}

and another one that looks like this:

{-# LANGUAGE LambdaCase #-}
module Liquid.Hello where

import Liquid.Prelude

{-@ foo :: x:Bool -> { v:Bool | x || v } @-}
foo :: Bool -> Bool
foo = \case
    True -> False
    False -> True

For LH to check this second module, it has to have access to the embedding of Bool as the logic type from the first module. How does that work / how is that supposed to work?

My initial suspicion is that everything is put into the typechecked module in serialiseSpec, but then that should mean that anything that works with ModIfaces built from typechecked modules should work. The motivation for my question is that I have a program that uses the GHC API (instead of the GHC executable) to compile Haskell(ish) programs, and the above example fails with:

Source error while processing module Liquid.Hello:
  Liquid.Hello:6:12: error:
      Illegal type specification for `Liquid.Hello.foo`
    Liquid.Hello.foo :: x:GHC.Types.Bool -> {v : GHC.Types.Bool | x
                                                                  || v}
    Sort Error in Refinement: {v : GHC.Types.Bool | x
                                                    || v}
    Expressions x should have bool sort, but has GHC.Types.Bool
    Just

(It does, of course, work when processed with real GHC and the vanilla LH plugin)

@gergoerdi
Copy link
Contributor Author

Actually, turns out that Liquid.Prelude module doesn't work so well with vanilla LH/GHC either, see #2393...

@facundominguez
Copy link
Collaborator

As far as I understand, loadDependencies is getting the annotations from dependencies.

@gergoerdi
Copy link
Contributor Author

As far as I understand, loadDependencies is getting the annotations from dependencies.

Thanks, this has been helpful. My problem was that when GHC builds the ModDetails that goes into the TypecheckedModule, the annotations are not copied from the TcGblEnv. So if you build a ModIface from that ModDetails, the annotations will be lost.

After copying manually the annotations from tcg_anns into md_anns before converting to ModIface, it seems to work now (modulo #2393 of course).

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

2 participants