Opened 9 years ago

Closed 8 years ago

Last modified 8 years ago

#4946 closed bug (invalid)

reify does not work on data structures defined in files without Language pragma of Template Haskell and without -fth or -XTemplateHaskell command line flags

Reported by: guest Owned by:
Priority: normal Milestone: 7.4.1
Component: GHCi Version: 7.0.1
Keywords: Cc: sivaramreddy@…
Operating System: Linux Architecture: x86
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description (last modified by simonmar)

reify does not work on data structures defined in files compiled without TemplateHaskell.

  • Main.hs: File with the splice expression
  • Fields.hs: File with the Template Haskell code that lists all the fields in particular datastructures recursively.
  • DataStructure.hs: File with the datastructure being reified in TH.hs

When all the files have the TemplateHaskell Language pragma, everything works. When the command line flag -fth or -XTemplateHaskell are used, everything works. When the DataStructure.hs does not have the TemplateHaskell Language pragma, then when the data-structure is being reified in TH.hs, it generates blank lists for all the fields of TyConI (DataD ...

Attachments (3)

DataStructure.hs (460 bytes) - added by guest 9 years ago.
Main.hs (389 bytes) - added by guest 9 years ago.
Fields.hs (4.9 KB) - added by guest 9 years ago.

Download all attachments as: .zip

Change History (9)

Changed 9 years ago by guest

Attachment: DataStructure.hs added

Changed 9 years ago by guest

Attachment: Main.hs added

Changed 9 years ago by guest

Attachment: Fields.hs added

comment:1 Changed 9 years ago by simonmar

Description: modified (diff)

comment:2 Changed 9 years ago by simonmar

Description: modified (diff)

comment:3 Changed 9 years ago by igloo

Milestone: 7.2.1

comment:4 Changed 8 years ago by simonpj

Resolution: invalid
Status: newclosed

Yes, you need to compile DataStructures.hs either with -fno-omit-interface-pragmas (or with -O which implies that), or with -XTemplateHaskell. I've added a note to the TH wiki to mention this. Do improve it.

Trying this out did show up a buglet to do with record fields, which I'm fixing too.

Simon

comment:5 Changed 8 years ago by simonpj@…

commit ffada1e9e717e7d0fb66ce02cdb551b2932f7be1

Author: Simon Peyton Jones <simonpj@microsoft.com>
Date:   Fri Sep 9 12:50:07 2011 +0100

    Record selectors should be Exported Ids
    
    We don't want to drop record selectors as dead code, even if they
    aren't exported in the module header.  The data type decl in the
    inteface file advertises their presenece, and we may get at them via
    Template Haskell.
    
       module M( f ) where
         data T = MkT { boo :: Int }
         f :: T -> T
         f = <blah>
    
    We don't want to drop the record selector for 'boo'.
    
    See Trac #4946

 compiler/typecheck/TcTyClsDecls.lhs |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

comment:6 Changed 8 years ago by simonmar

I was surprised by this. Should TH really be able to get at the parts of datatypes that were not exported?

Note: See TracTickets for help on using tickets.