summaryrefslogtreecommitdiff
path: root/compiler/GHC/Tc/Errors.hs
diff options
context:
space:
mode:
authorAndrei Barbu <andrei@0xab.com>2021-08-25 03:20:51 -0400
committerAndrei Barbu <andrei@0xab.com>2021-10-08 19:45:29 -0400
commita76409c758d8c7bd837dcc6c0b58f8cce656b4f1 (patch)
tree95dde306e370fe296ef84efa959828e8ecdd1267 /compiler/GHC/Tc/Errors.hs
parent55a6377a5d55d6e6e93cf3d087f1e2d17fe7d3f3 (diff)
downloadhaskell-a76409c758d8c7bd837dcc6c0b58f8cce656b4f1.tar.gz
Add defaulting plugins.
Like the built-in type defaulting rules these plugins can propose candidates to resolve ambiguous type variables. Machine learning and other large APIs like those for game engines introduce new numeric types and other complex typed APIs. The built-in defaulting mechanism isn't powerful enough to resolve ambiguous types in these cases forcing users to specify minutia that they might not even know how to do. There is an example defaulting plugin linked in the documentation. Applications include defaulting the device a computation executes on, if a gradient should be computed for a tensor, or the size of a tensor. See https://github.com/ghc-proposals/ghc-proposals/pull/396 for details.
Diffstat (limited to 'compiler/GHC/Tc/Errors.hs')
-rw-r--r--compiler/GHC/Tc/Errors.hs19
1 files changed, 13 insertions, 6 deletions
diff --git a/compiler/GHC/Tc/Errors.hs b/compiler/GHC/Tc/Errors.hs
index e420bd1c23..f474c3383d 100644
--- a/compiler/GHC/Tc/Errors.hs
+++ b/compiler/GHC/Tc/Errors.hs
@@ -3151,19 +3151,26 @@ discardMsg = text "(Some bindings suppressed;" <+>
text "use -fmax-relevant-binds=N or -fno-max-relevant-binds)"
-----------------------
-warnDefaulting :: [Ct] -> Type -> TcM ()
-warnDefaulting wanteds default_ty
+warnDefaulting :: TcTyVar -> [Ct] -> Type -> TcM ()
+warnDefaulting the_tv wanteds default_ty
= do { warn_default <- woptM Opt_WarnTypeDefaults
; env0 <- tcInitTidyEnv
; let tidy_env = tidyFreeTyCoVars env0 $
tyCoVarsOfCtsList (listToBag wanteds)
tidy_wanteds = map (tidyCt tidy_env) wanteds
+ tidy_tv = lookupVarEnv (snd tidy_env) the_tv
(loc, ppr_wanteds) = pprWithArising tidy_wanteds
warn_msg =
- hang (hsep [ text "Defaulting the following"
- , text "constraint" <> plural tidy_wanteds
- , text "to type"
- , quotes (ppr default_ty) ])
+ hang (hsep $ [ text "Defaulting" ]
+ ++
+ (case tidy_tv of
+ Nothing -> []
+ Just tv -> [text "the type variable"
+ , quotes (ppr tv)])
+ ++
+ [ text "to type"
+ , quotes (ppr default_ty)
+ , text "in the following constraint" <> plural tidy_wanteds ])
2
ppr_wanteds
; let diag = TcRnUnknownMessage $