recursion-ninja pushed to branch wip/fix-26670 at Glasgow Haskell Compiler / GHC
Commits:
-
7a5b0700
by Recursion Ninja at 2025-12-22T20:06:56-05:00
15 changed files:
- compiler/GHC/Core/Opt/Simplify/Iteration.hs
- compiler/GHC/Core/Opt/Specialise.hs
- compiler/GHC/Core/Opt/WorkWrap.hs
- compiler/GHC/Core/Rules.hs
- compiler/GHC/CoreToIface.hs
- compiler/GHC/HsToCore/Binds.hs
- compiler/GHC/Iface/Syntax.hs
- compiler/GHC/Tc/Gen/Sig.hs
- compiler/GHC/Tc/TyCl/Instance.hs
- compiler/GHC/Types/Id.hs
- compiler/GHC/Types/Id/Info.hs
- compiler/GHC/Types/Id/Make.hs
- compiler/GHC/Types/InlinePragma.hs
- compiler/Language/Haskell/Syntax/Binds/InlinePragma.hs
- compiler/Language/Haskell/Syntax/Extension.hs
Changes:
| ... | ... | @@ -655,32 +655,19 @@ tryCastWorkerWrapper env _ _ bndr rhs -- All other bindings |
| 655 | 655 | , text "rhs:" <+> ppr rhs ])
|
| 656 | 656 | ; return (mkFloatBind env (NonRec bndr rhs)) }
|
| 657 | 657 | |
| 658 | -mkCastWrapperInlinePrag :: InlinePragma GhcRn -> InlinePragma GhcRn
|
|
| 658 | +mkCastWrapperInlinePrag :: InlinePragma GhcTc -> InlinePragma GhcTc
|
|
| 659 | 659 | -- See Note [Cast worker/wrapper]
|
| 660 | 660 | mkCastWrapperInlinePrag prag = prag
|
| 661 | - -- Consider each field of the 'InlinePragma' constructor
|
|
| 662 | - -- and deterimine what is the appropriate definition for the
|
|
| 663 | - -- corresponding value used within a worker/wrapper.
|
|
| 664 | - --
|
|
| 665 | - -- 1. 'inl_ext': Overwrite with defaults
|
|
| 666 | - -- > Changes <SOME>
|
|
| 667 | 661 | `setInlinePragmaSource` src_txt
|
| 668 | - `setInlinePragmaSaturation` AnySaturation
|
|
| 669 | - --
|
|
| 670 | - -- 2. 'inl_inline': *Preserve*
|
|
| 671 | - -- See Note [Worker/wrapper for INLINABLE functions]
|
|
| 662 | + `setInlinePragmaSaturation` AnySaturation
|
|
| 663 | + `setInlinePragmaActivation` wrap_act
|
|
| 664 | + -- 1. 'Activation' is conditionally updated
|
|
| 665 | + -- See Note [Wrapper activation]
|
|
| 672 | 666 | -- in GHC.Core.Opt.WorkWrap
|
| 673 | - -- > Changes <NONE>
|
|
| 674 | - --
|
|
| 675 | - -- 3. 'inl_act': Conditionally Update
|
|
| 676 | - -- See Note [Wrapper activation]
|
|
| 667 | + -- 2. 'InlineSpec' is also preserved
|
|
| 668 | + -- See Note [Worker/wrapper for INLINABLE functions]
|
|
| 677 | 669 | -- in GHC.Core.Opt.WorkWrap
|
| 678 | - -- > Changes <SOME>
|
|
| 679 | - `setInlinePragmaActivation` wrap_act
|
|
| 680 | - --
|
|
| 681 | - -- 4. 'inl_rule': *Preserve*
|
|
| 682 | - -- RuleMatchInfo is (and must be) unaffected
|
|
| 683 | - -- > Changes <NONE>
|
|
| 670 | + -- 3. 'RuleMatchInfo' is (and must be) unaffected
|
|
| 684 | 671 | where
|
| 685 | 672 | -- See Note [Wrapper activation] in GHC.Core.Opt.WorkWrap
|
| 686 | 673 | -- But simpler, because we don't need to disable during InitialPhase
|
| ... | ... | @@ -44,7 +44,7 @@ import GHC.Data.Bag |
| 44 | 44 | import GHC.Data.OrdList
|
| 45 | 45 | import GHC.Data.List.SetOps
|
| 46 | 46 | |
| 47 | -import GHC.Hs.Extension ( GhcPass, GhcRn )
|
|
| 47 | +import GHC.Hs.Extension ( GhcPass )
|
|
| 48 | 48 | |
| 49 | 49 | import GHC.Types.Basic
|
| 50 | 50 | import GHC.Types.Unique.Supply
|
| ... | ... | @@ -1641,7 +1641,6 @@ specCalls spec_imp env existing_rules calls_for_me fn rhs |
| 1641 | 1641 | |
| 1642 | 1642 | -- Copy InlinePragma information from the parent Id.
|
| 1643 | 1643 | -- So if f has INLINE[1] so does spec_fn
|
| 1644 | - spec_inl_prag :: InlinePragma GhcRn
|
|
| 1645 | 1644 | spec_inl_prag
|
| 1646 | 1645 | | not is_local -- See Note [Specialising imported functions]
|
| 1647 | 1646 | , isStrongLoopBreaker (idOccInfo fn) -- in GHC.Core.Opt.OccurAnal
|
| ... | ... | @@ -22,7 +22,7 @@ import GHC.Core.SimpleOpt |
| 22 | 22 | |
| 23 | 23 | import GHC.Data.FastString
|
| 24 | 24 | |
| 25 | -import GHC.Hs.Extension (GhcPass, GhcRn)
|
|
| 25 | +import GHC.Hs.Extension (GhcPass, GhcTc)
|
|
| 26 | 26 | |
| 27 | 27 | import GHC.Types.Var
|
| 28 | 28 | import GHC.Types.Id
|
| ... | ... | @@ -897,7 +897,7 @@ mkWWBindPair ww_opts fn_id fn_info fn_args fn_body work_uniq div |
| 897 | 897 | fn_unfolding = realUnfoldingInfo fn_info
|
| 898 | 898 | fn_rules = ruleInfoRules (ruleInfo fn_info)
|
| 899 | 899 | |
| 900 | -mkStrWrapperInlinePrag :: InlinePragma (GhcPass p) -> [CoreRule] -> InlinePragma GhcRn
|
|
| 900 | +mkStrWrapperInlinePrag :: InlinePragma (GhcPass p) -> [CoreRule] -> InlinePragma GhcTc
|
|
| 901 | 901 | mkStrWrapperInlinePrag (InlinePragma { inl_inline = fn_inl
|
| 902 | 902 | , inl_act = fn_act
|
| 903 | 903 | , inl_rule = rule_info }) rules
|
| ... | ... | @@ -67,7 +67,7 @@ import GHC.Core.Make ( mkCoreLams ) |
| 67 | 67 | import GHC.Core.Opt.OccurAnal( occurAnalyseExpr )
|
| 68 | 68 | import GHC.Core.Rules.Config (roBuiltinRules)
|
| 69 | 69 | |
| 70 | -import GHC.Hs.Extension ( GhcPass, GhcRn )
|
|
| 70 | +import GHC.Hs.Extension ( GhcPass, GhcTc )
|
|
| 71 | 71 | |
| 72 | 72 | import GHC.Tc.Utils.TcType ( tcSplitTyConApp_maybe )
|
| 73 | 73 | import GHC.Builtin.Types ( anyTypeOfKind )
|
| ... | ... | @@ -1930,7 +1930,7 @@ ruleCheckProgram ropts curr_phase rule_pat rules binds |
| 1930 | 1930 | in ds `unionBags` go env' binds
|
| 1931 | 1931 | |
| 1932 | 1932 | data RuleCheckEnv = RuleCheckEnv
|
| 1933 | - { rc_is_active :: Activation GhcRn -> Bool
|
|
| 1933 | + { rc_is_active :: Activation GhcTc -> Bool
|
|
| 1934 | 1934 | , rc_id_unf :: IdUnfoldingFun
|
| 1935 | 1935 | , rc_pattern :: String
|
| 1936 | 1936 | , rc_rules :: Id -> [CoreRule]
|
| ... | ... | @@ -87,7 +87,7 @@ import GHC.Utils.Outputable |
| 87 | 87 | import GHC.Utils.Panic
|
| 88 | 88 | import GHC.Utils.Misc
|
| 89 | 89 | |
| 90 | -import GHC.Hs.Extension (GhcRn)
|
|
| 90 | +import GHC.Hs.Extension ( GhcRn )
|
|
| 91 | 91 | |
| 92 | 92 | import Data.Maybe ( isNothing, catMaybes )
|
| 93 | 93 |
| ... | ... | @@ -1020,7 +1020,7 @@ dsSpec_help poly_nm poly_id poly_rhs spec_inl orig_bndrs ds_call |
| 1020 | 1020 | fn_unf = realIdUnfolding poly_id
|
| 1021 | 1021 | spec_unf = specUnfolding simpl_opts spec_bndrs mk_spec_body rule_lhs_args fn_unf
|
| 1022 | 1022 | spec_info = vanillaIdInfo
|
| 1023 | - `setInlinePragInfo` specFunInlinePrag poly_id id_inl (demoteInlinePragmaTc spec_inl)
|
|
| 1023 | + `setInlinePragInfo` specFunInlinePrag poly_id id_inl spec_inl
|
|
| 1024 | 1024 | `setUnfoldingInfo` spec_unf
|
| 1025 | 1025 | spec_id = mkLocalVar (idDetails poly_id) spec_name ManyTy spec_ty spec_info
|
| 1026 | 1026 | -- Specialised binding is toplevel, hence Many.
|
| ... | ... | @@ -1191,7 +1191,7 @@ getCastedVar (Var v) = Just (v, MRefl) |
| 1191 | 1191 | getCastedVar (Cast (Var v) co) = Just (v, MCo co)
|
| 1192 | 1192 | getCastedVar _ = Nothing
|
| 1193 | 1193 | |
| 1194 | -specFunInlinePrag :: Id -> InlinePragma GhcRn -> InlinePragma GhcRn -> InlinePragma GhcRn
|
|
| 1194 | +specFunInlinePrag :: Id -> InlinePragma GhcTc -> InlinePragma GhcTc -> InlinePragma GhcTc
|
|
| 1195 | 1195 | -- See Note [Activation pragmas for SPECIALISE]
|
| 1196 | 1196 | specFunInlinePrag poly_id id_inl spec_inl
|
| 1197 | 1197 | | not (isDefaultInlinePragma spec_inl) = spec_inl
|
| ... | ... | @@ -84,7 +84,7 @@ import GHC.Core.DataCon (SrcStrictness(..), SrcUnpackedness(..)) |
| 84 | 84 | import GHC.Builtin.Types ( constraintKindTyConName )
|
| 85 | 85 | import GHC.Stg.EnforceEpt.TagSig
|
| 86 | 86 | import GHC.Parser.Annotation (noLocA)
|
| 87 | -import GHC.Hs.Extension ( GhcRn )
|
|
| 87 | +import GHC.Hs.Extension ( GhcRn, GhcTc )
|
|
| 88 | 88 | import GHC.Hs.Doc ( WithHsDocIdentifiers(..) )
|
| 89 | 89 | |
| 90 | 90 | import GHC.Utils.Lexeme (isLexSym)
|
| ... | ... | @@ -460,7 +460,7 @@ data IfaceInfoItem |
| 460 | 460 | = HsArity Arity
|
| 461 | 461 | | HsDmdSig DmdSig
|
| 462 | 462 | | HsCprSig CprSig
|
| 463 | - | HsInline (InlinePragma GhcRn)
|
|
| 463 | + | HsInline (InlinePragma GhcTc)
|
|
| 464 | 464 | | HsUnfold Bool -- True <=> isStrongLoopBreaker is true
|
| 465 | 465 | IfaceUnfolding -- See Note [Expose recursive functions]
|
| 466 | 466 | | HsNoCafRefs
|
| ... | ... | @@ -620,11 +620,11 @@ addInlinePrags poly_id prags_for_me |
| 620 | 620 | | inl@(L _ prag) : inls <- inl_prags
|
| 621 | 621 | = do { traceTc "addInlinePrag" (ppr poly_id $$ ppr prag)
|
| 622 | 622 | ; unless (null inls) (warn_multiple_inlines inl inls)
|
| 623 | - ; return (poly_id `setInlinePragma` demoteInlinePragmaTc prag) }
|
|
| 623 | + ; return (poly_id `setInlinePragma` prag) }
|
|
| 624 | 624 | | otherwise
|
| 625 | 625 | = return poly_id
|
| 626 | 626 | where
|
| 627 | - inl_prags = [L loc (promoteInlinePragmaRn prag) | L loc (InlineSig _ _ prag) <- prags_for_me]
|
|
| 627 | + inl_prags = [L loc (witnessInlinePragmaPass prag) | L loc (InlineSig _ _ prag) <- prags_for_me]
|
|
| 628 | 628 | |
| 629 | 629 | warn_multiple_inlines _ [] = return ()
|
| 630 | 630 | |
| ... | ... | @@ -987,7 +987,7 @@ tcSpecPrag poly_id prag@(SpecSig _ fun_name hs_tys inl) |
| 987 | 987 | tc_one hs_ty
|
| 988 | 988 | = do { spec_ty <- tcHsSigType (FunSigCtxt name NoRRC) hs_ty
|
| 989 | 989 | ; wrap <- tcSpecWrapper (FunSigCtxt name (lhsSigTypeContextSpan hs_ty)) poly_ty spec_ty
|
| 990 | - ; return (SpecPrag poly_id wrap (promoteInlinePragmaRn inl)) }
|
|
| 990 | + ; return (SpecPrag poly_id wrap (witnessInlinePragmaPass inl)) }
|
|
| 991 | 991 | |
| 992 | 992 | tcSpecPrag poly_id (SpecSigE nm rule_bndrs spec_e inl)
|
| 993 | 993 | -- For running commentary, see Note [Handling new-form SPECIALISE pragmas]
|
| ... | ... | @@ -1050,7 +1050,7 @@ tcSpecPrag poly_id (SpecSigE nm rule_bndrs spec_e inl) |
| 1050 | 1050 | , spe_bndrs = qevs ++ rule_bndrs' -- Dependency order
|
| 1051 | 1051 | -- does not matter
|
| 1052 | 1052 | , spe_call = lhs_call
|
| 1053 | - , spe_inl = promoteInlinePragmaRn inl }] }
|
|
| 1053 | + , spe_inl = witnessInlinePragmaPass inl }] }
|
|
| 1054 | 1054 | |
| 1055 | 1055 | tcSpecPrag _ prag = pprPanic "tcSpecPrag" (ppr prag)
|
| 1056 | 1056 |
| ... | ... | @@ -2264,7 +2264,7 @@ mkDefMethBind :: SrcSpan -> DFunId -> Class -> Id -> Name |
| 2264 | 2264 | mkDefMethBind loc dfun_id clas sel_id dm_name dm_spec
|
| 2265 | 2265 | = do { logger <- getLogger
|
| 2266 | 2266 | ; dm_id <- tcLookupId dm_name
|
| 2267 | - ; let inline_prag = idInlinePragma dm_id
|
|
| 2267 | + ; let inline_prag = witnessInlinePragmaPass $ idInlinePragma dm_id
|
|
| 2268 | 2268 | inline_prags | isAnyInlinePragma inline_prag
|
| 2269 | 2269 | = [noLocA (InlineSig noAnn fn inline_prag)]
|
| 2270 | 2270 | | otherwise
|
| ... | ... | @@ -150,7 +150,7 @@ import GHC.Core.DataCon |
| 150 | 150 | import GHC.Core.Class
|
| 151 | 151 | import GHC.Core.Multiplicity
|
| 152 | 152 | |
| 153 | -import GHC.Hs.Extension (GhcRn)
|
|
| 153 | +import GHC.Hs.Extension (GhcTc)
|
|
| 154 | 154 | |
| 155 | 155 | import GHC.Types.RepType
|
| 156 | 156 | import GHC.Types.Demand
|
| ... | ... | @@ -796,7 +796,7 @@ alwaysActiveUnfoldingFun id |
| 796 | 796 | -- | Returns an unfolding only if
|
| 797 | 797 | -- (a) not a strong loop breaker and
|
| 798 | 798 | -- (b) active in according to is_active
|
| 799 | -whenActiveUnfoldingFun :: (Activation GhcRn -> Bool) -> IdUnfoldingFun
|
|
| 799 | +whenActiveUnfoldingFun :: (Activation GhcTc -> Bool) -> IdUnfoldingFun
|
|
| 800 | 800 | whenActiveUnfoldingFun is_active id
|
| 801 | 801 | | is_active (idInlineActivation id) = idUnfolding id
|
| 802 | 802 | | otherwise = NoUnfolding
|
| ... | ... | @@ -944,19 +944,19 @@ The inline pragma tells us to be very keen to inline this Id, but it's still |
| 944 | 944 | OK not to if optimisation is switched off.
|
| 945 | 945 | -}
|
| 946 | 946 | |
| 947 | -idInlinePragma :: Id -> InlinePragma GhcRn
|
|
| 947 | +idInlinePragma :: Id -> InlinePragma GhcTc
|
|
| 948 | 948 | idInlinePragma id = inlinePragInfo (idInfo id)
|
| 949 | 949 | |
| 950 | -setInlinePragma :: Id -> InlinePragma GhcRn -> Id
|
|
| 950 | +setInlinePragma :: Id -> InlinePragma GhcTc -> Id
|
|
| 951 | 951 | setInlinePragma id prag = modifyIdInfo (`setInlinePragInfo` prag) id
|
| 952 | 952 | |
| 953 | -modifyInlinePragma :: Id -> (InlinePragma GhcRn -> InlinePragma GhcRn) -> Id
|
|
| 953 | +modifyInlinePragma :: Id -> (InlinePragma GhcTc -> InlinePragma GhcTc) -> Id
|
|
| 954 | 954 | modifyInlinePragma id fn = modifyIdInfo (\info -> info `setInlinePragInfo` (fn (inlinePragInfo info))) id
|
| 955 | 955 | |
| 956 | -idInlineActivation :: Id -> Activation GhcRn
|
|
| 956 | +idInlineActivation :: Id -> Activation GhcTc
|
|
| 957 | 957 | idInlineActivation id = inlinePragmaActivation (idInlinePragma id)
|
| 958 | 958 | |
| 959 | -setInlineActivation :: Id -> Activation GhcRn -> Id
|
|
| 959 | +setInlineActivation :: Id -> Activation GhcTc -> Id
|
|
| 960 | 960 | setInlineActivation id act = modifyInlinePragma id (\prag -> setInlinePragmaActivation prag act)
|
| 961 | 961 | |
| 962 | 962 | idRuleMatchInfo :: Id -> RuleMatchInfo
|
| ... | ... | @@ -52,7 +52,7 @@ module GHC.Types.Id.Info ( |
| 52 | 52 | realUnfoldingInfo, unfoldingInfo, setUnfoldingInfo, hasInlineUnfolding,
|
| 53 | 53 | |
| 54 | 54 | -- ** The InlinePragInfo type
|
| 55 | - InlinePragInfo,
|
|
| 55 | + InlinePragmaInfo,
|
|
| 56 | 56 | inlinePragInfo, setInlinePragInfo,
|
| 57 | 57 | |
| 58 | 58 | -- ** The OccInfo type
|
| ... | ... | @@ -100,7 +100,6 @@ import GHC.Core.TyCon |
| 100 | 100 | import GHC.Core.Type (mkTyConApp)
|
| 101 | 101 | import GHC.Core.PatSyn
|
| 102 | 102 | import GHC.Core.ConLike
|
| 103 | -import GHC.Hs.Extension
|
|
| 104 | 103 | import GHC.Types.ForeignCall
|
| 105 | 104 | import GHC.Unit.Module
|
| 106 | 105 | import GHC.Types.Demand
|
| ... | ... | @@ -439,7 +438,7 @@ data IdInfo |
| 439 | 438 | -- See Note [Specialisations and RULES in IdInfo]
|
| 440 | 439 | realUnfoldingInfo :: Unfolding,
|
| 441 | 440 | -- ^ The 'Id's unfolding
|
| 442 | - inlinePragInfo :: InlinePragma GhcRn,
|
|
| 441 | + inlinePragInfo :: InlinePragmaInfo,
|
|
| 443 | 442 | -- ^ Any inline pragma attached to the 'Id'
|
| 444 | 443 | occInfo :: OccInfo,
|
| 445 | 444 | -- ^ How the 'Id' occurs in the program
|
| ... | ... | @@ -553,7 +552,7 @@ tagSigInfo = tagSig |
| 553 | 552 | setRuleInfo :: IdInfo -> RuleInfo -> IdInfo
|
| 554 | 553 | setRuleInfo info sp = sp `seq` info { ruleInfo = sp }
|
| 555 | 554 | |
| 556 | -setInlinePragInfo :: IdInfo -> InlinePragma GhcRn -> IdInfo
|
|
| 555 | +setInlinePragInfo :: IdInfo -> InlinePragmaInfo -> IdInfo
|
|
| 557 | 556 | setInlinePragInfo info pr = pr `seq` info { inlinePragInfo = pr }
|
| 558 | 557 | |
| 559 | 558 | setOccInfo :: IdInfo -> OccInfo -> IdInfo
|
| ... | ... | @@ -704,27 +703,6 @@ ppArityInfo :: Int -> SDoc |
| 704 | 703 | ppArityInfo 0 = empty
|
| 705 | 704 | ppArityInfo n = hsep [text "Arity", int n]
|
| 706 | 705 | |
| 707 | -{-
|
|
| 708 | -************************************************************************
|
|
| 709 | -* *
|
|
| 710 | -\subsection{Inline-pragma information}
|
|
| 711 | -* *
|
|
| 712 | -************************************************************************
|
|
| 713 | --}
|
|
| 714 | - |
|
| 715 | --- | Inline Pragma Information
|
|
| 716 | ---
|
|
| 717 | --- Tells when the inlining is active.
|
|
| 718 | --- When it is active the thing may be inlined, depending on how
|
|
| 719 | --- big it is.
|
|
| 720 | ---
|
|
| 721 | --- If there was an @INLINE@ pragma, then as a separate matter, the
|
|
| 722 | --- RHS will have been made to look small with a Core inline 'Note'
|
|
| 723 | ---
|
|
| 724 | --- The default 'InlinePragInfo' is 'AlwaysActive', so the info serves
|
|
| 725 | --- entirely as a way to inhibit inlining until we want it
|
|
| 726 | -type InlinePragInfo = InlinePragma
|
|
| 727 | - |
|
| 728 | 706 | {-
|
| 729 | 707 | ************************************************************************
|
| 730 | 708 | * *
|
| ... | ... | @@ -65,8 +65,6 @@ import GHC.Core.TyCon |
| 65 | 65 | import GHC.Core.Class
|
| 66 | 66 | import GHC.Core.DataCon
|
| 67 | 67 | |
| 68 | -import GHC.Hs.Extension (GhcRn)
|
|
| 69 | - |
|
| 70 | 68 | import GHC.Types.Literal
|
| 71 | 69 | import GHC.Types.RepType ( countFunRepArgs, typePrimRep )
|
| 72 | 70 | import GHC.Types.Name.Set
|
| ... | ... | @@ -608,7 +606,7 @@ mkDataConWorkId wkr_name data_con |
| 608 | 606 | -- See Note [Strict fields in Core]
|
| 609 | 607 | `setLFInfo` wkr_lf_info
|
| 610 | 608 | |
| 611 | - wkr_inline_prag :: InlinePragma GhcRn
|
|
| 609 | + wkr_inline_prag :: InlinePragmaInfo
|
|
| 612 | 610 | wkr_inline_prag = alwaysInlineConLikePragma
|
| 613 | 611 | wkr_arity = dataConRepArity data_con
|
| 614 | 612 | |
| ... | ... | @@ -989,7 +987,7 @@ mkDataConRep dc_bang_opts fam_envs wrap_name data_con |
| 989 | 987 | ; return (unbox_fn expr) }
|
| 990 | 988 | |
| 991 | 989 | |
| 992 | -dataConWrapperInlinePragma :: InlinePragma GhcRn
|
|
| 990 | +dataConWrapperInlinePragma :: InlinePragmaInfo
|
|
| 993 | 991 | -- See Note [DataCon wrappers are conlike]
|
| 994 | 992 | dataConWrapperInlinePragma = alwaysInlineConLikePragma
|
| 995 | 993 |
| ... | ... | @@ -24,6 +24,7 @@ module GHC.Types.InlinePragma |
| 24 | 24 | -- ** InlinePragma
|
| 25 | 25 | -- *** Data-type
|
| 26 | 26 | InlinePragma(..)
|
| 27 | + , InlinePragmaInfo
|
|
| 27 | 28 | -- *** Constants
|
| 28 | 29 | , defaultInlinePragma
|
| 29 | 30 | , alwaysInlinePragma
|
| ... | ... | @@ -51,8 +52,7 @@ module GHC.Types.InlinePragma |
| 51 | 52 | , setInlinePragmaSpec
|
| 52 | 53 | , setInlinePragmaRuleMatchInfo
|
| 53 | 54 | -- *** GHC pass conversions
|
| 54 | - , demoteInlinePragmaTc
|
|
| 55 | - , promoteInlinePragmaRn
|
|
| 55 | + , witnessInlinePragmaPass
|
|
| 56 | 56 | -- *** Pretty-printing
|
| 57 | 57 | , pprInline
|
| 58 | 58 | , pprInlineDebug
|
| ... | ... | @@ -148,6 +148,28 @@ instance NFData InlineSaturation where |
| 148 | 148 | rnf (AppliedToAtLeast !w) = rnf w `seq` ()
|
| 149 | 149 | rnf !AnySaturation = ()
|
| 150 | 150 | |
| 151 | + |
|
| 152 | +{-
|
|
| 153 | +************************************************************************
|
|
| 154 | +* *
|
|
| 155 | +\subsection{Inline-pragma information}
|
|
| 156 | +* *
|
|
| 157 | +************************************************************************
|
|
| 158 | +-}
|
|
| 159 | + |
|
| 160 | +-- | Inline Pragma Information
|
|
| 161 | +--
|
|
| 162 | +-- Tells when the inlining is active.
|
|
| 163 | +-- When it is active the thing may be inlined, depending on how
|
|
| 164 | +-- big it is.
|
|
| 165 | +--
|
|
| 166 | +-- If there was an @INLINE@ pragma, then as a separate matter, the
|
|
| 167 | +-- RHS will have been made to look small with a Core inline 'Note'
|
|
| 168 | +--
|
|
| 169 | +-- The default 'InlinePragInfo' is 'AlwaysActive', so the info serves
|
|
| 170 | +-- entirely as a way to inhibit inlining until we want it
|
|
| 171 | +type InlinePragmaInfo = InlinePragma GhcTc
|
|
| 172 | + |
|
| 151 | 173 | data XInlinePragmaGhc = XInlinePragmaGhc
|
| 152 | 174 | { xinl_src :: SourceText
|
| 153 | 175 | -- ^ See Note [Pragma source text]
|
| ... | ... | @@ -181,6 +203,14 @@ type instance XInlinePragma GhcTc = XInlinePragmaGhc |
| 181 | 203 | type instance XXInlinePragma (GhcPass _) = DataConCantHappen
|
| 182 | 204 | type instance XXActivation (GhcPass _) = XXActivationGhc
|
| 183 | 205 | |
| 206 | +witnessInlinePragmaPass :: forall p q.
|
|
| 207 | + (XInlinePragma (GhcPass p) ~ XInlinePragmaGhc, XInlinePragma (GhcPass q) ~ XInlinePragmaGhc)
|
|
| 208 | + => InlinePragma (GhcPass p) -> InlinePragma (GhcPass q)
|
|
| 209 | +witnessInlinePragmaPass prag@(InlinePragma { inl_ext = src }) =
|
|
| 210 | + prag { inl_ext = src
|
|
| 211 | + , inl_act = coerceActivation $ inl_act prag
|
|
| 212 | + }
|
|
| 213 | + |
|
| 184 | 214 | -- | The default 'InlinePragma' definition for GHC.
|
| 185 | 215 | -- The type and value of 'inl_ext' provided will differ
|
| 186 | 216 | -- between the passes of GHC. Consequently, it may be
|
| ... | ... | @@ -235,18 +265,6 @@ inlinePragmaSaturation :: forall p. (XInlinePragma (GhcPass p) ~ XInlinePragmaGh |
| 235 | 265 | => InlinePragma (GhcPass p) -> InlineSaturation
|
| 236 | 266 | inlinePragmaSaturation = xinl_sat . inl_ext
|
| 237 | 267 | |
| 238 | -promoteInlinePragmaRn :: InlinePragma GhcRn -> InlinePragma GhcTc
|
|
| 239 | -promoteInlinePragmaRn prag@(InlinePragma { inl_ext = src }) =
|
|
| 240 | - prag { inl_ext = src
|
|
| 241 | - , inl_act = coerceActivation $ inl_act prag
|
|
| 242 | - }
|
|
| 243 | - |
|
| 244 | -demoteInlinePragmaTc :: InlinePragma GhcTc -> InlinePragma GhcRn
|
|
| 245 | -demoteInlinePragmaTc prag@(InlinePragma { inl_ext = src }) =
|
|
| 246 | - prag { inl_ext = src
|
|
| 247 | - , inl_act = coerceActivation $ inl_act prag
|
|
| 248 | - }
|
|
| 249 | - |
|
| 250 | 268 | inlinePragmaSpec :: InlinePragma p -> InlineSpec
|
| 251 | 269 | inlinePragmaSpec = inl_inline
|
| 252 | 270 | |
| ... | ... | @@ -339,6 +357,26 @@ coerceActivation = \case |
| 339 | 357 | AlwaysActive -> AlwaysActive
|
| 340 | 358 | NeverActive -> NeverActive
|
| 341 | 359 | |
| 360 | +activeInPhase :: PhaseNum -> Activation (GhcPass p) -> Bool
|
|
| 361 | +activeInPhase _ AlwaysActive = True
|
|
| 362 | +activeInPhase _ NeverActive = False
|
|
| 363 | +activeInPhase _ ActiveFinal = False
|
|
| 364 | +activeInPhase p (ActiveAfter n) = p <= n
|
|
| 365 | +activeInPhase p (ActiveBefore n) = p > n
|
|
| 366 | + |
|
| 367 | +activeInFinalPhase :: Activation (GhcPass p) -> Bool
|
|
| 368 | +activeInFinalPhase AlwaysActive = True
|
|
| 369 | +activeInFinalPhase ActiveFinal = True
|
|
| 370 | +activeInFinalPhase (ActiveAfter {}) = True
|
|
| 371 | +activeInFinalPhase _ = False
|
|
| 372 | + |
|
| 373 | +isNeverActive, isAlwaysActive :: Activation p -> Bool
|
|
| 374 | +isNeverActive NeverActive = True
|
|
| 375 | +isNeverActive _ = False
|
|
| 376 | + |
|
| 377 | +isAlwaysActive AlwaysActive = True
|
|
| 378 | +isAlwaysActive _ = False
|
|
| 379 | + |
|
| 342 | 380 | activateAfterInitial :: Activation (GhcPass p)
|
| 343 | 381 | -- ^ Active in the first phase after the initial phase
|
| 344 | 382 | activateAfterInitial = activeAfter (nextPhase InitialPhase)
|
| ... | ... | @@ -43,11 +43,6 @@ module Language.Haskell.Syntax.Binds.InlinePragma |
| 43 | 43 | -- *** Data-type
|
| 44 | 44 | , Activation(..)
|
| 45 | 45 | , PhaseNum
|
| 46 | - -- *** Queries
|
|
| 47 | - , activeInPhase
|
|
| 48 | - , activeInFinalPhase
|
|
| 49 | - , isAlwaysActive
|
|
| 50 | - , isNeverActive
|
|
| 51 | 46 | ) where
|
| 52 | 47 | |
| 53 | 48 | import Language.Haskell.Syntax.Extension
|
| ... | ... | @@ -310,23 +305,3 @@ instance NFData (XXActivation p) => NFData (Activation p) where |
| 310 | 305 | ActiveBefore aa -> rnf aa
|
| 311 | 306 | ActiveAfter ab -> rnf ab
|
| 312 | 307 | XActivation x -> rnf x `seq` () |
| 313 | - |
|
| 314 | -activeInPhase :: PhaseNum -> Activation p -> Bool
|
|
| 315 | -activeInPhase _ AlwaysActive = True
|
|
| 316 | -activeInPhase _ NeverActive = False
|
|
| 317 | -activeInPhase _ (XActivation _) = False
|
|
| 318 | -activeInPhase p (ActiveAfter n) = p <= n
|
|
| 319 | -activeInPhase p (ActiveBefore n) = p > n
|
|
| 320 | - |
|
| 321 | -activeInFinalPhase :: Activation p -> Bool
|
|
| 322 | -activeInFinalPhase AlwaysActive = True
|
|
| 323 | -activeInFinalPhase (XActivation {}) = True
|
|
| 324 | -activeInFinalPhase (ActiveAfter {}) = True
|
|
| 325 | -activeInFinalPhase _ = False
|
|
| 326 | - |
|
| 327 | -isNeverActive, isAlwaysActive :: Activation p -> Bool
|
|
| 328 | -isNeverActive NeverActive = True
|
|
| 329 | -isNeverActive _ = False
|
|
| 330 | - |
|
| 331 | -isAlwaysActive AlwaysActive = True
|
|
| 332 | -isAlwaysActive _ = False |
| ... | ... | @@ -241,8 +241,8 @@ type family XCompleteMatchSig x |
| 241 | 241 | type family XXSig x
|
| 242 | 242 | |
| 243 | 243 | -- Inline Pragma families
|
| 244 | -type family XInlinePragma x
|
|
| 245 | -type family XXInlinePragma x
|
|
| 244 | +type family XInlinePragma x
|
|
| 245 | +type family XXInlinePragma x
|
|
| 246 | 246 | |
| 247 | 247 | -- Inline Activation family
|
| 248 | 248 | type family XXActivation x
|