Guard newGiven calls against CoEvBindsVar to prevent GHC panic on ill-kinded types#133
Open
martijnbastiaan with Copilot wants to merge 2 commits into
Open
Guard newGiven calls against CoEvBindsVar to prevent GHC panic on ill-kinded types#133martijnbastiaan with Copilot wants to merge 2 commits into
martijnbastiaan with Copilot wants to merge 2 commits into
Conversation
…-kinded types When GHC encounters ill-kinded type expressions (e.g., BitSize Meta instead of BitSize (Meta a)), it may invoke the plugin with a CoEvBindsVar evidence bindings variable. Calling newGiven in this context causes a GHC panic because CoEvBindsVar does not support adding evidence bindings. This fix checks askEvBinds before calling newGiven in: - reduceGivens: skip reduction if CoEvBindsVar - simples (via unifyItemToGiven): skip given creation if CoEvBindsVar With this fix, ill-kinded expressions properly produce kind errors instead of panicking GHC. Agent-Logs-Url: https://github.com/clash-lang/ghc-typelits-natnormalise/sessions/e42555bb-d8c2-41bc-aaa1-17c8d5ccbc18 Co-authored-by: martijnbastiaan <5658854+martijnbastiaan@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix GHC panic on ill-kinded expressions
Guard newGiven calls against CoEvBindsVar to prevent GHC panic on ill-kinded types
Apr 23, 2026
martijnbastiaan
marked this pull request as ready for review
April 23, 2026 12:55
martijnbastiaan
requested review from
christiaanb and
rowanG077
and removed request for
martijnbastiaan
April 23, 2026 12:55
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When GHC encounters ill-kinded type expressions (e.g.,
BitSize Metainstead ofBitSize (Meta a)), it may invoke the plugin with aCoEvBindsVarevidence bindings variable. The plugin'snewGivencalls then triggersetEvBindonCoEvBindsVar, which panics unconditionally.Changes
reduceGivens: CheckaskEvBindsupfront; bail out returning original givens whenCoEvBindsVarsimplesinsimplifyNats: GuardunifyItemToGivencalls with the same check via newcanCreateGivenshelpercanCreateGivens: New helper that returnsFalsewhen evidence bindings variable isCoEvBindsVarTcEvidence as GHC.Tc.Types.Evidencefor GHC < 9.0 compatibility