module Unison.PatternMatchCoverage.Constraint
( Constraint (..),
prettyConstraint,
)
where
import Unison.ConstructorReference (ConstructorReference)
import Unison.PatternMatchCoverage.EffectHandler
import Unison.PatternMatchCoverage.IntervalSet (IntervalSet)
import Unison.PatternMatchCoverage.PmLit
import Unison.PatternMatchCoverage.Pretty
import Unison.PrettyPrintEnv (PrettyPrintEnv)
import Unison.Syntax.TypePrinter qualified as TypePrinter
import Unison.Type (Type)
import Unison.Util.Pretty
import Unison.Var (Var)
data Constraint vt v loc
=
PosCon v ConstructorReference [(v, Type vt loc)]
|
NegCon v ConstructorReference
|
PosEffect v EffectHandler [(v, Type vt loc)]
|
NegEffect v EffectHandler
|
PosLit v PmLit
|
NegLit v PmLit
|
PosListHead
v
Int
v
|
PosListTail
v
Int
v
|
NegListInterval v IntervalSet
|
Effectful v
|
Eq v v
deriving stock (Constraint vt v loc -> Constraint vt v loc -> Bool
(Constraint vt v loc -> Constraint vt v loc -> Bool)
-> (Constraint vt v loc -> Constraint vt v loc -> Bool)
-> Eq (Constraint vt v loc)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall vt v loc.
(Var vt, Eq v) =>
Constraint vt v loc -> Constraint vt v loc -> Bool
$c== :: forall vt v loc.
(Var vt, Eq v) =>
Constraint vt v loc -> Constraint vt v loc -> Bool
== :: Constraint vt v loc -> Constraint vt v loc -> Bool
$c/= :: forall vt v loc.
(Var vt, Eq v) =>
Constraint vt v loc -> Constraint vt v loc -> Bool
/= :: Constraint vt v loc -> Constraint vt v loc -> Bool
Eq, Eq (Constraint vt v loc)
Eq (Constraint vt v loc) =>
(Constraint vt v loc -> Constraint vt v loc -> Ordering)
-> (Constraint vt v loc -> Constraint vt v loc -> Bool)
-> (Constraint vt v loc -> Constraint vt v loc -> Bool)
-> (Constraint vt v loc -> Constraint vt v loc -> Bool)
-> (Constraint vt v loc -> Constraint vt v loc -> Bool)
-> (Constraint vt v loc
-> Constraint vt v loc -> Constraint vt v loc)
-> (Constraint vt v loc
-> Constraint vt v loc -> Constraint vt v loc)
-> Ord (Constraint vt v loc)
Constraint vt v loc -> Constraint vt v loc -> Bool
Constraint vt v loc -> Constraint vt v loc -> Ordering
Constraint vt v loc -> Constraint vt v loc -> Constraint vt v loc
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall vt v loc. (Var vt, Ord v) => Eq (Constraint vt v loc)
forall vt v loc.
(Var vt, Ord v) =>
Constraint vt v loc -> Constraint vt v loc -> Bool
forall vt v loc.
(Var vt, Ord v) =>
Constraint vt v loc -> Constraint vt v loc -> Ordering
forall vt v loc.
(Var vt, Ord v) =>
Constraint vt v loc -> Constraint vt v loc -> Constraint vt v loc
$ccompare :: forall vt v loc.
(Var vt, Ord v) =>
Constraint vt v loc -> Constraint vt v loc -> Ordering
compare :: Constraint vt v loc -> Constraint vt v loc -> Ordering
$c< :: forall vt v loc.
(Var vt, Ord v) =>
Constraint vt v loc -> Constraint vt v loc -> Bool
< :: Constraint vt v loc -> Constraint vt v loc -> Bool
$c<= :: forall vt v loc.
(Var vt, Ord v) =>
Constraint vt v loc -> Constraint vt v loc -> Bool
<= :: Constraint vt v loc -> Constraint vt v loc -> Bool
$c> :: forall vt v loc.
(Var vt, Ord v) =>
Constraint vt v loc -> Constraint vt v loc -> Bool
> :: Constraint vt v loc -> Constraint vt v loc -> Bool
$c>= :: forall vt v loc.
(Var vt, Ord v) =>
Constraint vt v loc -> Constraint vt v loc -> Bool
>= :: Constraint vt v loc -> Constraint vt v loc -> Bool
$cmax :: forall vt v loc.
(Var vt, Ord v) =>
Constraint vt v loc -> Constraint vt v loc -> Constraint vt v loc
max :: Constraint vt v loc -> Constraint vt v loc -> Constraint vt v loc
$cmin :: forall vt v loc.
(Var vt, Ord v) =>
Constraint vt v loc -> Constraint vt v loc -> Constraint vt v loc
min :: Constraint vt v loc -> Constraint vt v loc -> Constraint vt v loc
Ord)
prettyConstraint :: forall vt v loc. (Var vt, Var v) => PrettyPrintEnv -> Constraint vt v loc -> Pretty ColorText
prettyConstraint :: forall vt v loc.
(Var vt, Var v) =>
PrettyPrintEnv -> Constraint vt v loc -> Pretty ColorText
prettyConstraint PrettyPrintEnv
ppe = \case
PosCon v
var ConstructorReference
con [(v, Type vt loc)]
convars ->
let xs :: [Pretty ColorText]
xs = ConstructorReference -> Pretty ColorText
pc ConstructorReference
con Pretty ColorText -> [Pretty ColorText] -> [Pretty ColorText]
forall a. a -> [a] -> [a]
: ((v, Type vt loc) -> Pretty ColorText)
-> [(v, Type vt loc)] -> [Pretty ColorText]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(v
trm, Type vt loc
typ) -> Pretty ColorText -> [Pretty ColorText] -> Pretty ColorText
forall (f :: * -> *) s.
(Foldable f, IsString s) =>
Pretty s -> f (Pretty s) -> Pretty s
sep Pretty ColorText
" " [Pretty ColorText
"(" Pretty ColorText -> Pretty ColorText -> Pretty ColorText
forall a. Semigroup a => a -> a -> a
<> v -> Pretty ColorText
forall v. Var v => v -> Pretty ColorText
prettyVar v
trm, Pretty ColorText
":", PrettyPrintEnv -> Type vt loc -> Pretty ColorText
forall v a. Var v => PrettyPrintEnv -> Type v a -> Pretty ColorText
TypePrinter.pretty PrettyPrintEnv
ppe Type vt loc
typ Pretty ColorText -> Pretty ColorText -> Pretty ColorText
forall a. Semigroup a => a -> a -> a
<> Pretty ColorText
")"]) [(v, Type vt loc)]
convars [Pretty ColorText] -> [Pretty ColorText] -> [Pretty ColorText]
forall a. [a] -> [a] -> [a]
++ [Pretty ColorText
"<-", v -> Pretty ColorText
forall v. Var v => v -> Pretty ColorText
prettyVar v
var]
in Pretty ColorText -> [Pretty ColorText] -> Pretty ColorText
forall (f :: * -> *) s.
(Foldable f, IsString s) =>
Pretty s -> f (Pretty s) -> Pretty s
sep Pretty ColorText
" " [Pretty ColorText]
xs
NegCon v
var ConstructorReference
con -> Pretty ColorText -> [Pretty ColorText] -> Pretty ColorText
forall (f :: * -> *) s.
(Foldable f, IsString s) =>
Pretty s -> f (Pretty s) -> Pretty s
sep Pretty ColorText
" " [v -> Pretty ColorText
forall v. Var v => v -> Pretty ColorText
prettyVar v
var, Pretty ColorText
"≠", ConstructorReference -> Pretty ColorText
pc ConstructorReference
con]
PosEffect v
var EffectHandler
eff [(v, Type vt loc)]
effvars ->
let xs :: [Pretty ColorText]
xs = EffectHandler -> Pretty ColorText
pe EffectHandler
eff Pretty ColorText -> [Pretty ColorText] -> [Pretty ColorText]
forall a. a -> [a] -> [a]
: ((v, Type vt loc) -> Pretty ColorText)
-> [(v, Type vt loc)] -> [Pretty ColorText]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(v
trm, Type vt loc
typ) -> Pretty ColorText -> [Pretty ColorText] -> Pretty ColorText
forall (f :: * -> *) s.
(Foldable f, IsString s) =>
Pretty s -> f (Pretty s) -> Pretty s
sep Pretty ColorText
" " [Pretty ColorText
"(" Pretty ColorText -> Pretty ColorText -> Pretty ColorText
forall a. Semigroup a => a -> a -> a
<> v -> Pretty ColorText
forall v. Var v => v -> Pretty ColorText
prettyVar v
trm, Pretty ColorText
":", PrettyPrintEnv -> Type vt loc -> Pretty ColorText
forall v a. Var v => PrettyPrintEnv -> Type v a -> Pretty ColorText
TypePrinter.pretty PrettyPrintEnv
ppe Type vt loc
typ Pretty ColorText -> Pretty ColorText -> Pretty ColorText
forall a. Semigroup a => a -> a -> a
<> Pretty ColorText
")"]) [(v, Type vt loc)]
effvars [Pretty ColorText] -> [Pretty ColorText] -> [Pretty ColorText]
forall a. [a] -> [a] -> [a]
++ [Pretty ColorText
"<-", v -> Pretty ColorText
forall v. Var v => v -> Pretty ColorText
prettyVar v
var]
in Pretty ColorText -> [Pretty ColorText] -> Pretty ColorText
forall (f :: * -> *) s.
(Foldable f, IsString s) =>
Pretty s -> f (Pretty s) -> Pretty s
sep Pretty ColorText
" " [Pretty ColorText]
xs
NegEffect v
var EffectHandler
eff -> Pretty ColorText -> [Pretty ColorText] -> Pretty ColorText
forall (f :: * -> *) s.
(Foldable f, IsString s) =>
Pretty s -> f (Pretty s) -> Pretty s
sep Pretty ColorText
" " [v -> Pretty ColorText
forall v. Var v => v -> Pretty ColorText
prettyVar v
var, Pretty ColorText
"≠", EffectHandler -> Pretty ColorText
pe EffectHandler
eff]
PosLit v
var PmLit
lit -> Pretty ColorText -> [Pretty ColorText] -> Pretty ColorText
forall (f :: * -> *) s.
(Foldable f, IsString s) =>
Pretty s -> f (Pretty s) -> Pretty s
sep Pretty ColorText
" " [PmLit -> Pretty ColorText
forall s. IsString s => PmLit -> Pretty s
prettyPmLit PmLit
lit, Pretty ColorText
"<-", v -> Pretty ColorText
forall v. Var v => v -> Pretty ColorText
prettyVar v
var]
NegLit v
var PmLit
lit -> Pretty ColorText -> [Pretty ColorText] -> Pretty ColorText
forall (f :: * -> *) s.
(Foldable f, IsString s) =>
Pretty s -> f (Pretty s) -> Pretty s
sep Pretty ColorText
" " [v -> Pretty ColorText
forall v. Var v => v -> Pretty ColorText
prettyVar v
var, Pretty ColorText
"≠", PmLit -> Pretty ColorText
forall s. IsString s => PmLit -> Pretty s
prettyPmLit PmLit
lit]
PosListHead v
root Int
n v
el -> Pretty ColorText -> [Pretty ColorText] -> Pretty ColorText
forall (f :: * -> *) s.
(Foldable f, IsString s) =>
Pretty s -> f (Pretty s) -> Pretty s
sep Pretty ColorText
" " [v -> Pretty ColorText
forall v. Var v => v -> Pretty ColorText
prettyVar v
el, Pretty ColorText
"<-", Pretty ColorText
"head", Int -> Pretty ColorText
forall a. Show a => a -> Pretty ColorText
pany Int
n, v -> Pretty ColorText
forall v. Var v => v -> Pretty ColorText
prettyVar v
root]
PosListTail v
root Int
n v
el -> Pretty ColorText -> [Pretty ColorText] -> Pretty ColorText
forall (f :: * -> *) s.
(Foldable f, IsString s) =>
Pretty s -> f (Pretty s) -> Pretty s
sep Pretty ColorText
" " [v -> Pretty ColorText
forall v. Var v => v -> Pretty ColorText
prettyVar v
el, Pretty ColorText
"<-", Pretty ColorText
"tail", Int -> Pretty ColorText
forall a. Show a => a -> Pretty ColorText
pany Int
n, v -> Pretty ColorText
forall v. Var v => v -> Pretty ColorText
prettyVar v
root]
NegListInterval v
var IntervalSet
x -> Pretty ColorText -> [Pretty ColorText] -> Pretty ColorText
forall (f :: * -> *) s.
(Foldable f, IsString s) =>
Pretty s -> f (Pretty s) -> Pretty s
sep Pretty ColorText
" " [v -> Pretty ColorText
forall v. Var v => v -> Pretty ColorText
prettyVar v
var, Pretty ColorText
"≠", String -> Pretty ColorText
forall s. IsString s => String -> Pretty s
string (IntervalSet -> String
forall a. Show a => a -> String
show IntervalSet
x)]
Effectful v
var -> Pretty ColorText
"!" Pretty ColorText -> Pretty ColorText -> Pretty ColorText
forall a. Semigroup a => a -> a -> a
<> v -> Pretty ColorText
forall v. Var v => v -> Pretty ColorText
prettyVar v
var
Eq v
v0 v
v1 -> Pretty ColorText -> [Pretty ColorText] -> Pretty ColorText
forall (f :: * -> *) s.
(Foldable f, IsString s) =>
Pretty s -> f (Pretty s) -> Pretty s
sep Pretty ColorText
" " [v -> Pretty ColorText
forall v. Var v => v -> Pretty ColorText
prettyVar v
v0, Pretty ColorText
"=", v -> Pretty ColorText
forall v. Var v => v -> Pretty ColorText
prettyVar v
v1]
where
pany :: (Show a) => a -> Pretty ColorText
pany :: forall a. Show a => a -> Pretty ColorText
pany = String -> Pretty ColorText
forall s. IsString s => String -> Pretty s
string (String -> Pretty ColorText)
-> (a -> String) -> a -> Pretty ColorText
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> String
forall a. Show a => a -> String
show
pc :: ConstructorReference -> Pretty ColorText
pc = PrettyPrintEnv -> ConstructorReference -> Pretty ColorText
prettyConstructorReference PrettyPrintEnv
ppe
pe :: EffectHandler -> Pretty ColorText
pe = PrettyPrintEnv -> EffectHandler -> Pretty ColorText
prettyEffectHandler PrettyPrintEnv
ppe