Skip to content

Commit 1671fd4

Browse files
committed
Parse stratified keyword and don't check for positivity stratified types
1 parent cfd99bd commit 1671fd4

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

liquidhaskell-boot/src/Language/Haskell/Liquid/Bare.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ makeTargetSpec :: Config
9393
-> TargetDependencies
9494
-> Ghc.TcRn (Either Diagnostics ([Warning], TargetSpec, LiftedSpec))
9595
makeTargetSpec cfg localVars lnameEnv lmap targetSrc bareSpec dependencies = do
96-
let targDiagnostics = Bare.checkTargetSrc cfg targetSrc
96+
let targDiagnostics = Bare.checkTargetSrc cfg bareSpec targetSrc
9797
let depsDiagnostics = mapM (Bare.checkBareSpec . snd) legacyDependencies
9898
let bareSpecDiagnostics = Bare.checkBareSpec bareSpec
9999
case targDiagnostics >> depsDiagnostics >> bareSpecDiagnostics of

liquidhaskell-boot/src/Language/Haskell/Liquid/Bare/Check.hs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,25 @@ import qualified Language.Haskell.Liquid.Bare.Resolve as Bare
5555
import Language.Haskell.Liquid.UX.Config
5656
import Language.Fixpoint.Types.Config (ElabFlags (ElabFlags), solverFlags)
5757

58+
-- import Debug.Trace
5859

5960
----------------------------------------------------------------------------------------------
6061
-- | Checking TargetSrc ------------------------------------------------------------------------
6162
----------------------------------------------------------------------------------------------
62-
checkTargetSrc :: Config -> TargetSrc -> Either Diagnostics ()
63-
checkTargetSrc cfg spec
63+
checkTargetSrc :: Config -> BareSpec -> TargetSrc -> Either Diagnostics ()
64+
checkTargetSrc cfg bare spec
6465
| nopositivity cfg
6566
|| nopositives == emptyDiagnostics
6667
= Right ()
6768
| otherwise
6869
= Left nopositives
69-
where nopositives = checkPositives (gsTcs spec)
70+
where nopositives = checkPositives $ filter (not . isStratifiedTyCon bare) $ gsTcs spec
7071

72+
isStratifiedTyCon :: BareSpec -> TyCon -> Bool
73+
isStratifiedTyCon bs tc = (Ghc.tyConName tc) `elem` sn
74+
where sn = mapMaybe ctorName $ S.toList $ stratified bs
75+
ctorName (F.Loc _ _ (LHNResolved (LHRGHC c) _)) = Just c
76+
ctorName _ = Nothing
7177

7278
checkPositives :: [TyCon] -> Diagnostics
7379
checkPositives tys = mkDiagnostics [] $ mkNonPosError (getNonPositivesTyCon tys)

