Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for unsupported builtins #2757

Merged
merged 1 commit into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/Juvix/Compiler/Core/Language/Builtins.hs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,13 @@ builtinIsFoldable = \case
OpRandomEcPoint -> False

builtinIsCairo :: BuiltinOp -> Bool
builtinIsCairo = \case
OpPoseidonHash -> True
OpEc -> True
OpRandomEcPoint -> True
_ -> False
builtinIsCairo op = op `elem` builtinsCairo

builtinsString :: [BuiltinOp]
builtinsString = [OpStrConcat, OpStrToInt, OpShow]

builtinsCairo :: [BuiltinOp]
builtinsCairo = [OpPoseidonHash, OpEc, OpRandomEcPoint]

builtinsAnoma :: [BuiltinOp]
builtinsAnoma = [OpAnomaGet]
2 changes: 1 addition & 1 deletion src/Juvix/Compiler/Core/Transformation/Check/Anoma.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ checkAnoma md = do
checkMainExists md
checkNoAxioms md
mapAllNodesM checkNoIO md
mapAllNodesM (checkBuiltins' [OpStrConcat, OpStrToInt, OpShow] [PrimString]) md
mapAllNodesM (checkBuiltins' (builtinsString ++ builtinsCairo) [PrimString, PrimField]) md
13 changes: 9 additions & 4 deletions src/Juvix/Compiler/Core/Transformation/Check/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ checkBuiltins allowUntypedFail = dmapRM go
throw $ unsupportedError "strings" node (getInfoLocation _typePrimInfo)
NBlt BuiltinApp {..} ->
case _builtinAppOp of
OpShow -> throw $ unsupportedError "strings" node (getInfoLocation _builtinAppInfo)
OpStrConcat -> throw $ unsupportedError "strings" node (getInfoLocation _builtinAppInfo)
OpStrToInt -> throw $ unsupportedError "strings" node (getInfoLocation _builtinAppInfo)
OpTrace -> throw $ unsupportedError "tracing" node (getInfoLocation _builtinAppInfo)
OpFail | not allowUntypedFail -> do
let ty = Info.getInfoType _builtinAppInfo
Expand All @@ -67,7 +64,15 @@ checkBuiltins allowUntypedFail = dmapRM go
return $ Recur node
OpFail -> do
return $ End node
_ -> return $ Recur node
_
| _builtinAppOp `elem` builtinsString ->
throw $ unsupportedError "strings" node (getInfoLocation _builtinAppInfo)
| _builtinAppOp `elem` builtinsCairo ->
throw $ unsupportedError "cairo" node (getInfoLocation _builtinAppInfo)
| _builtinAppOp `elem` builtinsAnoma ->
throw $ unsupportedError "anoma" node (getInfoLocation _builtinAppInfo)
| otherwise ->
return $ Recur node
_ -> return $ Recur node

checkBuiltins' :: forall r. (Member (Error CoreError) r) => [BuiltinOp] -> [Primitive] -> Node -> Sem r Node
Expand Down
2 changes: 1 addition & 1 deletion src/Juvix/Compiler/Core/Transformation/Check/Cairo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ checkCairo md = do
checkMainType
checkNoAxioms md
mapAllNodesM checkNoIO md
mapAllNodesM (checkBuiltins' [OpStrConcat, OpStrToInt, OpShow] [PrimString]) md
mapAllNodesM (checkBuiltins' builtinsString [PrimString]) md
where
checkMainType :: Sem r ()
checkMainType =
Expand Down
48 changes: 27 additions & 21 deletions src/Juvix/Compiler/Core/Transformation/Check/Exec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,39 @@ import Juvix.Data.PPOutput
checkExec :: forall r. (Member (Error CoreError) r) => Module -> Sem r Module
checkExec md = do
checkNoAxioms md
case md ^. moduleInfoTable . infoMain of
Nothing ->
throw
CoreError
{ _coreErrorMsg = ppOutput "no `main` function",
_coreErrorNode = Nothing,
_coreErrorLoc = defaultLoc
}
Just sym ->
case ii ^. identifierType of
NPi {} ->
checkMainExists md
checkMainType
mapAllNodesM (checkBuiltins' (builtinsCairo ++ builtinsAnoma) []) md
where
checkMainType :: Sem r ()
checkMainType =
case md ^. moduleInfoTable . infoMain of
Nothing ->
throw
CoreError
{ _coreErrorMsg = ppOutput "`main` cannot have a function type for this target",
{ _coreErrorMsg = ppOutput "no `main` function",
_coreErrorNode = Nothing,
_coreErrorLoc = loc
_coreErrorLoc = defaultLoc
}
ty
| isTypeConstr md ty ->
Just sym ->
case ii ^. identifierType of
NPi {} ->
throw
CoreError
{ _coreErrorMsg = ppOutput "`main` cannot be a type for this target",
{ _coreErrorMsg = ppOutput "`main` cannot have a function type for this target",
_coreErrorNode = Nothing,
_coreErrorLoc = loc
}
_ ->
return md
where
ii = lookupIdentifierInfo md sym
loc = fromMaybe defaultLoc (ii ^. identifierLocation)
ty
| isTypeConstr md ty ->
throw
CoreError
{ _coreErrorMsg = ppOutput "`main` cannot be a type for this target",
_coreErrorNode = Nothing,
_coreErrorLoc = loc
}
_ ->
return ()
where
ii = lookupIdentifierInfo md sym
loc = fromMaybe defaultLoc (ii ^. identifierLocation)
Loading