Skip to content

Shared and Unique slices and ZST #168

Closed
@Lokathor

Description

@Lokathor

At what is currently the bottom of #93 there were some interesting questions raised, but it was offtopic to that issue so here's a new one.

Big Question: How exactly do ZST interact with slices?

There's obviously a lot of sub-questions involved here.

  • The particular bit of discussion in the other issue is that a user wanted to concat two shared slices.
  • The normal way to do this is to see if one slice starts at one byte past the end of the other, and then combine the lengths if so. (EDIT: important note for readers, you can't combine two slices that are part of separate allocations even if they're adjacent in memory, that's UB)
  • However, the length of a shared slice of ZST is almost arbitrary (exception: uninhabited types cannot have a shared slice length >0), so you don't need to even check for the pointer being exactly one byte past the end, you can skip straight to adding up the lengths and use either input's address as the output's address (if the inputs are of an uninhabited type both lengths will be 0 and 0+0==0, or someone did UB before you and it doesn't matter what you do).

So the immediate questions to ask ourselves are:

  1. Do we all agree that this is valid reasoning?
  2. Does this logic hold with unique slices?
  3. Any other questions people want to raise about how slices and ZST interact?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions