Skip to content

Commit

Permalink
Try to improve compile times
Browse files Browse the repository at this point in the history
  • Loading branch information
saethlin committed Oct 14, 2024
1 parent a211812 commit 6f6737a
Show file tree
Hide file tree
Showing 13 changed files with 24 additions and 46 deletions.
2 changes: 2 additions & 0 deletions compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,8 @@ rustc_queries! {
/// and with extra transforms applied.
query build_codegen_mir(key: ty::Instance<'tcx>) -> &'tcx mir::Body<'tcx> {
desc { |tcx| "finalizing codegen MIR for `{}`", tcx.def_path_str_with_args(key.def_id(), key.args) }
cache_on_disk_if { true }
arena_cache
}

/// Checks for the nearest `#[coverage(off)]` or `#[coverage(on)]` on
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_mir_transform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ fn inner_optimized_mir(tcx: TyCtxt<'_>, did: LocalDefId) -> Body<'_> {
body
}

pub fn build_codegen_mir<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> &'tcx Body<'tcx> {
pub fn build_codegen_mir<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> Body<'tcx> {
let body = tcx.instance_mir(instance.def);
let mut body = instance.instantiate_mir_and_normalize_erasing_regions(
tcx,
Expand All @@ -705,19 +705,19 @@ pub fn build_codegen_mir<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> &
// failures. So we rely on the fact that validation only runs after passes? It's
// probably better to just delete that validation check.
&abort_unwinding_calls::AbortUnwindingCalls,
&o1(gvn::GVN::PostMono),
&gvn::GVN::PostMono,
// FIXME: Enabling this InstSimplify is required to fix the MIR from the
// unreachable_unchecked precondition check that UnreachablePropagation creates, but
// also enabling it breaks tests/codegen/issues/issue-122600-ptr-discriminant-update.rs
// LLVM appears to handle switches on i64 better than it handles icmp eq + br.
&o1(instsimplify::InstSimplify::PostMono),
&instsimplify::InstSimplify::PostMono,
&o1(simplify_branches::SimplifyConstCondition::PostMono),
&o1(simplify::SimplifyCfg::PostMono),
&add_call_guards::CriticalCallEdges,
],
Some(MirPhase::Runtime(RuntimePhase::Codegen)),
);
tcx.arena.alloc(body)
body
}

/// Fetch all the promoteds of an item and prepare their MIR bodies to be ready for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ pub fn foo5(a: &dyn Trait5<Type5, 32>) {
let b = &[Type5; 32];
a.quux(&b);
// CHECK-LABEL: define{{.*}}4foo5{{.*}}!{{<unknown kind #36>|kcfi_type}} !{{[0-9]+}}
// CHECK: call void %{{[0-9]}}(ptr align 1 {{%[a-z](\.0)*|%_[0-9]+]}}, ptr align 1 {{%[a-z](\.0)*|%[0-9]+}}){{.*}}[ "kcfi"(i32 [[TYPE5:[[:print:]]+]]) ]
// CHECK: call void %{{[0-9]}}(ptr align 1 {{%[a-z](\.0)*|%_[0-9]+]}}, ptr align 1 {{%[a-z](\.0)*|%_[0-9]+}}){{.*}}[ "kcfi"(i32 [[TYPE5:[[:print:]]+]]) ]
}

