Skip to content

Commit 1103d2e

Browse files
committed
Auto merge of #94205 - Mark-Simulacrum:revert-93800, r=oli-obk
Revert #93800, fixing CI time regression This reverts commit a240ccd (merge commit of #93800), reversing changes made to 393fdc1. This PR was likely responsible for a relatively large regression in dist-x86_64-msvc-alt builder times, from approximately 1.7 to 2.8 hours, bringing that builder into the pool of the slowest builders we currently have. This seems to be limited to the alt builder due to needing parallel-compiler enabled, likely leading to slow LLVM compilation for some reason. See some investigation in [this Zulip stream](https://rust-lang.zulipchat.com/#narrow/stream/242791-t-infra/topic/msvc.28.3F.29.20builders.20running.20much.20slower). cc `@lcnr` `@oli-obk` `@b-naber` (per original PRs review/author) We can re-apply this PR once the regression is fixed, but it is sufficiently large that I don't think keeping this on master is viable in the meantime unless there's a very strong case to be made for it. Alternatively, we can disable that builder (it's not critical since it's an alt build), but that obviously carries its own costs.
2 parents a924ef7 + 9f76214 commit 1103d2e

18 files changed

+64
-38
lines changed

compiler/rustc_middle/src/mir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2533,7 +2533,7 @@ pub enum ConstantKind<'tcx> {
25332533

