Skip to content

Commit

Permalink
Auto merge of rust-lang#79128 - m-ou-se:rollup-lzz1dym, r=m-ou-se
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Nov 17, 2020
2 parents 54508a2 + d6c5c52 commit efcb3b3
Show file tree
Hide file tree
Showing 24 changed files with 223 additions and 45 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -987,9 +987,9 @@ dependencies = [

[[package]]
name = "dlmalloc"
version = "0.1.4"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "35055b1021724f4eb5262eb49130eebff23fc59fc5a14160e05faad8eeb36673"
checksum = "332570860c2edf2d57914987bf9e24835425f75825086b6ba7d1e6a3e4f1f254"
dependencies = [
"compiler_builtins",
"libc",
Expand Down
18 changes: 10 additions & 8 deletions compiler/rustc_errors/src/diagnostic_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,16 +184,18 @@ impl<'a> DiagnosticBuilder<'a> {
self.cancel();
}

/// Adds a span/label to be included in the resulting snippet.
/// Appends a labeled span to the diagnostic.
///
/// This is pushed onto the [`MultiSpan`] that was created when the diagnostic
/// was first built. That means it will be shown together with the original
/// span/label, *not* a span added by one of the `span_{note,warn,help,suggestions}` methods.
/// Labels are used to convey additional context for the diagnostic's primary span. They will
/// be shown together with the original diagnostic's span, *not* with spans added by
/// `span_note`, `span_help`, etc. Therefore, if the primary span is not displayable (because
/// the span is `DUMMY_SP` or the source code isn't found), labels will not be displayed
/// either.
///
/// This span is *not* considered a ["primary span"][`MultiSpan`]; only
/// the `Span` supplied when creating the diagnostic is primary.
///
/// [`MultiSpan`]: ../rustc_span/struct.MultiSpan.html
/// Implementation-wise, the label span is pushed onto the [`MultiSpan`] that was created when
/// the diagnostic was constructed. However, the label span is *not* considered a
/// ["primary span"][`MultiSpan`]; only the `Span` supplied when creating the diagnostic is
/// primary.
pub fn span_label(&mut self, span: Span, label: impl Into<String>) -> &mut Self {
self.0.diagnostic.span_label(span, label);
self
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,9 @@ impl<'tcx> Body<'tcx> {
/// Returns an iterator over all user-defined variables and compiler-generated temporaries (all
/// locals that are neither arguments nor the return place).
#[inline]
pub fn vars_and_temps_iter(&self) -> impl Iterator<Item = Local> + ExactSizeIterator {
pub fn vars_and_temps_iter(
&self,
) -> impl DoubleEndedIterator<Item = Local> + ExactSizeIterator {
let arg_count = self.arg_count;
let local_count = self.local_decls.len();
(arg_count + 1..local_count).map(Local::new)
Expand Down
39 changes: 39 additions & 0 deletions compiler/rustc_mir/src/transform/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ impl Inliner<'tcx> {
tcx: self.tcx,
callsite_span: callsite.source_info.span,
body_span: callee_body.span,
always_live_locals: BitSet::new_filled(callee_body.local_decls.len()),
};

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

// If there are any locals without storage markers, give them storage only for the
// duration of the call.
for local in callee_body.vars_and_temps_iter() {
if integrator.always_live_locals.contains(local) {
let new_local = integrator.map_local(local);
caller_body[callsite.block].statements.push(Statement {
source_info: callsite.source_info,
kind: StatementKind::StorageLive(new_local),
});
}
}
if let Some(block) = callsite.target {
// To avoid repeated O(n) insert, push any new statements to the end and rotate
// the slice once.
let mut n = 0;
for local in callee_body.vars_and_temps_iter().rev() {
if integrator.always_live_locals.contains(local) {
let new_local = integrator.map_local(local);
caller_body[block].statements.push(Statement {
source_info: callsite.source_info,
kind: StatementKind::StorageDead(new_local),
});
n += 1;
}
}
caller_body[block].statements.rotate_right(n);
}

// Insert all of the (mapped) parts of the callee body into the caller.
caller_body.local_decls.extend(
// FIXME(eddyb) make `Range<Local>` iterable so that we can use
Expand Down Expand Up @@ -670,6 +699,7 @@ struct Integrator<'a, 'tcx> {
tcx: TyCtxt<'tcx>,
callsite_span: Span,
body_span: Span,
always_live_locals: BitSet<Local>,
}

impl<'a, 'tcx> Integrator<'a, 'tcx> {
Expand Down Expand Up @@ -759,6 +789,15 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Integrator<'a, 'tcx> {
}
}

fn visit_statement(&mut self, statement: &mut Statement<'tcx>, location: Location) {
if let StatementKind::StorageLive(local) | StatementKind::StorageDead(local) =
statement.kind
{
self.always_live_locals.remove(local);
}
self.super_statement(statement, location);
}

fn visit_terminator(&mut self, terminator: &mut Terminator<'tcx>, loc: Location) {
// Don't try to modify the implicit `_0` access on return (`return` terminators are
// replaced down below anyways).
Expand Down
2 changes: 2 additions & 0 deletions library/alloc/src/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ extern "Rust" {
// (the code expanding that attribute macro generates those functions), or to call
// the default implementations in libstd (`__rdl_alloc` etc. in `library/std/src/alloc.rs`)
// otherwise.
// The rustc fork of LLVM also special-cases these function names to be able to optimize them
// like `malloc`, `realloc`, and `free`, respectively.
#[rustc_allocator]
#[rustc_allocator_nounwind]
fn __rust_alloc(size: usize, align: usize) -> *mut u8;
Expand Down
2 changes: 1 addition & 1 deletion library/std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ features = ['read_core', 'elf', 'macho', 'pe']
rand = "0.7"

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

[target.x86_64-fortanix-unknown-sgx.dependencies]
fortanix-sgx-abi = { version = "0.3.2", features = ['rustc-dep-of-std'] }
Expand Down
3 changes: 3 additions & 0 deletions library/std/src/fs/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1341,6 +1341,9 @@ fn metadata_access_times() {
#[test]
fn symlink_hard_link() {
let tmpdir = tmpdir();
if !got_symlink_permission(&tmpdir) {
return;
};

// Create "file", a file.
check!(fs::File::create(tmpdir.join("file")));
Expand Down
12 changes: 12 additions & 0 deletions library/std/src/sys/sgx/abi/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ pub(crate) unsafe fn rel_ptr_mut<T>(offset: u64) -> *mut T {

extern "C" {
static ENCLAVE_SIZE: usize;
static HEAP_BASE: u64;
static HEAP_SIZE: usize;
}

/// Returns the base memory address of the heap
pub(crate) fn heap_base() -> *const u8 {
unsafe { rel_ptr_mut(HEAP_BASE) }
}

/// Returns the size of the heap
pub(crate) fn heap_size() -> usize {
unsafe { HEAP_SIZE }
}

// Do not remove inline: will result in relocation failure
Expand Down
46 changes: 45 additions & 1 deletion library/std/src/sys/sgx/alloc.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::alloc::{GlobalAlloc, Layout, System};
use crate::ptr;
use crate::sys::sgx::abi::mem as sgx_mem;
use core::sync::atomic::{AtomicBool, Ordering};

use super::waitqueue::SpinMutex;

Expand All @@ -10,7 +13,48 @@ use super::waitqueue::SpinMutex;
// dlmalloc.c from C to Rust.
#[cfg_attr(test, linkage = "available_externally")]
#[export_name = "_ZN16__rust_internals3std3sys3sgx5alloc8DLMALLOCE"]
static DLMALLOC: SpinMutex<dlmalloc::Dlmalloc> = SpinMutex::new(dlmalloc::DLMALLOC_INIT);
static DLMALLOC: SpinMutex<dlmalloc::Dlmalloc<Sgx>> =
SpinMutex::new(dlmalloc::Dlmalloc::new_with_allocator(Sgx {}));

struct Sgx;

unsafe impl dlmalloc::Allocator for Sgx {
/// Allocs system resources
fn alloc(&self, _size: usize) -> (*mut u8, usize, u32) {
static INIT: AtomicBool = AtomicBool::new(false);

// No ordering requirement since this function is protected by the global lock.
if !INIT.swap(true, Ordering::Relaxed) {
(sgx_mem::heap_base() as _, sgx_mem::heap_size(), 0)
} else {
(ptr::null_mut(), 0, 0)
}
}

fn remap(&self, _ptr: *mut u8, _oldsize: usize, _newsize: usize, _can_move: bool) -> *mut u8 {
ptr::null_mut()
}

fn free_part(&self, _ptr: *mut u8, _oldsize: usize, _newsize: usize) -> bool {
false
}

fn free(&self, _ptr: *mut u8, _size: usize) -> bool {
return false;
}

fn can_release_part(&self, _flags: u32) -> bool {
false
}

fn allocates_zeros(&self) -> bool {
false
}

fn page_size(&self) -> usize {
0x1000
}
}

#[stable(feature = "alloc_system_type", since = "1.28.0")]
unsafe impl GlobalAlloc for System {
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sys/wasm/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use crate::alloc::{GlobalAlloc, Layout, System};

static mut DLMALLOC: dlmalloc::Dlmalloc = dlmalloc::DLMALLOC_INIT;
static mut DLMALLOC: dlmalloc::Dlmalloc = dlmalloc::Dlmalloc::new();

#[stable(feature = "alloc_system_type", since = "1.28.0")]
unsafe impl GlobalAlloc for System {
Expand Down
4 changes: 3 additions & 1 deletion src/librustdoc/html/highlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ fn write_header(out: &mut String, class: Option<&str>) {
}

fn write_code(out: &mut String, src: &str) {
Classifier::new(src).highlight(&mut |highlight| {
// This replace allows to fix how the code source with DOS backline characters is displayed.
let src = src.replace("\r\n", "\n");
Classifier::new(&src).highlight(&mut |highlight| {
match highlight {
Highlight::Token { text, class } => string(out, Escape(text), class),
Highlight::EnterSpan { class } => enter_span(out, class),
Expand Down
3 changes: 3 additions & 0 deletions src/librustdoc/html/highlight/fixtures/dos_line.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">foo</span>() {
<span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;foo&quot;</span>);
}
32 changes: 21 additions & 11 deletions src/librustdoc/html/highlight/tests.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
use super::write_code;
use expect_test::expect_file;

#[test]
fn test_html_highlighting() {
let src = include_str!("fixtures/sample.rs");
let html = {
let mut out = String::new();
write_code(&mut out, src);
format!("{}<pre><code>{}</code></pre>\n", STYLE, out)
};
expect_file!["fixtures/sample.html"].assert_eq(&html);
}

const STYLE: &str = r#"
<style>
.kw { color: #8959A8; }
Expand All @@ -23,3 +12,24 @@ const STYLE: &str = r#"
.question-mark { color: #ff9011; }
</style>
"#;

#[test]
fn test_html_highlighting() {
let src = include_str!("fixtures/sample.rs");
let html = {
let mut out = String::new();
write_code(&mut out, src);
format!("{}<pre><code>{}</code></pre>\n", STYLE, out)
};
expect_file!["fixtures/sample.html"].assert_eq(&html);
}

#[test]
fn test_dos_backline() {
let src = "pub fn foo() {\r\n\
println!(\"foo\");\r\n\
}\r\n";
let mut html = String::new();
write_code(&mut html, src);
expect_file!["fixtures/dos_line.html"].assert_eq(&html);
}
7 changes: 5 additions & 2 deletions src/librustdoc/passes/html_tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::core::DocContext;
use crate::fold::DocFolder;
use crate::html::markdown::opts;
use core::ops::Range;
use pulldown_cmark::{Event, Parser};
use pulldown_cmark::{Event, Parser, Tag};
use rustc_session::lint;
use std::iter::Peekable;
use std::str::CharIndices;
Expand Down Expand Up @@ -196,14 +196,17 @@ impl<'a, 'tcx> DocFolder for InvalidHtmlTagsLinter<'a, 'tcx> {

let mut tags = Vec::new();
let mut is_in_comment = None;
let mut in_code_block = false;

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

for (event, range) in p {
match event {
Event::Html(text) | Event::Text(text) => {
Event::Start(Tag::CodeBlock(_)) => in_code_block = true,
Event::Html(text) | Event::Text(text) if !in_code_block => {
extract_tags(&mut tags, &text, range, &mut is_in_comment, &report_diag)
}
Event::End(Tag::CodeBlock(_)) => in_code_block = false,
_ => {}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/codegen/internalize-closures.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// compile-flags: -C no-prepopulate-passes
// compile-flags: -C no-prepopulate-passes -Zmir-opt-level=0

pub fn main() {

Expand Down
20 changes: 14 additions & 6 deletions src/test/codegen/issue-37945.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
// compile-flags: -O
// compile-flags: -O -Zmerge-functions=disabled
// ignore-x86
// ignore-arm
// ignore-emscripten
// ignore-gnux32
// ignore 32-bit platforms (LLVM has a bug with them)

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

#![crate_type = "lib"]

use std::slice::Iter;

// CHECK-LABEL: @is_empty_1
#[no_mangle]
pub fn is_empty_1(xs: Iter<f32>) -> bool {
// CHECK-NOT: icmp eq float* {{.*}}, null
// CHECK-LABEL: @is_empty_1(
// CHECK-NEXT: start:
// CHECK-NEXT: [[A:%.*]] = icmp ne i32* %xs.1, null
// CHECK-NEXT: tail call void @llvm.assume(i1 [[A]])
// CHECK-NEXT: [[B:%.*]] = icmp eq i32* %xs.0, %xs.1
// CHECK-NEXT: ret i1 [[B:%.*]]
{xs}.next().is_none()
}

// CHECK-LABEL: @is_empty_2
#[no_mangle]
pub fn is_empty_2(xs: Iter<f32>) -> bool {
// CHECK-NOT: icmp eq float* {{.*}}, null
// CHECK-LABEL: @is_empty_2
// CHECK-NEXT: start:
// CHECK-NEXT: [[C:%.*]] = icmp ne i32* %xs.1, null
// CHECK-NEXT: tail call void @llvm.assume(i1 [[C]])
// CHECK-NEXT: [[D:%.*]] = icmp eq i32* %xs.0, %xs.1
// CHECK-NEXT: ret i1 [[D:%.*]]
xs.map(|&x| x).next().is_none()
}
4 changes: 2 additions & 2 deletions src/test/codegen/vec-shrink-panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ pub fn shrink_to_fit(vec: &mut Vec<u32>) {

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

// CHECK-LABEL: @issue75636
Expand Down
1 change: 1 addition & 0 deletions src/test/mir-opt/inline/inline_diverging.h.Inline.diff
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
- // mir::Constant
// + span: $DIR/inline-diverging.rs:22:16: 22:21
// + literal: Const { ty: fn() -> ! {sleep}, val: Value(Scalar(<ZST>)) }
+ StorageLive(_6); // scope 0 at $DIR/inline-diverging.rs:22:5: 22:22
+ StorageLive(_3); // scope 1 at $DIR/inline-diverging.rs:22:5: 22:22
+ StorageLive(_4); // scope 1 at $DIR/inline-diverging.rs:22:5: 22:22
+ _4 = &_2; // scope 1 at $DIR/inline-diverging.rs:22:5: 22:22
Expand Down
Loading

0 comments on commit efcb3b3

Please sign in to comment.