about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-04-18 06:44:48 +0200
committerGitHub <noreply@github.com>2023-04-18 06:44:48 +0200
commit5606653f01b6b2fbcbaa1b2ff37e04d4e66486f8 (patch)
tree72032c7a03dd418bdcf725ec92a8feb13f0ca55e
parentd97b39d3a0990d8d062f263e8e0898e0710a37e0 (diff)
parentc960a043e368c1e89974dbed244a3fdae222109a (diff)
downloadrust-5606653f01b6b2fbcbaa1b2ff37e04d4e66486f8.tar.gz
rust-5606653f01b6b2fbcbaa1b2ff37e04d4e66486f8.zip
Rollup merge of #110465 - WaffleLapkin:assure_everyone_that_has_type_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``
-rw-r--r--compiler/rustc_middle/src/ty/visit.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/compiler/rustc_middle/src/ty/visit.rs b/compiler/rustc_middle/src/ty/visit.rs
index 24a1f04c7e3..1b07f52afca 100644
--- a/compiler/rustc_middle/src/ty/visit.rs
+++ b/compiler/rustc_middle/src/ty/visit.rs
@@ -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");