1
1
mirror of https://github.com/anoma/juvix.git synced 2024-11-29 21:32:43 +03:00

Check for the executable (WASM/native) pipeline prerequisites (#1970)

* Closes #1959
This commit is contained in:
Łukasz Czajka 2023-04-04 11:58:36 +02:00 committed by GitHub
parent 63a2c5144d
commit dbd24f2f93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 60 additions and 3 deletions

View File

@ -18,6 +18,7 @@ data TransformationId
| EtaExpandApps
| DisambiguateNames
| CheckGeb
| CheckExec
| LetFolding
deriving stock (Data, Bounded, Enum, Show)
@ -53,7 +54,7 @@ toEvalTransformations = [EtaExpandApps, MatchToCase, NatToInt, ConvertBuiltinTyp
toStrippedTransformations :: [TransformationId]
toStrippedTransformations =
toEvalTransformations ++ [LambdaLetRecLifting, LetFolding, TopEtaExpand, MoveApps, RemoveTypeArgs]
toEvalTransformations ++ [CheckExec, LambdaLetRecLifting, LetFolding, TopEtaExpand, MoveApps, RemoveTypeArgs]
toGebTransformations :: [TransformationId]
toGebTransformations = toEvalTransformations ++ [CheckGeb, LetRecLifting, LetFolding, UnrollRecursion, ComputeTypeInfo]

View File

@ -82,6 +82,7 @@ transformationText = \case
UnrollRecursion -> strUnrollRecursion
DisambiguateNames -> strDisambiguateNames
CheckGeb -> strCheckGeb
CheckExec -> strCheckExec
LetFolding -> strLetFolding
parsePipeline :: MonadParsec e Text m => m PipelineId
@ -147,5 +148,8 @@ strDisambiguateNames = "disambiguate-names"
strCheckGeb :: Text
strCheckGeb = "check-geb"
strCheckExec :: Text
strCheckExec = "check-exec"
strLetFolding :: Text
strLetFolding = "let-folding"

View File

@ -12,6 +12,7 @@ import Juvix.Compiler.Core.Data.TransformationId
import Juvix.Compiler.Core.Error
import Juvix.Compiler.Core.Options
import Juvix.Compiler.Core.Transformation.Base
import Juvix.Compiler.Core.Transformation.CheckExec
import Juvix.Compiler.Core.Transformation.CheckGeb
import Juvix.Compiler.Core.Transformation.ComputeTypeInfo
import Juvix.Compiler.Core.Transformation.ConvertBuiltinTypes
@ -48,4 +49,5 @@ applyTransformations ts tbl = foldM (flip appTrans) tbl ts
EtaExpandApps -> return . etaExpansionApps
DisambiguateNames -> return . disambiguateNames
CheckGeb -> mapError (JuvixError @CoreError) . checkGeb
CheckExec -> mapError (JuvixError @CoreError) . checkExec
LetFolding -> return . letFolding

View File

@ -0,0 +1,40 @@
module Juvix.Compiler.Core.Transformation.CheckExec where
import Data.HashMap.Strict qualified as HashMap
import Juvix.Compiler.Core.Error
import Juvix.Compiler.Core.Extra
import Juvix.Compiler.Core.Transformation.Base
import Juvix.Data.PPOutput
checkExec :: forall r. Member (Error CoreError) r => InfoTable -> Sem r InfoTable
checkExec tab =
case tab ^. infoMain of
Nothing -> return tab
Just sym ->
case ii ^. identifierType of
NPi {} ->
throw
CoreError
{ _coreErrorMsg = ppOutput "`main` cannot have a function type for this target",
_coreErrorNode = Nothing,
_coreErrorLoc = loc
}
ty
| isTypeConstr tab ty ->
throw
CoreError
{ _coreErrorMsg = ppOutput "`main` cannot be a type for this target",
_coreErrorNode = Nothing,
_coreErrorLoc = loc
}
_ ->
return tab
where
ii = fromJust $ HashMap.lookup sym (tab ^. infoIdentifiers)
loc = fromMaybe defaultLoc (ii ^. identifierLocation)
mockFile :: Path Abs File
mockFile = $(mkAbsFile "/core-to-exec")
defaultLoc :: Interval
defaultLoc = singletonInterval (mkInitialLoc mockFile)

View File

@ -43,6 +43,6 @@ compileErrorAssertion mainFile step = do
cwd <- getCurrentDir
let entryPoint = defaultEntryPoint cwd mainFile
tab <- (^. Core.coreResultTable) . snd <$> runIO' entryPoint upToCore
case run $ runReader Core.defaultCoreOptions $ runError @JuvixError $ Core.toEval' tab of
case run $ runReader Core.defaultCoreOptions $ runError @JuvixError $ Core.toStripped' tab of
Left _ -> assertBool "" True
Right _ -> assertFailure "no error"

View File

@ -41,5 +41,9 @@ tests =
NegTest
"Pattern matching coverage in lambdas"
$(mkRelDir ".")
$(mkRelFile "test003.juvix")
$(mkRelFile "test003.juvix"),
NegTest
"The definition of main has a function type"
$(mkRelDir ".")
$(mkRelFile "test004.juvix")
]

View File

@ -0,0 +1,6 @@
module test004;
open import Stdlib.Prelude;
main : Nat -> Nat;
main x := x;