Skip to content

Commit 8a6d434

Browse files
committed
Auto merge of #73954 - Manishearth:rollup-8qvh170, r=Manishearth
Rollup of 10 pull requests Successful merges: - #73414 (Implement `slice_strip` feature) - #73564 (linker: Create GNU_EH_FRAME header by default when producing ELFs) - #73622 (Deny unsafe ops in unsafe fns in libcore) - #73684 (add spans to injected coverage counters, extract with CoverageData query) - #73812 (ast_pretty: Pass some token streams and trees by reference) - #73853 (Add newline to rustc MultiSpan docs) - #73883 (Compile rustdoc less often.) - #73885 (Fix wasm32 being broken due to a NodeJS version bump) - #73903 (Changes required for rustc/cargo to build for iOS targets) - #73938 (Optimise fast path of checked_ops with `unlikely`) Failed merges: r? @ghost
2 parents b7856f6 + 4f536f2 commit 8a6d434

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+1790
-630
lines changed

src/bootstrap/builder/tests.rs

+79
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ fn dist_baseline() {
5454
&[dist::Std { compiler: Compiler { host: a, stage: 1 }, target: a },]
5555
);
5656
assert_eq!(first(builder.cache.all::<dist::Src>()), &[dist::Src]);
57+
// Make sure rustdoc is only built once.
58+
assert_eq!(
59+
first(builder.cache.all::<tool::Rustdoc>()),
60+
&[tool::Rustdoc { compiler: Compiler { host: a, stage: 2 } },]
61+
);
5762
}
5863

5964
#[test]
@@ -414,3 +419,77 @@ fn test_exclude() {
414419
// Ensure other tests are not affected.
415420
assert!(builder.cache.contains::<test::RustdocUi>());
416421
}
422+
423+
#[test]
424+
fn doc_default() {
425+
let mut config = configure(&[], &[]);
426+
config.compiler_docs = true;
427+
config.cmd = Subcommand::Doc { paths: Vec::new(), open: false };
428+
let build = Build::new(config);
429+
let mut builder = Builder::new(&build);
430+
builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Doc), &[]);
431+
let a = INTERNER.intern_str("A");
432+
433+
// error_index_generator uses stage 1 to share rustdoc artifacts with the
434+
// rustdoc tool.
435+
assert_eq!(
436+
first(builder.cache.all::<doc::ErrorIndex>()),
437+
&[doc::ErrorIndex { compiler: Compiler { host: a, stage: 1 }, target: a },]
438+
);
439+
assert_eq!(
440+
first(builder.cache.all::<tool::ErrorIndex>()),
441+
&[tool::ErrorIndex { compiler: Compiler { host: a, stage: 1 } }]
442+
);
443+
// This is actually stage 1, but Rustdoc::run swaps out the compiler with
444+
// stage minus 1 if --stage is not 0. Very confusing!
445+
assert_eq!(
446+
first(builder.cache.all::<tool::Rustdoc>()),
447+
&[tool::Rustdoc { compiler: Compiler { host: a, stage: 2 } },]
448+
);
449+
}
450+
451+
#[test]
452+
fn test_docs() {
453+
// Behavior of `x.py test` doing various documentation tests.
454+
let mut config = configure(&[], &[]);
455+
config.cmd = Subcommand::Test {
456+
paths: vec![],
457+
test_args: vec![],
458+
rustc_args: vec![],
459+
fail_fast: true,
460+
doc_tests: DocTests::Yes,
461+
bless: false,
462+
compare_mode: None,
463+
rustfix_coverage: false,
464+
pass: None,
465+
};
466+
let build = Build::new(config);
467+
let mut builder = Builder::new(&build);
468+
builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Test), &[]);
469+
let a = INTERNER.intern_str("A");
470+
471+
// error_index_generator uses stage 1 to share rustdoc artifacts with the
472+
// rustdoc tool.
473+
assert_eq!(
474+
first(builder.cache.all::<doc::ErrorIndex>()),
475+
&[doc::ErrorIndex { compiler: Compiler { host: a, stage: 1 }, target: a },]
476+
);
477+
assert_eq!(
478+
first(builder.cache.all::<tool::ErrorIndex>()),
479+
&[tool::ErrorIndex { compiler: Compiler { host: a, stage: 1 } }]
480+
);
481+
// Unfortunately rustdoc is built twice. Once from stage1 for compiletest
482+
// (and other things), and once from stage0 for std crates. Ideally it
483+
// would only be built once. If someone wants to fix this, it might be
484+
// worth investigating if it would be possible to test std from stage1.
485+
// Note that the stages here are +1 than what they actually are because
486+
// Rustdoc::run swaps out the compiler with stage minus 1 if --stage is
487+
// not 0.
488+
assert_eq!(
489+
first(builder.cache.all::<tool::Rustdoc>()),
490+
&[
491+
tool::Rustdoc { compiler: Compiler { host: a, stage: 1 } },
492+
tool::Rustdoc { compiler: Compiler { host: a, stage: 2 } },
493+
]
494+
);
495+
}

