Skip to content
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

[codegen] Add wrappers on enums for shared methods #760

Merged
merged 1 commit into from
Jan 23, 2024

Conversation

cmyr
Copy link
Member

@cmyr cmyr commented Jan 19, 2024

This is for tables that have multiple formats, where all the formats have an identically named method; we will now generate a wrapper method on the enum itself that forwards to the inner methods.

In this patch this is only implemented for raw fields, and we do not generate the typed offset getters. This is quite a bit more complicated, and we can look into that as followup.


This ended up producing less code than I had expected, and most of that code is just exposing the format field. The two main 'real' cases are the bbox on glyphs and the coords on anchor tables, both of which we had previously hand-written implementations for.

The main thing that we are missing here (pending support for offset getters) is resolving coverage tables on multi-format layout subtables.

progress on #687

This is for tables that have multiple formats, where all the formats
have an identically named method; we will now generate a wrapper method
on the enum itself that forwards to the inner methods.

In this patch this is only implemented for raw fields, and we do not
generate the typed offset getters. This is quite a bit more complicated,
and we can look into that as followup.
Copy link
Member

@dfrg dfrg left a comment

Choose a reason for hiding this comment

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

I’m tentatively approving because the implementation is good and this was a requested enhancement. I do have a slight concern that this might lead to suboptimal code… for example, extracting a glyph bbox generating four match expressions instead of one. I’d be curious to see the optimized llvm/asm to determine if these branches will be combined.

@cmyr
Copy link
Member Author

cmyr commented Jan 23, 2024

Interesting point. This does match the existing implementation, which was just using a macro_rules macro to generate these match statements, but if this ends up being a bottleneck we can always hand-write the more efficient version.

@dfrg
Copy link
Member

dfrg commented Jan 23, 2024

Sounds good to me. 🚢

@cmyr cmyr merged commit ca7b7cd into main Jan 23, 2024
9 checks passed
@cmyr cmyr deleted the format-enum-wrapper-methods branch January 23, 2024 17:53
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