From e5ed7e07b7a0dc2d0db83278c1172f23119c56ca Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Fri, 14 Nov 2008 15:30:02 +0000 Subject: [PATCH] Fixed the apply function, which (mainly due to having the wrong type signature, but also its use of extTransformRoute) was not as polymorphic as it should have been, which was breaking the traversal (I think it would only work on one Structured type) --- checks/CheckFramework.hs | 11 +++++------ common/GenericUtils.hs | 13 ------------- 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/checks/CheckFramework.hs b/checks/CheckFramework.hs index c0c7208..5a843e8 100644 --- a/checks/CheckFramework.hs +++ b/checks/CheckFramework.hs @@ -289,13 +289,12 @@ traverse typeSet f route tr -- The return of this function is ignored. All changes should be done in the -- state. -apply :: forall a. Data a => TypeSet -> (a -> CheckOptM' a ()) -> - (a, Route a A.AST) -> RestartT CheckOptM a +apply :: TypeSet -> (forall a. Data a => a -> CheckOptM' a ()) -> + (forall b. Data b => (b, Route b A.AST) -> RestartT CheckOptM b) apply typeSet f (x, route) - = (flip runReaderT route (deCheckOptM' (f x))) - >> (lift (CheckOptM get) >>* ast >>* routeGet route) - >>= gmapMForRoute typeSet (extTransformRoute baseTransformRoute $ - \(y, route') -> apply typeSet f (y, route @-> route')) + = (lift . CheckOptM $ modify $ \d -> if findMeta x == emptyMeta then d else d {lastValidMeta = findMeta x}) + >> (flip runReaderT route (deCheckOptM' (f x))) + >> gmapMForRoute typeSet (\(y, route') -> apply typeSet f (y, route @-> route')) x -- | For both of these functions I'm going to need to mark all analyses as no longer -- valid, but more difficult will be to maintain the current position (if possible diff --git a/common/GenericUtils.hs b/common/GenericUtils.hs index 28e790d..dff11a2 100644 --- a/common/GenericUtils.hs +++ b/common/GenericUtils.hs @@ -30,7 +30,6 @@ module GenericUtils ( , gmapMForRoute , routeModify, routeGet, routeSet, Route(..), (@->), routeIdentity, routeId, routeList , route22, route23, route33, route34, route44, route45, route55 - , baseTransformRoute, extTransformRoute ) where import Control.Monad.Identity @@ -42,7 +41,6 @@ import Data.IntSet (IntSet) import qualified Data.IntSet as IntSet import Data.List import Data.Typeable -import GHC.Base (unsafeCoerce#) import System.IO.Unsafe import qualified AST as A @@ -220,17 +218,6 @@ gmapMWithRoute f = gmapFuncs [GM {unGM = f' n} | n <- [0..]] f' :: Int -> (forall b. Data b => b -> m b) f' n x = f (x, makeRoute n) -baseTransformRoute :: forall m s t. (Data s, Monad m) => (s, Route s t) -> m s -baseTransformRoute (x, _) = return x - -extTransformRoute :: forall s m t. (Data s, Monad m) => (forall a. Data a => (a, Route a t) -> m a) -> ((s, Route s t) -> m - s) -> (forall a. Data a => (a, Route a t) -> m a) -extTransformRoute generalFunc specificFunc (x, route) - = case cast x of - Just x' -> do Just y <- specificFunc (x', unsafeCoerce# route) >>* cast - return y - Nothing -> generalFunc (x, route) - -- Given a number, makes a route function for that child: makeRoute :: (Data s, Data t) => Int -> Route s t makeRoute target = Route [target] (\f -> gmapFuncs [mkM' (if n == target then f else return) | n <- [0..]])