Skip to content
GitLab
Projects Groups Snippets
  • /
  • 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 5,247
    • Issues 5,247
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 577
    • Merge requests 577
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell CompilerGlasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #20245
Closed
Open
Issue created Aug 18, 2021 by Sylvain Henry@hsyl20Developer

Bignum literals aren't always considered as constructor applications

Reproducer:

module Bug where

import GHC.Num.Integer

foo :: Int
foo = case 2 of
  IS _ -> 9999
  IP _ -> 0
  IN _ -> 0

Even with -O2 with HEAD we get the following Core:

foo2 = I# 9999#
foo1 = I# 0#
foo3 = 2
foo
  = case foo3 of {
      IS ds_dxZ -> foo2;
      IP ds_dy0 -> foo1;
      IN ds_dy1 -> foo1
    }

while we would expect:

foo = I# 9999#

It's because bignum literals are only desugared into IS/IN/IP constructor applications in Core prep; after Core optimisations. In some places (e.g. rules) we are careful to match on both bignum literal representations but usually to extract a Literal from a ConApp (e.g. IS 2# ==> 2). We would have to do the same in the opposite direction but exprIsConApp_maybe currently doesn't handle bignum literals.

I've found this while working on #15327. Luckily I already have a branch that fixes this because having two representations in Core for bignum literals already bothered me. Instead of adding another special case to exprIsConApp_maybe, it removes Integer and Natural literals to only keep BigNat# literals.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking