-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Immovable types prototype where the Move trait is builtin #44917
Conversation
r? @pnkfelix (rust_highfive has picked a reviewer for you, use r? to override) |
@bors try |
@Zoxc: 🔑 Insufficient privileges: and not in try users |
@bors try |
DO NOT MERGE: Immovable types prototype where the Move trait is builtin
☀️ Test successful - status-travis |
Crater run requested by zoxc/eddyb and now started. |
src/libcore/cell.rs
Outdated
#[cfg(not(stage0))] | ||
#[unstable(feature = "immovable_types", issue = "0")] | ||
#[lang = "movable_cell"] | ||
#[derive(Eq, PartialEq, Ord, PartialOrd, Copy, Clone, Hash, Debug)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These shouldn't be derived as the implementations would take pointers to the inner value.
a74dede
to
0f21a1c
Compare
This currently contains a hack where it catches all panics when building move data, a proper solution would be to ignore the errors and let borrowck handle them, see #44830. This also causes |
☔ The latest upstream changes (presumably #44901) made this pull request unmergeable. Please resolve the merge conflicts. |
4f75c60
to
5a3ee2b
Compare
☔ The latest upstream changes (presumably #45016) made this pull request unmergeable. Please resolve the merge conflicts. |
At long last! Sorry for the delay, internal s3 errors delayed things a fair amount. Cargobomb results: http://cargobomb-reports.s3.amazonaws.com/pr-44917/index.html. 'Blacklisted' crates (spurious failures etc) can be found here. |
I looked over the results. Errors due to duplicate bounds #21974 (comment):
Errors due to where bounds guiding type inference astray:
The above errors is also expected to appear due to the addition of the Errors due to FnOnce::Output not implementing Move:
Erros due to Deref::Target not implementing Move:
|
I fixed the MoveData hack now that #45016 finally landed. |
@Zoxc are you looking for review comments at this point? |
(@Zoxc to be clear, I am aware you've been working on this a while and discussing in the chat rooms. But I'm not sure if you expect the PR to actually be reviewed; as far as I know there isn't an RFC for this change, am I wrong?) |
@Zoxc having said that, I would like to at least coordinate the MIR-dataflow/MoveData changes made here so that they align with changes that I'm planning for the MoveData in MIR-borrowck. |
@pnkfelix This is ready to be reviewed. There is an RFC, although it was not been merged. This feature is required for experiments with immovable generators though (which does have a eRFC). The compiler team was also in favor of merging the |
@@ -1267,3 +1269,35 @@ fn assert_coerce_unsized(a: UnsafeCell<&i32>, b: Cell<&i32>, c: RefCell<&i32>) { | |||
let _: Cell<&Send> = b; | |||
let _: RefCell<&Send> = c; | |||
} | |||
|
|||
/// A cell that is always movable, even if the interior type is immovable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't a normal Cell
take T: ?Move
? I suppose that wouldn't work because we need a lang-item.
☔ The latest upstream changes (presumably #45701) made this pull request unmergeable. Please resolve the merge conflicts. |
Friendly ping to keep this on your radar @pnkfelix ! |
#[cfg(not(stage0))] | ||
#[lang = "move"] | ||
#[unstable(feature = "immovable_types", issue = "0")] | ||
pub unsafe trait Move: ?Move { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
weird: do you have to have ?Move
constraint on this trait?
Just curious, since I noticed that trait Sized
does not have an analogous ?Sized
bound...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Auto traits cannot have supertraits because that is unsound. Also we do not want Move
to require Move
. That would probably result in interesting things happening.
@@ -91,19 +91,6 @@ impl<'a> AstValidator<'a> { | |||
} | |||
} | |||
|
|||
fn no_questions_in_bounds(&self, bounds: &TyParamBounds, where_: &str, is_trait: bool) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You've removed all the calls to this method. I infer that it because you want to assume that traits automatically start off as implementing Move
, and thus you need to be able to put : ?Move
as bound on trait definitions in order to override that initial default.
But shouldn't we replace the old function with one that is specialized to (see update in followup comment below)?Sized
? Or is there some reason why we want to stop erroring in response to something like trait X : ?Sized { fn x(&self); }
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh never mind, I see that you did add such a check in fn conv_object_ty_poly_trait_ref
|
||
type A1 = Tr + ?Sized; //~ ERROR `?Trait` is not permitted in trait object types | ||
type A2 = for<'a> Tr + ?Sized; //~ ERROR `?Trait` is not permitted in trait object types | ||
type A1 = Tr + ?Sized; //~ WARN default bound relaxed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm... I'm a little worried that this error has gone away. (I'd need to review the details about why its an error in the first place, but assuming that there was a good reason for it being an error, I assume that those same reason still hold here?)
Or was this just a case of "trait objects are implicitly unsized and thus it makes no sense to put ?Sized
in them" ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trait objects previously had no default bounds, so the dyn TraitA + ?TraitB
syntax wasn't useful. However now you can use it with Move
, so dyn Trait
implements Move
, dyn Trait + ?Move
does not.
|
||
fn main() { | ||
test(immovable()); | ||
//~^ ERROR the trait bound `std::marker::Immovable: std::marker::Move` is not satisfied |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm. This is certainly fine as a conservative choice for now (I do see that the RFC says "Existential types (impl Trait) are Move if their underlying type are Move" which I take to be an "if and only if").
But I find it interesting because I would have guessed that since no borrows are taken of the value returned from immovable()
, nor do we call any methods on it that take &self
/&mut self
, that it would be safe to subsequently move it in the call to test(..)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is safe to move it into test
. The problem is that the test
function has a Move
bound, so it may rely on the type being movable after taking the address of it.
use std::marker::{PhantomData}; | ||
|
||
unsafe trait Zen {} | ||
unsafe trait Zen: ?Move {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did ... you need to add this? In other words, was it injecting new compiler errors otherwise? (If so, what were they?)
If not, then I assume you just added it because its the right way to preserve the previous semantics of the test here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Auto traits cannot have supertraits because that is unsound, so we need to opt-out to Move
, which is a default bound on Self
for all traits.
trait MarkerTr {} | ||
use std::marker::Move; | ||
|
||
trait MarkerTr: ?Move {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(likewise here, I am again curious as to whether this was a necessary change, or just an artifact of your methodology for updating the tests...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I'll stop asking about the future instances of this pattern now, though.)
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
#![feature(conservative_impl_trait, specialization)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see you factored this test out from a separate piece of code that started failing (in a new way) in src/test/ui/impl-trait/equality.rs
... do we need to be concerned about this change in behavior? I.e. Does it need a separate issue filed for it, once this PR lands?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I split this out since this error happens in another compiler phase compared to the rest. I don't remember the details, but I probably did something which caused the compiler to exit earlier due to errors.
Looks fine to me. I had a bunch of questions that I posted as comments on the diff. But I don't think any of them actually warrant holding up trying to land this (assuming that we're collectively fine with landing this as an experimental extension for non-finalized RFC). So, r=me after a rebase (but I'd love to see those questions answered!) |
let a = new_box_immovable(); | ||
&*a; // ok | ||
move_from_box(a); // ok | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing newline
#[stable(feature = "catch_unwind", since = "1.9.0")] | ||
impl<'a, T: ?Sized> !UnwindSafe for &'a mut T {} | ||
#[cfg(not(stage0))] | ||
#[stable(feature = "catch_unwind", since = "1.9.0")] | ||
impl<'a, T: ?Sized+?::marker::Move> !UnwindSafe for &'a mut T {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing spaces around the +
#[stable(feature = "catch_unwind", since = "1.9.0")] | ||
impl<T: ?Sized> !RefUnwindSafe for UnsafeCell<T> {} | ||
#[cfg(not(stage0))] | ||
#[stable(feature = "catch_unwind", since = "1.9.0")] | ||
impl<T: ?Sized+?::marker::Move> !RefUnwindSafe for UnsafeCell<T> {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing spaces around the +
} | ||
} | ||
|
||
fn main() {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing newline
I'm not sure why @pnkfelix is still assigned here. I saw @arielb1 unassign him in the log. Anyway this is still blocked on @arielb1 and @nikomatsakis looking into fixing the breaking changes and looking into the changes on the |
Hi @Zoxc, is this still blocked by the |
Yes. |
Friendly ping @arielb1 and @nikomatsakis, this comment seems to say this is waiting on you!
|
Triage — this PR appears to be still blocked by
BTW @Zoxc There is merge conflict. |
Status of the Move/DynSized PRsI apologize that this was not communicated clearly enough, but there are breakage and language-design issues blocking these PRs. We are probably not going to merge them until these are solved:
|
rust-lang/rfcs#2255 seems relevant to @arielb1's second point (quoted here)
|
Immovable generators This adds support for immovable generators which allow you to borrow local values inside generator across suspension points. These are declared using a `static` keyword: ```rust let mut generator = static || { let local = &Vec::new(); yield; local.push(0i8); }; generator.resume(); // ERROR moving the generator after it has resumed would invalidate the interior reference // drop(generator); ``` Region inference is no longer affected by the types stored in generators so the regions inside should be similar to other code (and unaffected by the presence of `yield` expressions). The borrow checker is extended to pick up the slack so interior references still result in errors for movable generators. This fixes #44197, #45259 and #45093. This PR depends on [PR #44917 (immovable types)](#44917), I suggest potential reviewers ignore the first commit as it adds immovable types.
No description provided.