Skip to content

Commit 660326e

Browse files
committed
Auto merge of #70072 - Centril:rollup-722hooh, r=Centril
Rollup of 7 pull requests Successful merges: - #68746 (Make macro metavars respect (non-)hygiene) - #69688 (Move tidy check to mingw-check) - #69735 (bootstrap: Use hash to determine if sanitizers needs to be rebuilt) - #69922 (implement zeroed and uninitialized with MaybeUninit) - #69956 (Ensure HAS_FREE_LOCAL_NAMES is set for ReFree) - #70061 (Cosmetic fixes in documentation) - #70064 (Update books) Failed merges: r? @ghost
2 parents 5e9ebf4 + 36da5ee commit 660326e

File tree

26 files changed

+233
-201
lines changed

26 files changed

+233
-201
lines changed

src/bootstrap/native.rs

+67-31
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use std::env;
1212
use std::ffi::OsString;
1313
use std::fs::{self, File};
14+
use std::io;
1415
use std::path::{Path, PathBuf};
1516
use std::process::Command;
1617

@@ -54,7 +55,6 @@ impl Step for Llvm {
5455
}
5556
}
5657

57-
let llvm_info = &builder.in_tree_llvm_info;
5858
let root = "src/llvm-project/llvm";
5959
let out_dir = builder.llvm_out(target);
6060
let mut llvm_config_ret_dir = builder.llvm_out(builder.config.build);
@@ -65,40 +65,35 @@ impl Step for Llvm {
6565

6666
let build_llvm_config =
6767
llvm_config_ret_dir.join(exe("llvm-config", &*builder.config.build));
68-
let done_stamp = out_dir.join("llvm-finished-building");
6968

70-
if done_stamp.exists() {
71-
if builder.config.llvm_skip_rebuild {
72-
builder.info(
73-
"Warning: \
74-
Using a potentially stale build of LLVM; \
75-
This may not behave well.",
76-
);
77-
return build_llvm_config;
78-
}
69+
let stamp = out_dir.join("llvm-finished-building");
70+
let stamp = HashStamp::new(stamp, builder.in_tree_llvm_info.sha());
7971

80-
if let Some(llvm_commit) = llvm_info.sha() {
81-
let done_contents = t!(fs::read(&done_stamp));
72+
if builder.config.llvm_skip_rebuild && stamp.path.exists() {
73+
builder.info(
74+
"Warning: \
75+
Using a potentially stale build of LLVM; \
76+
This may not behave well.",
77+
);
78+
return build_llvm_config;
79+
}
8280

83-
// If LLVM was already built previously and the submodule's commit didn't change
84-
// from the previous build, then no action is required.
85-
if done_contents == llvm_commit.as_bytes() {
86-
return build_llvm_config;
87-
}
88-
} else {
81+
if stamp.is_done() {
82+
if stamp.hash.is_none() {
8983
builder.info(
9084
"Could not determine the LLVM submodule commit hash. \
9185
Assuming that an LLVM rebuild is not necessary.",
9286
);
9387
builder.info(&format!(
9488
"To force LLVM to rebuild, remove the file `{}`",
95-
done_stamp.display()
89+
stamp.path.display()
9690
));
97-
return build_llvm_config;
9891
}
92+
return build_llvm_config;
9993
}
10094

10195
builder.info(&format!("Building LLVM for {}", target));
96+
t!(stamp.remove());
10297
let _time = util::timeit(&builder);
10398
t!(fs::create_dir_all(&out_dir));
10499

@@ -271,7 +266,7 @@ impl Step for Llvm {
271266

272267
cfg.build();
273268

274-
t!(fs::write(&done_stamp, llvm_info.sha().unwrap_or("")));
269+
t!(stamp.write());
275270

276271
build_llvm_config
277272
}
@@ -584,17 +579,21 @@ impl Step for Sanitizers {
584579
return runtimes;
585580
}
586581

587-
let done_stamp = out_dir.join("sanitizers-finished-building");
588-
if done_stamp.exists() {
589-
builder.info(&format!(
590-
"Assuming that sanitizers rebuild is not necessary. \
591-
To force a rebuild, remove the file `{}`",
592-
done_stamp.display()
593-
));
582+
let stamp = out_dir.join("sanitizers-finished-building");
583+
let stamp = HashStamp::new(stamp, builder.in_tree_llvm_info.sha());
584+
585+
if stamp.is_done() {
586+
if stamp.hash.is_none() {
587+
builder.info(&format!(
588+
"Rebuild sanitizers by removing the file `{}`",
589+
stamp.path.display()
590+
));
591+
}
594592
return runtimes;
595593
}
596594

597595
builder.info(&format!("Building sanitizers for {}", self.target));
596+
t!(stamp.remove());
598597
let _time = util::timeit(&builder);
599598

600599
let mut cfg = cmake::Config::new(&compiler_rt_dir);
@@ -623,8 +622,7 @@ impl Step for Sanitizers {
623622
cfg.build_target(&runtime.cmake_target);
624623
cfg.build();
625624
}
626-
627-
t!(fs::write(&done_stamp, b""));
625+
t!(stamp.write());
628626

629627
runtimes
630628
}
@@ -689,3 +687,41 @@ fn supported_sanitizers(
689687
}
690688
result
691689
}
690+
691+
struct HashStamp {
692+
path: PathBuf,
693+
hash: Option<Vec<u8>>,
694+
}
695+
696+
impl HashStamp {
697+
fn new(path: PathBuf, hash: Option<&str>) -> Self {
698+
HashStamp { path, hash: hash.map(|s| s.as_bytes().to_owned()) }
699+
}
700+
701+
fn is_done(&self) -> bool {
702+
match fs::read(&self.path) {
703+
Ok(h) => self.hash.as_deref().unwrap_or(b"") == h.as_slice(),
704+
Err(e) if e.kind() == io::ErrorKind::NotFound => false,
705+
Err(e) => {
706+
panic!("failed to read stamp file `{}`: {}", self.path.display(), e);
707+
}
708+
}
709+
}
710+
711+
fn remove(&self) -> io::Result<()> {
712+
match fs::remove_file(&self.path) {
713+
Ok(()) => Ok(()),
714+
Err(e) => {
715+
if e.kind() == io::ErrorKind::NotFound {
716+
Ok(())
717+
} else {
718+
Err(e)
719+
}
720+
}
721+
}
722+
}
723+
724+
fn write(&self) -> io::Result<()> {
725+
fs::write(&self.path, self.hash.as_deref().unwrap_or(b""))
726+
}
727+
}

src/ci/docker/mingw-check/Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ ENV RUN_CHECK_WITH_PARALLEL_QUERIES 1
2525
ENV SCRIPT python2.7 ../x.py check --target=i686-pc-windows-gnu --host=i686-pc-windows-gnu && \
2626
python2.7 ../x.py build --stage 0 src/tools/build-manifest && \
2727
python2.7 ../x.py test --stage 0 src/tools/compiletest && \
28+
python2.7 ../x.py test src/tools/tidy && \
2829
/scripts/validate-toolstate.sh

src/ci/docker/x86_64-gnu-llvm-7/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ ENV RUST_CONFIGURE_ARGS \
2929
--enable-llvm-link-shared \
3030
--set rust.thin-lto-import-instr-limit=10
3131

32-
ENV SCRIPT python2.7 ../x.py test src/tools/tidy && python2.7 ../x.py test
32+
ENV SCRIPT python2.7 ../x.py test --exclude src/tools/tidy && python2.7 ../x.py test src/tools/tidy
3333

3434
# The purpose of this container isn't to test with debug assertions and
3535
# this is run on all PRs, so let's get speedier builds by disabling these extra

src/libcore/intrinsics.rs

+1-39
Original file line numberDiff line numberDiff line change
@@ -1027,46 +1027,8 @@ extern "rust-intrinsic" {
10271027
#[rustc_const_unstable(feature = "const_caller_location", issue = "47809")]
10281028
pub fn caller_location() -> &'static crate::panic::Location<'static>;
10291029

1030-
/// Creates a value initialized to zero.
1031-
///
1032-
/// `init` is unsafe because it returns a zeroed-out datum,
1033-
/// which is unsafe unless `T` is `Copy`. Also, even if T is
1034-
/// `Copy`, an all-zero value may not correspond to any legitimate
1035-
/// state for the type in question.
1036-
///
1037-
/// The stabilized version of this intrinsic is
1038-
/// [`std::mem::zeroed`](../../std/mem/fn.zeroed.html).
1039-
#[unstable(
1040-
feature = "core_intrinsics",
1041-
reason = "intrinsics are unlikely to ever be stabilized, instead \
1042-
they should be used through stabilized interfaces \
1043-
in the rest of the standard library",
1044-
issue = "none"
1045-
)]
1046-
#[rustc_deprecated(reason = "superseded by MaybeUninit, removal planned", since = "1.38.0")]
1047-
pub fn init<T>() -> T;
1048-
1049-
/// Creates an uninitialized value.
1050-
///
1051-
/// `uninit` is unsafe because there is no guarantee of what its
1052-
/// contents are. In particular its drop-flag may be set to any
1053-
/// state, which means it may claim either dropped or
1054-
/// undropped. In the general case one must use `ptr::write` to
1055-
/// initialize memory previous set to the result of `uninit`.
1056-
///
1057-
/// The stabilized version of this intrinsic is
1058-
/// [`std::mem::MaybeUninit`](../../std/mem/union.MaybeUninit.html).
1059-
#[unstable(
1060-
feature = "core_intrinsics",
1061-
reason = "intrinsics are unlikely to ever be stabilized, instead \
1062-
they should be used through stabilized interfaces \
1063-
in the rest of the standard library",
1064-
issue = "none"
1065-
)]
1066-
#[rustc_deprecated(reason = "superseded by MaybeUninit, removal planned", since = "1.38.0")]
1067-
pub fn uninit<T>() -> T;
1068-
10691030
/// Moves a value out of scope without running drop glue.
1031+
/// This exists solely for `mem::forget_unsized`; normal `forget` uses `ManuallyDrop` instead.
10701032
pub fn forget<T: ?Sized>(_: T);
10711033

