Use HsOuterExplicit in instance sigs in deriving-generated code
Issue #18914 revealed that `GeneralizedNewtypeDeriving` would generate code that mentions unbound type variables, which is dangerously fragile. The problem (and fix) is described in the new `Wrinkle: Use HsOuterExplicit` in `Note [GND and QuantifiedConstraints]`. The gist of it: make sure to put the top-level `forall`s in `deriving`-generated instance signatures in an `HsOuterExplicit` to ensure that they scope over the bodies of methods correctly. A side effect of this process is that it will expand any type synonyms in the instance signature, which will surface any `forall`s that are hidden underneath type synonyms (such as in the test case for #18914). While I was in town, I also performed some maintenance on `NewHsTypeX`, which powers `GeneralizedNewtypeDeriving`: * I renamed `NewHsTypeX` to `HsCoreTy`, which more accurately describes its intended purpose (#15706). I also made `HsCoreTy` a type synonym instead of a newtype, as making it a distinct data type wasn't buying us much. * To make sure that mistakes similar to #18914 do not occur later, I added an additional validity check when renaming `HsCoreTy`s that complains if an `HsCoreTy`s contains an out-of-scope type variable. See the new `Note [Renaming HsCoreTys]` in `GHC.Rename.HsType` for the details. Fixes #15706. Fixes #18914. Bumps the `haddock` submodule.
Showing
- compiler/GHC/Hs/Type.hs 10 additions, 19 deletionscompiler/GHC/Hs/Type.hs
- compiler/GHC/Rename/HsType.hs 49 additions, 4 deletionscompiler/GHC/Rename/HsType.hs
- compiler/GHC/Tc/Deriv/Generate.hs 113 additions, 8 deletionscompiler/GHC/Tc/Deriv/Generate.hs
- compiler/GHC/Tc/Gen/HsType.hs 11 additions, 11 deletionscompiler/GHC/Tc/Gen/HsType.hs
- compiler/GHC/Tc/Gen/Sig.hs 1 addition, 1 deletioncompiler/GHC/Tc/Gen/Sig.hs
- compiler/GHC/Tc/TyCl/Instance.hs 1 addition, 1 deletioncompiler/GHC/Tc/TyCl/Instance.hs
- testsuite/tests/deriving/should_compile/T14578.stderr 13 additions, 10 deletionstestsuite/tests/deriving/should_compile/T14578.stderr
- testsuite/tests/deriving/should_compile/T18914.hs 12 additions, 0 deletionstestsuite/tests/deriving/should_compile/T18914.hs
- testsuite/tests/deriving/should_compile/all.T 1 addition, 0 deletionstestsuite/tests/deriving/should_compile/all.T
- utils/haddock 1 addition, 1 deletionutils/haddock
Loading
Please register or sign in to comment