src/bootstrap/doc.rs

+15-16
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,7 @@ impl Step for Rustc {
518518
let out = builder.compiler_doc_out(target);
519519
t!(fs::create_dir_all(&out));
520520

521-
// Get the correct compiler for this stage.
522-
let compiler = builder.compiler_for(stage, builder.config.build, target);
521+
let compiler = builder.compiler(stage, builder.config.build);
523522

524523
if !builder.config.compiler_docs {
525524
builder.info("\tskipping - compiler/librustdoc docs disabled");
@@ -599,8 +598,7 @@ impl Step for Rustdoc {
599598
let out = builder.compiler_doc_out(target);
600599
t!(fs::create_dir_all(&out));
601600

602-
// Get the correct compiler for this stage.
603-
let compiler = builder.compiler_for(stage, builder.config.build, target);
601+
let compiler = builder.compiler(stage, builder.config.build);
604602

605603
if !builder.config.compiler_docs {
606604
builder.info("\tskipping - compiler/librustdoc docs disabled");
@@ -639,9 +637,10 @@ impl Step for Rustdoc {
639637
}
640638
}
641639

642-
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
640+
#[derive(Ord, PartialOrd, Debug, Copy, Clone, Hash, PartialEq, Eq)]
643641
pub struct ErrorIndex {
644-
target: Interned<String>,
642+
pub compiler: Compiler,
643+
pub target: Interned<String>,
645644
}
646645

647646
impl Step for ErrorIndex {
@@ -655,26 +654,26 @@ impl Step for ErrorIndex {
655654
}
656655

657656
fn make_run(run: RunConfig<'_>) {
658-
run.builder.ensure(ErrorIndex { target: run.target });
657+
let target = run.target;
658+
// error_index_generator depends on librustdoc. Use the compiler that
659+
// is normally used to build rustdoc for other documentation so that
660+
// it shares the same artifacts.
661+
let compiler =
662+
run.builder.compiler_for(run.builder.top_stage, run.builder.config.build, target);
663+
run.builder.ensure(ErrorIndex { compiler, target });
659664
}
660665

661666
/// Generates the HTML rendered error-index by running the
662667
/// `error_index_generator` tool.
663668
fn run(self, builder: &Builder<'_>) {
664-
let target = self.target;
665-
666-
builder.info(&format!("Documenting error index ({})", target));
667-
let out = builder.doc_out(target);
669+
builder.info(&format!("Documenting error index ({})", self.target));
670+
let out = builder.doc_out(self.target);
668671
t!(fs::create_dir_all(&out));
669-
let compiler = builder.compiler(2, builder.config.build);
670-
let mut index = tool::ErrorIndex::command(builder, compiler);
672+
let mut index = tool::ErrorIndex::command(builder, self.compiler);
671673
index.arg("html");
672674
index.arg(out.join("error-index.html"));
673675
index.arg(crate::channel::CFG_RELEASE_NUM);
674676

675-
// FIXME: shouldn't have to pass this env var
676-
index.env("CFG_BUILD", &builder.config.build);
677-
678677
builder.run(&mut index);
679678
}
680679
}

src/bootstrap/native.rs

+19
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,17 @@ impl Step for Llvm {
175175
cfg.define("LLVM_ENABLE_ZLIB", "OFF");
176176
}
177177

178+
// Are we compiling for iOS/tvOS?
179+
if target.contains("apple-ios") || target.contains("apple-tvos") {
180+
// These two defines prevent CMake from automatically trying to add a MacOSX sysroot, which leads to a compiler error.
181+
cfg.define("CMAKE_OSX_SYSROOT", "/");
182+
cfg.define("CMAKE_OSX_DEPLOYMENT_TARGET", "");
183+
// Prevent cmake from adding -bundle to CFLAGS automatically, which leads to a compiler error because "-bitcode_bundle" also gets added.
184+
cfg.define("LLVM_ENABLE_PLUGINS", "OFF");
185+
// Zlib fails to link properly, leading to a compiler error.
186+
cfg.define("LLVM_ENABLE_ZLIB", "OFF");
187+
}
188+
178189
if builder.config.llvm_thin_lto {
179190
cfg.define("LLVM_ENABLE_LTO", "Thin");
180191
if !target.contains("apple") {
@@ -412,6 +423,14 @@ fn configure_cmake(
412423
if let Some(ref s) = builder.config.llvm_cflags {
413424
cflags.push_str(&format!(" {}", s));
414425
}
426+
// Some compiler features used by LLVM (such as thread locals) will not work on a min version below iOS 10.
427+
if target.contains("apple-ios") {
428+
if target.contains("86-") {
429+
cflags.push_str(" -miphonesimulator-version-min=10.0");
430+
} else {
431+
cflags.push_str(" -miphoneos-version-min=10.0");
432+
}
433+
}
415434
cfg.define("CMAKE_C_FLAGS", cflags);
416435
let mut cxxflags = builder.cflags(target, GitRepo::Llvm).join(" ");
417436
if builder.config.llvm_static_stdcpp && !target.contains("msvc") && !target.contains("netbsd") {

src/bootstrap/test.rs

+47-13
Original file line numberDiff line numberDiff line change
@@ -1454,8 +1454,11 @@ impl Step for ErrorIndex {
14541454
}
14551455

14561456
fn make_run(run: RunConfig<'_>) {
1457-
run.builder
1458-
.ensure(ErrorIndex { compiler: run.builder.compiler(run.builder.top_stage, run.host) });
1457+
// error_index_generator depends on librustdoc. Use the compiler that
1458+
// is normally used to build rustdoc for other tests (like compiletest
1459+
// tests in src/test/rustdoc) so that it shares the same artifacts.
1460+
let compiler = run.builder.compiler_for(run.builder.top_stage, run.host, run.host);
1461+
run.builder.ensure(ErrorIndex { compiler });
14591462
}
14601463

14611464
/// Runs the error index generator tool to execute the tests located in the error
@@ -1467,22 +1470,23 @@ impl Step for ErrorIndex {
14671470
fn run(self, builder: &Builder<'_>) {
14681471
let compiler = self.compiler;
14691472

1470-
builder.ensure(compile::Std { compiler, target: compiler.host });
1471-
14721473
let dir = testdir(builder, compiler.host);
14731474
t!(fs::create_dir_all(&dir));
14741475
let output = dir.join("error-index.md");
14751476

1476-
let mut tool = tool::ErrorIndex::command(
1477-
builder,
1478-
builder.compiler(compiler.stage, builder.config.build),
1479-
);
1480-
tool.arg("markdown").arg(&output).env("CFG_BUILD", &builder.config.build);
1477+
let mut tool = tool::ErrorIndex::command(builder, compiler);
1478+
tool.arg("markdown").arg(&output);
14811479

1482-
builder.info(&format!("Testing error-index stage{}", compiler.stage));
1480+
// Use the rustdoc that was built by self.compiler. This copy of
1481+
// rustdoc is shared with other tests (like compiletest tests in
1482+
// src/test/rustdoc). This helps avoid building rustdoc multiple
1483+
// times.
1484+
let rustdoc_compiler = builder.compiler(builder.top_stage, builder.config.build);
1485+
builder.info(&format!("Testing error-index stage{}", rustdoc_compiler.stage));
14831486
let _time = util::timeit(&builder);
14841487
builder.run_quiet(&mut tool);
1485-
markdown_test(builder, compiler, &output);
1488+
builder.ensure(compile::Std { compiler: rustdoc_compiler, target: rustdoc_compiler.host });
1489+
markdown_test(builder, rustdoc_compiler, &output);
14861490
}
14871491
}
14881492

@@ -1797,9 +1801,13 @@ impl Step for CrateRustdoc {
17971801

17981802
fn run(self, builder: &Builder<'_>) {
17991803
let test_kind = self.test_kind;
1804+
let target = self.host;
18001805

1801-
let compiler = builder.compiler(builder.top_stage, self.host);
1802-
let target = compiler.host;
1806+
// Use the previous stage compiler to reuse the artifacts that are
1807+
// created when running compiletest for src/test/rustdoc. If this used
1808+
// `compiler`, then it would cause rustdoc to be built *again*, which
1809+
// isn't really necessary.
1810+
let compiler = builder.compiler_for(builder.top_stage, target, target);
18031811
builder.ensure(compile::Rustc { compiler, target });
18041812

18051813
let mut cargo = tool::prepare_tool_cargo(
@@ -1825,6 +1833,32 @@ impl Step for CrateRustdoc {
18251833
cargo.arg("'-Ctarget-feature=-crt-static'");
18261834
}
18271835

1836+
// This is needed for running doctests on librustdoc. This is a bit of
1837+
// an unfortunate interaction with how bootstrap works and how cargo
1838+
// sets up the dylib path, and the fact that the doctest (in
1839+
// html/markdown.rs) links to rustc-private libs. For stage1, the
1840+
// compiler host dylibs (in stage1/lib) are not the same as the target
1841+
// dylibs (in stage1/lib/rustlib/...). This is different from a normal
1842+
// rust distribution where they are the same.
1843+
//
1844+
// On the cargo side, normal tests use `target_process` which handles
1845+
// setting up the dylib for a *target* (stage1/lib/rustlib/... in this
1846+
// case). However, for doctests it uses `rustdoc_process` which only
1847+
// sets up the dylib path for the *host* (stage1/lib), which is the
1848+
// wrong directory.
1849+
//
1850+
// It should be considered to just stop running doctests on
1851+
// librustdoc. There is only one test, and it doesn't look too
1852+
// important. There might be other ways to avoid this, but it seems
1853+
// pretty convoluted.
1854+
//
1855+
// See also https://github.com/rust-lang/rust/issues/13983 where the
1856+
// host vs target dylibs for rustdoc are consistently tricky to deal
1857+
// with.
1858+
let mut dylib_path = dylib_path();
1859+
dylib_path.insert(0, PathBuf::from(&*builder.sysroot_libdir(compiler, target)));
1860+
cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
1861+
18281862
if !builder.config.verbose_tests {
18291863
cargo.arg("--quiet");
18301864
}

src/bootstrap/tool.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ bootstrap_tool!(
366366
ExpandYamlAnchors, "src/tools/expand-yaml-anchors", "expand-yaml-anchors";
367367
);
368368

369-
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
369+
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, Ord, PartialOrd)]
370370
pub struct ErrorIndex {
371371
pub compiler: Compiler,
372372
}
@@ -392,9 +392,9 @@ impl Step for ErrorIndex {
392392
fn make_run(run: RunConfig<'_>) {
393393
// Compile the error-index in the same stage as rustdoc to avoid
394394
// recompiling rustdoc twice if we can.
395-
let stage = if run.builder.top_stage >= 2 { run.builder.top_stage } else { 0 };
396-
run.builder
397-
.ensure(ErrorIndex { compiler: run.builder.compiler(stage, run.builder.config.build) });
395+
let host = run.builder.config.build;
396+
let compiler = run.builder.compiler_for(run.builder.top_stage, host, host);
397+
run.builder.ensure(ErrorIndex { compiler });
398398
}
399399

400400
fn run(self, builder: &Builder<'_>) -> PathBuf {
@@ -449,7 +449,7 @@ impl Step for RemoteTestServer {
449449
}
450450
}
451451

452-
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
452+
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, Ord, PartialOrd)]
453453
pub struct Rustdoc {
454454
/// This should only ever be 0 or 2.
455455
/// We sometimes want to reference the "bootstrap" rustdoc, which is why this option is here.

src/ci/docker/wasm32/Dockerfile

+12-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,18 @@ RUN ln `which python3` /usr/bin/python
2525

2626
ENV PATH=$PATH:/emsdk-portable
2727
ENV PATH=$PATH:/emsdk-portable/upstream/emscripten/
28-
ENV PATH=$PATH:/emsdk-portable/node/12.9.1_64bit/bin/
28+
29+
# Rust's build system requires NodeJS to be in the path, but the directory in
30+
# which emsdk stores it contains the version number. This caused breakages in
31+
# the past when emsdk bumped the node version causing the path to point to a
32+
# missing directory.
33+
#
34+
# To avoid the problem this symlinks the latest NodeJs version available to
35+
# "latest", and adds that to the path.
36+
RUN ln -s /emsdk-portable/node/$(ls /emsdk-portable/node | sort -V | tail -n 1) \
37+
/emsdk-portable/node/latest
38+
ENV PATH=$PATH:/emsdk-portable/node/latest/bin/
39+
2940
ENV BINARYEN_ROOT=/emsdk-portable/upstream/
3041
ENV EMSDK=/emsdk-portable
3142
ENV EM_CONFIG=/emsdk-portable/.emscripten

src/libcore/alloc/global.rs

+16-6
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,12 @@ pub unsafe trait GlobalAlloc {
127127
#[stable(feature = "global_alloc", since = "1.28.0")]
128128
unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
129129
let size = layout.size();
130-
let ptr = self.alloc(layout);
130+
// SAFETY: the safety contract for `alloc` must be upheld by the caller.
131+
let ptr = unsafe { self.alloc(layout) };
131132
if !ptr.is_null() {
132-
ptr::write_bytes(ptr, 0, size);
133+
// SAFETY: as allocation succeeded, the region from `ptr`
134+
// of size `size` is guaranteed to be valid for writes.
135+
unsafe { ptr::write_bytes(ptr, 0, size) };
133136
}
134137
ptr
135138
}
@@ -187,11 +190,18 @@ pub unsafe trait GlobalAlloc {
187190
/// [`handle_alloc_error`]: ../../alloc/alloc/fn.handle_alloc_error.html
188191
#[stable(feature = "global_alloc", since = "1.28.0")]
189192
unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
190-
let new_layout = Layout::from_size_align_unchecked(new_size, layout.align());
191-
let new_ptr = self.alloc(new_layout);
193+
// SAFETY: the caller must ensure that the `new_size` does not overflow.
194+
// `layout.align()` comes from a `Layout` and is thus guaranteed to be valid.
195+
let new_layout = unsafe { Layout::from_size_align_unchecked(new_size, layout.align()) };
196+
// SAFETY: the caller must ensure that `new_layout` is greater than zero.
197+
let new_ptr = unsafe { self.alloc(new_layout) };
192198
if !new_ptr.is_null() {
193-
ptr::copy_nonoverlapping(ptr, new_ptr, cmp::min(layout.size(), new_size));
194-
self.dealloc(ptr, layout);
199+
// SAFETY: the previously allocated block cannot overlap the newly allocated block.
200+
// The safety contract for `dealloc` must be upheld by the caller.
201+
unsafe {
202+
ptr::copy_nonoverlapping(ptr, new_ptr, cmp::min(layout.size(), new_size));
203+
self.dealloc(ptr, layout);
204+
}
195205
}
196206
new_ptr
197207
}

src/libcore/alloc/layout.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ impl Layout {
9090
#[rustc_const_stable(feature = "alloc_layout", since = "1.28.0")]
9191
#[inline]
9292
pub const unsafe fn from_size_align_unchecked(size: usize, align: usize) -> Self {
93-
Layout { size_: size, align_: NonZeroUsize::new_unchecked(align) }
93+
// SAFETY: the caller must ensure that `align` is greater than zero.
94+
Layout { size_: size, align_: unsafe { NonZeroUsize::new_unchecked(align) } }
9495
}
9596

9697
/// The minimum size in bytes for a memory block of this layout.

0 commit comments

Comments
 (0)