Apoorv Ingle pushed to branch wip/spj-apporv-Oct24 at Glasgow Haskell Compiler / GHC
Commits:
-
da6e83b0
by Apoorv Ingle at 2025-06-24T00:17:51-05:00
7 changed files:
- compiler/GHC/Hs.hs
- compiler/GHC/Hs/Expr.hs
- compiler/GHC/Hs/Instances.hs
- compiler/GHC/HsToCore/Ticks.hs
- compiler/GHC/Tc/Errors/Ppr.hs
- compiler/GHC/Tc/Types/Origin.hs
- compiler/GHC/Tc/Utils/Monad.hs
Changes:
| ... | ... | @@ -150,16 +150,8 @@ data HsParsedModule = HsParsedModule { |
| 150 | 150 | -- them change (#3589)
|
| 151 | 151 | }
|
| 152 | 152 | |
| 153 | --- All the various located syntax things that sets the user context code in TcLclEnv
|
|
| 154 | --- data SrcCodeOrigin =
|
|
| 155 | --- ExprThing (HsExpr GhcRn)
|
|
| 156 | --- | PatThing (LPat GhcRn)
|
|
| 157 | --- | StmtThing (ExprLStmt GhcRn) HsDoFlavour
|
|
| 158 | - |
|
| 159 | --- I'm a looking at a generated thing or am I a user written thing?
|
|
| 160 | -data SrcCodeCtxt = UserCode | GeneratedCode HsThingRn
|
|
| 161 | - |
|
| 162 | --- mkSrcCodeOrigin :: HsThingRn -> SrcCodeOrigin
|
|
| 163 | --- mkSrcCodeOrigin (OrigExpr e) = ExprThing e
|
|
| 164 | --- mkSrcCodeOrigin (OrigPat p) = PatThing p
|
|
| 165 | --- mkSrcCodeOrigin (OrigStmt s f) = StmtThing e f |
|
| 153 | +-- Used in TcLclCtxt.tcl_in_gen_code to mark if the current expression
|
|
| 154 | +-- is a user generated code or a compiler generated expansion of some user written code
|
|
| 155 | +data SrcCodeCtxt
|
|
| 156 | + = UserCode
|
|
| 157 | + | GeneratedCode SrcCodeOrigin |
| ... | ... | @@ -672,12 +672,13 @@ type instance XXExpr GhcTc = XXExprGhcTc |
| 672 | 672 | -- | The different source constructs that we use to instantiate the "original" field
|
| 673 | 673 | -- in an `XXExprGhcRn original expansion`
|
| 674 | 674 | -- See Note [Handling overloaded and rebindable constructs] in `GHC.Rename.Expr`
|
| 675 | -data HsThingRn = OrigExpr (HsExpr GhcRn) -- ^ The source, user written, expression
|
|
| 676 | - | OrigStmt (ExprLStmt GhcRn) HsDoFlavour -- ^ which kind of do-block did this statement come from
|
|
| 677 | - | OrigPat (LPat GhcRn) -- ^ Used for failable patterns that trigger MonadFail constraints
|
|
| 675 | +data SrcCodeOrigin
|
|
| 676 | + = OrigExpr (HsExpr GhcRn) -- ^ The source, user written, expression
|
|
| 677 | + | OrigStmt (ExprLStmt GhcRn) HsDoFlavour -- ^ which kind of do-block did this statement come from
|
|
| 678 | + | OrigPat (LPat GhcRn) -- ^ Used for failable patterns that trigger MonadFail constraints
|
|
| 678 | 679 | |
| 679 | 680 | data XXExprGhcRn
|
| 680 | - = ExpandedThingRn { xrn_orig :: HsThingRn -- The original source thing to be used for error messages
|
|
| 681 | + = ExpandedThingRn { xrn_orig :: SrcCodeOrigin -- The original source thing to be used for error messages
|
|
| 681 | 682 | , xrn_expanded :: HsExpr GhcRn -- The compiler generated expanded thing
|
| 682 | 683 | }
|
| 683 | 684 | |
| ... | ... | @@ -718,7 +719,7 @@ data XXExprGhcTc |
| 718 | 719 | |
| 719 | 720 | | ExpandedThingTc -- See Note [Rebindable syntax and XXExprGhcRn]
|
| 720 | 721 | -- See Note [Expanding HsDo with XXExprGhcRn] in `GHC.Tc.Gen.Do`
|
| 721 | - { xtc_orig :: HsThingRn -- The original user written thing
|
|
| 722 | + { xtc_orig :: SrcCodeOrigin -- The original user written thing
|
|
| 722 | 723 | , xtc_expanded :: HsExpr GhcTc } -- The expanded typechecked expression
|
| 723 | 724 | |
| 724 | 725 | | ConLikeTc -- Result of typechecking a data-con
|
| ... | ... | @@ -752,10 +753,10 @@ mkExpandedExprTc |
| 752 | 753 | :: HsExpr GhcRn -- ^ source expression
|
| 753 | 754 | -> HsExpr GhcTc -- ^ expanded typechecked expression
|
| 754 | 755 | -> HsExpr GhcTc -- ^ suitably wrapped 'XXExprGhcRn'
|
| 755 | -mkExpandedExprTc oExpr eExpr = XExpr (ExpandedThingTc (OrigExpr oExpr) eExpr)
|
|
| 756 | +mkExpandedExprTc oExpr eExpr = mkExpandedTc (OrigExpr oExpr) eExpr
|
|
| 756 | 757 | |
| 757 | 758 | mkExpandedTc
|
| 758 | - :: HsThingRn -- ^ source do statement
|
|
| 759 | + :: SrcCodeOrigin -- ^ source, user written do statement/expression
|
|
| 759 | 760 | -> HsExpr GhcTc -- ^ expanded typechecked expression
|
| 760 | 761 | -> HsExpr GhcTc -- ^ suitably wrapped 'XXExprGhcRn'
|
| 761 | 762 | mkExpandedTc o e = XExpr (ExpandedThingTc o e)
|
| ... | ... | @@ -1020,7 +1021,7 @@ ppr_expr (XExpr x) = case ghcPass @p of |
| 1020 | 1021 | GhcRn -> ppr x
|
| 1021 | 1022 | GhcTc -> ppr x
|
| 1022 | 1023 | |
| 1023 | -instance Outputable HsThingRn where
|
|
| 1024 | +instance Outputable SrcCodeOrigin where
|
|
| 1024 | 1025 | ppr thing
|
| 1025 | 1026 | = case thing of
|
| 1026 | 1027 | OrigExpr x -> ppr_builder "<OrigExpr>:" x
|
| ... | ... | @@ -1087,7 +1088,7 @@ ppr_infix_expr_tc (HsTick {}) = Nothing |
| 1087 | 1088 | ppr_infix_expr_tc (HsBinTick {}) = Nothing
|
| 1088 | 1089 | ppr_infix_expr_tc (HsRecSelTc f) = Just (pprInfixOcc f)
|
| 1089 | 1090 | |
| 1090 | -ppr_infix_hs_expansion :: HsThingRn -> Maybe SDoc
|
|
| 1091 | +ppr_infix_hs_expansion :: SrcCodeOrigin -> Maybe SDoc
|
|
| 1091 | 1092 | ppr_infix_hs_expansion (OrigExpr e) = ppr_infix_expr e
|
| 1092 | 1093 | ppr_infix_hs_expansion _ = Nothing
|
| 1093 | 1094 | |
| ... | ... | @@ -1195,7 +1196,7 @@ hsExprNeedsParens prec = go |
| 1195 | 1196 | go_x_rn (PopErrCtxt a) = hsExprNeedsParens prec a
|
| 1196 | 1197 | go_x_rn (HsRecSelRn{}) = False
|
| 1197 | 1198 | |
| 1198 | - hsExpandedNeedsParens :: HsThingRn -> Bool
|
|
| 1199 | + hsExpandedNeedsParens :: SrcCodeOrigin -> Bool
|
|
| 1199 | 1200 | hsExpandedNeedsParens (OrigExpr e) = hsExprNeedsParens prec e
|
| 1200 | 1201 | hsExpandedNeedsParens _ = False
|
| 1201 | 1202 | |
| ... | ... | @@ -1248,7 +1249,7 @@ isAtomicHsExpr (XExpr x) |
| 1248 | 1249 | go_x_rn (PopErrCtxt a) = isAtomicHsExpr a
|
| 1249 | 1250 | go_x_rn (HsRecSelRn{}) = True
|
| 1250 | 1251 | |
| 1251 | - isAtomicExpandedThingRn :: HsThingRn -> Bool
|
|
| 1252 | + isAtomicExpandedThingRn :: SrcCodeOrigin -> Bool
|
|
| 1252 | 1253 | isAtomicExpandedThingRn (OrigExpr e) = isAtomicHsExpr e
|
| 1253 | 1254 | isAtomicExpandedThingRn _ = False
|
| 1254 | 1255 |
| ... | ... | @@ -591,7 +591,7 @@ deriving instance Eq (IE GhcTc) |
| 591 | 591 | |
| 592 | 592 | -- ---------------------------------------------------------------------
|
| 593 | 593 | |
| 594 | -deriving instance Data HsThingRn
|
|
| 594 | +deriving instance Data SrcCodeOrigin
|
|
| 595 | 595 | deriving instance Data XXExprGhcRn
|
| 596 | 596 | deriving instance Data a => Data (WithUserRdr a)
|
| 597 | 597 |
| ... | ... | @@ -611,7 +611,7 @@ addTickHsExpr (HsDo srcloc cxt (L l stmts)) |
| 611 | 611 | ListComp -> Just $ BinBox QualBinBox
|
| 612 | 612 | _ -> Nothing
|
| 613 | 613 | |
| 614 | +-- addTickHsExpanded :: SrcCodeOrigin -> HsExpr GhcTc -> TM (HsExpr GhcTc)
|
|
| 614 | 615 | -- addTickHsExpanded o e = liftM (XExpr . ExpandedThingTc o) $ case o of
|
| 615 | 616 | -- -- We always want statements to get a tick, so we can step over each one.
|
| 616 | 617 | -- -- To avoid duplicates we blacklist SrcSpans we already inserted here.
|
| ... | ... | @@ -5306,11 +5306,9 @@ pprArising :: CtLoc -> SDoc |
| 5306 | 5306 | -- We've done special processing for TypeEq, KindEq, givens
|
| 5307 | 5307 | pprArising ct_loc
|
| 5308 | 5308 | | suppress_origin = empty
|
| 5309 | - | in_generated_code = pprCtOrigin orig -- TODO ANI: maybe should go way
|
|
| 5310 | 5309 | | otherwise = pprCtOrigin orig
|
| 5311 | 5310 | where
|
| 5312 | 5311 | orig = ctLocOrigin ct_loc
|
| 5313 | - in_generated_code = ctLocEnvInGeneratedCode (ctLocEnv ct_loc)
|
|
| 5314 | 5312 | suppress_origin
|
| 5315 | 5313 | | isGivenOrigin orig = True
|
| 5316 | 5314 | | otherwise = case orig of
|
| ... | ... | @@ -763,18 +763,18 @@ exprCtOrigin (HsHole _) = Shouldn'tHappenOrigin "hole expression" |
| 763 | 763 | exprCtOrigin (HsForAll {}) = Shouldn'tHappenOrigin "forall telescope" -- See Note [Types in terms]
|
| 764 | 764 | exprCtOrigin (HsQual {}) = Shouldn'tHappenOrigin "constraint context" -- See Note [Types in terms]
|
| 765 | 765 | exprCtOrigin (HsFunArr {}) = Shouldn'tHappenOrigin "function arrow" -- See Note [Types in terms]
|
| 766 | -exprCtOrigin (XExpr (ExpandedThingRn {})) = Shouldn'tHappenOrigin "XExpr ExpandedThingRn"
|
|
| 766 | +exprCtOrigin (XExpr (ExpandedThingRn o _)) = srcCodeOriginCtOrigin o
|
|
| 767 | 767 | exprCtOrigin (XExpr (PopErrCtxt e)) = exprCtOrigin e
|
| 768 | 768 | exprCtOrigin (XExpr (HsRecSelRn f)) = OccurrenceOfRecSel (foExt f)
|
| 769 | 769 | |
| 770 | -hsThingCtOrigin :: HsThingRn -> CtOrigin
|
|
| 771 | -hsThingCtOrigin (OrigExpr e) = exprCtOrigin e
|
|
| 772 | -hsThingCtOrigin (OrigStmt{}) = DoStmtOrigin
|
|
| 773 | -hsThingCtOrigin (OrigPat p) = DoPatOrigin p
|
|
| 770 | +srcCodeOriginCtOrigin :: SrcCodeOrigin -> CtOrigin
|
|
| 771 | +srcCodeOriginCtOrigin (OrigExpr e) = exprCtOrigin e
|
|
| 772 | +srcCodeOriginCtOrigin (OrigStmt{}) = DoStmtOrigin
|
|
| 773 | +srcCodeOriginCtOrigin (OrigPat p) = DoPatOrigin p
|
|
| 774 | 774 | |
| 775 | 775 | srcCodeCtxtCtOrigin :: HsExpr GhcRn -> SrcCodeCtxt -> CtOrigin
|
| 776 | 776 | srcCodeCtxtCtOrigin e UserCode = exprCtOrigin e
|
| 777 | -srcCodeCtxtCtOrigin _ (GeneratedCode e) = hsThingCtOrigin e
|
|
| 777 | +srcCodeCtxtCtOrigin _ (GeneratedCode e) = srcCodeOriginCtOrigin e
|
|
| 778 | 778 | |
| 779 | 779 | -- | Extract a suitable CtOrigin from a MatchGroup
|
| 780 | 780 | matchesCtOrigin :: MatchGroup GhcRn (LHsExpr GhcRn) -> CtOrigin
|
| ... | ... | @@ -990,9 +990,9 @@ getSrcCodeCtxt = getLclEnvSrcCodeCtxt <$> getLclEnv |
| 990 | 990 | -- | Mark the inner computation as being done inside generated code.
|
| 991 | 991 | --
|
| 992 | 992 | -- See Note [Error contexts in generated code]
|
| 993 | -setInGeneratedCode :: HsThingRn -> TcRn a -> TcRn a
|
|
| 994 | -setInGeneratedCode syntax_thing thing_inside =
|
|
| 995 | - updLclCtxt (setLclCtxtSrcCodeCtxt (GeneratedCode syntax_thing)) thing_inside
|
|
| 993 | +setInGeneratedCode :: SrcCodeOrigin -> TcRn a -> TcRn a
|
|
| 994 | +setInGeneratedCode scOrig thing_inside =
|
|
| 995 | + updLclCtxt (setLclCtxtSrcCodeCtxt (GeneratedCode scOrig)) thing_inside
|
|
| 996 | 996 | |
| 997 | 997 | setSrcSpanA :: EpAnn ann -> TcRn a -> TcRn a
|
| 998 | 998 | setSrcSpanA l = setSrcSpan (locA l)
|