Apoorv Ingle pushed to branch wip/ani/T27156 at Glasgow Haskell Compiler / GHC
Commits:
-
0ceec1e3
by Apoorv Ingle at 2026-04-20T23:42:56-05:00
7 changed files:
- compiler/GHC/Hs/Expr.hs
- compiler/GHC/Hs/Instances.hs
- compiler/GHC/HsToCore/Quote.hs
- compiler/GHC/Rename/Expr.hs
- compiler/GHC/Tc/Gen/Expand.hs
- compiler/GHC/Tc/Gen/Expr.hs
- compiler/GHC/Tc/TyCl/PatSyn.hs
Changes:
| ... | ... | @@ -279,7 +279,7 @@ type instance XCase GhcRn = HsMatchContextRn |
| 279 | 279 | type instance XCase GhcTc = HsMatchContextRn
|
| 280 | 280 | |
| 281 | 281 | type instance XIf GhcPs = AnnsIf
|
| 282 | -type instance XIf GhcRn = Maybe RebindableSyntaxTable -- Nothing <=> RebindableSyntax is off
|
|
| 282 | +type instance XIf GhcRn = RebindableSyntaxTable -- NoRebindable <=> RebindableSyntax is off
|
|
| 283 | 283 | type instance XIf GhcTc = NoExtField
|
| 284 | 284 | |
| 285 | 285 | type instance XMultiIf GhcPs = (EpToken "if", EpToken "{", EpToken "}")
|
| ... | ... | @@ -295,7 +295,7 @@ type instance XDo GhcRn = NoExtField |
| 295 | 295 | type instance XDo GhcTc = Type
|
| 296 | 296 | |
| 297 | 297 | type instance XExplicitList GhcPs = AnnList ()
|
| 298 | -type instance XExplicitList GhcRn = Maybe RebindableSyntaxTable -- Nothing <=> RebindableSyntax is off
|
|
| 298 | +type instance XExplicitList GhcRn = RebindableSyntaxTable -- NoRebindable <=> RebindableSyntax is off
|
|
| 299 | 299 | type instance XExplicitList GhcTc = Type
|
| 300 | 300 | -- GhcPs: ExplicitList includes all source-level
|
| 301 | 301 | -- list literals, including overloaded ones
|
| ... | ... | @@ -310,7 +310,7 @@ type instance XRecordCon GhcRn = NoExtField |
| 310 | 310 | type instance XRecordCon GhcTc = PostTcExpr -- Instantiated constructor function
|
| 311 | 311 | |
| 312 | 312 | type instance XRecordUpd GhcPs = (Maybe (EpToken "{"), Maybe (EpToken "}"))
|
| 313 | -type instance XRecordUpd GhcRn = Maybe RebindableSyntaxTable -- Nothing <=> RebindableSyntaxTable is off
|
|
| 313 | +type instance XRecordUpd GhcRn = RebindableSyntaxTable -- NoRebindable <=> RebindableSyntaxTable is off
|
|
| 314 | 314 | type instance XRecordUpd GhcTc = DataConCantHappen
|
| 315 | 315 | -- We desugar record updates in the typechecker.
|
| 316 | 316 | -- See [Handling overloaded and rebindable constructs],
|
| ... | ... | @@ -1485,11 +1485,15 @@ type instance XXCmd GhcTc = HsWrap HsCmd |
| 1485 | 1485 | type CmdSyntaxTable p = [(Name, HsExpr p)]
|
| 1486 | 1486 | -- See Note [CmdSyntaxTable]
|
| 1487 | 1487 | |
| 1488 | -type RebindableSyntaxTable = [(String, Name)]
|
|
| 1488 | +data RebindableSyntaxTable = NoRebindable | Rebindable [(OccName, Name)]
|
|
| 1489 | 1489 | -- Stores the names of the operators for rebindable syntax
|
| 1490 | 1490 | -- eg. getField, setField etc.
|
| 1491 | 1491 | -- GHC.Tc.Expand will use these names to build the expansions
|
| 1492 | 1492 | |
| 1493 | +isNoRebindable :: RebindableSyntaxTable -> Bool
|
|
| 1494 | +isNoRebindable NoRebindable = True
|
|
| 1495 | +isNoRebindable Rebindable{} = False
|
|
| 1496 | + |
|
| 1493 | 1497 | {-
|
| 1494 | 1498 | Note [CmdSyntaxTable]
|
| 1495 | 1499 | ~~~~~~~~~~~~~~~~~~~~~
|
| ... | ... | @@ -340,6 +340,8 @@ deriving instance Data (RoleAnnotDecl GhcTc) |
| 340 | 340 | -- ---------------------------------------------------------------------
|
| 341 | 341 | -- Data derivations from GHC.Hs.Expr -----------------------------------
|
| 342 | 342 | |
| 343 | +deriving instance Data RebindableSyntaxTable -- maybe don't traverse?
|
|
| 344 | + |
|
| 343 | 345 | deriving instance Data (FieldLabelStrings GhcPs)
|
| 344 | 346 | deriving instance Data (FieldLabelStrings GhcRn)
|
| 345 | 347 | deriving instance Data (FieldLabelStrings GhcTc)
|
| ... | ... | @@ -684,7 +686,6 @@ deriving instance Data (HsExpansion GhcTc) |
| 684 | 686 | deriving instance Data a => Data (WithUserRdr a)
|
| 685 | 687 | |
| 686 | 688 | -- -------------------------------
|
| 687 | ---------------------------------------
|
|
| 688 | 689 | deriving instance Data XXExprGhcTc
|
| 689 | 690 | deriving instance Data XXPatGhcTc
|
| 690 | 691 |
| ... | ... | @@ -44,6 +44,8 @@ import GHC.Tc.Types.Evidence |
| 44 | 44 | import GHC.Tc.Types.ErrCtxt
|
| 45 | 45 | import GHC.Tc.TyCl ( IsPrefixConGADT(..), unannotatedMultIsLinear )
|
| 46 | 46 | |
| 47 | +import GHC.Tc.Gen.Expand ( tcExpandNoTcM )
|
|
| 48 | + |
|
| 47 | 49 | import GHC.Core.Class
|
| 48 | 50 | import GHC.Core.DataCon
|
| 49 | 51 | import GHC.Core.TyCon
|
| ... | ... | @@ -1618,11 +1620,13 @@ repE (HsCase _ e (MG { mg_alts = (L _ ms) })) |
| 1618 | 1620 | ; ms2 <- mapM repMatchTup ms
|
| 1619 | 1621 | ; core_ms2 <- coreListM matchTyConName ms2
|
| 1620 | 1622 | ; repCaseE arg core_ms2 }
|
| 1621 | -repE (HsIf _ x y z) = do
|
|
| 1622 | - a <- repLE x
|
|
| 1623 | - b <- repLE y
|
|
| 1624 | - c <- repLE z
|
|
| 1625 | - repCond a b c
|
|
| 1623 | +repE e@(HsIf _ x y z) = case (tcExpandNoTcM e) of
|
|
| 1624 | + Nothing -> do { a <- repLE x
|
|
| 1625 | + ; b <- repLE y
|
|
| 1626 | + ; c <- repLE z
|
|
| 1627 | + ; repCond a b c }
|
|
| 1628 | + Just (HSE _ (L _ e')) -> repE e'
|
|
| 1629 | + |
|
| 1626 | 1630 | repE (HsMultiIf _ alts)
|
| 1627 | 1631 | = do { (binds, alts') <- NE.unzip <$> mapM repLGRHS alts
|
| 1628 | 1632 | ; expr' <- repMultiIf (nonEmptyCoreList' alts')
|
| ... | ... | @@ -344,7 +344,7 @@ rnExpr (HsHole h) |
| 344 | 344 | -- HsOverLabel: see Note [Handling overloaded and rebindable constructs]
|
| 345 | 345 | rnExpr (HsOverLabel src v)
|
| 346 | 346 | = do { (from_label, fvs) <- lookupSyntaxName fromLabelClassOpName
|
| 347 | - ; let rs_table = [("fromLabel", from_label)]
|
|
| 347 | + ; let rs_table = Rebindable [(nameOccName fromLabelClassOpName, from_label)]
|
|
| 348 | 348 | ; return (HsOverLabel (src, rs_table) v, fvs)
|
| 349 | 349 | }
|
| 350 | 350 | |
| ... | ... | @@ -416,14 +416,14 @@ rnExpr (HsGetField _ e f) |
| 416 | 416 | = do { (getField, fv_getField) <- lookupSyntaxName getFieldName
|
| 417 | 417 | ; (e, fv_e) <- rnLExpr e
|
| 418 | 418 | ; let f' = rnDotFieldOcc <$> f
|
| 419 | - rs_table = [("getField", getField)]
|
|
| 419 | + rs_table = Rebindable [(nameOccName getFieldName, getField)]
|
|
| 420 | 420 | ; return (HsGetField rs_table e f', fv_e `plusFN` fv_getField) }
|
| 421 | 421 | |
| 422 | 422 | rnExpr (HsProjection _ fs)
|
| 423 | 423 | = do { (getFieldName, fv_getField) <- lookupSyntaxName getFieldName
|
| 424 | 424 | ; circName <- lookupOccRn WL_TermVariable compose_RDR
|
| 425 | 425 | ; let fs' = NE.map rnDotFieldOcc fs
|
| 426 | - rs_table = [("getField" , getFieldName), ("circ", circName)]
|
|
| 426 | + rs_table = Rebindable [(nameOccName getFieldName , getFieldName), (rdrNameOcc compose_RDR, circName)]
|
|
| 427 | 427 | ; return (HsProjection rs_table fs', unitFN circName `plusFN` fv_getField) }
|
| 428 | 428 | |
| 429 | 429 | ------------------------------------------
|
| ... | ... | @@ -487,10 +487,10 @@ rnExpr (ExplicitList _ exps) |
| 487 | 487 | = do { (exps', fvs) <- rnExprs exps
|
| 488 | 488 | ; opt_OverloadedLists <- xoptM LangExt.OverloadedLists
|
| 489 | 489 | ; if not opt_OverloadedLists
|
| 490 | - then return (ExplicitList Nothing exps', fvs)
|
|
| 490 | + then return (ExplicitList NoRebindable exps', fvs)
|
|
| 491 | 491 | else
|
| 492 | 492 | do { (from_list_n_name, fvs') <- lookupSyntaxName fromListNName
|
| 493 | - ; let rs_table = Just [("fromListN", from_list_n_name)]
|
|
| 493 | + ; let rs_table = Rebindable [(nameOccName fromListNName, from_list_n_name)]
|
|
| 494 | 494 | rn_list = ExplicitList rs_table exps'
|
| 495 | 495 | ; return ( rn_list
|
| 496 | 496 | , fvs `plusFN` fvs') } }
|
| ... | ... | @@ -536,7 +536,7 @@ rnExpr (RecordUpd { rupd_expr = L l expr, rupd_flds = rbinds }) |
| 536 | 536 | RegularRecUpdFields
|
| 537 | 537 | { xRecUpdFields = parents
|
| 538 | 538 | , recUpdFields = flds }
|
| 539 | - ; return ( RecordUpd Nothing (L l e) upd_flds
|
|
| 539 | + ; return ( RecordUpd NoRebindable (L l e) upd_flds
|
|
| 540 | 540 | , fv_e `plusFN` fv_flds ) }
|
| 541 | 541 | |
| 542 | 542 | -- 'OverloadedRecordUpdate' is in effect. Record dot update desugaring.
|
| ... | ... | @@ -554,7 +554,7 @@ rnExpr (RecordUpd { rupd_expr = L l expr, rupd_flds = rbinds }) |
| 554 | 554 | ; let upd_flds = OverloadedRecUpdFields
|
| 555 | 555 | { xOLRecUpdFields = noExtField
|
| 556 | 556 | , olRecUpdFields = us }
|
| 557 | - rs_table = Just [("getFieldName", getField) , ("setFieldName", setField)]
|
|
| 557 | + rs_table = Rebindable [(nameOccName getField, getField) , (nameOccName getField, setField)]
|
|
| 558 | 558 | ; return (RecordUpd rs_table (L l e) upd_flds
|
| 559 | 559 | , plusFNs [fv_getField, fv_setField, fv_e, fv_us] )
|
| 560 | 560 | }
|
| ... | ... | @@ -2698,11 +2698,11 @@ rnHsIf p b1 b2 |
| 2698 | 2698 | ; mb_ite <- lookupIfThenElse
|
| 2699 | 2699 | ; case mb_ite of
|
| 2700 | 2700 | Nothing -- Non rebindable-syntax case
|
| 2701 | - -> return (HsIf Nothing p' b1' b2', fvs_if)
|
|
| 2701 | + -> return (HsIf NoRebindable p' b1' b2', fvs_if)
|
|
| 2702 | 2702 | |
| 2703 | 2703 | Just ite_name -- Rebindable-syntax case
|
| 2704 | 2704 | -> do { let fvs = plusFNs [fvs_if, unitFN ite_name]
|
| 2705 | - ; return (HsIf (Just [("ifThenElse" , ite_name)]) p' b1' b2', fvs) } }
|
|
| 2705 | + ; return (HsIf (Rebindable [(rdrNameOcc $ mkVarUnqual (fsLit "ifThenElse"), ite_name)]) p' b1' b2', fvs) } }
|
|
| 2706 | 2706 | |
| 2707 | 2707 | |
| 2708 | 2708 | rnHsUpdProjs :: [LHsRecUpdProj GhcPs] -> RnM ([LHsRecUpdProj GhcRn], FreeNames)
|
| ... | ... | @@ -5,30 +5,34 @@ |
| 5 | 5 | (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
|
| 6 | 6 | -}
|
| 7 | 7 | |
| 8 | -module GHC.Tc.Gen.Expand( tcExpand ) where
|
|
| 8 | +module GHC.Tc.Gen.Expand( tcExpand, tcExpandNoTcM ) where
|
|
| 9 | 9 | |
| 10 | 10 | import GHC.Prelude hiding (last, init, tail)
|
| 11 | - |
|
| 12 | -import {-# SOURCE #-} GHC.Tc.Gen.Splice( getUntypedSpliceBody )
|
|
| 11 | +import GHC.Data.FastString
|
|
| 13 | 12 | |
| 14 | 13 | import GHC.Hs
|
| 15 | 14 | |
| 16 | 15 | import GHC.Tc.Utils.Monad
|
| 17 | 16 | import GHC.Tc.Types.ErrCtxt
|
| 18 | 17 | import GHC.Tc.Gen.Do
|
| 18 | +import {-# SOURCE #-} GHC.Tc.Gen.Splice( getUntypedSpliceBody )
|
|
| 19 | 19 | |
| 20 | 20 | import GHC.Types.Name
|
| 21 | +import GHC.Types.Name.Reader
|
|
| 21 | 22 | import GHC.Types.Id.Make
|
| 22 | 23 | import GHC.Types.SrcLoc
|
| 23 | 24 | import GHC.Types.SourceText ( mkIntegralLit , SourceText(..) )
|
| 24 | 25 | |
| 26 | +import GHC.Builtin.Names
|
|
| 27 | + |
|
| 25 | 28 | import GHC.Rename.Utils
|
| 26 | -import qualified Data.List.NonEmpty as NE ( map, head, (<|) )
|
|
| 27 | -import Data.List.NonEmpty ( NonEmpty(..), init, last, tail )
|
|
| 28 | 29 | |
| 29 | 30 | import GHC.Utils.Panic
|
| 30 | 31 | import GHC.Utils.Outputable
|
| 31 | 32 | |
| 33 | +import qualified Data.List.NonEmpty as NE ( map, head, (<|) )
|
|
| 34 | +import Data.List.NonEmpty ( NonEmpty(..), init, last, tail )
|
|
| 35 | + |
|
| 32 | 36 | import qualified GHC.LanguageExtensions as LangExt
|
| 33 | 37 | |
| 34 | 38 | {- Note [Typechecking by expansion: overview]
|
| ... | ... | @@ -116,14 +120,15 @@ Wrinkle (TBE1) |
| 116 | 120 | |
| 117 | 121 | -- See Note [Typechecking by expansion: overview]
|
| 118 | 122 | tcExpand :: HsExpr GhcRn -> TcM (Maybe (HsExpansion GhcRn))
|
| 123 | +tcExpandNoTcM :: HsExpr GhcRn -> Maybe (HsExpansion GhcRn)
|
|
| 119 | 124 | |
| 120 | 125 | ------------------------------------------
|
| 121 | 126 | -- Overloaded labels
|
| 122 | -tcExpand e@(HsOverLabel (_, rs_table) v)
|
|
| 123 | - | Just fromLabelName <- lookup "fromLabel" rs_table
|
|
| 127 | +tcExpandNoTcM e@(HsOverLabel (_, Rebindable rs_table) v)
|
|
| 128 | + | Just fromLabelName <- lookup (nameOccName fromLabelClassOpName) rs_table
|
|
| 124 | 129 | , let hs_ty_arg = mkEmptyWildCardBndrs $ wrapGenSpan $
|
| 125 | 130 | HsTyLit noExtField (HsString NoSourceText v)
|
| 126 | - = return $ Just $
|
|
| 131 | + = Just $
|
|
| 127 | 132 | HSE { hse_ctxt = ExprCtxt e
|
| 128 | 133 | , hse_exp = wrapGenSpan $ HsAppType noExtField (genLHsVar fromLabelName) hs_ty_arg
|
| 129 | 134 | }
|
| ... | ... | @@ -134,26 +139,92 @@ tcExpand e@(HsOverLabel (_, rs_table) v) |
| 134 | 139 | |
| 135 | 140 | ------------------------------------------
|
| 136 | 141 | -- Qualified Literals
|
| 137 | -tcExpand e@(HsQualLit _ QualLit{ql_val = ql_val, ql_ext = (L _ fromStringName)})
|
|
| 142 | +tcExpandNoTcM e@(HsQualLit _ QualLit{ql_val = ql_val, ql_ext = (L _ fromStringName)})
|
|
| 138 | 143 | = do { let hsLit = case ql_val of
|
| 139 | 144 | -- See Note [Implementation of QualifiedStrings]
|
| 140 | 145 | HsQualString st s -> HsString st s
|
| 141 | - ; return $ Just $
|
|
| 142 | - HSE { hse_ctxt = ExprCtxt e
|
|
| 143 | - , hse_exp = wrapGenSpan $ genHsApps fromStringName [genLHsLit hsLit]
|
|
| 144 | - }
|
|
| 146 | + ; Just $
|
|
| 147 | + HSE { hse_ctxt = ExprCtxt e
|
|
| 148 | + , hse_exp = wrapGenSpan $ genHsApps fromStringName [genLHsLit hsLit]
|
|
| 149 | + }
|
|
| 145 | 150 | }
|
| 146 | 151 | |
| 147 | 152 | |
| 148 | 153 | ------------------------------------------
|
| 149 | 154 | -- Operator Applications
|
| 150 | -tcExpand e@(OpApp _ arg1 op arg2)
|
|
| 151 | - = return $ Just $
|
|
| 155 | +tcExpandNoTcM e@(OpApp _ arg1 op arg2)
|
|
| 156 | + = Just $
|
|
| 152 | 157 | HSE { hse_ctxt = ExprCtxt e
|
| 153 | 158 | , hse_exp = foldl ap op [arg1,arg2] }
|
| 154 | 159 | where
|
| 155 | 160 | ap f a = wrapGenSpan (HsApp noExtField f a)
|
| 156 | 161 | |
| 162 | +------------------------------------------
|
|
| 163 | +-- If
|
|
| 164 | + |
|
| 165 | +-- NoRebindable <=> rebindable is turned off
|
|
| 166 | +-- so we typecheck the HsIf in tcExprNoExpand
|
|
| 167 | +tcExpandNoTcM (HsIf NoRebindable _ _ _ )
|
|
| 168 | + = Nothing
|
|
| 169 | +tcExpandNoTcM e@(HsIf (Rebindable rs_table) p b1 b2)
|
|
| 170 | + | Just ifThenElseName <- lookup (rdrNameOcc $ mkVarUnqual (fsLit "ifThenElse")) rs_table
|
|
| 171 | + = Just $
|
|
| 172 | + HSE { hse_ctxt = ExprCtxt e
|
|
| 173 | + , hse_exp = wrapGenSpan $ genHsApps ifThenElseName [p, b1, b2]
|
|
| 174 | + }
|
|
| 175 | + | otherwise
|
|
| 176 | + = pprPanic "tcExpand" (vcat [ text "Should Never Happen: could not find ifThenElse in rs_table"
|
|
| 177 | + , ppr e ])
|
|
| 178 | + |
|
| 179 | +------------------------------------------
|
|
| 180 | +-- Record dot syntax
|
|
| 181 | + |
|
| 182 | +tcExpandNoTcM e@(HsGetField (Rebindable rs_table) expr f)
|
|
| 183 | + | Just getField <- lookup (nameOccName getFieldName) rs_table
|
|
| 184 | + = Just $
|
|
| 185 | + HSE { hse_ctxt = ExprCtxt e
|
|
| 186 | + , hse_exp = wrapGenSpan $ (mkGetField getField expr (fmap (unLoc . dfoLabel) f)) }
|
|
| 187 | + | otherwise
|
|
| 188 | + = pprPanic "tcExpand" (vcat [ text "Should Never Happen: could not find getField in rs_table"
|
|
| 189 | + , ppr e ])
|
|
| 190 | + |
|
| 191 | +tcExpandNoTcM e@(HsProjection (Rebindable rs_table) fs)
|
|
| 192 | + | Just getField <- lookup (nameOccName getFieldName) rs_table
|
|
| 193 | + , Just circ <- lookup (rdrNameOcc compose_RDR) rs_table
|
|
| 194 | + = Just $
|
|
| 195 | + HSE { hse_ctxt = ExprCtxt e
|
|
| 196 | + , hse_exp = wrapGenSpan $ (mkProjection getField circ $ NE.map (unLoc . dfoLabel) fs) }
|
|
| 197 | + | otherwise
|
|
| 198 | + = pprPanic "tcExpand" (vcat [ text "Should Never Happen: could not find getField or circ in rs_table"
|
|
| 199 | + , ppr e])
|
|
| 200 | + |
|
| 201 | + |
|
| 202 | +tcExpandNoTcM (RecordUpd NoRebindable _ _ ) = Nothing -- until #27160 is fixed
|
|
| 203 | + |
|
| 204 | +tcExpandNoTcM e@(RecordUpd (Rebindable rs_table) (L l expr) (OverloadedRecUpdFields { olRecUpdFields = us}))
|
|
| 205 | + | Just getField <- lookup (nameOccName getFieldName) rs_table
|
|
| 206 | + , Just setField <- lookup (nameOccName setFieldName) rs_table
|
|
| 207 | + = Just $
|
|
| 208 | + HSE { hse_ctxt = ExprCtxt e
|
|
| 209 | + , hse_exp = wrapGenSpan $ mkRecordDotUpd getField setField (L l expr) us }
|
|
| 210 | + | otherwise
|
|
| 211 | + = pprPanic "tcExpand" (vcat [ text "Should Never Happen: could not find getField or setfield in rs_table"
|
|
| 212 | + , ppr e ])
|
|
| 213 | + |
|
| 214 | + |
|
| 215 | + |
|
| 216 | +------------------------
|
|
| 217 | +-- XExpr
|
|
| 218 | +-- Expansions are idempotent, XExprs do not expand again
|
|
| 219 | +tcExpandNoTcM (XExpr (ExpandedThingRn hse))
|
|
| 220 | + = Just hse
|
|
| 221 | + |
|
| 222 | + |
|
| 223 | +tcExpandNoTcM _
|
|
| 224 | + = Nothing
|
|
| 225 | + |
|
| 226 | + |
|
| 227 | + |
|
| 157 | 228 | ------------------------------------------
|
| 158 | 229 | -- Left and Right Sections
|
| 159 | 230 | |
| ... | ... | @@ -174,15 +245,20 @@ tcExpand e@(SectionL _ expr op) |
| 174 | 245 | HSE { hse_ctxt = ExprCtxt e
|
| 175 | 246 | , hse_exp = wrapGenSpan ds_section } }
|
| 176 | 247 | |
| 177 | -tcExpand (ExplicitList Nothing _ )
|
|
| 248 | +------------------------------------------
|
|
| 249 | +-- Explicit Lists
|
|
| 250 | + |
|
| 251 | +tcExpand (ExplicitList NoRebindable _ )
|
|
| 178 | 252 | = return Nothing -- rebindable syntax is off
|
| 179 | -tcExpand e@(ExplicitList (Just rs_table) exps)
|
|
| 180 | - | Just from_list_n_name <- lookup "fromListN" rs_table
|
|
| 253 | +tcExpand e@(ExplicitList (Rebindable rs_table) exps)
|
|
| 254 | + | Just from_list_n_name <- lookup (nameOccName fromListNName) rs_table
|
|
| 181 | 255 | = do { loc <- getSrcSpanM -- See Note [Source locations for implicit function calls]
|
| 182 | 256 | ; let lit_n = mkIntegralLit (length exps)
|
| 183 | 257 | hs_lit = genHsIntegralLit lit_n
|
| 184 | 258 | exp_list = genHsApps' (wrapGenSpan' loc from_list_n_name)
|
| 185 | - [hs_lit, wrapGenSpan (ExplicitList Nothing exps)]
|
|
| 259 | + [hs_lit, wrapGenSpan (ExplicitList NoRebindable exps)]
|
|
| 260 | + -- important to make it NoRebindable
|
|
| 261 | + -- Or we will go into an infinite loop
|
|
| 186 | 262 | ; return $ Just $
|
| 187 | 263 | HSE { hse_ctxt = ExprCtxt e
|
| 188 | 264 | , hse_exp = wrapGenSpan $ exp_list }
|
| ... | ... | @@ -193,7 +269,7 @@ tcExpand e@(ExplicitList (Just rs_table) exps) |
| 193 | 269 | |
| 194 | 270 | |
| 195 | 271 | ------------------------------------------
|
| 196 | --- Do expression statements
|
|
| 272 | +-- Do statements
|
|
| 197 | 273 | |
| 198 | 274 | tcExpand (HsDo _ do_or_lc stmts)
|
| 199 | 275 | | DoExpr{} <- do_or_lc
|
| ... | ... | @@ -214,66 +290,6 @@ tcExpand (HsDo _ do_or_lc stmts) |
| 214 | 290 | -- GHCiStmts are handled completely separate
|
| 215 | 291 | = return Nothing
|
| 216 | 292 | |
| 217 | -------------------------------------------
|
|
| 218 | --- If
|
|
| 219 | - |
|
| 220 | --- Nothing <=> rebindable is turned off
|
|
| 221 | --- so we typecheck the HsIf in tcExprNoExpand
|
|
| 222 | -tcExpand (HsIf Nothing _ _ _ )
|
|
| 223 | - = return Nothing
|
|
| 224 | -tcExpand e@(HsIf (Just rs_table) p b1 b2)
|
|
| 225 | - | Just ifThenElseName <- lookup "ifThenElse" rs_table
|
|
| 226 | - = return $ Just $
|
|
| 227 | - HSE { hse_ctxt = ExprCtxt e
|
|
| 228 | - , hse_exp = wrapGenSpan $ genHsApps ifThenElseName [p, b1, b2]
|
|
| 229 | - }
|
|
| 230 | - | otherwise
|
|
| 231 | - = pprPanic "tcExpand" (vcat [ text "Should Never Happen: could not find ifThenElse in rs_table"
|
|
| 232 | - , ppr e ])
|
|
| 233 | - |
|
| 234 | -------------------------------------------
|
|
| 235 | --- Record dot syntax
|
|
| 236 | - |
|
| 237 | -tcExpand e@(HsGetField rs_table expr f)
|
|
| 238 | - | Just getFieldName <- lookup "getField" rs_table
|
|
| 239 | - = return $ Just $
|
|
| 240 | - HSE { hse_ctxt = ExprCtxt e
|
|
| 241 | - , hse_exp = wrapGenSpan $ (mkGetField getFieldName expr (fmap (unLoc . dfoLabel) f)) }
|
|
| 242 | - | otherwise
|
|
| 243 | - = pprPanic "tcExpand" (vcat [ text "Should Never Happen: could not find getField in rs_table"
|
|
| 244 | - , ppr e ])
|
|
| 245 | - |
|
| 246 | -tcExpand e@(HsProjection rs_table fs)
|
|
| 247 | - | Just getFieldName <- lookup "getField" rs_table
|
|
| 248 | - , Just circName <- lookup "circ" rs_table
|
|
| 249 | - = return $ Just $
|
|
| 250 | - HSE { hse_ctxt = ExprCtxt e
|
|
| 251 | - , hse_exp = wrapGenSpan $ (mkProjection getFieldName circName $ NE.map (unLoc . dfoLabel) fs) }
|
|
| 252 | - | otherwise
|
|
| 253 | - = pprPanic "tcExpand" (vcat [ text "Should Never Happen: could not find getField or circ in rs_table"
|
|
| 254 | - , ppr e])
|
|
| 255 | - |
|
| 256 | - |
|
| 257 | -tcExpand (RecordUpd Nothing _ _ ) = return Nothing -- until #27160 is fixed
|
|
| 258 | - |
|
| 259 | -tcExpand e@(RecordUpd (Just rs_table) (L l expr) (OverloadedRecUpdFields { olRecUpdFields = us}))
|
|
| 260 | - | Just getFieldName <- lookup "getFieldName" rs_table
|
|
| 261 | - , Just setFieldName <- lookup "setFieldName" rs_table
|
|
| 262 | - = return $ Just $
|
|
| 263 | - HSE { hse_ctxt = ExprCtxt e
|
|
| 264 | - , hse_exp = wrapGenSpan $ mkRecordDotUpd getFieldName setFieldName (L l expr) us }
|
|
| 265 | - | otherwise
|
|
| 266 | - = pprPanic "tcExpand" (vcat [ text "Should Never Happen: could not find getField or setfield in rs_table"
|
|
| 267 | - , ppr e ])
|
|
| 268 | - |
|
| 269 | - |
|
| 270 | - |
|
| 271 | -------------------------
|
|
| 272 | --- XExpr
|
|
| 273 | --- Expansions are idempotent, XExprs do not expand again
|
|
| 274 | -tcExpand (XExpr (ExpandedThingRn hse))
|
|
| 275 | - = return (Just hse)
|
|
| 276 | - |
|
| 277 | 293 | ------------------------------------------
|
| 278 | 294 | -- Template Haskell Splices
|
| 279 | 295 | |
| ... | ... | @@ -281,10 +297,11 @@ tcExpand e@(HsUntypedSplice splice_res _) |
| 281 | 297 | -- See Note [Looking through Template Haskell splices in splitHsApps]
|
| 282 | 298 | = do { fun <- getUntypedSpliceBody splice_res
|
| 283 | 299 | ; return $ Just $
|
| 284 | - HSE { hse_ctxt = ExprCtxt e
|
|
| 285 | - , hse_exp = wrapGenSpan fun } }
|
|
| 300 | + HSE { hse_ctxt = ExprCtxt e
|
|
| 301 | + , hse_exp = wrapGenSpan fun }
|
|
| 302 | + }
|
|
| 286 | 303 | |
| 287 | -tcExpand _ = return Nothing
|
|
| 304 | +tcExpand e = return $ tcExpandNoTcM e
|
|
| 288 | 305 | |
| 289 | 306 | |
| 290 | 307 |
| ... | ... | @@ -445,7 +445,7 @@ tcExprNoExpand e@HsQualLit{} _ = pprPanic "tcExpr: HsQualLit" (ppr e) |
| 445 | 445 | -- list type, so that's all we need concern ourselves with here. See
|
| 446 | 446 | -- GHC.Rename.Expr. Note [Handling overloaded and rebindable constructs]
|
| 447 | 447 | tcExprNoExpand (ExplicitList x exprs) res_ty
|
| 448 | - = assert (isNothing x) $
|
|
| 448 | + = assert (isNoRebindable x) $
|
|
| 449 | 449 | do { res_ty <- expTypeToType res_ty
|
| 450 | 450 | ; (coi, elt_ty) <- matchExpectedListTy res_ty
|
| 451 | 451 | ; let tc_elt expr = tcCheckPolyExpr expr elt_ty
|
| ... | ... | @@ -540,7 +540,7 @@ tcExprNoExpand (HsCase ctxt scrut matches) res_ty |
| 540 | 540 | tcExprNoExpand (HsIf x pred b1 b2) res_ty
|
| 541 | 541 | -- HsIf in rebindable case would be expanded out so we would not
|
| 542 | 542 | -- have a Just RebindableSyntaxTable here, only Nothing
|
| 543 | - = assert (isNothing x) $
|
|
| 543 | + = assert (isNoRebindable x) $
|
|
| 544 | 544 | do { pred' <- tcCheckMonoExpr pred boolTy
|
| 545 | 545 | ; let res_ty' = adjustExpTypeForCaseBranches res_ty [b1,b2]
|
| 546 | 546 | ; (u1,b1') <- tcCollectingUsage $ tcMonoLExpr b1 res_ty'
|
| ... | ... | @@ -680,7 +680,7 @@ tcExprNoExpand expr@(RecordCon { rcon_con = L loc qcon@(WithUserRdr _ con_name) |
| 680 | 680 | orig = OccurrenceOf con_name
|
| 681 | 681 | |
| 682 | 682 | -- Record updates via dot syntax are replaced by expanded expressions
|
| 683 | --- in the renamer. See Note [Overview of record dot syntax] in
|
|
| 683 | +-- in GHC.Tc.Expand. See Note [Overview of record dot syntax] in
|
|
| 684 | 684 | -- GHC.Hs.Expr. This is why we match on 'rupd_flds = Left rbnds' here
|
| 685 | 685 | -- and panic otherwise.
|
| 686 | 686 | -- WIP: To be fixed soon (#27160) expandRecordUpd needs to return HsExpansion and not a separate ds_res_ty
|
| ... | ... | @@ -1644,7 +1644,7 @@ disambiguateRecordBinds record_expr record_rho possible_parents rbnds res_ty |
| 1644 | 1644 | RegularRecUpdFields
|
| 1645 | 1645 | { xRecUpdFields = parents
|
| 1646 | 1646 | , recUpdFields = rbnds }
|
| 1647 | - , rupd_ext = Nothing }
|
|
| 1647 | + , rupd_ext = NoRebindable }
|
|
| 1648 | 1648 | loc = getLocA (head rbnds)
|
| 1649 | 1649 | |
| 1650 | 1650 | {-
|
| ... | ... | @@ -1087,7 +1087,7 @@ tcPatToExpr args pat = go pat |
| 1087 | 1087 | go1 (ParPat _ pat) = fmap (HsPar noExtField) (go pat)
|
| 1088 | 1088 | go1 (ListPat _ pats)
|
| 1089 | 1089 | = do { exprs <- mapM go pats
|
| 1090 | - ; return $ ExplicitList Nothing exprs }
|
|
| 1090 | + ; return $ ExplicitList NoRebindable exprs }
|
|
| 1091 | 1091 | go1 (TuplePat _ pats box) = do { exprs <- mapM go pats
|
| 1092 | 1092 | ; return $ ExplicitTuple noExtField
|
| 1093 | 1093 | (map (Present noExtField) exprs) box }
|