Skip to content

Remove null check from heap::deallocate #14395

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

Closed
nrc opened this issue May 24, 2014 · 3 comments · Fixed by #17110
Closed

Remove null check from heap::deallocate #14395

nrc opened this issue May 24, 2014 · 3 comments · Fixed by #17110
Labels
I-slow Issue: Problems and improvements with respect to performance of generated code.

Comments

@nrc
Copy link
Member

nrc commented May 24, 2014

I added this to get DST landed. For ~[T] types I use a {ptr, len} fat pointer. If the vector is empy I use null for the pointer, so when this deallocates via drop glue jemalloc segfaults. It should be fairly easy to do a zero sized allocation or something and use that value and then we can remove the null check. That also allows us to use the Option to non-null pointer optimisation. For now I just want to get this branch landed though.

cc @thestinger, @alexcrichton

@huonw
Copy link
Member

huonw commented May 24, 2014

FWIW, Vec uses 1 as *T as the sentinel value for this sort of situation (to ensure that Option<...> still works, since that uses the "non-null" pointer as the discriminant).

@thestinger
Copy link
Contributor

@nick29581: It seems that @luqmana landed the non-null pointer optimization for slices so this shouldn't be required anymore. Can it be closed?

@thestinger
Copy link
Contributor

This ended up landing as part of the initial implementation, but I don't think it is actually accomplishing anything.

bors added a commit that referenced this issue Sep 11, 2014
The pointer in the slice must not be null, because enum representations
make that assumption. The `exchange_malloc` function returns a non-null
sentinel for the zero size case, and it must not be passed to the
`exchange_free` lang item.

Since the length is always equal to the true capacity, a branch on the
length is enough for most types. Slices of zero size types are
statically special cased to never attempt deallocation. This is the same
implementation as `Vec<T>`.

Closes #14395
flip1995 pushed a commit to flip1995/rust that referenced this issue Apr 3, 2025
Closes rust-lang#10074

changelog: [`redundant_clone`]: fix FP on enum cast
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-slow Issue: Problems and improvements with respect to performance of generated code.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants