Ticket #2386 (closed merge: fixed)

Opened 5 years ago

Last modified 5 years ago

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: Difficulty: Unknown
Test Case: th/T2386 Blocked By:
Blocking: Related Tickets:

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

Changed 5 years ago by igloo

  • difficulty set to Unknown
  • milestone set to 6.10.1

Changed 5 years ago by simonpj

  • owner set to simonpj

Good point. I'm fixing.

S

Changed 5 years ago by simonpj

  • owner changed from simonpj to igloo
  • testcase set to th/T2386
  • type changed from bug to merge

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

Changed 5 years ago by igloo

  • milestone changed from 6.10.1 to 6.8 branch

Changed 5 years ago by igloo

  • owner igloo deleted

Changed 5 years ago by igloo

  • status changed from new to closed
  • resolution set to fixed

We won't be releasing 6.8.4.

Note: See TracTickets for help on using tickets.