Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 7 pull requests #70016

Merged
merged 20 commits into from
Mar 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
54d1c50
Remove `sip::Hasher::short_write`.
nnethercote Feb 25, 2020
e1a5472
Emit 1-based column numbers in debuginfo
tmiasko Feb 21, 2020
0c51f2f
Use byte offsets when emitting debuginfo columns
tmiasko Feb 25, 2020
8e93a01
Test that column information is not emitted for MSVC targets
tmiasko Feb 25, 2020
c8b527e
change method -> associated function
mark-i-m Feb 26, 2020
b6518f0
update tests
mark-i-m Mar 5, 2020
4b46271
Remove a couple of Rc's from RegionInferenceContext
mark-i-m Mar 13, 2020
508d4a2
Remove another Rc from RegionInferenceContext
mark-i-m Mar 13, 2020
da4e33a
move frozen to rustc_data_structures
mark-i-m Mar 13, 2020
a58b17f
update rustdocs for frozen
mark-i-m Mar 13, 2020
40ffcc2
Add self to .mailmap
kraai Mar 13, 2020
47f6d63
fix E0117 message out of sync
contrun Mar 14, 2020
1c88052
Add long error explanation for E0693 #61137
Mar 14, 2020
62c0579
Rollup merge of #69357 - tmiasko:debuginfo-column, r=michaelwoerister
Dylan-DPC Mar 15, 2020
0619e46
Rollup merge of #69471 - nnethercote:rm-sip-Hasher-short_write, r=dto…
Dylan-DPC Mar 15, 2020
f40272c
Rollup merge of #69498 - mark-i-m:describe-it-2, r=matthewjasper
Dylan-DPC Mar 15, 2020
bf6e715
Rollup merge of #69967 - mark-i-m:rinfctx, r=matthewjasper
Dylan-DPC Mar 15, 2020
65f56da
Rollup merge of #69987 - kraai:mailmap, r=nikomatsakis
Dylan-DPC Mar 15, 2020
191a796
Rollup merge of #69991 - contrun:fix-69980, r=Dylan-DPC
Dylan-DPC Mar 15, 2020
838884e
Rollup merge of #69993 - ayushmishra2005:doc/61137-add-long-error-cod…
Dylan-DPC Mar 15, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ Mateusz Mikuła <matti@marinelayer.io> <mati865@gmail.com>
Mateusz Mikuła <matti@marinelayer.io> <mati865@users.noreply.github.com>
Matt Brubeck <mbrubeck@limpet.net> <mbrubeck@cs.hmc.edu>
Matthew Auld <matthew.auld@intel.com>
Matthew Kraai <kraai@ftbfs.org>
Matthew Kraai <kraai@ftbfs.org> <matt.kraai@abbott.com>
Matthew Kraai <kraai@ftbfs.org> <mkraai@its.jnj.com>
Matthew McPherrin <matthew@mcpherrin.ca> <matt@mcpherrin.ca>
Matthijs Hofstra <thiezz@gmail.com>
Melody Horn <melody@boringcactus.com> <mathphreak@gmail.com>
Expand Down
53 changes: 7 additions & 46 deletions src/libcore/hash/sip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,37 +220,6 @@ impl<S: Sip> Hasher<S> {
self.state.v3 = self.k1 ^ 0x7465646279746573;
self.ntail = 0;
}

// Specialized write function that is only valid for buffers with len <= 8.
// It's used to force inlining of write_u8 and write_usize, those would normally be inlined
// except for composite types (that includes slices and str hashing because of delimiter).
// Without this extra push the compiler is very reluctant to inline delimiter writes,
// degrading performance substantially for the most common use cases.
#[inline]
fn short_write(&mut self, msg: &[u8]) {
debug_assert!(msg.len() <= 8);
let length = msg.len();
self.length += length;

let needed = 8 - self.ntail;
let fill = cmp::min(length, needed);
if fill == 8 {
self.tail = unsafe { load_int_le!(msg, 0, u64) };
} else {
self.tail |= unsafe { u8to64_le(msg, 0, fill) } << (8 * self.ntail);
if length < needed {
self.ntail += length;
return;
}
}
self.state.v3 ^= self.tail;
S::c_rounds(&mut self.state);
self.state.v0 ^= self.tail;

// Buffered tail is now flushed, process new input.
self.ntail = length - needed;
self.tail = unsafe { u8to64_le(msg, needed, self.ntail) };
}
}

#[stable(feature = "rust1", since = "1.0.0")]
Expand Down Expand Up @@ -280,21 +249,13 @@ impl super::Hasher for SipHasher13 {
}