liquidhaskell-boot/src/Language/Haskell/Liquid/Parse.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,7 @@ data BPspec
899899
| Insts (Located LHName) -- ^ 'auto-inst' or 'ple' annotation; use ple locally on binder
900900
| HMeas (Located LHName) -- ^ 'measure' annotation; lift Haskell binder as measure
901901
| Reflect (Located LHName) -- ^ 'reflect' annotation; reflect Haskell binder as function in logic
902+
| Stratified (Located LHName) -- ^ 'stratified' annotation; stratification check for type declarations
902903
| PrivateReflect LocSymbol -- ^ 'private-reflect' annotation
903904
| OpaqueReflect (Located LHName) -- ^ 'opaque-reflect' annotation
904905
| Inline (Located LHName) -- ^ 'inline' annotation; inline (non-recursive) binder as an alias
@@ -984,6 +985,8 @@ ppPspec k (HMeas lx)
984985
= "measure" <+> pprintTidy k (val lx)
985986
ppPspec k (Reflect lx)
986987
= "reflect" <+> pprintTidy k (val lx)
988+
ppPspec k (Stratified lx)
989+
= "stratified" <+> pprintTidy k (val lx)
987990
ppPspec k (PrivateReflect lx)
988991
= "private-reflect" <+> pprintTidy k (val lx)
989992
ppPspec k (OpaqueReflect lx)
@@ -1106,6 +1109,7 @@ mkSpec xs = Measure.Spec
11061109
, Measure.rewriteWith = M.fromList [s | Rewritewith s <- xs]
11071110
, Measure.bounds = M.fromList [(bname i, i) | PBound i <- xs]
11081111
, Measure.reflects = S.fromList [s | Reflect s <- xs]
1112+
, Measure.stratified = S.fromList [s | Stratified s <- xs]
11091113
, Measure.privateReflects = S.fromList [s | PrivateReflect s <- xs]
11101114
, Measure.opaqueReflects = S.fromList [s | OpaqueReflect s <- xs]
11111115
, Measure.hmeas = S.fromList [s | HMeas s <- xs]
@@ -1129,6 +1133,7 @@ specP
11291133
-- TODO: These next two are synonyms, kill one
11301134
<|> fallbackSpecP "axiomatize" (fmap Reflect locBinderLHNameP)
11311135
<|> fallbackSpecP "reflect" (fmap Reflect locBinderLHNameP)
1136+
<|> fallbackSpecP "stratified" (fmap Stratified tyConBindLHNameP)
11321137
<|> (reserved "private-reflect" >> fmap PrivateReflect axiomP )
11331138
<|> (reserved "opaque-reflect" >> fmap OpaqueReflect locBinderLHNameP )
11341139

liquidhaskell-boot/src/Language/Haskell/Liquid/Types/Specs.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ data Spec lname ty = Spec
398398
, rewriteWith :: !(M.HashMap (F.Located LHName) [F.Located LHName]) -- ^ Definitions using rewrite rules
399399
, fails :: !(S.HashSet (F.Located LHName)) -- ^ These Functions should be unsafe
400400
, reflects :: !(S.HashSet (F.Located LHName)) -- ^ Binders to reflect
401+
, stratified :: !(S.HashSet (F.Located LHName)) -- ^ Type declaration to check for stratification
401402
, privateReflects :: !(S.HashSet F.LocSymbol) -- ^ Private binders to reflect
402403
, opaqueReflects :: !(S.HashSet (F.Located LHName)) -- ^ Binders to opaque-reflect
403404
, autois :: !(S.HashSet (F.Located LHName)) -- ^ Automatically instantiate axioms in these Functions
@@ -624,6 +625,7 @@ instance Semigroup (Spec lname ty) where
624625
, rewriteWith = M.union (rewriteWith s1) (rewriteWith s2)
625626
, fails = S.union (fails s1) (fails s2)
626627
, reflects = S.union (reflects s1) (reflects s2)
628+
, stratified = S.union (stratified s1) (stratified s2)
627629
, privateReflects = S.union (privateReflects s1) (privateReflects s2)
628630
, opaqueReflects = S.union (opaqueReflects s1) (opaqueReflects s2)
629631
, hmeas = S.union (hmeas s1) (hmeas s2)
@@ -660,6 +662,7 @@ instance Monoid (Spec lname ty) where
660662
, autois = S.empty
661663
, hmeas = S.empty
662664
, reflects = S.empty
665+
, stratified = S.empty
663666
, privateReflects = S.empty
664667
, opaqueReflects = S.empty
665668
, inlines = S.empty
@@ -1012,6 +1015,7 @@ unsafeFromLiftedSpec a = Spec
10121015
, rewrites = mempty
10131016
, rewriteWith = mempty
10141017
, reflects = mempty
1018+
, stratified = mempty
10151019
, privateReflects = liftedPrivateReflects a
10161020
, opaqueReflects = mempty
10171021
, autois = liftedAutois a

0 commit comments

Comments
 (0)