on master help sign in
Implement support for inline signatures
046f14emrkkrp
data/examples/declaration/signature/inline/inline-out.hsnew file+11
@@ -0,0 +1,11 @@
1+foo :: Int -> Int
2+foo = id
3+{-# INLINE foo #-}
4+
5+{-# INLINE [2] bar #-}
6+bar :: Int -> Int
7+bar = id
8+
9+baz :: Int -> Int
10+baz = id
11+{-# INLINE [~2] baz #-}
data/examples/declaration/signature/inline/inline.hsnew file+13
@@ -0,0 +1,13 @@
1+foo :: Int -> Int
2+foo = id
3+
4+{-# INLINE foo #-}
5+
6+{-# INLINE [2] bar #-}
7+
8+bar :: Int -> Int
9+bar = id
10+
11+baz :: Int -> Int
12+baz = id
13+{-# INLINE [~2] baz #-}
data/examples/declaration/signature/inline/inlineable-out.hsnew file+11
@@ -0,0 +1,11 @@
1+foo :: Int -> Int
2+foo = id
3+{-# INLINEABLE foo #-}
4+
5+{-# INLINEABLE [2] bar #-}
6+bar :: Int -> Int
7+bar = id
8+
9+baz :: Int -> Int
10+baz = id
11+{-# INLINEABLE [~2] baz #-}
data/examples/declaration/signature/inline/inlineable.hsnew file+13
@@ -0,0 +1,13 @@
1+foo :: Int -> Int
2+foo = id
3+
4+{-# INLINEABLE foo #-}
5+
6+{-# INLINEABLE [2] bar #-}
7+
8+bar :: Int -> Int
9+bar = id
10+
11+baz :: Int -> Int
12+baz = id
13+{-# INLINEABLE [~2] baz #-}
data/examples/declaration/signature/inline/noinline-out.hsnew file+11
@@ -0,0 +1,11 @@
1+foo :: Int -> Int
2+foo = id
3+{-# NOINLINE foo #-}
4+
5+{-# NOINLINE [2] bar #-}
6+bar :: Int -> Int
7+bar = id
8+
9+baz :: Int -> Int
10+baz = id
11+{-# NOINLINE [~2] baz #-}
data/examples/declaration/signature/inline/noinline.hsnew file+13
@@ -0,0 +1,13 @@
1+foo :: Int -> Int
2+foo = id
3+{-# NOINLINE foo #-}
4+
5+{-# NOINLINE [2] bar #-}
6+
7+bar :: Int -> Int
8+bar = id
9+
10+baz :: Int -> Int
11+baz = id
12+
13+{-# NOINLINE [~2] baz #-}
src/Ormolu/Printer/Meat/Declaration/Signature.hs+26−1
@@ -10,7 +10,7 @@ module Ormolu.Printer.Meat.Declaration.Signature
10 )
10 )
11where
11where
12
12
13−import BasicTypes (Fixity (..))
13+import BasicTypes
14import Control.Monad
14import Control.Monad
15import GHC
15import GHC
16import Ormolu.Printer.Combinators
16import Ormolu.Printer.Combinators
@@ -26,6 +26,7 @@ p_sigDecl' = \case
26 TypeSig NoExt names hswc -> p_typeSig names hswc
26 TypeSig NoExt names hswc -> p_typeSig names hswc
27 ClassOpSig NoExt def names hsib -> p_classOpSig def names hsib
27 ClassOpSig NoExt def names hsib -> p_classOpSig def names hsib
28 FixSig NoExt sig -> p_fixSig sig
28 FixSig NoExt sig -> p_fixSig sig
29+ InlineSig NoExt name inlinePragma -> p_inlineSig name inlinePragma
29 _ -> notImplemented "certain types of signature declarations"
30 _ -> notImplemented "certain types of signature declarations"
30
31
31p_typeSig
32p_typeSig
@@ -63,3 +64,27 @@ p_fixSig = \case
63 space
64 space
64 sequence_ (withSep comma p_rdrName names)
65 sequence_ (withSep comma p_rdrName names)
65 XFixitySig NoExt -> notImplemented "XFixitySig"
66 XFixitySig NoExt -> notImplemented "XFixitySig"
67+
68+p_inlineSig
69+ :: Located RdrName -- ^ Name
70+ -> InlinePragma -- ^ Inline pragma specification
71+ -> R ()
72+p_inlineSig name InlinePragma {..} = do
73+ txt "{-# "
74+ txt $ case inl_inline of
75+ Inline -> "INLINE"
76+ Inlinable -> "INLINEABLE"
77+ NoInline -> "NOINLINE"
78+ NoUserInline -> notImplemented "NoUserInline"
79+ space
80+ case inl_act of
81+ NeverActive -> return ()
82+ AlwaysActive -> return ()
83+ ActiveBefore _ n -> do
84+ brackets (txt "~" >> atom n)
85+ space
86+ ActiveAfter _ n -> do
87+ brackets (atom n)
88+ space
89+ p_rdrName name
90+ txt " #-}"
src/Ormolu/Printer/Meat/Module.hs+4
@@ -66,4 +66,8 @@ separatedDecls
66 -> Bool
66 -> Bool
67separatedDecls (SigD NoExt (TypeSig NoExt (n:_) _)) (ValD NoExt (FunBind NoExt n' _ _ _)) =
67separatedDecls (SigD NoExt (TypeSig NoExt (n:_) _)) (ValD NoExt (FunBind NoExt n' _ _ _)) =
68 unL n /= unL n'
68 unL n /= unL n'
69+separatedDecls (ValD NoExt (FunBind NoExt n _ _ _)) (SigD NoExt (InlineSig NoExt n' _)) =
70+ unL n /= unL n'
71+separatedDecls (SigD NoExt (InlineSig NoExt n _)) (SigD NoExt (TypeSig NoExt (n':_) _)) =
72+ unL n /= unL n'
69separatedDecls _ _ = True
73separatedDecls _ _ = True