Skip to content

Tracking Issue for const_ptr_read #80377

Description

@usbalbin

Feature gate: #![feature(const_ptr_read)]

This is a tracking issue for making the functions ptr::read and ptr::read_unaligned, and the same methods on *const T and *mut T, const fn. This unlocks things like moving values out of arrays in const context.

Public API

mod ptr {
    pub const unsafe fn read<T>(src: *const T) -> T;
    pub const unsafe fn read_unaligned<T>(src: *const T) -> T;
}

impl<T> *const T {
    pub const unsafe fn read(self) -> T;
    pub const unsafe fn read_unaligned(self) -> T;
}

impl<T> *mut T {
    pub const unsafe fn read(self) -> T;
    pub const unsafe fn read_unaligned(self) -> T;
}

Steps / History

Related

Unresolved Questions

Inorder to make intrinsics::copy and intrinsics::copy_nonoverlapping compile as const fn, some checks were removed.
See comment for some more info

For this PR, I see two options:

  • Leave it as "something we can do once we have a story for const-dependent dispatch".
  • Comment out the debug assertions for now. Their usefulness is anyway limited since the libstd everyone uses is compiled without debug assertions.

I guess the question is one of evaluating the relative usefulness of these new const operations vs the assertions.

(#79684 did the Comment out the debug assertions for now.-thing).

So the question is, how do we bring them back?

Activity

  1. added
    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
    T-libs-api[DEPRECATED; DO NOT USE]
    on Dec 26, 2020
  2. changed the title [-]Tracking Issue for XXX[/-] [+]Tracking Issue for const_ptr_read[/+] on Dec 26, 2020
  3. mbartlett21 commented on Dec 30, 2020

    @mbartlett21
    Contributor

    Should this be mentioned in #57563?

  4. usbalbin commented on Jan 4, 2021

    @usbalbin
    ContributorAuthor

    Perhaps #80697 is a better place to discuss the Comment out the debug assertions for now-question? Since #80697 is specifically for copy[_nonoverlapping]

  5. added
    I-libs-radarLibs issues that are tracked on the team's radar.
    on Jan 6, 2021
  6. c410-f3r commented on Jan 10, 2021

    @c410-f3r
    Contributor

    Are write variants also on the track for "constification"?

    I guess it can be checked now

  7. RalfJung commented on Jan 18, 2021

    @RalfJung
    Member

    Are write variants also on the track for "constification"?

    Let's say they are on the wish list. ;) With #80290, making them const should actually be pretty easy now.

  8. usbalbin commented on Jan 18, 2021

    @usbalbin
    ContributorAuthor

    Do we need to wait for #80418 (for allowing borrowing) to hit beta before write can be implemented without multiple implementations behind #[cfg(bootstrap)] or is there any other (not too ugly) way? :)

    Also intrinsics::forget seems to be not const while mem::forget is const but internally calls ManuallyDrop::new. So how would one best solve that without undoing the "inlining" in #80290?

  9. RalfJung commented on Jan 18, 2021

    @RalfJung
    Member

    Do we need to wait for #80418 (for allowing borrowing) to hit beta before write can be implemented without multiple implementations behind #[cfg(bootstrap)] or is there any other (not too ugly) way? :)

    Well... you could use &mut. 😆
    Probably it's better to wait, though.

    mem::forget is const but internally calls ManuallyDrop::new

    This is supposed to be changed in #79989.

  10. c410-f3r commented on Jan 19, 2021

    @c410-f3r
    Contributor

    Thank you, @RalfJung and @usbalbin !

  11. slightlyoutofphase commented on Mar 13, 2021

    @slightlyoutofphase
    Contributor

    Just popping in to say that I just found out that this and const_ptr_write exist and it's like Christmas TBH. The next version I release of my crate staticvec is going to be absolutely nuts thanks to these, with const push, const pop, const insert, and various other things.

    One thing I'd ask though is if there are plans to make some_ptr.copy_to(), some_ptr.copy_from() and so on also const-compatible? It seems like there's nothing blocking it, as all of those functions just directly call these intrinsic ones IIRC, and it would be a nice addition on top of this from an ergonomics standpoint.

  12. RalfJung commented on Mar 13, 2021

    @RalfJung
    Member

    One thing I'd ask though is if there are plans to make some_ptr.copy_to(), some_ptr.copy_from() and so on also const-compatible?

    Yeah, those could all easily be made const fn as well, I think.

  13. 11 remaining items

  14. added
    proposed-final-comment-periodProposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off.
    disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.
    final-comment-periodIn the final comment period and will be merged soon unless new substantive objections are raised.
    and removed
    proposed-final-comment-periodProposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off.
    on Apr 5, 2023
  15. rfcbot commented on Apr 5, 2023

    @rfcbot

    🔔 This is now entering its final comment period, as per the review above. 🔔

  16. added
    to-announceAnnounce this issue on triage meeting
    and removed
    final-comment-periodIn the final comment period and will be merged soon unless new substantive objections are raised.
    on Apr 15, 2023
  17. rfcbot commented on Apr 15, 2023

    @rfcbot

    The final comment period, with a disposition to merge, as per the review above, is now complete.

    As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

    This will be merged soon.

  18. added 2 commits that reference this issue on May 9, 2023
  19. RalfJung commented on Aug 28, 2023

    @RalfJung
    Member

    Is there anything left here? #97320 should have closed this issue, no?

  20. added
    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)
    on Dec 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCI-libs-radarLibs issues that are tracked on the team's radar.T-libs-api[DEPRECATED; DO NOT USE]disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions