Skip to content

Commit 0efe642

Browse files
committed
Auto merge of #129643 - workingjubilee:rollup-h3n6hmz, r=workingjubilee
Rollup of 9 pull requests Successful merges: - #126985 (Implement `-Z embed-source` (DWARFv5 source code embedding extension)) - #127922 (Add unsafe to extern blocks in style guide) - #128731 (simd_shuffle intrinsic: allow argument to be passed as vector) - #128935 (More work on `zstd` compression) - #128942 (miri weak memory emulation: put previous value into initial store buffer) - #129418 (rustc: Simplify getting sysroot library directory) - #129490 (Add Trusty OS as tier 3 target) - #129559 (float types: document NaN bit pattern guarantees) - #129642 (Bump backtrace to rust-lang/backtrace@fc37b22) r? `@ghost` `@rustbot` modify labels: rollup
2 parents bf662eb + d05e28b commit 0efe642

File tree

54 files changed

+856
-296
lines changed

Some content is hidden

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

54 files changed

+856
-296
lines changed

compiler/rustc_codegen_cranelift/src/intrinsics/simd.rs

+10
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,14 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
191191
})
192192
.try_into()
193193
.unwrap(),
194+
_ if idx_ty.is_simd()
195+
&& matches!(
196+
idx_ty.simd_size_and_type(fx.tcx).1.kind(),
197+
ty::Uint(ty::UintTy::U32)
198+
) =>
199+
{
200+
idx_ty.simd_size_and_type(fx.tcx).0.try_into().unwrap()
201+
}
194202
_ => {
195203
fx.tcx.dcx().span_err(
196204
span,
@@ -213,6 +221,8 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
213221

214222
let total_len = lane_count * 2;
215223

224+
// FIXME: this is a terrible abstraction-breaking hack.
225+
// Find a way to reuse `immediate_const_vector` from `codegen_ssa` instead.
216226
let indexes = {
217227
use rustc_middle::mir::interpret::*;
218228
let idx_const = match &idx.node {

compiler/rustc_codegen_gcc/src/builder.rs

+30-14
Original file line numberDiff line numberDiff line change
@@ -1923,15 +1923,11 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
19231923
v2: RValue<'gcc>,
19241924
mask: RValue<'gcc>,
19251925
) -> RValue<'gcc> {
1926-
let struct_type = mask.get_type().is_struct().expect("mask should be of struct type");
1927-
19281926
// TODO(antoyo): use a recursive unqualified() here.
19291927
let vector_type = v1.get_type().unqualified().dyncast_vector().expect("vector type");
19301928
let element_type = vector_type.get_element_type();
19311929
let vec_num_units = vector_type.get_num_units();
19321930

1933-
let mask_num_units = struct_type.get_field_count();
1934-
let mut vector_elements = vec![];
19351931
let mask_element_type = if element_type.is_integral() {
19361932
element_type
19371933
} else {
@@ -1942,19 +1938,39 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
19421938
#[cfg(not(feature = "master"))]
19431939
self.int_type
19441940
};
1945-
for i in 0..mask_num_units {
1946-
let field = struct_type.get_field(i as i32);
1947-
vector_elements.push(self.context.new_cast(
1948-
self.location,
1949-
mask.access_field(self.location, field).to_rvalue(),
1950-
mask_element_type,
1951-
));
1952-
}
1941+
1942+
let mut mask_elements = if let Some(vector_type) = mask.get_type().dyncast_vector() {
1943+
let mask_num_units = vector_type.get_num_units();
1944+
let mut mask_elements = vec![];
1945+
for i in 0..mask_num_units {
1946+
let index = self.context.new_rvalue_from_long(self.cx.type_u32(), i as _);
1947+
mask_elements.push(self.context.new_cast(
1948+
self.location,
1949+
self.extract_element(mask, index).to_rvalue(),
1950+
mask_element_type,
1951+
));
1952+
}
1953+
mask_elements
1954+
} else {
1955+
let struct_type = mask.get_type().is_struct().expect("mask should be of struct type");
1956+
let mask_num_units = struct_type.get_field_count();
1957+
let mut mask_elements = vec![];
1958+
for i in 0..mask_num_units {
1959+
let field = struct_type.get_field(i as i32);
1960+
mask_elements.push(self.context.new_cast(
1961+
self.location,
1962+
mask.access_field(self.location, field).to_rvalue(),
1963+
mask_element_type,
1964+
));
1965+
}
1966+
mask_elements
1967+
};
1968+
let mask_num_units = mask_elements.len();
19531969

19541970
// NOTE: the mask needs to be the same length as the input vectors, so add the missing
19551971
// elements in the mask if needed.
19561972
for _ in mask_num_units..vec_num_units {
1957-
vector_elements.push(self.context.new_rvalue_zero(mask_element_type));
1973+
mask_elements.push(self.context.new_rvalue_zero(mask_element_type));
19581974
}
19591975

19601976
let result_type = self.context.new_vector_type(element_type, mask_num_units as u64);
@@ -1998,7 +2014,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
19982014

19992015
let new_mask_num_units = std::cmp::max(mask_num_units, vec_num_units);
20002016
let mask_type = self.context.new_vector_type(mask_element_type, new_mask_num_units as u64);
2001-
let mask = self.context.new_rvalue_from_vector(self.location, mask_type, &vector_elements);
2017+
let mask = self.context.new_rvalue_from_vector(self.location, mask_type, &mask_elements);
20022018
let result = self.context.new_rvalue_vector_perm(self.location, v1, v2, mask);
20032019

20042020
if vec_num_units != mask_num_units {

compiler/rustc_codegen_gcc/src/intrinsic/simd.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -353,19 +353,24 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
353353
}
354354

355355
if name == sym::simd_shuffle {
356-
// Make sure this is actually an array, since typeck only checks the length-suffixed
356+
// Make sure this is actually an array or SIMD vector, since typeck only checks the length-suffixed
357357
// version of this intrinsic.
358-
let n: u64 = match *args[2].layout.ty.kind() {
358+
let idx_ty = args[2].layout.ty;
359+
let n: u64 = match idx_ty.kind() {
359360
ty::Array(ty, len) if matches!(*ty.kind(), ty::Uint(ty::UintTy::U32)) => {
360361
len.try_eval_target_usize(bx.cx.tcx, ty::ParamEnv::reveal_all()).unwrap_or_else(
361362
|| span_bug!(span, "could not evaluate shuffle index array length"),
362363
)
363364
}
364-
_ => return_error!(InvalidMonomorphization::SimdShuffle {
365-
span,
366-
name,
367-
ty: args[2].layout.ty
368-
}),
365+
_ if idx_ty.is_simd()
366+
&& matches!(
367+
idx_ty.simd_size_and_type(bx.cx.tcx).1.kind(),
368+
ty::Uint(ty::UintTy::U32)
369+
) =>
370+
{
371+
idx_ty.simd_size_and_type(bx.cx.tcx).0
372+
}
373+
_ => return_error!(InvalidMonomorphization::SimdShuffle { span, name, ty: idx_ty }),
369374
};
370375
require_simd!(ret_ty, InvalidMonomorphization::SimdReturn { span, name, ty: ret_ty });
371376

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+9
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,9 @@ pub(crate) fn file_metadata<'ll>(cx: &CodegenCx<'ll, '_>, source_file: &SourceFi
629629
};
630630
let hash_value = hex_encode(source_file.src_hash.hash_bytes());
631631

632+
let source =
633+
cx.sess().opts.unstable_opts.embed_source.then_some(()).and(source_file.src.as_ref());
634+
632635
unsafe {
633636
llvm::LLVMRustDIBuilderCreateFile(
634637
DIB(cx),
@@ -639,6 +642,8 @@ pub(crate) fn file_metadata<'ll>(cx: &CodegenCx<'ll, '_>, source_file: &SourceFi
639642
hash_kind,
640643
hash_value.as_ptr().cast(),
641644
hash_value.len(),
645+
source.map_or(ptr::null(), |x| x.as_ptr().cast()),
646+
source.map_or(0, |x| x.len()),
642647
)
643648
}
644649
}
@@ -659,6 +664,8 @@ fn unknown_file_metadata<'ll>(cx: &CodegenCx<'ll, '_>) -> &'ll DIFile {
659664
llvm::ChecksumKind::None,
660665
hash_value.as_ptr().cast(),
661666
hash_value.len(),
667+
ptr::null(),
668+
0,
662669
)
663670
})
664671
}
@@ -943,6 +950,8 @@ pub(crate) fn build_compile_unit_di_node<'ll, 'tcx>(
943950
llvm::ChecksumKind::None,
944951
ptr::null(),
945952
0,
953+
ptr::null(),
954+
0,
946955
);
947956

