1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-15 01:52:11 +03:00
juvix/test/Reachability/Positive.hs

90 lines
2.8 KiB
Haskell
Raw Normal View History

module Reachability.Positive where
import Base
import Data.HashSet qualified as HashSet
2022-09-26 20:14:17 +03:00
import Juvix.Compiler.Internal.Language qualified as Internal
import Juvix.Compiler.Internal.Translation.FromInternal.Analysis.TypeChecking.Data.Context qualified as Internal
data PosTest = PosTest
{ _name :: String,
2022-12-20 15:05:40 +03:00
_relDir :: Path Rel Dir,
_stdlibMode :: StdlibMode,
2022-12-20 15:05:40 +03:00
_file :: Path Rel File,
_reachable :: HashSet String
}
makeLenses ''PosTest
2022-12-20 15:05:40 +03:00
root :: Path Abs Dir
root = relToProject $(mkRelDir "tests/positive")
testDescr :: PosTest -> TestDescr
testDescr PosTest {..} =
2022-12-20 15:05:40 +03:00
let tRoot = root <//> _relDir
file' = tRoot <//> _file
in TestDescr
{ _testName = _name,
_testRoot = tRoot,
_testAssertion = Steps $ \step -> do
let noStdlib = _stdlibMode == StdlibExclude
entryPoint <-
set entryPointNoStdlib noStdlib
<$> defaultEntryPointCwdIO file'
step "Pipeline up to reachability"
p :: Internal.InternalTypedResult <- snd <$> runIO' entryPoint upToInternalReachability
step "Check reachability results"
2022-09-26 20:14:17 +03:00
let names = concatMap getNames (p ^. Internal.resultModules)
mapM_ check names
}
where
check n = assertBool ("unreachable not filtered: " ++ unpack n) (HashSet.member (unpack n) _reachable)
2022-09-26 20:14:17 +03:00
getNames :: Internal.Module -> [Text]
getNames m = concatMap getDeclName (m ^. (Internal.moduleBody . Internal.moduleStatements))
where
2022-09-26 20:14:17 +03:00
getDeclName :: Internal.Statement -> [Text]
getDeclName = \case
Internal.StatementMutual (Internal.MutualBlock f) -> map getMutualName (toList f)
2022-09-26 20:14:17 +03:00
Internal.StatementAxiom ax -> [ax ^. (Internal.axiomName . Internal.nameText)]
Internal.StatementInclude i -> getNames (i ^. Internal.includeModule)
getMutualName :: Internal.MutualStatement -> Text
getMutualName = \case
Internal.StatementFunction f -> f ^. Internal.funDefName . Internal.nameText
Internal.StatementInductive f -> f ^. Internal.inductiveName . Internal.nameText
allTests :: TestTree
allTests =
testGroup
"Reachability positive tests"
(map (mkTest . testDescr) tests)
tests :: [PosTest]
tests =
[ PosTest
"Reachability with modules"
2022-12-20 15:05:40 +03:00
$(mkRelDir "Reachability")
StdlibInclude
2022-12-20 15:05:40 +03:00
$(mkRelFile "M.juvix")
( HashSet.fromList
["f", "g", "h", "Bool", "Maybe"]
),
PosTest
"Reachability with modules and standard library"
2022-12-20 15:05:40 +03:00
$(mkRelDir "Reachability")
StdlibInclude
2022-12-20 15:05:40 +03:00
$(mkRelFile "N.juvix")
( HashSet.fromList
Add builtin integer type to the surface language (#1948) This PR adds a builtin integer type to the surface language that is compiled to the backend integer type. ## Inductive definition The `Int` type is defined in the standard library as: ``` builtin int type Int := | --- ofNat n represents the integer n ofNat : Nat -> Int | --- negSuc n represents the integer -(n + 1) negSuc : Nat -> Int; ``` ## New builtin functions defined in the standard library ``` intToString : Int -> String; + : Int -> Int -> Int; neg : Int -> Int; * : Int -> Int -> Int; - : Int -> Int -> Int; div : Int -> Int -> Int; mod : Int -> Int -> Int; == : Int -> Int -> Bool; <= : Int -> Int -> Bool; < : Int -> Int -> Bool; ``` Additional builtins required in the definition of the other builtins: ``` negNat : Nat -> Int; intSubNat : Nat -> Nat -> Int; nonNeg : Int -> Bool; ``` ## REPL types of literals In the REPL, non-negative integer literals have the inferred type `Nat`, negative integer literals have the inferred type `Int`. ``` Stdlib.Prelude> :t 1 Nat Stdlib.Prelude> :t -1 Int :t let x : Int := 1 in x Int ``` ## The standard library Prelude The definitions of `*`, `+`, `div` and `mod` are not exported from the standard library prelude as these would conflict with the definitions from `Stdlib.Data.Nat`. Stdlib.Prelude ``` open import Stdlib.Data.Int hiding {+;*;div;mod} public; ``` * Closes https://github.com/anoma/juvix/issues/1679 * Closes https://github.com/anoma/juvix/issues/1984 --------- Co-authored-by: Lukasz Czajka <lukasz@heliax.dev>
2023-04-13 10:16:49 +03:00
["test", "Unit", "Bool", "Nat", "Int"]
),
PosTest
"Reachability with public imports"
2022-12-20 15:05:40 +03:00
$(mkRelDir "Reachability")
StdlibInclude
2022-12-20 15:05:40 +03:00
$(mkRelFile "O.juvix")
( HashSet.fromList
["f", "g", "h", "k", "Bool", "Maybe", "Nat"]
)
]