Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,829
    • Issues 4,829
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 444
    • Merge requests 444
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
    • Value stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #20864

Closed
Open
Created Dec 24, 2021 by David Feuer@treeowlReporter

TransformListComp accepts invalid unboxed let bindings

Summary

let bindings with unboxed types in transformed list comprehensions desugar to invalid Core.

Steps to reproduce

{-# language MagicHash, TransformListComp #-}
module TLC where
import GHC.Exts

glum :: [Int] -> [Int]
glum xs = [I# p | I# x <- xs, let p = x +# 3#, then take 3]

This fails Core Lint. With optimizations enabled, it desugars like the following, but it's desugared just as invalidly when optimizations are disabled.

glum :: [Int] -> [Int]
[LclIdX]
glum
  = \ (xs_aw5 :: [Int]) ->
      build
        @Int
        (\ (@a_dye) (c_dyf :: Int -> a_dye -> a_dye) (n_dyg :: a_dye) ->
           GHC.Base.foldr
             @Int#
             @a_dye
             (\ (ds_dyv :: Int#) (ds_dyu :: a_dye) ->
                let {
                  p_axE :: Int#
                  [LclId]
                  p_axE = ds_dyv } in
                c_dyf ((\ (ds_dyw :: Int#) -> GHC.Types.I# ds_dyw) p_axE) ds_dyu)
             n_dyg
             ((\ (@a_axU) -> take @a_axU (GHC.Types.I# 3#))
                @Int#
                (build
                   @Int#
                   (\ (@a_dyh) (c_dyi :: Int# -> a_dyh -> a_dyh) (n_dyj :: a_dyh) ->
                      GHC.Base.foldr
                        @Int
                        @a_dyh
                        (\ (ds_dyl :: Int) (ds_dyk :: a_dyh) ->
                           case ds_dyl of wild_00 { I# x_axD ->
                           let {
                             p_axR :: Int#
                             [LclId]
                             p_axR = +# x_axD 3# } in
                           let {
                             p_axE :: Int#
                             [LclId]
                             p_axE = p_axR } in
                           c_dyi p_axE ds_dyk
                           })
                        n_dyj
                        xs_aw5))))
end Rec }

Note that one application each of foldr and build are at type Int#, which has the wrong kind.

Expected behavior

I expect this particular example to be rejected by the type checker. However, I would expect the following to continue to work:

loom :: [Int] -> [Int]
loom xs = [z | I# x <- xs, let p = x +# 3#, z <- [1 .. I# p], then take 3]

Note: I've included a "runtime crash" tag even though I haven't written an example that crashes because my informal testing strongly indicates invalid memory accesses that don't happen to segfault.

Environment

  • GHC version used:

Optional:

  • Operating System:
  • System Architecture:
Edited Dec 24, 2021 by David Feuer
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking