ghc-9.6.3: The GHC API

Safe Haskell | Safe-Inferred
Language | Haskell2010

GHC.Iface.Ext.Utils

Synopsis

- type RefMap a = Map Identifier [(Span, IdentifierDetails a)]
- generateReferencesMap :: Foldable f => f (HieAST a) -> RefMap a
- renderHieType :: DynFlags -> HieTypeFix -> String
- resolveVisibility :: Type -> [Type] -> [(Bool, Type)]
- foldType :: (HieType a -> a) -> HieTypeFix -> a
- selectPoint :: HieFile -> (Int, Int) -> Maybe (HieAST Int)
- findEvidenceUse :: NodeIdentifiers a -> [Name]
- data EvidenceInfo a = EvidenceInfo {
  - evidenceVar :: Name
  - evidenceSpan :: RealSrcSpan
  - evidenceType :: a
  - evidenceDetails :: Maybe (EvVarSource, Scope, Maybe Span)
  }
- getEvidenceTreesAtPoint :: HieFile -> RefMap a -> (Int, Int) -> Forest (EvidenceInfo a)
- getEvidenceTree :: RefMap a -> Name -> Maybe (Tree (EvidenceInfo a))
- hieTypeToIface :: HieTypeFix -> IfaceType
- data HieTypeState = HTS {
  - tyMap :: !(TypeMap TypeIndex)
  - htyTable :: !(IntMap HieTypeFlat)
  - freshIndex :: !TypeIndex
  }