10721034
/// Reinterprets the bits of a value of one type as another type.

src/libcore/mem/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ pub const fn needs_drop<T>() -> bool {
490490
///
491491
/// let _x: &i32 = unsafe { mem::zeroed() }; // Undefined behavior!
492492
/// ```
493-
#[inline]
493+
#[inline(always)]
494494
#[stable(feature = "rust1", since = "1.0.0")]
495495
#[allow(deprecated_in_future)]
496496
#[allow(deprecated)]
@@ -500,7 +500,7 @@ pub unsafe fn zeroed<T>() -> T {
500500
intrinsics::assert_zero_valid::<T>();
501501
#[cfg(bootstrap)]
502502
intrinsics::panic_if_uninhabited::<T>();
503-
intrinsics::init()
503+
MaybeUninit::zeroed().assume_init()
504504
}
505505

506506
/// Bypasses Rust's normal memory-initialization checks by pretending to
@@ -525,7 +525,7 @@ pub unsafe fn zeroed<T>() -> T {
525525
/// [uninit]: union.MaybeUninit.html#method.uninit
526526
/// [assume_init]: union.MaybeUninit.html#method.assume_init
527527
/// [inv]: union.MaybeUninit.html#initialization-invariant
528-
#[inline]
528+
#[inline(always)]
529529
#[rustc_deprecated(since = "1.39.0", reason = "use `mem::MaybeUninit` instead")]
530530
#[stable(feature = "rust1", since = "1.0.0")]
531531
#[allow(deprecated_in_future)]
@@ -536,7 +536,7 @@ pub unsafe fn uninitialized<T>() -> T {
536536
intrinsics::assert_uninit_valid::<T>();
537537
#[cfg(bootstrap)]
538538
intrinsics::panic_if_uninhabited::<T>();
539-
intrinsics::uninit()
539+
MaybeUninit::uninit().assume_init()
540540
}
541541

542542
/// Swaps the values at two mutable locations, without deinitializing either one.

src/librustc/ty/mod.rs

+15-12
Original file line numberDiff line numberDiff line change
@@ -554,24 +554,26 @@ bitflags! {
554554
/// Does this have [ConstKind::Placeholder]?
555555
const HAS_CT_PLACEHOLDER = 1 << 8;
556556

557+
/// `true` if there are "names" of regions and so forth
558+
/// that are local to a particular fn/inferctxt
559+
const HAS_FREE_LOCAL_REGIONS = 1 << 9;
560+
557561
/// `true` if there are "names" of types and regions and so forth
558562
/// that are local to a particular fn
559563
const HAS_FREE_LOCAL_NAMES = TypeFlags::HAS_TY_PARAM.bits
560-
| TypeFlags::HAS_RE_PARAM.bits
561564
| TypeFlags::HAS_CT_PARAM.bits
562565
| TypeFlags::HAS_TY_INFER.bits
563-
| TypeFlags::HAS_RE_INFER.bits
564566
| TypeFlags::HAS_CT_INFER.bits
565567
| TypeFlags::HAS_TY_PLACEHOLDER.bits
566-
| TypeFlags::HAS_RE_PLACEHOLDER.bits
567-
| TypeFlags::HAS_CT_PLACEHOLDER.bits;
568+
| TypeFlags::HAS_CT_PLACEHOLDER.bits
569+
| TypeFlags::HAS_FREE_LOCAL_REGIONS.bits;
568570

569571
/// Does this have [Projection] or [UnnormalizedProjection]?
570-
const HAS_TY_PROJECTION = 1 << 9;
572+
const HAS_TY_PROJECTION = 1 << 10;
571573
/// Does this have [Opaque]?
572-
const HAS_TY_OPAQUE = 1 << 10;
574+
const HAS_TY_OPAQUE = 1 << 11;
573575
/// Does this have [ConstKind::Unevaluated]?
574-
const HAS_CT_PROJECTION = 1 << 11;
576+
const HAS_CT_PROJECTION = 1 << 12;
575577

576578
/// Could this type be normalized further?
577579
const HAS_PROJECTION = TypeFlags::HAS_TY_PROJECTION.bits
@@ -580,21 +582,21 @@ bitflags! {
580582

581583
/// Present if the type belongs in a local type context.
582584
/// Set for placeholders and inference variables that are not "Fresh".
583-
const KEEP_IN_LOCAL_TCX = 1 << 12;
585+
const KEEP_IN_LOCAL_TCX = 1 << 13;
584586

585587
/// Is an error type reachable?
586-
const HAS_TY_ERR = 1 << 13;
588+
const HAS_TY_ERR = 1 << 14;
587589

588590
/// Does this have any region that "appears free" in the type?
589591
/// Basically anything but [ReLateBound] and [ReErased].
590-
const HAS_FREE_REGIONS = 1 << 14;
592+
const HAS_FREE_REGIONS = 1 << 15;
591593

592594
/// Does this have any [ReLateBound] regions? Used to check
593595
/// if a global bound is safe to evaluate.
594-
const HAS_RE_LATE_BOUND = 1 << 15;
596+
const HAS_RE_LATE_BOUND = 1 << 16;
595597

596598
/// Does this have any [ReErased] regions?
597-
const HAS_RE_ERASED = 1 << 16;
599+
const HAS_RE_ERASED = 1 << 17;
598600

599601
/// Flags representing the nominal content of a type,
600602
/// computed by FlagsComputation. If you add a new nominal
@@ -608,6 +610,7 @@ bitflags! {
608610
| TypeFlags::HAS_TY_PLACEHOLDER.bits
609611
| TypeFlags::HAS_RE_PLACEHOLDER.bits
610612
| TypeFlags::HAS_CT_PLACEHOLDER.bits
613+
| TypeFlags::HAS_FREE_LOCAL_REGIONS.bits
611614
| TypeFlags::HAS_TY_PROJECTION.bits
612615
| TypeFlags::HAS_TY_OPAQUE.bits
613616
| TypeFlags::HAS_CT_PROJECTION.bits

src/librustc/ty/sty.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -1743,42 +1743,42 @@ impl RegionKind {
17431743
}
17441744
}
17451745

1746-
pub fn keep_in_local_tcx(&self) -> bool {
1747-
if let ty::ReVar(..) = self { true } else { false }
1748-
}
1749-
17501746
pub fn type_flags(&self) -> TypeFlags {
17511747
let mut flags = TypeFlags::empty();
17521748

1753-
if self.keep_in_local_tcx() {
1754-
flags = flags | TypeFlags::KEEP_IN_LOCAL_TCX;
1755-
}
1756-
17571749
match *self {
17581750
ty::ReVar(..) => {
17591751
flags = flags | TypeFlags::HAS_FREE_REGIONS;
1752+
flags = flags | TypeFlags::HAS_FREE_LOCAL_REGIONS;
17601753
flags = flags | TypeFlags::HAS_RE_INFER;
1754+
flags = flags | TypeFlags::KEEP_IN_LOCAL_TCX;
17611755
}
17621756
ty::RePlaceholder(..) => {
17631757
flags = flags | TypeFlags::HAS_FREE_REGIONS;
1758+
flags = flags | TypeFlags::HAS_FREE_LOCAL_REGIONS;
17641759
flags = flags | TypeFlags::HAS_RE_PLACEHOLDER;
17651760
}
1766-
ty::ReLateBound(..) => {
1767-
flags = flags | TypeFlags::HAS_RE_LATE_BOUND;
1768-
}
17691761
ty::ReEarlyBound(..) => {
17701762
flags = flags | TypeFlags::HAS_FREE_REGIONS;
1763+
flags = flags | TypeFlags::HAS_FREE_LOCAL_REGIONS;
17711764
flags = flags | TypeFlags::HAS_RE_PARAM;
17721765
}
1773-
ty::ReEmpty(_) | ty::ReStatic | ty::ReFree { .. } | ty::ReScope { .. } => {
1766+
ty::ReFree { .. } | ty::ReScope { .. } => {
17741767
flags = flags | TypeFlags::HAS_FREE_REGIONS;
1768+
flags = flags | TypeFlags::HAS_FREE_LOCAL_REGIONS;
17751769
}
1776-
ty::ReErased => {
1777-
flags = flags | TypeFlags::HAS_RE_ERASED;
1770+
ty::ReEmpty(_) | ty::ReStatic => {
1771+
flags = flags | TypeFlags::HAS_FREE_REGIONS;
17781772
}
17791773
ty::ReClosureBound(..) => {
17801774
flags = flags | TypeFlags::HAS_FREE_REGIONS;
17811775
}
1776+
ty::ReLateBound(..) => {
1777+
flags = flags | TypeFlags::HAS_RE_LATE_BOUND;
1778+
}
1779+
ty::ReErased => {
1780+
flags = flags | TypeFlags::HAS_RE_ERASED;
1781+
}
17821782
}
17831783

17841784
debug!("type_flags({:?}) = {:?}", self, flags);

0 commit comments

Comments
 (0)