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 upTracking issue for `borrow_state` stabilization #27733
Comments
aturon
added
T-libs
B-unstable
labels
Aug 12, 2015
alexcrichton
added
the
E-easy
label
Aug 13, 2015
Ms2ger
referenced this issue
Aug 16, 2015
Open
Tracking: Unstable Rust feature gates used by Servo #5286
This comment has been minimized.
This comment has been minimized.
|
I believe @nikomatsakis has mentioned that he's found a use for these methods at some point, but I can't remember what those uses were off the top of my head. |
This comment has been minimized.
This comment has been minimized.
|
I've never used this pattern in Rust, but in previous lives I've been in the situation where I had a graph that was supposed to be acyclic. I was walking the graph, acquiring locks on the nodes as I went. This should not result in deadlock. The problem was that the graph was constructed from untrusted user input, and hence a deadlock was possible if the input was in error. This was neatly solved by using a 'try lock' structure, such that whenever we failed to acquire a lock, we could infer that the graph was potentially cyclic (and, if so, report an error). I can easily imagine a similar scenario arising with |
alexcrichton
added
the
I-nominated
label
Sep 17, 2015
This comment has been minimized.
This comment has been minimized.
|
This issue is now entering its cycle-long FCP for stabilization in 1.5 |
alexcrichton
added
final-comment-period
and removed
I-nominated
labels
Sep 24, 2015
steveklabnik
added this to the 1.5 milestone
Oct 1, 2015
Manishearth
removed
the
E-easy
label
Oct 2, 2015
This comment has been minimized.
This comment has been minimized.
|
I argued in the meeting today that we should instead opt to break the fallible/infallible convention and just have General ambivalence about this problem. This will remain unstable for at least one more release. |
This comment has been minimized.
This comment has been minimized.
|
The libs team discussed this during triage today and the decision was to punt to a future FCP. |
alexcrichton
removed
the
final-comment-period
label
Oct 22, 2015
This comment has been minimized.
This comment has been minimized.
|
I find the "borrow-state" version rather annoying to use in practice. For On Wed, Oct 21, 2015 at 5:06 PM, Alex Crichton notifications@github.com
|
This comment has been minimized.
This comment has been minimized.
|
+1 for one method returning |
This comment has been minimized.
This comment has been minimized.
|
So to be clear here, the issue at hand is that we long ago settled on a simple convention to avoid combinatoric bloat:
This stance is strongly championed by @alexcrichton and @aturon, and for good reason! I don't want to live in a world with Vec::try_insert, try_remove, try_swap_remove, ...etc. However I maintain that all good conventions exist to be broken! Most obviously, we break this convention with indexing (and soon, slicing!). Part of this is that indexing and slicing are so fundamental that they deserve several ways to do them. Indexing in particular has 4:
At the heart of this convention is "decide if this is panicky or should be checked". For most interfaces we deem that it should be checked, because that's the strictly more general operation. There are two reasons to use panciky ops:
Index-based ops like insert/remove have both of these properties, and are therefore a great candidate for panicky ops. RefCell only has the second condition. It would be an ergonomic nightmare to have to unwrap ever borrow, so we went for panicky. However there's no way to introspect its state to check in a pinch. In deference to The Convention, the original solution was to make it so it could be trivially checked, but the problem here is that checking is totally useless unless you're about to |
This comment has been minimized.
This comment has been minimized.
|
@Gankro I definitely think
The downside of "try" variants, of course, is just that you need to have one per function, typically, whereas you only need one method to expose the state. I wanted to expand on point 4, about forwards compatibility. I could imagine wanting to extend Another way to address concerns 2 and 4 (but not 3) by making the borrow-state opaque and have it offer methods like |
This comment has been minimized.
This comment has been minimized.
|
To be clear, I'm not advocating that borrow_state is more ergonomic than I see @Gankro's slicing/indexing examples above as separate because they all deal with @nikomatsakis I definitely agree with many of your points, and it's why this is an extreme case for I also disagree that it's a cliff in terms of ergnomics, e.g. compare: if let Some(borrow) = cell.try_borrow_mut() {
// ...
}and if let BorrowState::None = cell.borrow_state() {
// .. work with cell.borrow_mut()
}Again, though, I'm not claiming it to be more ergonomic, I just want to point out that it's not necessarily the end of the world. This is especially compounded by the fact that we're talking about the 0.1% use case, if it were expected to be called quite a bit then we'd of course choose the more ergonomic version. I think your suggestion about method accessors would also be fine as it'd even reduce the number of imports! |
This comment has been minimized.
This comment has been minimized.
|
I think the real comparison is: if let Some(borrow) = cell.try_borrow_mut() {
}and use std::cell::BorrowState;
...
if BorrowState::None == cell.borrow_state() {
let borrow = cell.borrow_mut();
..
}I certainly agree it's not the end of the world, but I still think it kind I also disagree that this use case is 0.1%. I agree that detecting a cycle, However, ultimately, I would perhaps be mollified if we removed the borrow |
alexcrichton
added
the
I-nominated
label
Jan 27, 2016
This comment has been minimized.
This comment has been minimized.
|
Although I nominated this for stabilization in 1.8, the libs team decided against it due to the double-check on the borrow flag. We'd instead like to explore methods like |
alexcrichton
removed
the
I-nominated
label
Jan 29, 2016
alexcrichton
removed this from the 1.5 milestone
Jan 29, 2016
SimonSapin
referenced this issue
Jun 27, 2016
Merged
Introduce non-panicking borrow methods on `RefCell<T>` #1660
This comment has been minimized.
This comment has been minimized.
|
Isn't this code a race condition, in that it still may panic?
I'm not saying that |
This comment has been minimized.
This comment has been minimized.
|
@cbreeden |
This comment has been minimized.
This comment has been minimized.
|
oh right, thanks for clarifying that :) |
This comment has been minimized.
This comment has been minimized.
|
@rfcbot fcp close We've added/stabilized |
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Nov 1, 2016
•
|
Team member @alexcrichton has proposed to close this. The next step is review by the rest of the tagged teams: No concerns currently listed. Once these reviewers reach consensus, this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Nov 12, 2016
|
psst @alexcrichton, I wasn't able to add the |
alexcrichton
added
the
final-comment-period
label
Nov 12, 2016
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Nov 22, 2016
|
The final comment period is now complete. |
aturon
referenced this issue
Dec 14, 2016
Merged
Library stabilizations/deprecations for 1.15 release #38369
bors
added a commit
that referenced
this issue
Dec 16, 2016
bors
added a commit
that referenced
this issue
Dec 16, 2016
bors
added a commit
that referenced
this issue
Dec 16, 2016
bors
added a commit
that referenced
this issue
Dec 16, 2016
bors
added a commit
that referenced
this issue
Dec 18, 2016
bors
added a commit
that referenced
this issue
Dec 18, 2016
bors
closed this
in
#38369
Dec 18, 2016
This comment has been minimized.
This comment has been minimized.
|
It turns out I actually have a use case in Servo where I can't use |
aturon commentedAug 12, 2015
The
RefCellAPI offers a way to determine the state of the borrow, to avoid panics on additional borrowing. It's not clear how useful this API is in practice, but it's otherwise ready for stabilization.