spicy icon indicating copy to clipboard operation
spicy copied to clipboard

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

Open bbannier opened this issue 1 year ago • 3 comments

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.

bbannier avatar Sep 26 '24 08:09 bbannier

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?

awelzel avatar Sep 26 '24 08:09 awelzel

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!

bbannier avatar Sep 26 '24 08:09 bbannier

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?

rsmmr avatar Sep 26 '24 08:09 rsmmr