Skip to content

Commit bca0ea9

Browse files
Try moving DefId freeze earlier
1 parent 776dc68 commit bca0ea9

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed

compiler/rustc_interface/src/passes.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,22 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
784784
}
785785
);
786786
});
787+
787788
rustc_hir_analysis::check_crate(tcx);
789+
sess.time("MIR_coroutine_by_move_body", || {
790+
tcx.hir().par_body_owners(|def_id| {
791+
if tcx.needs_coroutine_by_move_body_def_id(def_id) {
792+
tcx.ensure_with_value().coroutine_by_move_body_def_id(def_id);
793+
}
794+
});
795+
});
796+
// Freeze definitions as we don't add new ones at this point.
797+
// We need to wait until now since we synthesize a by-move body
798+
// This improves performance by allowing lock-free access to them.
799+
// FIXME(async_closures): We could force `coroutine_by_move_body_def_id`
800+
// immediately after typeck, then freeze after that.
801+
tcx.untracked().definitions.freeze();
802+
788803
sess.time("MIR_borrow_checking", || {
789804
tcx.hir().par_body_owners(|def_id| {
790805
// Run unsafety check because it's responsible for stealing and
@@ -816,12 +831,6 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
816831
);
817832
}
818833
});
819-
// Freeze definitions as we don't add new ones at this point.
820-
// We need to wait until now since we synthesize a by-move body
821-
// This improves performance by allowing lock-free access to them.
822-
// FIXME(async_closures): We could force `coroutine_by_move_body_def_id`
823-
// immediately after typeck, then freeze after that.
824-
tcx.untracked().definitions.freeze();
825834

826835
sess.time("layout_testing", || layout_test::test_layout(tcx));
827836
sess.time("abi_testing", || abi_test::test_abi(tcx));

compiler/rustc_middle/src/ty/context.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3176,6 +3176,18 @@ impl<'tcx> TyCtxt<'tcx> {
31763176
pub fn impl_polarity(self, def_id: impl IntoQueryParam<DefId>) -> ty::ImplPolarity {
31773177
self.impl_trait_header(def_id).map_or(ty::ImplPolarity::Positive, |h| h.polarity)
31783178
}
3179+
3180+
pub fn needs_coroutine_by_move_body_def_id(self, def_id: LocalDefId) -> bool {
3181+
if let Some(hir::CoroutineKind::Desugared(_, hir::CoroutineSource::Closure)) =
3182+
self.coroutine_kind(def_id)
3183+
&& let ty::Coroutine(_, args) = self.type_of(def_id).instantiate_identity().kind()
3184+
&& args.as_coroutine().kind_ty().to_opt_closure_kind() != Some(ty::ClosureKind::FnOnce)
3185+
{
3186+
true
3187+
} else {
3188+
false
3189+
}
3190+
}
31793191
}
31803192

31813193
/// Parameter attributes that can only be determined by examining the body of a function instead

compiler/rustc_mir_transform/src/lib.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -333,12 +333,7 @@ fn mir_promoted(
333333
tcx.ensure_with_value().has_ffi_unwind_calls(def);
334334

335335
// the `by_move_body` query uses the raw mir, so make sure it is run.
336-
if matches!(
337-
tcx.coroutine_kind(def),
338-
Some(hir::CoroutineKind::Desugared(_, hir::CoroutineSource::Closure))
339-
) && let ty::Coroutine(_, args) = tcx.type_of(def).instantiate_identity().kind()
340-
&& args.as_coroutine().kind_ty().to_opt_closure_kind() != Some(ty::ClosureKind::FnOnce)
341-
{
336+
if tcx.needs_coroutine_by_move_body_def_id(def) {
342337
tcx.ensure_with_value().coroutine_by_move_body_def_id(def);
343338
}
344339

0 commit comments

Comments
 (0)