Skip to content

Commit 71ec145

Browse files
committed
Auto merge of #105436 - nnethercote:inline-place_contents_drop_state_cannot_differ, r=spastorino
Inline and remove `place_contents_drop_state_cannot_differ`. It has a single call site and is hot enough to be worth inlining. And make sure `is_terminal_path` is inlined, too. r? `@ghost`
2 parents b96d9e0 + 68a1920 commit 71ec145

File tree

1 file changed

+46
-51
lines changed

1 file changed

+46
-51
lines changed

compiler/rustc_mir_dataflow/src/drop_flag_effects.rs

+46-51
Original file line numberDiff line numberDiff line change
@@ -29,56 +29,6 @@ where
2929
None
3030
}
3131

32-
/// When enumerating the child fragments of a path, don't recurse into
33-
/// paths (1.) past arrays, slices, and pointers, nor (2.) into a type
34-
/// that implements `Drop`.
35-
///
36-
/// Places behind references or arrays are not tracked by elaboration
37-
/// and are always assumed to be initialized when accessible. As
38-
/// references and indexes can be reseated, trying to track them can
39-
/// only lead to trouble.
40-
///
41-
/// Places behind ADT's with a Drop impl are not tracked by
42-
/// elaboration since they can never have a drop-flag state that
43-
/// differs from that of the parent with the Drop impl.
44-
///
45-
/// In both cases, the contents can only be accessed if and only if
46-
/// their parents are initialized. This implies for example that there
47-
/// is no need to maintain separate drop flags to track such state.
48-
//
49-
// FIXME: we have to do something for moving slice patterns.
50-
fn place_contents_drop_state_cannot_differ<'tcx>(
51-
tcx: TyCtxt<'tcx>,
52-
body: &Body<'tcx>,
53-
place: mir::Place<'tcx>,
54-
) -> bool {
55-
let ty = place.ty(body, tcx).ty;
56-
match ty.kind() {
57-
ty::Array(..) => {
58-
debug!(
59-
"place_contents_drop_state_cannot_differ place: {:?} ty: {:?} => false",
60-
place, ty
61-
);
62-
false
63-
}
64-
ty::Slice(..) | ty::Ref(..) | ty::RawPtr(..) => {
65-
debug!(
66-
"place_contents_drop_state_cannot_differ place: {:?} ty: {:?} refd => true",
67-
place, ty
68-
);
69-
true
70-
}
71-
ty::Adt(def, _) if (def.has_dtor(tcx) && !def.is_box()) || def.is_union() => {
72-
debug!(
73-
"place_contents_drop_state_cannot_differ place: {:?} ty: {:?} Drop => true",
74-
place, ty
75-
);
76-
true
77-
}
78-
_ => false,
79-
}
80-
}
81-
8232
pub fn on_lookup_result_bits<'tcx, F>(
8333
tcx: TyCtxt<'tcx>,
8434
body: &Body<'tcx>,
@@ -105,13 +55,58 @@ pub fn on_all_children_bits<'tcx, F>(
10555
) where
10656
F: FnMut(MovePathIndex),
10757
{
58+
#[inline]
10859
fn is_terminal_path<'tcx>(
10960
tcx: TyCtxt<'tcx>,
11061
body: &Body<'tcx>,
11162
move_data: &MoveData<'tcx>,
11263
path: MovePathIndex,
11364
) -> bool {
114-
place_contents_drop_state_cannot_differ(tcx, body, move_data.move_paths[path].place)
65+
let place = move_data.move_paths[path].place;
66+
67+
// When enumerating the child fragments of a path, don't recurse into
68+
// paths (1.) past arrays, slices, and pointers, nor (2.) into a type
69+
// that implements `Drop`.
70+
//
71+
// Places behind references or arrays are not tracked by elaboration
72+
// and are always assumed to be initialized when accessible. As
73+
// references and indexes can be reseated, trying to track them can
74+
// only lead to trouble.
75+
//
76+
// Places behind ADT's with a Drop impl are not tracked by
77+
// elaboration since they can never have a drop-flag state that
78+
// differs from that of the parent with the Drop impl.
79+
//
80+
// In both cases, the contents can only be accessed if and only if
81+
// their parents are initialized. This implies for example that there
82+
// is no need to maintain separate drop flags to track such state.
83+
//
84+
// FIXME: we have to do something for moving slice patterns.
85+
let ty = place.ty(body, tcx).ty;
86+
match ty.kind() {
87+
ty::Adt(def, _) if (def.has_dtor(tcx) && !def.is_box()) || def.is_union() => {
88+
debug!(
89+
"place_contents_drop_state_cannot_differ place: {:?} ty: {:?} Drop => true",
90+
place, ty
91+
);
92+
true
93+
}
94+
ty::Array(..) => {
95+
debug!(
96+
"place_contents_drop_state_cannot_differ place: {:?} ty: {:?} => false",
97+
place, ty
98+
);
99+
false
100+
}
101+
ty::Slice(..) | ty::Ref(..) | ty::RawPtr(..) => {
102+
debug!(
103+
"place_contents_drop_state_cannot_differ place: {:?} ty: {:?} refd => true",
104+
place, ty
105+
);
106+
true
107+
}
108+
_ => false,
109+
}
115110
}
116111

117112
fn on_all_children_bits<'tcx, F>(

0 commit comments

Comments
 (0)