Ticket #5854 (closed feature request: fixed)

Opened 17 months ago

Last modified 13 months ago

TH: INLINABLE pragma support (patch)

Reported by: mikhail.vorozhtsov Owned by:
Priority: normal Milestone:
Component: Template Haskell Version: 7.4.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

I needed it for my  data-dword library, so here it is:

GHCi, version 7.5.20120206: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
λ> import Language.Haskell.TH
λ> (mapM_ print =<<) $ runQ [d| f1 = id; {-# NOINLINE f1 #-}; f2 = id; {-# INLINE f2 #-}; f3 = id; {-# INLINABLE f3 #-} |]
Loading package array-0.3.0.3 ... linking ... done.
Loading package deepseq-1.2.0.1 ... linking ... done.
Loading package containers-0.4.2.0 ... linking ... done.
Loading package pretty-1.1.1.0 ... linking ... done.
Loading package template-haskell ... linking ... done.
ValD (VarP f1_2) (NormalB (VarE GHC.Base.id)) []
PragmaD (InlineP f1_2 (InlineSpec NoInline False Nothing))
ValD (VarP f2_1) (NormalB (VarE GHC.Base.id)) []
PragmaD (InlineP f2_1 (InlineSpec Inline False Nothing))
ValD (VarP f3_0) (NormalB (VarE GHC.Base.id)) []
PragmaD (InlineP f3_0 (InlineSpec Inlinable False Nothing))

The other way around:

{-# LANGUAGE UnicodeSyntax #-}

module TH where

import Language.Haskell.TH

noInlineP ∷ Name → DecsQ
noInlineP n = fmap return $ pragInlD n $ inlineSpecNoPhase NoInline False

inlineP ∷ Name → DecsQ
inlineP n = fmap return $ pragInlD n $ inlineSpecNoPhase Inline False

inlinableP ∷ Name → DecsQ
inlinableP n = fmap return $ pragInlD n $ inlineSpecNoPhase Inlinable False
{-# LANGUAGE UnicodeSyntax #-}
{-# LANGUAGE TemplateHaskell #-}

import TH

f1, f2, f3 ∷ α → α
f1 = id
f2 = id
f3 = id

$(noInlineP 'f1)
$(inlineP 'f2)
$(inlinableP 'f3)

main = return ()
$ ghc-stage2 -ddump-splices -fforce-recomp TH.hs Main.hs
[1 of 2] Compiling TH               ( TH.hs, TH.o )
[2 of 2] Compiling Main             ( Main.hs, Main.o )
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package pretty-1.1.1.0 ... linking ... done.
Loading package array-0.3.0.3 ... linking ... done.
Loading package deepseq-1.2.0.1 ... linking ... done.
Loading package containers-0.4.2.0 ... linking ... done.
Loading package template-haskell ... linking ... done.
Main.hs:1:1: Splicing declarations
    noInlineP 'f1
  ======>
    Main.hs:11:3-15
    {-# NOINLINE f1 #-}
Main.hs:1:1: Splicing declarations
    inlineP 'f2
  ======>
    Main.hs:12:3-13
    {-# INLINE f2 #-}
Main.hs:1:1: Splicing declarations
    inlinableP 'f3
  ======>
    Main.hs:13:3-16
    {-# INLINABLE[ALWAYS] f3 #-}
Linking Main ...

Please review the patches.

Attachments

th-inlinable.patch Download (4.6 KB) - added by mikhail.vorozhtsov 17 months ago.
Patch for the template-haskell library
ghc-th-inlinable.patch Download (6.9 KB) - added by mikhail.vorozhtsov 17 months ago.
Patch for the GHC
dph-th-inlinable.patch Download (0.9 KB) - added by mikhail.vorozhtsov 17 months ago.
Patch for the DPH library

Change History

Changed 17 months ago by mikhail.vorozhtsov

Patch for the template-haskell library

Changed 17 months ago by mikhail.vorozhtsov

Patch for the GHC

Changed 17 months ago by mikhail.vorozhtsov

Patch for the DPH library

Changed 16 months ago by mikhail.vorozhtsov

  • status changed from new to patch

Changed 13 months ago by simonpj

  • status changed from patch to closed
  • difficulty set to Unknown
  • resolution set to fixed

Mikhail, I'm sorry this has taken so long, but I've now committed your changes more or less exactly as you offered them. Thanks!

Simon

To the compiler

commit b6bf6abe2b5729137391a88c8deb4cc7ed851375
Author: Simon Peyton Jones <simonpj@microsoft.com>
Date:   Fri May 18 10:10:02 2012 +0100

    Allow INLINABLE pragmas in TH
    
    Thanks to mikhail.vorozhtsov for doing the work

 compiler/deSugar/DsMeta.hs |   55 +++++++++++++++++++++++++++++++------------
 compiler/hsSyn/Convert.lhs |   11 ++++----
 2 files changed, 45 insertions(+), 21 deletions(-)

And in template-haskell:

commit 6c0b59b8d9db5ce12e5b566a2c3cf6889a00aca4
Author: Simon Peyton Jones <simonpj@microsoft.com>
Date:   Fri May 18 10:03:50 2012 +0100

    Add INLINABLE pragmas in Template Haskell
    
    Thanks to mikhail.vorozhtsov for doing the work

 Language/Haskell/TH.hs        |   12 ++++++------
 Language/Haskell/TH/Lib.hs    |    4 ++--
 Language/Haskell/TH/Ppr.hs    |   10 ++++++++--
 Language/Haskell/TH/Syntax.hs |   13 +++++++++----
 4 files changed, 25 insertions(+), 14 deletions(-)
Note: See TracTickets for help on using tickets.