mirror of
https://github.com/anoma/juvix.git
synced 2024-11-26 17:06:23 +03:00
Check for the executable (WASM/native) pipeline prerequisites (#1970)
* Closes #1959
This commit is contained in:
parent
63a2c5144d
commit
dbd24f2f93
@ -18,6 +18,7 @@ data TransformationId
|
|||||||
| EtaExpandApps
|
| EtaExpandApps
|
||||||
| DisambiguateNames
|
| DisambiguateNames
|
||||||
| CheckGeb
|
| CheckGeb
|
||||||
|
| CheckExec
|
||||||
| LetFolding
|
| LetFolding
|
||||||
deriving stock (Data, Bounded, Enum, Show)
|
deriving stock (Data, Bounded, Enum, Show)
|
||||||
|
|
||||||
@ -53,7 +54,7 @@ toEvalTransformations = [EtaExpandApps, MatchToCase, NatToInt, ConvertBuiltinTyp
|
|||||||
|
|
||||||
toStrippedTransformations :: [TransformationId]
|
toStrippedTransformations :: [TransformationId]
|
||||||
toStrippedTransformations =
|
toStrippedTransformations =
|
||||||
toEvalTransformations ++ [LambdaLetRecLifting, LetFolding, TopEtaExpand, MoveApps, RemoveTypeArgs]
|
toEvalTransformations ++ [CheckExec, LambdaLetRecLifting, LetFolding, TopEtaExpand, MoveApps, RemoveTypeArgs]
|
||||||
|
|
||||||
toGebTransformations :: [TransformationId]
|
toGebTransformations :: [TransformationId]
|
||||||
toGebTransformations = toEvalTransformations ++ [CheckGeb, LetRecLifting, LetFolding, UnrollRecursion, ComputeTypeInfo]
|
toGebTransformations = toEvalTransformations ++ [CheckGeb, LetRecLifting, LetFolding, UnrollRecursion, ComputeTypeInfo]
|
||||||
|
@ -82,6 +82,7 @@ transformationText = \case
|
|||||||
UnrollRecursion -> strUnrollRecursion
|
UnrollRecursion -> strUnrollRecursion
|
||||||
DisambiguateNames -> strDisambiguateNames
|
DisambiguateNames -> strDisambiguateNames
|
||||||
CheckGeb -> strCheckGeb
|
CheckGeb -> strCheckGeb
|
||||||
|
CheckExec -> strCheckExec
|
||||||
LetFolding -> strLetFolding
|
LetFolding -> strLetFolding
|
||||||
|
|
||||||
parsePipeline :: MonadParsec e Text m => m PipelineId
|
parsePipeline :: MonadParsec e Text m => m PipelineId
|
||||||
@ -147,5 +148,8 @@ strDisambiguateNames = "disambiguate-names"
|
|||||||
strCheckGeb :: Text
|
strCheckGeb :: Text
|
||||||
strCheckGeb = "check-geb"
|
strCheckGeb = "check-geb"
|
||||||
|
|
||||||
|
strCheckExec :: Text
|
||||||
|
strCheckExec = "check-exec"
|
||||||
|
|
||||||
strLetFolding :: Text
|
strLetFolding :: Text
|
||||||
strLetFolding = "let-folding"
|
strLetFolding = "let-folding"
|
||||||
|
@ -12,6 +12,7 @@ import Juvix.Compiler.Core.Data.TransformationId
|
|||||||
import Juvix.Compiler.Core.Error
|
import Juvix.Compiler.Core.Error
|
||||||
import Juvix.Compiler.Core.Options
|
import Juvix.Compiler.Core.Options
|
||||||
import Juvix.Compiler.Core.Transformation.Base
|
import Juvix.Compiler.Core.Transformation.Base
|
||||||
|
import Juvix.Compiler.Core.Transformation.CheckExec
|
||||||
import Juvix.Compiler.Core.Transformation.CheckGeb
|
import Juvix.Compiler.Core.Transformation.CheckGeb
|
||||||
import Juvix.Compiler.Core.Transformation.ComputeTypeInfo
|
import Juvix.Compiler.Core.Transformation.ComputeTypeInfo
|
||||||
import Juvix.Compiler.Core.Transformation.ConvertBuiltinTypes
|
import Juvix.Compiler.Core.Transformation.ConvertBuiltinTypes
|
||||||
@ -48,4 +49,5 @@ applyTransformations ts tbl = foldM (flip appTrans) tbl ts
|
|||||||
EtaExpandApps -> return . etaExpansionApps
|
EtaExpandApps -> return . etaExpansionApps
|
||||||
DisambiguateNames -> return . disambiguateNames
|
DisambiguateNames -> return . disambiguateNames
|
||||||
CheckGeb -> mapError (JuvixError @CoreError) . checkGeb
|
CheckGeb -> mapError (JuvixError @CoreError) . checkGeb
|
||||||
|
CheckExec -> mapError (JuvixError @CoreError) . checkExec
|
||||||
LetFolding -> return . letFolding
|
LetFolding -> return . letFolding
|
||||||
|
40
src/Juvix/Compiler/Core/Transformation/CheckExec.hs
Normal file
40
src/Juvix/Compiler/Core/Transformation/CheckExec.hs
Normal 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)
|
@ -43,6 +43,6 @@ compileErrorAssertion mainFile step = do
|
|||||||
cwd <- getCurrentDir
|
cwd <- getCurrentDir
|
||||||
let entryPoint = defaultEntryPoint cwd mainFile
|
let entryPoint = defaultEntryPoint cwd mainFile
|
||||||
tab <- (^. Core.coreResultTable) . snd <$> runIO' entryPoint upToCore
|
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
|
Left _ -> assertBool "" True
|
||||||
Right _ -> assertFailure "no error"
|
Right _ -> assertFailure "no error"
|
||||||
|
@ -41,5 +41,9 @@ tests =
|
|||||||
NegTest
|
NegTest
|
||||||
"Pattern matching coverage in lambdas"
|
"Pattern matching coverage in lambdas"
|
||||||
$(mkRelDir ".")
|
$(mkRelDir ".")
|
||||||
$(mkRelFile "test003.juvix")
|
$(mkRelFile "test003.juvix"),
|
||||||
|
NegTest
|
||||||
|
"The definition of main has a function type"
|
||||||
|
$(mkRelDir ".")
|
||||||
|
$(mkRelFile "test004.juvix")
|
||||||
]
|
]
|
||||||
|
6
tests/Compilation/negative/test004.juvix
Normal file
6
tests/Compilation/negative/test004.juvix
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
module test004;
|
||||||
|
|
||||||
|
open import Stdlib.Prelude;
|
||||||
|
|
||||||
|
main : Nat -> Nat;
|
||||||
|
main x := x;
|
Loading…
Reference in New Issue
Block a user