Skip to content

Commit 3d3394e

Browse files
committed
Auto merge of rust-lang#119899 - onur-ozkan:redesign-stage0-std, r=<try>
redesign stage 0 std This is intended to update bootstrap to use the beta standard library on stage 0, rather than compiling it from source (see the motivation at rust-lang/compiler-team#619). ~~Blocked on rust-lang#122709 try-job: mingw-check
2 parents 961351c + 97d0bb1 commit 3d3394e

File tree

31 files changed

+118
-121
lines changed

31 files changed

+118
-121
lines changed

compiler/rustc_lint/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
2222
// tidy-alphabetical-start
2323
#![allow(internal_features)]
24+
#![cfg_attr(bootstrap, feature(extract_if))]
2425
#![cfg_attr(doc, recursion_limit = "256")] // FIXME(nnethercote): will be removed by #124141
2526
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
2627
#![doc(rust_logo)]

compiler/rustc_metadata/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// tidy-alphabetical-start
22
#![allow(internal_features)]
3+
#![cfg_attr(bootstrap, feature(extract_if))]
34
#![cfg_attr(doc, recursion_limit = "256")] // FIXME(nnethercote): will be removed by #124141
45
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
56
#![doc(rust_logo)]

compiler/rustc_middle/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#![allow(rustc::diagnostic_outside_of_impl)]
3030
#![allow(rustc::potential_query_instability)]
3131
#![allow(rustc::untranslatable_diagnostic)]
32+
#![cfg_attr(bootstrap, feature(extract_if))]
3233
#![cfg_attr(doc, recursion_limit = "256")] // FIXME(nnethercote): will be removed by #124141
3334
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
3435
#![doc(rust_logo)]

compiler/rustc_resolve/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#![allow(rustc::diagnostic_outside_of_impl)]
1212
#![allow(rustc::potential_query_instability)]
1313
#![allow(rustc::untranslatable_diagnostic)]
14+
#![cfg_attr(bootstrap, feature(extract_if))]
1415
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
1516
#![doc(rust_logo)]
1617
#![feature(assert_matches)]

compiler/rustc_serialize/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// tidy-alphabetical-start
44
#![allow(internal_features)]
55
#![allow(rustc::internal)]
6+
#![cfg_attr(bootstrap, feature(ptr_sub_ptr))]
67
#![cfg_attr(test, feature(test))]
78
#![doc(
89
html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/",

compiler/rustc_serialize/src/opaque.rs

+24-3
Original file line numberDiff line numberDiff line change
@@ -280,13 +280,27 @@ impl<'a> MemDecoder<'a> {
280280
#[inline]
281281
pub fn len(&self) -> usize {
282282
// SAFETY: This recovers the length of the original slice, only using members we never modify.
283-
unsafe { self.end.offset_from_unsigned(self.start) }
283+
#[cfg(bootstrap)]
284+
unsafe {
285+
return self.end.sub_ptr(self.start);
286+
}
287+
#[cfg(not(bootstrap))]
288+
unsafe {
289+
self.end.offset_from_unsigned(self.start)
290+
}
284291
}
285292

286293
#[inline]
287294
pub fn remaining(&self) -> usize {
288295
// SAFETY: This type guarantees current <= end.
289-
unsafe { self.end.offset_from_unsigned(self.current) }
296+
#[cfg(bootstrap)]
297+
unsafe {
298+
return self.end.sub_ptr(self.current);
299+
}
300+
#[cfg(not(bootstrap))]
301+
unsafe {
302+
self.end.offset_from_unsigned(self.current)
303+
}
290304
}
291305

292306
#[cold]
@@ -400,7 +414,14 @@ impl<'a> Decoder for MemDecoder<'a> {
400414
#[inline]
401415
fn position(&self) -> usize {
402416
// SAFETY: This type guarantees start <= current
403-
unsafe { self.current.offset_from_unsigned(self.start) }
417+
#[cfg(bootstrap)]
418+
unsafe {
419+
return self.current.sub_ptr(self.start);
420+
}
421+
#[cfg(not(bootstrap))]
422+
unsafe {
423+
self.current.offset_from_unsigned(self.start)
424+
}
404425
}
405426
}
406427

compiler/rustc_span/src/analyze_source_file.rs

+14
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,30 @@ cfg_match! {
8383

8484
// For character in the chunk, see if its byte value is < 0, which
8585
// indicates that it's part of a UTF-8 char.
86+
#[cfg(bootstrap)]
87+
let multibyte_test = unsafe { _mm_cmplt_epi8(chunk, _mm_set1_epi8(0)) };
88+
#[cfg(not(bootstrap))]
8689
let multibyte_test = _mm_cmplt_epi8(chunk, _mm_set1_epi8(0));
90+
8791
// Create a bit mask from the comparison results.
92+
#[cfg(bootstrap)]
93+
let multibyte_mask = unsafe { _mm_movemask_epi8(multibyte_test) };
94+
#[cfg(not(bootstrap))]
8895
let multibyte_mask = _mm_movemask_epi8(multibyte_test);
8996

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

94101
// Check for newlines in the chunk
102+
#[cfg(bootstrap)]
103+
let newlines_test = unsafe { _mm_cmpeq_epi8(chunk, _mm_set1_epi8(b'\n' as i8)) };
104+
#[cfg(not(bootstrap))]
95105
let newlines_test = _mm_cmpeq_epi8(chunk, _mm_set1_epi8(b'\n' as i8));
106+
107+
#[cfg(bootstrap)]
108+
let mut newlines_mask = unsafe { _mm_movemask_epi8(newlines_test) };
109+
#[cfg(not(bootstrap))]
96110
let mut newlines_mask = _mm_movemask_epi8(newlines_test);
97111

98112
let output_offset = RelativeBytePos::from_usize(chunk_index * CHUNK_SIZE + 1);

compiler/rustc_trait_selection/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#![allow(internal_features)]
1515
#![allow(rustc::diagnostic_outside_of_impl)]
1616
#![allow(rustc::untranslatable_diagnostic)]
17+
#![cfg_attr(bootstrap, feature(extract_if))]
1718
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
1819
#![doc(rust_logo)]
1920
#![feature(assert_matches)]

library/alloc/src/collections/btree/set_val.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub(super) struct SetValZST;
99
/// Returns `true` only for type `SetValZST`, `false` for all other types (blanket implementation).
1010
/// `TypeId` requires a `'static` lifetime, use of this trait avoids that restriction.
1111
///
12-
/// [`TypeId`]: std::any::TypeId
12+
/// [`TypeId`]: core::any::TypeId
1313
pub(super) trait IsSetVal {
1414
fn is_set_val() -> bool;
1515
}

library/core/src/clone.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ pub macro Clone($item:item) {
216216
/// Use closures allow captured values to be automatically used.
217217
/// This is similar to have a closure that you would call `.use` over each captured value.
218218
#[unstable(feature = "ergonomic_clones", issue = "132290")]
219-
#[cfg_attr(not(bootstrap), lang = "use_cloned")]
219+
#[lang = "use_cloned"]
220220
pub trait UseCloned: Clone {
221221
// Empty.
222222
}

library/core/src/fmt/mod.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1501,9 +1501,6 @@ unsafe fn run(fmt: &mut Formatter<'_>, arg: &rt::Placeholder, args: &[rt::Argume
15011501

15021502
unsafe fn getcount(args: &[rt::Argument<'_>], cnt: &rt::Count) -> Option<u16> {
15031503
match *cnt {
1504-
#[cfg(bootstrap)]
1505-
rt::Count::Is(n) => Some(n as u16),
1506-
#[cfg(not(bootstrap))]
15071504
rt::Count::Is(n) => Some(n),
15081505
rt::Count::Implied => None,
15091506
rt::Count::Param(i) => {

library/core/src/fmt/rt.rs

-4
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ pub enum Alignment {
4747
#[derive(Copy, Clone)]
4848
pub enum Count {
4949
/// Specified with a literal number, stores the value
50-
#[cfg(bootstrap)]
51-
Is(usize),
52-
/// Specified with a literal number, stores the value
53-
#[cfg(not(bootstrap))]
5450
Is(u16),
5551
/// Specified using `$` and `*` syntaxes, stores the index into `args`
5652
Param(usize),

library/core/src/intrinsics/mod.rs

-48
Original file line numberDiff line numberDiff line change
@@ -2149,41 +2149,17 @@ pub unsafe fn truncf128(x: f128) -> f128;
21492149
/// [`f16::round_ties_even`](../../std/primitive.f16.html#method.round_ties_even)
21502150
#[rustc_intrinsic]
21512151
#[rustc_nounwind]
2152-
#[cfg(not(bootstrap))]
21532152
pub fn round_ties_even_f16(x: f16) -> f16;
21542153

2155-
/// To be removed on next bootstrap bump.
2156-
#[cfg(bootstrap)]
2157-
pub fn round_ties_even_f16(x: f16) -> f16 {
2158-
#[rustc_intrinsic]
2159-
#[rustc_nounwind]
2160-
unsafe fn rintf16(x: f16) -> f16;
2161-
2162-
// SAFETY: this intrinsic isn't actually unsafe
2163-
unsafe { rintf16(x) }
2164-
}
2165-
21662154
/// Returns the nearest integer to an `f32`. Rounds half-way cases to the number with an even
21672155
/// least significant digit.
21682156
///
21692157
/// The stabilized version of this intrinsic is
21702158
/// [`f32::round_ties_even`](../../std/primitive.f32.html#method.round_ties_even)
21712159
#[rustc_intrinsic]
21722160
#[rustc_nounwind]
2173-
#[cfg(not(bootstrap))]
21742161
pub fn round_ties_even_f32(x: f32) -> f32;
21752162

2176-
/// To be removed on next bootstrap bump.
2177-
#[cfg(bootstrap)]
2178-
pub fn round_ties_even_f32(x: f32) -> f32 {
2179-
#[rustc_intrinsic]
2180-
#[rustc_nounwind]
2181-
unsafe fn rintf32(x: f32) -> f32;
2182-
2183-
// SAFETY: this intrinsic isn't actually unsafe
2184-
unsafe { rintf32(x) }
2185-
}
2186-
21872163
/// Provided for compatibility with stdarch. DO NOT USE.
21882164
#[inline(always)]
21892165
pub unsafe fn rintf32(x: f32) -> f32 {
@@ -2197,20 +2173,8 @@ pub unsafe fn rintf32(x: f32) -> f32 {
21972173
/// [`f64::round_ties_even`](../../std/primitive.f64.html#method.round_ties_even)
21982174
#[rustc_intrinsic]
21992175
#[rustc_nounwind]
2200-
#[cfg(not(bootstrap))]
22012176
pub fn round_ties_even_f64(x: f64) -> f64;
22022177

2203-
/// To be removed on next bootstrap bump.
2204-
#[cfg(bootstrap)]
2205-
pub fn round_ties_even_f64(x: f64) -> f64 {
2206-
#[rustc_intrinsic]
2207-
#[rustc_nounwind]
2208-
unsafe fn rintf64(x: f64) -> f64;
2209-
2210-
// SAFETY: this intrinsic isn't actually unsafe
2211-
unsafe { rintf64(x) }
2212-
}
2213-
22142178
/// Provided for compatibility with stdarch. DO NOT USE.
22152179
#[inline(always)]
22162180
pub unsafe fn rintf64(x: f64) -> f64 {
@@ -2224,20 +2188,8 @@ pub unsafe fn rintf64(x: f64) -> f64 {
22242188
/// [`f128::round_ties_even`](../../std/primitive.f128.html#method.round_ties_even)
22252189
#[rustc_intrinsic]
22262190
#[rustc_nounwind]
2227-
#[cfg(not(bootstrap))]
22282191
pub fn round_ties_even_f128(x: f128) -> f128;
22292192

2230-
/// To be removed on next bootstrap bump.
2231-
#[cfg(bootstrap)]
2232-
pub fn round_ties_even_f128(x: f128) -> f128 {
2233-
#[rustc_intrinsic]
2234-
#[rustc_nounwind]
2235-
unsafe fn rintf128(x: f128) -> f128;
2236-
2237-
// SAFETY: this intrinsic isn't actually unsafe
2238-
unsafe { rintf128(x) }
2239-
}
2240-
22412193
/// Returns the nearest integer to an `f16`. Rounds half-way cases away from zero.
22422194
///
22432195
/// The stabilized version of this intrinsic is

library/core/src/macros/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1753,7 +1753,6 @@ pub(crate) mod builtin {
17531753
reason = "`type_alias_impl_trait` has open design concerns"
17541754
)]
17551755
#[rustc_builtin_macro]
1756-
#[cfg(not(bootstrap))]
17571756
pub macro define_opaque($($tt:tt)*) {
17581757
/* compiler built-in */
17591758
}

library/core/src/pat.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ macro_rules! pattern_type {
2525
)]
2626
pub trait RangePattern {
2727
/// Trait version of the inherent `MIN` assoc const.
28-
#[cfg_attr(not(bootstrap), lang = "RangeMin")]
28+
#[lang = "RangeMin"]
2929
const MIN: Self;
3030

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

3535
/// A compile-time helper to subtract 1 for exclusive ranges.
36-
#[cfg_attr(not(bootstrap), lang = "RangeSub")]
36+
#[lang = "RangeSub"]
3737
#[track_caller]
3838
fn sub_one(self) -> Self;
3939
}

library/core/src/prelude/v1.rs

-1
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,4 @@ pub use crate::macros::builtin::deref;
117117
issue = "63063",
118118
reason = "`type_alias_impl_trait` has open design concerns"
119119
)]
120-
#[cfg(not(bootstrap))]
121120
pub use crate::macros::builtin::define_opaque;

library/std/src/backtrace.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ mod helper {
432432
use super::*;
433433
pub(super) type LazyResolve = impl (FnOnce() -> Capture) + Send + Sync + UnwindSafe;
434434

435-
#[cfg_attr(not(bootstrap), define_opaque(LazyResolve))]
435+
#[define_opaque(LazyResolve)]
436436
pub(super) fn lazy_resolve(mut capture: Capture) -> LazyResolve {
437437
move || {
438438
// Use the global backtrace lock to synchronize this as it's a

library/std/src/prelude/v1.rs

-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ pub use core::prelude::v1::deref;
109109
issue = "63063",
110110
reason = "`type_alias_impl_trait` has open design concerns"
111111
)]
112-
#[cfg(not(bootstrap))]
113112
pub use core::prelude::v1::define_opaque;
114113

115114
// The file so far is equivalent to core/src/prelude/v1.rs. It is duplicated

src/bootstrap/defaults/config.library.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# These defaults are meant for contributors to the standard library and documentation.
22
[build]
33
# When building the standard library, you almost never want to build the compiler itself.
4-
build-stage = 0
5-
test-stage = 0
6-
bench-stage = 0
4+
build-stage = 1
5+
test-stage = 1
6+
bench-stage = 1
77

88
[rust]
99
# This greatly increases the speed of rebuilds, especially when there are only minor changes. However, it makes the initial build slightly slower.

src/bootstrap/src/core/build_steps/check.rs

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Implementation of compiling the compiler and standard library, in "check"-based modes.
22
3+
use crate::core::build_steps::compile;
34
use crate::core::build_steps::compile::{
45
add_to_sysroot, run_cargo, rustc_cargo, rustc_cargo_env, std_cargo, std_crates_for_run_make,
56
};
@@ -45,10 +46,12 @@ impl Step for Std {
4546
const DEFAULT: bool = true;
4647

4748
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
49+
let stage = run.builder.top_stage;
4850
run.crate_or_deps("sysroot")
4951
.crate_or_deps("coretests")
5052
.crate_or_deps("alloctests")
5153
.path("library")
54+
.default_condition(stage != 0)
5255
}
5356

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

68+
if builder.top_stage == 0 {
69+
// Reuse the beta compiler's libstd
70+
builder.ensure(compile::Std::new(compiler, target));
71+
return;
72+
}
73+
6574
let mut cargo = builder::Cargo::new(
6675
builder,
6776
compiler,

0 commit comments

Comments
 (0)