[GHC] #11785: Kinds should be treated like types in TcSplice
#11785: Kinds should be treated like types in TcSplice -------------------------------------+------------------------------------- Reporter: goldfire | Owner: Type: task | Status: new Priority: normal | Milestone: Component: Template | Version: 8.1 Haskell | 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: -------------------------------------+------------------------------------- !TcSplice handles kinds differently than types. Now that they are the same, it's probably best to rewrite this code. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11785> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11785: Kinds should be treated like types in TcSplice -------------------------------------+------------------------------------- Reporter: goldfire | Owner: Type: task | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 8.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: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * cc: RyanGlScott (added) -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11785#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11785: Kinds should be treated like types in TcSplice -------------------------------------+------------------------------------- Reporter: goldfire | Owner: (none) Type: task | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 8.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 RyanGlScott): Another place we should unify the treatment of `Type`s and `Kind`s is `DsMeta`. We have both `repLTy` and `repLKind`, but the latter covers far fewer things than the former, which has led to bugs like #13781. Sadly, accomplishing this requires more work than you'd believe, since `repLTy` returns a `TypeQ`, whereas `repLKind` returns a pure `Kind`. In other words, we'd have to go through and purify `repLTy`, as well as every function it calls which is also monadic (see https://phabricator.haskell.org/D3627#103117). -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11785#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11785: Kinds should be treated like types in TcSplice -------------------------------------+------------------------------------- Reporter: goldfire | Owner: (none) Type: task | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 8.1 Resolution: | Keywords: TypeInType Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by goldfire): * keywords: => TypeInType -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11785#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11785: Merge types and kinds in Template Haskell -------------------------------------+------------------------------------- Reporter: goldfire | Owner: (none) Type: task | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 8.1 Resolution: | Keywords: TypeInType 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 RyanGlScott): Actually, there's another way to go about this. Instead of making more things pure, we could make more things monadic. This can be accomplished with the following combinator: {{{#!hs bindCore :: DsM (Core (TH.Q a)) -> (Core a -> DsM (Core (TH.Q b))) -> DsM (Core (TH.Q b)) bindCore dsma f = do { cqa@(MkC qa) <- dsma ; loc <- getSrcSpanDs ; a_name <- newNameAt (mkVarOccFS (fsLit "a")) loc ; let [a_ty] = tcTyConAppArgs (exprType qa) ; let a_id = mkLocalId (localiseName a_name) a_ty ca = MkC (Var a_id) ; MkC qb <- f ca ; let [b_ty] = tcTyConAppArgs (exprType qb) ; repBindQ a_ty b_ty cqa (MkC (Lam a_id qb)) } }}} With `bindCore`, we can retrofit existing uses of `repLKind` with `repLTy`. Here's one example: {{{#!diff diff --git a/compiler/deSugar/DsMeta.hs b/compiler/deSugar/DsMeta.hs index c679981..8acc6eb 100644 --- a/compiler/deSugar/DsMeta.hs +++ b/compiler/deSugar/DsMeta.hs @@ -1043,8 +1044,9 @@ repTy (HsEqTy t1 t2) = do repTapps eq [t1', t2'] repTy (HsKindSig t k) = do t1 <- repLTy t - k1 <- repLKind k - repTSig t1 k1 + bindCore (repLTy k) $ repTSig t1 + -- k1 <- repLKind k + -- repTSig t1 k1 repTy (HsSpliceTy splice _) = repSplice splice repTy (HsExplicitListTy _ _ tys) = do tys1 <- repLTys tys }}} It's somewhat unsavory, but it prevents us from having to change a truckload of combinators in `Language.Haskell.TH.Lib` to take `KindQ` as an argument instead of `Kind`. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11785#comment:4> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11785: Merge types and kinds in Template Haskell -------------------------------------+------------------------------------- Reporter: goldfire | Owner: (none) Type: task | Status: patch Priority: normal | Milestone: Component: Template Haskell | Version: 8.1 Resolution: | Keywords: TypeInType Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3751 Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * status: new => patch * differential: => Phab:D3751 Comment: Phab:D3751 addresses the `DsMeta` portion of this ticket. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11785#comment:5> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11785: Merge types and kinds in Template Haskell -------------------------------------+------------------------------------- Reporter: goldfire | Owner: (none) Type: task | Status: patch Priority: normal | Milestone: Component: Template Haskell | Version: 8.1 Resolution: | Keywords: TypeInType Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3751 Wiki Page: | -------------------------------------+------------------------------------- Comment (by Ryan Scott <ryan.gl.scott@…>): In [changeset:"b3b564fbc0ceb06e6a880289935449fda7d33f31/ghc" b3b564fb/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="b3b564fbc0ceb06e6a880289935449fda7d33f31" Merge types and kinds in DsMeta Summary: Types and kinds are now the same in GHC... well, except in the code that involves Template Haskell, where types and kinds are given separate treatment. This aims to unify that treatment in the `DsMeta` module. The gist of this patch is replacing all uses of `repLKind` with `repLTy`. This is isn't quite as simple as one might imagine, since `repLTy` returns a `Core (Q Type)` (a monadic expression), whereas `repLKind` returns a `Core Kind` (a pure expression). This causes many awkward impedance mismatches. One option would be to change every combinator in `Language.Haskell.TH.Lib` to take `KindQ` as an argument instead of `Kind`. But this would be a breaking change of colossal proportions. Instead, this patch takes a somewhat different approach. This migrates the existing `Language.Haskell.TH.Lib` module to `Language.Haskell.TH.Lib.Internal`, and changes all `Kind`-related combinators in `Language.Haskell.TH.Lib.Internal` to live in `Q`. The new `Language.Haskell.TH.Lib` module then re-exports most of `Language.Haskell.TH.Lib.Internal` with the exception of the `Kind`-related combinators, for which it redefines them to be their current definitions (which don't live in `Q`). This allows us to retain backwards compatibility with previous `template-haskell` releases, but more importantly, it allows GHC to make as many changes to the `Internal` code as it wants for its purposes without fear of disrupting the public API. This solves half of #11785 (the other half being `TcSplice`). Test Plan: ./validate Reviewers: goldfire, austin, bgamari Reviewed By: goldfire Subscribers: rwbarton, thomie GHC Trac Issues: #11785 Differential Revision: https://phabricator.haskell.org/D3751 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11785#comment:6> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11785: Merge types and kinds in Template Haskell -------------------------------------+------------------------------------- Reporter: goldfire | Owner: (none) Type: task | Status: patch Priority: normal | Milestone: Component: Template Haskell | Version: 8.1 Resolution: | Keywords: TypeInType Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3751 Wiki Page: | -------------------------------------+------------------------------------- Comment (by RyanGlScott): I looked into completing the `TcSplice` portion of this ticket recently. While making the change was simple enough, many reified kinds became a lot noisier due to the symptoms described in #14060. It'd be nice to fix #14060 first so as not to regress the quality of reified kinds. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11785#comment:7> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11785: Merge types and kinds in Template Haskell -------------------------------------+------------------------------------- Reporter: goldfire | Owner: (none) Type: task | Status: patch Priority: normal | Milestone: Component: Template Haskell | Version: 8.1 Resolution: | Keywords: TypeInType Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3751, Wiki Page: | Phab:D3854 -------------------------------------+------------------------------------- Changes (by RyanGlScott): * differential: Phab:D3751 => Phab:D3751, Phab:D3854 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11785#comment:8> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11785: Merge types and kinds in Template Haskell -------------------------------------+------------------------------------- Reporter: goldfire | Owner: (none) Type: task | Status: patch Priority: normal | Milestone: Component: Template Haskell | Version: 8.1 Resolution: | Keywords: TypeInType Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3751, Wiki Page: | Phab:D3854 -------------------------------------+------------------------------------- Comment (by Ryan Scott <ryan.gl.scott@…>): In [changeset:"c948b7865ace38d3d6912db0fc271aa7e9f70d2b/ghc" c948b786/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="c948b7865ace38d3d6912db0fc271aa7e9f70d2b" Fix #11785 by making reifyKind = reifyType Summary: This ties up the last loose end in Template Haskell's separate code paths for types and kinds. By making `reifyKind = reifyType` in `TcSplice`, types and kinds are now treated on equal terms in TH. This is itself a small patch, but most of the heavy lifting to make this possible was done in ad7b945257ea262e3f6f46daa4ff3e451aeeae0b. Test Plan: ./validate Reviewers: goldfire, austin, bgamari Reviewed By: goldfire Subscribers: rwbarton, thomie GHC Trac Issues: #11785 Differential Revision: https://phabricator.haskell.org/D3854 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11785#comment:9> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11785: Merge types and kinds in Template Haskell -------------------------------------+------------------------------------- Reporter: goldfire | Owner: (none) Type: task | Status: closed Priority: normal | Milestone: 8.4.1 Component: Template Haskell | Version: 8.1 Resolution: fixed | Keywords: TypeInType Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3751, Wiki Page: | Phab:D3854 -------------------------------------+------------------------------------- Changes (by RyanGlScott): * status: patch => closed * resolution: => fixed * milestone: => 8.4.1 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11785#comment:10> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC