Skip to content

Commit be38083

Browse files
authored
Add SrcSpans of Vars in the compilation trace (#7299)
1 parent b486e58 commit be38083

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
### Added
2+
3+
- During compilation, if a `Var` carries `SrcSpan`, the `SrcSpan` is added to the
4+
compilation trace. The effect can be seen both in the full compilation trace
5+
(via `dump-compilation-trace`), or in the error message when the compilation fails.

plutus-tx-plugin/src/PlutusTx/Compiler/Expr.hs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -637,24 +637,30 @@ hoistExpr var t = do
637637
-- See Note [Dependency tracking]
638638
modifyCurDeps (Set.insert lexName)
639639
maybeDef <- PIR.lookupTerm lexName
640-
let addSpan = case getVarSourceSpan var of
640+
let varSpan = getVarSourceSpan var
641+
addSpan = case varSpan of
641642
Nothing -> id
642643
Just src -> fmap . fmap . addSrcSpan $ src ^. srcSpanIso
644+
varSpanMsg = case varSpan of
645+
Nothing -> ""
646+
Just src -> ", located at" GHC.<+> GHC.ppr src
643647
case maybeDef of
644648
Just term -> pure term
645649
-- See Note [Dependency tracking]
646-
Nothing -> withCurDef lexName . traceCompilation 1 ("Compiling definition of:" GHC.<+> GHC.ppr var) $ do
647-
var' <- compileVarFresh ann var
648-
-- See Note [Occurrences of recursive names]
649-
PIR.defineTerm
650-
lexName
651-
(PIR.Def var' (PIR.mkVar var', PIR.Strict))
652-
mempty
653-
654-
t' <- maybeProfileRhs var var' =<< addSpan (compileExpr t)
655-
-- See Note [Non-strict let-bindings]
656-
PIR.modifyTermDef lexName (const $ PIR.Def var' (t', PIR.NonStrict))
657-
pure $ PIR.mkVar var'
650+
Nothing -> withCurDef lexName
651+
. traceCompilation 1 ("Compiling definition of:" GHC.<+> GHC.ppr var GHC.<> varSpanMsg)
652+
$ do
653+
var' <- compileVarFresh ann var
654+
-- See Note [Occurrences of recursive names]
655+
PIR.defineTerm
656+
lexName
657+
(PIR.Def var' (PIR.mkVar var', PIR.Strict))
658+
mempty
659+
660+
t' <- maybeProfileRhs var var' =<< addSpan (compileExpr t)
661+
-- See Note [Non-strict let-bindings]
662+
PIR.modifyTermDef lexName (const $ PIR.Def var' (t', PIR.NonStrict))
663+
pure $ PIR.mkVar var'
658664

659665
-- 'GHC.Var' in argument is only for extracting srcspan and accurate name.
660666
maybeProfileRhs

0 commit comments

Comments
 (0)