Skip to content

Commit 5a72ecf

Browse files
committed
Auto merge of #70016 - Dylan-DPC:rollup-5k7lxs3, r=Dylan-DPC
Rollup of 7 pull requests Successful merges: - #69357 (Emit 1-based column numbers in debuginfo) - #69471 (Remove `sip::Hasher::short_write`.) - #69498 (Change "method" to "associated function") - #69967 (Remove a few `Rc`s from RegionInferenceCtxt) - #69987 (Add self to .mailmap) - #69991 (fix E0117 message out of sync) - #69993 (Add long error explanation for E0693) Failed merges: r? @ghost
2 parents 7cdbc87 + 838884e commit 5a72ecf

File tree

95 files changed

+383
-278
lines changed

Some content is hidden

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

95 files changed

+383
-278
lines changed

.mailmap

+3
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ Mateusz Mikuła <matti@marinelayer.io> <mati865@gmail.com>
172172
Mateusz Mikuła <matti@marinelayer.io> <mati865@users.noreply.github.com>
173173
Matt Brubeck <mbrubeck@limpet.net> <mbrubeck@cs.hmc.edu>
174174
Matthew Auld <matthew.auld@intel.com>
175+
Matthew Kraai <kraai@ftbfs.org>
176+
Matthew Kraai <kraai@ftbfs.org> <matt.kraai@abbott.com>
177+
Matthew Kraai <kraai@ftbfs.org> <mkraai@its.jnj.com>
175178
Matthew McPherrin <matthew@mcpherrin.ca> <matt@mcpherrin.ca>
176179
Matthijs Hofstra <thiezz@gmail.com>
177180
Melody Horn <melody@boringcactus.com> <mathphreak@gmail.com>

src/libcore/hash/sip.rs

+7-46
Original file line numberDiff line numberDiff line change
@@ -220,37 +220,6 @@ impl<S: Sip> Hasher<S> {
220220
self.state.v3 = self.k1 ^ 0x7465646279746573;
221221
self.ntail = 0;
222222
}
223-
224-
// Specialized write function that is only valid for buffers with len <= 8.
225-
// It's used to force inlining of write_u8 and write_usize, those would normally be inlined
226-
// except for composite types (that includes slices and str hashing because of delimiter).
227-
// Without this extra push the compiler is very reluctant to inline delimiter writes,
228-
// degrading performance substantially for the most common use cases.
229-
#[inline]
230-
fn short_write(&mut self, msg: &[u8]) {
231-
debug_assert!(msg.len() <= 8);
232-
let length = msg.len();
233-
self.length += length;
234-
235-
let needed = 8 - self.ntail;
236-
let fill = cmp::min(length, needed);
237-
if fill == 8 {
238-
self.tail = unsafe { load_int_le!(msg, 0, u64) };
239-
} else {
240-
self.tail |= unsafe { u8to64_le(msg, 0, fill) } << (8 * self.ntail);
241-
if length < needed {
242-
self.ntail += length;
243-
return;
244-
}
245-
}
246-
self.state.v3 ^= self.tail;
247-
S::c_rounds(&mut self.state);
248-
self.state.v0 ^= self.tail;
249-
250-
// Buffered tail is now flushed, process new input.
251-
self.ntail = length - needed;
252-
self.tail = unsafe { u8to64_le(msg, needed, self.ntail) };
253-
}
254223
}
255224

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

