agda / agda

Agda is a dependently typed programming language / interactive theorem prover.

Home Page:https://wiki.portal.chalmers.se/agda/pmwiki.php

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Revert cyclic computation of ranges (and ban `mdo` from this code base)

andreasabel opened this issue · comments

parseSource :: SourceFile -> TCM Source
parseSource sourceFile@(SourceFile f) = Bench.billTo [Bench.Parsing] $ do
(source, fileType, parsedMod, attrs, parsedModName) <- mdo
-- This piece of code uses mdo because the top-level module name
-- (parsedModName) is obtained from the parser's result, but it is
-- also used by the parser.
let rf = mkRangeFile f (Just parsedModName)
source <- runPM $ readFilePM rf
((parsedMod, attrs), fileType) <- runPM $
parseFile moduleParser rf $
TL.unpack source
parsedModName <- moduleName f parsedMod
return (source, fileType, parsedMod, attrs, parsedModName)
libs <- getAgdaLibFiles f parsedModName

This change in 2.6.3 caused the SrcFile component of ranges to be black holes during parsing, making stuff not Showable and causing regression #7301.

This regression shows that playing with exotic language features like mdo can lead to obscure termination bugs that are very hard to discover (the code that loops is fine, but the data it processes goes to Nirwana when you try to look at it).

I think we should find another solution to the mapping of ranges to files/modules, one that is robust and does not make debugging a mine field.
And then ban mdo.
ATTN: @nad

Here's the only other use:

runRecPatM :: RecPatM a -> TCM a
runRecPatM (RecPatM m) =
mapTCMT (\m -> do
(x, noVars) <- mfix $ \ ~(_, noVars) ->
runStateT (runReaderT m noVars) 0
return x)
m

Here's the only other use:

Indeed, and this is dead code since we replaced the record pattern translation by some other implementation.