Skip to content
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

Fix late-bound lifetime closure ICEs in HIR typeck and MIR borrowck #103780

Merged
merged 6 commits into from
Nov 4, 2022

Conversation

compiler-errors
Copy link
Member

During HIR typeck, we need to teach astconv to treat late-bound regions within a closure body as free, fixing escaping bound vars ICEs in both of the issues below.

However, this then gets us to MIR borrowck, which itself needs to be taught how to instantiate free region vids for late-bound regions that come from items that aren't the typeck root (for now, just closures).

Fixes #103771
Fixes #103736

@rustbot
Copy link
Collaborator

rustbot commented Oct 30, 2022

r? @wesleywiser

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 30, 2022
@compiler-errors compiler-errors changed the title Bound closure lifetimes Fix late-bound lifetime closure ICEs in HIR typeck and MIR borrowck Oct 30, 2022
@cjgillot
Copy link
Contributor

@compiler-errors are you missing part of the first commit? The diff is unrelated to the message.

@rust-log-analyzer

This comment has been minimized.

@compiler-errors
Copy link
Member Author

compiler-errors commented Oct 30, 2022

@cjgillot I didn't forget anything, though I could've named it better. Let me rename it.

@compiler-errors compiler-errors force-pushed the bound-closure-lifetimes branch from 6282e0c to 9c9282d Compare October 31, 2022 01:48
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@compiler-errors compiler-errors force-pushed the bound-closure-lifetimes branch from f6b3cca to c012e56 Compare October 31, 2022 03:58
compiler/rustc_borrowck/src/universal_regions.rs Outdated Show resolved Hide resolved
compiler/rustc_borrowck/src/universal_regions.rs Outdated Show resolved Hide resolved
compiler/rustc_borrowck/src/universal_regions.rs Outdated Show resolved Hide resolved
compiler/rustc_middle/src/ty/context.rs Outdated Show resolved Hide resolved
if let Some(late_bounds) = tcx.is_late_bound_map(fn_def_id.expect_local()) {
for &region_def_id in late_bounds.iter() {
let name = tcx.item_name(region_def_id.to_def_id());
let typeck_root_def_id = tcx.typeck_root_def_id(mir_def_id.to_def_id());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To have a single loop, we can use while tcx.is_typeck_child(mir_def_id.to_def_id()).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That doesn't loop over the root def id, but stops one def id before it -- I'm not sure if I understand?

compiler/rustc_borrowck/src/universal_regions.rs Outdated Show resolved Hide resolved
@compiler-errors compiler-errors force-pushed the bound-closure-lifetimes branch from c012e56 to 2768c2f Compare October 31, 2022 21:26
) -> IndexVec<RegionVid, ty::Region<'tcx>> {
let mut region_mapping = IndexVec::with_capacity(expected_num_vars);
region_mapping.push(tcx.lifetimes.re_static);
tcx.for_each_free_region(&closure_substs, |fr| {
region_mapping.push(fr);
});

for_each_late_bound_region_defined_on(tcx, typeck_root_def_id, |r| {
for_each_late_bound_region_in_recursive_scope(tcx, tcx.local_parent(closure_def_id), |r| {
Copy link
Member

@aliemjay aliemjay Nov 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: This functions now assumes being called from the strict parent of the closure, not any higher parent. Can we make it a method on UniversalRegions and add assert_eq!(self.len(), expected_num_vars) and assert_eq!(self.defining_ty.def_id(), tcx.parent(closure_def_id))

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make it a method on UniversalRegions

Make what a method? for_each_late_bound_region_in_recursive_scope?

and add assert_eq!(self.len(), expected_num_vars)

What's the difference between this assertion and the one that happens below?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make what a method?

I meant closure_mapping.

What's the difference between this assertion and the one that happens below?

Oops, I missed that. I guess it is sufficient then.

@jackh726
Copy link
Member

jackh726 commented Nov 2, 2022

r=me with or without @aliemjay's comment

@compiler-errors
Copy link
Member Author

@bors r=jackh726

@bors
Copy link
Contributor

bors commented Nov 3, 2022

📌 Commit 2768c2f has been approved by jackh726

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 3, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 4, 2022
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#103680 (CStr: add some doc links)
 - rust-lang#103780 (Fix late-bound lifetime closure ICEs in HIR typeck and MIR borrowck)
 - rust-lang#103845 (Add track_caller to some Lock methods)
 - rust-lang#103935 (Remove rustdoc clean::Visibility type)
 - rust-lang#103941 (Fixed typos)
 - rust-lang#103950 (Fix ICE when negative impl is collected during eager mono)
 - rust-lang#103953 (Remove unused argument from `throw_unresolved_import_error`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit d10187f into rust-lang:master Nov 4, 2022
@rustbot rustbot added this to the 1.67.0 milestone Nov 4, 2022
@compiler-errors compiler-errors deleted the bound-closure-lifetimes branch November 5, 2022 01:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ICE normalizing binder for closure ICE when using closure_lifetime_binder lifetime inside closure body
8 participants