- initialHTS :: HieTypeState
- freshTypeIndex :: State HieTypeState TypeIndex
- compressTypes :: HieASTs Type -> (HieASTs TypeIndex, Array TypeIndex HieTypeFlat)
- recoverFullType :: TypeIndex -> Array TypeIndex HieTypeFlat -> HieTypeFix
- getTypeIndex :: Type -> State HieTypeState TypeIndex
- resolveTyVarScopes :: Map HiePath (HieAST a) -> Map HiePath (HieAST a)
- resolveTyVarScopeLocal :: HieAST a -> Map HiePath (HieAST a) -> HieAST a
- getNameBinding :: Name -> Map HiePath (HieAST a) -> Maybe Span
- getNameScope :: Name -> Map HiePath (HieAST a) -> Maybe [Scope]
- getNameBindingInClass :: Name -> Span -> Map HiePath (HieAST a) -> Maybe Span
- getNameScopeAndBinding :: Name -> Map HiePath (HieAST a) -> Maybe ([Scope], Maybe Span)
- getScopeFromContext :: ContextInfo -> Maybe [Scope]
- getBindSiteFromContext :: ContextInfo -> Maybe Span
- flattenAst :: HieAST a -> [HieAST a]
- smallestContainingSatisfying :: Span -> (HieAST a -> Bool) -> HieAST a -> Maybe (HieAST a)
- selectLargestContainedBy :: Span -> HieAST a -> Maybe (HieAST a)
- selectSmallestContaining :: Span -> HieAST a -> Maybe (HieAST a)
- definedInAsts :: Map HiePath (HieAST a) -> Name -> Bool
- getEvidenceBindDeps :: ContextInfo -> [Name]
- isEvidenceBind :: ContextInfo -> Bool
- isEvidenceContext :: ContextInfo -> Bool
- isEvidenceUse :: ContextInfo -> Bool
- isOccurrence :: ContextInfo -> Bool
- scopeContainsSpan :: Scope -> Span -> Bool
- combineAst :: HieAST Type -> HieAST Type -> HieAST Type
- insertAst :: HieAST Type -> [HieAST Type] -> [HieAST Type]
- nodeInfo :: HieAST Type -> NodeInfo Type
- emptyNodeInfo :: NodeInfo a
- sourcedNodeIdents :: SourcedNodeInfo a -> NodeIdentifiers a
- combineSourcedNodeInfo :: SourcedNodeInfo Type -> SourcedNodeInfo Type -> SourcedNodeInfo Type
- combineNodeInfo :: NodeInfo Type -> NodeInfo Type -> NodeInfo Type
- mergeAsts :: [HieAST Type] -> [HieAST Type] -> [HieAST Type]
- rightOf :: Span -> Span -> Bool
- leftOf :: Span -> Span -> Bool
- startsRightOf :: Span -> Span -> Bool
- mergeSortAsts :: [HieAST Type] -> [HieAST Type]
- simpleNodeInfo :: FastString -> FastString -> NodeInfo a
- locOnly :: Monad m => SrcSpan -> ReaderT NodeOrigin m [HieAST a]
- mkScopeA :: SrcSpanAnn' ann -> Scope
- mkScope :: SrcSpan -> Scope
- mkLScope :: Located a -> Scope
- mkLScopeA :: GenLocated (SrcSpanAnn' a) e -> Scope
- mkLScopeN :: LocatedN a -> Scope
- combineScopes :: Scope -> Scope -> Scope
- mkSourcedNodeInfo :: NodeOrigin -> NodeInfo a -> SourcedNodeInfo a
- makeNodeA :: (Monad m, Data a) => a -> SrcSpanAnn' ann -> ReaderT NodeOrigin m [HieAST b]
- makeNode :: (Monad m, Data a) => a -> SrcSpan -> ReaderT NodeOrigin m [HieAST b]
- makeTypeNodeA :: (Monad m, Data a) => a -> SrcSpanAnnA -> Type -> ReaderT NodeOrigin m [HieAST Type]
- makeTypeNode :: (Monad m, Data a) => a -> SrcSpan -> Type -> ReaderT NodeOrigin m [HieAST Type]

# Documentation

type RefMap a = Map Identifier [(Span, IdentifierDetails a)] Source #

generateReferencesMap :: Foldable f => f (HieAST a) -> RefMap a Source #

renderHieType :: DynFlags -> HieTypeFix -> String Source #

resolveVisibility :: Type -> [Type] -> [(Bool, Type)] Source #

foldType :: (HieType a -> a) -> HieTypeFix -> a Source #

selectPoint :: HieFile -> (Int, Int) -> Maybe (HieAST Int) Source #

findEvidenceUse :: NodeIdentifiers a -> [Name] Source #

data EvidenceInfo a Source #

Constructors

EvidenceInfo |

Fields

- evidenceVar :: Name
- evidenceSpan :: RealSrcSpan
- evidenceType :: a
- evidenceDetails :: Maybe (EvVarSource, Scope, Maybe Span)

#### Instances

Instances details

Functor EvidenceInfo Source # |
Instance details Defined in GHC.Iface.Ext.Utils Methods fmap :: (a -> b) -> EvidenceInfo a -> EvidenceInfo b Source # (<$) :: a -> EvidenceInfo b -> EvidenceInfo a Source #
Outputable a => Outputable (EvidenceInfo a) Source # |
Instance details Defined in GHC.Iface.Ext.Utils Methods ppr :: EvidenceInfo a -> SDoc Source #
Eq a => Eq (EvidenceInfo a) Source # |
Instance details Defined in GHC.Iface.Ext.Utils Methods (==) :: EvidenceInfo a -> EvidenceInfo a -> Bool # (/=) :: EvidenceInfo a -> EvidenceInfo a -> Bool #
Ord a => Ord (EvidenceInfo a) Source # |

Instance details

Defined in GHC.Iface.Ext.Utils

Methods

compare :: EvidenceInfo a -> EvidenceInfo a -> Ordering #

(<) :: EvidenceInfo a -> EvidenceInfo a -> Bool #

(<=) :: EvidenceInfo a -> EvidenceInfo a -> Bool #

(>) :: EvidenceInfo a -> EvidenceInfo a -> Bool #

(>=) :: EvidenceInfo a -> EvidenceInfo a -> Bool #

max :: EvidenceInfo a -> EvidenceInfo a -> EvidenceInfo a #

min :: EvidenceInfo a -> EvidenceInfo a -> EvidenceInfo a #

getEvidenceTreesAtPoint :: HieFile -> RefMap a -> (Int, Int) -> Forest (EvidenceInfo a) Source #

getEvidenceTree :: RefMap a -> Name -> Maybe (Tree (EvidenceInfo a)) Source #

hieTypeToIface :: HieTypeFix -> IfaceType Source #

data HieTypeState Source #

Constructors

HTS |

Fields

- tyMap :: !(TypeMap TypeIndex)
- htyTable :: !(IntMap HieTypeFlat)
- freshIndex :: !TypeIndex

initialHTS :: HieTypeState Source #

freshTypeIndex :: State HieTypeState TypeIndex Source #

compressTypes :: HieASTs Type -> (HieASTs TypeIndex, Array TypeIndex HieTypeFlat) Source #

recoverFullType :: TypeIndex -> Array TypeIndex HieTypeFlat -> HieTypeFix Source #

getTypeIndex :: Type -> State HieTypeState TypeIndex Source #

resolveTyVarScopes :: Map HiePath (HieAST a) -> Map HiePath (HieAST a) Source #

resolveTyVarScopeLocal :: HieAST a -> Map HiePath (HieAST a) -> HieAST a Source #

getNameBinding :: Name -> Map HiePath (HieAST a) -> Maybe Span Source #

getNameScope :: Name -> Map HiePath (HieAST a) -> Maybe [Scope] Source #

getNameBindingInClass :: Name -> Span -> Map HiePath (HieAST a) -> Maybe Span Source #

getNameScopeAndBinding :: Name -> Map HiePath (HieAST a) -> Maybe ([Scope], Maybe Span) Source #

getScopeFromContext :: ContextInfo -> Maybe [Scope] Source #

getBindSiteFromContext :: ContextInfo -> Maybe Span Source #

flattenAst :: HieAST a -> [HieAST a] Source #

smallestContainingSatisfying :: Span -> (HieAST a -> Bool) -> HieAST a -> Maybe (HieAST a) Source #

selectLargestContainedBy :: Span -> HieAST a -> Maybe (HieAST a) Source #

selectSmallestContaining :: Span -> HieAST a -> Maybe (HieAST a) Source #

definedInAsts :: Map HiePath (HieAST a) -> Name -> Bool Source #

getEvidenceBindDeps :: ContextInfo -> [Name] Source #

isEvidenceBind :: ContextInfo -> Bool Source #

isEvidenceContext :: ContextInfo -> Bool Source #

isEvidenceUse :: ContextInfo -> Bool Source #

isOccurrence :: ContextInfo -> Bool Source #

scopeContainsSpan :: Scope -> Span -> Bool Source #

combineAst :: HieAST Type -> HieAST Type -> HieAST Type Source #

One must contain the other. Leaf nodes cannot contain anything

insertAst :: HieAST Type -> [HieAST Type] -> [HieAST Type] Source #

Insert an AST in a sorted list of disjoint Asts

nodeInfo :: HieAST Type -> NodeInfo Type Source #

emptyNodeInfo :: NodeInfo a Source #

sourcedNodeIdents :: SourcedNodeInfo a -> NodeIdentifiers a Source #

combineSourcedNodeInfo :: SourcedNodeInfo Type -> SourcedNodeInfo Type -> SourcedNodeInfo Type Source #

combineNodeInfo :: NodeInfo Type -> NodeInfo Type -> NodeInfo Type Source #

Merge two nodes together.

Precondition and postcondition: elements in `nodeType` are ordered.

mergeAsts :: [HieAST Type] -> [HieAST Type] -> [HieAST Type] Source #

Merge two sorted, disjoint lists of ASTs, combining when necessary.

In the absence of position-altering pragmas (ex: `# line "file.hs" 3`), different nodes in an AST tree should either have disjoint spans (in which case you can say for sure which one comes first) or one span should be completely contained in the other (in which case the contained span corresponds to some child node).

However, since Haskell does have position-altering pragmas it is possible for spans to be overlapping. Here is an example of a source file in which `foozball` and `quuuuuux` have overlapping spans:

    module Baz where

    # line 3 "Baz.hs"
    foozball :: Int
    foozball = 0

    # line 3 "Baz.hs"
    bar, quuuuuux :: Int
    bar = 1
    quuuuuux = 2

In these cases, we just do our best to produce sensible `HieAST`'s. The blame should be laid at the feet of whoever wrote the line pragmas in the first place (usually the C preprocessor...).

rightOf :: Span -> Span -> Bool Source #

leftOf :: Span -> Span -> Bool Source #

startsRightOf :: Span -> Span -> Bool Source #

mergeSortAsts :: [HieAST Type] -> [HieAST Type] Source #

combines and sorts ASTs using a merge sort

simpleNodeInfo :: FastString -> FastString -> NodeInfo a Source #

locOnly :: Monad m => SrcSpan -> ReaderT NodeOrigin m [HieAST a] Source #

mkScopeA :: SrcSpanAnn' ann -> Scope Source #

mkScope :: SrcSpan -> Scope Source #

mkLScope :: Located a -> Scope Source #

mkLScopeA :: GenLocated (SrcSpanAnn' a) e -> Scope Source #

mkLScopeN :: LocatedN a -> Scope Source #

combineScopes :: Scope -> Scope -> Scope Source #

mkSourcedNodeInfo :: NodeOrigin -> NodeInfo a -> SourcedNodeInfo a Source #

makeNodeA Source #

Arguments

:: (Monad m, Data a) |
=> a | helps fill in `nodeAnnotations` (with `Data`)
-> SrcSpanAnn' ann | return an empty list if this is unhelpful
-> ReaderT NodeOrigin m [HieAST b] |

makeNode Source #

Arguments

:: (Monad m, Data a) |
=> a | helps fill in `nodeAnnotations` (with `Data`)
-> SrcSpan | return an empty list if this is unhelpful
-> ReaderT NodeOrigin m [HieAST b] |

makeTypeNodeA Source #

Arguments

:: (Monad m, Data a) |
=> a | helps fill in `nodeAnnotations` (with `Data`)
-> SrcSpanAnnA | return an empty list if this is unhelpful
-> Type | type to associate with the node
-> ReaderT NodeOrigin m [HieAST Type] |

makeTypeNode Source #

Arguments

:: (Monad m, Data a) |
=> a | helps fill in `nodeAnnotations` (with `Data`)
-> SrcSpan | return an empty list if this is unhelpful
-> Type | type to associate with the node
-> ReaderT NodeOrigin m [HieAST Type] |