See Note [CoreSyn let/app invariant] in CoreSyn.

 

Briefly, you can write

            let x::Int# = e in …

if e is “ok-for-speculation”.  See extensive comments in CoreUtils on what that means.

 

You could also use case, but let-bindings “float” more easily than cases, because they are not worried about preserving exception behaviour.

 

Simon

 

From: ghc-devs [mailto:ghc-devs-bounces@haskell.org] On Behalf Of Sebastian Graf
Sent: 29 October 2017 21:07
To: ghc-devs <ghc-devs@haskell.org>
Subject: When does GHC produce unlifted `let` bindings?

 

Hi folks,

 

I was debugging a Core-to-Core transform for TEST=spec-inline and was wondering (yet again) why GHC produces unlifted `let` bindings in Core like it seems supposed to be doing.

  • Why doesn't this use `case` instead? 
  • Is there a semantic difference? 
  • Can `case` be used with unlifted types? 
  • And if not, why can `let`?

Unlifted `let` seems much close to `case` than to `let`. Some GHC passes seem to agree.

 

Cheers,

Sebastian