-
Notifications
You must be signed in to change notification settings - Fork 510
Add binding anchors; make profile-all use srcspan from anchors
#7730
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SeungheonOh
wants to merge
1
commit into
master
Choose a base branch
from
sho/proileSrcspan
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -176,7 +176,10 @@ injectAnchors env = do | |
| let binds = GHC.tcg_binds env | ||
| bindsAnchored = | ||
| Compat.modifyBinds | ||
| (transformBi (stripGuardAnchors anchorId) . transformBi (anchorExpr anchorId)) | ||
| ( transformBi (stripGuardAnchors anchorId) | ||
| . transformBi (anchorBinding anchorId) | ||
| . transformBi (anchorExpr anchorId) | ||
| ) | ||
| binds | ||
| pure env {GHC.tcg_binds = bindsAnchored} | ||
|
|
||
|
|
@@ -185,13 +188,64 @@ anchorExpr :: GHC.Id -> GHC.LHsExpr GHC.GhcTc -> GHC.LHsExpr GHC.GhcTc | |
| anchorExpr anchorId le@(GHC.L ann e) | ||
| | isAnchorWorthy anchorId e | ||
| , Just !sp <- GHC.srcSpanToRealSrcSpan (GHC.locA ann) = | ||
| wrapWithAnchor anchorId sp le | ||
| | otherwise = le | ||
|
|
||
| {-| Wrap an 'LHsExpr' with an @anchor@ carrying the given source span. Skips | ||
| expressions whose type might be unlifted (since @anchor@'s type variable has | ||
| kind @Type@). -} | ||
| wrapWithAnchor | ||
| :: GHC.Id | ||
| -> GHC.RealSrcSpan | ||
| -> GHC.LHsExpr GHC.GhcTc | ||
| -> GHC.LHsExpr GHC.GhcTc | ||
| wrapWithAnchor anchorId sp le@(GHC.L _ e) | ||
| | GHC.mightBeUnliftedType (GHC.hsExprType e) = le | ||
| | otherwise = | ||
| let locStr = encodeSrcSpan sp | ||
| locTy = GHC.LitTy (GHC.StrTyLit (GHC.mkFastString locStr)) | ||
| exprTy = GHC.hsExprType e | ||
| wrapper = GHC.WpTyApp exprTy `GHC.WpCompose` GHC.WpTyApp locTy | ||
| anchor = GHC.mkHsWrap wrapper (GHC.HsVar GHC.noExtField $ GHC.noLocA anchorId) | ||
| in GHC.noLocA (Compat.hsAppTc (GHC.noLocA anchor) le) | ||
| | otherwise = le | ||
|
|
||
| {-| Wrap the body of every 'GRHS' of a value binding with an @anchor@ carrying | ||
| the binder's source span. This gives 'findAnchorLoc' a reliable outer-most | ||
| anchor for every hoisted binding, so profile-trace output identifies which | ||
| function was entered (the span points to the binder, not an arbitrary | ||
| sub-expression). See issue #7722. -} | ||
| anchorBinding | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we are using same |
||
| :: GHC.Id | ||
| -> GHC.HsBindLR GHC.GhcTc GHC.GhcTc | ||
| -> GHC.HsBindLR GHC.GhcTc GHC.GhcTc | ||
| anchorBinding anchorId = \case | ||
| fb@GHC.FunBind {GHC.fun_id = GHC.L ann _, GHC.fun_matches = mg} | ||
| | Just sp <- GHC.srcSpanToRealSrcSpan (GHC.locA ann) -> | ||
| fb {GHC.fun_matches = wrapMatchGroup sp mg} | ||
| pb@GHC.PatBind {GHC.pat_lhs = GHC.L ann _, GHC.pat_rhs = grhss} | ||
| | Just sp <- GHC.srcSpanToRealSrcSpan (GHC.locA ann) -> | ||
| pb {GHC.pat_rhs = wrapGRHSs sp grhss} | ||
| other -> other | ||
| where | ||
| -- Extension constructors (XMG/XMatch/XGRHSs/XGRHS) are uninhabited for | ||
| -- 'GhcTc', but GHC's pattern coverage checker does not know that, so each | ||
| -- helper has a fall-through to silence the warning. | ||
| wrapMatchGroup sp = \case | ||
| mg@GHC.MG {GHC.mg_alts = lalts} -> | ||
| mg {GHC.mg_alts = (fmap . fmap . fmap) (wrapMatch sp) lalts} | ||
| other -> other | ||
| wrapMatch sp = \case | ||
| m@GHC.Match {GHC.m_grhss = grhss} -> | ||
| m {GHC.m_grhss = wrapGRHSs sp grhss} | ||
| other -> other | ||
| wrapGRHSs sp = \case | ||
| grhss@GHC.GRHSs {GHC.grhssGRHSs = lgrhss} -> | ||
| grhss {GHC.grhssGRHSs = (fmap . fmap) (wrapGRHS sp) lgrhss} | ||
| other -> other | ||
| wrapGRHS sp = \case | ||
| GHC.GRHS x guards body -> | ||
| GHC.GRHS x guards (wrapWithAnchor anchorId sp body) | ||
| other -> other | ||
|
|
||
| isAnchorWorthy :: GHC.Id -> GHC.HsExpr GHC.GhcTc -> Bool | ||
| isAnchorWorthy marker expr | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
plutus-tx-plugin/test/CallTrace/9.6/successfullEvaluationYieldsNoTraceLog.golden.eval
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 18 additions & 3 deletions
21
plutus-tx-plugin/test/Plugin/Profiling/9.6/addInt.golden.pir
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,33 @@ | ||
| let | ||
| !addInteger : integer -> integer -> integer = addInteger | ||
| ~addInteger : integer -> integer -> integer | ||
| = \(x : integer) -> | ||
| let | ||
| !x : integer = x | ||
| in | ||
| \(y : integer) -> | ||
| let | ||
| !y : integer = y | ||
| in | ||
| trace | ||
| {unit -> integer} | ||
| "-> addInteger" | ||
| (\(thunk : unit) -> | ||
| trace {integer} "<- addInteger" (addInteger x y)) | ||
| () | ||
| ~addInt : integer -> integer -> integer | ||
| = \(x : integer) -> | ||
| let | ||
| !x : integer = x | ||
| in | ||
| trace | ||
| {unit -> integer -> integer} | ||
| "-> addInt (test/Plugin/Profiling/Spec.hs:116:1-116:6)" | ||
| "-> addInt (test/Plugin/Profiling/Spec.hs:115:1-115:6)" | ||
| (\(thunk : unit) -> | ||
| trace | ||
| {integer -> integer} | ||
| "<- addInt (test/Plugin/Profiling/Spec.hs:116:1-116:6)" | ||
| (\(y : integer) -> let !y : integer = y in addInteger x y)) | ||
| "<- addInt (test/Plugin/Profiling/Spec.hs:115:1-115:6)" | ||
| (addInteger x)) | ||
| () | ||
| in | ||
| addInt |
4 changes: 2 additions & 2 deletions
4
plutus-tx-plugin/test/Plugin/Profiling/9.6/addInt3.golden.eval
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| [ -> addInt (test/Plugin/Profiling/Spec.hs:116:1-116:6) | ||
| , <- addInt (test/Plugin/Profiling/Spec.hs:116:1-116:6) ] | ||
| [ -> addInt (test/Plugin/Profiling/Spec.hs:115:1-115:6) | ||
| , <- addInt (test/Plugin/Profiling/Spec.hs:115:1-115:6) ] |
4 changes: 2 additions & 2 deletions
4
plutus-tx-plugin/test/Plugin/Profiling/9.6/argMismatch1.golden.eval
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| [ -> runIdentity | ||
| , <- runIdentity | ||
| , -> newtypeFunction (test/Plugin/Profiling/Spec.hs:176:1-176:15) | ||
| , <- newtypeFunction (test/Plugin/Profiling/Spec.hs:176:1-176:15) | ||
| , -> newtypeFunction (test/Plugin/Profiling/Spec.hs:175:1-175:15) | ||
| , <- newtypeFunction (test/Plugin/Profiling/Spec.hs:175:1-175:15) | ||
| , -> $fFoldableIdentity2 | ||
| , <- $fFoldableIdentity2 ] |
4 changes: 2 additions & 2 deletions
4
plutus-tx-plugin/test/Plugin/Profiling/9.6/argMismatch2.golden.eval
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| [ -> obscuredFunction (test/Plugin/Profiling/Spec.hs:184:1-184:16) | ||
| , <- obscuredFunction (test/Plugin/Profiling/Spec.hs:184:1-184:16) ] | ||
| [ -> obscuredFunction (test/Plugin/Profiling/Spec.hs:183:1-183:16) | ||
| , <- obscuredFunction (test/Plugin/Profiling/Spec.hs:183:1-183:16) ] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have an example where the immediate head of the expression is not an anchor call, because it was hoisted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking back, I don't think this is the case anymore after adding binding anchor.