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-11-07 16:47:56 +03:00
|
|
|
import Juvix.Compiler.Builtins (iniState)
|
2022-08-03 14:20:40 +03:00
|
|
|
import Juvix.Compiler.Pipeline
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
|
posTest _name rdir rfile =
|
|
|
|
let _dir = root <//> rdir
|
|
|
|
_file = _dir <//> rfile
|
|
|
|
in PosTest {..}
|
|
|
|
|
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
|
|
|
|
let entryPoint = defaultEntryPoint _dir _file
|
|
|
|
(void . runIO' iniState entryPoint) upToInternalTyped
|
|
|
|
}
|
2022-04-05 23:02:03 +03:00
|
|
|
|
2022-07-23 10:27:12 +03:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- Testing --no-positivity flag with all related negative tests
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
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
|
|
|
|
|
|
|
testNoPositivityFlag :: N.NegTest -> TestDescr
|
|
|
|
testNoPositivityFlag N.NegTest {..} =
|
2022-12-20 15:05:40 +03:00
|
|
|
let tRoot = rootNegTests <//> _relDir
|
|
|
|
file' = tRoot <//> _file
|
2022-07-23 10:27:12 +03:00
|
|
|
in TestDescr
|
|
|
|
{ _testName = _name,
|
|
|
|
_testRoot = tRoot,
|
|
|
|
_testAssertion = Single $ do
|
|
|
|
let entryPoint =
|
2022-12-20 15:05:40 +03:00
|
|
|
(defaultEntryPoint tRoot file')
|
2022-08-19 17:57:07 +03:00
|
|
|
{ _entryPointNoPositivity = True
|
2022-07-23 10:27:12 +03:00
|
|
|
}
|
|
|
|
|
2022-11-07 16:47:56 +03:00
|
|
|
(void . runIO' iniState entryPoint) upToInternal
|
2022-07-23 10:27:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
negPositivityTests :: [N.NegTest]
|
|
|
|
negPositivityTests = N.negPositivityTests
|
|
|
|
|
|
|
|
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"
|
|
|
|
(map (mkTest . testDescr) testPositivityKeyword)
|
|
|
|
]
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
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-06-13 15:25:22 +03:00
|
|
|
"PolySimpleFungibleToken"
|
2022-12-20 15:05:40 +03:00
|
|
|
$(mkRelDir "FullExamples")
|
|
|
|
$(mkRelFile "SimpleFungibleTokenImplicit.juvix"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2022-05-06 13:45:09 +03:00
|
|
|
"GHC backend MonoSimpleFungibleToken"
|
2022-12-20 15:05:40 +03:00
|
|
|
$(mkRelDir "FullExamples")
|
|
|
|
$(mkRelFile "MonoSimpleFungibleToken.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-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")
|
|
|
|
$(mkRelFile "Synonyms.juvix")
|
2022-04-05 23:02:03 +03:00
|
|
|
]
|
2023-01-17 11:41:07 +03:00
|
|
|
<> [ compilationTest t | t <- Compilation.tests, t ^. Compilation.name `notElem` ["Self-application"]
|
|
|
|
]
|