Apoorv Ingle pushed to branch wip/ani/kill-SrcCodeOrigin at Glasgow Haskell Compiler / GHC

Commits:

4 changed files:

Changes:

  • compiler/GHC/Hs/Expr.hs
    ... ... @@ -1064,6 +1064,7 @@ instance Outputable XXExprGhcRn where
    1064 1064
           pprCtxt (ExprCtxt e) = ppr_builder "<OrigExpr>:"  (ppr e)
    
    1065 1065
           pprCtxt (StmtErrCtxt _ stmt) = ppr_builder "<OrigStmt>:" (ppr stmt)
    
    1066 1066
           pprCtxt (StmtErrCtxtPat _ _ pat) = ppr_builder "<OrigPat>:" (ppr pat)
    
    1067
    +      pprCtxt (FunAppCtxt (FunAppCtxtExpr _ e) _) = ppr_builder "<FunAppCtxt>:"  (ppr e)
    
    1067 1068
           pprCtxt _ = empty
    
    1068 1069
     
    
    1069 1070
     instance Outputable XXExprGhcTc where
    
    ... ... @@ -1079,6 +1080,7 @@ instance Outputable XXExprGhcTc where
    1079 1080
           pprCtxt (ExprCtxt e) = ppr_builder "<OrigExpr>:"  (ppr e)
    
    1080 1081
           pprCtxt (StmtErrCtxt _ stmt) = ppr_builder "<OrigStmt>:" (ppr stmt)
    
    1081 1082
           pprCtxt (StmtErrCtxtPat _ _ pat) = ppr_builder "<OrigPat>:" (ppr pat)
    
    1083
    +      pprCtxt (FunAppCtxt (FunAppCtxtExpr _ e) _) = ppr_builder "<FunAppCtxt>:"  (ppr e)
    
    1082 1084
           pprCtxt _ = empty
    
    1083 1085
     
    
    1084 1086
                 -- e is the expanded expression, we print the original
    

  • compiler/GHC/Tc/Utils/Monad.hs
    ... ... @@ -1961,18 +1961,20 @@ mkErrCtxt env ctxts
    1961 1961
      = go False 0 env ctxts -- regular error ctx
    
    1962 1962
      where
    
    1963 1963
        go :: Bool -> Int -> TidyEnv -> [ErrCtxt] -> TcM [ErrCtxtMsg]
    
    1964
    -   go _ _ _   [] = return []
    
    1964
    +   go _ _ _ [] = return []
    
    1965 1965
        go dbg n env (MkErrCtxt LandmarkUserSrcCode ctxt : ctxts)
    
    1966
    -     = do { -- (env', msg) <- liftZonkM $ emptyTidyEnv env
    
    1967
    -          ; rest <- go dbg n env ctxts
    
    1968
    -          ; return (ctxt : rest) }
    
    1966
    +     = do { (env', msg) <- liftZonkM $ zonkTidyErrCtxtMsg env ctxt
    
    1967
    +          ; rest <- go dbg n env' ctxts
    
    1968
    +          ; return (msg : rest) }
    
    1969 1969
        go dbg n env (MkErrCtxt _ ctxt : ctxts)
    
    1970 1970
          | n < mAX_CONTEXTS -- Too verbose || dbg
    
    1971
    -     = do { -- (env', msg) <- liftZonkM $ emptyTidyEnv env
    
    1972
    -          ; rest <- go dbg (n+1) env ctxts
    
    1973
    -          ; return (ctxt : rest) }
    
    1974
    -     | otherwise
    
    1975
    -     = go dbg n env ctxts -- need to compute this for zonking
    
    1971
    +     = do { (env', msg) <- liftZonkM $ zonkTidyErrCtxtMsg env ctxt
    
    1972
    +          ; rest <- go dbg (n+1) env' ctxts
    
    1973
    +          ; return (msg : rest) }
    
    1974
    +     | otherwise  -- need to compute this for zonking
    
    1975
    +     = do { (env', _) <- liftZonkM $ zonkTidyErrCtxtMsg env ctxt
    
    1976
    +          ; go dbg n env' ctxts
    
    1977
    +          }
    
    1976 1978
     
    
    1977 1979
     
    
    1978 1980
     mAX_CONTEXTS :: Int     -- No more than this number of non-landmark contexts
    

  • compiler/GHC/Tc/Zonk/TcType.hs
    ... ... @@ -49,7 +49,7 @@ module GHC.Tc.Zonk.TcType
    49 49
       , tidyCt, tidyEvVar, tidyDelayedError
    
    50 50
     
    
    51 51
         -- ** Zonk & tidy
    
    52
    -  , zonkTidyTcType, zonkTidyTcTypes
    
    52
    +  , zonkTidyTcType, zonkTidyTcTypes, zonkTidyErrCtxtMsg
    
    53 53
       , zonkTidyOrigin, zonkTidyOrigins
    
    54 54
       , zonkTidyFRRInfos
    
    55 55
     
    
    ... ... @@ -793,3 +793,171 @@ tidyFRROrigin env (FixedRuntimeRepOrigin ty orig)
    793 793
     tidyEvVar :: TidyEnv -> EvVar -> EvVar
    
    794 794
     tidyEvVar env var = updateIdTypeAndMult (tidyType env) var
    
    795 795
       -- No need for tidyOpenType because all the free tyvars are already tidied
    
    796
    +
    
    797
    +
    
    798
    +
    
    799
    +{-
    
    800
    +Zonk ErrCtxtMsg
    
    801
    +-}
    
    802
    +
    
    803
    +zonkTidyErrCtxtMsg :: TidyEnv -> ErrCtxtMsg -> ZonkM (TidyEnv, ErrCtxtMsg)
    
    804
    +zonkTidyErrCtxtMsg env e@(ExprCtxt{}) = return (env, e)
    
    805
    +zonkTidyErrCtxtMsg env (ThetaCtxt ctxt theta_ty) = do
    
    806
    +  (env', theta_ty') <- zonkTidyTcTypes env theta_ty
    
    807
    +  return $ (env', ThetaCtxt ctxt theta_ty')
    
    808
    +-- zonkTidyErrCtxtMsg env (QuantifiedCtCtxt ty) = do
    
    809
    +--   (env', ty') <- zonkTidyTcTypes env ty
    
    810
    +--   return $ QuantifiedCtCtxt ty'
    
    811
    +zonkTidyErrCtxtMsg env (InferredTypeCtxt n ty) = do
    
    812
    +  (env', ty') <- zonkTidyTcType env ty
    
    813
    +  return $ (env', InferredTypeCtxt n ty')
    
    814
    +-- zonkTidyErrCtxtMsg (RecordUpdCtxt n1 n2 tys) = do
    
    815
    +--   tys' <- lift $ mapM zonkTcTypeToType tys
    
    816
    +--   return $ RecordUpdCtxt n1 n2 tys'
    
    817
    +zonkTidyErrCtxtMsg env (ClassOpCtxt n ty) = do
    
    818
    +  (env', ty') <- zonkTidyTcType env ty
    
    819
    +  return $ (env', ClassOpCtxt n ty')
    
    820
    +zonkTidyErrCtxtMsg env (MethSigCtxt n ty1 ty2) = do
    
    821
    +  (env', ty1) <- zonkTidyTcType env ty1
    
    822
    +  (env', ty2) <- zonkTidyTcType env ty2
    
    823
    +  return $ (env',  MethSigCtxt n ty1 ty2)
    
    824
    +-- zonkTidyErrCtxtMsg (PatSigErrCtxt ty exp_ty) = do
    
    825
    +--   ty' <- lift $ zonkTcTypeToType ty
    
    826
    +--   exp_ty' <- lift $ readExpType_maybe exp_ty
    
    827
    +--   case exp_ty' of
    
    828
    +--      Nothing -> error "zonkTidyErrCtxtMsg PatSingErrCtxt"
    
    829
    +--      Just exp_ty' -> do
    
    830
    +--        exp_ty' <- lift $ zonkTcTypeToType exp_ty'
    
    831
    +--        return $ PatSigErrCtxt ty' exp_ty'
    
    832
    +
    
    833
    +zonkTidyErrCtxtMsg env e@(FunAppCtxt{}) = return (env, e)
    
    834
    +zonkTidyErrCtxtMsg env (FunTysCtxt ctxt ty i1 i2) = do
    
    835
    +  (env', ty') <- zonkTidyTcType env ty
    
    836
    +  return $ (env', FunTysCtxt ctxt ty' i1 i2)
    
    837
    +zonkTidyErrCtxtMsg env (FunResCtxt e i1 ty1 ty2 i2 i3) = do
    
    838
    +  (env', ty1') <- zonkTidyTcType env ty1
    
    839
    +  (env', ty2') <- zonkTidyTcType env ty2
    
    840
    +  return $ (env', FunResCtxt e i1 ty1' ty2' i2 i3)
    
    841
    +zonkTidyErrCtxtMsg env p = return (env, p)
    
    842
    +{-
    
    843
    +  -- or a type signature, or... (see 'Sig').
    
    844
    +  | SigCtxt !(Sig GhcRn)
    
    845
    +  -- | In a user-written type signature.
    
    846
    +  | UserSigCtxt !UserTypeCtxt !UserSigType
    
    847
    +
    
    848
    +  -- | In a pattern.
    
    849
    +  | PatCtxt !(Pat GhcRn)
    
    850
    +  -- | In a pattern synonym declaration.
    
    851
    +  | PatSynDeclCtxt !Name
    
    852
    +  -- | In a pattern matching context, e.g. a equation for a function binding,
    
    853
    +  -- or a case alternative, ...
    
    854
    +  | MatchCtxt !HsMatchContextRn
    
    855
    +  -- | In a match in a pattern matching context,
    
    856
    +  -- either for an expression or for an arrow command.
    
    857
    +  | forall body. (Outputable body)
    
    858
    +  => MatchInCtxt !(Match GhcRn body)
    
    859
    +  -- | In the declaration of a type constructor.
    
    860
    +  | TyConDeclCtxt !Name !(TyConFlavour TyCon)
    
    861
    +  -- | In a type or data family instance (or default instance).
    
    862
    +  | TyConInstCtxt !Name !TyConInstFlavour
    
    863
    +  -- | In the declaration of a data constructor.
    
    864
    +  | DataConDefCtxt !(NE.NonEmpty (LocatedN Name))
    
    865
    +  -- | In the result type of a data constructor.
    
    866
    +  | DataConResTyCtxt !(NE.NonEmpty (LocatedN Name))
    
    867
    +  -- | In the equations for a closed type family.
    
    868
    +  | ClosedFamEqnCtxt !TyCon
    
    869
    +  -- | In the expansion of a type synonym.
    
    870
    +  | TySynErrCtxt !TyCon
    
    871
    +  -- | In a role annotation.
    
    872
    +  | RoleAnnotErrCtxt !Name
    
    873
    +  -- | In an arrow command.
    
    874
    +  | CmdCtxt !(HsCmd GhcRn)
    
    875
    +  -- | In an instance declaration.
    
    876
    +  | InstDeclErrCtxt !(Either (LHsType GhcRn) PredType)
    
    877
    +  -- | In a default declaration.
    
    878
    +  | DefaultDeclErrCtxt { ddec_in_type_list :: !Bool }
    
    879
    +  -- | In the body of a static form.
    
    880
    +  | StaticFormCtxt !(LHsExpr GhcRn)
    
    881
    +  -- | In a pattern binding.
    
    882
    +  | forall p. OutputableBndrId p
    
    883
    +  => PatMonoBindsCtxt !(LPat (GhcPass p)) !(GRHSs GhcRn (LHsExpr GhcRn))
    
    884
    +  -- | In a foreign import/export declaration.
    
    885
    +  | ForeignDeclCtxt !(ForeignDecl GhcRn)
    
    886
    +  -- | In a record field.
    
    887
    +  | FieldCtxt !FieldLabelString
    
    888
    +  -- | In a type.
    
    889
    +  | TypeCtxt !(LHsType GhcRn)
    
    890
    +  -- | In a kind.
    
    891
    +  | KindCtxt !(LHsKind GhcRn)
    
    892
    +  -- | In an ambiguity check.
    
    893
    +  | AmbiguityCheckCtxt !UserTypeCtxt !Bool
    
    894
    +
    
    895
    +  -- | In a term-level use of a 'Name'.
    
    896
    +  | TermLevelUseCtxt !Name !TermLevelUseCtxt
    
    897
    +
    
    898
    +  -- | When checking the type of the @main@ function.
    
    899
    +  | MainCtxt !Name
    
    900
    +  -- | Warning emitted when inferring use of visible dependent quantification.
    
    901
    +  | VDQWarningCtxt !TcTyCon
    
    902
    +
    
    903
    +  -- | In a statement
    
    904
    +  | forall body.
    
    905
    +    ( Anno (StmtLR GhcRn GhcRn body) ~ SrcSpanAnnA
    
    906
    +    , Outputable body
    
    907
    +    ) => StmtErrCtxt !HsStmtContextRn !(StmtLR GhcRn GhcRn body)
    
    908
    +
    
    909
    +  -- | In a do statement.
    
    910
    +  | DoStmtErrCtxt !HsStmtContextRn !(ExprLStmt GhcRn)
    
    911
    +
    
    912
    +  -- | In patten of the do statement. (c.f. MonadFailErrors)
    
    913
    +  | StmtErrCtxtPat !HsStmtContextRn !(ExprLStmt GhcRn) (LPat GhcRn)
    
    914
    +
    
    915
    +  -- | In an rebindable syntax expression.
    
    916
    +  | SyntaxNameCtxt !(HsExpr GhcRn) !CtOrigin !TcType !SrcSpan
    
    917
    +  -- | In a RULE.
    
    918
    +  | RuleCtxt !FastString
    
    919
    +  -- | In a subtype check.
    
    920
    +  | SubTypeCtxt !TcType !TcType
    
    921
    +
    
    922
    +  -- | In an export.
    
    923
    +  | forall p. OutputableBndrId p
    
    924
    +  => ExportCtxt (IE (GhcPass p))
    
    925
    +  -- | In an export of a pattern synonym.
    
    926
    +  | PatSynExportCtxt !PatSyn
    
    927
    +  -- | In an export of a pattern synonym record field.
    
    928
    +  | PatSynRecSelExportCtxt !PatSyn !Name
    
    929
    +
    
    930
    +  -- | In an annotation.
    
    931
    +  | forall p. OutputableBndrId p
    
    932
    +  => AnnCtxt (AnnDecl (GhcPass p))
    
    933
    +
    
    934
    +  -- | In a specialise pragma.
    
    935
    +  | SpecPragmaCtxt !(Sig GhcRn)
    
    936
    +
    
    937
    +  -- | In a deriving clause.
    
    938
    +  | DerivInstCtxt !PredType
    
    939
    +  -- | In a standalone deriving clause.
    
    940
    +  | StandaloneDerivCtxt !(LHsSigWcType GhcRn)
    
    941
    +  -- | When typechecking the body of a derived instance.
    
    942
    +  | DerivBindCtxt !Id !Class ![Type]
    
    943
    +
    
    944
    +  -- | In an untyped Template Haskell quote.
    
    945
    +  | UntypedTHBracketCtxt !(HsQuote GhcPs)
    
    946
    +  -- | In a typed Template Haskell quote.
    
    947
    +  | forall p. OutputableBndrId p
    
    948
    +  => TypedTHBracketCtxt !(LHsExpr (GhcPass p))
    
    949
    +  -- | In an untyped Template Haskell splice or quasi-quote.
    
    950
    +  | UntypedSpliceCtxt !(HsUntypedSplice GhcPs)
    
    951
    +  -- | In a typed Template Haskell splice.
    
    952
    +  | forall p. OutputableBndrId p
    
    953
    +  => TypedSpliceCtxt !(Maybe SplicePointName) !(HsTypedSplice (GhcPass p))
    
    954
    +  -- | In the result of a typed Template Haskell splice.
    
    955
    +  | TypedSpliceResultCtxt !(LHsExpr GhcTc)
    
    956
    +  -- | In an argument to the Template Haskell @reifyInstances@ function.
    
    957
    +  | ReifyInstancesCtxt !TH.Name ![TH.Type]
    
    958
    +
    
    959
    +  -- | While merging Backpack signatures.
    
    960
    +  | MergeSignaturesCtxt !UnitState !ModuleName ![InstantiatedModule]
    
    961
    +  -- | While checking that a module implements a Backpack signature.
    
    962
    +  | CheckImplementsCtxt !UnitState !Module !InstantiatedModule
    
    963
    +-}

  • compiler/GHC/Tc/Zonk/Type.hs
    ... ... @@ -2005,4 +2005,3 @@ Quantifying here is awkward because (a) the data type is big and (b)
    2005 2005
     finding the free type vars of an expression is necessarily monadic
    
    2006 2006
     operation. (consider /\a -> f @ b, where b is side-effected to a)
    
    2007 2007
     -}
    2008
    -