Skip to content

Commit 8baecfa

Browse files
authored
Unrolled build for #158193
Rollup merge of #158193 - JonathanBrouwer:late-lint-experiment, r=jdonszelmann Remove `has_delayed_lints` optimization Keeping track of `has_delayed_lints` doesn't seem to have a perf effect anymore so let's not make the code more complicated than needed. These flags were previously used so we don't have to iterate over all hir owners, but iterating over all hir owners seems fast enough cc @jdonszelmann
2 parents 40f92b3 + f72b866 commit 8baecfa

24 files changed

Lines changed: 429 additions & 507 deletions

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
227227
kind,
228228
vis_span,
229229
span: self.lower_span(i.span),
230-
has_delayed_lints: !self.delayed_lints.is_empty(),
231230
eii: find_attr!(attrs, EiiImpls(..) | EiiDeclaration(..)),
232231
};
233232
self.arena.alloc(item)
@@ -700,7 +699,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
700699
kind,
701700
vis_span,
702701
span: this.lower_span(use_tree.span()),
703-
has_delayed_lints: !this.delayed_lints.is_empty(),
704702
eii: find_attr!(attrs, EiiImpls(..) | EiiDeclaration(..)),
705703
};
706704
hir::OwnerNode::Item(this.arena.alloc(item))
@@ -788,7 +786,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
788786
kind,
789787
vis_span: self.lower_span(i.vis.span),
790788
span: self.lower_span(i.span),
791-
has_delayed_lints: !self.delayed_lints.is_empty(),
792789
};
793790
self.arena.alloc(item)
794791
}
@@ -1087,7 +1084,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
10871084
kind,
10881085
span: self.lower_span(i.span),
10891086
defaultness,
1090-
has_delayed_lints: !self.delayed_lints.is_empty(),
10911087
};
10921088
self.arena.alloc(item)
10931089
}
@@ -1304,7 +1300,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
13041300
impl_kind,
13051301
kind,
13061302
span,
1307-
has_delayed_lints: !self.delayed_lints.is_empty(),
13081303
};
13091304
self.arena.alloc(item)
13101305
}

compiler/rustc_hir/src/hir.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3280,7 +3280,6 @@ pub struct TraitItem<'hir> {
32803280
pub kind: TraitItemKind<'hir>,
32813281
pub span: Span,
32823282
pub defaultness: Defaultness,
3283-
pub has_delayed_lints: bool,
32843283
}
32853284

32863285
macro_rules! expect_methods_self_kind {
@@ -3384,7 +3383,6 @@ pub struct ImplItem<'hir> {
33843383
pub kind: ImplItemKind<'hir>,
33853384
pub impl_kind: ImplItemImplKind,
33863385
pub span: Span,
3387-
pub has_delayed_lints: bool,
33883386
}
33893387

33903388
#[derive(Debug, Clone, Copy, StableHash)]
@@ -4560,7 +4558,6 @@ pub struct Item<'hir> {
45604558
pub kind: ItemKind<'hir>,
45614559
pub span: Span,
45624560
pub vis_span: Span,
4563-
pub has_delayed_lints: bool,
45644561
/// hint to speed up collection: true if the item is a static or function and has
45654562
/// either an `EiiImpls` or `EiiExternTarget` attribute
45664563
pub eii: bool,
@@ -4955,7 +4952,6 @@ pub struct ForeignItem<'hir> {
49554952
pub owner_id: OwnerId,
49564953
pub span: Span,
49574954
pub vis_span: Span,
4958-
pub has_delayed_lints: bool,
49594955
}
49604956

