Apoorv Ingle pushed to branch wip/spj-apporv-Oct24 at Glasgow Haskell Compiler / GHC

Commits:

2 changed files:

Changes:

  • compiler/GHC/Tc/Gen/Expr.hs
    ... ... @@ -849,6 +849,60 @@ The rest of this Note explains how that is done.
    849 849
     * Note that inside an expansion we have sub-expressions from the original program.
    
    850 850
       As soon as we enter one of those, identified by a /user/ span, `setSrcSpanA` will
    
    851 851
       sets the `tcl_loc` to reflect that span, and switch off `tcl_in_gen_code`.  Nice!
    
    852
    +
    
    853
    +Wrinkle [Why GeneratedSrcSpanDetails in GeneratedSrcSpan]
    
    854
    +
    
    855
    +* HIE Ast is used to compute information necessary for IDE tooling
    
    856
    +  and haddock document generation.
    
    857
    +  https://gitlab.haskell.org/ghc/ghc/-/wikis/hie-files
    
    858
    +* Compiler expanded code may give rise to constraints that are solved and stored
    
    859
    +  as evidences in the typecheck AST, LHsExpr GhcTc. Naturally, those evidences are marked as
    
    860
    +  arising from a generated code. Some of these evidences, however, need to be
    
    861
    +  traced back to the original user written code. (c.f. T23540 haddockHypsrcTest)
    
    862
    +
    
    863
    +* Eg. consider the user written overloaded list example:
    
    864
    +
    
    865
    +        data BetterList x = Nil | Cons x (BetterList x)
    
    866
    +
    
    867
    +        list :: BetterList Modulo1
    
    868
    +        list = [0, 1, 2, 3, Zero]
    
    869
    +
    
    870
    +  Over loadedlists are expanded by the compiler to
    
    871
    +
    
    872
    +        list = XExpr (ExpandedThingRn
    
    873
    +                 { hs_ctxt =  [0, 1, 2, 3, Zero]
    
    874
    +                 , hs_ex = L <gen> fromListN 5 [0, 1, 2, 3, Zero] })
    
    875
    +
    
    876
    +  where `fromListN :: IsList l => Int -> [Item l] -> l`
    
    877
    +
    
    878
    +
    
    879
    +  HIE AST needs to associate the implicit typeclass evidence bound by
    
    880
    +  the call to `fromListN` to the user written expression `[0, 1, 2, 3, Zero]`
    
    881
    +
    
    882
    +      ==========================
    
    883
    +      At point (43,8), we found:
    
    884
    +      ==========================
    
    885
    +
    
    886
    +      │ $dIsList at T23540.hs:1:1, of type: IsList (BetterList Modulo1)
    
    887
    +      │     is an evidence variable bound by a let, depending on: [$fIsListBetterList]
    
    888
    +      │           with scope: ModuleScope
    
    889
    +
    
    890
    +      │     Defined at <no location info>
    
    891
    +
    
    892
    +      |
    
    893
    +      `- ┌
    
    894
    +         │ $fIsListBetterList at T23540.hs:36:10-30, of type: forall x. IsList (BetterList x)
    
    895
    +         │     is an evidence variable bound by an instance of class IsList
    
    896
    +         │           with scope: ModuleScope
    
    897
    +
    
    898
    +         │     Defined at T23540.hs:36:10
    
    899
    +
    
    900
    +
    
    901
    +  We hence embedd the original source code in generated source span details in `SrcSpan.GeneratedSrcSpan`
    
    902
    +  and the function `Iface.Ext.Ast.getUnlocatedEvBinds` can build the appropriate Hie ast Node pointing
    
    903
    +  to the user written expression.
    
    904
    +
    
    905
    +
    
    852 906
     -}
    
    853 907
     
    
    854 908
     tcHsExpansion :: HsExpansion GhcRn -> ExpRhoType -> TcM (HsExpr GhcTc)
    

  • compiler/GHC/Types/SrcLoc.hs
    ... ... @@ -390,13 +390,16 @@ instance Semigroup BufSpan where
    390 390
     -- or a human-readable description of a location.
    
    391 391
     data SrcSpan =
    
    392 392
         RealSrcSpan !RealSrcSpan !(Strict.Maybe BufSpan)  -- See Note [Why Maybe BufPos]
    
    393
    -  | GeneratedSrcSpan !GeneratedSrcSpanDetails
    
    393
    +  | GeneratedSrcSpan !GeneratedSrcSpanDetails -- See Wrinkle [Why GeneratedSrcSpanDetails in GeneratedSrcSpan]
    
    394
    +                                              -- in Note [Typechecking by expansion: overview]
    
    394 395
       | UnhelpfulSpan !UnhelpfulSpanReason
    
    395 396
     
    
    396 397
       deriving (Eq, Show) -- Show is used by GHC.Parser.Lexer, because we
    
    397 398
                           -- derive Show for Token
    
    398 399
     
    
    399
    --- Needed for HIE. See Note [Source locations for implicit function calls] in GHC.Iface.Ext.Ast
    
    400
    +-- Needed for HIE.
    
    401
    +-- See Note [Source locations for implicit function calls] in GHC.Iface.Ext.Ast
    
    402
    +-- See Wrinkle [Why GeneratedSrcSpanDetails in GeneratedSrcSpan] in Note [Typechecking by expansion: overview]
    
    400 403
     data GeneratedSrcSpanDetails =
    
    401 404
         OrigSpan !RealSrcSpan -- this the span of the user written thing
    
    402 405
       | UnhelpfulGenerated -- we do not have the original location.