#15502 closed bug (fixed)

-ddump-splices truncates Integer literals to Int literals

Reported by: ChaiTRex Owned by:
Priority: high Milestone: 8.6.1
Component: Compiler Version: 8.4.3
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s): Phab:D5089, Phab:D5151
Wiki Page:

Description

I trusted that the splice results shown by -ddump-splices were correct. They weren't, which caused me to waste a lot of time debugging my Template Haskell expressions when they were already correct.

$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.4.3

Example program

{-# OPTIONS_GHC -ddump-splices #-}
{-# LANGUAGE TemplateHaskell #-}

module Main where

import Language.Haskell.TH.Syntax  (Lift(lift))

main = print ( $( lift (toInteger (maxBound :: Int) + 1) )
             , $( lift (minBound :: Int) )
             )

Output of runghc

Note that the output of the program on the bottom line below is correct. The two splice results shown by -ddump-splices incorrectly match each other:

Example.hs:8:19-56: Splicing expression
    lift (toInteger (maxBound :: Int) + 1) ======> -9223372036854775808
Example.hs:9:19-40: Splicing expression
    lift (minBound :: Int) ======> (-9223372036854775808)
(9223372036854775808,-9223372036854775808)

Change History (7)

comment:1 Changed 16 months ago by simonpj

Priority: normalhigh

That indeed looks bad. I'm bumping up the priority because it surely can't be hard to find and fix. Is anyone up for that?

comment:2 Changed 16 months ago by RyanGlScott

Differential Rev(s): Phab:D5089
Status: newpatch

Phab:D5089 ought to do it.

comment:3 Changed 16 months ago by Krzysztof Gogolewski <krz.gogolewski@…>

In 7a3cda53/ghc:

Fix #15502 by not casting to Int during TH conversion

Summary:
When turning an `IntegerL` to an `IntegralLit` during TH
conversion, we were stupidly casting an `Integer` to an `Int` in
order to determine how it should be pretty-printed. Unsurprisingly,
this causes problems when the `Integer` doesn't lie within the bounds
of an `Int`, as demonstrated in #15502.

The fix is simple: don't cast to an `Int`.

Test Plan: make test TEST=T15502

Reviewers: bgamari, simonpj

Reviewed By: simonpj

Subscribers: simonpj, rwbarton, carter

GHC Trac Issues: #15502

Differential Revision: https://phabricator.haskell.org/D5089

comment:4 Changed 16 months ago by monoidal

Status: patchmerge

If it's not too late, this can be merged to 8.6.

comment:5 Changed 15 months ago by monoidal

Differential Rev(s): Phab:D5089Phab:D5089, Phab:D5151

comment:6 Changed 15 months ago by Krzysztof Gogolewski <krz.gogolewski@…>

In ecbe26b/ghc:

Fix T15502 on 32-bit

Summary:
The expected output uses a hardcoded value for
maxBound :: Int.

This should fix one of circleci failures on i386.

Test Plan: make test TEST=T15502

Reviewers: RyanGlScott, bgamari

Reviewed By: RyanGlScott

Subscribers: rwbarton, carter

GHC Trac Issues: #15502

Differential Revision: https://phabricator.haskell.org/D5151

comment:7 Changed 15 months ago by bgamari

Resolution: fixed
Status: mergeclosed
Note: See TracTickets for help on using tickets.