Skip to content

Commit

Permalink
Rollup merge of #110465 - WaffleLapkin:assure_everyone_that_has_type_…
Browse files Browse the repository at this point in the history
…flags_is_fast, r=oli-obk

Assure everyone that `has_type_flags` is fast

`number_of_people_who_tripped_on_this += 1`

r? `@oli-obk`
  • Loading branch information
matthiaskrgr authored Apr 17, 2023
2 parents 4c8f1c1 + c960a04 commit ed84388
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions compiler/rustc_middle/src/ty/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ pub trait TypeVisitableExt<'tcx>: TypeVisitable<TyCtxt<'tcx>> {
}

fn has_type_flags(&self, flags: TypeFlags) -> bool {
// N.B. Even though this uses a visitor, the visitor does not actually
// recurse through the whole `TypeVisitable` implementor type.
//
// Instead it stops on the first "level", visiting types, regions,
// consts and predicates just fetches their type flags.
//
// Thus this is a lot faster than it might seem and should be
// optimized to a simple field access.
let res =
self.visit_with(&mut HasTypeFlagsVisitor { flags }).break_value() == Some(FoundFlags);
trace!(?self, ?flags, ?res, "has_type_flags");
Expand Down

0 comments on commit ed84388

Please sign in to comment.