Do not emit prior emitted KnownNat constraints#122
Conversation
christiaanb
left a comment
There was a problem hiding this comment.
See my comment here clash-lang/ghc-typelits-knownnat#68 (comment) :
The reason I’m worried about keeping a simple set of types is that:
- Variables are only unique within their scope, and
- Plugin state is module-wide
So you might have two distinct case alternative (GADT pattern match) that bring a type variable in scope which are themselves not distinct. So with a simple set could end up in a situation where you emit a wanted constraint in one branch A, but then not emit it in branch B, even though it would be required for soundness.
Perhaps we need to maintain a set of
- Location (perhaps https://hackage-content.haskell.org/package/ghc-9.14.1/docs/GHC-Tc-Types-CtLoc.html#v:getCtLocEnvLoc) of the constraint that is requiring us to generate that KnownNat constraint
- Whether we already emitted a KnownNat constraint for that location.
That way we can distinguish scopes.
4d1ddc1 to
d58efc9
Compare
|
I have been trying to get the plugin to allow erroneous programs to be accepted with the simple |
dacfe1f to
a03b716
Compare
of the same KnownNat multiple times, potentially leading to loops.
a03b716 to
a893232
Compare
|
@sheaf I'm very curious what you think about this approach? |
|
My opinion is that using an As @christiaanb explained, the design of Unfortunately I don't have convincing reproducers to provide right now, but certainly something which involves only stuck type families and literals (with no variables), with various pieces of evidence learned in GADT pattern matches, seems like an approach to cause issues. It would be worth looking at the |
|
I think a more typical approach would be to use |
|
Thanks you for your reply! I see, I do agree that it's risky. I'd hoped That would be mitigated by using the full I will investigate a bit deeper if I can think of a different approach. |
|
The only way I can see this being fixed without the There is a similar idea inside GHC itself with The disadvantage is of course this is a GHC change, so only future GHC versions benefit from the fix. But it's a pretty generic way to do inter-plugin things. Of course a question is whether GHC devs think this is even a good/feasible idea. |
|
In c84e911 I have implement this There are GHC test failures, but those fail for me locally on master as well. I will try to see what the GHC devs think about it soonish. |
Implemented by maintaining a set of prior emitted
KnownNatconstraints.Fixes clash-lang/ghc-typelits-knownnat#68