Skip to content

Fast-path some relations via strict equality #104598

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
Closed
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion compiler/rustc_hir_analysis/src/check/dropck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ impl<'tcx> TypeRelation<'tcx> for SimpleEqRelation<'tcx> {
self.param_env
}

fn fast_equate_combine(&self) -> bool {
#[inline]
fn fast_equate(&self) -> bool {
true
}

Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_infer/src/infer/combine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,8 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
self.param_env
}

fn fast_equate_combine(&self) -> bool {
#[inline]
fn fast_equate(&self) -> bool {
false
}

Expand Down Expand Up @@ -806,7 +807,8 @@ impl<'tcx> TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> {
self.param_env
}

fn fast_equate_combine(&self) -> bool {
#[inline]
fn fast_equate(&self) -> bool {
false
}

Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_infer/src/infer/equate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ impl<'tcx> TypeRelation<'tcx> for Equate<'_, '_, 'tcx> {
self.fields.tcx()
}

fn fast_equate_combine(&self) -> bool {
#[inline]
fn fast_equate(&self) -> bool {
true
}

Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2945,7 +2945,8 @@ impl<'tcx> TypeRelation<'tcx> for SameTypeModuloInfer<'_, 'tcx> {
"SameTypeModuloInfer"
}

fn fast_equate_combine(&self) -> bool {
#[inline]
fn fast_equate(&self) -> bool {
true
}

Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_infer/src/infer/glb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ impl<'tcx> TypeRelation<'tcx> for Glb<'_, '_, 'tcx> {
self.fields.tcx()
}

fn fast_equate_combine(&self) -> bool {
#[inline]
fn fast_equate(&self) -> bool {
true
}

Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_infer/src/infer/lub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ impl<'tcx> TypeRelation<'tcx> for Lub<'_, '_, 'tcx> {
self.fields.tcx()
}

fn fast_equate_combine(&self) -> bool {
#[inline]
fn fast_equate(&self) -> bool {
true
}

Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_infer/src/infer/nll_relate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,8 @@ where
self.delegate.param_env()
}

fn fast_equate_combine(&self) -> bool {
#[inline]
fn fast_equate(&self) -> bool {
false
}

Expand Down Expand Up @@ -905,7 +906,8 @@ where
self.delegate.param_env()
}

fn fast_equate_combine(&self) -> bool {
#[inline]
fn fast_equate(&self) -> bool {
false
}

Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_infer/src/infer/outlives/test_type_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ impl<'tcx> TypeRelation<'tcx> for Match<'tcx> {
fn param_env(&self) -> ty::ParamEnv<'tcx> {
self.param_env
}
fn fast_equate_combine(&self) -> bool {
#[inline]
fn fast_equate(&self) -> bool {
false
}
fn a_is_expected(&self) -> bool {
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_infer/src/infer/sub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ impl<'tcx> TypeRelation<'tcx> for Sub<'_, '_, 'tcx> {
self.fields.param_env
}

fn fast_equate_combine(&self) -> bool {
#[inline]
fn fast_equate(&self) -> bool {
true
}

Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_middle/src/ty/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ impl<'tcx> TypeRelation<'tcx> for Match<'tcx> {
fn param_env(&self) -> ty::ParamEnv<'tcx> {
self.param_env
}
fn fast_equate_combine(&self) -> bool {
#[inline]
fn fast_equate(&self) -> bool {
false
}
fn a_is_expected(&self) -> bool {
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_middle/src/ty/relate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub trait TypeRelation<'tcx>: Sized {
fn tag(&self) -> &'static str;

/// Returns whether or not structural equality can be used to fast-path this relation
fn fast_equate_combine(&self) -> bool;
fn fast_equate(&self) -> bool;
Copy link

Choose a reason for hiding this comment

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

Annotate inline this declaration instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

#[inline] means nothing on trait methods without a body.


/// Returns `true` if the value `a` is the "expected" type in the
/// relation. Just affects error messages.
Expand Down Expand Up @@ -143,7 +143,7 @@ pub fn relate_substs<'tcx, R: TypeRelation<'tcx>>(
a_subst: SubstsRef<'tcx>,
b_subst: SubstsRef<'tcx>,
) -> RelateResult<'tcx, SubstsRef<'tcx>> {
if relation.fast_equate_combine() && a_subst == b_subst {
if relation.fast_equate() && a_subst == b_subst {
return Ok(a_subst);
}

Expand All @@ -159,7 +159,7 @@ pub fn relate_substs_with_variances<'tcx, R: TypeRelation<'tcx>>(
a_subst: SubstsRef<'tcx>,
b_subst: SubstsRef<'tcx>,
) -> RelateResult<'tcx, SubstsRef<'tcx>> {
if relation.fast_equate_combine() && a_subst == b_subst {
if relation.fast_equate() && a_subst == b_subst {
return Ok(a_subst);
}

Expand Down Expand Up @@ -365,7 +365,7 @@ impl<'tcx> Relate<'tcx> for GeneratorWitness<'tcx> {
a: GeneratorWitness<'tcx>,
b: GeneratorWitness<'tcx>,
) -> RelateResult<'tcx, GeneratorWitness<'tcx>> {
if relation.fast_equate_combine() && a == b {
if relation.fast_equate() && a == b {
return Ok(a);
}

Expand Down Expand Up @@ -670,7 +670,7 @@ impl<'tcx> Relate<'tcx> for &'tcx ty::List<ty::Binder<'tcx, ty::ExistentialPredi
a: Self,
b: Self,
) -> RelateResult<'tcx, Self> {
if relation.fast_equate_combine() && a == b {
if relation.fast_equate() && a == b {
return Ok(a);
}

Expand Down