948957
let unit_metadata = llvm::LLVMRustDIBuilderCreateCompileUnit(

compiler/rustc_codegen_llvm/src/intrinsic.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -1287,19 +1287,24 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
12871287
}
12881288

12891289
if name == sym::simd_shuffle {
1290-
// Make sure this is actually an array, since typeck only checks the length-suffixed
1290+
// Make sure this is actually an array or SIMD vector, since typeck only checks the length-suffixed
12911291
// version of this intrinsic.
1292-
let n: u64 = match args[2].layout.ty.kind() {
1292+
let idx_ty = args[2].layout.ty;
1293+
let n: u64 = match idx_ty.kind() {
12931294
ty::Array(ty, len) if matches!(ty.kind(), ty::Uint(ty::UintTy::U32)) => {
12941295
len.try_eval_target_usize(bx.cx.tcx, ty::ParamEnv::reveal_all()).unwrap_or_else(
12951296
|| span_bug!(span, "could not evaluate shuffle index array length"),
12961297
)
12971298
}
1298-
_ => return_error!(InvalidMonomorphization::SimdShuffle {
1299-
span,
1300-
name,
1301-
ty: args[2].layout.ty
1302-
}),
1299+
_ if idx_ty.is_simd()
1300+
&& matches!(
1301+
idx_ty.simd_size_and_type(bx.cx.tcx).1.kind(),
1302+
ty::Uint(ty::UintTy::U32)
1303+
) =>
1304+
{
1305+
idx_ty.simd_size_and_type(bx.cx.tcx).0
1306+
}
1307+
_ => return_error!(InvalidMonomorphization::SimdShuffle { span, name, ty: idx_ty }),
13031308
};
13041309

13051310
let (out_len, out_ty) = require_simd!(ret_ty, SimdReturn);

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1860,6 +1860,8 @@ extern "C" {
18601860
CSKind: ChecksumKind,
18611861
Checksum: *const c_char,
18621862
ChecksumLen: size_t,
1863+
Source: *const c_char,
1864+
SourceLen: size_t,
18631865
) -> &'a DIFile;
18641866

18651867
pub fn LLVMRustDIBuilderCreateSubroutineType<'a>(

compiler/rustc_codegen_ssa/src/back/link.rs

+11-16
Original file line numberDiff line numberDiff line change
@@ -1317,11 +1317,9 @@ fn link_sanitizer_runtime(
13171317
name: &str,
13181318
) {
13191319
fn find_sanitizer_runtime(sess: &Session, filename: &str) -> PathBuf {
1320-
let session_tlib =
1321-
filesearch::make_target_lib_path(&sess.sysroot, sess.opts.target_triple.triple());
1322-
let path = session_tlib.join(filename);
1320+
let path = sess.target_tlib_path.dir.join(filename);
13231321
if path.exists() {
1324-
return session_tlib;
1322+
return sess.target_tlib_path.dir.clone();
13251323
} else {
13261324
let default_sysroot =
13271325
filesearch::get_or_default_sysroot().expect("Failed finding sysroot");
@@ -1612,19 +1610,18 @@ fn print_native_static_libs(
16121610
}
16131611

16141612
fn get_object_file_path(sess: &Session, name: &str, self_contained: bool) -> PathBuf {
1615-
let fs = sess.target_filesearch(PathKind::Native);
1616-
let file_path = fs.get_lib_path().join(name);
1613+
let file_path = sess.target_tlib_path.dir.join(name);
16171614
if file_path.exists() {
16181615
return file_path;
16191616
}
16201617
// Special directory with objects used only in self-contained linkage mode
16211618
if self_contained {
1622-
let file_path = fs.get_self_contained_lib_path().join(name);
1619+
let file_path = sess.target_tlib_path.dir.join("self-contained").join(name);
16231620
if file_path.exists() {
16241621
return file_path;
16251622
}
16261623
}
1627-
for search_path in fs.search_paths() {
1624+
for search_path in sess.target_filesearch(PathKind::Native).search_paths() {
16281625
let file_path = search_path.dir.join(name);
16291626
if file_path.exists() {
16301627
return file_path;
@@ -2131,7 +2128,7 @@ fn add_library_search_dirs(
21312128
| LinkSelfContainedComponents::UNWIND
21322129
| LinkSelfContainedComponents::MINGW,
21332130
) {
2134-
let lib_path = sess.target_filesearch(PathKind::Native).get_self_contained_lib_path();
2131+
let lib_path = sess.target_tlib_path.dir.join("self-contained");
21352132
cmd.include_path(&fix_windows_verbatim_for_gcc(&lib_path));
21362133
}
21372134

@@ -2146,8 +2143,7 @@ fn add_library_search_dirs(
21462143
|| sess.target.os == "fuchsia"
21472144
|| sess.target.is_like_osx && !sess.opts.unstable_opts.sanitizer.is_empty()
21482145
{
2149-
let lib_path = sess.target_filesearch(PathKind::Native).get_lib_path();
2150-
cmd.include_path(&fix_windows_verbatim_for_gcc(&lib_path));
2146+
cmd.include_path(&fix_windows_verbatim_for_gcc(&sess.target_tlib_path.dir));
21512147
}
21522148

21532149
// Mac Catalyst uses the macOS SDK, but to link to iOS-specific frameworks
@@ -2859,15 +2855,14 @@ fn add_upstream_native_libraries(
28592855
//
28602856
// The returned path will always have `fix_windows_verbatim_for_gcc()` applied to it.
28612857
fn rehome_sysroot_lib_dir(sess: &Session, lib_dir: &Path) -> PathBuf {
2862-
let sysroot_lib_path = sess.target_filesearch(PathKind::All).get_lib_path();
2858+
let sysroot_lib_path = &sess.target_tlib_path.dir;
28632859
let canonical_sysroot_lib_path =
2864-
{ try_canonicalize(&sysroot_lib_path).unwrap_or_else(|_| sysroot_lib_path.clone()) };
2860+
{ try_canonicalize(sysroot_lib_path).unwrap_or_else(|_| sysroot_lib_path.clone()) };
28652861

28662862
let canonical_lib_dir = try_canonicalize(lib_dir).unwrap_or_else(|_| lib_dir.to_path_buf());
28672863
if canonical_lib_dir == canonical_sysroot_lib_path {
2868-
// This path, returned by `target_filesearch().get_lib_path()`, has
2869-
// already had `fix_windows_verbatim_for_gcc()` applied if needed.
2870-
sysroot_lib_path
2864+
// This path already had `fix_windows_verbatim_for_gcc()` applied if needed.
2865+
sysroot_lib_path.clone()
28712866
} else {
28722867
fix_windows_verbatim_for_gcc(lib_dir)
28732868
}

compiler/rustc_const_eval/src/interpret/memory.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
10141014
///
10151015
/// We do this so Miri's allocation access tracking does not show the validation
10161016
/// reads as spurious accesses.
1017-
pub(super) fn run_for_validation<R>(&self, f: impl FnOnce() -> R) -> R {
1017+
pub fn run_for_validation<R>(&self, f: impl FnOnce() -> R) -> R {
10181018
// This deliberately uses `==` on `bool` to follow the pattern
10191019
// `assert!(val.replace(new) == old)`.
10201020
assert!(

compiler/rustc_interface/src/tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,7 @@ fn test_unstable_options_tracking_hash() {
774774
tracked!(direct_access_external_data, Some(true));
775775
tracked!(dual_proc_macros, true);
776776
tracked!(dwarf_version, Some(5));
777+
tracked!(embed_source, true);
777778
tracked!(emit_thin_lto, false);
778779
tracked!(export_executable_symbols, true);
779780
tracked!(fewer_names, Some(true));

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -913,14 +913,19 @@ extern "C" LLVMMetadataRef
913913
LLVMRustDIBuilderCreateFile(LLVMRustDIBuilderRef Builder, const char *Filename,
914914
size_t FilenameLen, const char *Directory,
915915
size_t DirectoryLen, LLVMRustChecksumKind CSKind,
916-
const char *Checksum, size_t ChecksumLen) {
916+
const char *Checksum, size_t ChecksumLen,
917+
const char *Source, size_t SourceLen) {
917918

918919
std::optional<DIFile::ChecksumKind> llvmCSKind = fromRust(CSKind);
919920
std::optional<DIFile::ChecksumInfo<StringRef>> CSInfo{};
920921
if (llvmCSKind)
921922
CSInfo.emplace(*llvmCSKind, StringRef{Checksum, ChecksumLen});
923+
std::optional<StringRef> oSource{};
924+
if (Source)
925+
oSource = StringRef(Source, SourceLen);
922926
return wrap(Builder->createFile(StringRef(Filename, FilenameLen),
923-
StringRef(Directory, DirectoryLen), CSInfo));
927+
StringRef(Directory, DirectoryLen), CSInfo,
928+
oSource));
924929
}
925930

926931
extern "C" LLVMMetadataRef

compiler/rustc_session/messages.ftl

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ session_crate_name_empty = crate name must not be empty
1414
1515
session_crate_name_invalid = crate names cannot start with a `-`, but `{$s}` has a leading hyphen
1616
17+
session_embed_source_insufficient_dwarf_version = `-Zembed-source=y` requires at least `-Z dwarf-version=5` but DWARF version is {$dwarf_version}
18+
19+
session_embed_source_requires_debug_info = `-Zembed-source=y` requires debug information to be enabled
20+
1721
session_expr_parentheses_needed = parentheses are required to parse this as an expression
1822
1923
session_failed_to_create_profiler = failed to create profiler: {$err}

compiler/rustc_session/src/errors.rs

+10
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,16 @@ pub(crate) struct UnsupportedDwarfVersion {
165165
pub(crate) dwarf_version: u32,
166166
}
167167

168+
#[derive(Diagnostic)]
169+
#[diag(session_embed_source_insufficient_dwarf_version)]
170+
pub(crate) struct EmbedSourceInsufficientDwarfVersion {
171+
pub(crate) dwarf_version: u32,
172+
}
173+
174+
#[derive(Diagnostic)]
175+
#[diag(session_embed_source_requires_debug_info)]
176+
pub(crate) struct EmbedSourceRequiresDebugInfo;
177+
168178
#[derive(Diagnostic)]
169179
#[diag(session_target_stack_protector_not_supported)]
170180
pub(crate) struct StackProtectorNotSupportedForTarget<'a> {

compiler/rustc_session/src/filesearch.rs

+1-15
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,11 @@ use std::{env, fs};
55

66
use rustc_fs_util::{fix_windows_verbatim_for_gcc, try_canonicalize};
77
use smallvec::{smallvec, SmallVec};
8-
use tracing::debug;
98

109
use crate::search_paths::{PathKind, SearchPath};
1110

1211
#[derive(Clone)]
1312
pub struct FileSearch<'a> {
14-
sysroot: &'a Path,
15-
triple: &'a str,
1613
cli_search_paths: &'a [SearchPath],
1714
tlib_path: &'a SearchPath,
1815
kind: PathKind,
@@ -32,23 +29,12 @@ impl<'a> FileSearch<'a> {
3229
.chain(std::iter::once(self.tlib_path))
3330
}
3431

35-
pub fn get_lib_path(&self) -> PathBuf {
36-
make_target_lib_path(self.sysroot, self.triple)
37-
}
38-
39-
pub fn get_self_contained_lib_path(&self) -> PathBuf {
40-
self.get_lib_path().join("self-contained")
41-
}
42-
4332
pub fn new(
44-
sysroot: &'a Path,
45-
triple: &'a str,
4633
cli_search_paths: &'a [SearchPath],
4734
tlib_path: &'a SearchPath,
4835
kind: PathKind,
4936
) -> FileSearch<'a> {
50-
debug!("using sysroot = {}, triple = {}", sysroot.display(), triple);
51-
FileSearch { sysroot, triple, cli_search_paths, tlib_path, kind }
37+
FileSearch { cli_search_paths, tlib_path, kind }
5238
}
5339
}
5440

compiler/rustc_session/src/options.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1701,6 +1701,8 @@ options! {
17011701
them only if an error has not been emitted"),
17021702
ehcont_guard: bool = (false, parse_bool, [TRACKED],
17031703
"generate Windows EHCont Guard tables"),
1704+
embed_source: bool = (false, parse_bool, [TRACKED],
1705+
"embed source text in DWARF debug sections (default: no)"),
17041706
emit_stack_sizes: bool = (false, parse_bool, [UNTRACKED],
17051707
"emit a section containing stack size metadata (default: no)"),
17061708
emit_thin_lto: bool = (true, parse_bool, [TRACKED],

0 commit comments

Comments
 (0)