impl<S: Sip> super::Hasher for Hasher<S> {
// see short_write comment for explanation
#[inline]
fn write_usize(&mut self, i: usize) {
let bytes = unsafe {
crate::slice::from_raw_parts(&i as *const usize as *const u8, mem::size_of::<usize>())
};
self.short_write(bytes);
}

// see short_write comment for explanation
#[inline]
fn write_u8(&mut self, i: u8) {
self.short_write(&[i]);
}

// Note: no integer hashing methods (`write_u*`, `write_i*`) are defined
// for this type. We could add them, copy the `short_write` implementation
// in librustc_data_structures/sip128.rs, and add `write_u*`/`write_i*`
// methods to `SipHasher`, `SipHasher13`, and `DefaultHasher`. This would
// greatly speed up integer hashing by those hashers, at the cost of
// slightly slowing down compile speeds on some benchmarks. See #69152 for
// details.
#[inline]
fn write(&mut self, msg: &[u8]) {
let length = msg.len();
Expand Down
16 changes: 6 additions & 10 deletions src/librustc_codegen_llvm/debuginfo/create_scope_map.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
use super::metadata::file_metadata;
use super::utils::{span_start, DIB};
use super::metadata::{file_metadata, UNKNOWN_COLUMN_NUMBER, UNKNOWN_LINE_NUMBER};
use super::utils::DIB;
use rustc_codegen_ssa::mir::debuginfo::{DebugScope, FunctionDebugContext};

use crate::common::CodegenCx;
use crate::llvm;
use crate::llvm::debuginfo::{DIScope, DISubprogram};
use rustc::mir::{Body, SourceScope};

use libc::c_uint;

use rustc_span::Pos;

use rustc_index::bit_set::BitSet;
use rustc_index::vec::Idx;

Expand Down Expand Up @@ -54,7 +50,7 @@ fn make_mir_scope(
debug_context.scopes[parent]
} else {
// The root is the function itself.
let loc = span_start(cx, mir.span);
let loc = cx.lookup_debug_loc(mir.span.lo());
debug_context.scopes[scope] = DebugScope {
scope_metadata: Some(fn_metadata),
file_start_pos: loc.file.start_pos,
Expand All @@ -70,16 +66,16 @@ fn make_mir_scope(
return;
}

let loc = span_start(cx, scope_data.span);
let loc = cx.lookup_debug_loc(scope_data.span.lo());
let file_metadata = file_metadata(cx, &loc.file.name, debug_context.defining_crate);

let scope_metadata = unsafe {
Some(llvm::LLVMRustDIBuilderCreateLexicalBlock(
DIB(cx),
parent_scope.scope_metadata.unwrap(),
file_metadata,
loc.line as c_uint,
loc.col.to_usize() as c_uint,
loc.line.unwrap_or(UNKNOWN_LINE_NUMBER),
loc.col.unwrap_or(UNKNOWN_COLUMN_NUMBER),
))
};
debug_context.scopes[scope] = DebugScope {
Expand Down
10 changes: 5 additions & 5 deletions src/librustc_codegen_llvm/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use self::RecursiveTypeDescription::*;
use super::namespace::mangled_name_of_instance;
use super::type_names::compute_debuginfo_type_name;
use super::utils::{
create_DIArray, debug_context, get_namespace_for_item, is_node_local_to_unit, span_start, DIB,
create_DIArray, debug_context, get_namespace_for_item, is_node_local_to_unit, DIB,
};
use super::CrateDebugContext;

Expand Down Expand Up @@ -2309,10 +2309,10 @@ pub fn create_global_var_metadata(cx: &CodegenCx<'ll, '_>, def_id: DefId, global
let span = tcx.def_span(def_id);

let (file_metadata, line_number) = if !span.is_dummy() {
let loc = span_start(cx, span);
(file_metadata(cx, &loc.file.name, LOCAL_CRATE), loc.line as c_uint)
let loc = cx.lookup_debug_loc(span.lo());
(file_metadata(cx, &loc.file.name, LOCAL_CRATE), loc.line)
} else {
(unknown_file_metadata(cx), UNKNOWN_LINE_NUMBER)
(unknown_file_metadata(cx), None)
};

let is_local_to_unit = is_node_local_to_unit(cx, def_id);
Expand All @@ -2339,7 +2339,7 @@ pub fn create_global_var_metadata(cx: &CodegenCx<'ll, '_>, def_id: DefId, global
linkage_name.as_ptr().cast(),
linkage_name.len(),
file_metadata,
line_number,
line_number.unwrap_or(UNKNOWN_LINE_NUMBER),
type_metadata,
is_local_to_unit,
global,
Expand Down
14 changes: 7 additions & 7 deletions src/librustc_codegen_llvm/debuginfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ mod doc;

use rustc_codegen_ssa::mir::debuginfo::VariableKind::*;

use self::metadata::{file_metadata, type_metadata, TypeMap};
use self::metadata::{file_metadata, type_metadata, TypeMap, UNKNOWN_LINE_NUMBER};
use self::namespace::mangled_name_of_instance;
use self::type_names::compute_debuginfo_type_name;
use self::utils::{create_DIArray, is_node_local_to_unit, span_start, DIB};
use self::utils::{create_DIArray, is_node_local_to_unit, DIB};

use crate::llvm;
use crate::llvm::debuginfo::{
Expand Down Expand Up @@ -248,7 +248,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {

let def_id = instance.def_id();
let containing_scope = get_containing_scope(self, instance);
let loc = span_start(self, span);
let loc = self.lookup_debug_loc(span.lo());
let file_metadata = file_metadata(self, &loc.file.name, def_id.krate);

let function_type_metadata = unsafe {
Expand Down Expand Up @@ -304,9 +304,9 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
linkage_name.as_ptr().cast(),
linkage_name.len(),
file_metadata,
loc.line as c_uint,
loc.line.unwrap_or(UNKNOWN_LINE_NUMBER),
function_type_metadata,
scope_line as c_uint,
scope_line.unwrap_or(UNKNOWN_LINE_NUMBER),
flags,
spflags,
llfn,
Expand Down Expand Up @@ -530,7 +530,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
variable_kind: VariableKind,
span: Span,
) -> &'ll DIVariable {
let loc = span_start(self, span);
let loc = self.lookup_debug_loc(span.lo());
let file_metadata = file_metadata(self, &loc.file.name, dbg_context.defining_crate);

let type_metadata = type_metadata(self, variable_type, span);
Expand All @@ -550,7 +550,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
name.as_ptr().cast(),
name.len(),
file_metadata,
loc.line as c_uint,
loc.line.unwrap_or(UNKNOWN_LINE_NUMBER),
type_metadata,
true,
DIFlags::FlagZero,
Expand Down
52 changes: 39 additions & 13 deletions src/librustc_codegen_llvm/debuginfo/source_loc.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,58 @@
use super::metadata::UNKNOWN_COLUMN_NUMBER;
use super::utils::{debug_context, span_start};
use super::metadata::{UNKNOWN_COLUMN_NUMBER, UNKNOWN_LINE_NUMBER};
use super::utils::debug_context;

use crate::common::CodegenCx;
use crate::llvm::debuginfo::DIScope;
use crate::llvm::{self, Value};
use rustc_codegen_ssa::traits::*;

use libc::c_uint;
use rustc_span::{Pos, Span};
use rustc_data_structures::sync::Lrc;
use rustc_span::{BytePos, Pos, SourceFile, SourceFileAndLine, Span};

/// A source code location used to generate debug information.
pub struct DebugLoc {
/// Information about the original source file.
pub file: Lrc<SourceFile>,
/// The (1-based) line number.
pub line: Option<u32>,
/// The (1-based) column number.
pub col: Option<u32>,
}

impl CodegenCx<'ll, '_> {
pub fn create_debug_loc(&self, scope: &'ll DIScope, span: Span) -> &'ll Value {
let loc = span_start(self, span);
/// Looks up debug source information about a `BytePos`.
pub fn lookup_debug_loc(&self, pos: BytePos) -> DebugLoc {
let (file, line, col) = match self.sess().source_map().lookup_line(pos) {
Ok(SourceFileAndLine { sf: file, line }) => {
let line_pos = file.line_begin_pos(pos);

// Use 1-based indexing.
let line = (line + 1) as u32;
let col = (pos - line_pos).to_u32() + 1;

(file, Some(line), Some(col))
}
Err(file) => (file, None, None),
};

// For MSVC, set the column number to zero.
// For MSVC, omit the column number.
// Otherwise, emit it. This mimics clang behaviour.
// See discussion in https://github.com/rust-lang/rust/issues/42921
let col_used = if self.sess().target.target.options.is_like_msvc {
UNKNOWN_COLUMN_NUMBER
if self.sess().target.target.options.is_like_msvc {
DebugLoc { file, line, col: None }
} else {
loc.col.to_usize() as c_uint
};
DebugLoc { file, line, col }
}
}

pub fn create_debug_loc(&self, scope: &'ll DIScope, span: Span) -> &'ll Value {
let DebugLoc { line, col, .. } = self.lookup_debug_loc(span.lo());

unsafe {
llvm::LLVMRustDIBuilderCreateDebugLocation(
debug_context(self).llcontext,
loc.line as c_uint,
col_used,
line.unwrap_or(UNKNOWN_LINE_NUMBER),
col.unwrap_or(UNKNOWN_COLUMN_NUMBER),
scope,
None,
)
Expand Down
8 changes: 0 additions & 8 deletions src/librustc_codegen_llvm/debuginfo/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ use rustc_hir::def_id::DefId;
use crate::common::CodegenCx;
use crate::llvm;
use crate::llvm::debuginfo::{DIArray, DIBuilder, DIDescriptor, DIScope};
use rustc_codegen_ssa::traits::*;

use rustc_span::Span;

pub fn is_node_local_to_unit(cx: &CodegenCx<'_, '_>, def_id: DefId) -> bool {
// The is_local_to_unit flag indicates whether a function is local to the
Expand All @@ -32,11 +29,6 @@ pub fn create_DIArray(builder: &DIBuilder<'ll>, arr: &[Option<&'ll DIDescriptor>
};
}

/// Returns rustc_span::Loc corresponding to the beginning of the span
pub fn span_start(cx: &CodegenCx<'_, '_>, span: Span) -> rustc_span::Loc {
cx.sess().source_map().lookup_char_pos(span.lo())
}

#[inline]
pub fn debug_context(cx: &'a CodegenCx<'ll, 'tcx>) -> &'a CrateDebugContext<'ll, 'tcx> {
cx.dbg_cx.as_ref().unwrap()
Expand Down
63 changes: 63 additions & 0 deletions src/librustc_data_structures/frozen.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//! An immutable, owned value (except for interior mutability).
//!
//! The purpose of `Frozen` is to make a value immutable for the sake of defensive programming. For example,
//! suppose we have the following:
//!
//! ```rust
//! struct Bar { /* some data */ }
//!
//! struct Foo {
//! /// Some computed data that should never change after construction.
//! pub computed: Bar,
//!
//! /* some other fields */
//! }
//!
//! impl Bar {
//! /// Mutate the `Bar`.
//! pub fn mutate(&mut self) { }
//! }
//! ```
//!
//! Now suppose we want to pass around a mutable `Foo` instance but, we want to make sure that
//! `computed` does not change accidentally (e.g. somebody might accidentally call
//! `foo.computed.mutate()`). This is what `Frozen` is for. We can do the following:
//!
//! ```rust
//! use rustc_data_structures::frozen::Frozen;
//!
//! struct Foo {
//! /// Some computed data that should never change after construction.
//! pub computed: Frozen<Bar>,
//!
//! /* some other fields */
//! }
//! ```
//!
//! `Frozen` impls `Deref`, so we can ergonomically call methods on `Bar`, but it doesn't `impl
//! DerefMut`. Now calling `foo.compute.mutate()` will result in a compile-time error stating that
//! `mutate` requires a mutable reference but we don't have one.
//!
//! # Caveats
//!
//! - `Frozen` doesn't try to defend against interior mutability (e.g. `Frozen<RefCell<Bar>>`).
//! - `Frozen` doesn't pin it's contents (e.g. one could still do `foo.computed =
//! Frozen::freeze(new_bar)`).

/// An owned immutable value.
#[derive(Debug)]
pub struct Frozen<T>(T);

impl<T> Frozen<T> {
pub fn freeze(val: T) -> Self {
Frozen(val)
}
}

impl<T> std::ops::Deref for Frozen<T> {
type Target = T;

fn deref(&self) -> &T {
&self.0
}
}
1 change: 1 addition & 0 deletions src/librustc_data_structures/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ pub mod profiling;
pub mod vec_linked_list;
pub mod work_queue;
pub use atomic_ref::AtomicRef;
pub mod frozen;

pub struct OnDrop<F: Fn()>(pub F);

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_error_codes/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ E0689: include_str!("./error_codes/E0689.md"),
E0690: include_str!("./error_codes/E0690.md"),
E0691: include_str!("./error_codes/E0691.md"),
E0692: include_str!("./error_codes/E0692.md"),
E0693: include_str!("./error_codes/E0693.md"),
E0695: include_str!("./error_codes/E0695.md"),
E0697: include_str!("./error_codes/E0697.md"),
E0698: include_str!("./error_codes/E0698.md"),
Expand Down Expand Up @@ -595,7 +596,6 @@ E0748: include_str!("./error_codes/E0748.md"),
E0667, // `impl Trait` in projections
E0687, // in-band lifetimes cannot be used in `fn`/`Fn` syntax
E0688, // in-band lifetimes cannot be mixed with explicit lifetime binders
E0693, // incorrect `repr(align)` attribute format
// E0694, // an unknown tool name found in scoped attributes
E0696, // `continue` pointing to a labeled block
// E0702, // replaced with a generic attribute input check
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_error_codes/error_codes/E0117.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
The `Drop` trait was implemented on a non-struct type.
Only traits defined in the current crate can be implemented for arbitrary types.

Erroneous code example:

Expand Down
Loading