-
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
Reduce false positives of tail-expr-drop-order from consumed values (attempt #2) #131326
base: master
Are you sure you want to change the base?
Reduce false positives of tail-expr-drop-order from consumed values (attempt #2) #131326
Conversation
Some changes occurred to the CTFE / Miri interpreter cc @rust-lang/miri Some changes occurred in src/tools/clippy cc @rust-lang/clippy Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt Some changes occurred in coverage instrumentation. cc @Zalathar This PR changes Stable MIR cc @oli-obk, @celinval, @ouz-a Some changes occurred in compiler/rustc_codegen_cranelift cc @bjorn3 This PR changes MIR cc @oli-obk, @RalfJung, @JakobDegen, @davidtwco, @celinval, @vakaras Some changes occurred in match lowering cc @Nadrieril |
31f4a7f
to
39b18f4
Compare
I still have two issues.
About the futuresTake the crate
|
This comment has been minimized.
This comment has been minimized.
39b18f4
to
e6641cf
Compare
This comment has been minimized.
This comment has been minimized.
e6641cf
to
0c227e9
Compare
This comment has been minimized.
This comment has been minimized.
@rustbot labels +A-edition-2024 |
This comment has been minimized.
This comment has been minimized.
@bors try |
…t-2, r=<try> Reduce false positives of tail-expr-drop-order from consumed values (attempt #2) r? `@nikomatsakis` Related to rust-lang#129864 but not replacing, yet. Related to rust-lang#130836. This is an implementation of the approach suggested in the [Zulip stream](https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/temporary.20drop.20order.20changes). A new MIR statement `BackwardsIncompatibleDrop` is added to the MIR syntax. The lint now works by inspecting possibly live move paths before at the `BackwardsIncompatibleDrop` location and the actual drop under the current edition, which should be one before Edition 2024 in practice.
☀️ Try build successful - checks-actions |
@bors try |
…t-2, r=<try> Reduce false positives of tail-expr-drop-order from consumed values (attempt #2) r? `@nikomatsakis` Related to rust-lang#129864 but not replacing, yet. Related to rust-lang#130836. This is an implementation of the approach suggested in the [Zulip stream](https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/temporary.20drop.20order.20changes). A new MIR statement `BackwardsIncompatibleDrop` is added to the MIR syntax. The lint now works by inspecting possibly live move paths before at the `BackwardsIncompatibleDrop` location and the actual drop under the current edition, which should be one before Edition 2024 in practice.
This comment has been minimized.
This comment has been minimized.
☀️ Try build successful - checks-actions |
@compiler-errors Shall we give it a crater run with |
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.
Overall this seems much better than before! Minimally invasive, which is good.
{ | ||
visitor.terminating_scopes.insert(tail_expr.hir_id.local_id); | ||
// Note: we are unconditionally adding this information so that we can run |
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.
The word "unconditionally" is confusing here, since clearly this insert call is conditioned on several things (edition, lint level, etc). I think I know what you mean by it, perhaps rewrite to
// If this temporary scope will be changing once the codebase adopts Rust 2024,
// and we are linting about possible semantic changes that would result,
// then record this node-id in the field `backwards_incompatible_scope`
// for future reference.
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.
Applied. The original comment was added when I thought it was right to insert the linting info under all circumstances. Given that we only want to lint when edition migration is run, I changed the condition when the linting info is inserted.
compiler/rustc_middle/src/thir.rs
Outdated
/// Lifetime for temporaries as expected. | ||
/// This should be `None` in a constant context. | ||
pub temp_lifetime: Option<region::Scope>, | ||
/// Backward-incompatible lifetime for future editions |
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 would say:
/// If `Some(lt)`, indicates that the lifetime of this temporary will change to `lt` in a future edition.
/// If `None`, then no changes are expected, or lints are disabled.
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.
Applied
cc @traviscross for visibility |
@bors try |
…t-2, r=<try> Reduce false positives of tail-expr-drop-order from consumed values (attempt #2) r? `@nikomatsakis` Tracked by rust-lang#123739. Related to rust-lang#129864 but not replacing, yet. Related to rust-lang#130836. This is an implementation of the approach suggested in the [Zulip stream](https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/temporary.20drop.20order.20changes). A new MIR statement `BackwardsIncompatibleDrop` is added to the MIR syntax. The lint now works by inspecting possibly live move paths before at the `BackwardsIncompatibleDrop` location and the actual drop under the current edition, which should be one before Edition 2024 in practice.
bb15b7c
to
2f5657b
Compare
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.
OK, left some comments, but also a few questions.
☔ The latest upstream changes (presumably #132027) made this pull request unmergeable. Please resolve the merge conflicts. |
55a1a8b
to
4cc5482
Compare
@rustbot ready
There are merge conflicts but I would prefer to get feedback first for the general framework and outlook of the lint messages. |
take 2 open up coroutines tweak the wordings the lint works up until 2021 We were missing one case, for ADTs, which was causing `Result` to yield incorrect results. only include field spans with significant types deduplicate and eliminate field spans switch to emit spans to impl Drops Co-authored-by: Niko Matsakis <nikomat@amazon.com>
509f9d0
to
b66ccf0
Compare
This comment has been minimized.
This comment has been minimized.
Some changes occurred to the CTFE machinery cc @rust-lang/wg-const-eval |
f6b0503
to
56fea8d
Compare
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.
Since the new statement has no semantic, can we just handle it as a Nop
in StableMir? Thanks!
mir::StatementKind::BackwardIncompatibleDropHint { place, reason } => { | ||
stable_mir::mir::StatementKind::BackwardIncompatibleDropHint { | ||
place: place.stable(tables), | ||
reason: reason.stable(tables), | ||
} | ||
} |
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.
Since this has no semantics, can we translate it to Nop
for now?
mir::StatementKind::BackwardIncompatibleDropHint { place, reason } => { | |
stable_mir::mir::StatementKind::BackwardIncompatibleDropHint { | |
place: place.stable(tables), | |
reason: reason.stable(tables), | |
} | |
} | |
mir::StatementKind::BackwardIncompatibleDropHint { .. } => stable_mir::mir::StatementKind::Nop, |
impl<'tcx> Stable<'tcx> for mir::BackwardIncompatibleDropReason { | ||
type T = stable_mir::mir::BackwardIncompatibleDropReason; | ||
|
||
fn stable(&self, _tables: &mut Tables<'_>) -> Self::T { | ||
match self { | ||
mir::BackwardIncompatibleDropReason::Edition2024 => { | ||
stable_mir::mir::BackwardIncompatibleDropReason::Edition2024 | ||
} | ||
} | ||
} | ||
} | ||
|
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.
then we can cleanup all the other code that was added to StableMIR.
impl<'tcx> Stable<'tcx> for mir::BackwardIncompatibleDropReason { | |
type T = stable_mir::mir::BackwardIncompatibleDropReason; | |
fn stable(&self, _tables: &mut Tables<'_>) -> Self::T { | |
match self { | |
mir::BackwardIncompatibleDropReason::Edition2024 => { | |
stable_mir::mir::BackwardIncompatibleDropReason::Edition2024 | |
} | |
} | |
} | |
} |
@@ -448,9 +448,15 @@ pub enum StatementKind { | |||
Coverage(Coverage), | |||
Intrinsic(NonDivergingIntrinsic), | |||
ConstEvalCounter, | |||
BackwardIncompatibleDropHint { place: Place, reason: BackwardIncompatibleDropReason }, |
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.
BackwardIncompatibleDropHint { place: Place, reason: BackwardIncompatibleDropReason }, | |
/// This has no semantics. E.g.: BackwardIncompatibleDropHint is translated to Nop. |
#[derive(Clone, Debug, Eq, PartialEq, Serialize)] | ||
pub enum BackwardIncompatibleDropReason { | ||
Edition2024, | ||
} | ||
|
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.
#[derive(Clone, Debug, Eq, PartialEq, Serialize)] | |
pub enum BackwardIncompatibleDropReason { | |
Edition2024, | |
} |
StatementKind::BackwardIncompatibleDropHint { place, reason: _ } => { | ||
writeln!(writer, "backwards incompatible drop({place:?});") | ||
} |
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.
StatementKind::BackwardIncompatibleDropHint { place, reason: _ } => { | |
writeln!(writer, "backwards incompatible drop({place:?});") | |
} |
StatementKind::BackwardIncompatibleDropHint { .. } | ||
| StatementKind::ConstEvalCounter | ||
| StatementKind::Nop => {} |
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.
StatementKind::BackwardIncompatibleDropHint { .. } | |
| StatementKind::ConstEvalCounter | |
| StatementKind::Nop => {} | |
StatementKind::ConstEvalCounter | StatementKind::Nop => {} |
☔ The latest upstream changes (presumably #132762) made this pull request unmergeable. Please resolve the merge conflicts. |
r? @nikomatsakis
Tracked by #123739.
Related to #129864 but not replacing, yet.
Related to #130836.
This is an implementation of the approach suggested in the Zulip stream. A new MIR statement
BackwardsIncompatibleDrop
is added to the MIR syntax. The lint now works by inspecting possibly live move paths before at theBackwardsIncompatibleDrop
location and the actual drop under the current edition, which should be one before Edition 2024 in practice.