summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2022-05-10 17:18:28 +0100
committerSimon Peyton Jones <simonpj@microsoft.com>2022-05-10 17:18:28 +0100
commiteadc1f0591ac7ad3e6ed284b4f8530ba94ee8fa2 (patch)
treeccea15695d16bb82e2382a11c4b31253f6407820
parenta4fbb589fd176e6c2f6648dea6c93e25668f1db8 (diff)
downloadhaskell-wip/T21489.tar.gz
Specialiser: saturate DFuns correctlywip/T21489
Ticket #21489 showed that the saturation mechanism for DFuns (see Note Specialising DFuns) should use both UnspecType and UnspecArg. We weren't doing that; but this MR fixes that problem. No test case because it's hard to tickle, but it showed up in Gergo's work with GHC-as-a-library.
-rw-r--r--compiler/GHC/Core/Opt/Specialise.hs11
1 files changed, 7 insertions, 4 deletions
diff --git a/compiler/GHC/Core/Opt/Specialise.hs b/compiler/GHC/Core/Opt/Specialise.hs
index 76b76a972d..1e429a4c1e 100644
--- a/compiler/GHC/Core/Opt/Specialise.hs
+++ b/compiler/GHC/Core/Opt/Specialise.hs
@@ -1501,9 +1501,12 @@ specCalls spec_imp env dict_binds existing_rules calls_for_me fn rhs
-> SpecM SpecInfo
spec_call spec_acc@(rules_acc, pairs_acc, uds_acc) _ci@(CI { ci_key = call_args })
= -- See Note [Specialising Calls]
- do { let all_call_args | is_dfun = call_args ++ repeat UnspecArg
+ do { let all_call_args | is_dfun = saturating_call_args -- See Note [Specialising DFuns]
| otherwise = call_args
- -- See Note [Specialising DFuns]
+ saturating_call_args = call_args ++ map mk_extra_dfun_arg (dropList call_args rhs_bndrs)
+ mk_extra_dfun_arg bndr | isTyVar bndr = UnspecType
+ | otherwise = UnspecArg
+
; ( useful, rhs_env2, leftover_bndrs
, rule_bndrs, rule_lhs_args
, spec_bndrs1, dx_binds, spec_args) <- specHeader env_with_dict_bndrs
@@ -1641,8 +1644,8 @@ specLookupRule env fn args rules
DFuns have a special sort of unfolding (DFunUnfolding), and these are
hard to specialise a DFunUnfolding to give another DFunUnfolding
unless the DFun is fully applied (#18120). So, in the case of DFunIds
-we simply extend the CallKey with trailing UnspecArgs, so we'll
-generate a rule that completely saturates the DFun.
+we simply extend the CallKey with trailing UnspecTypes/UnspecArgs,
+so that we'll generate a rule that completely saturates the DFun.
There is an ASSERT that checks this, in the DFunUnfolding case of
GHC.Core.Unfold.Make.specUnfolding.