Fixed the nasty hack of checking for _sizes by checking the new NameSource field instead

To avoid problems with removing _sizes variables, we simply don't remove any nonce variables.
This commit is contained in:
Neil Brown 2008-11-25 17:42:00 +00:00
parent 0e7a6c5b98
commit ce03f2ca27

View File

@ -282,13 +282,14 @@ checkUnusedVar = forAnyASTStructBottomUpAccum doSpec
doSpec (A.Spec _ (A.Specification mspec name _) scope)
= do -- We can't remove _sizes arrays because the backend uses them for bounds
-- checks that are not explicit in the AST. We'll have to move the
-- bounds checking forward into the AST before we can remove them:
when (not $ "_sizes" `isSuffixOf` A.nameName name) $
-- bounds checking forward into the AST before we can remove them.
-- Making this more general, we don't actually remove any unused nonces.
nd <- lookupName name
when (A.ndNameSource nd == A.NameUser) $
do usedNames <- askAccum >>* delete name
-- ^ strip off one use of each name, since it's used in the spec
when (not $ A.nameName name `elem` map A.nameName usedNames) $
do -- TODO have a way of not warning about compiler-generated names:
warnPC mspec WarnUnusedVariable $ formatCode "Unused variable: %" name
do warnPC mspec WarnUnusedVariable $ formatCode "Unused variable: %" name
modify (\st -> st { csNames = Map.delete (A.nameName name) (csNames st) })
substitute scope
doSpec _ = return ()