pub fn bar5() {
Expand All @@ -165,7 +165,7 @@ pub fn bar5() {
let b = &a as &dyn Trait5<Type5, 32>;
b.quux(&a);
// CHECK-LABEL: define{{.*}}4bar5{{.*}}!{{<unknown kind #36>|kcfi_type}} !{{[0-9]+}}
// CHECK: call void %{{[0-9]}}(ptr align 1 {{%[a-z](\.0)*|%_[0-9]+]}}, ptr align 1 {{%[a-z](\.0)*|%[0-9]+}}){{.*}}[ "kcfi"(i32 [[TYPE5:[[:print:]]+]]) ]
// CHECK: call void %{{[0-9]}}(ptr align 1 {{%[a-z](\.0)*|%_[0-9]+]}}, ptr align 1 {{%[a-z](\.0)*|%_[0-9]+}}){{.*}}[ "kcfi"(i32 [[TYPE5:[[:print:]]+]]) ]
}

// CHECK: !{{[0-9]+}} = !{i32 [[TYPE1]]}
Expand Down
8 changes: 0 additions & 8 deletions tests/ui/consts/const-eval/issue-50814.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@ note: erroneous constant encountered
LL | &Sum::<U8, U8>::MAX
| ^^^^^^^^^^^^^^^^^^

note: erroneous constant encountered
--> $DIR/issue-50814.rs:21:6
|
LL | &Sum::<U8, U8>::MAX
| ^^^^^^^^^^^^^^^^^^
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error[E0080]: evaluation of `<Sum<U8, U8> as Unsigned>::MAX` failed
--> $DIR/issue-50814.rs:15:21
|
Expand Down
6 changes: 0 additions & 6 deletions tests/ui/consts/mono-reachable-invalid-const.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ error[E0080]: evaluation of `Bar::<0>::ASSERT` failed
LL | ["oops"][b];
| ^^^^^^^^^^^ index out of bounds: the length is 1 but the index is 1

note: erroneous constant encountered
--> $DIR/mono-reachable-invalid-const.rs:9:9
|
LL | ["oops"][b];
| ^^^^^^^^^^^

note: erroneous constant encountered
--> $DIR/mono-reachable-invalid-const.rs:14:19
|
Expand Down
6 changes: 0 additions & 6 deletions tests/ui/inline-const/const-expr-generic-err.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ error[E0080]: evaluation of `bar::<0>::{constant#0}` failed
LL | const { N - 1 }
| ^^^^^ attempt to compute `0_usize - 1_usize`, which would overflow

note: erroneous constant encountered
--> $DIR/const-expr-generic-err.rs:9:13
|
LL | const { N - 1 }
| ^^^^^

note: erroneous constant encountered
--> $DIR/const-expr-generic-err.rs:9:5
|
Expand Down
3 changes: 2 additions & 1 deletion tests/ui/layout/layout-cycle.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//@ build-fail
//~^ ERROR: cycle detected when computing layout of
//~^ ERROR: a cycle occurred during layout computation
//~| ERROR: cycle detected when computing layout of

// Issue #111176 -- ensure that we do not emit ICE on layout cycles

Expand Down
10 changes: 2 additions & 8 deletions tests/ui/layout/layout-cycle.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,10 @@ error[E0391]: cycle detected when computing layout of `S<S<()>>`
|
= note: ...which requires computing layout of `<S<()> as Tr>::I`...
= note: ...which again requires computing layout of `S<S<()>>`, completing the cycle
note: cycle used when finalizing codegen MIR for `core::mem::size_of::<S<S<()>>>`
--> $SRC_DIR/core/src/mem/mod.rs:LL:COL
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information

note: the above error was encountered while instantiating `fn std::mem::size_of::<S<S<()>>>`
--> $DIR/layout-cycle.rs:25:5
|
LL | mem::size_of::<S<T>>()
| ^^^^^^^^^^^^^^^^^^^^^^
error: failed to get layout for S<S<()>>: a cycle occurred during layout computation

error: aborting due to 1 previous error
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0391`.
1 change: 1 addition & 0 deletions tests/ui/layout/post-mono-layout-cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ struct Wrapper<T: Trait> {
}

fn abi<T: Trait>(_: Option<Wrapper<T>>) {}
//~^ ERROR a cycle occurred during layout computation

fn indirect<T: Trait>() {
abi::<T>(None);
Expand Down
10 changes: 5 additions & 5 deletions tests/ui/layout/post-mono-layout-cycle.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ error[E0391]: cycle detected when computing layout of `Wrapper<()>`
= note: cycle used when computing layout of `core::option::Option<Wrapper<()>>`
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information

note: the above error was encountered while instantiating `fn indirect::<()>`
--> $DIR/post-mono-layout-cycle.rs:23:5
error: a cycle occurred during layout computation
--> $DIR/post-mono-layout-cycle.rs:16:1
|
LL | indirect::<()>();
| ^^^^^^^^^^^^^^^^
LL | fn abi<T: Trait>(_: Option<Wrapper<T>>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0391`.
8 changes: 4 additions & 4 deletions tests/ui/lint/large_assignments/copy_into_fn.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ LL | #![deny(large_assignments)]
| ^^^^^^^^^^^^^^^^^

error: moving 9999 bytes
--> $DIR/copy_into_fn.rs:17:20
--> $DIR/copy_into_fn.rs:17:15
|
LL | many_args(Data([0; 9999]), true, Data([0; 9999]));
| ^^^^^^^^^ value moved from here
| ^^^^^^^^^^^^^^^ value moved from here
|
= note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`

error: moving 9999 bytes
--> $DIR/copy_into_fn.rs:17:43
--> $DIR/copy_into_fn.rs:17:38
|
LL | many_args(Data([0; 9999]), true, Data([0; 9999]));
| ^^^^^^^^^ value moved from here
| ^^^^^^^^^^^^^^^ value moved from here
|
= note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/recursion_limit/zero-overflow.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//~ ERROR overflow evaluating the requirement `{closure@rt::lang_start<()>::{closure#0}}: Freeze`
//~ ERROR overflow evaluating the requirement `{closure@rt::lang_start<()>::{closure#0}}: Unsize<dyn Fn() -> i32 + Sync + RefUnwindSafe>`
//~| HELP consider increasing the recursion limit
//@ build-fail

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/recursion_limit/zero-overflow.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0275]: overflow evaluating the requirement `{closure@rt::lang_start<()>::{closure#0}}: Freeze`
error[E0275]: overflow evaluating the requirement `{closure@rt::lang_start<()>::{closure#0}}: Unsize<dyn Fn() -> i32 + Sync + RefUnwindSafe>`
|
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "2"]` attribute to your crate (`zero_overflow`)

Expand Down

0 comments on commit 6f6737a

Please sign in to comment.