[GHC] #15320: Save the types in the typechecked syntax tree

#15320: Save the types in the typechecked syntax tree -------------------------------------+------------------------------------- Reporter: nboldi | Owner: (none) Type: feature | Status: new request | Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 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: -------------------------------------+------------------------------------- When working on development tools that use the GHC API as a backend, it is useful to have information on the types (or kinds) of the elements of the syntax tree (expressions, patterns, types). I found that the lack of this semantic information is limiting in some cases of refactoring transformations (for example to generate the type signature or extract a subexpression to a binding with type signature), and is necessary for tools that try to fix common programmer errors. But there should be other kind of tools that this little change may help. The type is currently saved for some expressions and most patterns but it would be useful if it would be available uniformly. It could be implemented nicely by adding type information to the `X* GhcTc` type families. I plan to implement these changes, I'm just asking the opinion of the developers about a change in this direction. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15320 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15320: Save the types in the typechecked syntax tree -------------------------------------+------------------------------------- Reporter: nboldi | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 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 mpickering): One way to get the type of an expression is to desugar it using `dsExpr` and then using `exprType`. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15320#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15320: Save the types in the typechecked syntax tree -------------------------------------+------------------------------------- Reporter: nboldi | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 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 simonpj): Moreover, the post-typechecked tree is ''already'' annotated with enough type information to be able to get its type easily. We just need someone to write `hsExprType :: HsExpr GhcTc -> Type`. It should not be difficult to do this. We already have its near cousin `hsPatType :: Pat GhcTc -> Type`. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15320#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15320: Save the types in the typechecked syntax tree -------------------------------------+------------------------------------- Reporter: nboldi | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 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 goldfire): comment:1 is true, but I can't imagine it's all that difficult to get the type from a `HsExpr GhcTc` directly. I don't think we have that function currently, but I think `hsExprType :: HsExpr GhcTc -> Type` should be quite doable. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15320#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15320: Save the types in the typechecked syntax tree -------------------------------------+------------------------------------- Reporter: nboldi | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 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 nboldi): I'm concerned that reconstructing the types of multiple subexpressions/subpatterns takes a lot of calculation time. In my opinion, it would be better to save the types where we have them. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15320#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15320: Save the types in the typechecked syntax tree -------------------------------------+------------------------------------- Reporter: nboldi | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 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 goldfire): But GHC itself has no need for such information, so it seems that doing this would necessarily slow down every compilation... so I'm worried that everyone will have to pay the cost of this feature. On the other hand, you could define a new pass (an alternative to `GhcTc`) that adds the type information and then calculate all the types once, when you need them, but never again. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15320#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15320: Save the types in the typechecked syntax tree -------------------------------------+------------------------------------- Reporter: nboldi | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 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 simonpj): Let's do the `hsExprType` route first. We can always memoise this function in the data structure later -- but I agree with Richard that doing so seems to impose a tax on all users willy-nilly, which sounds unattractive. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15320#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15320: Save the types in the typechecked syntax tree -------------------------------------+------------------------------------- Reporter: nboldi | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 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 nboldi): Ok, I will try to go for `hsExprType :: HsExpr GhcTc -> Type` and `hsTypeKind :: HsType GhcTc -> Kind`. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15320#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15320: Save the types in the typechecked syntax tree -------------------------------------+------------------------------------- Reporter: nboldi | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 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 goldfire): You'll have a very hard time with the latter: GHC never produces `HsType GhcTc`s. Instead, the kind-checker just produces `TcType`s, which are in the Core AST, not the Haskell one. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15320#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15320: Save the types in the typechecked syntax tree -------------------------------------+------------------------------------- Reporter: nboldi | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: 8.10.1 Component: Compiler | Version: 8.4.3 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 alanz): * cc: alanz (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15320#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC