From 02238340dfec5173381e3dc53c13a082ed52a2c6 Mon Sep 17 00:00:00 2001 From: "Vlad P. Luchian" Date: Wed, 1 Feb 2023 10:13:27 +0000 Subject: [PATCH 01/11] update: add the arbitrary instances --- .../lambda-buffers-compiler.cabal | 1 + .../Compiler/ProtoCompat/Types.hs | 234 ++++++++++++------ 2 files changed, 165 insertions(+), 70 deletions(-) diff --git a/lambda-buffers-compiler/lambda-buffers-compiler.cabal b/lambda-buffers-compiler/lambda-buffers-compiler.cabal index c3b48c5d..f51c6e72 100644 --- a/lambda-buffers-compiler/lambda-buffers-compiler.cabal +++ b/lambda-buffers-compiler/lambda-buffers-compiler.cabal @@ -100,6 +100,7 @@ library , parsec >=3.1 , prettyprinter >=1.7 , proto-lens >=0.7 + , QuickCheck >=2.14 , text >=1.2 exposed-modules: diff --git a/lambda-buffers-compiler/src/LambdaBuffers/Compiler/ProtoCompat/Types.hs b/lambda-buffers-compiler/src/LambdaBuffers/Compiler/ProtoCompat/Types.hs index de43aff8..931e6623 100644 --- a/lambda-buffers-compiler/src/LambdaBuffers/Compiler/ProtoCompat/Types.hs +++ b/lambda-buffers-compiler/src/LambdaBuffers/Compiler/ProtoCompat/Types.hs @@ -1,4 +1,5 @@ {-# LANGUAGE DuplicateRecordFields #-} +{-# OPTIONS_GHC -Wno-orphans #-} module LambdaBuffers.Compiler.ProtoCompat.Types ( ClassDef (..), @@ -44,11 +45,12 @@ module LambdaBuffers.Compiler.ProtoCompat.Types ( ) where import Control.Exception (Exception) -import Data.List.NonEmpty (NonEmpty) +import Data.List.NonEmpty (NonEmpty ((:|)), (<|)) import Data.Map qualified as M -import Data.Text (Text) +import Data.Text (Text, pack) import GHC.Generics (Generic) import LambdaBuffers.Compiler.KindCheck.Variable as VARS (Atom, Var) +import Test.QuickCheck (Arbitrary (arbitrary), Gen, oneof, sized) data SourceInfo = SourceInfo {file :: Text, posFrom :: SourcePosition, posTo :: SourcePosition} deriving stock (Show, Eq, Ord, Generic) @@ -84,106 +86,58 @@ data ClassName = ClassName {name :: Text, sourceInfo :: SourceInfo} newtype Kind = Kind {kind :: KindType} deriving stock (Show, Eq, Ord, Generic) -data KindType - = KindRef KindRefType - | KindArrow Kind Kind +data KindType = KindRef KindRefType | KindArrow Kind Kind deriving stock (Show, Eq, Ord, Generic) -data KindRefType - = KUnspecified - | KType +data KindRefType = KUnspecified | KType deriving stock (Show, Eq, Ord, Generic) data TyVar = TyVar {varName :: VarName, sourceInfo :: SourceInfo} deriving stock (Show, Eq, Ord, Generic) -data Ty - = TyVarI TyVar - | TyAppI TyApp - | TyRefI TyRef +data Ty = TyVarI TyVar | TyAppI TyApp | TyRefI TyRef deriving stock (Show, Eq, Ord, Generic) -data TyApp = TyApp - { tyFunc :: Ty - , tyArgs :: NonEmpty Ty - , sourceInfo :: SourceInfo - } +data TyApp = TyApp {tyFunc :: Ty, tyArgs :: NonEmpty Ty, sourceInfo :: SourceInfo} deriving stock (Show, Eq, Ord, Generic) -data ForeignRef = ForeignRef - { tyName :: TyName - , moduleName :: ModuleName - , sourceInfo :: SourceInfo - } +data ForeignRef = ForeignRef {tyName :: TyName, moduleName :: ModuleName, sourceInfo :: SourceInfo} deriving stock (Show, Eq, Ord, Generic) data LocalRef = LocalRef {tyName :: TyName, sourceInfo :: SourceInfo} deriving stock (Show, Eq, Ord, Generic) -data TyRef - = LocalI LocalRef - | ForeignI ForeignRef +data TyRef = LocalI LocalRef | ForeignI ForeignRef deriving stock (Show, Eq, Ord, Generic) -data TyDef = TyDef - { tyName :: TyName - , tyAbs :: TyAbs - , sourceInfo :: SourceInfo - } +data TyDef = TyDef {tyName :: TyName, tyAbs :: TyAbs, sourceInfo :: SourceInfo} deriving stock (Show, Eq, Ord, Generic) -data TyAbs = TyAbs - { tyArgs :: [TyArg] - , tyBody :: TyBody - , sourceInfo :: SourceInfo - } +data TyAbs = TyAbs {tyArgs :: [TyArg], tyBody :: TyBody, sourceInfo :: SourceInfo} deriving stock (Show, Eq, Ord, Generic) -data TyArg = TyArg - { argName :: VarName - , argKind :: Kind - , sourceInfo :: SourceInfo - } +data TyArg = TyArg {argName :: VarName, argKind :: Kind, sourceInfo :: SourceInfo} deriving stock (Show, Eq, Ord, Generic) -data TyBody - = OpaqueI SourceInfo - | SumI Sum +data TyBody = OpaqueI SourceInfo | SumI Sum deriving stock (Show, Eq, Ord, Generic) -data Constructor = Constructor - { constrName :: ConstrName - , product :: Product - } +data Constructor = Constructor {constrName :: ConstrName, product :: Product} deriving stock (Show, Eq, Ord, Generic) -data Sum = Sum - { constructors :: NonEmpty Constructor - , sourceInfo :: SourceInfo - } +data Sum = Sum {constructors :: NonEmpty Constructor, sourceInfo :: SourceInfo} deriving stock (Show, Eq, Ord, Generic) -data Field = Field - { fieldName :: FieldName - , fieldTy :: Ty - } +data Field = Field {fieldName :: FieldName, fieldTy :: Ty} deriving stock (Show, Eq, Ord, Generic) -data Record = Record - { fields :: NonEmpty Field - , sourceInfo :: SourceInfo - } +data Record = Record {fields :: NonEmpty Field, sourceInfo :: SourceInfo} deriving stock (Show, Eq, Ord, Generic) -data Tuple = Tuple - { fields :: [Ty] - , sourceInfo :: SourceInfo - } +data Tuple = Tuple {fields :: [Ty], sourceInfo :: SourceInfo} deriving stock (Show, Eq, Ord, Generic) -data Product - = RecordI Record - | TupleI Tuple +data Product = RecordI Record | TupleI Tuple deriving stock (Show, Eq, Ord, Generic) data ClassDef = ClassDef @@ -237,17 +191,157 @@ instance Exception KindCheckErr newtype CompilerInput = CompilerInput {modules :: [Module]} deriving stock (Show, Eq, Ord, Generic) - deriving newtype (Monoid, Semigroup) + deriving newtype (Monoid, Semigroup, Arbitrary) -newtype CompilerOutput = CompilerOutput - { typeDefs :: M.Map Var Kind - } +newtype CompilerOutput = CompilerOutput {typeDefs :: M.Map Var Kind} deriving stock (Show, Eq, Ord, Generic) + deriving newtype (Arbitrary) newtype CompilerFailure = KCErr KindCheckErr deriving stock (Show, Eq, Ord, Generic) + deriving newtype (Arbitrary) data CompilerResult = RCompilerFailure CompilerFailure | RCompilerOutput CompilerOutput deriving stock (Show, Eq, Ord, Generic) + +instance Arbitrary SourceInfo where + arbitrary = SourceInfo <$> arbitrary <*> arbitrary <*> arbitrary + +instance Arbitrary SourcePosition where + arbitrary = SourcePosition <$> arbitrary <*> arbitrary + +instance Arbitrary LBName where + arbitrary = LBName <$> arbitrary <*> arbitrary + +instance Arbitrary TyName where + arbitrary = TyName <$> arbitrary <*> arbitrary + +instance Arbitrary ConstrName where + arbitrary = ConstrName <$> arbitrary <*> arbitrary + +instance Arbitrary ModuleName where + arbitrary = ModuleName <$> arbitrary <*> arbitrary + +instance Arbitrary ModuleNamePart where + arbitrary = ModuleNamePart <$> arbitrary <*> arbitrary + +instance Arbitrary VarName where + arbitrary = VarName <$> arbitrary <*> arbitrary + +instance Arbitrary FieldName where + arbitrary = FieldName <$> arbitrary <*> arbitrary + +instance Arbitrary ClassName where + arbitrary = ClassName <$> arbitrary <*> arbitrary + +instance Arbitrary Kind where + arbitrary = Kind <$> arbitrary + +instance Arbitrary KindType where + arbitrary = oneof [KindRef <$> arbitrary, KindArrow <$> arbitrary <*> arbitrary] + +instance Arbitrary KindRefType where + arbitrary = oneof [pure KUnspecified, pure KType] + +instance Arbitrary TyVar where + arbitrary = TyVar <$> arbitrary <*> arbitrary + +instance Arbitrary Ty where + arbitrary = oneof [TyVarI <$> arbitrary, TyAppI <$> arbitrary, TyRefI <$> arbitrary] + +instance Arbitrary TyApp where + arbitrary = TyApp <$> arbitrary <*> arbitrary <*> arbitrary + +instance Arbitrary ForeignRef where + arbitrary = ForeignRef <$> arbitrary <*> arbitrary <*> arbitrary + +instance Arbitrary LocalRef where + arbitrary = LocalRef <$> arbitrary <*> arbitrary + +instance Arbitrary TyRef where + arbitrary = oneof [LocalI <$> arbitrary, ForeignI <$> arbitrary] + +instance Arbitrary TyDef where + arbitrary = TyDef <$> arbitrary <*> arbitrary <*> arbitrary + +instance Arbitrary TyAbs where + arbitrary = TyAbs <$> arbitrary <*> arbitrary <*> arbitrary + +instance Arbitrary TyArg where + arbitrary = TyArg <$> arbitrary <*> arbitrary <*> arbitrary + +instance Arbitrary TyBody where + arbitrary = oneof [OpaqueI <$> arbitrary, SumI <$> arbitrary] + +instance Arbitrary Constructor where + arbitrary = Constructor <$> arbitrary <*> arbitrary + +instance Arbitrary Sum where + arbitrary = Sum <$> arbitrary <*> arbitrary + +instance Arbitrary Field where + arbitrary = Field <$> arbitrary <*> arbitrary + +instance Arbitrary Record where + arbitrary = Record <$> arbitrary <*> arbitrary + +instance Arbitrary Tuple where + arbitrary = Tuple <$> arbitrary <*> arbitrary + +instance Arbitrary Product where + arbitrary = oneof [RecordI <$> arbitrary, TupleI <$> arbitrary] + +instance Arbitrary ClassDef where + arbitrary = ClassDef <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary + +instance Arbitrary InstanceClause where + arbitrary = InstanceClause <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary + +instance Arbitrary Constraint where + arbitrary = Constraint <$> arbitrary <*> arbitrary <*> arbitrary + +instance Arbitrary Module where + arbitrary = Module <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary + +instance Arbitrary InferenceErr where + arbitrary = + oneof + [ UnboundTermErr <$> arbitrary + , ImpossibleErr <$> arbitrary + , UnificationErr <$> arbitrary + , RecursiveSubstitutionErr <$> arbitrary + ] + +instance Arbitrary KindCheckErr where + arbitrary = + oneof + [ InconsistentTypeErr <$> arbitrary + , InferenceFailure <$> arbitrary <*> arbitrary + ] + +instance Arbitrary CompilerResult where + arbitrary = + oneof + [ RCompilerFailure <$> arbitrary + , RCompilerOutput <$> arbitrary + ] + +-- Orphan Instances + +instance Arbitrary a => Arbitrary (NonEmpty a) where + arbitrary = sized f + where + f :: (Num t, Ord t) => t -> Gen (NonEmpty a) + f n + | n <= 0 = do + x <- arbitrary @a + pure $ x :| [] + | otherwise = do + x <- arbitrary + xs <- f (n - 1) + pure $ x <| xs + +instance Arbitrary Text where + arbitrary = pack <$> arbitrary From a5797c4d6e26f2c311e9d282ce0df8c1fc8c5986 Mon Sep 17 00:00:00 2001 From: "Vlad P. Luchian" Date: Wed, 1 Feb 2023 15:45:37 +0000 Subject: [PATCH 02/11] update: implement sized elements --- .../lambda-buffers-compiler.cabal | 5 + .../LambdaBuffers/Compiler/KindCheck/Type.hs | 13 + .../Compiler/KindCheck/Variable.hs | 1 + .../Compiler/ProtoCompat/Types.hs | 224 +++++++----------- lambda-buffers-compiler/src/Orphan/Text.hs | 7 + .../test/Test/KindCheck.hs | 56 ++++- 6 files changed, 169 insertions(+), 137 deletions(-) create mode 100644 lambda-buffers-compiler/src/Orphan/Text.hs diff --git a/lambda-buffers-compiler/lambda-buffers-compiler.cabal b/lambda-buffers-compiler/lambda-buffers-compiler.cabal index f51c6e72..eb2b7c10 100644 --- a/lambda-buffers-compiler/lambda-buffers-compiler.cabal +++ b/lambda-buffers-compiler/lambda-buffers-compiler.cabal @@ -37,6 +37,7 @@ common common-language DeriveLift DeriveTraversable DerivingStrategies + DerivingVia DoAndIfThenElse DuplicateRecordFields EmptyCase @@ -94,6 +95,7 @@ library build-depends: , containers >=0.6.5.1 , freer-simple >=1.2 + , generic-arbitrary , generic-lens >=2.2 , lambda-buffers-compiler-pb >=0.1.0.0 , mtl >=2.2 @@ -116,6 +118,7 @@ library LambdaBuffers.Compiler.ProtoCompat LambdaBuffers.Compiler.ProtoCompat.Types LambdaBuffers.Compiler.TypeClassCheck + Orphan.Text hs-source-dirs: src @@ -145,8 +148,10 @@ test-suite tests , lambda-buffers-compiler , lambda-buffers-compiler-pb >=0.1 , proto-lens >=0.7 + , QuickCheck >=2.14 , tasty >=1.4 , tasty-hunit >=0.10 + , tasty-quickcheck >=0.10 , text >=1.2 other-modules: diff --git a/lambda-buffers-compiler/src/LambdaBuffers/Compiler/KindCheck/Type.hs b/lambda-buffers-compiler/src/LambdaBuffers/Compiler/KindCheck/Type.hs index edf693d5..5a8988ef 100644 --- a/lambda-buffers-compiler/src/LambdaBuffers/Compiler/KindCheck/Type.hs +++ b/lambda-buffers-compiler/src/LambdaBuffers/Compiler/KindCheck/Type.hs @@ -2,6 +2,7 @@ module LambdaBuffers.Compiler.KindCheck.Type (Type (Var, Abs, App)) where import LambdaBuffers.Compiler.KindCheck.Variable (Var) import Prettyprinter (Doc, Pretty (pretty), parens, (<+>)) +import Test.QuickCheck (Arbitrary, arbitrary, oneof, sized) data Type = Var Var @@ -20,3 +21,15 @@ instance Pretty Type where Var a -> pretty a App t1 t2 -> parens $ show' t1 <+> show' t2 Abs a t1 -> parens $ "λ" <> pretty a <> "." <> show' t1 + +instance Arbitrary Type where + arbitrary = sized f + where + f n + | n <= 0 = Var <$> arbitrary + | otherwise = + oneof + [ Var <$> arbitrary + , App <$> f (n `div` 2) <*> f (n `div` 2) + , Abs <$> arbitrary <*> f (n - 1) + ] diff --git a/lambda-buffers-compiler/src/LambdaBuffers/Compiler/KindCheck/Variable.hs b/lambda-buffers-compiler/src/LambdaBuffers/Compiler/KindCheck/Variable.hs index 7dbcd2f6..8184bce1 100644 --- a/lambda-buffers-compiler/src/LambdaBuffers/Compiler/KindCheck/Variable.hs +++ b/lambda-buffers-compiler/src/LambdaBuffers/Compiler/KindCheck/Variable.hs @@ -1,6 +1,7 @@ module LambdaBuffers.Compiler.KindCheck.Variable (Atom, Var) where import Data.Text (Text) +import Orphan.Text type Atom = Text type Var = Text diff --git a/lambda-buffers-compiler/src/LambdaBuffers/Compiler/ProtoCompat/Types.hs b/lambda-buffers-compiler/src/LambdaBuffers/Compiler/ProtoCompat/Types.hs index 931e6623..dd86fdd4 100644 --- a/lambda-buffers-compiler/src/LambdaBuffers/Compiler/ProtoCompat/Types.hs +++ b/lambda-buffers-compiler/src/LambdaBuffers/Compiler/ProtoCompat/Types.hs @@ -1,4 +1,3 @@ -{-# LANGUAGE DuplicateRecordFields #-} {-# OPTIONS_GHC -Wno-orphans #-} module LambdaBuffers.Compiler.ProtoCompat.Types ( @@ -47,98 +46,151 @@ module LambdaBuffers.Compiler.ProtoCompat.Types ( import Control.Exception (Exception) import Data.List.NonEmpty (NonEmpty ((:|)), (<|)) import Data.Map qualified as M -import Data.Text (Text, pack) +import Data.Text (Text) import GHC.Generics (Generic) import LambdaBuffers.Compiler.KindCheck.Variable as VARS (Atom, Var) -import Test.QuickCheck (Arbitrary (arbitrary), Gen, oneof, sized) +import Test.QuickCheck (Arbitrary (arbitrary), Gen, NonEmptyList (getNonEmpty), oneof, resize, sized) +import Test.QuickCheck.Arbitrary.Generic data SourceInfo = SourceInfo {file :: Text, posFrom :: SourcePosition, posTo :: SourcePosition} deriving stock (Show, Eq, Ord, Generic) + deriving (Arbitrary) via GenericArbitrary SourceInfo data SourcePosition = SourcePosition {column :: Int, row :: Int} deriving stock (Show, Eq, Ord, Generic) + deriving (Arbitrary) via GenericArbitrary SourcePosition --- NOTE(gnumonik): I need a "generic name" type for my template haskell, this shouldn't be used anywhere outside of that +{- | NOTE(gnumonik): I need a "generic name" type for my template haskell, this + shouldn't be used anywhere outside of that +-} data LBName = LBName {name :: Text, sourceInfo :: SourceInfo} deriving stock (Show, Eq, Ord, Generic) + deriving (Arbitrary) via GenericArbitrary LBName data TyName = TyName {name :: Text, sourceInfo :: SourceInfo} deriving stock (Show, Eq, Ord, Generic) + deriving (Arbitrary) via GenericArbitrary TyName data ConstrName = ConstrName {name :: Text, sourceInfo :: SourceInfo} deriving stock (Show, Eq, Ord, Generic) + deriving (Arbitrary) via GenericArbitrary ConstrName data ModuleName = ModuleName {parts :: [ModuleNamePart], sourceInfo :: SourceInfo} deriving stock (Show, Eq, Ord, Generic) + deriving (Arbitrary) via GenericArbitrary ModuleName data ModuleNamePart = ModuleNamePart {name :: Text, sourceInfo :: SourceInfo} deriving stock (Show, Eq, Ord, Generic) + deriving (Arbitrary) via GenericArbitrary ModuleNamePart data VarName = VarName {name :: Text, sourceInfo :: SourceInfo} deriving stock (Show, Eq, Ord, Generic) + deriving (Arbitrary) via GenericArbitrary VarName data FieldName = FieldName {name :: Text, sourceInfo :: SourceInfo} deriving stock (Show, Eq, Ord, Generic) + deriving (Arbitrary) via GenericArbitrary FieldName data ClassName = ClassName {name :: Text, sourceInfo :: SourceInfo} deriving stock (Show, Eq, Ord, Generic) + deriving (Arbitrary) via GenericArbitrary ClassName newtype Kind = Kind {kind :: KindType} deriving stock (Show, Eq, Ord, Generic) +instance Arbitrary Kind where + arbitrary = sized fn + where + fn n = Kind <$> resize n arbitrary + data KindType = KindRef KindRefType | KindArrow Kind Kind deriving stock (Show, Eq, Ord, Generic) +instance Arbitrary KindType where + arbitrary = sized fn + where + fn n + | n <= 0 = KindRef <$> arbitrary + | otherwise = KindArrow <$> resize (n `div` 2) arbitrary <*> resize (n `div` 2) arbitrary + data KindRefType = KUnspecified | KType deriving stock (Show, Eq, Ord, Generic) + deriving (Arbitrary) via GenericArbitrary KindRefType data TyVar = TyVar {varName :: VarName, sourceInfo :: SourceInfo} deriving stock (Show, Eq, Ord, Generic) + deriving (Arbitrary) via GenericArbitrary TyVar data Ty = TyVarI TyVar | TyAppI TyApp | TyRefI TyRef deriving stock (Show, Eq, Ord, Generic) +instance Arbitrary Ty where + arbitrary = sized fn + where + fn n + | n <= 0 = TyRefI <$> arbitrary + | otherwise = + oneof + [ TyVarI <$> arbitrary + , TyAppI <$> arbitrary + , TyRefI <$> arbitrary + ] + data TyApp = TyApp {tyFunc :: Ty, tyArgs :: NonEmpty Ty, sourceInfo :: SourceInfo} deriving stock (Show, Eq, Ord, Generic) + deriving (Arbitrary) via GenericArbitrary TyApp data ForeignRef = ForeignRef {tyName :: TyName, moduleName :: ModuleName, sourceInfo :: SourceInfo} deriving stock (Show, Eq, Ord, Generic) + deriving (Arbitrary) via GenericArbitrary ForeignRef data LocalRef = LocalRef {tyName :: TyName, sourceInfo :: SourceInfo} deriving stock (Show, Eq, Ord, Generic) + deriving (Arbitrary) via GenericArbitrary LocalRef data TyRef = LocalI LocalRef | ForeignI ForeignRef deriving stock (Show, Eq, Ord, Generic) + deriving (Arbitrary) via GenericArbitrary TyRef data TyDef = TyDef {tyName :: TyName, tyAbs :: TyAbs, sourceInfo :: SourceInfo} deriving stock (Show, Eq, Ord, Generic) + deriving (Arbitrary) via GenericArbitrary TyDef data TyAbs = TyAbs {tyArgs :: [TyArg], tyBody :: TyBody, sourceInfo :: SourceInfo} deriving stock (Show, Eq, Ord, Generic) + deriving (Arbitrary) via GenericArbitrary TyAbs data TyArg = TyArg {argName :: VarName, argKind :: Kind, sourceInfo :: SourceInfo} deriving stock (Show, Eq, Ord, Generic) + deriving (Arbitrary) via GenericArbitrary TyArg data TyBody = OpaqueI SourceInfo | SumI Sum deriving stock (Show, Eq, Ord, Generic) + deriving (Arbitrary) via GenericArbitrary TyBody data Constructor = Constructor {constrName :: ConstrName, product :: Product} deriving stock (Show, Eq, Ord, Generic) + deriving (Arbitrary) via GenericArbitrary Constructor data Sum = Sum {constructors :: NonEmpty Constructor, sourceInfo :: SourceInfo} deriving stock (Show, Eq, Ord, Generic) + deriving (Arbitrary) via GenericArbitrary Sum data Field = Field {fieldName :: FieldName, fieldTy :: Ty} deriving stock (Show, Eq, Ord, Generic) + deriving (Arbitrary) via GenericArbitrary Field data Record = Record {fields :: NonEmpty Field, sourceInfo :: SourceInfo} deriving stock (Show, Eq, Ord, Generic) + deriving (Arbitrary) via GenericArbitrary Record data Tuple = Tuple {fields :: [Ty], sourceInfo :: SourceInfo} deriving stock (Show, Eq, Ord, Generic) + deriving (Arbitrary) via GenericArbitrary Tuple data Product = RecordI Record | TupleI Tuple deriving stock (Show, Eq, Ord, Generic) + deriving (Arbitrary) via GenericArbitrary Product data ClassDef = ClassDef { className :: ClassName @@ -148,6 +200,7 @@ data ClassDef = ClassDef , sourceInfo :: SourceInfo } deriving stock (Show, Eq, Ord, Generic) + deriving (Arbitrary) via GenericArbitrary ClassDef data InstanceClause = InstanceClause { className :: ClassName @@ -157,12 +210,23 @@ data InstanceClause = InstanceClause } deriving stock (Show, Eq, Ord, Generic) +instance Arbitrary InstanceClause where + arbitrary = sized fn + where + fn n = + InstanceClause + <$> resize n arbitrary + <*> resize n arbitrary + <*> resize n arbitrary + <*> resize n arbitrary + data Constraint = Constraint { className :: ClassName , argument :: Ty , sourceInfo :: SourceInfo } deriving stock (Show, Eq, Ord, Generic) + deriving (Arbitrary) via GenericArbitrary Constraint data Module = Module { moduleName :: ModuleName @@ -173,12 +237,24 @@ data Module = Module } deriving stock (Show, Eq, Ord, Generic) +instance Arbitrary Module where + arbitrary = sized fn + where + fn n = + Module + <$> resize n arbitrary + <*> resize n arbitrary + <*> resize n arbitrary + <*> resize n arbitrary + <*> resize n arbitrary + data InferenceErr = UnboundTermErr Text | ImpossibleErr Text | UnificationErr Text | RecursiveSubstitutionErr Text deriving stock (Show, Eq, Ord, Generic) + deriving (Arbitrary) via GenericArbitrary InferenceErr instance Exception InferenceErr @@ -186,150 +262,37 @@ data KindCheckErr = InconsistentTypeErr TyDef | InferenceFailure TyDef InferenceErr deriving stock (Show, Eq, Ord, Generic) + deriving (Arbitrary) via GenericArbitrary KindCheckErr instance Exception KindCheckErr newtype CompilerInput = CompilerInput {modules :: [Module]} deriving stock (Show, Eq, Ord, Generic) - deriving newtype (Monoid, Semigroup, Arbitrary) + deriving newtype (Monoid, Semigroup) + +instance Arbitrary CompilerInput where + arbitrary = sized fn + where + fn n = CompilerInput <$> resize n arbitrary newtype CompilerOutput = CompilerOutput {typeDefs :: M.Map Var Kind} deriving stock (Show, Eq, Ord, Generic) - deriving newtype (Arbitrary) + deriving (Arbitrary) via GenericArbitrary CompilerOutput newtype CompilerFailure = KCErr KindCheckErr deriving stock (Show, Eq, Ord, Generic) - deriving newtype (Arbitrary) + deriving (Arbitrary) via GenericArbitrary CompilerFailure data CompilerResult = RCompilerFailure CompilerFailure | RCompilerOutput CompilerOutput deriving stock (Show, Eq, Ord, Generic) + deriving (Arbitrary) via GenericArbitrary CompilerResult -instance Arbitrary SourceInfo where - arbitrary = SourceInfo <$> arbitrary <*> arbitrary <*> arbitrary - -instance Arbitrary SourcePosition where - arbitrary = SourcePosition <$> arbitrary <*> arbitrary - -instance Arbitrary LBName where - arbitrary = LBName <$> arbitrary <*> arbitrary - -instance Arbitrary TyName where - arbitrary = TyName <$> arbitrary <*> arbitrary - -instance Arbitrary ConstrName where - arbitrary = ConstrName <$> arbitrary <*> arbitrary - -instance Arbitrary ModuleName where - arbitrary = ModuleName <$> arbitrary <*> arbitrary - -instance Arbitrary ModuleNamePart where - arbitrary = ModuleNamePart <$> arbitrary <*> arbitrary - -instance Arbitrary VarName where - arbitrary = VarName <$> arbitrary <*> arbitrary - -instance Arbitrary FieldName where - arbitrary = FieldName <$> arbitrary <*> arbitrary - -instance Arbitrary ClassName where - arbitrary = ClassName <$> arbitrary <*> arbitrary - -instance Arbitrary Kind where - arbitrary = Kind <$> arbitrary - -instance Arbitrary KindType where - arbitrary = oneof [KindRef <$> arbitrary, KindArrow <$> arbitrary <*> arbitrary] - -instance Arbitrary KindRefType where - arbitrary = oneof [pure KUnspecified, pure KType] - -instance Arbitrary TyVar where - arbitrary = TyVar <$> arbitrary <*> arbitrary - -instance Arbitrary Ty where - arbitrary = oneof [TyVarI <$> arbitrary, TyAppI <$> arbitrary, TyRefI <$> arbitrary] - -instance Arbitrary TyApp where - arbitrary = TyApp <$> arbitrary <*> arbitrary <*> arbitrary - -instance Arbitrary ForeignRef where - arbitrary = ForeignRef <$> arbitrary <*> arbitrary <*> arbitrary - -instance Arbitrary LocalRef where - arbitrary = LocalRef <$> arbitrary <*> arbitrary - -instance Arbitrary TyRef where - arbitrary = oneof [LocalI <$> arbitrary, ForeignI <$> arbitrary] - -instance Arbitrary TyDef where - arbitrary = TyDef <$> arbitrary <*> arbitrary <*> arbitrary - -instance Arbitrary TyAbs where - arbitrary = TyAbs <$> arbitrary <*> arbitrary <*> arbitrary - -instance Arbitrary TyArg where - arbitrary = TyArg <$> arbitrary <*> arbitrary <*> arbitrary - -instance Arbitrary TyBody where - arbitrary = oneof [OpaqueI <$> arbitrary, SumI <$> arbitrary] - -instance Arbitrary Constructor where - arbitrary = Constructor <$> arbitrary <*> arbitrary - -instance Arbitrary Sum where - arbitrary = Sum <$> arbitrary <*> arbitrary - -instance Arbitrary Field where - arbitrary = Field <$> arbitrary <*> arbitrary - -instance Arbitrary Record where - arbitrary = Record <$> arbitrary <*> arbitrary - -instance Arbitrary Tuple where - arbitrary = Tuple <$> arbitrary <*> arbitrary - -instance Arbitrary Product where - arbitrary = oneof [RecordI <$> arbitrary, TupleI <$> arbitrary] - -instance Arbitrary ClassDef where - arbitrary = ClassDef <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary - -instance Arbitrary InstanceClause where - arbitrary = InstanceClause <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary - -instance Arbitrary Constraint where - arbitrary = Constraint <$> arbitrary <*> arbitrary <*> arbitrary - -instance Arbitrary Module where - arbitrary = Module <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary - -instance Arbitrary InferenceErr where - arbitrary = - oneof - [ UnboundTermErr <$> arbitrary - , ImpossibleErr <$> arbitrary - , UnificationErr <$> arbitrary - , RecursiveSubstitutionErr <$> arbitrary - ] - -instance Arbitrary KindCheckErr where - arbitrary = - oneof - [ InconsistentTypeErr <$> arbitrary - , InferenceFailure <$> arbitrary <*> arbitrary - ] - -instance Arbitrary CompilerResult where - arbitrary = - oneof - [ RCompilerFailure <$> arbitrary - , RCompilerOutput <$> arbitrary - ] +nonEmptyArbList :: forall a. Arbitrary a => Gen [a] +nonEmptyArbList = getNonEmpty <$> arbitrary @(NonEmptyList a) -- Orphan Instances - instance Arbitrary a => Arbitrary (NonEmpty a) where arbitrary = sized f where @@ -342,6 +305,3 @@ instance Arbitrary a => Arbitrary (NonEmpty a) where x <- arbitrary xs <- f (n - 1) pure $ x <| xs - -instance Arbitrary Text where - arbitrary = pack <$> arbitrary diff --git a/lambda-buffers-compiler/src/Orphan/Text.hs b/lambda-buffers-compiler/src/Orphan/Text.hs new file mode 100644 index 00000000..d6702027 --- /dev/null +++ b/lambda-buffers-compiler/src/Orphan/Text.hs @@ -0,0 +1,7 @@ +module Orphan.Text where + +import Data.Text +import Test.QuickCheck (Arbitrary (arbitrary), Gen, oneof, sized) + +instance Arbitrary Text where + arbitrary = pack <$> arbitrary diff --git a/lambda-buffers-compiler/test/Test/KindCheck.hs b/lambda-buffers-compiler/test/Test/KindCheck.hs index 1ef021f0..f013b401 100644 --- a/lambda-buffers-compiler/test/Test/KindCheck.hs +++ b/lambda-buffers-compiler/test/Test/KindCheck.hs @@ -1,5 +1,6 @@ module Test.KindCheck (test) where +import Data.Bifunctor (Bifunctor (bimap)) import Data.List.NonEmpty (NonEmpty ((:|)), cons) import LambdaBuffers.Compiler.KindCheck ( check_, @@ -7,19 +8,37 @@ import LambdaBuffers.Compiler.KindCheck ( foldWithSum, ) import LambdaBuffers.Compiler.KindCheck.Type (Type (App, Var)) -import LambdaBuffers.Compiler.ProtoCompat qualified as P -import Test.Samples (compilerInput'incoherent, compilerInput'maybe) +import LambdaBuffers.Compiler.ProtoCompat.Types qualified as P ( + CompilerInput (CompilerInput), + ) +import Test.QuickCheck ( + Arbitrary (arbitrary, shrink), + Property, + forAll, + forAllShrink, + resize, + shuffle, + (===), + ) +import Test.Samples.Proto.CompilerInput ( + compilerInput'incoherent, + compilerInput'maybe, + ) import Test.Tasty (TestTree, testGroup) import Test.Tasty.HUnit (assertBool, testCase, (@?=)) +import Test.Tasty.QuickCheck (testProperty) + +-------------------------------------------------------------------------------- +-- Top Level tests test :: TestTree -test = testGroup "Compiler tests" [testCheck, testFolds] +test = testGroup "Compiler tests" [testCheck, testFolds, testRefl] -------------------------------------------------------------------------------- -- Module tests testCheck :: TestTree -testCheck = testGroup "KindChecker Tests" [trivialKCTest, kcTestMaybe, kcTestFailing] +testCheck = testGroup "KindChecker Tests" [trivialKCTest, kcTestMaybe, kcTestFailing, kcTestOrdering] trivialKCTest :: TestTree trivialKCTest = @@ -37,6 +56,20 @@ kcTestFailing = assertBool "Test should have failed." $ check_ compilerInput'incoherent /= Right () +-- | TyDef order does not matter when kind checking +kcTestOrdering :: TestTree +kcTestOrdering = + testProperty "Module order inside the CompilerInput does not matter to the result of the kindchecker." $ + forAllShrink (resize 5 genModuleIn2Layouts) shrink $ + \(l, r) -> eitherFailOrPass (check_ l) == eitherFailOrPass (check_ r) + where + genModuleIn2Layouts = do + mods <- arbitrary + shuffledMods <- shuffle mods + pure (P.CompilerInput mods, P.CompilerInput shuffledMods) + + eitherFailOrPass = bimap (const ()) (const ()) + -------------------------------------------------------------------------------- -- Fold tests @@ -44,7 +77,7 @@ testFolds :: TestTree testFolds = testGroup "Test Folds" - [ testGroup "Test Product Folds." [testFoldProd1, testFoldProd2, testFoldProd3] + [ testGroup "Test Product Folds." [testFoldProd1, testFoldProd2, testFoldProd3, testPProdFoldTotal] , testGroup "Test Sum Folds." [testSumFold1, testSumFold2, testSumFold3] ] @@ -70,6 +103,12 @@ testFoldProd3 = (App (Var "Π") (Var "c")) (App (App (Var "Π") (Var "b")) (Var "a")) +testPProdFoldTotal :: TestTree +testPProdFoldTotal = + testProperty "ProductFold is total." $ + forAll arbitrary $ + \ts -> foldWithProduct ts === foldWithProduct ts + -- | [ a ] -> a testSumFold1 :: TestTree testSumFold1 = @@ -91,3 +130,10 @@ testSumFold3 = @?= App (App (Var "Σ") (Var "c")) (App (App (Var "Σ") (Var "b")) (Var "a")) + +-- Property Tests +testRefl :: TestTree +testRefl = testProperty "Refl" reflTerm + where + reflTerm :: Property + reflTerm = forAllShrink (arbitrary @Int) shrink (\a -> a == a) From a38170a42cacff7f54ca84073d61caf0fb47e7a6 Mon Sep 17 00:00:00 2001 From: "Vlad P. Luchian" Date: Wed, 1 Feb 2023 15:52:26 +0000 Subject: [PATCH 03/11] docs: better explanation of the property --- lambda-buffers-compiler/test/Test/KindCheck.hs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lambda-buffers-compiler/test/Test/KindCheck.hs b/lambda-buffers-compiler/test/Test/KindCheck.hs index f013b401..edc96a78 100644 --- a/lambda-buffers-compiler/test/Test/KindCheck.hs +++ b/lambda-buffers-compiler/test/Test/KindCheck.hs @@ -56,7 +56,13 @@ kcTestFailing = assertBool "Test should have failed." $ check_ compilerInput'incoherent /= Right () --- | TyDef order does not matter when kind checking +{- | TyDef order does not matter when kind checking. + + We're not interested in the failure error as there might be more than two + errors in a module - and it is non-determistic which one is first. But it is + deterministic if the property holds for the whole CompilerInput. Therefore we + only track if given the input - the fails or succeeds. +-} kcTestOrdering :: TestTree kcTestOrdering = testProperty "Module order inside the CompilerInput does not matter to the result of the kindchecker." $ From 061ebf1778f46ffd8a6ba851574129a29fbb6177 Mon Sep 17 00:00:00 2001 From: "Vlad P. Luchian" Date: Wed, 8 Feb 2023 12:31:52 +0000 Subject: [PATCH 04/11] update: clean-up --- .../lambda-buffers-compiler.cabal | 3 +-- .../LambdaBuffers/Compiler/KindCheck/Type.hs | 3 ++- .../Compiler/KindCheck/Variable.hs | 8 ++++++-- .../Compiler/ProtoCompat/Types.hs | 18 +++++++++--------- lambda-buffers-compiler/src/Orphan/Text.hs | 18 ++++++++++++++---- lambda-buffers-compiler/test/Test/KindCheck.hs | 1 + lambda-buffers-compiler/test/Test/Samples.hs | 7 ------- .../test/Test/Samples/Proto/TyDef.hs | 2 +- .../Samples/Proto/{Helpers.hs => Utils.hs} | 2 +- 9 files changed, 35 insertions(+), 27 deletions(-) delete mode 100644 lambda-buffers-compiler/test/Test/Samples.hs rename lambda-buffers-compiler/test/Test/Samples/Proto/{Helpers.hs => Utils.hs} (98%) diff --git a/lambda-buffers-compiler/lambda-buffers-compiler.cabal b/lambda-buffers-compiler/lambda-buffers-compiler.cabal index 97842f1a..4f55b5a7 100644 --- a/lambda-buffers-compiler/lambda-buffers-compiler.cabal +++ b/lambda-buffers-compiler/lambda-buffers-compiler.cabal @@ -156,10 +156,9 @@ test-suite tests other-modules: Test.KindCheck - Test.Samples Test.Samples.Proto.CompilerInput - Test.Samples.Proto.Helpers Test.Samples.Proto.Module Test.Samples.Proto.SourceInfo Test.Samples.Proto.TyDef + Test.Samples.Proto.Utils Test.TypeClassCheck diff --git a/lambda-buffers-compiler/src/LambdaBuffers/Compiler/KindCheck/Type.hs b/lambda-buffers-compiler/src/LambdaBuffers/Compiler/KindCheck/Type.hs index 47f54730..201f855f 100644 --- a/lambda-buffers-compiler/src/LambdaBuffers/Compiler/KindCheck/Type.hs +++ b/lambda-buffers-compiler/src/LambdaBuffers/Compiler/KindCheck/Type.hs @@ -8,7 +8,7 @@ module LambdaBuffers.Compiler.KindCheck.Type ( import LambdaBuffers.Compiler.KindCheck.Variable (Variable (LocalRef)) import Prettyprinter (Doc, Pretty (pretty), parens, (<+>)) -import Test.QuickCheck (Arbitrary, arbitrary, oneof, sized) +import Test.QuickCheck (Arbitrary, Gen, arbitrary, oneof, sized) data Type = Var Variable @@ -37,6 +37,7 @@ instance Pretty Type where instance Arbitrary Type where arbitrary = sized f where + f :: Integral a => a -> Gen Type f n | n <= 0 = Var <$> arbitrary | otherwise = diff --git a/lambda-buffers-compiler/src/LambdaBuffers/Compiler/KindCheck/Variable.hs b/lambda-buffers-compiler/src/LambdaBuffers/Compiler/KindCheck/Variable.hs index f7318372..692a5825 100644 --- a/lambda-buffers-compiler/src/LambdaBuffers/Compiler/KindCheck/Variable.hs +++ b/lambda-buffers-compiler/src/LambdaBuffers/Compiler/KindCheck/Variable.hs @@ -1,15 +1,19 @@ module LambdaBuffers.Compiler.KindCheck.Variable (Variable (LocalRef, ForeignRef), Atom) where import Data.Text (Text) -import Orphan.Text +import GHC.Generics (Generic) +import Orphan.Text () import Prettyprinter (Pretty (pretty), concatWith) +import Test.QuickCheck (Arbitrary) +import Test.QuickCheck.Arbitrary.Generic (GenericArbitrary (GenericArbitrary)) type Atom = Text data Variable = LocalRef Text | ForeignRef [Text] Text - deriving stock (Eq, Ord, Show) + deriving stock (Eq, Ord, Show, Generic) + deriving (Arbitrary) via GenericArbitrary Variable instance Pretty Variable where pretty = \case diff --git a/lambda-buffers-compiler/src/LambdaBuffers/Compiler/ProtoCompat/Types.hs b/lambda-buffers-compiler/src/LambdaBuffers/Compiler/ProtoCompat/Types.hs index d8d51543..508d616e 100644 --- a/lambda-buffers-compiler/src/LambdaBuffers/Compiler/ProtoCompat/Types.hs +++ b/lambda-buffers-compiler/src/LambdaBuffers/Compiler/ProtoCompat/Types.hs @@ -46,12 +46,11 @@ module LambdaBuffers.Compiler.ProtoCompat.Types ( import Control.Exception (Exception) import Data.List.NonEmpty (NonEmpty ((:|)), (<|)) -import Data.Map qualified as M import Data.Text (Text) import GHC.Generics (Generic) -import LambdaBuffers.Compiler.KindCheck.Variable as VARS (Atom, Var, Variable) -import Test.QuickCheck (Arbitrary (arbitrary), Gen, NonEmptyList (getNonEmpty), oneof, resize, sized) -import Test.QuickCheck.Arbitrary.Generic +import LambdaBuffers.Compiler.KindCheck.Variable as VARS (Atom, Variable) +import Test.QuickCheck (Gen, oneof, resize, sized) +import Test.QuickCheck.Arbitrary.Generic (Arbitrary (arbitrary), GenericArbitrary (GenericArbitrary)) data SourceInfo = SourceInfo {file :: Text, posFrom :: SourcePosition, posTo :: SourcePosition} deriving stock (Show, Eq, Ord, Generic) @@ -128,6 +127,7 @@ data Ty = TyVarI TyVar | TyAppI TyApp | TyRefI TyRef instance Arbitrary Ty where arbitrary = sized fn where + fn :: (Num a, Ord a) => a -> Gen Ty fn n | n <= 0 = TyRefI <$> arbitrary | otherwise = @@ -276,7 +276,6 @@ instance Arbitrary CompilerInput where where fn n = CompilerInput <$> resize n arbitrary -newtype CompilerOutput = CompilerOutput {typeDefs :: M.Map Var Kind} data KindCheckError = -- | The following term is unbound in the following type definition. UnboundTermError TyName VarName @@ -287,22 +286,23 @@ data KindCheckError | -- | The following type has the wrong. InconsistentTypeError TyName Kind Kind deriving stock (Show, Eq, Ord, Generic) + deriving (Arbitrary) via GenericArbitrary KindCheckError instance Exception KindCheckError data CompilerError = CompKindCheckError KindCheckError | InternalError Text deriving stock (Show, Eq, Ord, Generic) - deriving (Arbitrary) via GenericArbitrary CompilerOutput + deriving (Arbitrary) via GenericArbitrary CompilerError data CompilerResult = CompilerResult deriving stock (Show, Eq, Ord, Generic) - deriving (Arbitrary) via GenericArbitrary CompilerFailure + deriving (Arbitrary) via GenericArbitrary CompilerResult type CompilerOutput = Either CompilerError CompilerResult -nonEmptyArbList :: forall a. Arbitrary a => Gen [a] -nonEmptyArbList = getNonEmpty <$> arbitrary @(NonEmptyList a) +-- nonEmptyArbList :: forall a. Arbitrary a => Gen [a] +-- nonEmptyArbList = getNonEmpty <$> arbitrary @(NonEmptyList a) -- Orphan Instances instance Arbitrary a => Arbitrary (NonEmpty a) where diff --git a/lambda-buffers-compiler/src/Orphan/Text.hs b/lambda-buffers-compiler/src/Orphan/Text.hs index d6702027..a0cd3472 100644 --- a/lambda-buffers-compiler/src/Orphan/Text.hs +++ b/lambda-buffers-compiler/src/Orphan/Text.hs @@ -1,7 +1,17 @@ -module Orphan.Text where +{-# OPTIONS_GHC -Wno-orphans #-} -import Data.Text -import Test.QuickCheck (Arbitrary (arbitrary), Gen, oneof, sized) +module Orphan.Text () where + +import Data.Text (Text, pack) +import Test.QuickCheck (Arbitrary (arbitrary), Gen, sized) instance Arbitrary Text where - arbitrary = pack <$> arbitrary + arbitrary = sized f + where + f :: (Ord a, Num a) => a -> Gen Text + f n + | n <= 0 = pure $ pack [] + | otherwise = do + c <- arbitrary + cs <- f (n - 1) + pure $ pack [c] <> cs diff --git a/lambda-buffers-compiler/test/Test/KindCheck.hs b/lambda-buffers-compiler/test/Test/KindCheck.hs index 0e72a5a6..867c2262 100644 --- a/lambda-buffers-compiler/test/Test/KindCheck.hs +++ b/lambda-buffers-compiler/test/Test/KindCheck.hs @@ -78,6 +78,7 @@ kcTestOrdering = shuffledMods <- shuffle mods pure (P.CompilerInput mods, P.CompilerInput shuffledMods) + eitherFailOrPass :: forall {a} {c}. Either a c -> Either () () eitherFailOrPass = bimap (const ()) (const ()) -------------------------------------------------------------------------------- diff --git a/lambda-buffers-compiler/test/Test/Samples.hs b/lambda-buffers-compiler/test/Test/Samples.hs deleted file mode 100644 index e0660f66..00000000 --- a/lambda-buffers-compiler/test/Test/Samples.hs +++ /dev/null @@ -1,7 +0,0 @@ -{-# OPTIONS_GHC -Wno-missing-import-lists #-} - -module Test.Samples (module M) where - -import Test.Samples.Proto.CompilerInput as M -import Test.Samples.Proto.Module as M -import Test.Samples.Proto.SourceInfo as M diff --git a/lambda-buffers-compiler/test/Test/Samples/Proto/TyDef.hs b/lambda-buffers-compiler/test/Test/Samples/Proto/TyDef.hs index 9866f758..0bdc5ea8 100644 --- a/lambda-buffers-compiler/test/Test/Samples/Proto/TyDef.hs +++ b/lambda-buffers-compiler/test/Test/Samples/Proto/TyDef.hs @@ -1,7 +1,7 @@ module Test.Samples.Proto.TyDef (tyDef'maybe, tyDef'incoherent) where import LambdaBuffers.Compiler.ProtoCompat qualified as P -import Test.Samples.Proto.Helpers ( +import Test.Samples.Proto.Utils ( _TupleI, _TyAbs, _TyDef, diff --git a/lambda-buffers-compiler/test/Test/Samples/Proto/Helpers.hs b/lambda-buffers-compiler/test/Test/Samples/Proto/Utils.hs similarity index 98% rename from lambda-buffers-compiler/test/Test/Samples/Proto/Helpers.hs rename to lambda-buffers-compiler/test/Test/Samples/Proto/Utils.hs index 50c74693..19380205 100644 --- a/lambda-buffers-compiler/test/Test/Samples/Proto/Helpers.hs +++ b/lambda-buffers-compiler/test/Test/Samples/Proto/Utils.hs @@ -1,4 +1,4 @@ -module Test.Samples.Proto.Helpers ( +module Test.Samples.Proto.Utils ( _tyName, _varName, _tyVar, From 7bff35e69b126006796ceda96000c4d8afc1c5f7 Mon Sep 17 00:00:00 2001 From: Vlad Date: Thu, 9 Feb 2023 14:48:16 +0000 Subject: [PATCH 05/11] Update lambda-buffers-compiler/test/Test/KindCheck.hs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Dražen Popović --- lambda-buffers-compiler/test/Test/KindCheck.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lambda-buffers-compiler/test/Test/KindCheck.hs b/lambda-buffers-compiler/test/Test/KindCheck.hs index 867c2262..0aedc99a 100644 --- a/lambda-buffers-compiler/test/Test/KindCheck.hs +++ b/lambda-buffers-compiler/test/Test/KindCheck.hs @@ -69,7 +69,7 @@ kcTestFailing = -} kcTestOrdering :: TestTree kcTestOrdering = - testProperty "Module order inside the CompilerInput does not matter to the result of the kindchecker." $ + testProperty "Module order inside the CompilerInput does not matter." $ forAllShrink (resize 5 genModuleIn2Layouts) shrink $ \(l, r) -> eitherFailOrPass (check_ l) == eitherFailOrPass (check_ r) where From 8b9c79241c74d2297489e37dba4c3f9066dc6ab0 Mon Sep 17 00:00:00 2001 From: Vlad Date: Thu, 9 Feb 2023 14:58:41 +0000 Subject: [PATCH 06/11] Update lambda-buffers-compiler/src/LambdaBuffers/Compiler/ProtoCompat/Types.hs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Dražen Popović --- .../src/LambdaBuffers/Compiler/ProtoCompat/Types.hs | 3 --- 1 file changed, 3 deletions(-) diff --git a/lambda-buffers-compiler/src/LambdaBuffers/Compiler/ProtoCompat/Types.hs b/lambda-buffers-compiler/src/LambdaBuffers/Compiler/ProtoCompat/Types.hs index 508d616e..d3da5b40 100644 --- a/lambda-buffers-compiler/src/LambdaBuffers/Compiler/ProtoCompat/Types.hs +++ b/lambda-buffers-compiler/src/LambdaBuffers/Compiler/ProtoCompat/Types.hs @@ -301,9 +301,6 @@ data CompilerResult = CompilerResult type CompilerOutput = Either CompilerError CompilerResult --- nonEmptyArbList :: forall a. Arbitrary a => Gen [a] --- nonEmptyArbList = getNonEmpty <$> arbitrary @(NonEmptyList a) - -- Orphan Instances instance Arbitrary a => Arbitrary (NonEmpty a) where arbitrary = sized f From 4e43f6d774e98995eb797000f5f7d95e637a3ce9 Mon Sep 17 00:00:00 2001 From: "Vlad P. Luchian" Date: Thu, 9 Feb 2023 15:43:59 +0000 Subject: [PATCH 07/11] nit --- .../lambda-buffers-compiler.cabal | 2 +- .../Compiler/KindCheck/Variable.hs | 2 +- lambda-buffers-compiler/src/Orphan/Text.hs | 17 ----------------- 3 files changed, 2 insertions(+), 19 deletions(-) delete mode 100644 lambda-buffers-compiler/src/Orphan/Text.hs diff --git a/lambda-buffers-compiler/lambda-buffers-compiler.cabal b/lambda-buffers-compiler/lambda-buffers-compiler.cabal index 4f55b5a7..d674e6fc 100644 --- a/lambda-buffers-compiler/lambda-buffers-compiler.cabal +++ b/lambda-buffers-compiler/lambda-buffers-compiler.cabal @@ -103,6 +103,7 @@ library , prettyprinter >=1.7 , proto-lens >=0.7 , QuickCheck >=2.14 + , quickcheck-instances >=0.3 , text >=1.2 exposed-modules: @@ -118,7 +119,6 @@ library LambdaBuffers.Compiler.ProtoCompat LambdaBuffers.Compiler.ProtoCompat.Types LambdaBuffers.Compiler.TypeClassCheck - Orphan.Text hs-source-dirs: src diff --git a/lambda-buffers-compiler/src/LambdaBuffers/Compiler/KindCheck/Variable.hs b/lambda-buffers-compiler/src/LambdaBuffers/Compiler/KindCheck/Variable.hs index 692a5825..45ad5f46 100644 --- a/lambda-buffers-compiler/src/LambdaBuffers/Compiler/KindCheck/Variable.hs +++ b/lambda-buffers-compiler/src/LambdaBuffers/Compiler/KindCheck/Variable.hs @@ -2,10 +2,10 @@ module LambdaBuffers.Compiler.KindCheck.Variable (Variable (LocalRef, ForeignRef import Data.Text (Text) import GHC.Generics (Generic) -import Orphan.Text () import Prettyprinter (Pretty (pretty), concatWith) import Test.QuickCheck (Arbitrary) import Test.QuickCheck.Arbitrary.Generic (GenericArbitrary (GenericArbitrary)) +import Test.QuickCheck.Instances.Text () type Atom = Text diff --git a/lambda-buffers-compiler/src/Orphan/Text.hs b/lambda-buffers-compiler/src/Orphan/Text.hs deleted file mode 100644 index a0cd3472..00000000 --- a/lambda-buffers-compiler/src/Orphan/Text.hs +++ /dev/null @@ -1,17 +0,0 @@ -{-# OPTIONS_GHC -Wno-orphans #-} - -module Orphan.Text () where - -import Data.Text (Text, pack) -import Test.QuickCheck (Arbitrary (arbitrary), Gen, sized) - -instance Arbitrary Text where - arbitrary = sized f - where - f :: (Ord a, Num a) => a -> Gen Text - f n - | n <= 0 = pure $ pack [] - | otherwise = do - c <- arbitrary - cs <- f (n - 1) - pure $ pack [c] <> cs From 7876b0e69bedcd5c9d863c03768c29e2f86cc63d Mon Sep 17 00:00:00 2001 From: "Vlad P. Luchian" Date: Thu, 9 Feb 2023 17:40:30 +0000 Subject: [PATCH 08/11] update: remove Samples folder --- lambda-buffers-compiler/lambda-buffers-compiler.cabal | 10 +++++----- lambda-buffers-compiler/test/Test/KindCheck.hs | 8 ++++---- .../test/Test/{Samples => }/Proto/CompilerInput.hs | 4 ++-- .../test/Test/{Samples => }/Proto/Module.hs | 6 +++--- .../test/Test/{Samples => }/Proto/SourceInfo.hs | 2 +- .../test/Test/{Samples => }/Proto/TyDef.hs | 4 ++-- .../test/Test/{Samples => }/Proto/Utils.hs | 4 ++-- 7 files changed, 19 insertions(+), 19 deletions(-) rename lambda-buffers-compiler/test/Test/{Samples => }/Proto/CompilerInput.hs (72%) rename lambda-buffers-compiler/test/Test/{Samples => }/Proto/Module.hs (79%) rename lambda-buffers-compiler/test/Test/{Samples => }/Proto/SourceInfo.hs (76%) rename lambda-buffers-compiler/test/Test/{Samples => }/Proto/TyDef.hs (84%) rename lambda-buffers-compiler/test/Test/{Samples => }/Proto/Utils.hs (95%) diff --git a/lambda-buffers-compiler/lambda-buffers-compiler.cabal b/lambda-buffers-compiler/lambda-buffers-compiler.cabal index d674e6fc..c57aa41a 100644 --- a/lambda-buffers-compiler/lambda-buffers-compiler.cabal +++ b/lambda-buffers-compiler/lambda-buffers-compiler.cabal @@ -156,9 +156,9 @@ test-suite tests other-modules: Test.KindCheck - Test.Samples.Proto.CompilerInput - Test.Samples.Proto.Module - Test.Samples.Proto.SourceInfo - Test.Samples.Proto.TyDef - Test.Samples.Proto.Utils + Test.Proto.CompilerInput + Test.Proto.Module + Test.Proto.SourceInfo + Test.Proto.TyDef + Test.Proto.Utils Test.TypeClassCheck diff --git a/lambda-buffers-compiler/test/Test/KindCheck.hs b/lambda-buffers-compiler/test/Test/KindCheck.hs index 0aedc99a..365699ef 100644 --- a/lambda-buffers-compiler/test/Test/KindCheck.hs +++ b/lambda-buffers-compiler/test/Test/KindCheck.hs @@ -15,6 +15,10 @@ import LambdaBuffers.Compiler.KindCheck.Variable ( import LambdaBuffers.Compiler.ProtoCompat.Types qualified as P ( CompilerInput (CompilerInput), ) +import Test.Proto.CompilerInput ( + compilerInput'incoherent, + compilerInput'maybe, + ) import Test.QuickCheck ( Arbitrary (arbitrary, shrink), Property, @@ -24,10 +28,6 @@ import Test.QuickCheck ( shuffle, (===), ) -import Test.Samples.Proto.CompilerInput ( - compilerInput'incoherent, - compilerInput'maybe, - ) import Test.Tasty (TestTree, testGroup) import Test.Tasty.HUnit (assertBool, testCase, (@?=)) import Test.Tasty.QuickCheck (testProperty) diff --git a/lambda-buffers-compiler/test/Test/Samples/Proto/CompilerInput.hs b/lambda-buffers-compiler/test/Test/Proto/CompilerInput.hs similarity index 72% rename from lambda-buffers-compiler/test/Test/Samples/Proto/CompilerInput.hs rename to lambda-buffers-compiler/test/Test/Proto/CompilerInput.hs index d65d829e..d9ca964a 100644 --- a/lambda-buffers-compiler/test/Test/Samples/Proto/CompilerInput.hs +++ b/lambda-buffers-compiler/test/Test/Proto/CompilerInput.hs @@ -1,8 +1,8 @@ -module Test.Samples.Proto.CompilerInput (compilerInput'incoherent, compilerInput'maybe) where +module Test.Proto.CompilerInput (compilerInput'incoherent, compilerInput'maybe) where import Control.Lens ((&), (.~)) import LambdaBuffers.Compiler.ProtoCompat qualified as P -import Test.Samples.Proto.Module (module'incoherent, module'maybe) +import Test.Proto.Module (module'incoherent, module'maybe) -- | Compiler Input containing 1 module with 1 definition - Maybe. compilerInput'maybe :: P.CompilerInput diff --git a/lambda-buffers-compiler/test/Test/Samples/Proto/Module.hs b/lambda-buffers-compiler/test/Test/Proto/Module.hs similarity index 79% rename from lambda-buffers-compiler/test/Test/Samples/Proto/Module.hs rename to lambda-buffers-compiler/test/Test/Proto/Module.hs index dfec8562..db66fee2 100644 --- a/lambda-buffers-compiler/test/Test/Samples/Proto/Module.hs +++ b/lambda-buffers-compiler/test/Test/Proto/Module.hs @@ -1,9 +1,9 @@ -module Test.Samples.Proto.Module (module'maybe, module'incoherent) where +module Test.Proto.Module (module'maybe, module'incoherent) where import Control.Lens ((%~), (&)) import LambdaBuffers.Compiler.ProtoCompat qualified as P -import Test.Samples.Proto.SourceInfo (sourceInfo'empty) -import Test.Samples.Proto.TyDef (tyDef'incoherent, tyDef'maybe) +import Test.Proto.SourceInfo (sourceInfo'empty) +import Test.Proto.TyDef (tyDef'incoherent, tyDef'maybe) module'maybe :: P.Module module'maybe = diff --git a/lambda-buffers-compiler/test/Test/Samples/Proto/SourceInfo.hs b/lambda-buffers-compiler/test/Test/Proto/SourceInfo.hs similarity index 76% rename from lambda-buffers-compiler/test/Test/Samples/Proto/SourceInfo.hs rename to lambda-buffers-compiler/test/Test/Proto/SourceInfo.hs index 03fe0da9..620073b9 100644 --- a/lambda-buffers-compiler/test/Test/Samples/Proto/SourceInfo.hs +++ b/lambda-buffers-compiler/test/Test/Proto/SourceInfo.hs @@ -1,4 +1,4 @@ -module Test.Samples.Proto.SourceInfo (sourceInfo'empty) where +module Test.Proto.SourceInfo (sourceInfo'empty) where import LambdaBuffers.Compiler.ProtoCompat qualified as P diff --git a/lambda-buffers-compiler/test/Test/Samples/Proto/TyDef.hs b/lambda-buffers-compiler/test/Test/Proto/TyDef.hs similarity index 84% rename from lambda-buffers-compiler/test/Test/Samples/Proto/TyDef.hs rename to lambda-buffers-compiler/test/Test/Proto/TyDef.hs index 0bdc5ea8..f0da5369 100644 --- a/lambda-buffers-compiler/test/Test/Samples/Proto/TyDef.hs +++ b/lambda-buffers-compiler/test/Test/Proto/TyDef.hs @@ -1,7 +1,7 @@ -module Test.Samples.Proto.TyDef (tyDef'maybe, tyDef'incoherent) where +module Test.Proto.TyDef (tyDef'maybe, tyDef'incoherent) where import LambdaBuffers.Compiler.ProtoCompat qualified as P -import Test.Samples.Proto.Utils ( +import Test.Proto.Utils ( _TupleI, _TyAbs, _TyDef, diff --git a/lambda-buffers-compiler/test/Test/Samples/Proto/Utils.hs b/lambda-buffers-compiler/test/Test/Proto/Utils.hs similarity index 95% rename from lambda-buffers-compiler/test/Test/Samples/Proto/Utils.hs rename to lambda-buffers-compiler/test/Test/Proto/Utils.hs index 19380205..e3d0804f 100644 --- a/lambda-buffers-compiler/test/Test/Samples/Proto/Utils.hs +++ b/lambda-buffers-compiler/test/Test/Proto/Utils.hs @@ -1,4 +1,4 @@ -module Test.Samples.Proto.Utils ( +module Test.Proto.Utils ( _tyName, _varName, _tyVar, @@ -17,7 +17,7 @@ module Test.Samples.Proto.Utils ( import Data.List.NonEmpty (fromList) import Data.Text (Text) import LambdaBuffers.Compiler.ProtoCompat qualified as P -import Test.Samples.Proto.SourceInfo (sourceInfo'empty) +import Test.Proto.SourceInfo (sourceInfo'empty) _tyName :: Text -> P.TyName _tyName x = P.TyName x sourceInfo'empty From a448d57661310896887a6eeeafe2504a70fbd115 Mon Sep 17 00:00:00 2001 From: "Vlad P. Luchian" Date: Thu, 9 Feb 2023 17:46:14 +0000 Subject: [PATCH 09/11] update: move into Utils --- lambda-buffers-compiler/lambda-buffers-compiler.cabal | 10 +++++----- lambda-buffers-compiler/test/Test/KindCheck.hs | 8 ++++---- .../test/Test/{Proto => Utils}/CompilerInput.hs | 4 ++-- .../Test/{Proto/Utils.hs => Utils/Constructors.hs} | 4 ++-- .../test/Test/{Proto => Utils}/Module.hs | 6 +++--- .../test/Test/{Proto => Utils}/SourceInfo.hs | 2 +- .../test/Test/{Proto => Utils}/TyDef.hs | 4 ++-- 7 files changed, 19 insertions(+), 19 deletions(-) rename lambda-buffers-compiler/test/Test/{Proto => Utils}/CompilerInput.hs (78%) rename lambda-buffers-compiler/test/Test/{Proto/Utils.hs => Utils/Constructors.hs} (96%) rename lambda-buffers-compiler/test/Test/{Proto => Utils}/Module.hs (81%) rename lambda-buffers-compiler/test/Test/{Proto => Utils}/SourceInfo.hs (79%) rename lambda-buffers-compiler/test/Test/{Proto => Utils}/TyDef.hs (85%) diff --git a/lambda-buffers-compiler/lambda-buffers-compiler.cabal b/lambda-buffers-compiler/lambda-buffers-compiler.cabal index c57aa41a..96e2a41d 100644 --- a/lambda-buffers-compiler/lambda-buffers-compiler.cabal +++ b/lambda-buffers-compiler/lambda-buffers-compiler.cabal @@ -156,9 +156,9 @@ test-suite tests other-modules: Test.KindCheck - Test.Proto.CompilerInput - Test.Proto.Module - Test.Proto.SourceInfo - Test.Proto.TyDef - Test.Proto.Utils Test.TypeClassCheck + Test.Utils.CompilerInput + Test.Utils.Constructors + Test.Utils.Module + Test.Utils.SourceInfo + Test.Utils.TyDef diff --git a/lambda-buffers-compiler/test/Test/KindCheck.hs b/lambda-buffers-compiler/test/Test/KindCheck.hs index 365699ef..5708491a 100644 --- a/lambda-buffers-compiler/test/Test/KindCheck.hs +++ b/lambda-buffers-compiler/test/Test/KindCheck.hs @@ -15,10 +15,6 @@ import LambdaBuffers.Compiler.KindCheck.Variable ( import LambdaBuffers.Compiler.ProtoCompat.Types qualified as P ( CompilerInput (CompilerInput), ) -import Test.Proto.CompilerInput ( - compilerInput'incoherent, - compilerInput'maybe, - ) import Test.QuickCheck ( Arbitrary (arbitrary, shrink), Property, @@ -31,6 +27,10 @@ import Test.QuickCheck ( import Test.Tasty (TestTree, testGroup) import Test.Tasty.HUnit (assertBool, testCase, (@?=)) import Test.Tasty.QuickCheck (testProperty) +import Test.Utils.CompilerInput ( + compilerInput'incoherent, + compilerInput'maybe, + ) -------------------------------------------------------------------------------- -- Top Level tests diff --git a/lambda-buffers-compiler/test/Test/Proto/CompilerInput.hs b/lambda-buffers-compiler/test/Test/Utils/CompilerInput.hs similarity index 78% rename from lambda-buffers-compiler/test/Test/Proto/CompilerInput.hs rename to lambda-buffers-compiler/test/Test/Utils/CompilerInput.hs index d9ca964a..eba09124 100644 --- a/lambda-buffers-compiler/test/Test/Proto/CompilerInput.hs +++ b/lambda-buffers-compiler/test/Test/Utils/CompilerInput.hs @@ -1,8 +1,8 @@ -module Test.Proto.CompilerInput (compilerInput'incoherent, compilerInput'maybe) where +module Test.Utils.CompilerInput (compilerInput'incoherent, compilerInput'maybe) where import Control.Lens ((&), (.~)) import LambdaBuffers.Compiler.ProtoCompat qualified as P -import Test.Proto.Module (module'incoherent, module'maybe) +import Test.Utils.Module (module'incoherent, module'maybe) -- | Compiler Input containing 1 module with 1 definition - Maybe. compilerInput'maybe :: P.CompilerInput diff --git a/lambda-buffers-compiler/test/Test/Proto/Utils.hs b/lambda-buffers-compiler/test/Test/Utils/Constructors.hs similarity index 96% rename from lambda-buffers-compiler/test/Test/Proto/Utils.hs rename to lambda-buffers-compiler/test/Test/Utils/Constructors.hs index e3d0804f..936481b4 100644 --- a/lambda-buffers-compiler/test/Test/Proto/Utils.hs +++ b/lambda-buffers-compiler/test/Test/Utils/Constructors.hs @@ -1,4 +1,4 @@ -module Test.Proto.Utils ( +module Test.Utils.Constructors ( _tyName, _varName, _tyVar, @@ -17,7 +17,7 @@ module Test.Proto.Utils ( import Data.List.NonEmpty (fromList) import Data.Text (Text) import LambdaBuffers.Compiler.ProtoCompat qualified as P -import Test.Proto.SourceInfo (sourceInfo'empty) +import Test.Utils.SourceInfo (sourceInfo'empty) _tyName :: Text -> P.TyName _tyName x = P.TyName x sourceInfo'empty diff --git a/lambda-buffers-compiler/test/Test/Proto/Module.hs b/lambda-buffers-compiler/test/Test/Utils/Module.hs similarity index 81% rename from lambda-buffers-compiler/test/Test/Proto/Module.hs rename to lambda-buffers-compiler/test/Test/Utils/Module.hs index db66fee2..ac455647 100644 --- a/lambda-buffers-compiler/test/Test/Proto/Module.hs +++ b/lambda-buffers-compiler/test/Test/Utils/Module.hs @@ -1,9 +1,9 @@ -module Test.Proto.Module (module'maybe, module'incoherent) where +module Test.Utils.Module (module'maybe, module'incoherent) where import Control.Lens ((%~), (&)) import LambdaBuffers.Compiler.ProtoCompat qualified as P -import Test.Proto.SourceInfo (sourceInfo'empty) -import Test.Proto.TyDef (tyDef'incoherent, tyDef'maybe) +import Test.Utils.SourceInfo (sourceInfo'empty) +import Test.Utils.TyDef (tyDef'incoherent, tyDef'maybe) module'maybe :: P.Module module'maybe = diff --git a/lambda-buffers-compiler/test/Test/Proto/SourceInfo.hs b/lambda-buffers-compiler/test/Test/Utils/SourceInfo.hs similarity index 79% rename from lambda-buffers-compiler/test/Test/Proto/SourceInfo.hs rename to lambda-buffers-compiler/test/Test/Utils/SourceInfo.hs index 620073b9..cb04608b 100644 --- a/lambda-buffers-compiler/test/Test/Proto/SourceInfo.hs +++ b/lambda-buffers-compiler/test/Test/Utils/SourceInfo.hs @@ -1,4 +1,4 @@ -module Test.Proto.SourceInfo (sourceInfo'empty) where +module Test.Utils.SourceInfo (sourceInfo'empty) where import LambdaBuffers.Compiler.ProtoCompat qualified as P diff --git a/lambda-buffers-compiler/test/Test/Proto/TyDef.hs b/lambda-buffers-compiler/test/Test/Utils/TyDef.hs similarity index 85% rename from lambda-buffers-compiler/test/Test/Proto/TyDef.hs rename to lambda-buffers-compiler/test/Test/Utils/TyDef.hs index f0da5369..e6603f38 100644 --- a/lambda-buffers-compiler/test/Test/Proto/TyDef.hs +++ b/lambda-buffers-compiler/test/Test/Utils/TyDef.hs @@ -1,7 +1,7 @@ -module Test.Proto.TyDef (tyDef'maybe, tyDef'incoherent) where +module Test.Utils.TyDef (tyDef'maybe, tyDef'incoherent) where import LambdaBuffers.Compiler.ProtoCompat qualified as P -import Test.Proto.Utils ( +import Test.Utils.Constructors ( _TupleI, _TyAbs, _TyDef, From b4b29dc5d4bd91a0a5e253b73968c4153eec02e5 Mon Sep 17 00:00:00 2001 From: "Vlad P. Luchian" Date: Thu, 9 Feb 2023 17:57:50 +0000 Subject: [PATCH 10/11] update: replace NonEmpty orphan wit library instance --- .../Compiler/ProtoCompat/Types.hs | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/lambda-buffers-compiler/src/LambdaBuffers/Compiler/ProtoCompat/Types.hs b/lambda-buffers-compiler/src/LambdaBuffers/Compiler/ProtoCompat/Types.hs index d3da5b40..79c44565 100644 --- a/lambda-buffers-compiler/src/LambdaBuffers/Compiler/ProtoCompat/Types.hs +++ b/lambda-buffers-compiler/src/LambdaBuffers/Compiler/ProtoCompat/Types.hs @@ -1,6 +1,7 @@ {-# LANGUAGE DuplicateRecordFields #-} {-# OPTIONS_GHC -Wno-orphans #-} {-# OPTIONS_GHC -Wno-redundant-constraints #-} +{-# OPTIONS_GHC -Wno-unused-imports #-} module LambdaBuffers.Compiler.ProtoCompat.Types ( ClassDef (..), @@ -44,13 +45,15 @@ module LambdaBuffers.Compiler.ProtoCompat.Types ( module VARS, ) where +-- for NonEmpty import Control.Exception (Exception) -import Data.List.NonEmpty (NonEmpty ((:|)), (<|)) +import Data.List.NonEmpty (NonEmpty ((:|))) import Data.Text (Text) import GHC.Generics (Generic) import LambdaBuffers.Compiler.KindCheck.Variable as VARS (Atom, Variable) import Test.QuickCheck (Gen, oneof, resize, sized) import Test.QuickCheck.Arbitrary.Generic (Arbitrary (arbitrary), GenericArbitrary (GenericArbitrary)) +import Test.QuickCheck.Instances.Semigroup () data SourceInfo = SourceInfo {file :: Text, posFrom :: SourcePosition, posTo :: SourcePosition} deriving stock (Show, Eq, Ord, Generic) @@ -300,17 +303,3 @@ data CompilerResult = CompilerResult deriving (Arbitrary) via GenericArbitrary CompilerResult type CompilerOutput = Either CompilerError CompilerResult - --- Orphan Instances -instance Arbitrary a => Arbitrary (NonEmpty a) where - arbitrary = sized f - where - f :: (Num t, Ord t) => t -> Gen (NonEmpty a) - f n - | n <= 0 = do - x <- arbitrary @a - pure $ x :| [] - | otherwise = do - x <- arbitrary - xs <- f (n - 1) - pure $ x <| xs From 391f2c56f71eef8682cb2ed19e179821720817da Mon Sep 17 00:00:00 2001 From: "Vlad P. Luchian" Date: Thu, 9 Feb 2023 18:00:59 +0000 Subject: [PATCH 11/11] update: merge with new main --- .../src/LambdaBuffers/Compiler/ProtoCompat/Types.hs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lambda-buffers-compiler/src/LambdaBuffers/Compiler/ProtoCompat/Types.hs b/lambda-buffers-compiler/src/LambdaBuffers/Compiler/ProtoCompat/Types.hs index b2b43aa6..2373e696 100644 --- a/lambda-buffers-compiler/src/LambdaBuffers/Compiler/ProtoCompat/Types.hs +++ b/lambda-buffers-compiler/src/LambdaBuffers/Compiler/ProtoCompat/Types.hs @@ -205,14 +205,17 @@ data ForeignClassRef = ForeignClassRef , sourceInfo :: SourceInfo } deriving stock (Show, Eq, Ord, Generic) + deriving (Arbitrary) via GenericArbitrary ForeignClassRef data LocalClassRef = LocalClassRef {className :: ClassName, sourceInfo :: SourceInfo} deriving stock (Show, Eq, Ord, Generic) + deriving (Arbitrary) via GenericArbitrary LocalClassRef data TyClassRef = LocalCI LocalClassRef | ForeignCI ForeignClassRef deriving stock (Show, Eq, Ord, Generic) + deriving (Arbitrary) via GenericArbitrary TyClassRef data ClassDef = ClassDef { className :: ClassName @@ -270,6 +273,7 @@ instance Arbitrary Module where <*> resize n arbitrary <*> resize n arbitrary <*> resize n arbitrary + <*> resize n arbitrary data InferenceErr = UnboundTermErr Text