282251
impl<S: Sip> super::Hasher for Hasher<S> {
283-
// see short_write comment for explanation
284-
#[inline]
285-
fn write_usize(&mut self, i: usize) {
286-
let bytes = unsafe {
287-
crate::slice::from_raw_parts(&i as *const usize as *const u8, mem::size_of::<usize>())
288-
};
289-
self.short_write(bytes);
290-
}
291-
292-
// see short_write comment for explanation
293-
#[inline]
294-
fn write_u8(&mut self, i: u8) {
295-
self.short_write(&[i]);
296-
}
297-
252+
// Note: no integer hashing methods (`write_u*`, `write_i*`) are defined
253+
// for this type. We could add them, copy the `short_write` implementation
254+
// in librustc_data_structures/sip128.rs, and add `write_u*`/`write_i*`
255+
// methods to `SipHasher`, `SipHasher13`, and `DefaultHasher`. This would
256+
// greatly speed up integer hashing by those hashers, at the cost of
257+
// slightly slowing down compile speeds on some benchmarks. See #69152 for
258+
// details.
298259
#[inline]
299260
fn write(&mut self, msg: &[u8]) {
300261
let length = msg.len();

src/librustc_codegen_llvm/debuginfo/create_scope_map.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
use super::metadata::file_metadata;
2-
use super::utils::{span_start, DIB};
1+
use super::metadata::{file_metadata, UNKNOWN_COLUMN_NUMBER, UNKNOWN_LINE_NUMBER};
2+
use super::utils::DIB;
33
use rustc_codegen_ssa::mir::debuginfo::{DebugScope, FunctionDebugContext};
44

55
use crate::common::CodegenCx;
66
use crate::llvm;
77
use crate::llvm::debuginfo::{DIScope, DISubprogram};
88
use rustc::mir::{Body, SourceScope};
99

10-
use libc::c_uint;
11-
12-
use rustc_span::Pos;
13-
1410
use rustc_index::bit_set::BitSet;
1511
use rustc_index::vec::Idx;
1612

@@ -54,7 +50,7 @@ fn make_mir_scope(
5450
debug_context.scopes[parent]
5551
} else {
5652
// The root is the function itself.
57-
let loc = span_start(cx, mir.span);
53+
let loc = cx.lookup_debug_loc(mir.span.lo());
5854
debug_context.scopes[scope] = DebugScope {
5955
scope_metadata: Some(fn_metadata),
6056
file_start_pos: loc.file.start_pos,
@@ -70,16 +66,16 @@ fn make_mir_scope(
7066
return;
7167
}
7268

73-
let loc = span_start(cx, scope_data.span);
69+
let loc = cx.lookup_debug_loc(scope_data.span.lo());
7470
let file_metadata = file_metadata(cx, &loc.file.name, debug_context.defining_crate);
7571

7672
let scope_metadata = unsafe {
7773
Some(llvm::LLVMRustDIBuilderCreateLexicalBlock(
7874
DIB(cx),
7975
parent_scope.scope_metadata.unwrap(),
8076
file_metadata,
81-
loc.line as c_uint,
82-
loc.col.to_usize() as c_uint,
77+
loc.line.unwrap_or(UNKNOWN_LINE_NUMBER),
78+
loc.col.unwrap_or(UNKNOWN_COLUMN_NUMBER),
8379
))
8480
};
8581
debug_context.scopes[scope] = DebugScope {

src/librustc_codegen_llvm/debuginfo/metadata.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use self::RecursiveTypeDescription::*;
55
use super::namespace::mangled_name_of_instance;
66
use super::type_names::compute_debuginfo_type_name;
77
use super::utils::{
8-
create_DIArray, debug_context, get_namespace_for_item, is_node_local_to_unit, span_start, DIB,
8+
create_DIArray, debug_context, get_namespace_for_item, is_node_local_to_unit, DIB,
99
};
1010
use super::CrateDebugContext;
1111

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

23112311
let (file_metadata, line_number) = if !span.is_dummy() {
2312-
let loc = span_start(cx, span);
2313-
(file_metadata(cx, &loc.file.name, LOCAL_CRATE), loc.line as c_uint)
2312+
let loc = cx.lookup_debug_loc(span.lo());
2313+
(file_metadata(cx, &loc.file.name, LOCAL_CRATE), loc.line)
23142314
} else {
2315-
(unknown_file_metadata(cx), UNKNOWN_LINE_NUMBER)
2315+
(unknown_file_metadata(cx), None)
23162316
};
23172317

23182318
let is_local_to_unit = is_node_local_to_unit(cx, def_id);
@@ -2339,7 +2339,7 @@ pub fn create_global_var_metadata(cx: &CodegenCx<'ll, '_>, def_id: DefId, global
23392339
linkage_name.as_ptr().cast(),
23402340
linkage_name.len(),
23412341
file_metadata,
2342-
line_number,
2342+
line_number.unwrap_or(UNKNOWN_LINE_NUMBER),
23432343
type_metadata,
23442344
is_local_to_unit,
23452345
global,

src/librustc_codegen_llvm/debuginfo/mod.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ mod doc;
33

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

6-
use self::metadata::{file_metadata, type_metadata, TypeMap};
6+
use self::metadata::{file_metadata, type_metadata, TypeMap, UNKNOWN_LINE_NUMBER};
77
use self::namespace::mangled_name_of_instance;
88
use self::type_names::compute_debuginfo_type_name;
9-
use self::utils::{create_DIArray, is_node_local_to_unit, span_start, DIB};
9+
use self::utils::{create_DIArray, is_node_local_to_unit, DIB};
1010

1111
use crate::llvm;
1212
use crate::llvm::debuginfo::{
@@ -248,7 +248,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
248248

249249
let def_id = instance.def_id();
250250
let containing_scope = get_containing_scope(self, instance);
251-
let loc = span_start(self, span);
251+
let loc = self.lookup_debug_loc(span.lo());
252252
let file_metadata = file_metadata(self, &loc.file.name, def_id.krate);
253253

254254
let function_type_metadata = unsafe {
@@ -304,9 +304,9 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
304304
linkage_name.as_ptr().cast(),
305305
linkage_name.len(),
306306
file_metadata,
307-
loc.line as c_uint,
307+
loc.line.unwrap_or(UNKNOWN_LINE_NUMBER),
308308
function_type_metadata,
309-
scope_line as c_uint,
309+
scope_line.unwrap_or(UNKNOWN_LINE_NUMBER),
310310
flags,
311311
spflags,
312312
llfn,
@@ -530,7 +530,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
530530
variable_kind: VariableKind,
531531
span: Span,
532532
) -> &'ll DIVariable {
533-
let loc = span_start(self, span);
533+
let loc = self.lookup_debug_loc(span.lo());
534534
let file_metadata = file_metadata(self, &loc.file.name, dbg_context.defining_crate);
535535

536536
let type_metadata = type_metadata(self, variable_type, span);
@@ -550,7 +550,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
550550
name.as_ptr().cast(),
551551
name.len(),
552552
file_metadata,
553-
loc.line as c_uint,
553+
loc.line.unwrap_or(UNKNOWN_LINE_NUMBER),
554554
type_metadata,
555555
true,
556556
DIFlags::FlagZero,

src/librustc_codegen_llvm/debuginfo/source_loc.rs

+39-13
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,58 @@
1-
use super::metadata::UNKNOWN_COLUMN_NUMBER;
2-
use super::utils::{debug_context, span_start};
1+
use super::metadata::{UNKNOWN_COLUMN_NUMBER, UNKNOWN_LINE_NUMBER};
2+
use super::utils::debug_context;
33

44
use crate::common::CodegenCx;
55
use crate::llvm::debuginfo::DIScope;
66
use crate::llvm::{self, Value};
77
use rustc_codegen_ssa::traits::*;
88

9-
use libc::c_uint;
10-
use rustc_span::{Pos, Span};
9+
use rustc_data_structures::sync::Lrc;
10+
use rustc_span::{BytePos, Pos, SourceFile, SourceFileAndLine, Span};
11+
12+
/// A source code location used to generate debug information.
13+
pub struct DebugLoc {
14+
/// Information about the original source file.
15+
pub file: Lrc<SourceFile>,
16+
/// The (1-based) line number.
17+
pub line: Option<u32>,
18+
/// The (1-based) column number.
19+
pub col: Option<u32>,
20+
}
1121

1222
impl CodegenCx<'ll, '_> {
13-
pub fn create_debug_loc(&self, scope: &'ll DIScope, span: Span) -> &'ll Value {
14-
let loc = span_start(self, span);
23+
/// Looks up debug source information about a `BytePos`.
24+
pub fn lookup_debug_loc(&self, pos: BytePos) -> DebugLoc {
25+
let (file, line, col) = match self.sess().source_map().lookup_line(pos) {
26+
Ok(SourceFileAndLine { sf: file, line }) => {
27+
let line_pos = file.line_begin_pos(pos);
28+
29+
// Use 1-based indexing.
30+
let line = (line + 1) as u32;
31+
let col = (pos - line_pos).to_u32() + 1;
32+
33+
(file, Some(line), Some(col))
34+
}
35+
Err(file) => (file, None, None),
36+
};
1537

16-
// For MSVC, set the column number to zero.
38+
// For MSVC, omit the column number.
1739
// Otherwise, emit it. This mimics clang behaviour.
1840
// See discussion in https://github.com/rust-lang/rust/issues/42921
19-
let col_used = if self.sess().target.target.options.is_like_msvc {
20-
UNKNOWN_COLUMN_NUMBER
41+
if self.sess().target.target.options.is_like_msvc {
42+
DebugLoc { file, line, col: None }
2143
} else {
22-
loc.col.to_usize() as c_uint
23-
};
44+
DebugLoc { file, line, col }
45+
}
46+
}
47+
48+
pub fn create_debug_loc(&self, scope: &'ll DIScope, span: Span) -> &'ll Value {
49+
let DebugLoc { line, col, .. } = self.lookup_debug_loc(span.lo());
2450

2551
unsafe {
2652
llvm::LLVMRustDIBuilderCreateDebugLocation(
2753
debug_context(self).llcontext,
28-
loc.line as c_uint,
29-
col_used,
54+
line.unwrap_or(UNKNOWN_LINE_NUMBER),
55+
col.unwrap_or(UNKNOWN_COLUMN_NUMBER),
3056
scope,
3157
None,
3258
)

src/librustc_codegen_llvm/debuginfo/utils.rs

-8
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ use rustc_hir::def_id::DefId;
99
use crate::common::CodegenCx;
1010
use crate::llvm;
1111
use crate::llvm::debuginfo::{DIArray, DIBuilder, DIDescriptor, DIScope};
12-
use rustc_codegen_ssa::traits::*;
13-
14-
use rustc_span::Span;
1512

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

35-
/// Returns rustc_span::Loc corresponding to the beginning of the span
36-
pub fn span_start(cx: &CodegenCx<'_, '_>, span: Span) -> rustc_span::Loc {
37-
cx.sess().source_map().lookup_char_pos(span.lo())
38-
}
39-
4032
#[inline]
4133
pub fn debug_context(cx: &'a CodegenCx<'ll, 'tcx>) -> &'a CrateDebugContext<'ll, 'tcx> {
4234
cx.dbg_cx.as_ref().unwrap()
+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
//! An immutable, owned value (except for interior mutability).
2+
//!
3+
//! The purpose of `Frozen` is to make a value immutable for the sake of defensive programming. For example,
4+
//! suppose we have the following:
5+
//!
6+
//! ```rust
7+
//! struct Bar { /* some data */ }
8+
//!
9+
//! struct Foo {
10+
//! /// Some computed data that should never change after construction.
11+
//! pub computed: Bar,
12+
//!
13+
//! /* some other fields */
14+
//! }
15+
//!
16+
//! impl Bar {
17+
//! /// Mutate the `Bar`.
18+
//! pub fn mutate(&mut self) { }
19+
//! }
20+
//! ```
21+
//!
22+
//! Now suppose we want to pass around a mutable `Foo` instance but, we want to make sure that
23+
//! `computed` does not change accidentally (e.g. somebody might accidentally call
24+
//! `foo.computed.mutate()`). This is what `Frozen` is for. We can do the following:
25+
//!
26+
//! ```rust
27+
//! use rustc_data_structures::frozen::Frozen;
28+
//!
29+
//! struct Foo {
30+
//! /// Some computed data that should never change after construction.
31+
//! pub computed: Frozen<Bar>,
32+
//!
33+
//! /* some other fields */
34+
//! }
35+
//! ```
36+
//!
37+
//! `Frozen` impls `Deref`, so we can ergonomically call methods on `Bar`, but it doesn't `impl
38+
//! DerefMut`. Now calling `foo.compute.mutate()` will result in a compile-time error stating that
39+
//! `mutate` requires a mutable reference but we don't have one.
40+
//!
41+
//! # Caveats
42+
//!
43+
//! - `Frozen` doesn't try to defend against interior mutability (e.g. `Frozen<RefCell<Bar>>`).
44+
//! - `Frozen` doesn't pin it's contents (e.g. one could still do `foo.computed =
45+
//! Frozen::freeze(new_bar)`).
46+
47+
/// An owned immutable value.
48+
#[derive(Debug)]
49+
pub struct Frozen<T>(T);
50+
51+
impl<T> Frozen<T> {
52+
pub fn freeze(val: T) -> Self {
53+
Frozen(val)
54+
}
55+
}
56+
57+
impl<T> std::ops::Deref for Frozen<T> {
58+
type Target = T;
59+
60+
fn deref(&self) -> &T {
61+
&self.0
62+
}
63+
}

src/librustc_data_structures/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ pub mod profiling;
9494
pub mod vec_linked_list;
9595
pub mod work_queue;
9696
pub use atomic_ref::AtomicRef;
97+
pub mod frozen;
9798

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

src/librustc_error_codes/error_codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ E0689: include_str!("./error_codes/E0689.md"),
380380
E0690: include_str!("./error_codes/E0690.md"),
381381
E0691: include_str!("./error_codes/E0691.md"),
382382
E0692: include_str!("./error_codes/E0692.md"),
383+
E0693: include_str!("./error_codes/E0693.md"),
383384
E0695: include_str!("./error_codes/E0695.md"),
384385
E0697: include_str!("./error_codes/E0697.md"),
385386
E0698: include_str!("./error_codes/E0698.md"),
@@ -595,7 +596,6 @@ E0748: include_str!("./error_codes/E0748.md"),
595596
E0667, // `impl Trait` in projections
596597
E0687, // in-band lifetimes cannot be used in `fn`/`Fn` syntax
597598
E0688, // in-band lifetimes cannot be mixed with explicit lifetime binders
598-
E0693, // incorrect `repr(align)` attribute format
599599
// E0694, // an unknown tool name found in scoped attributes
600600
E0696, // `continue` pointing to a labeled block
601601
// E0702, // replaced with a generic attribute input check

src/librustc_error_codes/error_codes/E0117.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
The `Drop` trait was implemented on a non-struct type.
1+
Only traits defined in the current crate can be implemented for arbitrary types.
22

33
Erroneous code example:
44

0 commit comments

Comments
 (0)