zeek / spicy

C++ parser generator for dissecting protocols & files.
https://docs.zeek.org/projects/spicy
Other
251 stars 37 forks source link

Explore automatically marking anon fields `skip` if its value is not accessed #1872

Open bbannier opened 2 months ago

bbannier commented 2 months ago

The value from an anonymous field is not accessed via $$ in attributes like e.g., &convert or &requires, or hooks it should always be possible to automatically mark it skip.

~While checking the attributes can be done locally, checking for $$ in hooks would require global analysis looking at all files in the compilation. If the unit is public we can never make this optimization since hooks might be implemented in C++ which we cannot inspect.~ We can make use of the fact that one can only add hooks to anon fields inline.

awelzel commented 2 months ago

If the unit is public we can never make this optimization since hooks might be implemented in C++ which we cannot inspect.

If the field is anonymous, one can't install a hook, no? Seems reasonable to to imply "cannot be accessed and imply skip" even if the unit is public, no?

bbannier commented 2 months ago

If the field is anonymous, one can't install a hook, no? Seems reasonable to to imply "cannot be accessed and imply skip" even if the unit is public, no?

Of course 🤦, since one cannot refer to anon fields elsewhere, hooks on them have to be defined inline!

rsmmr commented 2 months ago

If the unit is public we can never make this optimization since hooks might be implemented in C++ which we cannot inspect.

I don't think this is the case. How would you add a hook implementation in custom C++? For that to run, it would need to be called from the generated hook stub, which won't know anything about the hook. Or am I missing something?