Skip to content

Commit d85d01c

Browse files
This time devirtualized
1 parent 4b6dfc2 commit d85d01c

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

compiler/rustc_index/src/idx.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,15 @@ impl Idx for u32 {
4343
self as usize
4444
}
4545
}
46+
47+
impl Idx for u8 {
48+
#[inline]
49+
fn new(idx: usize) -> Self {
50+
assert!(idx <= u8::MAX as usize);
51+
idx as u8
52+
}
53+
#[inline]
54+
fn index(self) -> usize {
55+
self as usize
56+
}
57+
}

compiler/rustc_lint/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#![feature(if_let_guard)]
3131
#![feature(iter_order_by)]
3232
#![feature(let_chains)]
33+
#![feature(macro_metavar_expr)]
3334
#![feature(rustc_attrs)]
3435
#![feature(rustdoc_internals)]
3536
#![feature(trait_upcasting)]
@@ -146,7 +147,7 @@ pub fn provide(providers: &mut Providers) {
146147
}
147148

148149
fn lint_mod(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) {
149-
late_lint_mod(tcx, module_def_id, BuiltinCombinedModuleLateLintPass::new());
150+
late_lint_mod(tcx, module_def_id, BuiltinCombinedModuleLateLintPass::new(tcx));
150151
}
151152

152153
early_lint_methods!(

compiler/rustc_lint/src/passes.rs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ impl LateLintPass<'_> for HardwiredLints {}
7575
#[macro_export]
7676
macro_rules! expand_combined_late_lint_pass_method {
7777
([$($pass:ident),*], $self: ident, $name: ident, $params:tt) => ({
78-
$($self.$pass.$name $params;)*
78+
$(
79+
if $self.enabled_passes.contains(EnabledPasses::$pass as u8) {
80+
$self.$pass.$name $params;
81+
}
82+
)*
7983
})
8084
}
8185

@@ -96,15 +100,37 @@ macro_rules! expand_combined_late_lint_pass_methods {
96100
#[macro_export]
97101
macro_rules! declare_combined_late_lint_pass {
98102
([$v:vis $name:ident, [$($pass:ident: $constructor:expr,)*]], $methods:tt) => (
103+
#[repr(u8)]
104+
enum EnabledPasses {
105+
$($pass,)*
106+
}
107+
99108
#[allow(non_snake_case)]
100109
$v struct $name {
110+
enabled_passes: rustc_index::bit_set::BitSet<u8>,
101111
$($pass: $pass,)*
102112
}
103113

104114
impl $name {
105-
$v fn new() -> Self {
115+
#[allow(non_snake_case)]
116+
$v fn new<'tcx>(tcx: TyCtxt<'tcx>) -> Self {
117+
let mut enabled_passes = rustc_index::bit_set::BitSet::new_filled(${count($pass)});
118+
let lints_that_dont_need_to_run = tcx.lints_that_dont_need_to_run(());
119+
$(
120+
let $pass = $constructor;
121+
{
122+
let lints = $pass.get_lints();
123+
// If the pass doesn't have a single needed lint, omit it.
124+
if !lints.is_empty()
125+
&& lints.iter().all(|lint| lints_that_dont_need_to_run.contains(&LintId::of(lint)))
126+
{
127+
enabled_passes.remove(EnabledPasses::$pass as u8);
128+
}
129+
}
130+
)*
106131
Self {
107-
$($pass: $constructor,)*
132+
enabled_passes,
133+
$($pass,)*
108134
}
109135
}
110136

0 commit comments

Comments
 (0)