From 152f5fc252f9c8f9cb21bff99ada046462f5ce5d Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Wed, 11 Feb 2009 11:23:39 +0000 Subject: [PATCH] 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. --- transformations/SimplifyAbbrevs.hs | 42 +++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/transformations/SimplifyAbbrevs.hs b/transformations/SimplifyAbbrevs.hs index 7c1a04e..f2ba8bd 100644 --- a/transformations/SimplifyAbbrevs.hs +++ b/transformations/SimplifyAbbrevs.hs @@ -210,26 +210,42 @@ abbrevCheckPass 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 (A.Structured a) doStructured s@(A.Spec _ (A.Specification _ n (A.Is _ A.Abbrev _ v)) scope) - = do pushRecurse scope - checkAbbreved v "Abbreviated variable % used inside the scope of the abbreviation" - pop + = 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" + pop return s doStructured s@(A.Spec _ (A.Specification m n (A.Is _ A.ValAbbrev _ v)) scope) - = 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 + = 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" + checkNotWritten (A.Variable m n) "VAL-abbreviated variable % written-to inside the scope of the abbreviation" + pop return s doStructured s@(A.Spec _ (A.Specification m n (A.IsExpr _ A.ValAbbrev _ e)) scope) - = do pushRecurse scope - checkNotWritten (A.Variable m n) "VAL-abbreviated variable % written-to inside the scope of the abbreviation" - sequence_ [checkNotWritten v - "Abbreviated variable % used inside the scope of the abbreviation" - | A.ExprVariable _ v <- fastListify (const True) e] - pop + = 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" + sequence_ [checkNotWritten v + "Abbreviated variable % used inside the scope of the abbreviation" + | A.ExprVariable _ v <- fastListify (const True) e] + pop return s doStructured s = descend s