Skip to content

Make -Zprofile-closures work with edition 2021 #86818

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 32 additions & 5 deletions compiler/rustc_typeck/src/check/upvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let after_feature_tys = self.final_upvar_tys(closure_def_id);

// We now fake capture information for all variables that are mentioned within the closure
// We do this after handling migrations so that min_captures computes before
if !enable_precise_capture(self.tcx, span) {
// We do this after handling migrations so that min_captures computed for closures with
// disjoint capture is used for migration ananlysis.
//
// We need to fake complete either in the case where the user doesn't have
// disjoint capture enabled (edititons before Rust 2021), or in the case where the user is
// trying to profile size of closures before and after enabling edition 2021.
let fake_info = if !enable_precise_capture(self.tcx, span)
|| self.tcx.sess.opts.debugging_opts.profile_closures
{
let mut capture_information: InferredCaptureInformation<'tcx> = Default::default();

if let Some(upvars) = self.tcx.upvars_mentioned(closure_def_id) {
Expand All @@ -203,11 +210,31 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}

capture_information
} else {
Default::default()
};

let mut before_feature_tys = Default::default();

if !enable_precise_capture(self.tcx, span) {
// This will update the min captures based on this new fake information.
self.compute_min_captures(closure_def_id, capture_clause, capture_information);
}
self.compute_min_captures(closure_def_id, capture_clause, fake_info);

// Regardless of if we profile the closure size this is the correct set
// of types before disjoint capture.
before_feature_tys = self.final_upvar_tys(closure_def_id);
} else if self.tcx.sess.opts.debugging_opts.profile_closures {
let backup = self.typeck_results.borrow().closure_min_captures.clone();

let before_feature_tys = self.final_upvar_tys(closure_def_id);
// This will update the min captures based on this new fake information.
// Since disjoint capture is enabled we don't want to actually update the information,
// therefore we made a backup before this.
self.compute_min_captures(closure_def_id, capture_clause, fake_info);
before_feature_tys = self.final_upvar_tys(closure_def_id);

self.typeck_results.borrow_mut().closure_min_captures = backup;
}

if let Some(closure_substs) = infer_kind {
// Unify the (as yet unbound) type variable in the closure
Expand Down