Skip to content

support non-defining uses of opaques in borrowck #145244

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

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

lcnr
Copy link
Contributor

@lcnr lcnr commented Aug 11, 2025

Reimplements the first part of #139587, but limited to only the new solver.

  • rips out all member_constraints shit out of the type checker and region inference context
    • only used to infer final hidden type, enforced via type equality with final inferred type
  • all opaque type errors are lazy, want to ignore them if there are other region errors
  • 'erased handling
  • apply_defining_uses is the thing that actually mutates the constraints
  • opaque_types_added_since add comment
  • defining use recursive RPIT call ignore bivariant regions, needs test
  • check_opaque_type_parameter_valid needs to be renamed, it's not valid, it's defining?
  • ToArgRegionsFolder should be in a separate PR

r? @ghost

@rustbot rustbot added A-CI Area: Our Github Actions CI A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue. labels Aug 11, 2025
@lcnr lcnr force-pushed the handle-opaque-types-before-region-inference branch from 0d7a748 to e276bbf Compare August 11, 2025 11:15
for error in errors {
guar = Some(match error {
DeferredOpaqueTypeError::InvalidOpaqueTypeArgs(err) => err.report(self.infcx),
DeferredOpaqueTypeError::LifetimeMismatchOpaqueParam(err) => {
self.infcx.dcx().emit_err(err)
}
DeferredOpaqueTypeError::UnexpectedHiddenRegion {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

just moved from RegionErrorKind::UnexpectedHiddenRegion

@lcnr lcnr force-pushed the handle-opaque-types-before-region-inference branch 3 times, most recently from 14e5264 to 5536a31 Compare August 11, 2025 11:29
@rust-log-analyzer

This comment has been minimized.

@lcnr lcnr force-pushed the handle-opaque-types-before-region-inference branch from 5536a31 to 298629b Compare August 11, 2025 11:55
@rust-log-analyzer

This comment has been minimized.

@lcnr lcnr force-pushed the handle-opaque-types-before-region-inference branch from 298629b to 9af9a2c Compare August 11, 2025 12:17
@rust-log-analyzer

This comment has been minimized.

@lcnr lcnr changed the title Handle opaque types before region inference support revealing uses of opaques in borrowck Aug 11, 2025
// FIXME(-Znext-solver): enable this test
//@ revisions: current next
//@ ignore-compare-mode-next-solver (explicit revisions)
//@[next] compile-flags: -Znext-solver
Copy link
Contributor Author

Choose a reason for hiding this comment

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

idk why I've added this FIXME to these 3 tests, only one of them actually failed with the new solver before.

@BoxyUwU BoxyUwU self-assigned this Aug 11, 2025
constraints,
universal_region_relations,
location_map,
&mut opaque_types,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

&opaque_types :<

@lcnr lcnr changed the title support revealing uses of opaques in borrowck support non-defining uses of opaques in borrowck Aug 11, 2025
hidden_type.span,
DefiningScopeKind::MirBorrowck,
) {
if tcx.use_typing_mode_borrowck() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

needs comment: a non-defining use

hidden_type: OpaqueHiddenType<'tcx>,
}

fn collect_defining_uses<'tcx>(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
fn collect_defining_uses<'tcx>(
fn compute_hidden_types<'tcx>(

and fn apply_computed_hidden_types?


let mut defining_uses = vec![];
let mut errors = vec![];
for &(opaque_type_key, hidden_type) in opaque_types {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

move this loopy loop into collect_defining_uses sub-fn

rcx.scc_values.add_region(member, min_choice_scc);
}

struct CollectMemberConstraintsVisitor<'a, 'b, 'tcx> {
Copy link
Contributor Author

@lcnr lcnr Aug 11, 2025

Choose a reason for hiding this comment

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

equiv to existing register_member_constraints

let mut decls_modulo_regions: FxIndexMap<OpaqueTypeKey<'tcx>, (OpaqueTypeKey<'tcx>, Span)> =
FxIndexMap::default();
for &DefiningUse { opaque_type_key, ref arg_regions, hidden_type } in defining_uses {
let opaque_type_key = opaque_type_key.fold_captured_lifetime_args(infcx.tcx, |r| {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

store non_nll_opaque_type_key in DefiningUse

Comment on lines +248 to +253
let _span = debug_span!(
"map_defining_uses_to_definition_site",
?opaque_type_key,
?arg_regions,
?hidden_type
);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
let _span = debug_span!(
"map_defining_uses_to_definition_site",
?opaque_type_key,
?arg_regions,
?hidden_type
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-CI Area: Our Github Actions CI A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants