Opened 11 years ago

Closed 11 years ago

#2386 closed merge (fixed)

Splicing in constructors that are abstract from the point of view of the splice point is unreliable

Reported by: batterseapower Owned by:
Priority: normal Milestone: 6.8 branch
Component: Template Haskell Version: 6.8.3
Keywords: Cc:
Operating System: MacOS X Architecture: x86_64 (amd64)
Type of failure: None/Unknown Test Case: th/T2386
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

Test1.hs:

{-# LANGUAGE TemplateHaskell #-}

module Main where

import Test2

main = putStrLn (show $(makeOne))

Test2.hs:

{-# LANGUAGE TemplateHaskell #-}

module Test2(ExportedAbstract, makeOne) where

data ExportedAbstract = Yay String | NonYay AnotherThing

data AnotherThing = Foo String

instance Show ExportedAbstract where
	show _ = "Shown"

makeOne = [| Yay "Yep" |]

Compile this with optimizations:

ghc Test2.hs -O2
ghc --make Test1.hs

Results in:

$ ./Test1
Shown

Compile this without optimizations:

ghc Test2.hs -O0
ghc --make Test1.hs

Results in:

$ ghc --make Test1.hs
[2 of 2] Compiling Main             ( Test1.hs, Test1.o )
Loading package base ... linking ... done.
Loading package pretty-1.0.0.0 ... linking ... done.
Loading package array-0.1.0.0 ... linking ... done.
Loading package packedstring-0.1.0.0 ... linking ... done.
Loading package containers-0.1.0.1 ... linking ... done.
Loading package template-haskell ... linking ... done.

Test1.hs:7:24:
    Can't find interface-file declaration for data constructor Test2.Yay
      Probable cause: bug in .hi-boot file, or inconsistent .hi file
      Use -ddump-if-trace to get an idea of which file caused the error
    In the first argument of `show', namely `$makeOne'
    In the first argument of `putStrLn', namely `(show ($makeOne))'
    In the expression: putStrLn (show ($makeOne))

Why is this? Because trimThing in TidyPgm makes data types abstract in some circumstances, and it only happens if compiling a boot file or with -O0!

I think this program should compile as the splicing is not a violation of the abstractness of the data type: all the manipulation etc is still being done by the defining module.

Change History (6)

comment:1 Changed 11 years ago by igloo

difficulty: Unknown
Milestone: 6.10.1

comment:2 Changed 11 years ago by simonpj

Owner: set to simonpj

Good point. I'm fixing.

S

comment:3 Changed 11 years ago by simonpj

Owner: changed from simonpj to igloo
Test Case: th/T2386
Type: bugmerge

Fixed by switching off data type pruning if -XTemplateHaskell is enabled.

Mon Jul  7 11:29:41 BST 2008  simonpj@microsoft.com
  * Fix Trac #2386: exceesive trimming of data types with Template Haskell

Merge to 6.8.4 if/when we release it.

Simon

comment:4 Changed 11 years ago by igloo

Milestone: 6.10.16.8 branch

comment:5 Changed 11 years ago by igloo

Owner: igloo deleted

comment:6 Changed 11 years ago by igloo

Resolution: fixed
Status: newclosed

We won't be releasing 6.8.4.

Note: See TracTickets for help on using tickets.