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/Core/DataCon.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/Core/DataCon.hs')
-rw-r--r-- | compiler/GHC/Core/DataCon.hs | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/compiler/GHC/Core/DataCon.hs b/compiler/GHC/Core/DataCon.hs index 064cdc866f..7e18b471f3 100644 --- a/compiler/GHC/Core/DataCon.hs +++ b/compiler/GHC/Core/DataCon.hs @@ -250,6 +250,8 @@ in wrapper_reqd in GHC.Types.Id.Make.mkDataConRep. * Type variables may be permuted; see MkId Note [Data con wrappers and GADT syntax] +* Datatype contexts require dropping some dictionary arguments. + See Note [Instantiating stupid theta]. Note [The stupid context] ~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -1449,9 +1451,9 @@ dataConWrapperType :: DataCon -> Type -- mentions the family tycon, not the internal one. dataConWrapperType (MkData { dcUserTyVarBinders = user_tvbs, dcOtherTheta = theta, dcOrigArgTys = arg_tys, - dcOrigResTy = res_ty }) + dcOrigResTy = res_ty, dcStupidTheta = stupid }) = mkInvisForAllTys user_tvbs $ - mkInvisFunTysMany theta $ + mkInvisFunTysMany (stupid ++ theta) $ mkVisFunTys arg_tys $ res_ty |