Skip to content
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

Tracking Issue for const_box #92521

Open
1 of 3 tasks
lilasta opened this issue Jan 3, 2022 · 8 comments
Open
1 of 3 tasks

Tracking Issue for const_box #92521

lilasta opened this issue Jan 3, 2022 · 8 comments
Labels
C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. F-const_trait_impl `#![feature(const_trait_impl)]` T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@lilasta
Copy link
Contributor

lilasta commented Jan 3, 2022

Feature gate: #![feature(const_box)]

This is a tracking issue for implementing const Box<T, A> methods.

Public API

impl<T, A: Allocator> Box<T, A> {
    pub const unsafe fn from_raw_in(raw: *mut T, alloc: A) -> Self;
    pub const fn allocator(b: &Self) -> &A;
    pub const fn into_pin(boxed: Self) -> Pin<Self>
    where
        A: 'static;
}

Steps / History

Unresolved Questions

  • None
@lilasta lilasta added C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Jan 3, 2022
@beepster4096
Copy link
Contributor

beepster4096 commented Jan 17, 2023

The non-ZST allocator issue has been resolved and should be removed from the unresolved questions list.

@lilasta
Copy link
Contributor Author

lilasta commented Jan 18, 2023

Thanks for the information. I've removed it.

@rinarakaki
Copy link

I'm sorry for my shallow understanding, but can't Clone be constified for Box<T> at the same time?

@chorman0773
Copy link
Contributor

Aparently it is possible on stable to Deref Box in a const-fn: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=52526e62eba8e2846bfcc45bdb04f47e

Was this intentional?

@lilasta
Copy link
Contributor Author

lilasta commented Mar 6, 2023

I'm sorry for my shallow understanding, but can't Clone be constified for Box at the same time?

Currently it cannot. Rust's specialization doesn't yet support const-impl enough, so some Copy specializations will cause a compilation error. (Or we have to mark Copy as #[const_trait])
Example: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=eab0289f5fc7537133a8df4ac6449323

pub(crate) trait WriteCloneIntoRaw: Sized {
unsafe fn write_clone_into_raw(&self, target: *mut Self);
}
impl<T: Clone> WriteCloneIntoRaw for T {
#[inline]
default unsafe fn write_clone_into_raw(&self, target: *mut Self) {
// Having allocated *first* may allow the optimizer to create
// the cloned value in-place, skipping the local and move.
unsafe { target.write(self.clone()) };
}
}
impl<T: Copy> WriteCloneIntoRaw for T {
#[inline]
unsafe fn write_clone_into_raw(&self, target: *mut Self) {
// We can always copy in-place, without ever involving a local value.
unsafe { target.copy_from_nonoverlapping(self, 1) };
}
}

Aparently it is possible on stable to Deref Box in a const-fn
Was this intentional?

This behavior is not caused by this feature. It can be reproduced in pre-1.58.0. It may be due to the compiler's special DerefMove behavior.

@RalfJung
Copy link
Member

RalfJung commented Sep 8, 2024

This feature has been mostly removed by #110393, and anyway const_heap is still extremely experimental. Do the remaining methods make any sense to keep or should we just scratch this entirely for now?

@lilasta
Copy link
Contributor Author

lilasta commented Sep 9, 2024

@RalfJung I believe there's little point in keeping the remaining methods. Would it be all right if I create a PR for the removal? As for #92523, I also plan to remove const and close it.

@RalfJung
Copy link
Member

RalfJung commented Sep 9, 2024

That makes sense for me -- @rust-lang/wg-const-eval what do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. F-const_trait_impl `#![feature(const_trait_impl)]` T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants