[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 <mnguyen1@brynmawr.edu> Date: Tue Dec 18 11:52:26 2018 -0500 Visible kind application Summary: This patch implements visible kind application (GHC Proposal 15/#12045), as well as #15360 and #15362. It also refactors unnamed wildcard handling, and requires that type equations in type families in Template Haskell be written with full type on lhs. PartialTypeSignatures are on and warnings are off automatically with visible kind application, just like in term-level. There are a few remaining issues with this patch, as documented in ticket #16082. Includes a submodule update for Haddock. Test Plan: Tests T12045a/b/c/TH1/TH2, T15362, T15592a Reviewers: simonpj, goldfire, bgamari, alanz, RyanGlScott, Iceland_jack Subscribers: ningning, Iceland_jack, RyanGlScott, int-index, rwbarton, mpickering, carter GHC Trac Issues: `#12045`, `#15362`, `#15592`, `#15788`, `#15793`, `#15795`, `#15797`, `#15799`, `#15801`, `#15807`, `#15816` Differential Revision: https://phabricator.haskell.org/D5229 }}} But it's unclear to me if this issue is actually fixed, based on the discussion in comment:3 and comment:4. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15799#comment:6> 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 Richard Eisenberg <rae@…>): In [changeset:"17bd163566153babbf51adaff8397f948ae363ca/ghc" 17bd1635/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="17bd163566153babbf51adaff8397f948ae363ca" Visible kind application Summary: This patch implements visible kind application (GHC Proposal 15/#12045), as well as #15360 and #15362. It also refactors unnamed wildcard handling, and requires that type equations in type families in Template Haskell be written with full type on lhs. PartialTypeSignatures are on and warnings are off automatically with visible kind application, just like in term-level. There are a few remaining issues with this patch, as documented in ticket #16082. Includes a submodule update for Haddock. Test Plan: Tests T12045a/b/c/TH1/TH2, T15362, T15592a Reviewers: simonpj, goldfire, bgamari, alanz, RyanGlScott, Iceland_jack Subscribers: ningning, Iceland_jack, RyanGlScott, int-index, rwbarton, mpickering, carter GHC Trac Issues: `#12045`, `#15362`, `#15592`, `#15788`, `#15793`, `#15795`, `#15797`, `#15799`, `#15801`, `#15807`, `#15816` Differential Revision: https://phabricator.haskell.org/D5229 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15799#comment:7> 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 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 <simonpj@…>): In [changeset:"682783828275cca5fd8bf5be5b52054c75e0e22c/ghc" 6827838/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="682783828275cca5fd8bf5be5b52054c75e0e22c" Make a smart mkAppTyM This patch finally delivers on Trac #15952. Specifically * Completely remove Note [The tcType invariant], along with its complicated consequences (IT1-IT6). * Replace Note [The well-kinded type invariant] with: Note [The Purely Kinded Type Invariant (PKTI)] * Instead, establish the (PKTI) in TcHsType.tcInferApps, by using a new function mkAppTyM when building a type application. See Note [mkAppTyM]. * As a result we can remove the delicate mkNakedXX functions entirely. Specifically, mkNakedCastTy retained lots of extremly delicate Refl coercions which just cluttered everything up, and(worse) were very vulnerable to being silently eliminated by (say) substTy. This led to a succession of bug reports. The result is noticeably simpler to explain, simpler to code, and Richard and I are much more confident that it is correct. It does not actually fix any bugs, but it brings us closer. E.g. I hoped it'd fix #15918 and #15799, but it doesn't quite do so. However, it makes it much easier to fix. I also did a raft of other minor refactorings: * Use tcTypeKind consistently in the type checker * Rename tcInstTyBinders to tcInvisibleTyBinders, and refactor it a bit * Refactor tcEqType, pickyEqType, tcEqTypeVis Simpler, probably more efficient. * Make zonkTcType zonk TcTyCons, at least if they have any free unification variables -- see zonk_tc_tycon in TcMType.zonkTcTypeMapper. Not zonking these TcTyCons was actually a bug before. * Simplify try_to_reduce_no_cache in TcFlatten (a lot) * Combine checkExpectedKind and checkExpectedKindX. And then combine the invisible-binder instantation code Much simpler now. * Fix a little bug in TcMType.skolemiseQuantifiedTyVar. I'm not sure how I came across this originally. * Fix a little bug in TyCoRep.isUnliftedRuntimeRep (the ASSERT was over-zealous). Again I'm not certain how I encountered this. * Add a missing solveLocalEqualities in TcHsType.tcHsPartialSigType. I came across this when trying to get level numbers right. }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15799#comment:11> 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 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