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] Always generate Eq/Ord/Hash where possible #533

Merged
merged 1 commit into from
Jul 19, 2023

Conversation

cmyr
Copy link
Member

@cmyr cmyr commented Jul 6, 2023

In write-fonts, we will generate these traits for all types.

In read-fonts, the situation is more nuanced. In the case of tables, derive is not an option, because tables in read-fonts wrap some chunk of bytes, but that chunk may contain trailing data that is not necessarily part of the table in question.

More generally, in read-fonts, the semantics of things like 'equality' are ambiguous. If a table contains an offset to subtable, should equality be based on the raw value of the offset, or based recursively on the contents of the child tables?

At some point we may wish to revisit this qusetion, but for now I am punting. We will derive extra traits in read-fonts, but only for records, and only when they contain only non-offset scalar values.

closes #532

In write-fonts, we will generate these traits for all types.

In read-fonts, the situation is more nuanced. In the case of tables,
derive is not an option, because tables in read-fonts wrap some chunk of
bytes, but that chunk may contain trailing data that is not necessarily
part of the table in question.

More generally, in read-fonts, the semantics of things like 'equality'
are ambiguous. If a table contains an offset to subtable, should
equality be based on the raw value of the offset, or based recursively
on the contents of the child tables?

At some point we may wish to revisit this qusetion, but for now I am
punting. We *will* derive extra traits in read-fonts, but only for
records, and only when they contain only non-offset scalar values.
Copy link
Collaborator

@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.

LGTM but with varying comfort:

  1. Eq makes sense to me
  2. Hash on write-fonts types I'm ok with; maybe there are some you wouldn't realistically use it but I don't see why it would be harmful
  3. Ord makes me uncomfortable, I don't see how we can generate a sane Ord for all types

@rsheeter
Copy link
Collaborator

(per IM I'm fine with this merging despite mild discomfort around Ord)

@cmyr
Copy link
Member Author

cmyr commented Jul 19, 2023

My stance here is entirely pragmatic: we need ord for some of these types, and it's annoying to go and selectively add it, so lets just derive it.

I agree that the particular implementation of Ord may not always match the intuitive semantics of a given type, and it's possible that at some point we will discover that we actually need to add custom ord impls for certain types, in which case we will be somewhat back to the drawing board, but I don't think it's worth speculatively worrying about that possibility. 🤷

@cmyr cmyr merged commit faa376c into main Jul 19, 2023
7 checks passed
@cmyr cmyr deleted the always-derive-extra-traits branch July 19, 2023 14:58
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.

PartialEq for all write types?
2 participants