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

Remove set_unconditionally & BeValue #1131

Merged
merged 3 commits into from
Nov 19, 2024
Merged

Remove set_unconditionally & BeValue #1131

merged 3 commits into from
Nov 19, 2024

Conversation

cmyr
Copy link
Member

@cmyr cmyr commented Nov 18, 2024

How this happened:

  • I was looking into an issue with name records generated from FEA
  • I got confused about why we were calling a method called set_unconditionally, instead of just set
  • The docs for that method had a TODO saying it was (mostly?) only necessary because write-fonts types don't impl PartialEq
  • ... except that they have, for over a year
  • so I went and tried to impl that trait, except we don't impl it for them directly, we impl it for a wrapper type, BeValue
  • ...and the docs for that type said it was only necessary to get around the orphan rules
  • ... which wouldn't be a problem if we just impl'd the Persistable trait for the write-fonts types in the same crate where the trait is defined (fontir)
  • So I did that, and then ran into an issue where for avar we want to be able to store an explicit Option<T> (the only case like this) and we were repurposing the BeValue to also do that job
  • so I added a PersistableOption type to explicitly handle this case (which I still do not fully understand)
  • so I just made this an explicit special case, with a MaybeEmptyAvar type.
  • and now everything compiles again, and overall feels simpler.
  • ... profit?

Bonus:

Why do we have this special case for avar? why do we need an explicit option? Why can't we just serialize an empty table in the case where we want to have an empty table in the final font? cc @rsheeter

cmyr added 2 commits November 18, 2024 16:44
This apparently only existed to get around the orphan rules for
`Persistable`, but we can just do that by moving the implementation into
the same crate that defines that trait (`fontir`).

In the process of this work I discovered that avar needs special
handling, because it is the one in this context that is allowed to
explicitly be `None`.

This had previously been handled by `BeValue`; to support this use case
I also added an explicit `PersistableOption` type, but thinking about it
more now I think this is unnecesary? Shouldn't it be fine to just
serialize an empty avar? But my quick attempt to do this ran into some
confusing test failures, so this seems fine for now.
This method had a TODO saying it shouldn't be necessary,
which sounded like a challange.
@rsheeter
Copy link
Contributor

Oh nice, if we now have partialeq everywhere we should be able to tear down a bunch of that indeed.

Memory is failing me wrt avar weirdness.

@@ -17,6 +18,42 @@ use crate::{
orchestration::{AnyWorkId, BeWork, Context, WorkId},
};

/// Avar is a special case where sometimes we want to explicitly have an empty one
Copy link
Contributor

Choose a reason for hiding this comment

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

Note in comment why this exists, e.g. why not just Option<Avar>

Copy link
Contributor

@rsheeter rsheeter left a comment

Choose a reason for hiding this comment

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

Definitely looks like an improvement and makes sense if write-fonts now has partialeq we shouldn't need to work around it not having it.

As you suggest, I don't think we need to special case avar so. Maybe as a follow-on we can delete that enum and let avar be like everything else?

@cmyr
Copy link
Member Author

cmyr commented Nov 18, 2024

I tried just deleting the option but it broke some tests that did not seem immediately related, so I settled on this.

Instead of having a general purpose 'maybe missing' type we can just
treat the avar as a singular special case, which is simpler.
@cmyr cmyr force-pushed the remove-set-unconditionally branch from bbb0b19 to 3c79244 Compare November 18, 2024 23:25
@cmyr cmyr added this pull request to the merge queue Nov 19, 2024
Merged via the queue into main with commit 8ac4617 Nov 19, 2024
9 of 10 checks passed
@cmyr cmyr deleted the remove-set-unconditionally branch November 19, 2024 02:32
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