49614957
impl ForeignItem<'_> {
@@ -5467,7 +5463,7 @@ mod size_asserts {
54675463
static_assert_size!(Expr<'_>, 64);
54685464
static_assert_size!(ExprKind<'_>, 48);
54695465
static_assert_size!(FnDecl<'_>, 40);
5470-
static_assert_size!(ForeignItem<'_>, 96);
5466+
static_assert_size!(ForeignItem<'_>, 88);
54715467
static_assert_size!(ForeignItemKind<'_>, 56);
54725468
static_assert_size!(GenericArg<'_>, 16);
54735469
static_assert_size!(GenericBound<'_>, 64);

compiler/rustc_hir/src/intravisit.rs

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ pub fn walk_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v Param<'v>) ->
530530
}
531531

532532
pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) -> V::Result {
533-
let Item { owner_id: _, kind, span: _, vis_span: _, has_delayed_lints: _, eii: _ } = item;
533+
let Item { owner_id: _, kind, span: _, vis_span: _, eii: _ } = item;
534534
try_visit!(visitor.visit_id(item.hir_id()));
535535
match *kind {
536536
ItemKind::ExternCrate(orig_name, ident) => {
@@ -660,8 +660,7 @@ pub fn walk_foreign_item<'v, V: Visitor<'v>>(
660660
visitor: &mut V,
661661
foreign_item: &'v ForeignItem<'v>,
662662
) -> V::Result {
663-
let ForeignItem { ident, kind, owner_id: _, span: _, vis_span: _, has_delayed_lints: _ } =
664-
foreign_item;
663+
let ForeignItem { ident, kind, owner_id: _, span: _, vis_span: _ } = foreign_item;
665664
try_visit!(visitor.visit_id(foreign_item.hir_id()));
666665
try_visit!(visitor.visit_ident(*ident));
667666

@@ -1258,15 +1257,7 @@ pub fn walk_trait_item<'v, V: Visitor<'v>>(
12581257
visitor: &mut V,
12591258
trait_item: &'v TraitItem<'v>,
12601259
) -> V::Result {
1261-
let TraitItem {
1262-
ident,
1263-
generics,
1264-
ref defaultness,
1265-
ref kind,
1266-
span,
1267-
owner_id: _,
1268-
has_delayed_lints: _,
1269-
} = *trait_item;
1260+
let TraitItem { ident, generics, ref defaultness, ref kind, span, owner_id: _ } = *trait_item;
12701261
let hir_id = trait_item.hir_id();
12711262
try_visit!(visitor.visit_ident(ident));
12721263
try_visit!(visitor.visit_generics(&generics));
@@ -1308,15 +1299,8 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(
13081299
visitor: &mut V,
13091300
impl_item: &'v ImplItem<'v>,
13101301
) -> V::Result {
1311-
let ImplItem {
1312-
owner_id: _,
1313-
ident,
1314-
ref generics,
1315-
ref impl_kind,
1316-
ref kind,
1317-
span: _,
1318-
has_delayed_lints: _,
1319-
} = *impl_item;
1302+
let ImplItem { owner_id: _, ident, ref generics, ref impl_kind, ref kind, span: _ } =
1303+
*impl_item;
13201304

13211305
try_visit!(visitor.visit_ident(ident));
13221306
try_visit!(visitor.visit_generics(generics));

compiler/rustc_interface/src/passes.rs

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,7 @@ impl<'a, 'tcx> Diagnostic<'a, ()> for DiagCallback<'tcx> {
10651065
}
10661066

10671067
pub fn emit_delayed_lints(tcx: TyCtxt<'_>) {
1068-
for owner_id in tcx.hir_crate_items(()).delayed_lint_items() {
1068+
for owner_id in tcx.hir_crate_items(()).owners() {
10691069
if let Some(delayed_lints) = tcx.opt_ast_lowering_delayed_lints(owner_id) {
10701070
for lint in delayed_lints.steal() {
10711071
tcx.emit_node_span_lint(
@@ -1131,28 +1131,6 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
11311131
});
11321132

11331133
sess.time("emit_ast_lowering_delayed_lints", || {
1134-
// Sanity check in debug mode that all lints are really noticed and we really will emit
1135-
// them all in the loop right below.
1136-
//
1137-
// During ast lowering, when creating items, foreign items, trait items and impl items,
1138-
// we store in them whether they have any lints in their owner node that should be
1139-
// picked up by `hir_crate_items`. However, theoretically code can run between that
1140-
// boolean being inserted into the item and the owner node being created. We don't want
1141-
// any new lints to be emitted there (you have to really try to manage that but still),
1142-
// but this check is there to catch that.
1143-
#[cfg(debug_assertions)]
1144-
{
1145-
let hir_items = tcx.hir_crate_items(());
1146-
for owner_id in hir_items.owners() {
1147-
if let Some(delayed_lints) = tcx.opt_ast_lowering_delayed_lints(owner_id)
1148-
&& !delayed_lints.borrow().is_empty()
1149-
{
1150-
// Assert that delayed_lint_items also picked up this item to have lints.
1151-
assert!(hir_items.delayed_lint_items().any(|i| i == owner_id));
1152-
}
1153-
}
1154-
}
1155-
11561134
emit_delayed_lints(tcx);
11571135
});
11581136

compiler/rustc_middle/src/hir/map.rs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,7 +1287,6 @@ pub(super) fn hir_module_items(tcx: TyCtxt<'_>, module_id: LocalModDefId) -> Mod
12871287
body_owners: body_owners.into_boxed_slice(),
12881288
opaques: opaques.into_boxed_slice(),
12891289
nested_bodies: nested_bodies.into_boxed_slice(),
1290-
delayed_lint_items: Box::new([]),
12911290
eiis: eiis.into_boxed_slice(),
12921291
}
12931292
}
@@ -1310,19 +1309,10 @@ pub(crate) fn hir_crate_items(tcx: TyCtxt<'_>, _: ()) -> ModuleItems {
13101309
body_owners,
13111310
opaques,
13121311
nested_bodies,
1313-
mut delayed_lint_items,
13141312
eiis,
13151313
..
13161314
} = collector;
13171315

1318-
// The crate could have delayed lints too, but would not be picked up by the visitor.
1319-
// The `delayed_lint_items` list is smart - it only contains items which we know from
1320-
// earlier passes is guaranteed to contain lints. It's a little harder to determine that
1321-
// for sure here, so we simply always add the crate to the list. If it has no lints,
1322-
// we'll discover that later. The cost of this should be low, there's only one crate
1323-
// after all compared to the many items we have we wouldn't want to iterate over later.
1324-
delayed_lint_items.push(CRATE_OWNER_ID);
1325-
13261316
ModuleItems {
13271317
add_root: true,
13281318
submodules: submodules.into_boxed_slice(),
@@ -1333,7 +1323,6 @@ pub(crate) fn hir_crate_items(tcx: TyCtxt<'_>, _: ()) -> ModuleItems {
13331323
body_owners: body_owners.into_boxed_slice(),
13341324
opaques: opaques.into_boxed_slice(),
13351325
nested_bodies: nested_bodies.into_boxed_slice(),
1336-
delayed_lint_items: delayed_lint_items.into_boxed_slice(),
13371326
eiis: eiis.into_boxed_slice(),
13381327
}
13391328
}
@@ -1351,7 +1340,6 @@ struct ItemCollector<'tcx> {
13511340
body_owners: Vec<LocalDefId>,
13521341
opaques: Vec<LocalDefId>,
13531342
nested_bodies: Vec<LocalDefId>,
1354-
delayed_lint_items: Vec<OwnerId>,
13551343
eiis: Vec<LocalDefId>,
13561344
}
13571345

@@ -1368,7 +1356,6 @@ impl<'tcx> ItemCollector<'tcx> {
13681356
body_owners: Vec::default(),
13691357
opaques: Vec::default(),
13701358
nested_bodies: Vec::default(),
1371-
delayed_lint_items: Vec::default(),
13721359
eiis: Vec::default(),
13731360
}
13741361
}
@@ -1387,9 +1374,6 @@ impl<'hir> Visitor<'hir> for ItemCollector<'hir> {
13871374
}
13881375

13891376
self.items.push(item.item_id());
1390-
if self.crate_collector && item.has_delayed_lints {
1391-
self.delayed_lint_items.push(item.item_id().owner_id);
1392-
}
13931377

13941378
if let ItemKind::Static(..) | ItemKind::Fn { .. } | ItemKind::Macro(..) = &item.kind
13951379
&& item.eii
@@ -1411,9 +1395,6 @@ impl<'hir> Visitor<'hir> for ItemCollector<'hir> {
14111395

14121396
fn visit_foreign_item(&mut self, item: &'hir ForeignItem<'hir>) {
14131397
self.foreign_items.push(item.foreign_item_id());
1414-
if self.crate_collector && item.has_delayed_lints {
1415-
self.delayed_lint_items.push(item.foreign_item_id().owner_id);
1416-
}
14171398
intravisit::walk_foreign_item(self, item)
14181399
}
14191400

@@ -1447,9 +1428,6 @@ impl<'hir> Visitor<'hir> for ItemCollector<'hir> {
14471428
}
14481429

14491430
self.trait_items.push(item.trait_item_id());
1450-
if self.crate_collector && item.has_delayed_lints {
1451-
self.delayed_lint_items.push(item.trait_item_id().owner_id);
1452-
}
14531431

14541432
intravisit::walk_trait_item(self, item)
14551433
}
@@ -1460,9 +1438,6 @@ impl<'hir> Visitor<'hir> for ItemCollector<'hir> {
14601438
}
14611439

14621440
self.impl_items.push(item.impl_item_id());
1463-
if self.crate_collector && item.has_delayed_lints {
1464-
self.delayed_lint_items.push(item.impl_item_id().owner_id);
1465-
}
14661441

14671442
intravisit::walk_impl_item(self, item)
14681443
}

compiler/rustc_middle/src/hir/mod.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ pub struct ModuleItems {
3636
opaques: Box<[LocalDefId]>,
3737
body_owners: Box<[LocalDefId]>,
3838
nested_bodies: Box<[LocalDefId]>,
39-
// only filled with hir_crate_items, not with hir_module_items
40-
delayed_lint_items: Box<[OwnerId]>,
4139

4240
/// Statics and functions with an `EiiImpls` or `EiiExternTarget` attribute
4341
eiis: Box<[LocalDefId]>,
@@ -58,10 +56,6 @@ impl ModuleItems {
5856
self.trait_items.iter().copied()
5957
}
6058

61-
pub fn delayed_lint_items(&self) -> impl Iterator<Item = OwnerId> {
62-
self.delayed_lint_items.iter().copied()
63-
}
64-
6559
pub fn eiis(&self) -> impl Iterator<Item = LocalDefId> {
6660
self.eiis.iter().copied()
6761
}

tests/incremental/hashes/function_interfaces.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,9 @@ pub fn inline_never() {}
275275
pub fn no_mangle() {}
276276

277277
#[cfg(not(any(bpass1,bpass4)))]
278-
#[rustc_clean(cfg = "bpass2", except="hir_owner")] // dirty because of stashed UNSAFE_CODE lint
278+
#[rustc_clean(cfg = "bpass2")]
279279
#[rustc_clean(cfg = "bpass3")]
280-
#[rustc_clean(cfg = "bpass5", except="hir_owner")] // dirty because of stashed UNSAFE_CODE lint
280+
#[rustc_clean(cfg = "bpass5")]
281281
#[rustc_clean(cfg = "bpass6")]
282282
#[unsafe(no_mangle)]
283283
pub fn no_mangle() {}

tests/incremental/hashes/inherent_impls.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -645,9 +645,9 @@ impl Foo {
645645
// Add #[no_mangle] to Method --------------------------------------------------
646646
#[cfg(any(bpass1,bpass4))]
647647
impl Foo {
648-
//-------------------------------------------------------------------------------------------
649648
//--------------------------
650-
//-------------------------------------------------------------------------------------------
649+
//--------------------------
650+
//--------------------------
651651
//--------------------------
652652
//------------------
653653
pub fn add_no_mangle_to_method(&self) { }
@@ -659,9 +659,9 @@ impl Foo {
659659
#[rustc_clean(cfg="bpass5")]
660660
#[rustc_clean(cfg="bpass6")]
661661
impl Foo {
662-
#[rustc_clean(cfg="bpass2", except="hir_owner")] // dirty because of stashed UNSAFE_CODE lint
662+
#[rustc_clean(cfg="bpass2")]
663663
#[rustc_clean(cfg="bpass3")]
664-
#[rustc_clean(cfg="bpass5", except="hir_owner")] // dirty because of stashed UNSAFE_CODE lint
664+
#[rustc_clean(cfg="bpass5")]
665665
#[rustc_clean(cfg="bpass6")]
666666
#[unsafe(no_mangle)]
667667
pub fn add_no_mangle_to_method(&self) { }

tests/incremental/hashes/statics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ static STATIC_LINKAGE: u8 = 0;
6262
static STATIC_NO_MANGLE: u8 = 0;
6363

6464
#[cfg(not(any(bpass1,bpass4)))]
65-
#[rustc_clean(cfg="bpass2", except="hir_owner")] // dirty because of stashed UNSAFE_CODE lint
65+
#[rustc_clean(cfg="bpass2")]
6666
#[rustc_clean(cfg="bpass3")]
67-
#[rustc_clean(cfg="bpass5", except="hir_owner")] // dirty because of stashed UNSAFE_CODE lint
67+
#[rustc_clean(cfg="bpass5")]
6868
#[rustc_clean(cfg="bpass6")]
6969
#[unsafe(no_mangle)]
7070
static STATIC_NO_MANGLE: u8 = 0;

tests/incremental/hashes/trait_impls.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -565,9 +565,9 @@ trait AddNoMangleToMethod {
565565

566566
#[cfg(any(bpass1,bpass4))]
567567
impl AddNoMangleToMethod for Foo {
568-
//-------------------------------------------------------------------------------------------
569568
//--------------------------
570-
//-------------------------------------------------------------------------------------------
569+
//--------------------------
570+
//--------------------------
571571
//--------------------------
572572
//------------------
573573
fn add_no_mangle_to_method(&self) { }
@@ -579,9 +579,9 @@ impl AddNoMangleToMethod for Foo {
579579
#[rustc_clean(cfg="bpass5")]
580580
#[rustc_clean(cfg="bpass6")]
581581
impl AddNoMangleToMethod for Foo {
582-
#[rustc_clean(cfg="bpass2", except="hir_owner")] // dirty because of stashed UNSAFE_CODE lint
582+
#[rustc_clean(cfg="bpass2")]
583583
#[rustc_clean(cfg="bpass3")]
584-
#[rustc_clean(cfg="bpass5", except="hir_owner")] // dirty because of stashed UNSAFE_CODE lint
584+
#[rustc_clean(cfg="bpass5")]
585585
#[rustc_clean(cfg="bpass6")]
586586
#[unsafe(no_mangle)]
587587
fn add_no_mangle_to_method(&self) { }

0 commit comments

Comments
 (0)