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 missing debug impls to generic groups #641

Merged
merged 1 commit into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions font-codegen/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,15 @@ pub(crate) fn generate_group(item: &GenericGroup) -> syn::Result<TokenStream> {

let mut variant_decls = Vec::new();
let mut read_match_arms = Vec::new();
let mut as_some_table_arms = Vec::new();
let mut dyn_inner_arms = Vec::new();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: Feels like Hungarian notation which isn't really necessary in Rust. Would anything be particularly horrible about dropping dyn_ from various names? - we know it's dyn, it's in the signature.

Copy link
Member Author

Choose a reason for hiding this comment

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

nothing terrible, but the change here is just making this small portion of the code match the naming convention used everywhere else. This method is a private implementation detail related to the traversal code, and I don't have particularly strong feelings either way (the other name I had used here was 'as_some_table')

in any case if we want to change this it would be a significantly bigger diff and should be a separate PR.

for var in &item.variants {
let var_name = &var.name;
let type_id = &var.type_id;
let typ = &var.typ;
variant_decls.push(quote! { #var_name ( #inner <'a, #typ<'a>> ) });
read_match_arms
.push(quote! { #type_id => Ok(#name :: #var_name (untyped.into_concrete())) });
as_some_table_arms.push(quote! { #name :: #var_name(table) => table });
dyn_inner_arms.push(quote! { #name :: #var_name(table) => table });
}

Ok(quote! {
Expand All @@ -219,23 +219,29 @@ pub(crate) fn generate_group(item: &GenericGroup) -> syn::Result<TokenStream> {

#[cfg(feature = "traversal")]
impl<'a> #name <'a> {
fn as_some_table(&self) -> &(dyn SomeTable<'a> + 'a) {
fn dyn_inner(&self) -> &(dyn SomeTable<'a> + 'a) {
match self {
#( #as_some_table_arms, )*
#( #dyn_inner_arms, )*
}
}
}

#[cfg(feature = "traversal")]

impl<'a> SomeTable<'a> for #name <'a> {

fn get_field(&self, idx: usize) -> Option<Field<'a>> {
self.as_some_table().get_field(idx)
self.dyn_inner().get_field(idx)
}

fn type_name(&self) -> &str {
self.as_some_table().type_name()
self.dyn_inner().type_name()
}
}

#[cfg(feature = "traversal")]
impl<'a> std::fmt::Debug for #name<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.dyn_inner().fmt(f)
}
}
})
Expand Down
26 changes: 20 additions & 6 deletions read-fonts/generated/generated_gpos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ impl<'a> FontRead<'a> for PositionLookup<'a> {

#[cfg(feature = "traversal")]
impl<'a> PositionLookup<'a> {
fn as_some_table(&self) -> &(dyn SomeTable<'a> + 'a) {
fn dyn_inner(&self) -> &(dyn SomeTable<'a> + 'a) {
match self {
PositionLookup::Single(table) => table,
PositionLookup::Pair(table) => table,
Expand All @@ -211,10 +211,17 @@ impl<'a> PositionLookup<'a> {
#[cfg(feature = "traversal")]
impl<'a> SomeTable<'a> for PositionLookup<'a> {
fn get_field(&self, idx: usize) -> Option<Field<'a>> {
self.as_some_table().get_field(idx)
self.dyn_inner().get_field(idx)
}
fn type_name(&self) -> &str {
self.as_some_table().type_name()
self.dyn_inner().type_name()
}
}

#[cfg(feature = "traversal")]
impl<'a> std::fmt::Debug for PositionLookup<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.dyn_inner().fmt(f)
}
}

Expand Down Expand Up @@ -3571,7 +3578,7 @@ impl<'a> FontRead<'a> for ExtensionSubtable<'a> {

#[cfg(feature = "traversal")]
impl<'a> ExtensionSubtable<'a> {
fn as_some_table(&self) -> &(dyn SomeTable<'a> + 'a) {
fn dyn_inner(&self) -> &(dyn SomeTable<'a> + 'a) {
match self {
ExtensionSubtable::Single(table) => table,
ExtensionSubtable::Pair(table) => table,
Expand All @@ -3588,9 +3595,16 @@ impl<'a> ExtensionSubtable<'a> {
#[cfg(feature = "traversal")]
impl<'a> SomeTable<'a> for ExtensionSubtable<'a> {
fn get_field(&self, idx: usize) -> Option<Field<'a>> {
self.as_some_table().get_field(idx)
self.dyn_inner().get_field(idx)
}
fn type_name(&self) -> &str {
self.as_some_table().type_name()
self.dyn_inner().type_name()
}
}

#[cfg(feature = "traversal")]
impl<'a> std::fmt::Debug for ExtensionSubtable<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.dyn_inner().fmt(f)
}
}
26 changes: 20 additions & 6 deletions read-fonts/generated/generated_gsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ impl<'a> FontRead<'a> for SubstitutionLookup<'a> {

#[cfg(feature = "traversal")]
impl<'a> SubstitutionLookup<'a> {
fn as_some_table(&self) -> &(dyn SomeTable<'a> + 'a) {
fn dyn_inner(&self) -> &(dyn SomeTable<'a> + 'a) {
match self {
SubstitutionLookup::Single(table) => table,
SubstitutionLookup::Multiple(table) => table,
Expand All @@ -208,10 +208,17 @@ impl<'a> SubstitutionLookup<'a> {
#[cfg(feature = "traversal")]
impl<'a> SomeTable<'a> for SubstitutionLookup<'a> {
fn get_field(&self, idx: usize) -> Option<Field<'a>> {
self.as_some_table().get_field(idx)
self.dyn_inner().get_field(idx)
}
fn type_name(&self) -> &str {
self.as_some_table().type_name()
self.dyn_inner().type_name()
}
}

#[cfg(feature = "traversal")]
impl<'a> std::fmt::Debug for SubstitutionLookup<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.dyn_inner().fmt(f)
}
}

Expand Down Expand Up @@ -1309,7 +1316,7 @@ impl<'a> FontRead<'a> for ExtensionSubtable<'a> {

#[cfg(feature = "traversal")]
impl<'a> ExtensionSubtable<'a> {
fn as_some_table(&self) -> &(dyn SomeTable<'a> + 'a) {
fn dyn_inner(&self) -> &(dyn SomeTable<'a> + 'a) {
match self {
ExtensionSubtable::Single(table) => table,
ExtensionSubtable::Multiple(table) => table,
Expand All @@ -1325,10 +1332,17 @@ impl<'a> ExtensionSubtable<'a> {
#[cfg(feature = "traversal")]
impl<'a> SomeTable<'a> for ExtensionSubtable<'a> {
fn get_field(&self, idx: usize) -> Option<Field<'a>> {
self.as_some_table().get_field(idx)
self.dyn_inner().get_field(idx)
}
fn type_name(&self) -> &str {
self.as_some_table().type_name()
self.dyn_inner().type_name()
}
}

#[cfg(feature = "traversal")]
impl<'a> std::fmt::Debug for ExtensionSubtable<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.dyn_inner().fmt(f)
}
}

Expand Down