From 0b6ec3a25c2759ec2a3d4faa51daf9eee3580eda Mon Sep 17 00:00:00 2001 From: b-naber Date: Fri, 4 Mar 2022 12:02:17 +0100 Subject: [PATCH 1/6] add parallel alt builder to CI --- .github/workflows/ci.yml | 5 +++++ src/ci/github-actions/ci.yml | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 97a31d3c97020..4acd73f6dbc73 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,6 +46,11 @@ jobs: - name: x86_64-gnu-llvm-12 os: ubuntu-20.04-xl env: {} + - name: dist-x86_64-msvc-alt + env: + RUST_CONFIGURE_ARGS: "--build=x86_64-pc-windows-msvc --enable-extended --enable-profiler" + SCRIPT: python x.py dist + os: windows-latest-xl - name: x86_64-gnu-tools env: CI_ONLY_WHEN_SUBMODULES_CHANGED: 1 diff --git a/src/ci/github-actions/ci.yml b/src/ci/github-actions/ci.yml index 8abf4244a38dd..7ffdf5fdc902d 100644 --- a/src/ci/github-actions/ci.yml +++ b/src/ci/github-actions/ci.yml @@ -291,6 +291,12 @@ jobs: - name: x86_64-gnu-llvm-12 <<: *job-linux-xl + - name: dist-x86_64-msvc-alt + env: + RUST_CONFIGURE_ARGS: --build=x86_64-pc-windows-msvc --enable-extended --enable-profiler + SCRIPT: python x.py dist + <<: *job-windows-xl + - name: x86_64-gnu-tools env: CI_ONLY_WHEN_SUBMODULES_CHANGED: 1 From 095fca29249e1e351cfdf941e77039acb44ca4b1 Mon Sep 17 00:00:00 2001 From: b-naber Date: Fri, 4 Mar 2022 14:27:28 +0100 Subject: [PATCH 2/6] check_static_ptr change --- compiler/rustc_middle/src/mir/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 9a36230516c17..8eb5c3be1bb97 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -2534,7 +2534,7 @@ pub enum ConstantKind<'tcx> { impl<'tcx> Constant<'tcx> { pub fn check_static_ptr(&self, tcx: TyCtxt<'_>) -> Option { - match self.literal.const_for_ty()?.val().try_to_scalar() { + match self.literal.try_to_scalar() { Some(Scalar::Ptr(ptr, _size)) => match tcx.global_alloc(ptr.provenance) { GlobalAlloc::Static(def_id) => { assert!(!tcx.is_thread_local_static(def_id)); From 4ae519f29e5db4856523cac5d6011ac4fe81ce58 Mon Sep 17 00:00:00 2001 From: b-naber Date: Fri, 4 Mar 2022 16:01:39 +0100 Subject: [PATCH 3/6] ExprKind::StaticRef changes --- compiler/rustc_middle/src/thir.rs | 4 +++- compiler/rustc_middle/src/thir/visit.rs | 2 +- .../rustc_mir_build/src/build/expr/as_constant.rs | 10 ++++++++-- compiler/rustc_mir_build/src/thir/cx/expr.rs | 12 ++---------- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/compiler/rustc_middle/src/thir.rs b/compiler/rustc_middle/src/thir.rs index 40dce281c82bf..04bc0c8b52114 100644 --- a/compiler/rustc_middle/src/thir.rs +++ b/compiler/rustc_middle/src/thir.rs @@ -17,6 +17,7 @@ use rustc_index::newtype_index; use rustc_index::vec::IndexVec; use rustc_middle::infer::canonical::Canonical; use rustc_middle::middle::region; +use rustc_middle::mir::interpret::AllocId; use rustc_middle::mir::{ BinOp, BorrowKind, FakeReadCause, Field, Mutability, UnOp, UserTypeProjection, }; @@ -419,7 +420,8 @@ pub enum ExprKind<'tcx> { /// This is only distinguished from `Literal` so that we can register some /// info for diagnostics. StaticRef { - literal: Const<'tcx>, + alloc_id: AllocId, + ty: Ty<'tcx>, def_id: DefId, }, /// Inline assembly, i.e. `asm!()`. diff --git a/compiler/rustc_middle/src/thir/visit.rs b/compiler/rustc_middle/src/thir/visit.rs index 95489ac3ab2c6..b3e2cb132a273 100644 --- a/compiler/rustc_middle/src/thir/visit.rs +++ b/compiler/rustc_middle/src/thir/visit.rs @@ -123,7 +123,7 @@ pub fn walk_expr<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, expr: &Exp } Closure { closure_id: _, substs: _, upvars: _, movability: _, fake_reads: _ } => {} Literal { literal, user_ty: _, const_id: _ } => visitor.visit_const(literal), - StaticRef { literal, def_id: _ } => visitor.visit_const(literal), + StaticRef { .. } => {} InlineAsm { ref operands, template: _, options: _, line_spans: _ } => { for op in &**operands { use InlineAsmOperand::*; diff --git a/compiler/rustc_mir_build/src/build/expr/as_constant.rs b/compiler/rustc_mir_build/src/build/expr/as_constant.rs index 79ac09d523d07..1db653559d118 100644 --- a/compiler/rustc_mir_build/src/build/expr/as_constant.rs +++ b/compiler/rustc_mir_build/src/build/expr/as_constant.rs @@ -1,6 +1,7 @@ //! See docs in build/expr/mod.rs use crate::build::Builder; +use rustc_middle::mir::interpret::{ConstValue, Scalar}; use rustc_middle::mir::*; use rustc_middle::thir::*; use rustc_middle::ty::CanonicalUserTypeAnnotation; @@ -23,11 +24,16 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { inferred_ty: ty, }) }); + assert_eq!(literal.ty(), ty); Constant { span, user_ty, literal: literal.into() } } - ExprKind::StaticRef { literal, .. } => { - Constant { span, user_ty: None, literal: literal.into() } + ExprKind::StaticRef { alloc_id, ty, .. } => { + let const_val = + ConstValue::Scalar(Scalar::from_pointer(alloc_id.into(), &this.tcx)); + let literal = ConstantKind::Val(const_val, ty); + + Constant { span, user_ty: None, literal } } ExprKind::ConstBlock { value } => { Constant { span: span, user_ty: None, literal: value.into() } diff --git a/compiler/rustc_mir_build/src/thir/cx/expr.rs b/compiler/rustc_mir_build/src/thir/cx/expr.rs index 651edc827c320..5a7e1d88dd03f 100644 --- a/compiler/rustc_mir_build/src/thir/cx/expr.rs +++ b/compiler/rustc_mir_build/src/thir/cx/expr.rs @@ -8,7 +8,6 @@ use rustc_middle::hir::place::Place as HirPlace; use rustc_middle::hir::place::PlaceBase as HirPlaceBase; use rustc_middle::hir::place::ProjectionKind as HirProjectionKind; use rustc_middle::middle::region; -use rustc_middle::mir::interpret::Scalar; use rustc_middle::mir::{BinOp, BorrowKind, Field, UnOp}; use rustc_middle::thir::*; use rustc_middle::ty::adjustment::{ @@ -941,15 +940,8 @@ impl<'tcx> Cx<'tcx> { let kind = if self.tcx.is_thread_local_static(id) { ExprKind::ThreadLocalRef(id) } else { - let ptr = self.tcx.create_static_alloc(id); - ExprKind::StaticRef { - literal: ty::Const::from_scalar( - self.tcx, - Scalar::from_pointer(ptr.into(), &self.tcx), - ty, - ), - def_id: id, - } + let alloc_id = self.tcx.create_static_alloc(id); + ExprKind::StaticRef { alloc_id, ty, def_id: id } }; ExprKind::Deref { arg: self.thir.exprs.push(Expr { ty, temp_lifetime, span: expr.span, kind }), From 4422846e6a61cc1742a6aa379cf58da8dae2ef84 Mon Sep 17 00:00:00 2001 From: b-naber Date: Fri, 4 Mar 2022 16:20:30 +0100 Subject: [PATCH 4/6] dont use x86_64-gnu-llvm-12 --- .github/workflows/ci.yml | 3 --- src/ci/github-actions/ci.yml | 3 --- 2 files changed, 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4acd73f6dbc73..8fac9dedf817c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -43,9 +43,6 @@ jobs: - name: mingw-check os: ubuntu-20.04-xl env: {} - - name: x86_64-gnu-llvm-12 - os: ubuntu-20.04-xl - env: {} - name: dist-x86_64-msvc-alt env: RUST_CONFIGURE_ARGS: "--build=x86_64-pc-windows-msvc --enable-extended --enable-profiler" diff --git a/src/ci/github-actions/ci.yml b/src/ci/github-actions/ci.yml index 7ffdf5fdc902d..6e8e158072a9a 100644 --- a/src/ci/github-actions/ci.yml +++ b/src/ci/github-actions/ci.yml @@ -288,9 +288,6 @@ jobs: - name: mingw-check <<: *job-linux-xl - - name: x86_64-gnu-llvm-12 - <<: *job-linux-xl - - name: dist-x86_64-msvc-alt env: RUST_CONFIGURE_ARGS: --build=x86_64-pc-windows-msvc --enable-extended --enable-profiler From 04cd0b9825d6a0b81126d23feb8c72ab5e7d0813 Mon Sep 17 00:00:00 2001 From: b-naber Date: Fri, 4 Mar 2022 17:56:35 +0100 Subject: [PATCH 5/6] pretty printer changes --- compiler/rustc_middle/src/mir/pretty.rs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_middle/src/mir/pretty.rs b/compiler/rustc_middle/src/mir/pretty.rs index 6886a0f4cf148..a3900dde1b6ab 100644 --- a/compiler/rustc_middle/src/mir/pretty.rs +++ b/compiler/rustc_middle/src/mir/pretty.rs @@ -17,9 +17,8 @@ use rustc_middle::mir::interpret::{ use rustc_middle::mir::visit::Visitor; use rustc_middle::mir::MirSource; use rustc_middle::mir::*; -use rustc_middle::ty::{self, TyCtxt, TypeFoldable, TypeVisitor}; +use rustc_middle::ty::{self, TyCtxt}; use rustc_target::abi::Size; -use std::ops::ControlFlow; const INDENT: &str = " "; /// Alignment for lining up comments following MIR statements @@ -669,16 +668,27 @@ pub fn write_allocations<'tcx>( } } struct CollectAllocIds(BTreeSet); - impl<'tcx> TypeVisitor<'tcx> for CollectAllocIds { - fn visit_const(&mut self, c: ty::Const<'tcx>) -> ControlFlow { + + impl<'tcx> Visitor<'tcx> for CollectAllocIds { + fn visit_const(&mut self, c: ty::Const<'tcx>, _loc: Location) { if let ty::ConstKind::Value(val) = c.val() { self.0.extend(alloc_ids_from_const(val)); } - c.super_visit_with(self) + } + + fn visit_constant(&mut self, c: &Constant<'tcx>, loc: Location) { + match c.literal { + ConstantKind::Ty(c) => self.visit_const(c, loc), + ConstantKind::Val(val, _) => { + self.0.extend(alloc_ids_from_const(val)); + } + } } } + let mut visitor = CollectAllocIds(Default::default()); - body.visit_with(&mut visitor); + visitor.visit_body(body); + // `seen` contains all seen allocations, including the ones we have *not* printed yet. // The protocol is to first `insert` into `seen`, and only if that returns `true` // then push to `todo`. From f67c9054a90a4ba3a96b1a8f264abc298ac1b0be Mon Sep 17 00:00:00 2001 From: b-naber Date: Fri, 4 Mar 2022 19:52:44 +0100 Subject: [PATCH 6/6] try build --- .github/workflows/ci.yml | 14 +++++++++++--- src/ci/github-actions/ci.yml | 19 ++++++++++++++++--- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8fac9dedf817c..ae03c11da27ba 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -560,9 +560,17 @@ jobs: strategy: matrix: include: - - name: dist-x86_64-linux - os: ubuntu-20.04-xl - env: {} + - name: dist-x86_64-msvc + env: + RUST_CONFIGURE_ARGS: "--build=x86_64-pc-windows-msvc --host=x86_64-pc-windows-msvc --target=x86_64-pc-windows-msvc --enable-full-tools --enable-profiler" + SCRIPT: python x.py dist + DIST_REQUIRE_ALL_TOOLS: 1 + os: windows-latest-xl + - name: dist-x86_64-msvc-alt + env: + RUST_CONFIGURE_ARGS: "--build=x86_64-pc-windows-msvc --enable-extended --enable-profiler" + SCRIPT: python x.py dist + os: windows-latest-xl timeout-minutes: 600 runs-on: "${{ matrix.os }}" steps: diff --git a/src/ci/github-actions/ci.yml b/src/ci/github-actions/ci.yml index 6e8e158072a9a..de2d6ae3d6c62 100644 --- a/src/ci/github-actions/ci.yml +++ b/src/ci/github-actions/ci.yml @@ -694,9 +694,22 @@ jobs: strategy: matrix: include: - - &dist-x86_64-linux - name: dist-x86_64-linux - <<: *job-linux-xl + - name: dist-x86_64-msvc + env: + RUST_CONFIGURE_ARGS: >- + --build=x86_64-pc-windows-msvc + --host=x86_64-pc-windows-msvc + --target=x86_64-pc-windows-msvc + --enable-full-tools + --enable-profiler + SCRIPT: python x.py dist + DIST_REQUIRE_ALL_TOOLS: 1 + <<: *job-windows-xl + - name: dist-x86_64-msvc-alt + env: + RUST_CONFIGURE_ARGS: --build=x86_64-pc-windows-msvc --enable-extended --enable-profiler + SCRIPT: python x.py dist + <<: *job-windows-xl master: name: master