25342534
impl<'tcx> Constant<'tcx> {
25352535
pub fn check_static_ptr(&self, tcx: TyCtxt<'_>) -> Option<DefId> {
2536-
match self.literal.try_to_scalar() {
2536+
match self.literal.const_for_ty()?.val().try_to_scalar() {
25372537
Some(Scalar::Ptr(ptr, _size)) => match tcx.global_alloc(ptr.provenance) {
25382538
GlobalAlloc::Static(def_id) => {
25392539
assert!(!tcx.is_thread_local_static(def_id));

compiler/rustc_middle/src/mir/pretty.rs

+6-18
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ use rustc_middle::mir::interpret::{
1717
use rustc_middle::mir::visit::Visitor;
1818
use rustc_middle::mir::MirSource;
1919
use rustc_middle::mir::*;
20-
use rustc_middle::ty::{self, TyCtxt};
20+
use rustc_middle::ty::{self, TyCtxt, TypeFoldable, TypeVisitor};
2121
use rustc_target::abi::Size;
22+
use std::ops::ControlFlow;
2223

2324
const INDENT: &str = " ";
2425
/// Alignment for lining up comments following MIR statements
@@ -663,7 +664,6 @@ pub fn write_allocations<'tcx>(
663664
fn alloc_ids_from_alloc(alloc: &Allocation) -> impl DoubleEndedIterator<Item = AllocId> + '_ {
664665
alloc.relocations().values().map(|id| *id)
665666
}
666-
667667
fn alloc_ids_from_const(val: ConstValue<'_>) -> impl Iterator<Item = AllocId> + '_ {
668668
match val {
669669
ConstValue::Scalar(interpret::Scalar::Ptr(ptr, _size)) => {
@@ -677,29 +677,17 @@ pub fn write_allocations<'tcx>(
677677
}
678678
}
679679
}
680-
681680
struct CollectAllocIds(BTreeSet<AllocId>);
682-
683-
impl<'tcx> Visitor<'tcx> for CollectAllocIds {
684-
fn visit_const(&mut self, c: ty::Const<'tcx>, _loc: Location) {
681+
impl<'tcx> TypeVisitor<'tcx> for CollectAllocIds {
682+
fn visit_const(&mut self, c: ty::Const<'tcx>) -> ControlFlow<Self::BreakTy> {
685683
if let ty::ConstKind::Value(val) = c.val() {
686684
self.0.extend(alloc_ids_from_const(val));
687685
}
688-
}
689-
690-
fn visit_constant(&mut self, c: &Constant<'tcx>, loc: Location) {
691-
match c.literal {
692-
ConstantKind::Ty(c) => self.visit_const(c, loc),
693-
ConstantKind::Val(val, _) => {
694-
self.0.extend(alloc_ids_from_const(val));
695-
}
696-
}
686+
c.super_visit_with(self)
697687
}
698688
}
699-
700689
let mut visitor = CollectAllocIds(Default::default());
701-
visitor.visit_body(body);
702-
690+
body.visit_with(&mut visitor);
703691
// `seen` contains all seen allocations, including the ones we have *not* printed yet.
704692
// The protocol is to first `insert` into `seen`, and only if that returns `true`
705693
// then push to `todo`.

compiler/rustc_middle/src/thir.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use rustc_index::newtype_index;
1717
use rustc_index::vec::IndexVec;
1818
use rustc_middle::infer::canonical::Canonical;
1919
use rustc_middle::middle::region;
20-
use rustc_middle::mir::interpret::AllocId;
2120
use rustc_middle::mir::{
2221
BinOp, BorrowKind, FakeReadCause, Field, Mutability, UnOp, UserTypeProjection,
2322
};
@@ -420,8 +419,7 @@ pub enum ExprKind<'tcx> {
420419
/// This is only distinguished from `Literal` so that we can register some
421420
/// info for diagnostics.
422421
StaticRef {
423-
alloc_id: AllocId,
424-
ty: Ty<'tcx>,
422+
literal: Const<'tcx>,
425423
def_id: DefId,
426424
},
427425
/// Inline assembly, i.e. `asm!()`.

compiler/rustc_middle/src/thir/visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ pub fn walk_expr<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, expr: &Exp
123123
}
124124
Closure { closure_id: _, substs: _, upvars: _, movability: _, fake_reads: _ } => {}
125125
Literal { literal, user_ty: _, const_id: _ } => visitor.visit_const(literal),
126-
StaticRef { .. } => {}
126+
StaticRef { literal, def_id: _ } => visitor.visit_const(literal),
127127
InlineAsm { ref operands, template: _, options: _, line_spans: _ } => {
128128
for op in &**operands {
129129
use InlineAsmOperand::*;

compiler/rustc_mir_build/src/build/expr/as_constant.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! See docs in build/expr/mod.rs
22
33
use crate::build::Builder;
4-
use rustc_middle::mir::interpret::{ConstValue, Scalar};
54
use rustc_middle::mir::*;
65
use rustc_middle::thir::*;
76
use rustc_middle::ty::CanonicalUserTypeAnnotation;
@@ -27,12 +26,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
2726
assert_eq!(literal.ty(), ty);
2827
Constant { span, user_ty, literal: literal.into() }
2928
}
30-
ExprKind::StaticRef { alloc_id, ty, .. } => {
31-
let const_val =
32-
ConstValue::Scalar(Scalar::from_pointer(alloc_id.into(), &this.tcx));
33-
let literal = ConstantKind::Val(const_val, ty);
34-
35-
Constant { span, user_ty: None, literal }
29+
ExprKind::StaticRef { literal, .. } => {
30+
Constant { span, user_ty: None, literal: literal.into() }
3631
}
3732
ExprKind::ConstBlock { value } => {
3833
Constant { span: span, user_ty: None, literal: value.into() }

compiler/rustc_mir_build/src/thir/cx/expr.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use rustc_middle::hir::place::Place as HirPlace;
88
use rustc_middle::hir::place::PlaceBase as HirPlaceBase;
99
use rustc_middle::hir::place::ProjectionKind as HirProjectionKind;
1010
use rustc_middle::middle::region;
11+
use rustc_middle::mir::interpret::Scalar;
1112
use rustc_middle::mir::{BinOp, BorrowKind, Field, UnOp};
1213
use rustc_middle::thir::*;
1314
use rustc_middle::ty::adjustment::{
@@ -940,8 +941,15 @@ impl<'tcx> Cx<'tcx> {
940941
let kind = if self.tcx.is_thread_local_static(id) {
941942
ExprKind::ThreadLocalRef(id)
942943
} else {
943-
let alloc_id = self.tcx.create_static_alloc(id);
944-
ExprKind::StaticRef { alloc_id, ty, def_id: id }
944+
let ptr = self.tcx.create_static_alloc(id);
945+
ExprKind::StaticRef {
946+
literal: ty::Const::from_scalar(
947+
self.tcx,
948+
Scalar::from_pointer(ptr.into(), &self.tcx),
949+
ty,
950+
),
951+
def_id: id,
952+
}
945953
};
946954
ExprKind::Deref {
947955
arg: self.thir.exprs.push(Expr { ty, temp_lifetime, span: expr.span, kind }),

src/test/mir-opt/const_allocation.main.ConstProp.after.32bit.mir

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ fn main() -> () {
99
StorageLive(_1); // scope 0 at $DIR/const_allocation.rs:8:5: 8:8
1010
StorageLive(_2); // scope 0 at $DIR/const_allocation.rs:8:5: 8:8
1111
_2 = const {alloc1: &&[(Option<i32>, &[&str])]}; // scope 0 at $DIR/const_allocation.rs:8:5: 8:8
12+
// ty::Const
13+
// + ty: &&[(std::option::Option<i32>, &[&str])]
14+
// + val: Value(Scalar(alloc1))
1215
// mir::Constant
1316
// + span: $DIR/const_allocation.rs:8:5: 8:8
14-
// + literal: Const { ty: &&[(Option<i32>, &[&str])], val: Value(Scalar(alloc1)) }
17+
// + literal: Const { ty: &&[(std::option::Option<i32>, &[&str])], val: Value(Scalar(alloc1)) }
1518
_1 = (*_2); // scope 0 at $DIR/const_allocation.rs:8:5: 8:8
1619
StorageDead(_2); // scope 0 at $DIR/const_allocation.rs:8:8: 8:9
1720
StorageDead(_1); // scope 0 at $DIR/const_allocation.rs:8:8: 8:9

src/test/mir-opt/const_allocation.main.ConstProp.after.64bit.mir

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ fn main() -> () {
99
StorageLive(_1); // scope 0 at $DIR/const_allocation.rs:8:5: 8:8
1010
StorageLive(_2); // scope 0 at $DIR/const_allocation.rs:8:5: 8:8
1111
_2 = const {alloc1: &&[(Option<i32>, &[&str])]}; // scope 0 at $DIR/const_allocation.rs:8:5: 8:8
12+
// ty::Const
13+
// + ty: &&[(std::option::Option<i32>, &[&str])]
14+
// + val: Value(Scalar(alloc1))
1215
// mir::Constant
1316
// + span: $DIR/const_allocation.rs:8:5: 8:8
14-
// + literal: Const { ty: &&[(Option<i32>, &[&str])], val: Value(Scalar(alloc1)) }
17+
// + literal: Const { ty: &&[(std::option::Option<i32>, &[&str])], val: Value(Scalar(alloc1)) }
1518
_1 = (*_2); // scope 0 at $DIR/const_allocation.rs:8:5: 8:8
1619
StorageDead(_2); // scope 0 at $DIR/const_allocation.rs:8:8: 8:9
1720
StorageDead(_1); // scope 0 at $DIR/const_allocation.rs:8:8: 8:9

src/test/mir-opt/const_allocation2.main.ConstProp.after.32bit.mir

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ fn main() -> () {
99
StorageLive(_1); // scope 0 at $DIR/const_allocation2.rs:5:5: 5:8
1010
StorageLive(_2); // scope 0 at $DIR/const_allocation2.rs:5:5: 5:8
1111
_2 = const {alloc1: &&[(Option<i32>, &[&u8])]}; // scope 0 at $DIR/const_allocation2.rs:5:5: 5:8
12+
// ty::Const
13+
// + ty: &&[(std::option::Option<i32>, &[&u8])]
14+
// + val: Value(Scalar(alloc1))
1215
// mir::Constant
1316
// + span: $DIR/const_allocation2.rs:5:5: 5:8
14-
// + literal: Const { ty: &&[(Option<i32>, &[&u8])], val: Value(Scalar(alloc1)) }
17+
// + literal: Const { ty: &&[(std::option::Option<i32>, &[&u8])], val: Value(Scalar(alloc1)) }
1518
_1 = (*_2); // scope 0 at $DIR/const_allocation2.rs:5:5: 5:8
1619
StorageDead(_2); // scope 0 at $DIR/const_allocation2.rs:5:8: 5:9
1720
StorageDead(_1); // scope 0 at $DIR/const_allocation2.rs:5:8: 5:9

src/test/mir-opt/const_allocation2.main.ConstProp.after.64bit.mir

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ fn main() -> () {
99
StorageLive(_1); // scope 0 at $DIR/const_allocation2.rs:5:5: 5:8
1010
StorageLive(_2); // scope 0 at $DIR/const_allocation2.rs:5:5: 5:8
1111
_2 = const {alloc1: &&[(Option<i32>, &[&u8])]}; // scope 0 at $DIR/const_allocation2.rs:5:5: 5:8
12+
// ty::Const
13+
// + ty: &&[(std::option::Option<i32>, &[&u8])]
14+
// + val: Value(Scalar(alloc1))
1215
// mir::Constant
1316
// + span: $DIR/const_allocation2.rs:5:5: 5:8
14-
// + literal: Const { ty: &&[(Option<i32>, &[&u8])], val: Value(Scalar(alloc1)) }
17+
// + literal: Const { ty: &&[(std::option::Option<i32>, &[&u8])], val: Value(Scalar(alloc1)) }
1518
_1 = (*_2); // scope 0 at $DIR/const_allocation2.rs:5:5: 5:8
1619
StorageDead(_2); // scope 0 at $DIR/const_allocation2.rs:5:8: 5:9
1720
StorageDead(_1); // scope 0 at $DIR/const_allocation2.rs:5:8: 5:9

src/test/mir-opt/const_allocation3.main.ConstProp.after.32bit.mir

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ fn main() -> () {
99
StorageLive(_1); // scope 0 at $DIR/const_allocation3.rs:5:5: 5:8
1010
StorageLive(_2); // scope 0 at $DIR/const_allocation3.rs:5:5: 5:8
1111
_2 = const {alloc1: &&Packed}; // scope 0 at $DIR/const_allocation3.rs:5:5: 5:8
12+
// ty::Const
13+
// + ty: &&Packed
14+
// + val: Value(Scalar(alloc1))
1215
// mir::Constant
1316
// + span: $DIR/const_allocation3.rs:5:5: 5:8
1417
// + literal: Const { ty: &&Packed, val: Value(Scalar(alloc1)) }

src/test/mir-opt/const_allocation3.main.ConstProp.after.64bit.mir

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ fn main() -> () {
99
StorageLive(_1); // scope 0 at $DIR/const_allocation3.rs:5:5: 5:8
1010
StorageLive(_2); // scope 0 at $DIR/const_allocation3.rs:5:5: 5:8
1111
_2 = const {alloc1: &&Packed}; // scope 0 at $DIR/const_allocation3.rs:5:5: 5:8
12+
// ty::Const
13+
// + ty: &&Packed
14+
// + val: Value(Scalar(alloc1))
1215
// mir::Constant
1316
// + span: $DIR/const_allocation3.rs:5:5: 5:8
1417
// + literal: Const { ty: &&Packed, val: Value(Scalar(alloc1)) }

src/test/mir-opt/const_promotion_extern_static.BAR-promoted[0].SimplifyCfg-elaborate-drops.after.mir

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ promoted[0] in BAR: &[&i32; 1] = {
88

99
bb0: {
1010
_3 = const {alloc1: &i32}; // scope 0 at $DIR/const-promotion-extern-static.rs:9:33: 9:34
11+
// ty::Const
12+
// + ty: &i32
13+
// + val: Value(Scalar(alloc1))
1114
// mir::Constant
1215
// + span: $DIR/const-promotion-extern-static.rs:9:33: 9:34
1316
// + literal: Const { ty: &i32, val: Value(Scalar(alloc1)) }

src/test/mir-opt/const_promotion_extern_static.BAR.PromoteTemps.diff

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
- StorageLive(_5); // scope 0 at $DIR/const-promotion-extern-static.rs:9:33: 9:34
1919
- _5 = const {alloc1: &i32}; // scope 0 at $DIR/const-promotion-extern-static.rs:9:33: 9:34
2020
+ _6 = const BAR::promoted[0]; // scope 0 at $DIR/const-promotion-extern-static.rs:9:31: 9:44
21-
+ // ty::Const
21+
// ty::Const
22+
- // + ty: &i32
23+
- // + val: Value(Scalar(alloc1))
2224
+ // + ty: &[&i32; 1]
2325
+ // + val: Unevaluated(BAR, [], Some(promoted[0]))
2426
// mir::Constant

src/test/mir-opt/const_promotion_extern_static.FOO-promoted[0].SimplifyCfg-elaborate-drops.after.mir

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ promoted[0] in FOO: &[&i32; 1] = {
88

99
bb0: {
1010
_3 = const {alloc3: *const i32}; // scope 0 at $DIR/const-promotion-extern-static.rs:13:42: 13:43
11+
// ty::Const
12+
// + ty: *const i32
13+
// + val: Value(Scalar(alloc3))
1114
// mir::Constant
1215
// + span: $DIR/const-promotion-extern-static.rs:13:42: 13:43
1316
// + literal: Const { ty: *const i32, val: Value(Scalar(alloc3)) }

src/test/mir-opt/const_promotion_extern_static.FOO.PromoteTemps.diff

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
- StorageLive(_5); // scope 1 at $DIR/const-promotion-extern-static.rs:13:42: 13:43
2121
- _5 = const {alloc3: *const i32}; // scope 1 at $DIR/const-promotion-extern-static.rs:13:42: 13:43
2222
+ _6 = const FOO::promoted[0]; // scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:55
23-
+ // ty::Const
23+
// ty::Const
24+
- // + ty: *const i32
25+
- // + val: Value(Scalar(alloc3))
2426
+ // + ty: &[&i32; 1]
2527
+ // + val: Unevaluated(FOO, [], Some(promoted[0]))
2628
// mir::Constant

src/test/mir-opt/const_prop/mutable_variable_no_prop.main.ConstProp.diff

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
StorageLive(_3); // scope 2 at $DIR/mutable_variable_no_prop.rs:9:13: 9:19
2525
StorageLive(_4); // scope 2 at $DIR/mutable_variable_no_prop.rs:9:13: 9:19
2626
_4 = const {alloc1: *mut u32}; // scope 2 at $DIR/mutable_variable_no_prop.rs:9:13: 9:19
27+
// ty::Const
28+
// + ty: *mut u32
29+
// + val: Value(Scalar(alloc1))
2730
// mir::Constant
2831
// + span: $DIR/mutable_variable_no_prop.rs:9:13: 9:19
2932
// + literal: Const { ty: *mut u32, val: Value(Scalar(alloc1)) }

src/test/mir-opt/const_prop/read_immutable_static.main.ConstProp.diff

+6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
StorageLive(_2); // scope 0 at $DIR/read_immutable_static.rs:7:13: 7:16
1818
StorageLive(_3); // scope 0 at $DIR/read_immutable_static.rs:7:13: 7:16
1919
_3 = const {alloc1: &u8}; // scope 0 at $DIR/read_immutable_static.rs:7:13: 7:16
20+
// ty::Const
21+
// + ty: &u8
22+
// + val: Value(Scalar(alloc1))
2023
// mir::Constant
2124
// + span: $DIR/read_immutable_static.rs:7:13: 7:16
2225
// + literal: Const { ty: &u8, val: Value(Scalar(alloc1)) }
@@ -25,6 +28,9 @@
2528
StorageLive(_4); // scope 0 at $DIR/read_immutable_static.rs:7:19: 7:22
2629
StorageLive(_5); // scope 0 at $DIR/read_immutable_static.rs:7:19: 7:22
2730
_5 = const {alloc1: &u8}; // scope 0 at $DIR/read_immutable_static.rs:7:19: 7:22
31+
// ty::Const
32+
// + ty: &u8
33+
// + val: Value(Scalar(alloc1))
2834
// mir::Constant
2935
// + span: $DIR/read_immutable_static.rs:7:19: 7:22
3036
// + literal: Const { ty: &u8, val: Value(Scalar(alloc1)) }

0 commit comments

Comments
 (0)