Skip to content

Commit

Permalink
Add a flag to allow unsafe ctor refinement
Browse files Browse the repository at this point in the history
  • Loading branch information
AlecsFerra committed Jan 14, 2025
1 parent 4d69733 commit df43885
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
4 changes: 3 additions & 1 deletion liquidhaskell-boot/src/Language/Haskell/Liquid/Bare/Check.hs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ checkTargetSpec specs src env cbs tsp
<> checkSizeFun emb env (gsTconsP (gsName tsp))
<> checkPlugged (catMaybes [ fmap (F.dropSym 2 $ GM.simplesymbol x,) (getMethodType t) | (x, t) <- gsMethods (gsSig tsp) ])
<> checkRewrites tsp
<> checkConstructorRefinement (gsTySigs $ gsSig tsp)
<> if allowUnsafeConstructors $ getConfig tsp
then mempty
else checkConstructorRefinement (gsTySigs $ gsSig tsp)

_rClasses = concatMap Ms.classes specs
_rInsts = concatMap Ms.rinstance specs
Expand Down
5 changes: 5 additions & 0 deletions liquidhaskell-boot/src/Language/Haskell/Liquid/UX/CmdLine.hs
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,10 @@ config = cmdArgsMode $ Config {
= def &= help "Dump pre-normalized core (before a-normalization)"
&= name "dump-pre-normalized-core"
&= explicit
, allowUnsafeConstructors
= def &= help "Allow refining constructors with unsafe refinements"
&= name "allow-unsafe-constructors"
&= explicit
} &= program "liquid"
&= help "Refinement Types for Haskell"
&= summary copyright
Expand Down Expand Up @@ -748,6 +752,7 @@ defConfig = Config
, excludeAutomaticAssumptionsFor = []
, dumpOpaqueReflections = False
, dumpPreNormalizedCore = False
, allowUnsafeConstructors = False
}

-- | Write the annotations (i.e. the files in the \".liquid\" hidden folder) and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ data Config = Config
, excludeAutomaticAssumptionsFor :: [String]
, dumpOpaqueReflections :: Bool -- Dumps all opaque reflections to the stdout
, dumpPreNormalizedCore :: Bool -- Dumps the prenormalized core (before a-normalization)
, allowUnsafeConstructors :: Bool -- ^ Allow refining constructors with unsafe refinements
} deriving (Generic, Data, Typeable, Show, Eq)

allowPLE :: Config -> Bool
Expand Down
15 changes: 15 additions & 0 deletions tests/pos/AllowUnsafeCtor.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{-# LANGUAGE GADTs #-}

module AllowUnsafeCtor where

import Language.Haskell.Liquid.ProofCombinators

{-@ type K X Y = { _:F | X = Y } @-}

{-@ LIQUID "--allow-unsafe-constructors" @-}
data F where
{-@ MkF :: x:Int -> y:Int -> K x y @-}
MkF :: Int -> Int -> F

{-@ falseProof :: { false } @-}
falseProof = () ? MkF 0 2

0 comments on commit df43885

Please sign in to comment.