Draft: Eta-expand remaining ValArgs in rebuildHsApps
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:
-
hasFixedRuntimeRep_remainingValArgs
renamed totcRemainingValArgs
. -
tcRemainingValArgs
is now called at the end oftcApp
withinrebuildHsApps
; this fills a hole as the logic in the implementation of quick-look impredicativity (inquickLookArg1
/tcEValArg
) mirrors in some important aspects the implementation intcApp
. -
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 ofdsConLike
which introduced representation-polymorphic lambdas.
Consequences:
-
rebuildHsApps
is now monadic, as necessitated by (2)+(3) - 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 existingWpLet
toWpEvLet
, being more specific about its nature. SomeData
andOutputable
instances had to be moved to avoid recursive imports now thatHsWrapper
, throughWpHsLet
, mentionsHsExpr
. - 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; it would be better to sort out #21683 first.