@@ -31,8 +31,10 @@ import qualified Agda.Syntax.Common.Pretty as P
3131import Agda.TypeChecking.Datatypes ( isDataOrRecordType )
3232import Agda.TypeChecking.Pretty
3333import Agda.TypeChecking.Records ( isRecordConstructor )
34+ import Agda.TypeChecking.Warnings ( warning )
3435
3536import qualified Agda.Utils.List1 as List1
37+ import Agda.Utils.Monad
3638import Agda.Utils.Maybe ( isJust , isNothing , whenJust , fromMaybe , caseMaybeM )
3739import Agda.Utils.Monad ( whenM )
3840
@@ -102,11 +104,28 @@ compileQName f
102104 Just (r, def) | not (_recNamedCon def) -> r -- use record name for unnamed constructors
103105 _ -> f
104106 hf0 <- compileName (qnameName f)
105- (hf, mimpBuiltin) <- fromMaybe (hf0, Nothing ) <$> isSpecialName f
107+ special <- isSpecialName f
108+ let (hf, mimpBuiltin) = fromMaybe (hf0, Nothing ) special
109+
106110 parent <- parentName f
107111 par <- traverse (compileName . qnameName) parent
108112 let mod0 = qnameModule $ fromMaybe f parent
109113 mod <- compileModuleName mod0
114+
115+ existsInHaskell <- orM
116+ [ pure $ isJust special
117+ , pure $ isPrimModule mod
118+ , hasCompilePragma f
119+ , isClassFunction f
120+ , isWhereFunction f
121+ , maybe (pure False ) hasCompilePragma parent
122+ ]
123+
124+ unless existsInHaskell $ do
125+ reportSDoc " agda2hs.name" 20 $ text " DOES NOT EXIST IN HASKELL"
126+ typeError $ CustomBackendError " agda2hs" $ P. text $
127+ " Symbol " ++ Hs. prettyPrint hf ++ " is missing a COMPILE pragma or rewrite rule"
128+
110129 currMod <- hsTopLevelModuleName <$> asks currModule
111130 let skipModule = mod == currMod
112131 || isJust mimpBuiltin
@@ -185,14 +204,19 @@ compileQName f
185204
186205 mkImport mod qual par hf maybeIsType
187206 -- make sure the Prelude is properly qualified
188- | any ( `isPrefixOf` pp mod ) primModules
207+ | isPrimModule mod
189208 = if isQualified qual then
190209 let mod' = hsModuleName " Prelude"
191210 in (mod', Just (Import mod' qual Nothing hf maybeIsType))
192211 else (mod , Nothing )
193212 | otherwise
194213 = (mod , Just (Import mod qual par hf maybeIsType))
195214
215+ isWhereFunction :: QName -> C Bool
216+ isWhereFunction f = do
217+ whereMods <- asks whereModules
218+ return $ any (qnameModule f `isLeChildModuleOf` ) whereMods
219+
196220hsTopLevelModuleName :: TopLevelModuleName -> Hs. ModuleName ()
197221hsTopLevelModuleName = hsModuleName . intercalate " ." . map unpack
198222 . List1. toList . moduleNameParts
0 commit comments