[GHC] #15799: GHC panic (and warnings)

#15799: GHC panic (and warnings) -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.6.1 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- On the [https://phabricator.haskell.org/D5229 visible kind application] differential, {{{#!hs {-# Language CPP #-} {-# Language DataKinds #-} {-# Language RankNTypes #-} {-# Language PatternSynonyms #-} {-# Language TypeOperators #-} {-# Language PolyKinds #-} {-# Language GADTs #-} {-# Language TypeFamilies #-} {-# Language TypeApplications #-} {-# Language FlexibleContexts #-} {-# Language FlexibleInstances #-} {-# Language InstanceSigs #-} import qualified GHC.TypeLits as TypeLits import GHC.TypeLits (Nat, KnownNat) import Data.Kind data Op obj = Op obj type family UnOp (op_a :: Op obj) :: obj where UnOp ('Op obj) = obj class Ríki (obj :: Type) where type (-->) :: Op obj -> obj -> Type type (<--) :: obj -> Op obj -> Type unop :: forall (a :: obj) (b :: obj). (a <-- 'Op b) -> ('Op b --> a) data (<=) :: Op Nat -> Nat -> Type where LessThan :: (KnownNat (UnOp op_a), KnownNat b, UnOp op_a TypeLits.<= b) => (op_a <= b) newtype (>=) :: Nat -> Op Nat -> Type where Y :: (a <= b) -> (b >= a) instance Ríki Nat where type (-->) = (<=) type (<--) = (>=) unop :: (a >= b) -> (b <= a) unop GreaterThan = LessThan pattern GreaterThan :: () => (KnownNat (UnOp b), KnownNat a, UnOp b <= a) => a >= b pattern GreaterThan = Y LessThan }}} {{{ $ ghci -ignore-dot-ghci 573_bug.hs GHCi, version 8.7.20181017: http://www.haskell.org/ghc/ :? for help [1 of 1] Compiling Main ( 573_bug.hs, interpreted ) WARNING: file compiler/types/TyCoRep.hs, line 2567 in_scope InScope {b_a1Em a_a1En} tenv [a1Em :-> b_a1Em[sk:0], a1En :-> a_a1En[sk:0]] cenv [] tys [KnownNat (UnOp b_a1Em[sk:1]), KnownNat a_a1En[sk:1], (UnOp b_a1Em[sk:1] |> {co_a1HN}) <= a_a1En[sk:1]] cos [] needInScope [a1HN :-> co_a1HN] WARNING: file compiler/types/TyCoRep.hs, line 2567 in_scope InScope {b_a1Jo a_a1Jp} tenv [a1Em :-> b_a1Jo[tau:3], a1En :-> a_a1Jp[tau:3]] cenv [] tys [KnownNat (UnOp b_a1Em), KnownNat a_a1En, (UnOp b_a1Em |> {co_a1HN}) <= a_a1En] cos [] needInScope [a1HN :-> co_a1HN] ghc-stage2: panic! (the 'impossible' happened) (GHC version 8.7.20181017 for x86_64-unknown-linux): tcEvVarPred irred_a1Js (UnOp b_a1Jo[tau:3] |> {co_a1HN}) <= a_a1Jp[tau:3] Call stack: CallStack (from HasCallStack): callStackDoc, called at compiler/utils/Outputable.hs:1160:37 in ghc:Outputable pprPanic, called at compiler/typecheck/TcType.hs:1998:20 in ghc:TcType Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
}}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15799 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15799: GHC panic (and warnings) -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.6.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by Iceland_jack): This works again if you qualify `UnOp b TypeLits.<= a` in the pattern signature for `GreaterThan`, or remove it entirely -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15799#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15799: GHC panic (and warnings) -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.6.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #12045 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by goldfire): * cc: mnguyen (added) * related: => #12045 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15799#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15799: GHC panic (and warnings) -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.6.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #12045 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by goldfire): Urgh. I know what's going on. It has nothing to do with #12045, but perhaps changes there affected code paths in such a way that this surfaced. The problem is that we have a constraint `b <= a`. Note that `(<=) :: ty1 -> ty2 -> Type` -- that is, `b <= a` is ill-kinded as a constraint. So GHC processes it and dutifully wraps it up by casting by a coercion hole; we get `(b <= a) |> co`, where `co :: Type ~ Constraint`. Then, we zonk (with `zonkTcType`). The zonker uses `mapType` with `tcm_smart` set to `True`. This means that casts are reconstructed with `mkCastTy`, which, of course, does a reflexivity check. And, lo, the reflexivity check decides that `Type` and `Constraint` are equal and thus drops the cast. Later, we try to treat `b <= a` as an predicate, and GHC falls over when `isPredTy (b <= a)` returns `False`. What to do? My first instinct was to add a new setting to `tcm_smart`: sometimes we want to use raw constructors (in `nakedSubstMapper`), sometimes we want core smart constructors (in `zonkTcTypeToType`), and now sometimes we want type-checker smart constructors (newly discovered for `zonkTcType`). We'll also need a `mkTcCastTy` which is like `mkCastTy` but calls `isTcReflexiveCo` instead of `isReflexiveCo`, so that `Type` can be known to be distinct from `Constraint`. (Actually, `mkTcCastTy` can probably skip some of the steps in `mkCastTy`, as we know we'll get another crack at establishing invariants, etc., in `zonkTcTypeToType`.) This is a mess! So my second instinct was to post here for help. Help? Does anyone see a way out? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15799#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15799: GHC panic (and warnings) -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.6.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #12045 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by goldfire): Discussion this morning essentially agreed with my "first instinct" above. But with a new spin on things: The `tcm_smart` setting on `TyCoMapper` is really about what to do about `Refl` casts. Do we preserve them? Discard them? Or, in our new mode, discard some of them? Previously, the "dumb" mode meant to preserve all casts. This is important for `Note [The well- kinded type invariant]` (where we sometimes use reflexive casts to make a type's kind looked zonked even when the type is not yet zonked). The "smart" mode dropped all reflexive casts. Now, we want a third mode that drops all casts that look reflexive to the type checker. By elucidating what we really mean by "smart", having a third setting does not look so unusual, after all. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15799#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15799: GHC panic (and warnings) -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.6.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #12045 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): Trac #15918 is another example of the need for `mkTcCastTy`. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15799#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15799: GHC panic (and warnings)
-------------------------------------+-------------------------------------
Reporter: Iceland_jack | Owner: (none)
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 8.6.1
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
| typecheck/should_fail/T15799
Blocked By: | Blocking:
Related Tickets: #12045 | Differential Rev(s): Phab:D5229
Wiki Page: |
-------------------------------------+-------------------------------------
Changes (by RyanGlScott):
* testcase: => typecheck/should_fail/T15799
* differential: => Phab:D5229
Comment:
A test case for this was added in
[https://gitlab.haskell.org/ghc/ghc/commit/17bd163566153babbf51adaff8397f948a...
17bd163566153babbf51adaff8397f948ae363ca]:
{{{
Author: mynguyen

#15799: GHC panic (and warnings)
-------------------------------------+-------------------------------------
Reporter: Iceland_jack | Owner: (none)
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 8.6.1
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
| typecheck/should_fail/T15799
Blocked By: | Blocking:
Related Tickets: #12045 | Differential Rev(s): Phab:D5229
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Richard Eisenberg

#15799: GHC panic (and warnings) -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.6.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: | typecheck/should_fail/T15799 Blocked By: | Blocking: Related Tickets: #12045 | Differential Rev(s): Phab:D5229 Wiki Page: | -------------------------------------+------------------------------------- Comment (by goldfire): This looks like it will be fixed by #16185. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15799#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15799: GHC panic (and warnings) -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.6.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: | typecheck/should_fail/T15799 Blocked By: | Blocking: Related Tickets: #12045 | Differential Rev(s): Phab:D5229 Wiki Page: | -------------------------------------+------------------------------------- Comment (by RyanGlScott): #16185 was fixed in [https://gitlab.haskell.org/ghc/ghc/commit/6cce36f83aec33d33545e0ef2135894d22... 6cce36f83aec33d33545e0ef2135894d22dff5ca] (re: comment:8). Did that commit fix this ticket? Someone should check. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15799#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15799: GHC panic (and warnings) -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: 8.10.1 Component: Compiler | Version: 8.6.1 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: | typecheck/should_fail/T15799 Blocked By: | Blocking: Related Tickets: #12045 | Differential Rev(s): Phab:D5229 Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * status: new => closed * resolution: => fixed * milestone: => 8.10.1 Comment: Replying to [comment:9 RyanGlScott]:
Did that commit fix this ticket? Someone should check.
I checked. It is fixed. Luckily, a test case already exists, so I'm going to just close this ticket. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15799#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15799: GHC panic (and warnings)
-------------------------------------+-------------------------------------
Reporter: Iceland_jack | Owner: (none)
Type: bug | Status: closed
Priority: normal | Milestone: 8.10.1
Component: Compiler | Version: 8.6.1
Resolution: fixed | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
| typecheck/should_fail/T15799
Blocked By: | Blocking:
Related Tickets: #12045 | Differential Rev(s): Phab:D5229
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Simon Peyton Jones

#15799: GHC panic (and warnings) -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: 8.10.1 Component: Compiler | Version: 8.6.1 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: | typecheck/should_fail/T15799 Blocked By: | Blocking: Related Tickets: #12045 | Differential Rev(s): Phab:D5229 Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): Just to note: the underlying bug is not fixed, but it's asleep. See #15918 for more details -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15799#comment:12 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC