Changed the abbreviation checking so that it doesn't check nonce names

When we pull up names (which happens before abbreviation checking), we create a lot of nonces with greater scope than the original variables.  When we go to abbreviation check this, we therefore set off lots of false alarms about originally safe code.  So to fix this, the easiest method seems to be turning off checking on all the names introduced by the compiler.
This commit is contained in:
Neil Brown 2009-02-11 11:23:39 +00:00
parent 18f23bf767
commit 152f5fc252

View File

@ -210,21 +210,37 @@ abbrevCheckPass
record b v = modify (\(m:ms) -> (Map.insertWith (||) (Var v) b m : ms)) record b v = modify (\(m:ms) -> (Map.insertWith (||) (Var v) b m : ms))
nameIsNonce :: A.Name -> StateT [Map.Map Var Bool] PassM Bool
nameIsNonce n
= do names <- lift getCompState >>* csNames
case fmap A.ndNameSource $ Map.lookup (A.nameName n) names of
Just A.NameNonce -> return True
_ -> return False
doStructured :: Data a => A.Structured a -> StateT [Map.Map Var Bool] PassM doStructured :: Data a => A.Structured a -> StateT [Map.Map Var Bool] PassM
(A.Structured a) (A.Structured a)
doStructured s@(A.Spec _ (A.Specification _ n (A.Is _ A.Abbrev _ v)) scope) doStructured s@(A.Spec _ (A.Specification _ n (A.Is _ A.Abbrev _ v)) scope)
= do pushRecurse scope = do nonce <- nameIsNonce n
if nonce
then descend s >> return ()
else do pushRecurse scope
checkAbbreved v "Abbreviated variable % used inside the scope of the abbreviation" checkAbbreved v "Abbreviated variable % used inside the scope of the abbreviation"
pop pop
return s return s
doStructured s@(A.Spec _ (A.Specification m n (A.Is _ A.ValAbbrev _ v)) scope) doStructured s@(A.Spec _ (A.Specification m n (A.Is _ A.ValAbbrev _ v)) scope)
= do pushRecurse scope = do nonce <- nameIsNonce n
if nonce
then descend s >> return ()
else do pushRecurse scope
checkAbbreved v "Abbreviated variable % used inside the scope of the abbreviation" checkAbbreved v "Abbreviated variable % used inside the scope of the abbreviation"
checkNotWritten (A.Variable m n) "VAL-abbreviated variable % written-to inside the scope of the abbreviation" checkNotWritten (A.Variable m n) "VAL-abbreviated variable % written-to inside the scope of the abbreviation"
pop pop
return s return s
doStructured s@(A.Spec _ (A.Specification m n (A.IsExpr _ A.ValAbbrev _ e)) scope) doStructured s@(A.Spec _ (A.Specification m n (A.IsExpr _ A.ValAbbrev _ e)) scope)
= do pushRecurse scope = do nonce <- nameIsNonce n
if nonce
then descend s >> return ()
else do pushRecurse scope
checkNotWritten (A.Variable m n) "VAL-abbreviated variable % written-to inside the scope of the abbreviation" checkNotWritten (A.Variable m n) "VAL-abbreviated variable % written-to inside the scope of the abbreviation"
sequence_ [checkNotWritten v sequence_ [checkNotWritten v
"Abbreviated variable % used inside the scope of the abbreviation" "Abbreviated variable % used inside the scope of the abbreviation"