2022-09-23 16:43:18 +03:00
|
|
|
module Typecheck.Positive where
|
2022-04-05 23:02:03 +03:00
|
|
|
|
|
|
|
import Base
|
2023-01-17 11:41:07 +03:00
|
|
|
import Compilation.Positive qualified as Compilation
|
2022-09-23 16:43:18 +03:00
|
|
|
import Typecheck.Negative qualified as N
|
2022-04-05 23:02:03 +03:00
|
|
|
|
|
|
|
data PosTest = PosTest
|
2022-04-08 13:46:37 +03:00
|
|
|
{ _name :: String,
|
2023-01-17 11:41:07 +03:00
|
|
|
_dir :: Path Abs Dir,
|
|
|
|
_file :: Path Abs File
|
2022-04-05 23:02:03 +03:00
|
|
|
}
|
|
|
|
|
2023-11-12 18:23:33 +03:00
|
|
|
makeLenses ''PosTest
|
|
|
|
|
2022-12-20 15:05:40 +03:00
|
|
|
root :: Path Abs Dir
|
|
|
|
root = relToProject $(mkRelDir "tests/positive")
|
2022-04-05 23:02:03 +03:00
|
|
|
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest :: String -> Path Rel Dir -> Path Rel File -> PosTest
|
2023-11-17 18:10:38 +03:00
|
|
|
posTest _name rdir rfile = posTestAbsDir _name (root <//> rdir) rfile
|
|
|
|
|
|
|
|
posTestAbsDir :: String -> Path Abs Dir -> Path Rel File -> PosTest
|
|
|
|
posTestAbsDir _name _dir f =
|
|
|
|
PosTest
|
|
|
|
{ _file = _dir <//> f,
|
|
|
|
_dir,
|
|
|
|
_name
|
|
|
|
}
|
2023-01-17 11:41:07 +03:00
|
|
|
|
2022-04-05 23:02:03 +03:00
|
|
|
testDescr :: PosTest -> TestDescr
|
|
|
|
testDescr PosTest {..} =
|
2023-01-17 11:41:07 +03:00
|
|
|
TestDescr
|
|
|
|
{ _testName = _name,
|
|
|
|
_testRoot = _dir,
|
|
|
|
_testAssertion = Single $ do
|
2023-12-06 20:24:59 +03:00
|
|
|
entryPoint <- testDefaultEntryPointIO _dir _file
|
|
|
|
(void . testRunIO entryPoint) upToInternalTyped
|
2023-01-17 11:41:07 +03:00
|
|
|
}
|
2022-04-05 23:02:03 +03:00
|
|
|
|
2022-12-20 15:05:40 +03:00
|
|
|
rootNegTests :: Path Abs Dir
|
|
|
|
rootNegTests = relToProject $(mkRelDir "tests/negative/")
|
2022-07-23 10:27:12 +03:00
|
|
|
|
2023-11-12 18:23:33 +03:00
|
|
|
-- Testing --no-positivity flag with all related negative tests
|
2022-07-23 10:27:12 +03:00
|
|
|
testNoPositivityFlag :: N.NegTest -> TestDescr
|
|
|
|
testNoPositivityFlag N.NegTest {..} =
|
2023-11-28 20:24:03 +03:00
|
|
|
let tRoot = _dir
|
|
|
|
file' = _file
|
2022-07-23 10:27:12 +03:00
|
|
|
in TestDescr
|
|
|
|
{ _testName = _name,
|
|
|
|
_testRoot = tRoot,
|
|
|
|
_testAssertion = Single $ do
|
2023-04-13 12:27:39 +03:00
|
|
|
entryPoint <-
|
|
|
|
set entryPointNoPositivity True
|
2023-12-06 20:24:59 +03:00
|
|
|
<$> testDefaultEntryPointIO tRoot file'
|
|
|
|
(void . testRunIO entryPoint) upToInternalTyped
|
2022-07-23 10:27:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
negPositivityTests :: [N.NegTest]
|
|
|
|
negPositivityTests = N.negPositivityTests
|
|
|
|
|
2023-05-08 21:13:26 +03:00
|
|
|
testWellDefinedInductiveDefs :: [PosTest]
|
|
|
|
testWellDefinedInductiveDefs =
|
|
|
|
[ posTest
|
|
|
|
"Rose tree definition is well-defined"
|
|
|
|
$(mkRelDir "Internal/Positivity")
|
|
|
|
$(mkRelFile "RoseTree.juvix")
|
|
|
|
]
|
|
|
|
|
2022-07-23 10:27:12 +03:00
|
|
|
testPositivityKeyword :: [PosTest]
|
|
|
|
testPositivityKeyword =
|
2023-01-17 11:41:07 +03:00
|
|
|
[ posTest
|
2022-07-23 10:27:12 +03:00
|
|
|
"Mark T0 data type as strictly positive"
|
2022-12-20 15:05:40 +03:00
|
|
|
$(mkRelDir "Internal/Positivity")
|
|
|
|
$(mkRelFile "E5.juvix")
|
2022-07-23 10:27:12 +03:00
|
|
|
]
|
|
|
|
|
|
|
|
positivityTestGroup :: TestTree
|
|
|
|
positivityTestGroup =
|
|
|
|
testGroup
|
|
|
|
"Positive tests for the positivity condition"
|
|
|
|
[ testGroup
|
|
|
|
"Bypass positivity checking using --non-positivity flag on negative tests"
|
|
|
|
(map (mkTest . testNoPositivityFlag) negPositivityTests),
|
|
|
|
testGroup
|
|
|
|
"Usages of the positive keyword"
|
2023-05-08 21:13:26 +03:00
|
|
|
(map (mkTest . testDescr) testPositivityKeyword),
|
|
|
|
testGroup
|
|
|
|
"Well-defined inductive definitions"
|
|
|
|
(map (mkTest . testDescr) testWellDefinedInductiveDefs)
|
2022-07-23 10:27:12 +03:00
|
|
|
]
|
|
|
|
|
2022-04-05 23:02:03 +03:00
|
|
|
allTests :: TestTree
|
|
|
|
allTests =
|
|
|
|
testGroup
|
2022-07-23 10:27:12 +03:00
|
|
|
"Typecheck positive tests"
|
|
|
|
[ testGroup
|
|
|
|
"General typechecking tests"
|
|
|
|
(map (mkTest . testDescr) tests),
|
|
|
|
positivityTestGroup
|
|
|
|
]
|
2022-04-05 23:02:03 +03:00
|
|
|
|
2023-01-17 11:41:07 +03:00
|
|
|
compilationTest :: Compilation.PosTest -> PosTest
|
|
|
|
compilationTest Compilation.PosTest {..} = PosTest {..}
|
|
|
|
|
2022-04-05 23:02:03 +03:00
|
|
|
tests :: [PosTest]
|
|
|
|
tests =
|
2023-01-17 11:41:07 +03:00
|
|
|
[ posTest
|
2022-04-05 23:02:03 +03:00
|
|
|
"Simple"
|
2022-12-20 15:05:40 +03:00
|
|
|
$(mkRelDir "Internal")
|
|
|
|
$(mkRelFile "Simple.juvix"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2022-04-05 23:02:03 +03:00
|
|
|
"Literal String matches any type"
|
2022-12-20 15:05:40 +03:00
|
|
|
$(mkRelDir "Internal")
|
|
|
|
$(mkRelFile "LiteralString.juvix"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2022-07-04 19:15:35 +03:00
|
|
|
"Box type"
|
2022-12-20 15:05:40 +03:00
|
|
|
$(mkRelDir "Internal")
|
|
|
|
$(mkRelFile "Box.juvix"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2022-04-05 23:02:03 +03:00
|
|
|
"Literal Int matches any type"
|
2022-12-20 15:05:40 +03:00
|
|
|
$(mkRelDir "Internal")
|
|
|
|
$(mkRelFile "LiteralInt.juvix"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2022-04-05 23:02:03 +03:00
|
|
|
"Axiom"
|
2022-12-20 15:05:40 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "Axiom.juvix"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2022-04-05 23:02:03 +03:00
|
|
|
"Inductive"
|
2022-12-20 15:05:40 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "Inductive.juvix"),
|
2023-08-01 15:39:43 +03:00
|
|
|
posTest
|
|
|
|
"ADT"
|
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "Adt.juvix"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2022-04-05 23:02:03 +03:00
|
|
|
"Operators"
|
2022-12-20 15:05:40 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "Operators.juvix"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2022-06-02 14:02:07 +03:00
|
|
|
"Holes in type signature"
|
2022-12-20 15:05:40 +03:00
|
|
|
$(mkRelDir "Internal")
|
|
|
|
$(mkRelFile "HoleInSignature.juvix"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2022-04-22 11:06:34 +03:00
|
|
|
"Polymorphism and higher rank functions"
|
2022-12-20 15:05:40 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "Polymorphism.juvix"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2022-06-01 18:54:53 +03:00
|
|
|
"Polymorphism and higher rank functions with explicit holes"
|
2022-12-20 15:05:40 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "PolymorphismHoles.juvix"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2022-06-13 19:16:32 +03:00
|
|
|
"Implicit arguments"
|
2022-12-20 15:05:40 +03:00
|
|
|
$(mkRelDir "Internal")
|
|
|
|
$(mkRelFile "Implicit.juvix"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2022-07-25 13:30:18 +03:00
|
|
|
"Simple type alias"
|
2022-12-20 15:05:40 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "TypeAlias.juvix"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2022-07-15 19:39:11 +03:00
|
|
|
"Refine hole in type signature"
|
2022-12-20 15:05:40 +03:00
|
|
|
$(mkRelDir "272")
|
|
|
|
$(mkRelFile "M.juvix"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2022-07-15 18:57:04 +03:00
|
|
|
"Pattern match a hole type"
|
2022-12-20 15:05:40 +03:00
|
|
|
$(mkRelDir "265")
|
|
|
|
$(mkRelFile "M.juvix"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2022-08-21 13:16:26 +03:00
|
|
|
"Pattern match type synonym"
|
2022-12-20 15:05:40 +03:00
|
|
|
$(mkRelDir "issue1466")
|
|
|
|
$(mkRelFile "M.juvix"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2022-07-01 17:59:52 +03:00
|
|
|
"Import a builtin multiple times"
|
2022-12-20 15:05:40 +03:00
|
|
|
$(mkRelDir "BuiltinsMultiImport")
|
|
|
|
$(mkRelFile "Input.juvix"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2022-09-23 16:43:18 +03:00
|
|
|
"Basic lambda functions"
|
2022-12-20 15:05:40 +03:00
|
|
|
$(mkRelDir "Internal")
|
|
|
|
$(mkRelFile "Lambda.juvix"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2022-09-26 20:14:17 +03:00
|
|
|
"Simple mutual inference"
|
2022-12-20 15:05:40 +03:00
|
|
|
$(mkRelDir "Internal")
|
|
|
|
$(mkRelFile "Mutual.juvix"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2022-07-03 18:16:46 +03:00
|
|
|
"open import a builtin multiple times"
|
2022-12-20 15:05:40 +03:00
|
|
|
$(mkRelDir "BuiltinsMultiOpenImport")
|
|
|
|
$(mkRelFile "Input.juvix"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2022-10-27 13:17:03 +03:00
|
|
|
"As Patterns"
|
2022-12-20 15:05:40 +03:00
|
|
|
$(mkRelDir "Internal")
|
2023-01-09 20:56:28 +03:00
|
|
|
$(mkRelFile "AsPattern.juvix"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2023-01-09 20:56:28 +03:00
|
|
|
"Issue 1693 (Inference and higher order functions)"
|
|
|
|
$(mkRelDir "issue1693")
|
2023-01-10 19:31:15 +03:00
|
|
|
$(mkRelFile "M.juvix"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2023-01-10 19:31:15 +03:00
|
|
|
"Issue 1704 (Type synonyms)"
|
|
|
|
$(mkRelDir "Internal")
|
2023-01-27 14:45:38 +03:00
|
|
|
$(mkRelFile "Synonyms.juvix"),
|
|
|
|
posTest
|
|
|
|
"Issue 1731 Trace builtin for debugging"
|
|
|
|
$(mkRelDir "issue1731")
|
|
|
|
$(mkRelFile "builtinTrace.juvix"),
|
|
|
|
posTest
|
|
|
|
"Issue 1731 Fail builtin for debugging"
|
|
|
|
$(mkRelDir "issue1731")
|
2023-02-06 16:53:35 +03:00
|
|
|
$(mkRelFile "builtinFail.juvix"),
|
|
|
|
posTest
|
|
|
|
"Case expressions"
|
|
|
|
$(mkRelDir "Internal")
|
2023-02-22 12:26:54 +03:00
|
|
|
$(mkRelFile "Case.juvix"),
|
|
|
|
posTest
|
|
|
|
"Let shadowing"
|
|
|
|
$(mkRelDir ".")
|
2023-03-10 11:53:05 +03:00
|
|
|
$(mkRelFile "LetShadow.juvix"),
|
|
|
|
posTest
|
|
|
|
"Type synonym inside let"
|
|
|
|
$(mkRelDir "issue1879")
|
2023-03-17 14:05:55 +03:00
|
|
|
$(mkRelFile "LetSynonym.juvix"),
|
2023-05-15 14:02:09 +03:00
|
|
|
posTest
|
|
|
|
"Mutually recursive of lambda calculus with synonyms"
|
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "LambdaCalculus.juvix"),
|
|
|
|
posTest
|
|
|
|
"Mutually recursive type synonym and inductive type"
|
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "MutualType.juvix"),
|
|
|
|
posTest
|
|
|
|
"Type synonym inside local module"
|
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "LocalSynonym.juvix"),
|
2023-03-17 14:05:55 +03:00
|
|
|
posTest
|
|
|
|
"Mutual inference inside let"
|
|
|
|
$(mkRelDir ".")
|
2023-05-03 12:24:39 +03:00
|
|
|
$(mkRelFile "MutualLet.juvix"),
|
2023-06-02 13:12:02 +03:00
|
|
|
posTest
|
|
|
|
"import inside local module"
|
|
|
|
$(mkRelDir "issue2163")
|
|
|
|
$(mkRelFile "Main.juvix"),
|
2023-05-10 15:07:03 +03:00
|
|
|
posTest
|
|
|
|
"id application in type"
|
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "IdInType.juvix"),
|
2023-05-03 12:24:39 +03:00
|
|
|
posTest
|
|
|
|
"Nested pattern match with type variables"
|
|
|
|
$(mkRelDir ".")
|
2023-07-11 13:26:52 +03:00
|
|
|
$(mkRelFile "NestedPatterns.juvix"),
|
|
|
|
posTest
|
|
|
|
"issue2248: Import type alias"
|
|
|
|
$(mkRelDir "issue2248")
|
2023-07-18 12:32:34 +03:00
|
|
|
$(mkRelFile "Main.juvix"),
|
|
|
|
posTest
|
|
|
|
"Named arguments"
|
|
|
|
$(mkRelDir ".")
|
2023-07-24 17:56:13 +03:00
|
|
|
$(mkRelFile "NamedArguments.juvix"),
|
|
|
|
posTest
|
|
|
|
"Record declaration"
|
|
|
|
$(mkRelDir ".")
|
2023-08-01 11:46:22 +03:00
|
|
|
$(mkRelFile "Records.juvix"),
|
2023-08-07 13:35:36 +03:00
|
|
|
posTest
|
|
|
|
"Record update"
|
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "Records2.juvix"),
|
2023-08-01 11:46:22 +03:00
|
|
|
posTest
|
|
|
|
"Record projections"
|
|
|
|
$(mkRelDir ".")
|
2023-08-08 17:01:20 +03:00
|
|
|
$(mkRelFile "Projections.juvix"),
|
|
|
|
posTest
|
|
|
|
"Record patterns"
|
|
|
|
$(mkRelDir ".")
|
2023-08-16 18:51:09 +03:00
|
|
|
$(mkRelFile "RecordPattern.juvix"),
|
|
|
|
posTest
|
|
|
|
"Wildcard arguments"
|
|
|
|
$(mkRelDir ".")
|
2023-08-22 11:32:26 +03:00
|
|
|
$(mkRelFile "WildcardArguments.juvix"),
|
|
|
|
posTest
|
|
|
|
"Omit Type annotation"
|
|
|
|
$(mkRelDir ".")
|
2023-08-22 12:40:12 +03:00
|
|
|
$(mkRelFile "OmitType.juvix"),
|
|
|
|
posTest
|
|
|
|
"Issue 2296 (Pi types with lhs arity other than unit)"
|
|
|
|
$(mkRelDir "issue2296")
|
2023-08-25 16:28:58 +03:00
|
|
|
$(mkRelFile "M.juvix"),
|
|
|
|
posTest
|
|
|
|
"Alias"
|
|
|
|
$(mkRelDir ".")
|
2023-09-08 13:16:43 +03:00
|
|
|
$(mkRelFile "Alias.juvix"),
|
|
|
|
posTest
|
|
|
|
"Traits"
|
|
|
|
$(mkRelDir ".")
|
2023-09-13 14:46:30 +03:00
|
|
|
$(mkRelFile "Traits.juvix"),
|
|
|
|
posTest
|
|
|
|
"Instance import"
|
|
|
|
$(mkRelDir "InstanceImport")
|
2023-09-26 14:17:50 +03:00
|
|
|
$(mkRelFile "Main.juvix"),
|
|
|
|
posTest
|
|
|
|
"Hole as numeric type"
|
|
|
|
$(mkRelDir "issue2373")
|
2023-10-02 19:58:21 +03:00
|
|
|
$(mkRelFile "Main.juvix"),
|
|
|
|
posTest
|
|
|
|
"Hole in type parameter"
|
|
|
|
$(mkRelDir ".")
|
2023-10-10 16:55:17 +03:00
|
|
|
$(mkRelFile "HoleTypeParameter.juvix"),
|
|
|
|
posTest
|
|
|
|
"Instance axiom"
|
|
|
|
$(mkRelDir ".")
|
2023-11-10 15:55:36 +03:00
|
|
|
$(mkRelFile "InstanceAxiom.juvix"),
|
|
|
|
posTest
|
|
|
|
"Markdown"
|
|
|
|
$(mkRelDir "Markdown")
|
2023-11-17 18:10:38 +03:00
|
|
|
$(mkRelFile "Test.juvix.md"),
|
|
|
|
posTest
|
|
|
|
"Import a .juvix.md module in a .juvix file"
|
|
|
|
$(mkRelDir "MarkdownImport")
|
|
|
|
$(mkRelFile "A.juvix"),
|
|
|
|
posTest
|
|
|
|
"Import a .juvix.md module in a .juvix.md file"
|
|
|
|
$(mkRelDir "MarkdownImport")
|
|
|
|
$(mkRelFile "C.juvix.md"),
|
2023-12-07 12:12:36 +03:00
|
|
|
posTest
|
|
|
|
"Typecheck constructor wildcard"
|
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "ConstructorWildcard.juvix"),
|
2023-11-17 18:10:38 +03:00
|
|
|
posTestAbsDir
|
|
|
|
"Typecheck orphan file"
|
|
|
|
(relToProject $(mkRelDir "tests/WithoutPackageFile"))
|
|
|
|
$(mkRelFile "Good.juvix")
|
2022-04-05 23:02:03 +03:00
|
|
|
]
|
2023-04-28 11:05:53 +03:00
|
|
|
<> [ compilationTest t | t <- Compilation.tests
|
2023-01-17 11:41:07 +03:00
|
|
|
]
|