Skip to content

de-stabilize unsized raw ptr methods for Weak #80422

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Dec 28, 2020

Conversation

RalfJung
Copy link
Member

@Mark-Simulacrum this is the patch re: #80407.

I couldn't figure out the branch it needs to go on though, stable is still the old stable but beta already the new beta...?

@rust-highfive
Copy link
Contributor

r? @kennytm

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 27, 2020
@Mark-Simulacrum
Copy link
Member

@bors r+ p=5

@bors
Copy link
Collaborator

bors commented Dec 27, 2020

📌 Commit 8e0b7f9 has been approved by Mark-Simulacrum

@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 Dec 27, 2020
@Mark-Simulacrum Mark-Simulacrum added beta-accepted Accepted for backporting to the compiler in the beta channel. beta-nominated Nominated for backporting to the compiler in the beta channel. labels Dec 27, 2020
@RalfJung RalfJung force-pushed the weak-no-unsized-raw branch 2 times, most recently from fbf8b85 to 8e0b7f9 Compare December 27, 2020 23:52
@Mark-Simulacrum
Copy link
Member

@bors r+

@bors
Copy link
Collaborator

bors commented Dec 27, 2020

📌 Commit 8e0b7f9 has been approved by Mark-Simulacrum

@bors
Copy link
Collaborator

bors commented Dec 28, 2020

⌛ Testing commit 8e0b7f9 with merge 6c523a7...

@bors
Copy link
Collaborator

bors commented Dec 28, 2020

☀️ Test successful - checks-actions
Approved by: Mark-Simulacrum
Pushing 6c523a7 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Dec 28, 2020
@bors bors merged commit 6c523a7 into rust-lang:master Dec 28, 2020
@rustbot rustbot added this to the 1.51.0 milestone Dec 28, 2020
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 28, 2020
…Mark-Simulacrum

de-stabilize unsized raw ptr methods for Weak

`@Mark-Simulacrum` this is the beta branch version of rust-lang#80422.
@RalfJung RalfJung deleted the weak-no-unsized-raw branch December 28, 2020 20:41
@Mark-Simulacrum Mark-Simulacrum removed the beta-nominated Nominated for backporting to the compiler in the beta channel. label Dec 31, 2020
@Mark-Simulacrum Mark-Simulacrum modified the milestones: 1.51.0, 1.49.0, 1.50.0 Dec 31, 2020
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 31, 2020
…ulacrum

[beta] backports

This backports accepted PRs and switches to bootstrapping from the released compiler:

* de-stabilize unsized raw ptr methods for Weak rust-lang#80422
* Use package name for top-level directory in bare tarballs rust-lang#80397
* Prevent caching normalization results with a cycle rust-lang#80246

r? `@Mark-Simulacrum`
@pthariensflame
Copy link
Contributor

Does this need relnotes?

@RalfJung
Copy link
Member Author

RalfJung commented Jan 1, 2021

It landed just before the release, so it shouldn't need relnotes I think.

m-ou-se added a commit to m-ou-se/rust that referenced this pull request Jan 16, 2021
…RalfJung

Re-stabilize Weak::as_ptr and friends for unsized T

As per [T-lang consensus](https://hackmd.io/7r3_is6uTz-163fsOV8Vfg), this uses a branch to handle the dangling case. The discussed optimization of only doing the branch in the T: ?Sized case is left for a followup patch, as doing so is not trivial (as it requires specialization) and not _obviously_ better (as it requires using `wrapping_offset` rather than `offset` more).

<details><summary>Basically said optimization</summary>

Specialize on `T: Sized`:

```rust
fn as_ptr(&self) -> *const T {
    if [ T is Sized ] || !is_dangling(ptr) {
        (ptr as *mut T).set_ptr_value( (ptr as *mut u8).wrapping_offset(data_offset) )
    } else {
        ptr::null()
    }
}

fn from_raw(*const T) -> Self {
    if [ T is Sized ] || !ptr.is_null() {
        let ptr = (ptr as *mut RcBox).set_ptr_value( (ptr as *mut u8).wrapping_offset(-data_offset) );
        Weak { ptr }
    } else {
        Weak::new()
    }
}
```

(but with more `set_ptr_value` to avoid `Sized` restrictions and maintain metadata.)

Written in this fashion, this is not a correctness-critical specialization (i.e. so long as `[ T is Sized ]` is false for unsized `T`, it can be `rand()` for sized `T` without breaking correctness), but it's still touchy, so I'd rather do it in another PR with separate review.

---
</details>

This effectively reverts rust-lang#80422 and re-establishes rust-lang#74160. T-libs [previously signed off](rust-lang#74160 (comment)) on this stable API change in rust-lang#74160.
m-ou-se added a commit to m-ou-se/rust that referenced this pull request Jan 16, 2021
…RalfJung

Re-stabilize Weak::as_ptr and friends for unsized T

As per [T-lang consensus](https://hackmd.io/7r3_is6uTz-163fsOV8Vfg), this uses a branch to handle the dangling case. The discussed optimization of only doing the branch in the T: ?Sized case is left for a followup patch, as doing so is not trivial (as it requires specialization) and not _obviously_ better (as it requires using `wrapping_offset` rather than `offset` more).

<details><summary>Basically said optimization</summary>

Specialize on `T: Sized`:

```rust
fn as_ptr(&self) -> *const T {
    if [ T is Sized ] || !is_dangling(ptr) {
        (ptr as *mut T).set_ptr_value( (ptr as *mut u8).wrapping_offset(data_offset) )
    } else {
        ptr::null()
    }
}

fn from_raw(*const T) -> Self {
    if [ T is Sized ] || !ptr.is_null() {
        let ptr = (ptr as *mut RcBox).set_ptr_value( (ptr as *mut u8).wrapping_offset(-data_offset) );
        Weak { ptr }
    } else {
        Weak::new()
    }
}
```

(but with more `set_ptr_value` to avoid `Sized` restrictions and maintain metadata.)

Written in this fashion, this is not a correctness-critical specialization (i.e. so long as `[ T is Sized ]` is false for unsized `T`, it can be `rand()` for sized `T` without breaking correctness), but it's still touchy, so I'd rather do it in another PR with separate review.

---
</details>

This effectively reverts rust-lang#80422 and re-establishes rust-lang#74160. T-libs [previously signed off](rust-lang#74160 (comment)) on this stable API change in rust-lang#74160.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
beta-accepted Accepted for backporting to the compiler in the beta channel. 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants