Hannes Siebenhandl pushed to branch wip/fendor/has-field-hie at Glasgow Haskell Compiler / GHC Commits: 760ff607 by fendor at 2026-12-01T11:40:40+01:00 Add additional details to evidence bindings Evidence bindings can be all sorts of things, such as type class evidence, a record selector or other builtin constructs such as `Typeable`. For some special evidence binding dependencies, we can include additional information for the user. For example, when we have a record selector, we can say from which type the record selector originates from. For `Typeable`, we include the type of the evidence dependency. During evidence dependency generation, we use a whitelist of which evidence terms are suitable as evidence dependencies that give the user usable source locations and transform them if needed. - - - - - 13 changed files: - compiler/GHC/Iface/Ext/Ast.hs - compiler/GHC/Iface/Ext/Types.hs - compiler/GHC/Iface/Ext/Utils.hs - + testsuite/tests/hiefile/should_run/HasCallStackIds.hs - + testsuite/tests/hiefile/should_run/HasCallStackIds.stdout - testsuite/tests/hiefile/should_run/HasFieldQueries.hs - testsuite/tests/hiefile/should_run/HasFieldQueries.stdout - + testsuite/tests/hiefile/should_run/HieTypeable.hs - + testsuite/tests/hiefile/should_run/HieTypeable.stdout - testsuite/tests/hiefile/should_run/NoFieldSelectorQueries.hs - testsuite/tests/hiefile/should_run/NoFieldSelectorQueries.stdout - testsuite/tests/hiefile/should_run/RecordDotTypes.stdout - testsuite/tests/hiefile/should_run/all.T Changes: ===================================== compiler/GHC/Iface/Ext/Ast.hs ===================================== @@ -21,7 +21,7 @@ import GHC.Core.Class ( className, classSCSelIds ) import GHC.Core.ConLike ( conLikeName ) import GHC.Core.DataCon ( dataConWrapperType ) import GHC.Core.Type ( Type, ForAllTyFlag(..) ) -import GHC.Core.TyCon ( TyCon, tyConClass_maybe ) +import GHC.Core.TyCon ( TyCon, tyConClass_maybe, tyConName ) import GHC.Core.InstEnv import GHC.Hs @@ -37,7 +37,7 @@ import GHC.Types.Name ( Name, nameSrcSpan, nameUnique, wiredInNameTy import GHC.Types.Name.Env ( NameEnv, emptyNameEnv, extendNameEnv, lookupNameEnv ) import GHC.Types.Name.Reader ( RecFieldInfo(..), WithUserRdr(..) ) import GHC.Types.SrcLoc -import GHC.Types.Var ( Id, Var, EvId, varName, varType, varUnique ) +import GHC.Types.Var ( Id, Var, varName, varType, varUnique ) import GHC.Types.Var.Env import GHC.Types.Var.FV @@ -680,21 +680,32 @@ instance ToHie (Context (Located Name)) where instance ToHie (Context (Located (WithUserRdr Name))) where toHie (C c (L l (WithUserRdr _ n))) = toHie $ C c (L l n) -hieEvIdsOfTerm :: EvTerm -> [EvId] --- Returns only EvIds satisfying relevantEvId -hieEvIdsOfTerm = runFVSelectiveList isId . evTermFVs +-- | Find the free variables of the evidence term. +-- +-- These need to be processed by 'mkEvBindDep_maybe' to filter +-- evidence variables irrelevant to the user and add better +-- evidence locations. +hieIdsOfTerm :: EvTerm -> [Id] +hieIdsOfTerm = runFVSelectiveList isId . evTermFVs + +-- | 'EvTerm' have a special case @Typeable@ evidence. +-- +-- Use it to provide better source locations. +builtinEvBindDeps :: EvTerm -> [EvBindDep] +builtinEvBindDeps (EvTypeable _ (EvTypeableTyCon tc _)) = [EvidenceTypeable (tyConName tc)] +builtinEvBindDeps _ = [] instance ToHie (EvBindContext (LocatedA TcEvBinds)) where toHie (EvBindContext sc sp (L span (EvBinds bs))) = concatMapM go $ bagToList bs where go evbind = do - let evDeps = hieEvIdsOfTerm $ eb_rhs evbind - depNames = EvBindDeps $ map varName evDeps + let evDeps = mapMaybe (\v -> (v,) <$> mkEvBindDep_maybe v) $ hieIdsOfTerm (eb_rhs evbind) + depNames = EvBindDeps (map snd evDeps ++ builtinEvBindDeps (eb_rhs evbind)) concatM $ [ toHie (C (EvidenceVarBind (EvLetBind depNames) (combineScopes sc (mkScope span)) sp) (L span $ eb_lhs evbind)) - , toHie $ map (C EvidenceVarUse . L span) $ evDeps + , toHie $ map (C EvidenceVarUse . L span . fst) evDeps ] toHie _ = pure [] @@ -710,7 +721,7 @@ instance ToHie (LocatedA HsWrapper) where toHie $ C (EvidenceVarBind EvWrapperBind (mkScope osp) (getRealSpanA osp)) $ L osp a (WpEvApp a) -> - concatMapM (toHie . C EvidenceVarUse . L osp) $ hieEvIdsOfTerm a + concatMapM (toHie . C EvidenceVarUse . L osp) $ filter (isJust . mkEvBindDep_maybe) $ hieIdsOfTerm a _ -> pure [] instance HiePass p => HasType (LocatedA (HsBind (GhcPass p))) where ===================================== compiler/GHC/Iface/Ext/Types.hs ===================================== @@ -11,37 +11,42 @@ module GHC.Iface.Ext.Types where import GHC.Prelude -import GHC.Settings.Config -import GHC.Utils.Binary import GHC.Data.FastString + +import GHC.Core.ConLike (ConLike (..)) +import GHC.Core.Predicate (isEvId) +import GHC.Core.TyCo.Rep (Type (..)) +import GHC.Core.TyCon (isClassTyCon, isFamilyTyCon, isTypeSynonymTyCon) +import GHC.Core.Type (Var (..), coreFullView, isFunTy) import GHC.Iface.Type -import GHC.Unit.Module ( Module ) +import GHC.Settings.Config +import GHC.Types.Avail +import GHC.Types.Id (Id, idDetails, isClassOpId, isLocalId, isRecordSelector) +import GHC.Types.Id.Info (IdDetails (..), recSelParentName) import GHC.Types.Name -import GHC.Utils.Outputable hiding ( (<>) ) import GHC.Types.SrcLoc -import GHC.Types.Avail -import qualified GHC.Utils.Outputable as O ( (<>) ) +import GHC.Types.TyThing (TyThing (..)) +import GHC.Types.Var (cmpForAllTyFlagExactly, isFUNArg, isTyVar) +import qualified GHC.Types.Var as Var +import GHC.Unit.Module (Module) +import GHC.Utils.Binary +import GHC.Utils.Outputable hiding ((<>)) +import qualified GHC.Utils.Outputable as O ((<>)) import GHC.Utils.Panic -import GHC.Core.ConLike ( ConLike(..) ) -import GHC.Core.TyCo.Rep ( Type(..) ) -import GHC.Core.Type ( coreFullView, isFunTy, Var (..) ) -import GHC.Core.TyCon ( isTypeSynonymTyCon, isClassTyCon, isFamilyTyCon ) -import GHC.Types.Id ( Id, isRecordSelector, isClassOpId ) -import GHC.Types.TyThing ( TyThing (..) ) -import GHC.Types.Var ( isTyVar, isFUNArg, cmpForAllTyFlagExactly ) +import Language.Haskell.Syntax.Module.Name + +import Control.Applicative ((<|>)) import qualified Data.Array as A +import Data.ByteString (ByteString) +import Data.Coerce (coerce) +import Data.Data (Data) +import Data.Function (on) import qualified Data.Map as M -import qualified Data.Set as S -import Data.ByteString ( ByteString ) -import Data.Data ( Data ) -import Data.Semigroup ( Semigroup(..) ) -import Data.Word ( Word8 ) -import Control.Applicative ( (<|>) ) -import Data.Coerce ( coerce ) -import Data.Function ( on ) +import Data.Semigroup (Semigroup (..)) import qualified Data.Semigroup as S -import Language.Haskell.Syntax.Module.Name +import qualified Data.Set as S +import Data.Word (Word8) type Span = RealSrcSpan @@ -618,17 +623,94 @@ instance Outputable EvVarSource where ppr (EvInstBind True cls) = text "bound due to a superclass of " <+> ppr cls ppr (EvLetBind deps) = text "bound by a let, depending on:" <+> ppr deps +-- | Evidence binding dependency with additional details. +data EvBindDep + = EvidenceVar Name + -- ^ Generic evidence bind dependency. + | EvidenceRecordField + -- ^ Evidence dependency on a record selector. + -- + -- This is for example generated with @-XOverloadedRecordDot@, where + -- the evidence includes a reference to which record selector is used + -- to implement @getField@. + Name + -- ^ 'Name' of the record selector + Name + -- ^ 'Name' of the parent type. + | EvidenceTypeable + -- ^ Typeable evidence dependency + Name + -- ^ Name of the type of 'Typeable' dependency. + +instance Outputable EvBindDep where + ppr = \ case + EvidenceVar n -> ppr n + EvidenceRecordField sel parent -> ppr sel <+> text "of record" <+> ppr parent + EvidenceTypeable ty -> text "Typeable" <+> ppr ty + +-- | Generate an 'EvBindDep' from an 'Id'. +-- +-- Only certain 'Id's are usable evidence binding dependencies. +-- The following 'Id's, we can do something useful with: +-- +-- * any 'isEvId': by definition, a usable evidence. +-- * Non-local ids are usually generated without any usable source spans. +-- * 'RecSelId': used for record dot syntax. +-- * 'DFunId': Dictionary function such as @$fShowList@ +-- * 'ClassOpId': if used as superclass selectors such as @$dEq = $p1Ord \@a $dOrd@ +mkEvBindDep_maybe :: Id -> Maybe EvBindDep +mkEvBindDep_maybe v = case idDetails v of + RecSelId{sel_tycon} -> Just $ EvidenceRecordField n (recSelParentName sel_tycon) + DFunId{} -> Just $ EvidenceVar n + ClassOpId{} | isEvId v -> Just $ EvidenceVar n + _ | isLocalId v, isEvId v -> Just $ EvidenceVar n + _ -> Nothing + where + n = Var.varName v + +evBindDepName :: EvBindDep -> Name +evBindDepName = \ case + EvidenceVar n -> n + EvidenceRecordField selector _record -> selector + EvidenceTypeable ty -> ty + +evBindDepHieName :: EvBindDep -> HieName +evBindDepHieName = toHieName . evBindDepName + +instance Binary EvBindDep where + put_ bh = \ case + EvidenceVar n -> do + putByte bh 0 + put_ bh n + EvidenceRecordField sel parent -> do + putByte bh 1 + put_ bh sel + put_ bh parent + EvidenceTypeable ty -> do + putByte bh 2 + put_ bh ty + + get bh = + getByte bh >>= \ case + 0 -> EvidenceVar <$> get bh + 1 -> EvidenceRecordField <$> get bh <*> get bh + 2 -> EvidenceTypeable <$> get bh + t -> fail $ "EvBindDep: Unknown tag: " ++ show t + -- | Eq/Ord instances compare on the converted HieName, -- as non-exported names may have different uniques after -- a roundtrip -newtype EvBindDeps = EvBindDeps { getEvBindDeps :: [Name] } +newtype EvBindDeps = EvBindDeps { getEvBindDeps :: [EvBindDep] } deriving Outputable +evBindDepsNames :: EvBindDeps -> [Name] +evBindDepsNames = map evBindDepName . getEvBindDeps + instance Eq EvBindDeps where - (==) = coerce ((==) `on` map toHieName) + (==) = coerce ((==) `on` map evBindDepHieName) instance Ord EvBindDeps where - compare = coerce (compare `on` map toHieName) + compare = coerce (compare `on` map evBindDepHieName) instance Binary EvBindDeps where put_ bh (EvBindDeps xs) = put_ bh xs ===================================== compiler/GHC/Iface/Ext/Utils.hs ===================================== @@ -145,7 +145,7 @@ getEvidenceTree refmap var = go emptyNameSet var det <- S.toList $ identInfo dets case det of EvidenceVarBind src@(EvLetBind (getEvBindDeps -> xs)) scp spn -> - pure $ Just ((src,scp,spn),mapMaybe (go $ extendNameSet seen var) xs) + pure $ Just ((src,scp,spn),mapMaybe (go (extendNameSet seen var) . evBindDepName) xs) EvidenceVarBind src scp spn -> pure $ Just ((src,scp,spn),[]) _ -> pure Nothing pure $ Tree.Node (EvidenceInfo var sp typ (Just evdet)) children @@ -390,7 +390,7 @@ definedInAsts asts n = case nameSrcSpan n of getEvidenceBindDeps :: ContextInfo -> [Name] getEvidenceBindDeps (EvidenceVarBind (EvLetBind xs) _ _) = - getEvBindDeps xs + evBindDepsNames xs getEvidenceBindDeps _ = [] isEvidenceBind :: ContextInfo -> Bool ===================================== testsuite/tests/hiefile/should_run/HasCallStackIds.hs ===================================== @@ -0,0 +1,27 @@ +{-# LANGUAGE DataKinds #-} +module Main where + +import TestUtils +import GHC.Stack +import GHC.TypeLits +import Data.Proxy + +callee :: HasCallStack => Int +callee = length (prettyCallStack callStack) + +caller :: HasCallStack => Int +caller = callee +-- ^ + +sym :: String +sym = symbolVal (Proxy :: Proxy "hello") +-- ^ + +points :: [(Int, Int)] +points = [(13,10), (17,7)] + +main :: IO () +main = do + (df, hf) <- readTestHie "HasCallStackIds.hie" + let refmap = generateReferencesMap $ getAsts $ hie_asts hf + mapM_ (explainEv df hf refmap) points ===================================== testsuite/tests/hiefile/should_run/HasCallStackIds.stdout ===================================== @@ -0,0 +1,38 @@ +========================== +At point (13,10), we found: +========================== +┌ +│ $dIP at HasCallStackIds.hs:13:1-15, of type: HasCallStack +│ is an evidence variable bound by a let, depending on: [$dIP] +│ with scope: LocalScope HasCallStackIds.hs:13:1-15 +│ bound at: HasCallStackIds.hs:13:1-15 +│ Defined at <no location info> +└ +| +`- ┌ + │ $dIP at HasCallStackIds.hs:13:1-15, of type: HasCallStack + │ is an evidence variable bound by a let, depending on: [$dIP] + │ with scope: LocalScope HasCallStackIds.hs:13:1-15 + │ bound at: HasCallStackIds.hs:13:1-15 + │ Defined at <no location info> + └ + | + `- ┌ + │ $dIP at HasCallStackIds.hs:13:1-15, of type: HasCallStack + │ is an evidence variable bound by a HsWrapper + │ with scope: LocalScope HasCallStackIds.hs:13:1-15 + │ bound at: HasCallStackIds.hs:13:1-15 + │ Defined at <no location info> + └ + +========================== +At point (17,7), we found: +========================== +┌ +│ $dKnownSymbol at HasCallStackIds.hs:1:1, of type: KnownSymbol "hello" +│ is an evidence variable bound by a let, depending on: [] +│ with scope: ModuleScope +│ +│ Defined at <no location info> +└ + ===================================== testsuite/tests/hiefile/should_run/HasFieldQueries.hs ===================================== @@ -3,8 +3,6 @@ module Main where import TestUtils import GHC.Records -import GHC.TypeLits -import Data.Tree data Thing = Thing {field1 :: Char, field2 :: Bool} deriving (Show, Eq) @@ -44,17 +42,17 @@ prefixNested x = (.nested1.field1) x points = - [ (13,17) - , (16,25) - , (16,27) - , (23,17) - , (23,25) - , (27,20) - , (27,28) - , (33,22) - , (37,14) - , (41,21) - , (41,30) + [ (11,17) + , (14,25) + , (14,27) + , (21,17) + , (21,25) + , (25,20) + , (25,28) + , (31,22) + , (35,14) + , (39,21) + , (39,30) ] main = do ===================================== testsuite/tests/hiefile/should_run/HasFieldQueries.stdout ===================================== @@ -1,80 +1,59 @@ ========================== -At point (13,17), we found: +At point (11,17), we found: ========================== ┌ │ $dHasField at HasFieldQueries.hs:1:1, of type: HasField "field1" Thing Char -│ is an evidence variable bound by a let, depending on: [C:HasField, -│ field1] +│ is an evidence variable bound by a let, depending on: [field1 of record Thing] │ with scope: ModuleScope │ │ Defined at <no location info> └ | -+- ┌ -| │ C:HasField at HasFieldQueries.hs:1:1, of type: forall {k} (x :: k) r a. (r -> a) -> HasField x r a -| │ is a usage of an external evidence variable -| │ Defined in `GHC.Internal.Records' -| └ -| `- ┌ │ field1 at HasFieldQueries.hs:1:1, of type: Thing -> Char │ is a usage of an external evidence variable - │ Defined at HasFieldQueries.hs:9:21 + │ Defined at HasFieldQueries.hs:7:21 └ ========================== -At point (16,25), we found: +At point (14,25), we found: ========================== ========================== -At point (16,27), we found: +At point (14,27), we found: ========================== ┌ -│ $dHasField at HasFieldQueries.hs:16:1-32, of type: HasField "field1" Thing Char -│ is an evidence variable bound by a let, depending on: [C:HasField, -│ field1] -│ with scope: LocalScope HasFieldQueries.hs:16:1-32 -│ bound at: HasFieldQueries.hs:16:1-32 +│ $dHasField at HasFieldQueries.hs:14:1-32, of type: HasField "field1" Thing Char +│ is an evidence variable bound by a let, depending on: [field1 of record Thing] +│ with scope: LocalScope HasFieldQueries.hs:14:1-32 +│ bound at: HasFieldQueries.hs:14:1-32 │ Defined at <no location info> └ | -+- ┌ -| │ C:HasField at HasFieldQueries.hs:1:1, of type: forall {k} (x :: k) r a. (r -> a) -> HasField x r a -| │ is a usage of an external evidence variable -| │ Defined in `GHC.Internal.Records' -| └ -| `- ┌ │ field1 at HasFieldQueries.hs:1:1, of type: Thing -> Char │ is a usage of an external evidence variable - │ Defined at HasFieldQueries.hs:9:21 + │ Defined at HasFieldQueries.hs:7:21 └ ========================== -At point (23,17), we found: +At point (21,17), we found: ========================== ┌ │ $dHasField at HasFieldQueries.hs:1:1, of type: HasField "nested1" NestedThing Thing -│ is an evidence variable bound by a let, depending on: [C:HasField, -│ nested1] +│ is an evidence variable bound by a let, depending on: [nested1 of record NestedThing] │ with scope: ModuleScope │ │ Defined at <no location info> └ | -+- ┌ -| │ C:HasField at HasFieldQueries.hs:1:1, of type: forall {k} (x :: k) r a. (r -> a) -> HasField x r a -| │ is a usage of an external evidence variable -| │ Defined in `GHC.Internal.Records' -| └ -| `- ┌ │ nested1 at HasFieldQueries.hs:1:1, of type: NestedThing -> Thing │ is a usage of an external evidence variable - │ Defined at HasFieldQueries.hs:20:34 + │ Defined at HasFieldQueries.hs:18:34 └ ========================== -At point (23,25), we found: +At point (21,25), we found: ========================== ┌ │ $dHasField at HasFieldQueries.hs:1:1, of type: HasField "field1" Thing Char @@ -86,84 +65,77 @@ At point (23,25), we found: | `- ┌ │ $dHasField at HasFieldQueries.hs:1:1, of type: HasField "field1" Thing Char - │ is an evidence variable bound by a let, depending on: [C:HasField, - │ field1] + │ is an evidence variable bound by a let, depending on: [field1 of record Thing] │ with scope: ModuleScope │ │ Defined at <no location info> └ | - +- ┌ - | │ C:HasField at HasFieldQueries.hs:1:1, of type: forall {k} (x :: k) r a. (r -> a) -> HasField x r a - | │ is a usage of an external evidence variable - | │ Defined in `GHC.Internal.Records' - | └ - | `- ┌ │ field1 at HasFieldQueries.hs:1:1, of type: Thing -> Char │ is a usage of an external evidence variable - │ Defined at HasFieldQueries.hs:9:21 + │ Defined at HasFieldQueries.hs:7:21 └ ========================== -At point (27,20), we found: +At point (25,20), we found: ========================== ┌ -│ $dHasField at HasFieldQueries.hs:27:1-40, of type: HasField "nested1" r r +│ $dHasField at HasFieldQueries.hs:25:1-40, of type: HasField "nested1" r r │ is an evidence variable bound by a let, depending on: [$dHasField] -│ with scope: LocalScope HasFieldQueries.hs:27:1-40 -│ bound at: HasFieldQueries.hs:27:1-40 +│ with scope: LocalScope HasFieldQueries.hs:25:1-40 +│ bound at: HasFieldQueries.hs:25:1-40 │ Defined at <no location info> └ | `- ┌ - │ $dHasField at HasFieldQueries.hs:27:1-40, of type: HasField "nested1" r r + │ $dHasField at HasFieldQueries.hs:25:1-40, of type: HasField "nested1" r r │ is an evidence variable bound by a type signature - │ with scope: LocalScope HasFieldQueries.hs:27:1-40 - │ bound at: HasFieldQueries.hs:27:1-40 + │ with scope: LocalScope HasFieldQueries.hs:25:1-40 + │ bound at: HasFieldQueries.hs:25:1-40 │ Defined at <no location info> └ ========================== -At point (27,28), we found: +At point (25,28), we found: ========================== ┌ -│ $dHasField at HasFieldQueries.hs:27:1-40, of type: HasField "field2" r Bool +│ $dHasField at HasFieldQueries.hs:25:1-40, of type: HasField "field2" r Bool │ is an evidence variable bound by a let, depending on: [$dHasField] -│ with scope: LocalScope HasFieldQueries.hs:27:1-40 -│ bound at: HasFieldQueries.hs:27:1-40 +│ with scope: LocalScope HasFieldQueries.hs:25:1-40 +│ bound at: HasFieldQueries.hs:25:1-40 │ Defined at <no location info> └ | `- ┌ - │ $dHasField at HasFieldQueries.hs:27:1-40, of type: HasField "field2" r Bool + │ $dHasField at HasFieldQueries.hs:25:1-40, of type: HasField "field2" r Bool │ is an evidence variable bound by a type signature - │ with scope: LocalScope HasFieldQueries.hs:27:1-40 - │ bound at: HasFieldQueries.hs:27:1-40 + │ with scope: LocalScope HasFieldQueries.hs:25:1-40 + │ bound at: HasFieldQueries.hs:25:1-40 │ Defined at <no location info> └ ========================== -At point (33,22), we found: +At point (31,22), we found: ========================== ┌ -│ $dHasField at HasFieldQueries.hs:33:1-27, of type: HasField "field1" x Char +│ $dHasField at HasFieldQueries.hs:31:1-27, of type: HasField "field1" x Char │ is an evidence variable bound by a let, depending on: [$dHasField] -│ with scope: LocalScope HasFieldQueries.hs:33:1-27 -│ bound at: HasFieldQueries.hs:33:1-27 +│ with scope: LocalScope HasFieldQueries.hs:31:1-27 +│ bound at: HasFieldQueries.hs:31:1-27 │ Defined at <no location info> └ | `- ┌ - │ $dHasField at HasFieldQueries.hs:33:1-27, of type: HasField "field1" x Char + │ $dHasField at HasFieldQueries.hs:31:1-27, of type: HasField "field1" x Char │ is an evidence variable bound by a HsWrapper - │ with scope: LocalScope HasFieldQueries.hs:33:1-27 - │ bound at: HasFieldQueries.hs:33:1-27 + │ with scope: LocalScope HasFieldQueries.hs:31:1-27 + │ bound at: HasFieldQueries.hs:31:1-27 │ Defined at <no location info> └ ========================== -At point (37,14), we found: +At point (35,14), we found: ========================== ┌ │ $dHasField at HasFieldQueries.hs:1:1, of type: HasField "field1" Thing Char @@ -175,70 +147,49 @@ At point (37,14), we found: | `- ┌ │ $dHasField at HasFieldQueries.hs:1:1, of type: HasField "field1" Thing Char - │ is an evidence variable bound by a let, depending on: [C:HasField, - │ field1] + │ is an evidence variable bound by a let, depending on: [field1 of record Thing] │ with scope: ModuleScope │ │ Defined at <no location info> └ | - +- ┌ - | │ C:HasField at HasFieldQueries.hs:1:1, of type: forall {k} (x :: k) r a. (r -> a) -> HasField x r a - | │ is a usage of an external evidence variable - | │ Defined in `GHC.Internal.Records' - | └ - | `- ┌ │ field1 at HasFieldQueries.hs:1:1, of type: Thing -> Char │ is a usage of an external evidence variable - │ Defined at HasFieldQueries.hs:9:21 + │ Defined at HasFieldQueries.hs:7:21 └ ========================== -At point (41,21), we found: +At point (39,21), we found: ========================== ┌ │ $dHasField at HasFieldQueries.hs:1:1, of type: HasField "nested1" NestedThing Thing -│ is an evidence variable bound by a let, depending on: [C:HasField, -│ nested1] +│ is an evidence variable bound by a let, depending on: [nested1 of record NestedThing] │ with scope: ModuleScope │ │ Defined at <no location info> └ | -+- ┌ -| │ C:HasField at HasFieldQueries.hs:1:1, of type: forall {k} (x :: k) r a. (r -> a) -> HasField x r a -| │ is a usage of an external evidence variable -| │ Defined in `GHC.Internal.Records' -| └ -| `- ┌ │ nested1 at HasFieldQueries.hs:1:1, of type: NestedThing -> Thing │ is a usage of an external evidence variable - │ Defined at HasFieldQueries.hs:20:34 + │ Defined at HasFieldQueries.hs:18:34 └ ========================== -At point (41,30), we found: +At point (39,30), we found: ========================== ┌ │ $dHasField at HasFieldQueries.hs:1:1, of type: HasField "field1" Thing Char -│ is an evidence variable bound by a let, depending on: [C:HasField, -│ field1] +│ is an evidence variable bound by a let, depending on: [field1 of record Thing] │ with scope: ModuleScope │ │ Defined at <no location info> └ | -+- ┌ -| │ C:HasField at HasFieldQueries.hs:1:1, of type: forall {k} (x :: k) r a. (r -> a) -> HasField x r a -| │ is a usage of an external evidence variable -| │ Defined in `GHC.Internal.Records' -| └ -| `- ┌ │ field1 at HasFieldQueries.hs:1:1, of type: Thing -> Char │ is a usage of an external evidence variable - │ Defined at HasFieldQueries.hs:9:21 + │ Defined at HasFieldQueries.hs:7:21 └ ===================================== testsuite/tests/hiefile/should_run/HieTypeable.hs ===================================== @@ -0,0 +1,36 @@ +module Main where + +import Data.Typeable +import TestUtils + +data Thing = Thing Char Bool + +repCon :: Thing -> TypeRep +repCon t = typeOf t +-- ^ + +repApp :: Maybe Thing -> TypeRep +repApp m = typeOf m +-- ^ + +repFun :: (Thing -> Bool) -> TypeRep +repFun f = typeOf f +-- ^ + +repGiven :: Typeable a => a -> TypeRep +repGiven x = typeOf (Just x) +-- ^ + +points :: [(Int, Int)] +points = + [ (9,12) + , (13,12) + , (17,12) + , (21,14) + ] + +main :: IO () +main = do + (df, hf) <- readTestHie "HieTypeable.hie" + let refmap = generateReferencesMap $ getAsts $ hie_asts hf + mapM_ (explainEv df hf refmap) points ===================================== testsuite/tests/hiefile/should_run/HieTypeable.stdout ===================================== @@ -0,0 +1,119 @@ +========================== +At point (9,12), we found: +========================== +┌ +│ $dTypeable at HieTypeable.hs:1:1, of type: Typeable Thing +│ is an evidence variable bound by a let, depending on: [$dTypeable] +│ with scope: ModuleScope +│ +│ Defined at <no location info> +└ +| +`- ┌ + │ $dTypeable at HieTypeable.hs:1:1, of type: Typeable Thing + │ is an evidence variable bound by a let, depending on: [Typeable Thing] + │ with scope: ModuleScope + │ + │ Defined at <no location info> + └ + +========================== +At point (13,12), we found: +========================== +┌ +│ $dTypeable at HieTypeable.hs:1:1, of type: Typeable (Maybe Thing) +│ is an evidence variable bound by a let, depending on: [$dTypeable, +│ $dTypeable] +│ with scope: ModuleScope +│ +│ Defined at <no location info> +└ +| ++- ┌ +| │ $dTypeable at HieTypeable.hs:1:1, of type: Typeable Maybe +| │ is an evidence variable bound by a let, depending on: [Typeable Maybe] +| │ with scope: ModuleScope +| │ +| │ Defined at <no location info> +| └ +| +`- ┌ + │ $dTypeable at HieTypeable.hs:1:1, of type: Typeable Thing + │ is an evidence variable bound by a let, depending on: [Typeable Thing] + │ with scope: ModuleScope + │ + │ Defined at <no location info> + └ + +========================== +At point (17,12), we found: +========================== +┌ +│ $dTypeable at HieTypeable.hs:1:1, of type: Typeable (Thing -> Bool) +│ is an evidence variable bound by a let, depending on: [$dTypeable, +│ $dTypeable, $dTypeable] +│ with scope: ModuleScope +│ +│ Defined at <no location info> +└ +| ++- ┌ +| │ $dTypeable at HieTypeable.hs:1:1, of type: Typeable 'Many +| │ is an evidence variable bound by a let, depending on: [Typeable Many] +| │ with scope: ModuleScope +| │ +| │ Defined at <no location info> +| └ +| ++- ┌ +| │ $dTypeable at HieTypeable.hs:1:1, of type: Typeable Thing +| │ is an evidence variable bound by a let, depending on: [Typeable Thing] +| │ with scope: ModuleScope +| │ +| │ Defined at <no location info> +| └ +| +`- ┌ + │ $dTypeable at HieTypeable.hs:1:1, of type: Typeable Bool + │ is an evidence variable bound by a let, depending on: [Typeable Bool] + │ with scope: ModuleScope + │ + │ Defined at <no location info> + └ + +========================== +At point (21,14), we found: +========================== +┌ +│ $dTypeable at HieTypeable.hs:21:1-28, of type: Typeable (Maybe a) +│ is an evidence variable bound by a let, depending on: [$dTypeable, +│ $dTypeable] +│ with scope: LocalScope HieTypeable.hs:21:1-28 +│ bound at: HieTypeable.hs:21:1-28 +│ Defined at <no location info> +└ +| ++- ┌ +| │ $dTypeable at HieTypeable.hs:1:1, of type: Typeable Maybe +| │ is an evidence variable bound by a let, depending on: [Typeable Maybe] +| │ with scope: ModuleScope +| │ +| │ Defined at <no location info> +| └ +| +`- ┌ + │ $dTypeable at HieTypeable.hs:21:1-28, of type: Typeable a + │ is an evidence variable bound by a let, depending on: [$dTypeable] + │ with scope: LocalScope HieTypeable.hs:21:1-28 + │ bound at: HieTypeable.hs:21:1-28 + │ Defined at <no location info> + └ + | + `- ┌ + │ $dTypeable at HieTypeable.hs:21:1-28, of type: Typeable a + │ is an evidence variable bound by a HsWrapper + │ with scope: LocalScope HieTypeable.hs:21:1-28 + │ bound at: HieTypeable.hs:21:1-28 + │ Defined at <no location info> + └ + ===================================== testsuite/tests/hiefile/should_run/NoFieldSelectorQueries.hs ===================================== @@ -37,13 +37,13 @@ multi1b = valD.c -- ^ -- 6 multi1c :: C -> Float -multi1c someC = someC.c -- Where does this point to? +multi1c someC = someC.c -- ^ -- 7 multi3 = valE.e -- ^ -- 8 -multi4 = valD.e -- This is a run-time error, but where does it point to? +multi4 = valD.e -- ^ -- 9 ===================================== testsuite/tests/hiefile/should_run/NoFieldSelectorQueries.stdout ===================================== @@ -3,19 +3,12 @@ At point (23,16), we found: ========================== ┌ │ $dHasField at NoFieldSelectorQueries.hs:1:1, of type: HasField "a" A Int -│ is an evidence variable bound by a let, depending on: [C:HasField, -│ a] +│ is an evidence variable bound by a let, depending on: [a of record A] │ with scope: ModuleScope │ │ Defined at <no location info> └ | -+- ┌ -| │ C:HasField at NoFieldSelectorQueries.hs:1:1, of type: forall {k} (x :: k) r a. (r -> a) -> HasField x r a -| │ is a usage of an external evidence variable -| │ Defined in `GHC.Internal.Records' -| └ -| `- ┌ │ a at NoFieldSelectorQueries.hs:1:1, of type: A -> Int │ is a usage of an external evidence variable @@ -46,19 +39,12 @@ At point (30,15), we found: ========================== ┌ │ $dHasField at NoFieldSelectorQueries.hs:30:1-17, of type: HasField "n" B A -│ is an evidence variable bound by a let, depending on: [C:HasField, -│ n] +│ is an evidence variable bound by a let, depending on: [n of record B] │ with scope: LocalScope NoFieldSelectorQueries.hs:30:1-17 │ bound at: NoFieldSelectorQueries.hs:30:1-17 │ Defined at <no location info> └ | -+- ┌ -| │ C:HasField at NoFieldSelectorQueries.hs:1:1, of type: forall {k} (x :: k) r a. (r -> a) -> HasField x r a -| │ is a usage of an external evidence variable -| │ Defined in `GHC.Internal.Records' -| └ -| `- ┌ │ n at NoFieldSelectorQueries.hs:30:1-17, of type: B -> A │ is a usage of an external evidence variable @@ -70,19 +56,12 @@ At point (30,17), we found: ========================== ┌ │ $dHasField at NoFieldSelectorQueries.hs:30:1-17, of type: HasField "b" A Char -│ is an evidence variable bound by a let, depending on: [C:HasField, -│ b] +│ is an evidence variable bound by a let, depending on: [b of record A] │ with scope: LocalScope NoFieldSelectorQueries.hs:30:1-17 │ bound at: NoFieldSelectorQueries.hs:30:1-17 │ Defined at <no location info> └ | -+- ┌ -| │ C:HasField at NoFieldSelectorQueries.hs:1:1, of type: forall {k} (x :: k) r a. (r -> a) -> HasField x r a -| │ is a usage of an external evidence variable -| │ Defined in `GHC.Internal.Records' -| └ -| `- ┌ │ b at NoFieldSelectorQueries.hs:30:1-17, of type: A -> Char │ is a usage of an external evidence variable @@ -94,19 +73,12 @@ At point (33,16), we found: ========================== ┌ │ $dHasField at NoFieldSelectorQueries.hs:33:1-16, of type: HasField "c" C Float -│ is an evidence variable bound by a let, depending on: [C:HasField, -│ c] +│ is an evidence variable bound by a let, depending on: [c of record C] │ with scope: LocalScope NoFieldSelectorQueries.hs:33:1-16 │ bound at: NoFieldSelectorQueries.hs:33:1-16 │ Defined at <no location info> └ | -+- ┌ -| │ C:HasField at NoFieldSelectorQueries.hs:1:1, of type: forall {k} (x :: k) r a. (r -> a) -> HasField x r a -| │ is a usage of an external evidence variable -| │ Defined in `GHC.Internal.Records' -| └ -| `- ┌ │ c at NoFieldSelectorQueries.hs:1:1, of type: C -> Float │ is a usage of an external evidence variable @@ -118,19 +90,12 @@ At point (36,16), we found: ========================== ┌ │ $dHasField at NoFieldSelectorQueries.hs:36:1-16, of type: HasField "c" C Float -│ is an evidence variable bound by a let, depending on: [C:HasField, -│ c] +│ is an evidence variable bound by a let, depending on: [c of record C] │ with scope: LocalScope NoFieldSelectorQueries.hs:36:1-16 │ bound at: NoFieldSelectorQueries.hs:36:1-16 │ Defined at <no location info> └ | -+- ┌ -| │ C:HasField at NoFieldSelectorQueries.hs:1:1, of type: forall {k} (x :: k) r a. (r -> a) -> HasField x r a -| │ is a usage of an external evidence variable -| │ Defined in `GHC.Internal.Records' -| └ -| `- ┌ │ c at NoFieldSelectorQueries.hs:1:1, of type: C -> Float │ is a usage of an external evidence variable @@ -142,19 +107,12 @@ At point (40,23), we found: ========================== ┌ │ $dHasField at NoFieldSelectorQueries.hs:1:1, of type: HasField "c" C Float -│ is an evidence variable bound by a let, depending on: [C:HasField, -│ c] +│ is an evidence variable bound by a let, depending on: [c of record C] │ with scope: ModuleScope │ │ Defined at <no location info> └ | -+- ┌ -| │ C:HasField at NoFieldSelectorQueries.hs:1:1, of type: forall {k} (x :: k) r a. (r -> a) -> HasField x r a -| │ is a usage of an external evidence variable -| │ Defined in `GHC.Internal.Records' -| └ -| `- ┌ │ c at NoFieldSelectorQueries.hs:1:1, of type: C -> Float │ is a usage of an external evidence variable @@ -166,19 +124,12 @@ At point (43,15), we found: ========================== ┌ │ $dHasField at NoFieldSelectorQueries.hs:43:1-15, of type: HasField "e" C Int -│ is an evidence variable bound by a let, depending on: [C:HasField, -│ e] +│ is an evidence variable bound by a let, depending on: [e of record C] │ with scope: LocalScope NoFieldSelectorQueries.hs:43:1-15 │ bound at: NoFieldSelectorQueries.hs:43:1-15 │ Defined at <no location info> └ | -+- ┌ -| │ C:HasField at NoFieldSelectorQueries.hs:1:1, of type: forall {k} (x :: k) r a. (r -> a) -> HasField x r a -| │ is a usage of an external evidence variable -| │ Defined in `GHC.Internal.Records' -| └ -| `- ┌ │ e at NoFieldSelectorQueries.hs:43:1-15, of type: C -> Int │ is a usage of an external evidence variable @@ -190,19 +141,12 @@ At point (46,15), we found: ========================== ┌ │ $dHasField at NoFieldSelectorQueries.hs:46:1-15, of type: HasField "e" C Int -│ is an evidence variable bound by a let, depending on: [C:HasField, -│ e] +│ is an evidence variable bound by a let, depending on: [e of record C] │ with scope: LocalScope NoFieldSelectorQueries.hs:46:1-15 │ bound at: NoFieldSelectorQueries.hs:46:1-15 │ Defined at <no location info> └ | -+- ┌ -| │ C:HasField at NoFieldSelectorQueries.hs:1:1, of type: forall {k} (x :: k) r a. (r -> a) -> HasField x r a -| │ is a usage of an external evidence variable -| │ Defined in `GHC.Internal.Records' -| └ -| `- ┌ │ e at NoFieldSelectorQueries.hs:43:1-15, of type: C -> Int │ is a usage of an external evidence variable ===================================== testsuite/tests/hiefile/should_run/RecordDotTypes.stdout ===================================== @@ -1,9 +1,9 @@ At (22,6), got type: MyRecord At (22,20), got type: MyRecord -> Integer At (22,25), got type: MyRecord -At (22,28), got type: MyChild -> [Char] -At (22,29), got type: MyChild -> [Char] -At (22,6) - (22,8), got type: [Char] +At (22,28), got type: MyChild -> String +At (22,29), got type: MyChild -> String +At (22,6) - (22,8), got type: String At (22,17) - (22,20), got type: Integer At (22,25) - (22,27), got type: MyChild -At (22,25) - (22,29), got type: [Char] +At (22,25) - (22,29), got type: String ===================================== testsuite/tests/hiefile/should_run/all.T ===================================== @@ -12,3 +12,5 @@ test('HieGadtConSigs', [extra_run_opts('"' + config.libdir + '"'), extra_files([ test('T25709', [extra_run_opts('"' + config.libdir + '"'), extra_files(['TestUtils.hs'])], compile_and_run, ['-package ghc -fwrite-ide-info']) test('HasFieldQueries', [extra_run_opts('"' + config.libdir + '"'), extra_files(['TestUtils.hs'])], compile_and_run, ['-package ghc -fwrite-ide-info']) test('NoFieldSelectorQueries', [extra_run_opts('"' + config.libdir + '"'), extra_files(['TestUtils.hs'])], compile_and_run, ['-package ghc -fwrite-ide-info']) +test('HasCallStackIds', [extra_run_opts('"' + config.libdir + '"'), extra_files(['TestUtils.hs'])], compile_and_run, ['-package ghc -fwrite-ide-info']) +test('HieTypeable', [extra_run_opts('"' + config.libdir + '"'), extra_files(['TestUtils.hs'])], compile_and_run, ['-package ghc -fwrite-ide-info']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/760ff607e162948ec9d94a944e04e7f6... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/760ff607e162948ec9d94a944e04e7f6... You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help
participants (1)
-
Hannes Siebenhandl (@fendor)