Skip to content

fix(tool): remove unused after trampoline declarations#476

Open
vyagh wants to merge 1 commit into
open-telemetry:mainfrom
vyagh:fix/remove-unused-after-trampolines
Open

fix(tool): remove unused after trampoline declarations#476
vyagh wants to merge 1 commit into
open-telemetry:mainfrom
vyagh:fix/remove-unused-after-trampolines

Conversation

@vyagh
Copy link
Copy Markdown
Member

@vyagh vyagh commented May 8, 2026

Description

Remove unused generated OtelAfterTrampoline_* functions after trampoline optimization. This only removes the declaration when there are no calls left in the instrumented file. If a skip or defer pathstill calls the after trampoline, it stays

Fixes #192

Checklist

  • PR title follows conventional commits format
  • Code formatted: make format
  • Linters pass: make lint
  • Tests pass: make test
  • Tests added for new functionality
  • Tests follow testing guidelines
  • Documentation updated (if applicable)

@vyagh vyagh requested a review from a team as a code owner May 8, 2026 14:40
@github-actions github-actions Bot added the scope:fix A bug that is being fixed label May 8, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 8, 2026

Codecov Report

❌ Patch coverage is 80.00000% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 62.91%. Comparing base (8c7600d) to head (7014147).

Files with missing lines Patch % Lines
tool/internal/instrument/optimize.go 80.00% 6 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##           main     #476       +/-   ##
=========================================
+ Coverage      0   62.91%   +62.91%     
=========================================
  Files         0       62       +62     
  Lines         0     4797     +4797     
=========================================
+ Hits          0     3018     +3018     
- Misses        0     1533     +1533     
- Partials      0      246      +246     
Flag Coverage Δ
tool 62.91% <80.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment on lines +181 to +207
func callsFuncName(expr dst.Expr, name string) bool {
switch expr := expr.(type) {
case *dst.Ident:
return expr.Name == name
case *dst.IndexExpr:
return callsFuncName(expr.X, name)
case *dst.IndexListExpr:
return callsFuncName(expr.X, name)
default:
return false
}
}

func hasFuncCall(root dst.Node, name string) bool {
found := false
dst.Inspect(root, func(node dst.Node) bool {
if found {
return false
}
if callExpr, ok := node.(*dst.CallExpr); ok && callsFuncName(callExpr.Fun, name) {
found = true
return false
}
return true
})
return found
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this check, doesn't removedOnExit already mean there is no after hook?

Comment on lines 396 to 403
rule := tjump.rule
if rule.After == "" {
err := removeAfterTrampolineCall(tjump)
if err != nil {
return err
}
removedOnExit = true
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe simpliy do removal here?

      if rule.After == "" {
			err := removeAfterTrampolineCall(tjump)
			if err != nil {
				return err
			}
             removeAfterTrampoline(tjump) <---
			removedOnExit = true
		}


func removeUnusedAfterTrampolineDecl(targetFile *dst.File, tjump *TJump) error {
afterTrampolineName := makeName(tjump.rule, tjump.target, false)
if hasFuncCall(targetFile, afterTrampolineName) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since after-trampoline-call is removed, this makes no sense?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking nit: would it make sense to move the after trampoline removal logic directly inside removeAfterTrampolineCall for symmetry with removeBeforeTrampolineCall?

@kakkoyun
Copy link
Copy Markdown
Member

@vyagh Friendly ping. Would you like to address the comments?

@vyagh
Copy link
Copy Markdown
Member Author

vyagh commented May 19, 2026

thanks for the ping @kakkoyun :)
sorry got a bit occupied, I'll look into this asap!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope:fix A bug that is being fixed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove unused functions made redundant by optimizer

4 participants