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,26 +210,42 @@ 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
checkAbbreved v "Abbreviated variable % used inside the scope of the abbreviation" if nonce
pop then descend s >> return ()
else do pushRecurse scope
checkAbbreved v "Abbreviated variable % used inside the scope of the abbreviation"
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
checkAbbreved v "Abbreviated variable % used inside the scope of the abbreviation" if nonce
checkNotWritten (A.Variable m n) "VAL-abbreviated variable % written-to inside the scope of the abbreviation" then descend s >> return ()
pop else do pushRecurse scope
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"
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
checkNotWritten (A.Variable m n) "VAL-abbreviated variable % written-to inside the scope of the abbreviation" if nonce
sequence_ [checkNotWritten v then descend s >> return ()
"Abbreviated variable % used inside the scope of the abbreviation" else do pushRecurse scope
| A.ExprVariable _ v <- fastListify (const True) e] checkNotWritten (A.Variable m n) "VAL-abbreviated variable % written-to inside the scope of the abbreviation"
pop sequence_ [checkNotWritten v
"Abbreviated variable % used inside the scope of the abbreviation"
| A.ExprVariable _ v <- fastListify (const True) e]
pop
return s return s
doStructured s = descend s doStructured s = descend s