diff options
author | sheaf <sam.derbyshire@gmail.com> | 2022-06-02 14:42:08 +0200 |
---|---|---|
committer | sheaf <sam.derbyshire@gmail.com> | 2022-06-02 14:42:08 +0200 |
commit | 30da74aa9c0cc6537c30581f30b8cc52d95c1c61 (patch) | |
tree | 275a32008985627e79ce7d69f7e8aa0200de857a /compiler/GHC/Tc/Utils/Zonk.hs | |
parent | 24b5bb61c33b2675bdfb09504aeec88e70ac3abf (diff) | |
download | haskell-wip/datacon-eta.tar.gz |
Eta-expand remaining ValArgs in rebuildHsAppswip/datacon-eta
This patch expands the scope of hasFixedRuntimeRep_remainingValArgs:
instead of simply checking that eta-expansion is possible, actually
perform the eta-expansion then and there.
Changes:
1. hasFixedRuntimeRep_remainingValArgs renamed to tcRemainingValArgs.
2. tcRemainingValArgs is now called at the end of tcApp within
rebuildHsApps; this fills a hole as the logic in the implementation
of quick-look impredicativity (in quickLookArg1/tcEValArg) mirrors
in some important aspects the implementation in tcApp.
3. tcRemainingValArgs now performs eta-expansion (instead of only
checking whether eta expansion is possible). In particular, it
eta-expands data constructors up to their arity, allowing us to
remove the problematic implementation of dsConLike which introduced
representation-polymorphic lambdas.
Consequences:
A. rebuildHsApps is now monadic, as necessitated by (2)+(3)
B. Introduce WpHsLet, a wrapper that creates a let binding.
This is because we might need to let-bind existing value
arguments when eta-expanding, to avoid loss of sharing.
We rename the existing WpLet to WpEvLet, being more specific
about its nature.
Some Data and Outputable instances had to be moved to avoid
recursive imports now HsWrapper, through WpHsLet, mentions HsExpr.
C. We drop stupid-theta dictionaries in the wrapper for the data
constructor, which is the only other sensible place for this logic
to go now that we got rid of dsConLike.
For the moment, the FixedRuntimeRep check in tcRemainingValArgs
is kept as a syntactic check, as a full on PHASE 2 check doesn't jibe
well with the rest of the compiler, which doesn't look at application
chains in a single go.
Fixes #21346.
Diffstat (limited to 'compiler/GHC/Tc/Utils/Zonk.hs')
-rw-r--r-- | compiler/GHC/Tc/Utils/Zonk.hs | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/compiler/GHC/Tc/Utils/Zonk.hs b/compiler/GHC/Tc/Utils/Zonk.hs index 2180a113da..8a208b1714 100644 --- a/compiler/GHC/Tc/Utils/Zonk.hs +++ b/compiler/GHC/Tc/Utils/Zonk.hs @@ -891,12 +891,12 @@ zonkExpr env (XExpr (WrapExpr (HsWrap co_fn expr))) zonkExpr env (XExpr (ExpansionExpr (HsExpanded a b))) = XExpr . ExpansionExpr . HsExpanded a <$> zonkExpr env b -zonkExpr env (XExpr (ConLikeTc con tvs tys)) - = XExpr . ConLikeTc con tvs <$> mapM zonk_scale tys +zonkExpr env (XExpr (ConLikeTc con arg_tys)) + = XExpr . ConLikeTc con <$> mapM zonk_scale arg_tys where zonk_scale (Scaled m ty) = Scaled <$> zonkTcTypeToTypeX env m <*> pure ty - -- Only the multiplicity can contain unification variables - -- The tvs come straight from the data-con, and so are strictly redundant + -- Only the multiplicities can contain unification variables; + -- the types come straight from the data constructor. -- See Wrinkles of Note [Typechecking data constructors] in GHC.Tc.Gen.Head zonkExpr _ expr = pprPanic "zonkExpr" (ppr expr) @@ -1037,8 +1037,14 @@ zonkCoFn env (WpTyLam tv) = assert (isImmutableTyVar tv) $ ; return (env', WpTyLam tv') } zonkCoFn env (WpTyApp ty) = do { ty' <- zonkTcTypeToTypeX env ty ; return (env, WpTyApp ty') } -zonkCoFn env (WpLet bs) = do { (env1, bs') <- zonkTcEvBinds env bs - ; return (env1, WpLet bs') } +zonkCoFn env (WpEvLet bs) = do { (env1, bs') <- zonkTcEvBinds env bs + ; return (env1, WpEvLet bs') } +zonkCoFn env (WpHsLet id rhs) = do { rhs' <- zonkExpr env rhs + -- NB: important to zonk RHS first, so that + -- the 'Id' has the most up-to-date type. + ; id' <- zonkId id + ; let env' = extendIdZonkEnv env id' + ; return (env', WpHsLet id' rhs') } zonkCoFn env (WpMultCoercion co) = do { co' <- zonkCoToCo env co ; return (env, WpMultCoercion co') } |