Skip to content

Commit

Permalink
Support OpaqueP
Browse files Browse the repository at this point in the history
The `OPAQUE` pragma was introduced in GHC 9.4.

Addresses one part of #157.
  • Loading branch information
RyanGlScott committed May 31, 2022
1 parent 0c9c26d commit c25a32a
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ Version 1.14 [????.??.??]
to two arguments, just like `InfixT` is desugared. Similarly, attempting to
desugar a `PromotedUInfixT` results in an error, just like attempting to
desugar a `UInfixT` would be.
* `th-desugar` now supports `DefaultD` (i.e., `default` declarations).
* `th-desugar` now supports `DefaultD` (i.e., `default` declarations) and
`OpaqueP` (i.e., `OPAQUE` pragmas), which were added in GHC 9.4.
* Fix an inconsistency which caused non-exhaustive `case` expressions to be
desugared into uses of `EmptyCase`. Non-exhaustive `case` expressions are now
desugared into code that throws a "`Non-exhaustive patterns in...`" error at
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 @@ -255,6 +255,7 @@ data DPragma = DInlineP Name Inline RuleMatch Phases
| DAnnP AnnTarget DExp
| DLineP Int String
| DCompleteP [Name] (Maybe Name)
| DOpaqueP Name
deriving (Eq, Show, Data, Generic)

-- | 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 @@ -1012,6 +1012,9 @@ dsPragma (LineP n str) = return $ DLineP n str
#if __GLASGOW_HASKELL__ >= 801
dsPragma (CompleteP cls mty) = return $ DCompleteP cls mty
#endif
#if __GLASGOW_HASKELL__ >= 903
dsPragma (OpaqueP n) = return $ DOpaqueP n
#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 @@ -250,6 +250,11 @@ pragmaToTH (DCompleteP {}) = error "COMPLETE pragmas only supported in GHC 8.2+"
#else
pragmaToTH (DCompleteP cls mty) = CompleteP cls mty
#endif
#if __GLASGOW_HASKELL__ >= 903
pragmaToTH (DOpaqueP n) = OpaqueP n
#else
pragmaToTH (DOpaqueP {}) = error "OPAQUE pragmas only supported in GHC 9.4+"
#endif

ruleBndrToTH :: DRuleBndr -> RuleBndr
ruleBndrToTH (DRuleVar n) = RuleVar n
Expand Down
3 changes: 3 additions & 0 deletions Test/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ tests = test [ "sections" ~: $test1_sections @=? $(dsSplice test1_sections)
#endif
#if __GLASGOW_HASKELL__ >= 902
, "overloaded_record_dot" ~: $test54_overloaded_record_dot @=? $(dsSplice test54_overloaded_record_dot)
#endif
#if __GLASGOW_HASKELL__ >= 903
, "opaque_pragma" ~: $test55_opaque_pragma @=? $(dsSplice test55_opaque_pragma)
#endif
]

Expand Down
11 changes: 11 additions & 0 deletions Test/Splices.hs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,14 @@ test54_overloaded_record_dot =
in (ord2.unORD2.unORD1, (.unORD2.unORD1) ord2) |]
#endif

#if __GLASGOW_HASKELL__ >= 903
test55_opaque_pragma =
[| let f :: String -> String
f x = x
{-# OPAQUE f #-}
in f "Hello, World!" |]
#endif

type family TFExpand x
type instance TFExpand Int = Bool
type instance TFExpand (Maybe a) = [a]
Expand Down Expand Up @@ -758,5 +766,8 @@ test_exprs = [ test1_sections
#endif
#if __GLASGOW_HASKELL__ >= 902
, test54_overloaded_record_dot
#endif
#if __GLASGOW_HASKELL__ >= 903
, test55_opaque_pragma
#endif
]

0 comments on commit c25a32a

Please sign in to comment.