Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EXPERIMENT: Use transitive closure of tyvar substitutions #43

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rowanG077
Copy link
Member

First of all this definitely isn't mergeable as is. It fixes #42 but if this is actually the solution it should go into ghc-tcplugins-extra. I have some suspicion there is a very good reason why this isn't already done as it seems too simple to not always have been done like this.

Please advice @christiaanb @martijnbastiaan

use transitive closure of type var substitutions
@christiaanb
Copy link
Member

A lot of this might not be needed any longer from ghc 9.4 onwards, since all constraints are unflattened then. Could try the test case on the 9.4.1 PR: #41

@rowanG077
Copy link
Member Author

rowanG077 commented Aug 21, 2022

@christiaanb Unfortunately the test also fails with GHC 9.4.1 on the branch you linked.

This the relevant type checker trace fragment:

tcPluginSolve start ghc-typelits-knownnat
  given   = [[G] $d~_a3Ep {0}:: b_a3Ea[sk:1]
                                ~ b_a3Ea[sk:1] (CDictCan),
             [G] $dKnownNat_a3Eg {0}:: KnownNat a_a3E9[sk:1] (CDictCan),
             [G] co_a3Eo {1}:: (2 ^ a_a3E9[sk:1])
                               ghc-prim:GHC.Prim.~# b_a3Ea[sk:1] (CEqCan)]
  wanted  = [[W] $dKnownNat_a3Er {0}:: KnownNat
                                         b_a3Ea[sk:1] (CDictCan)]
kn_wanteds
  [([W] $dKnownNat_a3Er {0}:: KnownNat b_a3Ea[sk:1] (CDictCan),
    KnownNat,
    b_a3Ea[sk:1],
    Outputable 
    b_a3Ea[sk:1])]
given_map
  [([W] $dKnownNat_a3Er {0}:: KnownNat b_a3Ea[sk:1] (CDictCan),
    KnownNat,
    b_a3Ea[sk:1],
    Outputable 
    b_a3Ea[sk:1])]
tcPluginSolveResult ghc-typelits-knownnat
  solved = []
  bad    = []
  new    = []

It doesn't include a flattening skolem anymore compared to GHC 9.0.2 so it's a little better. But it would still require manual "unflattening" (if you can call it that, there are no longer any fsk).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Intermediate type variable stops derivation of KnownNat constraint
2 participants