--- Any system name is candidate for inlining. Never inline user-defined
--- functions, to preserve structure.
-inlinetoplevel expr@(Var f) | not $ isUserDefined f = do
- body_maybe <- needsInline f
- case body_maybe of
- Just body -> do
- -- Regenerate all uniques in the to-be-inlined expression
- body_uniqued <- Trans.lift $ genUniques body
- -- And replace the variable reference with the unique'd body.
- change body_uniqued
- -- No need to inline
- Nothing -> return expr
-
+inlinetoplevel (LetBinding:_) expr =
+ case collectArgs expr of
+ -- Any system name is candidate for inlining. Never inline
+ -- user-defined functions, to preserve structure.
+ (Var f, args) | not $ isUserDefined f -> do
+ body_maybe <- needsInline f
+ case body_maybe of
+ Just body -> do
+ -- Regenerate all uniques in the to-be-inlined expression
+ body_uniqued <- Trans.lift $ genUniques body
+ -- And replace the variable reference with the unique'd body.
+ change (mkApps body_uniqued args)
+ -- No need to inline
+ Nothing -> return expr
+ -- This is not an application of a binder, leave it unchanged.
+ _ -> return expr