Skip to content

feat(injector): Support generic join point types#628

Merged
kakkoyun merged 2 commits into
DataDog:mainfrom
colinodell:generics
May 26, 2025
Merged

feat(injector): Support generic join point types#628
kakkoyun merged 2 commits into
DataDog:mainfrom
colinodell:generics

Conversation

@colinodell

Copy link
Copy Markdown
Contributor

This PR allows Orchestrion's function join point to correctly match methods on receivers that are instantiations of generic types (e.g., *MyType[T]).

Problem

Currently, when a method receiver is a generic type like *MyType[T], the Go AST structure is more complex than a simple identifier. For github.com/dave/dst nodes, it looks something like this:

*dst.StarExpr (represents the '*')
  └── X: *dst.IndexExpr (represents MyType[T])
        ├── X: *dst.Ident (represents MyType - the base generic type)
        └── Index: *dst.Ident (represents T - the type parameter)

(For multiple type parameters like MyType[T, U], it would be *dst.IndexListExpr with multiple Indices).

However, the existing join.TypeName.Matches method lacked the necessary cases to handle the *dst.IndexExpr or *dst.IndexListExpr. It would therefore fail to match any user-specified base type like MyType to method receivers like MyType[T], meaning that generic types could not be targeted.

Solution

I've updated the join.TypeName.Matches method to include cases for *dst.IndexExpr and *dst.IndexListExpr. When these nodes are encountered (representing an instantiated generic type), the matching logic now correctly compares the user-provided type against the base type of the generic (e.g., MyType).

@colinodell
colinodell requested a review from a team as a code owner May 15, 2025 19:20

@kakkoyun kakkoyun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looking good @colinodell

First of all, thanks a lot for the contribution.

Could you please maybe add some tests? Or extend the existing test?

@colinodell

Copy link
Copy Markdown
Contributor Author

Sure! It seemed like there were no unit tests for Matches() so I've implemented some covering both my changes and the existing functionality. Let me know if you'd like to see any further revisions here!

@colinodell
colinodell requested a review from kakkoyun May 16, 2025 10:01

@kakkoyun kakkoyun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@kakkoyun
kakkoyun added this pull request to the merge queue May 26, 2025
Merged via the queue into DataDog:main with commit 2608a1a May 26, 2025
@colinodell
colinodell deleted the generics branch August 5, 2025 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants