-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Avoid doing redundant work in receiver_is_valid
#127473
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1713,24 +1713,13 @@ fn receiver_is_valid<'tcx>( | |
let cause = | ||
ObligationCause::new(span, wfcx.body_def_id, traits::ObligationCauseCode::MethodReceiver); | ||
|
||
// Special case `receiver == self_ty`, which doesn't necessarily require the `Receiver` lang item. | ||
if let Ok(()) = wfcx.infcx.commit_if_ok(|_| { | ||
let ocx = ObligationCtxt::new(wfcx.infcx); | ||
ocx.eq(&cause, wfcx.param_env, self_ty, receiver_ty)?; | ||
if ocx.select_all_or_error().is_empty() { Ok(()) } else { Err(NoSolution) } | ||
}) { | ||
return true; | ||
} | ||
|
||
let mut autoderef = Autoderef::new(infcx, wfcx.param_env, wfcx.body_def_id, span, receiver_ty); | ||
|
||
// The `arbitrary_self_types` feature allows raw pointer receivers like `self: *const Self`. | ||
if arbitrary_self_types_enabled { | ||
autoderef = autoderef.include_raw_pointers(); | ||
} | ||
|
||
let receiver_trait_def_id = tcx.require_lang_item(LangItem::Receiver, Some(span)); | ||
|
||
// Keep dereferencing `receiver_ty` until we get to `self_ty`. | ||
while let Some((potential_self_ty, _)) = autoderef.next() { | ||
debug!( | ||
|
@@ -1752,6 +1741,8 @@ fn receiver_is_valid<'tcx>( | |
// Without `feature(arbitrary_self_types)`, we require that each step in the | ||
// deref chain implement `receiver`. | ||
if !arbitrary_self_types_enabled { | ||
let receiver_trait_def_id = tcx.require_lang_item(LangItem::Receiver, Some(span)); | ||
|
||
if !receiver_is_implemented( | ||
wfcx, | ||
receiver_trait_def_id, | ||
|
@@ -1761,14 +1752,6 @@ fn receiver_is_valid<'tcx>( | |
// We cannot proceed. | ||
break; | ||
} | ||
|
||
// Register the bound, in case it has any region side-effects. | ||
wfcx.register_bound( | ||
cause.clone(), | ||
wfcx.param_env, | ||
potential_self_ty, | ||
receiver_trait_def_id, | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This may have been perf negative, since we now have trait goals to process... If this is the problem, then we probably need to accept this for soundness reasons if we ever want to stabilize receiver lol There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so this means we only check There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As we were previously. Let me try adding it back and seeing what happens still... |
||
} | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.