Skip to content

Commit

Permalink
Support SCC pragmas
Browse files Browse the repository at this point in the history
Fixes #202.
  • Loading branch information
RyanGlScott committed Apr 22, 2024
1 parent 7722f04 commit cc21333
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Version 1.17 [????.??.??]
* Support GHC 9.10.
* Add support namespace identifiers in fixity declarations. As part of these
changes, the `DInfixD` data constructor now has a `NamespaceSpecifier` field.
* Add support for `SCC` declarations via the new `DSCCP` data constructor for
the `DPragma` data type.
* `extractBoundNamesDPat` no longer extracts type variables from constructor
patterns. That this function ever did extract type variables was a mistake,
and the new behavior of `extractBoundNamesDPat` brings it in line with the
Expand Down
1 change: 1 addition & 0 deletions Language/Haskell/TH/Desugar/AST.hs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ data DPragma = DInlineP Name Inline RuleMatch Phases
| DLineP Int String
| DCompleteP [Name] (Maybe Name)
| DOpaqueP Name
| DSCCP Name (Maybe String)
deriving (Eq, Show, Data, Generic, Lift)

-- | Corresponds to TH's @RuleBndr@ type.
Expand Down
3 changes: 3 additions & 0 deletions Language/Haskell/TH/Desugar/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,9 @@ dsPragma (CompleteP cls mty) = return $ DCompleteP cls mty
#if __GLASGOW_HASKELL__ >= 903
dsPragma (OpaqueP n) = return $ DOpaqueP n
#endif
#if __GLASGOW_HASKELL__ >= 909
dsPragma (SCCP nm mstr) = return $ DSCCP nm mstr
#endif

-- | Desugar a @RuleBndr@.
dsRuleBndr :: DsMonad q => RuleBndr -> q DRuleBndr
Expand Down
5 changes: 5 additions & 0 deletions Language/Haskell/TH/Desugar/Sweeten.hs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,11 @@ pragmaToTH (DOpaqueP n) = OpaqueP n
#else
pragmaToTH (DOpaqueP {}) = error "OPAQUE pragmas only supported in GHC 9.4+"
#endif
#if __GLASGOW_HASKELL__ >= 909
pragmaToTH (DSCCP nm mstr) = SCCP nm mstr
#else
pragmaToTH (DSCCP {}) = error "SCCP pragmas only supported in GHC 9.10+"
#endif

ruleBndrToTH :: DRuleBndr -> RuleBndr
ruleBndrToTH (DRuleVar n) = RuleVar n
Expand Down
1 change: 1 addition & 0 deletions Test/Dec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ $(S.dectest19)

#if __GLASGOW_HASKELL__ >= 909
$(S.dectest20)
$(S.dectest21)
#endif

$(fmap unqualify S.instance_test)
Expand Down
1 change: 1 addition & 0 deletions Test/DsDec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ $(dsDecSplice S.dectest19)

#if __GLASGOW_HASKELL__ >= 909
$(dsDecSplice S.dectest20)
$(dsDecSplice S.dectest21)
#endif

$(do decs <- S.rec_sel_test
Expand Down
4 changes: 4 additions & 0 deletions Test/Splices.hs
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,10 @@ dectest20 = [d| infixr 3 data !@#
(!@#) = (&&)

type family (!@#) :: Bool -> Bool -> Bool |]

dectest21 = [d| {-# SCC dec21 "dec21" #-}
dec21 :: a -> a
dec21 x = x |]
#endif

instance_test = [d| instance (Show a, Show b) => Show (a -> b) where
Expand Down

0 comments on commit cc21333

Please sign in to comment.