-argToPat in_scope con_env (Var v) arg_occ -- Don't uniqify existing vars,
- = return (interesting, Var v) -- so that we can spot when we pass them twice
- where
- interesting = not (isLocalId v) || v `elemVarEnv` in_scope
+argToPat in_scope con_env (Var v) arg_occ
+ | not (isLocalId v) || v `elemVarEnv` in_scope
+ = -- The recursive call passes a variable that
+ -- is in scope at the function definition site
+ -- It's worth specialising on this if
+ -- (a) it's used in an interesting way in the body
+ -- (b) we know what its value is
+ if (case arg_occ of { UnkOcc -> False; other -> True }) -- (a)
+ && isValueUnfolding (idUnfolding v) -- (b)
+ then return (True, Var v)
+ else wildCardPat (idType v)
+
+argToPat in_scope con_env (Let _ arg) arg_occ
+ = argToPat in_scope con_env arg arg_occ
+ -- Look through let expressions
+ -- e.g. f (let v = rhs in \y -> ...v...)
+ -- Here we can specialise for f (\y -> ...)
+ -- because the rule-matcher will look through the let.