Skip to content

Use ccache for stage0 tool builds #136942

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 19 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/rustc_lint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

// tidy-alphabetical-start
#![allow(internal_features)]
#![cfg_attr(bootstrap, feature(extract_if))]
#![cfg_attr(doc, recursion_limit = "256")] // FIXME(nnethercote): will be removed by #124141
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![doc(rust_logo)]
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_metadata/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// tidy-alphabetical-start
#![allow(internal_features)]
#![cfg_attr(bootstrap, feature(extract_if))]
#![cfg_attr(doc, recursion_limit = "256")] // FIXME(nnethercote): will be removed by #124141
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![doc(rust_logo)]
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_middle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#![allow(rustc::diagnostic_outside_of_impl)]
#![allow(rustc::potential_query_instability)]
#![allow(rustc::untranslatable_diagnostic)]
#![cfg_attr(bootstrap, feature(extract_if))]
#![cfg_attr(doc, recursion_limit = "256")] // FIXME(nnethercote): will be removed by #124141
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![doc(rust_logo)]
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#![allow(internal_features)]
#![allow(rustc::diagnostic_outside_of_impl)]
#![allow(rustc::untranslatable_diagnostic)]
#![cfg_attr(bootstrap, feature(extract_if))]
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![doc(rust_logo)]
#![feature(assert_matches)]
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_serialize/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// tidy-alphabetical-start
#![allow(internal_features)]
#![allow(rustc::internal)]
#![cfg_attr(bootstrap, feature(ptr_sub_ptr))]
#![cfg_attr(test, feature(test))]
#![doc(
html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/",
Expand Down
27 changes: 24 additions & 3 deletions compiler/rustc_serialize/src/opaque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,13 +280,27 @@ impl<'a> MemDecoder<'a> {
#[inline]
pub fn len(&self) -> usize {
// SAFETY: This recovers the length of the original slice, only using members we never modify.
unsafe { self.end.offset_from_unsigned(self.start) }
#[cfg(bootstrap)]
unsafe {
return self.end.sub_ptr(self.start);
}
#[cfg(not(bootstrap))]
unsafe {
self.end.offset_from_unsigned(self.start)
}
}

#[inline]
pub fn remaining(&self) -> usize {
// SAFETY: This type guarantees current <= end.
unsafe { self.end.offset_from_unsigned(self.current) }
#[cfg(bootstrap)]
unsafe {
return self.end.sub_ptr(self.current);
}
#[cfg(not(bootstrap))]
unsafe {
self.end.offset_from_unsigned(self.current)
}
}

#[cold]
Expand Down Expand Up @@ -400,7 +414,14 @@ impl<'a> Decoder for MemDecoder<'a> {
#[inline]
fn position(&self) -> usize {
// SAFETY: This type guarantees start <= current
unsafe { self.current.offset_from_unsigned(self.start) }
#[cfg(bootstrap)]
unsafe {
return self.current.sub_ptr(self.start);
}
#[cfg(not(bootstrap))]
unsafe {
self.current.offset_from_unsigned(self.start)
}
}
}

Expand Down
14 changes: 14 additions & 0 deletions compiler/rustc_span/src/analyze_source_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,30 @@ cfg_match! {

// For character in the chunk, see if its byte value is < 0, which
// indicates that it's part of a UTF-8 char.
#[cfg(bootstrap)]
let multibyte_test = unsafe { _mm_cmplt_epi8(chunk, _mm_set1_epi8(0)) };
#[cfg(not(bootstrap))]
let multibyte_test = _mm_cmplt_epi8(chunk, _mm_set1_epi8(0));

// Create a bit mask from the comparison results.
#[cfg(bootstrap)]
let multibyte_mask = unsafe { _mm_movemask_epi8(multibyte_test) };
#[cfg(not(bootstrap))]
let multibyte_mask = _mm_movemask_epi8(multibyte_test);

// If the bit mask is all zero, we only have ASCII chars here:
if multibyte_mask == 0 {
assert!(intra_chunk_offset == 0);

// Check for newlines in the chunk
#[cfg(bootstrap)]
let newlines_test = unsafe { _mm_cmpeq_epi8(chunk, _mm_set1_epi8(b'\n' as i8)) };
#[cfg(not(bootstrap))]
let newlines_test = _mm_cmpeq_epi8(chunk, _mm_set1_epi8(b'\n' as i8));

#[cfg(bootstrap)]
let mut newlines_mask = unsafe { _mm_movemask_epi8(newlines_test) };
#[cfg(not(bootstrap))]
let mut newlines_mask = _mm_movemask_epi8(newlines_test);

let output_offset = RelativeBytePos::from_usize(chunk_index * CHUNK_SIZE + 1);
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_trait_selection/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#![allow(internal_features)]
#![allow(rustc::diagnostic_outside_of_impl)]
#![allow(rustc::untranslatable_diagnostic)]
#![cfg_attr(bootstrap, feature(extract_if))]
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![doc(rust_logo)]
#![feature(assert_matches)]
Expand Down
2 changes: 1 addition & 1 deletion library/alloc/src/collections/btree/set_val.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub(super) struct SetValZST;
/// Returns `true` only for type `SetValZST`, `false` for all other types (blanket implementation).
/// `TypeId` requires a `'static` lifetime, use of this trait avoids that restriction.
///
/// [`TypeId`]: std::any::TypeId
/// [`TypeId`]: core::any::TypeId
pub(super) trait IsSetVal {
fn is_set_val() -> bool;
}
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ pub macro Clone($item:item) {
/// Use closures allow captured values to be automatically used.
/// This is similar to have a closure that you would call `.use` over each captured value.
#[unstable(feature = "ergonomic_clones", issue = "132290")]
#[cfg_attr(not(bootstrap), lang = "use_cloned")]
#[lang = "use_cloned"]
pub trait UseCloned: Clone {
// Empty.
}
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1546,7 +1546,7 @@ unsafe fn run(fmt: &mut Formatter<'_>, arg: &rt::Placeholder, args: &[rt::Argume
#[cfg(bootstrap)]
unsafe fn getcount(args: &[rt::Argument<'_>], cnt: &rt::Count) -> Option<u16> {
match *cnt {
rt::Count::Is(n) => Some(n as u16),
rt::Count::Is(n) => Some(n),
rt::Count::Implied => None,
rt::Count::Param(i) => {
debug_assert!(i < args.len());
Expand Down
4 changes: 0 additions & 4 deletions library/core/src/fmt/rt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ pub enum Alignment {
#[derive(Copy, Clone)]
pub enum Count {
/// Specified with a literal number, stores the value
#[cfg(bootstrap)]
Is(usize),
/// Specified with a literal number, stores the value
#[cfg(not(bootstrap))]
Is(u16),
/// Specified using `$` and `*` syntaxes, stores the index into `args`
Param(usize),
Expand Down
48 changes: 0 additions & 48 deletions library/core/src/intrinsics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2307,41 +2307,17 @@ pub unsafe fn truncf128(x: f128) -> f128;
/// [`f16::round_ties_even`](../../std/primitive.f16.html#method.round_ties_even)
#[rustc_intrinsic]
#[rustc_nounwind]
#[cfg(not(bootstrap))]
pub fn round_ties_even_f16(x: f16) -> f16;

/// To be removed on next bootstrap bump.
#[cfg(bootstrap)]
pub fn round_ties_even_f16(x: f16) -> f16 {
#[rustc_intrinsic]
#[rustc_nounwind]
unsafe fn rintf16(x: f16) -> f16;

// SAFETY: this intrinsic isn't actually unsafe
unsafe { rintf16(x) }
}

/// Returns the nearest integer to an `f32`. Rounds half-way cases to the number with an even
/// least significant digit.
///
/// The stabilized version of this intrinsic is
/// [`f32::round_ties_even`](../../std/primitive.f32.html#method.round_ties_even)
#[rustc_intrinsic]
#[rustc_nounwind]
#[cfg(not(bootstrap))]
pub fn round_ties_even_f32(x: f32) -> f32;

/// To be removed on next bootstrap bump.
#[cfg(bootstrap)]
pub fn round_ties_even_f32(x: f32) -> f32 {
#[rustc_intrinsic]
#[rustc_nounwind]
unsafe fn rintf32(x: f32) -> f32;

// SAFETY: this intrinsic isn't actually unsafe
unsafe { rintf32(x) }
}

/// Provided for compatibility with stdarch. DO NOT USE.
#[inline(always)]
pub unsafe fn rintf32(x: f32) -> f32 {
Expand All @@ -2355,20 +2331,8 @@ pub unsafe fn rintf32(x: f32) -> f32 {
/// [`f64::round_ties_even`](../../std/primitive.f64.html#method.round_ties_even)
#[rustc_intrinsic]
#[rustc_nounwind]
#[cfg(not(bootstrap))]
pub fn round_ties_even_f64(x: f64) -> f64;

/// To be removed on next bootstrap bump.
#[cfg(bootstrap)]
pub fn round_ties_even_f64(x: f64) -> f64 {
#[rustc_intrinsic]
#[rustc_nounwind]
unsafe fn rintf64(x: f64) -> f64;

// SAFETY: this intrinsic isn't actually unsafe
unsafe { rintf64(x) }
}

/// Provided for compatibility with stdarch. DO NOT USE.
#[inline(always)]
pub unsafe fn rintf64(x: f64) -> f64 {
Expand All @@ -2382,20 +2346,8 @@ pub unsafe fn rintf64(x: f64) -> f64 {
/// [`f128::round_ties_even`](../../std/primitive.f128.html#method.round_ties_even)
#[rustc_intrinsic]
#[rustc_nounwind]
#[cfg(not(bootstrap))]
pub fn round_ties_even_f128(x: f128) -> f128;

/// To be removed on next bootstrap bump.
#[cfg(bootstrap)]
pub fn round_ties_even_f128(x: f128) -> f128 {
#[rustc_intrinsic]
#[rustc_nounwind]
unsafe fn rintf128(x: f128) -> f128;

// SAFETY: this intrinsic isn't actually unsafe
unsafe { rintf128(x) }
}

/// Returns the nearest integer to an `f16`. Rounds half-way cases away from zero.
///
/// The stabilized version of this intrinsic is
Expand Down
1 change: 0 additions & 1 deletion library/core/src/macros/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1753,7 +1753,6 @@ pub(crate) mod builtin {
reason = "`type_alias_impl_trait` has open design concerns"
)]
#[rustc_builtin_macro]
#[cfg(not(bootstrap))]
pub macro define_opaque($($tt:tt)*) {
/* compiler built-in */
}
Expand Down
6 changes: 3 additions & 3 deletions library/core/src/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ macro_rules! pattern_type {
)]
pub trait RangePattern {
/// Trait version of the inherent `MIN` assoc const.
#[cfg_attr(not(bootstrap), lang = "RangeMin")]
#[lang = "RangeMin"]
const MIN: Self;

/// Trait version of the inherent `MIN` assoc const.
#[cfg_attr(not(bootstrap), lang = "RangeMax")]
#[lang = "RangeMax"]
const MAX: Self;

/// A compile-time helper to subtract 1 for exclusive ranges.
#[cfg_attr(not(bootstrap), lang = "RangeSub")]
#[lang = "RangeSub"]
#[track_caller]
fn sub_one(self) -> Self;
}
Expand Down
1 change: 0 additions & 1 deletion library/core/src/prelude/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,4 @@ pub use crate::macros::builtin::deref;
issue = "63063",
reason = "`type_alias_impl_trait` has open design concerns"
)]
#[cfg(not(bootstrap))]
pub use crate::macros::builtin::define_opaque;
2 changes: 1 addition & 1 deletion library/std/src/backtrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ mod helper {
use super::*;
pub(super) type LazyResolve = impl (FnOnce() -> Capture) + Send + Sync + UnwindSafe;

#[cfg_attr(not(bootstrap), define_opaque(LazyResolve))]
#[define_opaque(LazyResolve)]
pub(super) fn lazy_resolve(mut capture: Capture) -> LazyResolve {
move || {
// Use the global backtrace lock to synchronize this as it's a
Expand Down
1 change: 0 additions & 1 deletion library/std/src/prelude/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ pub use core::prelude::v1::deref;
issue = "63063",
reason = "`type_alias_impl_trait` has open design concerns"
)]
#[cfg(not(bootstrap))]
pub use core::prelude::v1::define_opaque;

// The file so far is equivalent to core/src/prelude/v1.rs. It is duplicated
Expand Down
13 changes: 7 additions & 6 deletions src/bootstrap/defaults/bootstrap.library.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
# These defaults are meant for contributors to the standard library and documentation.
[build]
# When building the standard library, you almost never want to build the compiler itself.
build-stage = 0
test-stage = 0
bench-stage = 0
build-stage = 1
test-stage = 1
bench-stage = 1

[rust]
# This greatly increases the speed of rebuilds, especially when there are only minor changes. However, it makes the initial build slightly slower.
incremental = true
# Make the compiler and standard library faster to build, at the expense of a ~20% runtime slowdown.
lto = "off"
# Download rustc by default for library profile if compiler-affecting
# directories are not modified. For CI this is disabled.
# When building the standard library, you almost never want to build the compiler itself.
#
# If compiler-affecting directories are not modified, use precompiled rustc to speed up
# library development by skipping compiler builds.
download-rustc = "if-unchanged"

[llvm]
Expand Down
9 changes: 9 additions & 0 deletions src/bootstrap/src/core/build_steps/check.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Implementation of compiling the compiler and standard library, in "check"-based modes.

use crate::core::build_steps::compile;
use crate::core::build_steps::compile::{
add_to_sysroot, run_cargo, rustc_cargo, rustc_cargo_env, std_cargo, std_crates_for_run_make,
};
Expand Down Expand Up @@ -45,10 +46,12 @@ impl Step for Std {
const DEFAULT: bool = true;

fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
let stage = run.builder.top_stage;
run.crate_or_deps("sysroot")
.crate_or_deps("coretests")
.crate_or_deps("alloctests")
.path("library")
.default_condition(stage != 0)
}

fn make_run(run: RunConfig<'_>) {
Expand All @@ -62,6 +65,12 @@ impl Step for Std {
let target = self.target;
let compiler = builder.compiler(builder.top_stage, builder.config.build);

if builder.top_stage == 0 {
// Reuse the stage0 libstd
builder.ensure(compile::Std::new(compiler, target));
return;
}

let mut cargo = builder::Cargo::new(
builder,
compiler,
Expand Down
26 changes: 15 additions & 11 deletions src/bootstrap/src/core/build_steps/clippy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,16 +207,18 @@ impl Step for Rustc {
let compiler = builder.compiler(builder.top_stage, builder.config.build);
let target = self.target;

if compiler.stage != 0 {
// If we're not in stage 0, then we won't have a std from the beta
// compiler around. That means we need to make sure there's one in
// the sysroot for the compiler to find. Otherwise, we're going to
// fail when building crates that need to generate code (e.g., build
// scripts and their dependencies).
builder.ensure(compile::Std::new(compiler, compiler.host));
builder.ensure(compile::Std::new(compiler, target));
} else {
builder.ensure(check::Std::new(target).build_kind(Some(Kind::Check)));
if !builder.download_rustc() {
if compiler.stage != 0 {
// If we're not in stage 0, then we won't have a std from the beta
// compiler around. That means we need to make sure there's one in
// the sysroot for the compiler to find. Otherwise, we're going to
// fail when building crates that need to generate code (e.g., build
// scripts and their dependencies).
builder.ensure(compile::Std::new(compiler, compiler.host));
builder.ensure(compile::Std::new(compiler, target));
} else {
builder.ensure(check::Std::new(target).build_kind(Some(Kind::Check)));
}
}

let mut cargo = builder::Cargo::new(
Expand Down Expand Up @@ -286,7 +288,9 @@ macro_rules! lint_any {
let compiler = builder.compiler(builder.top_stage, builder.config.build);
let target = self.target;

builder.ensure(check::Rustc::new(target, builder).build_kind(Some(Kind::Check)));
if !builder.download_rustc() {
builder.ensure(check::Rustc::new(target, builder).build_kind(Some(Kind::Check)));
};

let cargo = prepare_tool_cargo(
builder,
Expand Down
Loading
Loading