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

'let' getting changed into 'case' in a RULE #178

Open
roboguy13 opened this issue Oct 4, 2016 · 2 comments
Open

'let' getting changed into 'case' in a RULE #178

roboguy13 opened this issue Oct 4, 2016 · 2 comments
Labels

Comments

@roboguy13
Copy link
Member

I have a RULE:

{-# RULES "abs/let-float" [~]
    forall x v.
    abs (let bnd = v in x)
      =
    let bnd = v
    in
    abs x
  #-}

When I try to bring it into a lemma with rule-to-lemma (or look at it with show-rule), it "becomes":

abs/let-float (Not Proven)
  ∀ △ △ $dLift $d~ x v.
  abs ▲ $dLift $d~
      (case v of bnd ▲
         _ → x)
  ≡
  case HEq_sc ▲ ▲ ▲ ▲ ($p1~ ▲ ▲ ▲ $d~) of cobox ▲
    _ →
      case v of bnd ▲
        _ → abs ▲ $dLift (($d~ ▹ (■ ∷ ▲ ~R ▲)) ▹ (■ ∷ ▲ ~R ▲)) x

I imagine this is something GHC is doing, not HERMIT. As a result of this (I think), I cannot apply it where I would like to (where there is a let, not a case). I know that case and let have different semantics in Core with regard to strictness, so I imagine this is why I can't apply it in those places.

Is there a way around this or a way to tell it to keep it as let?

@xich
Copy link
Member

xich commented Oct 4, 2016

Yes, this is GHC enforcing the let/app invariant:

https://github.com/ghc/ghc/blob/68f72f101d67b276aff567be03619a3fd9618017/compiler/coreSyn/CoreSyn.hs#L355

It is because the let is built with mkCoreLets:

https://downloads.haskell.org/~ghc/latest/docs/html/libraries/ghc-8.0.1/MkCore.html#v:mkCoreLets

Your best bet is probably to build the lemma directly, instead of via a rule. You could define your own library, e.g.

https://github.com/ku-fpg/hermit-reasoning-14/blob/master/Reasoning-with-the-HERMIT/MakingACentury/hermit-century-lemmas/HERMIT/Libraries/Century.hs

The appendix of the reasoning paper sort of explains what is going on there:

http://ku-fpg.github.io/files/Farmer-15-HERMIT-reasoning.pdf

@xich
Copy link
Member

xich commented Oct 4, 2016

FWIW, mkLets will build let expressions without enforcing the invariant:

https://downloads.haskell.org/~ghc/latest/docs/html/libraries/ghc-8.0.1/CoreSyn.html#v:mkLets

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

No branches or pull requests

2 participants