@@ -31,18 +31,20 @@ runCompile afterCompile = case ?opts of
3131 -- compile the tail targetting sngT, and fold-apply the results together with the head
3232 astT <- foldlM (readCompileApply sngT) hdT tlS
3333
34- optAstT <- if _wholeOpt ? opts
35- -- self-compile one last time for optimisation
36- then compile sngT sngT astT
37- else pure astT
34+ appliedAstT <-
35+ if _wholeOpt ? opts
36+ then -- self-compile one last time for optimisation (also runs the checks)
37+ compile sngT sngT astT
38+ else -- The checks should run also at the whole (applied) program
39+ check sngT astT
3840
39- writeProgram sngT optAstT fileT afterCompile
41+ writeProgram sngT appliedAstT fileT afterCompile
4042
4143 case afterCompile of
4244 Exit {} -> exitSuccess -- nothing left to do
43- Run {} -> runRun sngT optAstT
44- Bench {} -> runBench sngT optAstT
45- Debug {} -> runDebug sngT optAstT
45+ Run {} -> runRun sngT appliedAstT
46+ Bench {} -> runBench sngT appliedAstT
47+ Debug {} -> runDebug sngT appliedAstT
4648
4749readCompileApply :: (? opts :: Opts )
4850 => SLang t -> FromLang t -> SomeFile -> IO (FromLang t )
@@ -70,3 +72,16 @@ compile sngS sngT astS =
7072 Left err -> withA @ Pretty (_sann sngS) $ failE $ show err
7173 Right res -> pure res
7274
75+ check :: (? opts :: Opts )
76+ => SLang t -> FromLang t -> IO (FromLang t )
77+ check sngT astT =
78+ if length (_inputs ? opts) == 1
79+ -- optimization: no need to do more checks if there was no application involved
80+ then pure astT
81+ else case checkProgram sngT astT of
82+ -- compilation errors use the annotation type of the sources
83+ Left err -> do
84+ printE " Failed to typecheck fully-applied program. The error was:"
85+ withA @ Pretty (_sann sngT) $ failE $ show err
86+ -- passed the checks, return it
87+ _ -> pure astT
0 commit comments