Skip to content

Commit efcb3b3

Browse files
committed
Auto merge of #79128 - m-ou-se:rollup-lzz1dym, r=m-ou-se
Rollup of 9 pull requests Successful merges: - #77939 (Ensure that the source code display is working with DOS backline) - #78138 (Upgrade dlmalloc to version 0.2) - #78967 (Make codegen tests compatible with extra inlining) - #79027 (Limit storage duration of inlined always live locals) - #79077 (document that __rust_alloc is also magic to our LLVM fork) - #79088 (clarify `span_label` documentation) - #79097 (Code block invalid html tag lint) - #79105 (std: Fix test `symlink_hard_link` on Windows) - #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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 10 additions & 8 deletions
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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 39 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 12 additions & 0 deletions
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

Lines changed: 45 additions & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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 {

0 commit comments

Comments
 (0)