diff options
author | Alina Banerjee <alina@glitchgirl.us> | 2021-08-05 08:08:31 +0000 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-08-11 18:15:05 -0400 |
commit | 100ffe75f509a73f1b26e768237888646f522b6c (patch) | |
tree | 56702bfdf582572a41b1bfbe9b066039023c0f95 /compiler/Language/Haskell | |
parent | f5fdace5613914724eb00bcf7547c82f3ad12686 (diff) | |
download | haskell-100ffe75f509a73f1b26e768237888646f522b6c.tar.gz |
Modify InlineSpec data constructor (helps fix #18138)
The inl_inline field of the InlinePragma record is modified to store pragma
source text by adding a data constructor of type SourceText. This can help in
tracking the actual text of pragma names.
Add/modify functions, modify type instance for InlineSpec type
Modify parser, lexer to handle InlineSpec constructors containing SourceText
Modify functions with InlineSpec type
Extract pragma source from InlineSpec for SpecSig, InlineSig types
Modify cvtInline function to add SourceText to InlineSpec type
Extract name for InlineSig, SpecSig from pragma, SpectInstSig from source (fixes #18138)
Extract pragma name for SpecPrag pragma, SpecSig signature
Add Haddock annotation for inlinePragmaName function
Add Haddock annotations for using helper functions in hsSigDoc
Remove redundant ppr in pragma name for SpecSig, InlineSig; update comment
Rename test to T18138 for misplaced SPECIALIZE pragma testcase
Diffstat (limited to 'compiler/Language/Haskell')
-rw-r--r-- | compiler/Language/Haskell/Syntax/Binds.hs | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/compiler/Language/Haskell/Syntax/Binds.hs b/compiler/Language/Haskell/Syntax/Binds.hs index 60ca3fad1b..e3e611674c 100644 --- a/compiler/Language/Haskell/Syntax/Binds.hs +++ b/compiler/Language/Haskell/Syntax/Binds.hs @@ -46,6 +46,7 @@ import GHC.Data.Bag import GHC.Data.BooleanFormula (LBooleanFormula) import GHC.Utils.Outputable +import GHC.Utils.Panic (pprPanic) import Data.Data hiding ( Fixity ) import Data.Void @@ -872,17 +873,29 @@ hsSigDoc (ClassOpSig _ is_deflt _ _) | is_deflt = text "default type signature" | otherwise = text "class method signature" hsSigDoc (IdSig {}) = text "id signature" -hsSigDoc (SpecSig _ _ _ inl) - = ppr inl <+> text "pragma" -hsSigDoc (InlineSig _ _ prag) = ppr (inlinePragmaSpec prag) <+> text "pragma" -hsSigDoc (SpecInstSig _ src _) - = pprWithSourceText src empty <+> text "instance pragma" +hsSigDoc (SpecSig _ _ _ inl) = (inlinePragmaName . inl_inline $ inl) <+> text "pragma" +hsSigDoc (InlineSig _ _ prag) = (inlinePragmaName . inl_inline $ prag) <+> text "pragma" +-- Using the 'inlinePragmaName' function ensures that the pragma name for any +-- one of the INLINE/INLINABLE/NOINLINE pragmas are printed after being extracted +-- from the InlineSpec field of the pragma. +hsSigDoc (SpecInstSig _ src _) = text (extractSpecPragName src) <+> text "instance pragma" hsSigDoc (FixSig {}) = text "fixity declaration" hsSigDoc (MinimalSig {}) = text "MINIMAL pragma" hsSigDoc (SCCFunSig {}) = text "SCC pragma" hsSigDoc (CompleteMatchSig {}) = text "COMPLETE pragma" hsSigDoc (XSig {}) = text "XSIG TTG extension" +-- | Extracts the name for a SPECIALIZE instance pragma. In 'hsSigDoc', the src +-- field of 'SpecInstSig' signature contains the SourceText for a SPECIALIZE +-- instance pragma of the form: "SourceText {-# SPECIALIZE" +-- +-- Extraction ensures that all variants of the pragma name (with a 'Z' or an +-- 'S') are output exactly as used in the pragma. +extractSpecPragName :: SourceText -> String +extractSpecPragName srcTxt = case (words $ show srcTxt) of + (_:_:pragName:_) -> filter (/= '\"') pragName + _ -> pprPanic "hsSigDoc: Misformed SPECIALISE instance pragma:" (ppr srcTxt) + {- ************************************************************************ * * |