When does GHC produce unlifted `let` bindings?

Ben Gamari ben at smart-cactus.org
Mon Oct 30 04:55:52 UTC 2017



Sebastian Graf <sgraf1337 at gmail.com> writes:

> Hi folks,
>
> I was debugging a Core-to-Core transform for TEST=spec-inline
> <https://github.com/ghc/ghc/blob/fe04f3783b662c52c4a0ff36b2d62a7a575998a5/testsuite/tests/simplCore/should_compile/spec-inline.hs>
> and
> was wondering (yet again) why GHC produces unlifted `let` bindings in Core
> like it seems supposed to be doing
> <https://github.com/ghc/ghc/blob/fe04f3783b662c52c4a0ff36b2d62a7a575998a5/testsuite/tests/simplCore/should_compile/spec-inline.stderr#L68-L76>
> .
>
>    - Why doesn't this use `case` instead?
>    - Is there a semantic difference?

My understanding is that we use `case` in this case since there is no
thunk evaluation necessary. Recall that operationally (under STG) `case`
is what drives evaluation whereas `let` is simply allocation. In a
sense, bringing an unlifted binding into scope is closer to the latter
than the former, being a simple register assignment.

>    - Can `case` be used with unlifted types?

I'm honestly not sure what would happen in this case. It may work fine
or something may explode. I suspect CoreToStg will lower a case with an
unlifted scrutinee to a let, but perhaps not. If not then things likely
will blow up since, according to Note [Types in StgConApp], unlifted
values can't be let-bound in STG.

Cheers,

- Ben
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 487 bytes
Desc: not available
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20171030/f6d35a77/attachment.sig>


More information about the ghc-devs mailing list