@@ -40,6 +40,7 @@ use tracing::{debug, trace};
40
40
pub ( super ) struct EncodeContext < ' a , ' tcx > {
41
41
opaque : opaque:: Encoder ,
42
42
tcx : TyCtxt < ' tcx > ,
43
+ feat : & ' tcx rustc_feature:: Features ,
43
44
44
45
tables : TableBuilders < ' tcx > ,
45
46
@@ -1132,15 +1133,25 @@ impl EncodeContext<'a, 'tcx> {
1132
1133
1133
1134
fn encode_stability ( & mut self , def_id : DefId ) {
1134
1135
debug ! ( "EncodeContext::encode_stability({:?})" , def_id) ;
1135
- if let Some ( stab) = self . tcx . lookup_stability ( def_id) {
1136
- record ! ( self . tables. stability[ def_id] <- stab)
1136
+
1137
+ // The query lookup can take a measurable amount of time in crates with many items. Check if
1138
+ // the stability attributes are even enabled before using their queries.
1139
+ if self . feat . staged_api || self . tcx . sess . opts . debugging_opts . force_unstable_if_unmarked {
1140
+ if let Some ( stab) = self . tcx . lookup_stability ( def_id) {
1141
+ record ! ( self . tables. stability[ def_id] <- stab)
1142
+ }
1137
1143
}
1138
1144
}
1139
1145
1140
1146
fn encode_const_stability ( & mut self , def_id : DefId ) {
1141
1147
debug ! ( "EncodeContext::encode_const_stability({:?})" , def_id) ;
1142
- if let Some ( stab) = self . tcx . lookup_const_stability ( def_id) {
1143
- record ! ( self . tables. const_stability[ def_id] <- stab)
1148
+
1149
+ // The query lookup can take a measurable amount of time in crates with many items. Check if
1150
+ // the stability attributes are even enabled before using their queries.
1151
+ if self . feat . staged_api || self . tcx . sess . opts . debugging_opts . force_unstable_if_unmarked {
1152
+ if let Some ( stab) = self . tcx . lookup_const_stability ( def_id) {
1153
+ record ! ( self . tables. const_stability[ def_id] <- stab)
1154
+ }
1144
1155
}
1145
1156
}
1146
1157
@@ -1979,6 +1990,7 @@ fn encode_metadata_impl(tcx: TyCtxt<'_>) -> EncodedMetadata {
1979
1990
let mut ecx = EncodeContext {
1980
1991
opaque : encoder,
1981
1992
tcx,
1993
+ feat : tcx. features ( ) ,
1982
1994
tables : Default :: default ( ) ,
1983
1995
lazy_state : LazyState :: NoNode ,
1984
1996
type_shorthands : Default :: default ( ) ,
0 commit comments