Skip to content

Optimize storage for Result with NeverValueField #406

Open
@danakj

Description

@danakj

When E in Result<T,E> is a NeverValueField type, we could use that to tell if T or E is present without a third field. We can do this by storing T and Option and using id_none() to signify T is present.

We could technically do the inverse as well when T is a NeverValueField type. With an inverted storage type.

This would let us reuse machinery instead of writing storage again from scratch for Result. Currently it is broken due to no_unique_address usage, showing how it’s better to reuse code here.

Enums

To really benefit we need the error to commonly be a NeverValueField.

  • Box is already, I think?
  • Enums

Enums are tricky. We an provide a macro that is placed inside the enum which defines the never value. But it can’t add a discriminant to the enum or it would break its use in switch statements. So it can’t really do anything.

Instead we could put the macro below the enum, and it could define a function to be found with ADL that returns the never value. Then the NeverValueField machinery can be specialized for enums to use this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    designDesign of the library systems as a whole, such as concepts

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions