summaryrefslogtreecommitdiff
path: root/compiler/GHC
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2019-09-20 16:50:29 -0400
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-10-17 22:01:38 -0400
commit59d7c9f45b034809516703b57c84e3dac1834578 (patch)
treee1caa111d009cd3524293c06b6538a30abfb420b /compiler/GHC
parentb02a9ea79dddd98f6bbb42e1652d7ea38db7d55e (diff)
downloadhaskell-59d7c9f45b034809516703b57c84e3dac1834578.tar.gz
Skip type family defaults with hs-boot and hsig files
Works around #17190, possible resolution for #17224. New design is is according to accepted [GHC Propoal 320]. Instances in signatures currently unconditionally opt into associated family defaults if no explicit instance is given. This is bad for two reasons: 1. It constrains possible instantiations to use the default, rather than possibly define the associated family differently. 2. It breaks compilation as type families are unsupported in signatures. This PR simply turns off the filling in of defaults in those cases. Additionally, it squelches a missing definition warning for hs-boot too that was only squelched for hsig before. The downsides are: 1. There is no way to opt into the default, other than copying its definition. 2. If we fixed type classes in signatures, and wanted instances to have to explicitly *out of* rather than into the default, that would now be a breaking change. The change that is most unambiguously goood is harmonizing the warning squelching between hs-boot or hsig. Maybe they should have the warning (opt out of default) maybe they shouldn't (opt in to default), but surely it should be the same for both. Add hs-boot version of a backpack test regarding class-specified defaults in instances that appear in an hs-boot file. The metrics increase is very slight and makes no sense --- at least no one has figured anything out after this languishing for a while, so I'm just going to accept it. Metric Increase: T10421a [GHC proposal 320]: https://github.com/ghc-proposals/ghc-proposals/pull/320
Diffstat (limited to 'compiler/GHC')
-rw-r--r--compiler/GHC/Tc/TyCl/Class.hs6
-rw-r--r--compiler/GHC/Tc/TyCl/Instance.hs15
2 files changed, 16 insertions, 5 deletions
diff --git a/compiler/GHC/Tc/TyCl/Class.hs b/compiler/GHC/Tc/TyCl/Class.hs
index 5fa26c2c57..baad1622c0 100644
--- a/compiler/GHC/Tc/TyCl/Class.hs
+++ b/compiler/GHC/Tc/TyCl/Class.hs
@@ -550,8 +550,10 @@ warnMissingAT name
= do { warn <- woptM Opt_WarnMissingMethods
; traceTc "warn" (ppr name <+> ppr warn)
; hsc_src <- fmap tcg_src getGblEnv
- -- Warn only if -Wmissing-methods AND not a signature
- ; warnTc (Reason Opt_WarnMissingMethods) (warn && hsc_src /= HsigFile)
+ -- hs-boot and signatures never need to provide complete "definitions"
+ -- of any sort, as they aren't really defining anything, but just
+ -- constraining items which are defined elsewhere.
+ ; warnTc (Reason Opt_WarnMissingMethods) (warn && hsc_src == HsSrcFile)
(text "No explicit" <+> text "associated type"
<+> text "or default declaration for"
<+> quotes (ppr name)) }
diff --git a/compiler/GHC/Tc/TyCl/Instance.hs b/compiler/GHC/Tc/TyCl/Instance.hs
index b0dfa80f90..4cc8a79e1e 100644
--- a/compiler/GHC/Tc/TyCl/Instance.hs
+++ b/compiler/GHC/Tc/TyCl/Instance.hs
@@ -512,9 +512,18 @@ tcClsInstDecl (L loc (ClsInstDecl { cid_poly_ty = hs_ty, cid_binds = binds
-- Check for missing associated types and build them
-- from their defaults (if available)
+ ; is_boot <- tcIsHsBootOrSig
+ ; let atItems = classATItems clas
; tf_insts2 <- mapM (tcATDefault loc mini_subst defined_ats)
- (classATItems clas)
-
+ (if is_boot then [] else atItems)
+ -- Don't default type family instances, but rather omit, in hsig/hs-boot.
+ -- Since hsig/hs-boot files are essentially large binders we want omission
+ -- of the definition to result in no restriction, rather than for example
+ -- attempting to "pattern match" with the invisible defaults and generate
+ -- equalities. Without further handling, this would just result in a panic
+ -- anyway.
+ -- See https://github.com/ghc-proposals/ghc-proposals/pull/320 for
+ -- additional discussion.
; return (df_stuff, tf_insts1 ++ concat tf_insts2) }
@@ -539,8 +548,8 @@ tcClsInstDecl (L loc (ClsInstDecl { cid_poly_ty = hs_ty, cid_binds = binds
all_insts = tyfam_insts ++ datafam_insts
-- In hs-boot files there should be no bindings
- ; is_boot <- tcIsHsBootOrSig
; let no_binds = isEmptyLHsBinds binds && null uprags
+ ; is_boot <- tcIsHsBootOrSig
; failIfTc (is_boot && not no_binds) badBootDeclErr
; return ( [inst_info], all_insts, deriv_infos ) }