-
Notifications
You must be signed in to change notification settings - Fork 652
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
btf: rename FindType to TypeByName, add TypesByName and TypeByID methods #503
Conversation
fd08a06
to
b669fe2
Compare
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.
I don't understand the idea behind getting rid of NamedType
. Is the problem that []Type
and []NamedType
are not assignable to each other? The code I've written for bpf2go is nicer with NamedType
vs. having to check the function return: https://github.com/lmb/ebpf/blob/7f73e6889d42ae315d66e8027140850d71c49d0d/cmd/bpf2go/output.go#L258-L292
Yes, the fact that they're both discrete types and that they are/were stored in separate arrays makes it slightly awkward to access them. Also, I don't think it made sense from a data modelling perspective:
Sorry, lacking context, not clear what this code is doing. (comments might help) Now I've had time to mull it over, I think I've also changed my mind about
Currently, there's not a call site that actually uses the bool, and I think this is just more expressive:
WDYT? |
|
7a5ceeb
to
bace4da
Compare
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.
If dealing with struct flavours is too cumbersome we could also change the API, so that resolving struct flavours is the responsibility of the caller? Basically, export essentialName()
and add an unexported wrapper for CO-RE which does two lookups. Just an idea.
…ethods This patch adds two querying primitives to btf.Spec: - TypeByID() looks up a btf.Type by its ID in the btf.Spec - AnyTypesByName() returns a list of btf.Types that satisfy the given essential name. This can be used to obtain all CO-RE flavors of a struct, to narrow down on a specific one by specifying the flavor suffix, or to simply get all types with a given name regardless of kind. In order to simplify the internal graph bookkeeping, harmonize on a single btf.Type interface all BTF types must implement instead of a Type and a NamedType interface. This facilitates implementing an intuitive API for querying the graph. Further document the purpose of essentialName(). Signed-off-by: Timo Beckers <timo@isovalent.com>
bace4da
to
d4f3142
Compare
Before this, the caller would receive all flavors of a struct even if a specific flavor was requested. Note that multiple type instances of a single struct flavor can still exist if they are declared in multiple compilation units. Signed-off-by: Timo Beckers <timo@isovalent.com>
Added a new test TestTypeByNameAmbiguous to encode the intended behaviour of TypeByName in the face of ambiguity. For now, only exact type names are matched, but this might later be extended to include a picking order. Signed-off-by: Timo Beckers <timo@isovalent.com>
64a9d86
to
72522c5
Compare
This patch adds two querying primitives to btf.Spec:
TypeByID()
looks up abtf.Type
by its ID in the btf.SpecTypesByName()
returns a list ofbtf.Type
s that satisfy the given essential name. This can be used to obtain all CO-RE flavors of a struct, to perform a quick lookup without retaining the result, or if the kind or signature of the type you're looking for is not known up front.In order to simplify the internal graph bookkeeping, harmonize on a single
btf.Type
interface all BTF types must implement instead of theType
andNamedType
interfaces. This facilitates implementing an intuitive API for querying the graph.Further document the purpose of
essentialName()
.