Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign uprefactor NonZero, Shared, and Unique APIs #41064
Conversation
rust-highfive
assigned
alexcrichton
Apr 4, 2017
This comment has been minimized.
This comment has been minimized.
|
(rust_highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
|
CC @eddyb who brought up the Deref issue. |
Gankro
reviewed
Apr 4, 2017
| // the contract anyway. | ||
| // This allows the null check to be elided in the destructor if we | ||
| // manipulated the reference count in the same function. | ||
| assume(!(*(&self.ptr as *const _ as *const *const ())).is_null()); |
This comment has been minimized.
This comment has been minimized.
Gankro
Apr 4, 2017
Author
Contributor
NOTE: I removed these assumes because they should be implied from NonZero, and the point of these changes is to make that metadata propagate more readily. Should probably try to validate that somehow? Not sure the best way forward.
This comment has been minimized.
This comment has been minimized.
alexcrichton
Apr 4, 2017
Member
I think you can test this out by taking a look at the IR for:
fn foo(r: &Rc<i32>) {
drop(r.clone());
}Ideally that's a noop function.
This comment has been minimized.
This comment has been minimized.
eddyb
Apr 6, 2017
Member
You may need to copy it to NonZero::get (if you can), at least until we have it in the compiler.
This comment has been minimized.
This comment has been minimized.
Gankro
Apr 7, 2017
Author
Contributor
I'm a bit concerned that copying an assume to NonZero::get will be disastrous to compile times (as this will show up in all accesses to every collection). Have those bloat problems with assume been resolved?
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Gankro
referenced this pull request
Apr 4, 2017
Closed
Tracking issue for `NonZero`/`Unique`/`Shared` stabilization #27730
This comment has been minimized.
This comment has been minimized.
|
Oh I also made Unique Copy/Clone, because it's unclear what value move semantics has here. |
This comment has been minimized.
This comment has been minimized.
This is kind of a weak argument, but copying or cloning seems contrary to the name "unique" or the docs "indicates that the possessor of this wrapper owns the referent". And is this useful? Something that contains |
This comment has been minimized.
This comment has been minimized.
|
Primary motivation for Copyable Unique was to have a by-value getter and maybe tax the optimizer a tiny bit less. Also to make it more of a drop-in-replacement for *mut; possibly if you're just trying to use it as an optimizer hint? I'm not particularly passionate about it either way. Maybe @nikomatsakis can speak to aliasing model implications? |
This comment has been minimized.
This comment has been minimized.
|
I appreciate not stressing the optimizer, but doing that does make for an annoying footgun. |
This comment has been minimized.
This comment has been minimized.
|
Every Unique lives in a struct that owns it, so I don't know what the footgun could possibly be; especially since using the Unique requires you to immediately turn it into a primitive pointer that can be copied. |
This comment has been minimized.
This comment has been minimized.
|
It's been a while, but I vaguely recall using "raw" Uniques not inside some other struct as a last-ditch attempt to prevent unwanted aliasing. Even if the wrapped struct case, there is still code working with the wrapper. |
alexcrichton
reviewed
Apr 4, 2017
| pub fn ptr(self) -> *mut T { | ||
| self.pointer.get() as *mut _ | ||
| } | ||
|
|
||
| /// Dereferences the content. | ||
| pub unsafe fn get(&self) -> &T { |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
alexcrichton
added
the
T-libs
label
Apr 4, 2017
This comment has been minimized.
This comment has been minimized.
|
These are so low-level I'm ok with adding |
This comment has been minimized.
This comment has been minimized.
|
|
eddyb
reviewed
Apr 6, 2017
| &*self.ptr() | ||
| } | ||
|
|
||
| /// Mutably dereferences the content. |
This comment has been minimized.
This comment has been minimized.
eddyb
Apr 6, 2017
Member
Should this be on Shared at all? I'd expect interior mutability to be required - or I suppose we could just have something along the lines "you shouldn't ever use this unless there is no other reference around" in the documentation (e.g. Rc with a refcount of 1).
This comment has been minimized.
This comment has been minimized.
That's a breaking change AFAIK, I think it's for variance. |
This comment has been minimized.
This comment has been minimized.
|
@eddyb it still contains a Shared has, basically, no semantics other than "it's non-null" and "it doesn't have It's possible there's interesting aliasing rules to document here, but until someone figures out what Rust's aliasing rules are, that's simply impossible. |
This comment has been minimized.
This comment has been minimized.
|
@Gankro Ahh, okay, keeping The refcounts are |
This comment has been minimized.
This comment has been minimized.
I can't speak to it with certainty, except to say that I think there is pretty broad consensus that errors ought to be mostly about which pointers get dereferenced and when, not which get copied from place to place. |
Mark-Simulacrum
added
the
S-waiting-on-author
label
Apr 14, 2017
This comment has been minimized.
This comment has been minimized.
|
Ping to keep this on your radar @Gankro! |
This comment has been minimized.
This comment has been minimized.
|
I'm not sure this is really blocked on me. The only real requested change is from @alexcrichton, but really the blocker is on libs/lang team people agreeing on the design. |
This comment has been minimized.
This comment has been minimized.
|
Another API question that I kinda spaced out on: the current design does |
This comment has been minimized.
This comment has been minimized.
|
@Gankro Oh I thought it should be in your court because there are merge conflicts and test failures. Are you waiting on approval from libs/lang on the design before fixing those? |
This comment has been minimized.
This comment has been minimized.
|
Yeah |
carols10cents
added
S-waiting-on-review
and removed
S-waiting-on-author
labels
Apr 17, 2017
This comment has been minimized.
This comment has been minimized.
|
I'll cc @rust-lang/libs to see if anyone else would like to leave a comment, but typically if we're not stabilizing something we don't discuss PRs during triage (as it's just too much to process). I would be comfortable r+'ing w/ my minor comment and a rebase. |
frewsxcv
added a commit
to frewsxcv/rust
that referenced
this pull request
May 5, 2017
bors
added a commit
that referenced
this pull request
May 5, 2017
This comment has been minimized.
This comment has been minimized.
|
|
bors
merged commit e8234e0
into
rust-lang:master
May 6, 2017
This was referenced May 7, 2017
jonhoo
added a commit
to jonhoo/arccstr
that referenced
this pull request
May 9, 2017
phil-opp
referenced this pull request
May 9, 2017
Closed
Compilation fails on latest nightly due to core::ptr::Unique refactor #324
This comment has been minimized.
This comment has been minimized.
twmb
commented
May 12, 2017
|
I believe the documentation needs updated to no longer refer to |
Gankro commentedApr 4, 2017
Major difference is that I removed Deref impls, as apparently LLVM has
trouble maintaining metadata with a
&ptr -> &ptrAPI. This was citedas a blocker for ever stabilizing this API. It wasn't that ergonomic
anyway.
getto NonZero to replace Deref implptrgetter to Shared/Unique to replace Deref implgetandget_mutconveniences to Sharedas_mut_ptron Shared in favour ofptrNote that Shared used to primarily expose only
*constbut there isn'ta good justification for that, so I made it
*mut.