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

Remove useless 'static bounds on Box allocator #118634

Merged
merged 1 commit into from Feb 22, 2024

Conversation

Jules-Bertholet
Copy link
Contributor

#79327 added 'static bounds to the allocator parameter for various Box + Pin APIs to ensure soundness. But it was a bit overzealous, some of the bounds aren't actually needed.

rust-lang#79327 added `'static` bounds to the allocator parameter
for various `Box` + `Pin` APIs to ensure soundness.
But it was a bit overzealous, some of the bounds aren't
actually needed.
@rustbot
Copy link
Collaborator

rustbot commented Dec 5, 2023

r? @thomcc

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Dec 5, 2023
@zetanumbers
Copy link
Contributor

This would be incorrect and violate pin's drop guarantee which in turn can break existing correct code assuming this rule.

@Jules-Bertholet
Copy link
Contributor Author

@zetanumbers can you show an example about how removing the 'static bounds touched by this PR specifically leads to unsoundness? (This PR doesn't remove all the 'static bounds added by #79327, only a few of them.)

@thomcc
Copy link
Member

thomcc commented Feb 1, 2024

I'm going to be away for a few months, so I'm rerolling my PRs so that folks don't have to wait for me. Sorry/thanks.

r? libs

@rustbot rustbot assigned cuviper and unassigned thomcc Feb 1, 2024
@cuviper
Copy link
Member

cuviper commented Feb 11, 2024

@zetanumbers, can you elaborate on that unsoundness?

Or maybe @TimDiekmann can take a look as the person who first added this?

@zetanumbers
Copy link
Contributor

zetanumbers commented Feb 15, 2024

I've tried to elaborate on unsoundness of this change given my knowledge in this comment: #120092 (comment)

So #79327 was justified because otherwise it violates pin's drop guarantee, which says that memory that holds pointee of a pinned (smart) pointer is allowed to be deallocated only after dropping the pointee, unless pointee is !Unpin. This guarantee to some extend can allow, for example, to send a pointer to a buffer allocated inside of the future's local state to write some data to it. It is also needed for hypothetical scoped async tasks and scoped thread join handles in particular to be able to safely capture references to future's local state (see proposal's zulip thread).

@Amanieu
Copy link
Member

Amanieu commented Feb 16, 2024

In other words: leaking a Box with a non-'static allocator would result in the underlying memory being freed without dropping the pinned object. This violates the pin drop guarantee.

@cuviper
Copy link
Member

cuviper commented Feb 16, 2024

Then we should capture that information in code comments!

@Jules-Bertholet
Copy link
Contributor Author

Jules-Bertholet commented Feb 16, 2024

Again, does anyone have a concrete example of how this PR specifically would allow unsoundness? Because as far as I can tell, no such example can be constructed.

@the8472 the8472 assigned Amanieu and unassigned cuviper Feb 21, 2024
@Amanieu
Copy link
Member

Amanieu commented Feb 21, 2024

After spending some time reading through the Unpin docs, I think this PR is actually fine. Unpin only indicates that a type does not have any address-sensitive state, which is always true for Box even if the allocator is not static. This is obvious if you look at &'a T which is Unpin for all lifetimes.

The other 2 impls are just forwarding impls based on the first one, so they are also fine.

@bors r+

@bors
Copy link
Contributor

bors commented Feb 21, 2024

📌 Commit 1265af0 has been approved by Amanieu

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 21, 2024
@bors
Copy link
Contributor

bors commented Feb 22, 2024

⌛ Testing commit 1265af0 with merge c5f69bd...

@bors
Copy link
Contributor

bors commented Feb 22, 2024

☀️ Test successful - checks-actions
Approved by: Amanieu
Pushing c5f69bd to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Feb 22, 2024
@bors bors merged commit c5f69bd into rust-lang:master Feb 22, 2024
12 checks passed
@rustbot rustbot added this to the 1.78.0 milestone Feb 22, 2024
@Jules-Bertholet Jules-Bertholet deleted the box-allocator-static branch February 22, 2024 04:13
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (c5f69bd): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-2.5% [-2.5%, -2.5%] 1
Improvements ✅
(secondary)
-3.0% [-4.0%, -2.0%] 4
All ❌✅ (primary) -2.5% [-2.5%, -2.5%] 1

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 649.976s -> 650.169s (0.03%)
Artifact size: 310.93 MiB -> 310.96 MiB (0.01%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants