Skip to content

Draft: Eta-expand remaining ValArgs in rebuildHsApps

sheaf requested to merge wip/datacon-eta into master

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:

  • 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 existing WpLet to WpEvLet, being more specific about its nature. Some Data and Outputable instances had to be moved to avoid recursive imports now that HsWrapper, through WpHsLet, mentions HsExpr.
  • 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.

Edited by sheaf

Merge request reports