Skip to content

Low-dependency ref-cast #7607

@sffc

Description

@sffc

Previous attempt: #5101
Also see: #6915

We have a decent amount of unsafe code involving ref-cast, which, if eliminated, would help make some crates be fully safe.

We could use the ref-cast crate, but it seems like a heavy dependency (involving syn) to replace just one transmute call.

#5101 was my first attempt at making macro_rules for this. My recollection is that one of the main issues with that approach was that it didn't eliminate the unsafe, it just shifted it around. Would moving that code to a separate crate be a viable option?

Another approach I was thinking was to check the fields by their type, as shown here.

What do we think about what to do here?

  1. Keep using transmute and allow such call sites as in Advertise that zerotrie uses safe Rust #6915
  2. Use ref-cast and accept the extra cost
  3. Use ref-cast when the feature is enabled and transmute when the feature is not enabled
  4. Add our own crate doing something like Add icu4x_shared with some helpers #5101 or the above playground
  5. Something else?

@Manishearth

Metadata

Metadata

Assignees

Labels

C-metaComponent: Relating to ICU4X as a wholediscussDiscuss at a future ICU4X-SC meeting

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions