diff options
Diffstat (limited to 'compiler/GHC')
-rw-r--r-- | compiler/GHC/Builtin/Names.hs | 36 | ||||
-rw-r--r-- | compiler/GHC/Runtime/Eval.hs | 4 | ||||
-rw-r--r-- | compiler/GHC/Tc/Errors.hs | 25 |
3 files changed, 37 insertions, 28 deletions
diff --git a/compiler/GHC/Builtin/Names.hs b/compiler/GHC/Builtin/Names.hs index b7f54060b9..364d7a913d 100644 --- a/compiler/GHC/Builtin/Names.hs +++ b/compiler/GHC/Builtin/Names.hs @@ -2794,17 +2794,41 @@ interactiveClassKeys = map getUnique interactiveClassNames * * ************************************************************************ -GHCi's :info command will usually filter out instances mentioning types whose -names are not in scope. GHCi makes an exception for some commonly used names, -such as Data.Kind.Type, which may not actually be in scope but should be -treated as though they were in scope. The list in the definition of -pretendNameIsInScope below contains these commonly used names. +Note [pretendNameIsInScope] +~~~~~~~~~~~~~~~~~~~~~~~~~~~ +In general, we filter out instances that mention types whose names are +not in scope. However, in the situations listed below, we make an exception +for some commonly used names, such as Data.Kind.Type, which may not actually +be in scope but should be treated as though they were in scope. +This includes built-in names, as well as a few extra names such as +'Type', 'TYPE', 'BoxedRep', etc. +Situations in which we apply this special logic: + + - GHCi's :info command, see GHC.Runtime.Eval.getInfo. + This fixes #1581. + + - When reporting instance overlap errors. Not doing so could mean + that we would omit instances for typeclasses like + + type Cls :: k -> Constraint + class Cls a + + because BoxedRep/Lifted were not in scope. + See GHC.Tc.Errors.pprPotentials. + This fixes one of the issues reported in #20465. -} +-- | Should this name be considered in-scope, even though it technically isn't? +-- +-- This ensures that we don't filter out information because, e.g., +-- Data.Kind.Type isn't imported. +-- +-- See Note [pretendNameIsInScope]. pretendNameIsInScope :: Name -> Bool pretendNameIsInScope n - = any (n `hasKey`) + = isBuiltInSyntax n + || any (n `hasKey`) [ liftedTypeKindTyConKey, unliftedTypeKindTyConKey , liftedDataConKey, unliftedDataConKey , tYPETyConKey diff --git a/compiler/GHC/Runtime/Eval.hs b/compiler/GHC/Runtime/Eval.hs index e28b2daeba..bceb9a4159 100644 --- a/compiler/GHC/Runtime/Eval.hs +++ b/compiler/GHC/Runtime/Eval.hs @@ -81,7 +81,6 @@ import GHC.Tc.Types.Constraint import GHC.Tc.Types.Origin import GHC.Builtin.Names ( toDynName, pretendNameIsInScope ) -import GHC.Builtin.Types ( isCTupleTyConName ) import GHC.Data.Maybe import GHC.Data.FastString @@ -873,8 +872,7 @@ getInfo allInfo name ok n | n == name = True -- The one we looked for in the first place! | pretendNameIsInScope n = True - | isBuiltInSyntax n = True - | isCTupleTyConName n = True + -- See Note [pretendNameIsInScope] in GHC.Builtin.Names | isExternalName n = isJust (lookupGRE_Name rdr_env n) | otherwise = True diff --git a/compiler/GHC/Tc/Errors.hs b/compiler/GHC/Tc/Errors.hs index 51ab0fca2a..e420bd1c23 100644 --- a/compiler/GHC/Tc/Errors.hs +++ b/compiler/GHC/Tc/Errors.hs @@ -50,7 +50,7 @@ import GHC.Types.Error import GHC.Rename.Unbound ( unknownNameSuggestions, WhatLooking(..) ) import GHC.Unit.Module import GHC.Hs.Binds ( PatSynBind(..) ) -import GHC.Builtin.Names ( typeableClassName ) +import GHC.Builtin.Names ( typeableClassName, pretendNameIsInScope ) import qualified GHC.LanguageExtensions as LangExt import GHC.Core.Predicate @@ -58,7 +58,7 @@ import GHC.Core.Type import GHC.Core.Coercion import GHC.Core.TyCo.Rep import GHC.Core.TyCo.Ppr ( pprTyVars, pprWithExplicitKindsWhen, pprSourceTyCon, pprWithTYPE ) -import GHC.Core.Unify ( tcMatchTys, flattenTys ) +import GHC.Core.Unify ( tcMatchTys ) import GHC.Core.InstEnv import GHC.Core.TyCon import GHC.Core.Class @@ -2420,8 +2420,7 @@ mkDictErr ctxt cts && (null unifiers || all (not . isAmbiguousTyVar) (tyCoVarsOfCtList ct)) lookup_cls_inst inst_envs ct - -- Note [Flattening in error message generation] - = (ct, lookupInstEnv True inst_envs clas (flattenTys emptyInScopeSet tys)) + = (ct, lookupInstEnv True inst_envs clas tys) where (clas, tys) = getClassPredTys (ctPred ct) @@ -2862,8 +2861,8 @@ pprPotentials (PrintPotentialInstances show_potentials) sty herald insts orphNamesOfTypes (is_tys cls_inst) name_in_scope name - | isBuiltInSyntax name - = True -- E.g. (->) + | pretendNameIsInScope name + = True -- E.g. (->); see Note [pretendNameIsInScope] in GHC.Builtin.Names | Just mod <- nameModule_maybe name = qual_in_scope (qualName sty mod (nameOccName name)) | otherwise @@ -2897,7 +2896,7 @@ we want to give it a bit of structure. Here's the plan These are the ones most likely to be useful to the programmer. * Show at most n_show in-scope instances, - and summarise the rest ("plus 3 others") + and summarise the rest ("plus N others") * Summarise the not-in-scope instances ("plus 4 not in scope") @@ -2906,18 +2905,6 @@ we want to give it a bit of structure. Here's the plan -} {- -Note [Flattening in error message generation] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Consider (C (Maybe (F x))), where F is a type function, and we have -instances - C (Maybe Int) and C (Maybe a) -Since (F x) might turn into Int, this is an overlap situation, and -indeed the main solver will have refrained -from solving. But by the time we get to error message generation, we've -un-flattened the constraint. So we must *re*-flatten it before looking -up in the instance environment, lest we only report one matching -instance when in fact there are two. - Note [Kind arguments in error messages] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ It can be terribly confusing to get an error message like (#9171) |