[Git][ghc/ghc][wip/T23496-take-three] deriving: Typecheck associated family instances before instance bindings
Ryan Scott (@RyanGlScott)
gitlab at gitlab.haskell.org
Thu Aug 3 12:14:42 UTC 2023
Ryan Scott pushed to branch wip/T23496-take-three at Glasgow Haskell Compiler / GHC
Commits:
c7f165cb by Ryan Scott at 2023-08-03T08:14:10-04:00
deriving: Typecheck associated family instances before instance bindings
This is a significant overhaul of the way that `deriving` clauses and
standalone `deriving` declarations are typechecked. The highlights:
* Standalone `deriving` declarations are located in the new `DerivInstD`
constructor of `ClsInstDecl`, rather than as part of the `DerivD` constructor
of `HsGroup`. This move now means that standalone `deriving` instance
declarations are located alongside other forms of instance declarations,
which makes it easier to perform SCC analysis on them, as they are now part
of a `TyClGroup`.
* Now that everything `deriving`-related lives in `TyClGroup`s, we now
typecheck all of the associated type family instances that are generated from
`deriving` clauses/declarations first (in `tcTyClGroup`) _before_
typechecking any of the generated instance bindings, which happen after all
of the `TyClGroup`s have been processed. Doing so is essential to ensuring
that these associated type instances are in scope when needed to typecheck
other code in later `TyClGroup`s, such as the failing examples seen
in #23496. I have written an extensive `Note [Staging of deriving]` (previously
`Note [Staging of tcDeriving]`) to describe how everything works.
The second bullet point above involves quite a bit of churn in the expected
output of several test cases. This is for two reasons:
1. The order in which things are printed with `-ddump-deriv` is now different,
since `deriving`-related family instances are now generated earlier in the
typechecker.
2. If a test case errors out when typechecking a `deriving`-related family
instance, then GHC will stop there before printing any errors involving the
generated instance bindings. (Previously, both sorts of errors were printed
simultaneously.) As such, some expected-to-fail test cases do not print out
as many errors as before.
Fixes #23496.
- - - - -
30 changed files:
- compiler/GHC/Hs/Decls.hs
- compiler/GHC/Hs/Instances.hs
- compiler/GHC/Hs/Stats.hs
- compiler/GHC/Hs/Utils.hs
- compiler/GHC/HsToCore/Docs.hs
- compiler/GHC/HsToCore/Quote.hs
- compiler/GHC/Iface/Ext/Ast.hs
- compiler/GHC/Parser.y
- compiler/GHC/Rename/Module.hs
- compiler/GHC/Rename/Names.hs
- compiler/GHC/Tc/Deriv.hs
- compiler/GHC/Tc/Deriv/Utils.hs
- compiler/GHC/Tc/Module.hs
- compiler/GHC/Tc/TyCl.hs
- compiler/GHC/Tc/TyCl/Instance.hs
- compiler/GHC/Tc/TyCl/Instance.hs-boot
- compiler/GHC/Tc/Utils/Env.hs
- compiler/GHC/ThToHs.hs
- compiler/Language/Haskell/Syntax/Decls.hs
- compiler/Language/Haskell/Syntax/Extension.hs
- libraries/base/GHC/Generics/Internal.hs
- testsuite/tests/deriving/should_compile/T11068_aggressive.stderr
- testsuite/tests/deriving/should_compile/T14578.stderr
- testsuite/tests/deriving/should_compile/T14579.stderr
- testsuite/tests/deriving/should_compile/T14682.stderr
- testsuite/tests/deriving/should_compile/T17240.stderr
- + testsuite/tests/deriving/should_compile/T23496a.hs
- + testsuite/tests/deriving/should_compile/T23496b.hs
- testsuite/tests/deriving/should_compile/all.T
- testsuite/tests/deriving/should_compile/drv-empty-data.stderr
The diff was not included because it is too large.
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c7f165cb75d93ca2662ddf802cd4139a8a8a95af
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c7f165cb75d93ca2662ddf802cd4139a8a8a95af
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20230803/06f58fb9/attachment.html>
More information about the ghc-commits
mailing list