Skip to content

Make mir borrowck's use of opaque types independent of the typeck query's result #87287

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

Merged
merged 7 commits into from
Jul 23, 2021
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Resolve nested inference variables.
I attempted that with the previous code, but I misunderstdood how
`shallow_resolve` works.
  • Loading branch information
oli-obk committed Jul 22, 2021
commit 9f09a5eb8b9b59360528f24f0c73fdaf6bf3300a
26 changes: 7 additions & 19 deletions compiler/rustc_mir/src/borrow_check/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,25 +182,13 @@ pub(crate) fn type_check<'mir, 'tcx>(
let mut opaque_type_values = cx.opaque_type_values;

for (_, revealed_ty) in &mut opaque_type_values {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does opaque_type_values contain elements at the start of the loop? It seems to me that the only place where elements were inserted into this field was in the code you deleted below?

Copy link
Contributor Author

@oli-obk oli-obk Jul 20, 2021

Choose a reason for hiding this comment

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

yes, but the function where I deleted code is called multiple times. The opaque types are collected over time.

// FIXME(oli-obk): Instead of looping, implement a visitor like
// FullTypeResolver. We can't use FullTypeResolver here, as that will
// resolve lifetimes lexically, which it can't because we didn't do old
// borrowck stuff. We want to use MIR borrowck information instead.

while revealed_ty.has_infer_types_or_consts() {
let prev = *revealed_ty;
trace!(prev=?prev.kind());
let type_resolved = infcx.shallow_resolve(prev);
trace!(type_resolved=?type_resolved.kind());
if prev == type_resolved {
infcx.tcx.sess.delay_span_bug(
body.span,
&format!("could not resolve {:#?}", type_resolved.kind()),
);
*revealed_ty = infcx.tcx.ty_error();
break;
}
*revealed_ty = type_resolved;
*revealed_ty = infcx.resolve_vars_if_possible(*revealed_ty);
if revealed_ty.has_infer_types_or_consts() {
infcx.tcx.sess.delay_span_bug(
body.span,
&format!("could not resolve {:#?}", revealed_ty.kind()),
);
*revealed_ty = infcx.tcx.ty_error();
}
}

Expand Down