Skip to content

Commit efcb3b3

Browse files
committed
Auto merge of rust-lang#79128 - m-ou-se:rollup-lzz1dym, r=m-ou-se
Rollup of 9 pull requests Successful merges: - rust-lang#77939 (Ensure that the source code display is working with DOS backline) - rust-lang#78138 (Upgrade dlmalloc to version 0.2) - rust-lang#78967 (Make codegen tests compatible with extra inlining) - rust-lang#79027 (Limit storage duration of inlined always live locals) - rust-lang#79077 (document that __rust_alloc is also magic to our LLVM fork) - rust-lang#79088 (clarify `span_label` documentation) - rust-lang#79097 (Code block invalid html tag lint) - rust-lang#79105 (std: Fix test `symlink_hard_link` on Windows) - rust-lang#79107 (build-manifest: strip newline from rustc version) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 54508a2 + d6c5c52 commit efcb3b3

File tree

24 files changed

+223
-45
lines changed

24 files changed

+223
-45
lines changed

Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -987,9 +987,9 @@ dependencies = [
987987

988988
[[package]]
989989
name = "dlmalloc"
990-
version = "0.1.4"
990+
version = "0.2.1"
991991
source = "registry+https://github.com/rust-lang/crates.io-index"
992-
checksum = "35055b1021724f4eb5262eb49130eebff23fc59fc5a14160e05faad8eeb36673"
992+
checksum = "332570860c2edf2d57914987bf9e24835425f75825086b6ba7d1e6a3e4f1f254"
993993
dependencies = [
994994
"compiler_builtins",
995995
"libc",

compiler/rustc_errors/src/diagnostic_builder.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -184,16 +184,18 @@ impl<'a> DiagnosticBuilder<'a> {
184184
self.cancel();
185185
}
186186

187-
/// Adds a span/label to be included in the resulting snippet.
187+
/// Appends a labeled span to the diagnostic.
188188
///
189-
/// This is pushed onto the [`MultiSpan`] that was created when the diagnostic
190-
/// was first built. That means it will be shown together with the original
191-
/// span/label, *not* a span added by one of the `span_{note,warn,help,suggestions}` methods.
189+
/// Labels are used to convey additional context for the diagnostic's primary span. They will
190+
/// be shown together with the original diagnostic's span, *not* with spans added by
191+
/// `span_note`, `span_help`, etc. Therefore, if the primary span is not displayable (because
192+
/// the span is `DUMMY_SP` or the source code isn't found), labels will not be displayed
193+
/// either.
192194
///
193-
/// This span is *not* considered a ["primary span"][`MultiSpan`]; only
194-
/// the `Span` supplied when creating the diagnostic is primary.
195-
///
196-
/// [`MultiSpan`]: ../rustc_span/struct.MultiSpan.html
195+
/// Implementation-wise, the label span is pushed onto the [`MultiSpan`] that was created when
196+
/// the diagnostic was constructed. However, the label span is *not* considered a
197+
/// ["primary span"][`MultiSpan`]; only the `Span` supplied when creating the diagnostic is
198+
/// primary.
197199
pub fn span_label(&mut self, span: Span, label: impl Into<String>) -> &mut Self {
198200
self.0.diagnostic.span_label(span, label);
199201
self

compiler/rustc_middle/src/mir/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,9 @@ impl<'tcx> Body<'tcx> {
420420
/// Returns an iterator over all user-defined variables and compiler-generated temporaries (all
421421
/// locals that are neither arguments nor the return place).
422422
#[inline]
423-
pub fn vars_and_temps_iter(&self) -> impl Iterator<Item = Local> + ExactSizeIterator {
423+
pub fn vars_and_temps_iter(
424+
&self,
425+
) -> impl DoubleEndedIterator<Item = Local> + ExactSizeIterator {
424426
let arg_count = self.arg_count;
425427
let local_count = self.local_decls.len();
426428
(arg_count + 1..local_count).map(Local::new)

compiler/rustc_mir/src/transform/inline.rs

+39
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,7 @@ impl Inliner<'tcx> {
459459
tcx: self.tcx,
460460
callsite_span: callsite.source_info.span,
461461
body_span: callee_body.span,
462+
always_live_locals: BitSet::new_filled(callee_body.local_decls.len()),
462463
};
463464

464465
// Map all `Local`s, `SourceScope`s and `BasicBlock`s to new ones
@@ -490,6 +491,34 @@ impl Inliner<'tcx> {
490491
}
491492
}
492493

494+
// If there are any locals without storage markers, give them storage only for the
495+
// duration of the call.
496+
for local in callee_body.vars_and_temps_iter() {
497+
if integrator.always_live_locals.contains(local) {
498+
let new_local = integrator.map_local(local);
499+
caller_body[callsite.block].statements.push(Statement {
500+
source_info: callsite.source_info,
501+
kind: StatementKind::StorageLive(new_local),
502+
});
503+
}
504+
}
505+
if let Some(block) = callsite.target {
506+
// To avoid repeated O(n) insert, push any new statements to the end and rotate
507+
// the slice once.
508+
let mut n = 0;
509+
for local in callee_body.vars_and_temps_iter().rev() {
510+
if integrator.always_live_locals.contains(local) {
511+
let new_local = integrator.map_local(local);
512+
caller_body[block].statements.push(Statement {
513+
source_info: callsite.source_info,
514+
kind: StatementKind::StorageDead(new_local),
515+
});
516+
n += 1;
517+
}
518+
}
519+
caller_body[block].statements.rotate_right(n);
520+
}
521+
493522
// Insert all of the (mapped) parts of the callee body into the caller.
494523
caller_body.local_decls.extend(
495524
// FIXME(eddyb) make `Range<Local>` iterable so that we can use
@@ -670,6 +699,7 @@ struct Integrator<'a, 'tcx> {
670699
tcx: TyCtxt<'tcx>,
671700
callsite_span: Span,
672701
body_span: Span,
702+
always_live_locals: BitSet<Local>,
673703
}
674704

675705
impl<'a, 'tcx> Integrator<'a, 'tcx> {
@@ -759,6 +789,15 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Integrator<'a, 'tcx> {
759789
}
760790
}
761791

792+
fn visit_statement(&mut self, statement: &mut Statement<'tcx>, location: Location) {
793+
if let StatementKind::StorageLive(local) | StatementKind::StorageDead(local) =
794+
statement.kind
795+
{
796+
self.always_live_locals.remove(local);
797+
}
798+
self.super_statement(statement, location);
799+
}
800+
762801
fn visit_terminator(&mut self, terminator: &mut Terminator<'tcx>, loc: Location) {
763802
// Don't try to modify the implicit `_0` access on return (`return` terminators are
764803
// replaced down below anyways).

library/alloc/src/alloc.rs

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ extern "Rust" {
2323
// (the code expanding that attribute macro generates those functions), or to call
2424
// the default implementations in libstd (`__rdl_alloc` etc. in `library/std/src/alloc.rs`)
2525
// otherwise.
26+
// The rustc fork of LLVM also special-cases these function names to be able to optimize them
27+
// like `malloc`, `realloc`, and `free`, respectively.
2628
#[rustc_allocator]
2729
#[rustc_allocator_nounwind]
2830
fn __rust_alloc(size: usize, align: usize) -> *mut u8;

library/std/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ features = ['read_core', 'elf', 'macho', 'pe']
3636
rand = "0.7"
3737

3838
[target.'cfg(any(all(target_arch = "wasm32", not(target_os = "emscripten")), all(target_vendor = "fortanix", target_env = "sgx")))'.dependencies]
39-
dlmalloc = { version = "0.1", features = ['rustc-dep-of-std'] }
39+
dlmalloc = { version = "0.2.1", features = ['rustc-dep-of-std'] }
4040

4141
[target.x86_64-fortanix-unknown-sgx.dependencies]
4242
fortanix-sgx-abi = { version = "0.3.2", features = ['rustc-dep-of-std'] }

library/std/src/fs/tests.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1341,6 +1341,9 @@ fn metadata_access_times() {
13411341
#[test]
13421342
fn symlink_hard_link() {
13431343
let tmpdir = tmpdir();
1344+
if !got_symlink_permission(&tmpdir) {
1345+
return;
1346+
};
13441347

13451348
// Create "file", a file.
13461349
check!(fs::File::create(tmpdir.join("file")));

library/std/src/sys/sgx/abi/mem.rs

+12
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ pub(crate) unsafe fn rel_ptr_mut<T>(offset: u64) -> *mut T {
1212

1313
extern "C" {
1414
static ENCLAVE_SIZE: usize;
15+
static HEAP_BASE: u64;
16+
static HEAP_SIZE: usize;
17+
}
18+
19+
/// Returns the base memory address of the heap
20+
pub(crate) fn heap_base() -> *const u8 {
21+
unsafe { rel_ptr_mut(HEAP_BASE) }
22+
}
23+
24+
/// Returns the size of the heap
25+
pub(crate) fn heap_size() -> usize {
26+
unsafe { HEAP_SIZE }
1527
}
1628

1729
// Do not remove inline: will result in relocation failure

library/std/src/sys/sgx/alloc.rs

+45-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
use crate::alloc::{GlobalAlloc, Layout, System};
2+
use crate::ptr;
3+
use crate::sys::sgx::abi::mem as sgx_mem;
4+
use core::sync::atomic::{AtomicBool, Ordering};
25

36
use super::waitqueue::SpinMutex;
47

@@ -10,7 +13,48 @@ use super::waitqueue::SpinMutex;
1013
// dlmalloc.c from C to Rust.
1114
#[cfg_attr(test, linkage = "available_externally")]
1215
#[export_name = "_ZN16__rust_internals3std3sys3sgx5alloc8DLMALLOCE"]
13-
static DLMALLOC: SpinMutex<dlmalloc::Dlmalloc> = SpinMutex::new(dlmalloc::DLMALLOC_INIT);
16+
static DLMALLOC: SpinMutex<dlmalloc::Dlmalloc<Sgx>> =
17+
SpinMutex::new(dlmalloc::Dlmalloc::new_with_allocator(Sgx {}));
18+
19+
struct Sgx;
20+
21+
unsafe impl dlmalloc::Allocator for Sgx {
22+
/// Allocs system resources
23+
fn alloc(&self, _size: usize) -> (*mut u8, usize, u32) {
24+
static INIT: AtomicBool = AtomicBool::new(false);
25+
26+
// No ordering requirement since this function is protected by the global lock.
27+
if !INIT.swap(true, Ordering::Relaxed) {
28+
(sgx_mem::heap_base() as _, sgx_mem::heap_size(), 0)
29+
} else {
30+
(ptr::null_mut(), 0, 0)
31+
}
32+
}
33+
34+
fn remap(&self, _ptr: *mut u8, _oldsize: usize, _newsize: usize, _can_move: bool) -> *mut u8 {
35+
ptr::null_mut()
36+
}
37+
38+
fn free_part(&self, _ptr: *mut u8, _oldsize: usize, _newsize: usize) -> bool {
39+
false
40+
}
41+
42+
fn free(&self, _ptr: *mut u8, _size: usize) -> bool {
43+
return false;
44+
}
45+
46+
fn can_release_part(&self, _flags: u32) -> bool {
47+
false
48+
}
49+
50+
fn allocates_zeros(&self) -> bool {
51+
false
52+
}
53+
54+
fn page_size(&self) -> usize {
55+
0x1000
56+
}
57+
}
1458

1559
#[stable(feature = "alloc_system_type", since = "1.28.0")]
1660
unsafe impl GlobalAlloc for System {

library/std/src/sys/wasm/alloc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
1919
use crate::alloc::{GlobalAlloc, Layout, System};
2020

21-
static mut DLMALLOC: dlmalloc::Dlmalloc = dlmalloc::DLMALLOC_INIT;
21+
static mut DLMALLOC: dlmalloc::Dlmalloc = dlmalloc::Dlmalloc::new();
2222

2323
#[stable(feature = "alloc_system_type", since = "1.28.0")]
2424
unsafe impl GlobalAlloc for System {

src/librustdoc/html/highlight.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ fn write_header(out: &mut String, class: Option<&str>) {
4646
}
4747

4848
fn write_code(out: &mut String, src: &str) {
49-
Classifier::new(src).highlight(&mut |highlight| {
49+
// This replace allows to fix how the code source with DOS backline characters is displayed.
50+
let src = src.replace("\r\n", "\n");
51+
Classifier::new(&src).highlight(&mut |highlight| {
5052
match highlight {
5153
Highlight::Token { text, class } => string(out, Escape(text), class),
5254
Highlight::EnterSpan { class } => enter_span(out, class),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">foo</span>() {
2+
<span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;foo&quot;</span>);
3+
}
+21-11
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
11
use super::write_code;
22
use expect_test::expect_file;
33

4-
#[test]
5-
fn test_html_highlighting() {
6-
let src = include_str!("fixtures/sample.rs");
7-
let html = {
8-
let mut out = String::new();
9-
write_code(&mut out, src);
10-
format!("{}<pre><code>{}</code></pre>\n", STYLE, out)
11-
};
12-
expect_file!["fixtures/sample.html"].assert_eq(&html);
13-
}
14-
154
const STYLE: &str = r#"
165
<style>
176
.kw { color: #8959A8; }
@@ -23,3 +12,24 @@ const STYLE: &str = r#"
2312
.question-mark { color: #ff9011; }
2413
</style>
2514
"#;
15+
16+
#[test]
17+
fn test_html_highlighting() {
18+
let src = include_str!("fixtures/sample.rs");
19+
let html = {
20+
let mut out = String::new();
21+
write_code(&mut out, src);
22+
format!("{}<pre><code>{}</code></pre>\n", STYLE, out)
23+
};
24+
expect_file!["fixtures/sample.html"].assert_eq(&html);
25+
}
26+
27+
#[test]
28+
fn test_dos_backline() {
29+
let src = "pub fn foo() {\r\n\
30+
println!(\"foo\");\r\n\
31+
}\r\n";
32+
let mut html = String::new();
33+
write_code(&mut html, src);
34+
expect_file!["fixtures/dos_line.html"].assert_eq(&html);
35+
}

src/librustdoc/passes/html_tags.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::core::DocContext;
44
use crate::fold::DocFolder;
55
use crate::html::markdown::opts;
66
use core::ops::Range;
7-
use pulldown_cmark::{Event, Parser};
7+
use pulldown_cmark::{Event, Parser, Tag};
88
use rustc_session::lint;
99
use std::iter::Peekable;
1010
use std::str::CharIndices;
@@ -196,14 +196,17 @@ impl<'a, 'tcx> DocFolder for InvalidHtmlTagsLinter<'a, 'tcx> {
196196

197197
let mut tags = Vec::new();
198198
let mut is_in_comment = None;
199+
let mut in_code_block = false;
199200

200201
let p = Parser::new_ext(&dox, opts()).into_offset_iter();
201202

202203
for (event, range) in p {
203204
match event {
204-
Event::Html(text) | Event::Text(text) => {
205+
Event::Start(Tag::CodeBlock(_)) => in_code_block = true,
206+
Event::Html(text) | Event::Text(text) if !in_code_block => {
205207
extract_tags(&mut tags, &text, range, &mut is_in_comment, &report_diag)
206208
}
209+
Event::End(Tag::CodeBlock(_)) => in_code_block = false,
207210
_ => {}
208211
}
209212
}

src/test/codegen/internalize-closures.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// compile-flags: -C no-prepopulate-passes
1+
// compile-flags: -C no-prepopulate-passes -Zmir-opt-level=0
22

33
pub fn main() {
44

src/test/codegen/issue-37945.rs

+14-6
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,34 @@
1-
// compile-flags: -O
1+
// compile-flags: -O -Zmerge-functions=disabled
22
// ignore-x86
33
// ignore-arm
44
// ignore-emscripten
55
// ignore-gnux32
66
// ignore 32-bit platforms (LLVM has a bug with them)
77

8-
// See issue #37945.
8+
// Check that LLVM understands that `Iter` pointer is not null. Issue #37945.
99

1010
#![crate_type = "lib"]
1111

1212
use std::slice::Iter;
1313

14-
// CHECK-LABEL: @is_empty_1
1514
#[no_mangle]
1615
pub fn is_empty_1(xs: Iter<f32>) -> bool {
17-
// CHECK-NOT: icmp eq float* {{.*}}, null
16+
// CHECK-LABEL: @is_empty_1(
17+
// CHECK-NEXT: start:
18+
// CHECK-NEXT: [[A:%.*]] = icmp ne i32* %xs.1, null
19+
// CHECK-NEXT: tail call void @llvm.assume(i1 [[A]])
20+
// CHECK-NEXT: [[B:%.*]] = icmp eq i32* %xs.0, %xs.1
21+
// CHECK-NEXT: ret i1 [[B:%.*]]
1822
{xs}.next().is_none()
1923
}
2024

21-
// CHECK-LABEL: @is_empty_2
2225
#[no_mangle]
2326
pub fn is_empty_2(xs: Iter<f32>) -> bool {
24-
// CHECK-NOT: icmp eq float* {{.*}}, null
27+
// CHECK-LABEL: @is_empty_2
28+
// CHECK-NEXT: start:
29+
// CHECK-NEXT: [[C:%.*]] = icmp ne i32* %xs.1, null
30+
// CHECK-NEXT: tail call void @llvm.assume(i1 [[C]])
31+
// CHECK-NEXT: [[D:%.*]] = icmp eq i32* %xs.0, %xs.1
32+
// CHECK-NEXT: ret i1 [[D:%.*]]
2533
xs.map(|&x| x).next().is_none()
2634
}

src/test/codegen/vec-shrink-panic.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ pub fn shrink_to_fit(vec: &mut Vec<u32>) {
1515

1616
// CHECK-LABEL: @issue71861
1717
#[no_mangle]
18-
pub fn issue71861(n: usize) -> Box<[u32]> {
18+
pub fn issue71861(vec: Vec<u32>) -> Box<[u32]> {
1919
// CHECK-NOT: panic
20-
vec![0; n].into_boxed_slice()
20+
vec.into_boxed_slice()
2121
}
2222

2323
// CHECK-LABEL: @issue75636

src/test/mir-opt/inline/inline_diverging.h.Inline.diff

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
- // mir::Constant
4141
// + span: $DIR/inline-diverging.rs:22:16: 22:21
4242
// + literal: Const { ty: fn() -> ! {sleep}, val: Value(Scalar(<ZST>)) }
43+
+ StorageLive(_6); // scope 0 at $DIR/inline-diverging.rs:22:5: 22:22
4344
+ StorageLive(_3); // scope 1 at $DIR/inline-diverging.rs:22:5: 22:22
4445
+ StorageLive(_4); // scope 1 at $DIR/inline-diverging.rs:22:5: 22:22
4546
+ _4 = &_2; // scope 1 at $DIR/inline-diverging.rs:22:5: 22:22

0 commit comments

Comments
 (0)