Skip to content

Make profiling output include better source span #7722

Description

@SeungheonOh

Describe the feature you'd like

maybeProfileRhs
:: CompilingDefault uni fun m ann
=> GHC.Var
-> PLCVar uni
-> PIRTerm uni fun
-> m (PIRTerm uni fun)
maybeProfileRhs ghcVar var t = do
CompileContext {ccOpts = compileOpts} <- ask
let
nameStr = GHC.occNameString $ GHC.occName $ GHC.varName $ ghcVar
displayName = T.pack $
case getVarSourceSpan ghcVar of
-- When module is not compiled and GHC is using cached build from previous build, it will
-- lack source span. There's nothing much we can do about this here since this is GHC
-- behavior. Issue #7203
Nothing -> nameStr
Just src -> nameStr <> " (" <> show (src ^. srcSpanIso) <> ")"
ty = PLC._varDeclType var
isFunctionOrAbstraction = case ty of PLC.TyFun {} -> True; PLC.TyForall {} -> True; _ -> False
-- Trace only if profiling is on *and* the thing being defined is a function
if coProfile compileOpts == All && isFunctionOrAbstraction
then do
thunk <- PLC.freshName "thunk"
pure $ entryExitTracingInside thunk displayName t ty
else pure t

This function is used to insert call profiling information to each function calls which is used to run profiling and also call trace information. Currently, it gets source span from GHC.Var; source span attached to GHC.Var is only available if the module GHC.Var resides in gets compiled from scratch without compilation cache. So, to get accurate source spans for these profiling traces, one must always run cabal clean and if not it will add traces without source span.

It should be possible now to get accurate srcspan without needing cabal clean with #7640

Describe alternatives you've considered

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions