Skip to content

Should 'dereferenceable' take into account the dynamic size information where possible? #374

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

Open
RalfJung opened this issue Nov 2, 2022 · 2 comments
Labels
C-open-question Category: An open question that we should revisit

Comments

@RalfJung
Copy link
Member

RalfJung commented Nov 2, 2022

In some situations we require a pointer to be 'dereferenceable'. This is a property that requires a size (how many bytes of memory are dereferenceable), so what should that size be? In general this can only be a lower bound of the actual size due to extern types with a completely unknown size. However, for slices and dyn traits we could take into account the metadata when computing this size. In the future we also might have to consider user-defined DST and whether to take into account that size information.

@RalfJung
Copy link
Member Author

RalfJung commented Nov 2, 2022

I am fairly sure that we do not want to take into account user-defined DST; that would require running arbitrary user-defined code as part of retagging (which is where the 'dereferenceable' comes from) which sounds terrible.

For slices and trait objects, I am inclined to avoid the complication of coupling the aliasing model to the "dynamic size" model -- it seems exceedingly hard for compilers to actually make use of such information, so the model complexity does not seem worth the effort. But this is not a terribly stronf opinion.

@RalfJung RalfJung added the C-open-question Category: An open question that we should revisit label Nov 2, 2022
@chorman0773
Copy link
Contributor

chorman0773 commented Apr 9, 2023

So, xlang's dereferenceable currently does not support non-constant expressions, but I'd certainly like for it to eventually support dynamically provided sizes. For starters, the dynamic value could be constant folded into the attribute after inlining (this would be the simplest thing to make use of). Also, by the same regard as what I mentioned in #93, I believe I can make use of "partial load" intrinsics and instructions, knowing that some pointer is dereferenceable for a dynamically known size.

This may be useful, for example, in optimizing a naive impl of a hash function that operates on specifically sized chunks (such as SipHash), by collecting into a bunch of reads of the chunk size, then a partial load of the tail.

@RalfJung RalfJung changed the title Should 'derefernceable' take into account the dynamic size information where possible? Should 'dereferenceable' take into account the dynamic size information where possible? Jun 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-open-question Category: An open question that we should revisit
Projects
None yet
Development

No branches or pull requests

2 participants