[clean up simplifier a lot. make more inlining decisions when variable is encountered.
John Meacham <john@repetae.net>**20060420045811] hunk ./E/SSimplify.hs 267
+data Forced = ForceInline | ForceNoinline | NotForced
+    deriving(Eq,Ord)
+
hunk ./E/SSimplify.hs 272
-    | IsBoundTo { bindingOccurance :: Occurance, bindingE :: OutE, bindingCheap :: Bool }
+    | IsBoundTo {
+        bindingOccurance :: Occurance,
+        bindingE :: OutE,
+        bindingCheap :: Bool,
+        inlineForced :: Forced,
+        bindingAtomic :: Bool
+        }
hunk ./E/SSimplify.hs 286
-    bindingCheap = isCheap e
-    }
+    bindingCheap = isCheap e,
+    inlineForced = if o == LoopBreaker then ForceNoinline else NotForced,
+    bindingAtomic = atomic
+    } where
+    atomic = isAtomic e
+
+
+instance Monoid Forced where
+    mempty = NotForced
+    mappend NotForced x = x
+    mappend x NotForced = x
+    mappend _ ForceNoinline = ForceNoinline
+    mappend ForceNoinline _ = ForceNoinline
+    mappend ForceInline ForceInline = ForceInline
+
+fixInline finalPhase v bt@IsBoundTo {} = bt { inlineForced = inlineForced bt `mappend` calcForced finalPhase v }  where
+
+calcForced finalPhase v =
+    case (forceNoinline v,finalPhase,forceInline v) of
+        (True,_,_) -> ForceNoinline
+        (False,True,_) -> NotForced
+        (False,False,True) -> ForceInline
+        (False,False,False) -> NotForced
+
hunk ./E/SSimplify.hs 409
+    finalPhase = so_finalPhase sopts
hunk ./E/SSimplify.hs 415
-    initialB = mempty { envInScope =  fmap (\e -> isBoundTo Many e) (so_boundVars sopts) }
-    initialB' = mempty { envInScope =  fmap (\e -> NotKnown) (so_boundVars sopts) }
+    initialB = let
+            bb (t,e) | isFullyConst e = [(t,Done e)]
+            bb _ = []
+        in cacheSubst mempty { envSubst = fromList $ concatMap bb  (massocs $ so_boundVars sopts),  envInScope =  fmap (\e -> isBoundTo Many e) (so_boundVars sopts) }
hunk ./E/SSimplify.hs 423
-        --ds' <- sequence [etaExpandDef' (so_dataTable sopts) t e | (t,e) <- dsIn ]
hunk ./E/SSimplify.hs 424
---        let g (t,e) = do
---                e' <- if not (so_finalPhase sopts) && forceInline t  then
---                        f e initialB'  -- ^ do not inline into functions which themself will be inlined
---                            else f e initialB
---                return (t,e')
---        mapM g ds'
hunk ./E/SSimplify.hs 566
-        d' <- f d (insertDoneSubst b (EVar b') (insertInScope (tvrIdent b') (isBoundTo Many e) inb))
+        d' <- f d (insertDoneSubst b (EVar b') (insertInScope (tvrIdent b') (fixInline finalPhase b' $ isBoundTo Many e) inb))
hunk ./E/SSimplify.hs 654
-        case (z,forceNoinline v) of
-            (Just (x,xs),_) -> didInline inb x xs  -- h x xs inb
-            (_,True) -> app (EVar v, xs')
+        case z of
+            (Just (x,xs)) -> didInline inb x xs  -- h x xs inb
hunk ./E/SSimplify.hs 657
-                Just IsBoundTo { bindingOccurance = LoopBreaker } -> appVar v xs'
+                Just IsBoundTo { inlineForced = ForceNoinline } -> appVar v xs'
hunk ./E/SSimplify.hs 659
-                Just IsBoundTo { bindingE = e } | isAtomic e  -> do
+                Just IsBoundTo { bindingE = e, bindingAtomic = True }  -> do
hunk ./E/SSimplify.hs 662
-                Just IsBoundTo { bindingE = e } | not (so_finalPhase sopts), forceInline v, someBenefit v e xs' -> do
+                Just IsBoundTo { bindingE = e, inlineForced = ForceInline } | someBenefit v e xs' -> do
+                    mtick  (toAtom $ "E.Simplify.inline.Forced.{" ++ tvrShowName v  ++ "}")
+                    didInline inb e xs'
+                Just IsBoundTo { bindingE = e } | forceInline v, someBenefit v e xs' -> do
hunk ./E/SSimplify.hs 735
-                let inb' = if not (so_finalPhase sopts) && forceInline t' then (cacheSubst $ envInScope_u (fmap (const NotKnown)) inb) else inb
+
+                let inb' = case isForced of
+                        ForceInline -> (cacheSubst $ envInScope_u (fmap nogrowth) inb)
+                        _ -> inb
+                    isForced = calcForced finalPhase t'
+                    nogrowth IsBoundTo { bindingAtomic = False } = NotKnown
+                    nogrowth x = x
hunk ./E/SSimplify.hs 743
-                w rs (insertInScope (tvrIdent t') (isBoundTo n e') inb)  ((t',e'):ds)
+                let ibt = fixInline finalPhase t' $ isBoundTo n e'
+                case (bindingAtomic ibt,inlineForced ibt) of
+                    (True,f) | f /= ForceNoinline -> do
+                        when (n /= Unused) $ mtick $ "E.Simplify.inline.Atomic.{" ++ showName t ++ "}"
+                        w rs (insertDoneSubst' t e' . insertInScope (tvrIdent t') (isBoundTo n e') $ inb) ds
+                    _ -> w rs (insertInScope (tvrIdent t') ibt inb)  ((t',e'):ds)