Skip to content

Commit 6c38ef0

Browse files
committed
perf experiment: get rid of the per-feature bool fields
1 parent 338ec91 commit 6c38ef0

File tree

110 files changed

+293
-332
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+293
-332
lines changed

compiler/rustc_ast_lowering/src/asm.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
4949
| asm::InlineAsmArch::RiscV64
5050
| asm::InlineAsmArch::LoongArch64
5151
);
52-
if !is_stable && !self.tcx.features().asm_experimental_arch {
52+
if !is_stable && !self.tcx.features().asm_experimental_arch() {
5353
feature_err(
5454
&self.tcx.sess,
5555
sym::asm_experimental_arch,
@@ -65,7 +65,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
6565
{
6666
self.dcx().emit_err(AttSyntaxOnlyX86 { span: sp });
6767
}
68-
if asm.options.contains(InlineAsmOptions::MAY_UNWIND) && !self.tcx.features().asm_unwind {
68+
if asm.options.contains(InlineAsmOptions::MAY_UNWIND) && !self.tcx.features().asm_unwind() {
6969
feature_err(
7070
&self.tcx.sess,
7171
sym::asm_unwind,
@@ -237,7 +237,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
237237
}
238238
}
239239
InlineAsmOperand::Label { block } => {
240-
if !self.tcx.features().asm_goto {
240+
if !self.tcx.features().asm_goto() {
241241
feature_err(
242242
sess,
243243
sym::asm_goto,

compiler/rustc_ast_lowering/src/expr.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
575575
} else {
576576
// Either `body.is_none()` or `is_never_pattern` here.
577577
if !is_never_pattern {
578-
if self.tcx.features().never_patterns {
578+
if self.tcx.features().never_patterns() {
579579
// If the feature is off we already emitted the error after parsing.
580580
let suggestion = span.shrink_to_hi();
581581
self.dcx().emit_err(MatchArmWithNoBody { span, suggestion });
@@ -716,7 +716,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
716716
outer_hir_id: HirId,
717717
inner_hir_id: HirId,
718718
) {
719-
if self.tcx.features().async_fn_track_caller
719+
if self.tcx.features().async_fn_track_caller()
720720
&& let Some(attrs) = self.attrs.get(&outer_hir_id.local_id)
721721
&& attrs.into_iter().any(|attr| attr.has_name(sym::track_caller))
722722
{
@@ -1571,7 +1571,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
15711571
);
15721572
}
15731573
Some(hir::CoroutineKind::Coroutine(_)) => {
1574-
if !self.tcx.features().coroutines {
1574+
if !self.tcx.features().coroutines() {
15751575
rustc_session::parse::feature_err(
15761576
&self.tcx.sess,
15771577
sym::coroutines,
@@ -1583,7 +1583,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
15831583
false
15841584
}
15851585
None => {
1586-
if !self.tcx.features().coroutines {
1586+
if !self.tcx.features().coroutines() {
15871587
rustc_session::parse::feature_err(
15881588
&self.tcx.sess,
15891589
sym::coroutines,

compiler/rustc_ast_lowering/src/item.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1512,7 +1512,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
15121512
continue;
15131513
}
15141514
let is_param = *is_param.get_or_insert_with(compute_is_param);
1515-
if !is_param && !self.tcx.features().more_maybe_bounds {
1515+
if !is_param && !self.tcx.features().more_maybe_bounds() {
15161516
self.tcx
15171517
.sess
15181518
.create_feature_err(
@@ -1530,7 +1530,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
15301530
let host_param_parts = if let Const::Yes(span) = constness
15311531
// if this comes from implementing a `const` trait, we must force constness to be appended
15321532
// to the impl item, no matter whether effects is enabled.
1533-
&& (self.tcx.features().effects || force_append_constness)
1533+
&& (self.tcx.features().effects() || force_append_constness)
15341534
{
15351535
let span = self.lower_span(span);
15361536
let param_node_id = self.next_node_id();

compiler/rustc_ast_lowering/src/lib.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
193193
impl_trait_defs: Vec::new(),
194194
impl_trait_bounds: Vec::new(),
195195
allow_try_trait: [sym::try_trait_v2, sym::yeet_desugar_details].into(),
196-
allow_gen_future: if tcx.features().async_fn_track_caller {
196+
allow_gen_future: if tcx.features().async_fn_track_caller() {
197197
[sym::gen_future, sym::closure_track_caller].into()
198198
} else {
199199
[sym::gen_future].into()
@@ -1030,7 +1030,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
10301030
span: data.inputs_span,
10311031
})
10321032
};
1033-
if !self.tcx.features().return_type_notation
1033+
if !self.tcx.features().return_type_notation()
10341034
&& self.tcx.sess.is_nightly_build()
10351035
{
10361036
add_feature_diagnostics(
@@ -1155,7 +1155,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
11551155
ast::GenericArg::Lifetime(lt) => GenericArg::Lifetime(self.lower_lifetime(lt)),
11561156
ast::GenericArg::Type(ty) => {
11571157
match &ty.kind {
1158-
TyKind::Infer if self.tcx.features().generic_arg_infer => {
1158+
TyKind::Infer if self.tcx.features().generic_arg_infer() => {
11591159
return GenericArg::Infer(hir::InferArg {
11601160
hir_id: self.lower_node_id(ty.id),
11611161
span: self.lower_span(ty.span),
@@ -1546,7 +1546,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
15461546
}
15471547
hir::OpaqueTyOrigin::FnReturn { in_trait_or_impl, .. } => {
15481548
if in_trait_or_impl.is_some()
1549-
|| self.tcx.features().lifetime_capture_rules_2024
1549+
|| self.tcx.features().lifetime_capture_rules_2024()
15501550
|| span.at_least_rust_2024()
15511551
{
15521552
// return-position impl trait in trait was decided to capture all
@@ -2315,7 +2315,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
23152315
fn lower_array_length(&mut self, c: &AnonConst) -> hir::ArrayLen<'hir> {
23162316
match c.value.kind {
23172317
ExprKind::Underscore => {
2318-
if self.tcx.features().generic_arg_infer {
2318+
if self.tcx.features().generic_arg_infer() {
23192319
hir::ArrayLen::Infer(hir::InferArg {
23202320
hir_id: self.lower_node_id(c.id),
23212321
span: self.lower_span(c.value.span),
@@ -2497,7 +2497,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24972497
(BoundConstness::Never, BoundPolarity::Positive) => hir::TraitBoundModifier::None,
24982498
(_, BoundPolarity::Maybe(_)) => hir::TraitBoundModifier::Maybe,
24992499
(BoundConstness::Never, BoundPolarity::Negative(_)) => {
2500-
if self.tcx.features().negative_bounds {
2500+
if self.tcx.features().negative_bounds() {
25012501
hir::TraitBoundModifier::Negative
25022502
} else {
25032503
hir::TraitBoundModifier::None

compiler/rustc_ast_lowering/src/path.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
268268
span: data.inputs_span,
269269
})
270270
};
271-
if !self.tcx.features().return_type_notation
271+
if !self.tcx.features().return_type_notation()
272272
&& self.tcx.sess.is_nightly_build()
273273
{
274274
add_feature_diagnostics(
@@ -496,7 +496,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
496496
// // disallowed --^^^^^^^^^^ allowed --^^^^^^^^^^
497497
// ```
498498
FnRetTy::Ty(ty) if matches!(itctx, ImplTraitContext::OpaqueTy { .. }) => {
499-
if self.tcx.features().impl_trait_in_fn_trait_return {
499+
if self.tcx.features().impl_trait_in_fn_trait_return() {
500500
self.lower_ty(ty, itctx)
501501
} else {
502502
self.lower_ty(

compiler/rustc_ast_passes/src/ast_validation.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,8 @@ impl<'a> AstValidator<'a> {
332332
return;
333333
};
334334

335-
let make_impl_const_sugg = if self.features.const_trait_impl
335+
let const_trait_impl = self.features.const_trait_impl();
336+
let make_impl_const_sugg = if const_trait_impl
336337
&& let TraitOrTraitImpl::TraitImpl {
337338
constness: Const::No,
338339
polarity: ImplPolarity::Positive,
@@ -345,13 +346,12 @@ impl<'a> AstValidator<'a> {
345346
None
346347
};
347348

348-
let make_trait_const_sugg = if self.features.const_trait_impl
349-
&& let TraitOrTraitImpl::Trait { span, constness: None } = parent
350-
{
351-
Some(span.shrink_to_lo())
352-
} else {
353-
None
354-
};
349+
let make_trait_const_sugg =
350+
if const_trait_impl && let TraitOrTraitImpl::Trait { span, constness: None } = parent {
351+
Some(span.shrink_to_lo())
352+
} else {
353+
None
354+
};
355355

356356
let parent_constness = parent.constness();
357357
self.dcx().emit_err(errors::TraitFnConst {
@@ -1185,7 +1185,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
11851185
}
11861186
self.check_type_no_bounds(bounds, "this context");
11871187

1188-
if self.features.lazy_type_alias {
1188+
if self.features.lazy_type_alias() {
11891189
if let Err(err) = self.check_type_alias_where_clause_location(ty_alias) {
11901190
self.dcx().emit_err(err);
11911191
}
@@ -1326,7 +1326,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
13261326
GenericBound::Trait(trait_ref, modifiers) => {
13271327
match (ctxt, modifiers.constness, modifiers.polarity) {
13281328
(BoundKind::SuperTraits, BoundConstness::Never, BoundPolarity::Maybe(_))
1329-
if !self.features.more_maybe_bounds =>
1329+
if !self.features.more_maybe_bounds() =>
13301330
{
13311331
self.sess
13321332
.create_feature_err(
@@ -1339,7 +1339,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
13391339
.emit();
13401340
}
13411341
(BoundKind::TraitObject, BoundConstness::Never, BoundPolarity::Maybe(_))
1342-
if !self.features.more_maybe_bounds =>
1342+
if !self.features.more_maybe_bounds() =>
13431343
{
13441344
self.sess
13451345
.create_feature_err(

compiler/rustc_ast_passes/src/feature_gate.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ use crate::errors;
1515
/// The common case.
1616
macro_rules! gate {
1717
($visitor:expr, $feature:ident, $span:expr, $explain:expr) => {{
18-
if !$visitor.features.$feature && !$span.allows_unstable(sym::$feature) {
18+
if !$visitor.features.$feature() && !$span.allows_unstable(sym::$feature) {
1919
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
2020
feature_err(&$visitor.sess, sym::$feature, $span, $explain).emit();
2121
}
2222
}};
2323
($visitor:expr, $feature:ident, $span:expr, $explain:expr, $help:expr) => {{
24-
if !$visitor.features.$feature && !$span.allows_unstable(sym::$feature) {
24+
if !$visitor.features.$feature() && !$span.allows_unstable(sym::$feature) {
2525
// FIXME: make this translatable
2626
#[allow(rustc::diagnostic_outside_of_impl)]
2727
#[allow(rustc::untranslatable_diagnostic)]
@@ -43,7 +43,7 @@ macro_rules! gate_alt {
4343
/// The case involving a multispan.
4444
macro_rules! gate_multi {
4545
($visitor:expr, $feature:ident, $spans:expr, $explain:expr) => {{
46-
if !$visitor.features.$feature {
46+
if !$visitor.features.$feature() {
4747
let spans: Vec<_> =
4848
$spans.filter(|span| !span.allows_unstable(sym::$feature)).collect();
4949
if !spans.is_empty() {
@@ -56,7 +56,7 @@ macro_rules! gate_multi {
5656
/// The legacy case.
5757
macro_rules! gate_legacy {
5858
($visitor:expr, $feature:ident, $span:expr, $explain:expr) => {{
59-
if !$visitor.features.$feature && !$span.allows_unstable(sym::$feature) {
59+
if !$visitor.features.$feature() && !$span.allows_unstable(sym::$feature) {
6060
feature_warn(&$visitor.sess, sym::$feature, $span, $explain);
6161
}
6262
}};
@@ -150,7 +150,7 @@ impl<'a> PostExpansionVisitor<'a> {
150150

151151
// FIXME(non_lifetime_binders): Const bound params are pretty broken.
152152
// Let's keep users from using this feature accidentally.
153-
if self.features.non_lifetime_binders {
153+
if self.features.non_lifetime_binders() {
154154
let const_param_spans: Vec<_> = params
155155
.iter()
156156
.filter_map(|param| match param.kind {
@@ -210,7 +210,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
210210
}
211211

212212
// Emit errors for non-staged-api crates.
213-
if !self.features.staged_api {
213+
if !self.features.staged_api() {
214214
if attr.has_name(sym::unstable)
215215
|| attr.has_name(sym::stable)
216216
|| attr.has_name(sym::rustc_const_unstable)
@@ -470,7 +470,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
470470
// Limit `min_specialization` to only specializing functions.
471471
gate_alt!(
472472
&self,
473-
self.features.specialization || (is_fn && self.features.min_specialization),
473+
self.features.specialization() || (is_fn && self.features.min_specialization()),
474474
sym::specialization,
475475
i.span,
476476
"specialization is unstable"
@@ -548,7 +548,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
548548
gate_all!(global_registration, "global registration is experimental");
549549
gate_all!(return_type_notation, "return type notation is experimental");
550550

551-
if !visitor.features.never_patterns {
551+
if !visitor.features.never_patterns() {
552552
if let Some(spans) = spans.get(&sym::never_patterns) {
553553
for &span in spans {
554554
if span.allows_unstable(sym::never_patterns) {
@@ -572,7 +572,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
572572
}
573573
}
574574

575-
if !visitor.features.negative_bounds {
575+
if !visitor.features.negative_bounds() {
576576
for &span in spans.get(&sym::negative_bounds).iter().copied().flatten() {
577577
sess.dcx().emit_err(errors::NegativeBoundUnsupported { span });
578578
}

compiler/rustc_attr/src/builtin.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ pub fn eval_condition(
622622
&((
623623
if *b { kw::True } else { kw::False },
624624
sym::cfg_boolean_literals,
625-
|features: &Features| features.cfg_boolean_literals,
625+
|features: &Features| features.cfg_boolean_literals(),
626626
)),
627627
cfg.span(),
628628
sess,
@@ -711,7 +711,7 @@ pub fn eval_condition(
711711
}
712712
sym::target => {
713713
if let Some(features) = features
714-
&& !features.cfg_target_compact
714+
&& !features.cfg_target_compact()
715715
{
716716
feature_err(
717717
sess,
@@ -825,7 +825,7 @@ pub fn find_deprecation(
825825
attrs: &[Attribute],
826826
) -> Option<(Deprecation, Span)> {
827827
let mut depr: Option<(Deprecation, Span)> = None;
828-
let is_rustc = features.staged_api;
828+
let is_rustc = features.staged_api();
829829

830830
'outer: for attr in attrs {
831831
if !attr.has_name(sym::deprecated) {
@@ -885,7 +885,7 @@ pub fn find_deprecation(
885885
}
886886
}
887887
sym::suggestion => {
888-
if !features.deprecated_suggestion {
888+
if !features.deprecated_suggestion() {
889889
sess.dcx().emit_err(
890890
session_diagnostics::DeprecatedItemSuggestion {
891891
span: mi.span,
@@ -903,7 +903,7 @@ pub fn find_deprecation(
903903
sess.dcx().emit_err(session_diagnostics::UnknownMetaItem {
904904
span: meta.span(),
905905
item: pprust::path_to_string(&mi.path),
906-
expected: if features.deprecated_suggestion {
906+
expected: if features.deprecated_suggestion() {
907907
&["since", "note", "suggestion"]
908908
} else {
909909
&["since", "note"]

compiler/rustc_borrowck/src/type_check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
10351035

10361036
fn unsized_feature_enabled(&self) -> bool {
10371037
let features = self.tcx().features();
1038-
features.unsized_locals || features.unsized_fn_params
1038+
features.unsized_locals() || features.unsized_fn_params()
10391039
}
10401040

10411041
/// Equate the inferred type and the annotated type for user type annotations

compiler/rustc_builtin_macros/src/assert.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pub(crate) fn expand_assert<'cx>(
6969
// If `generic_assert` is enabled, generates rich captured outputs
7070
//
7171
// FIXME(c410-f3r) See https://github.com/rust-lang/rust/issues/96949
72-
else if cx.ecfg.features.generic_assert {
72+
else if cx.ecfg.features.generic_assert() {
7373
context::Context::new(cx, call_site_span).build(cond_expr, panic_path())
7474
}
7575
// If `generic_assert` is not enabled, only outputs a literal "assertion failed: ..."

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
136136
let inner = attr.meta_item_list();
137137
match inner.as_deref() {
138138
Some([item]) if item.has_name(sym::linker) => {
139-
if !tcx.features().used_with_arg {
139+
if !tcx.features().used_with_arg() {
140140
feature_err(
141141
&tcx.sess,
142142
sym::used_with_arg,
@@ -148,7 +148,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
148148
codegen_fn_attrs.flags |= CodegenFnAttrFlags::USED_LINKER;
149149
}
150150
Some([item]) if item.has_name(sym::compiler) => {
151-
if !tcx.features().used_with_arg {
151+
if !tcx.features().used_with_arg() {
152152
feature_err(
153153
&tcx.sess,
154154
sym::used_with_arg,
@@ -212,7 +212,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
212212
.emit();
213213
}
214214
if is_closure
215-
&& !tcx.features().closure_track_caller
215+
&& !tcx.features().closure_track_caller()
216216
&& !attr.span.allows_unstable(sym::closure_track_caller)
217217
{
218218
feature_err(
@@ -267,7 +267,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
267267
//
268268
// This exception needs to be kept in sync with allowing
269269
// `#[target_feature]` on `main` and `start`.
270-
} else if !tcx.features().target_feature_11 {
270+
} else if !tcx.features().target_feature_11() {
271271
feature_err(
272272
&tcx.sess,
273273
sym::target_feature_11,
@@ -583,7 +583,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
583583
// its parent function, which effectively inherits the features anyway. Boxing this closure
584584
// would result in this closure being compiled without the inherited target features, but this
585585
// is probably a poor usage of `#[inline(always)]` and easily avoided by not using the attribute.
586-
if tcx.features().target_feature_11
586+
if tcx.features().target_feature_11()
587587
&& tcx.is_closure_like(did.to_def_id())
588588
&& codegen_fn_attrs.inline != InlineAttr::Always
589589
{

0 commit comments

Comments
 (0)