Skip to content

Commit 67dfa4c

Browse files
committed
Auto merge of #129547 - tgross35:rollup-3lihvog, r=tgross35
Rollup of 8 pull requests Successful merges: - #126985 (Implement `-Z embed-source` (DWARFv5 source code embedding extension)) - #128935 (More work on `zstd` compression) - #129134 (bootstrap: improve error recovery flags to curl) - #129190 (Add f16 and f128 to tests/ui/consts/const-float-bits-conv.rs) - #129416 (library: Move unstable API of new_uninit to new features) - #129418 (rustc: Simplify getting sysroot library directory) - #129459 (handle stage0 `cargo` and `rustc` separately) - #129511 (Update minifier to 0.3.1) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 717aec0 + 34a4834 commit 67dfa4c

File tree

35 files changed

+473
-134
lines changed

35 files changed

+473
-134
lines changed

Cargo.lock

+5-2
Original file line numberDiff line numberDiff line change
@@ -2227,9 +2227,12 @@ dependencies = [
22272227

22282228
[[package]]
22292229
name = "minifier"
2230-
version = "0.3.0"
2230+
version = "0.3.1"
22312231
source = "registry+https://github.com/rust-lang/crates.io-index"
2232-
checksum = "95bbbf96b9ac3482c2a25450b67a15ed851319bc5fabf3b40742ea9066e84282"
2232+
checksum = "9aa3f302fe0f8de065d4a2d1ed64f60204623cac58b80cd3c2a83a25d5a7d437"
2233+
dependencies = [
2234+
"clap",
2235+
]
22332236

22342237
[[package]]
22352238
name = "minimal-lexical"

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+9
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,9 @@ pub fn file_metadata<'ll>(cx: &CodegenCx<'ll, '_>, source_file: &SourceFile) ->
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 fn file_metadata<'ll>(cx: &CodegenCx<'ll, '_>, source_file: &SourceFile) ->
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 @@ pub 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 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/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_index/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#![cfg_attr(all(feature = "nightly", test), feature(stmt_expr_attributes))]
33
#![cfg_attr(feature = "nightly", allow(internal_features))]
44
#![cfg_attr(feature = "nightly", feature(extend_one, new_uninit, step_trait, test))]
5+
#![cfg_attr(feature = "nightly", feature(new_zeroed_alloc))]
56
// tidy-alphabetical-end
67

78
pub mod bit_set;

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],

compiler/rustc_session/src/session.rs

+18-16
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ use rustc_target::spec::{
3737
use crate::code_stats::CodeStats;
3838
pub use crate::code_stats::{DataTypeKind, FieldInfo, FieldKind, SizeKind, VariantInfo};
3939
use crate::config::{
40-
self, CoverageLevel, CrateType, ErrorOutputType, FunctionReturn, Input, InstrumentCoverage,
41-
OptLevel, OutFileName, OutputType, RemapPathScopeComponents, SwitchWithOptPath,
40+
self, CoverageLevel, CrateType, DebugInfo, ErrorOutputType, FunctionReturn, Input,
41+
InstrumentCoverage, OptLevel, OutFileName, OutputType, RemapPathScopeComponents,
42+
SwitchWithOptPath,
4243
};
4344
use crate::parse::{add_feature_diagnostics, ParseSess};
4445
use crate::search_paths::{PathKind, SearchPath};
@@ -439,22 +440,10 @@ impl Session {
439440
}
440441

441442
pub fn target_filesearch(&self, kind: PathKind) -> filesearch::FileSearch<'_> {
442-
filesearch::FileSearch::new(
443-
&self.sysroot,
444-
self.opts.target_triple.triple(),
445-
&self.opts.search_paths,
446-
&self.target_tlib_path,
447-
kind,
448-
)
443+
filesearch::FileSearch::new(&self.opts.search_paths, &self.target_tlib_path, kind)
449444
}
450445
pub fn host_filesearch(&self, kind: PathKind) -> filesearch::FileSearch<'_> {
451-
filesearch::FileSearch::new(
452-
&self.sysroot,
453-
config::host_triple(),
454-
&self.opts.search_paths,
455-
&self.host_tlib_path,
456-
kind,
457-
)
446+
filesearch::FileSearch::new(&self.opts.search_paths, &self.host_tlib_path, kind)
458447
}
459448

460449
/// Returns a list of directories where target-specific tool binaries are located. Some fallback
@@ -1306,6 +1295,19 @@ fn validate_commandline_args_with_session_available(sess: &Session) {
13061295
.emit_err(errors::SplitDebugInfoUnstablePlatform { debuginfo: sess.split_debuginfo() });
13071296
}
13081297

1298+
if sess.opts.unstable_opts.embed_source {
1299+
let dwarf_version =
1300+
sess.opts.unstable_opts.dwarf_version.unwrap_or(sess.target.default_dwarf_version);
1301+
1302+
if dwarf_version < 5 {
1303+
sess.dcx().emit_warn(errors::EmbedSourceInsufficientDwarfVersion { dwarf_version });
1304+
}
1305+
1306+
if sess.opts.debuginfo == DebugInfo::None {
1307+
sess.dcx().emit_warn(errors::EmbedSourceRequiresDebugInfo);
1308+
}
1309+
}
1310+
13091311
if sess.opts.unstable_opts.instrument_xray.is_some() && !sess.target.options.supports_xray {
13101312
sess.dcx().emit_err(errors::InstrumentationNotSupported { us: "XRay".to_string() });
13111313
}

library/alloc/src/boxed.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ impl<T> Box<T> {
293293
///
294294
/// ```
295295
/// #![feature(new_uninit)]
296+
/// #![feature(new_zeroed_alloc)]
296297
///
297298
/// let zero = Box::<u32>::new_zeroed();
298299
/// let zero = unsafe { zero.assume_init() };
@@ -303,7 +304,7 @@ impl<T> Box<T> {
303304
/// [zeroed]: mem::MaybeUninit::zeroed
304305
#[cfg(not(no_global_oom_handling))]
305306
#[inline]
306-
#[unstable(feature = "new_uninit", issue = "63291")]
307+
#[unstable(feature = "new_zeroed_alloc", issue = "129396")]
307308
#[must_use]
308309
pub fn new_zeroed() -> Box<mem::MaybeUninit<T>> {
309310
Self::new_zeroed_in(Global)
@@ -684,6 +685,7 @@ impl<T> Box<[T]> {
684685
/// # Examples
685686
///
686687
/// ```
688+
/// #![feature(new_zeroed_alloc)]
687689
/// #![feature(new_uninit)]
688690
///
689691
/// let values = Box::<[u32]>::new_zeroed_slice(3);
@@ -694,7 +696,7 @@ impl<T> Box<[T]> {
694696
///
695697
/// [zeroed]: mem::MaybeUninit::zeroed
696698
#[cfg(not(no_global_oom_handling))]
697-
#[unstable(feature = "new_uninit", issue = "63291")]
699+
#[unstable(feature = "new_zeroed_alloc", issue = "129396")]
698700
#[must_use]
699701
pub fn new_zeroed_slice(len: usize) -> Box<[mem::MaybeUninit<T>]> {
700702
unsafe { RawVec::with_capacity_zeroed(len).into_box(len) }
@@ -955,6 +957,7 @@ impl<T, A: Allocator> Box<mem::MaybeUninit<T>, A> {
955957
/// # Examples
956958
///
957959
/// ```
960+
/// #![feature(box_uninit_write)]
958961
/// #![feature(new_uninit)]
959962
///
960963
/// let big_box = Box::<[usize; 1024]>::new_uninit();
@@ -972,7 +975,7 @@ impl<T, A: Allocator> Box<mem::MaybeUninit<T>, A> {
972975
/// assert_eq!(*x, i);
973976
/// }
974977
/// ```
975-
#[unstable(feature = "new_uninit", issue = "63291")]
978+
#[unstable(feature = "box_uninit_write", issue = "129397")]
976979
#[inline]
977980
pub fn write(mut boxed: Self, value: T) -> Box<T, A> {
978981
unsafe {

library/alloc/src/rc.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,7 @@ impl<T> Rc<T> {
539539
/// # Examples
540540
///
541541
/// ```
542+
/// #![feature(new_zeroed_alloc)]
542543
/// #![feature(new_uninit)]
543544
///
544545
/// use std::rc::Rc;
@@ -551,7 +552,7 @@ impl<T> Rc<T> {
551552
///
552553
/// [zeroed]: mem::MaybeUninit::zeroed
553554
#[cfg(not(no_global_oom_handling))]
554-
#[unstable(feature = "new_uninit", issue = "63291")]
555+
#[unstable(feature = "new_zeroed_alloc", issue = "129396")]
555556
#[must_use]
556557
pub fn new_zeroed() -> Rc<mem::MaybeUninit<T>> {
557558
unsafe {
@@ -1000,6 +1001,7 @@ impl<T> Rc<[T]> {
10001001
///
10011002
/// ```
10021003
/// #![feature(new_uninit)]
1004+
/// #![feature(new_zeroed_alloc)]
10031005
///
10041006
/// use std::rc::Rc;
10051007
///
@@ -1011,7 +1013,7 @@ impl<T> Rc<[T]> {
10111013
///
10121014
/// [zeroed]: mem::MaybeUninit::zeroed
10131015
#[cfg(not(no_global_oom_handling))]
1014-
#[unstable(feature = "new_uninit", issue = "63291")]
1016+
#[unstable(feature = "new_zeroed_alloc", issue = "129396")]
10151017
#[must_use]
10161018
pub fn new_zeroed_slice(len: usize) -> Rc<[mem::MaybeUninit<T>]> {
10171019
unsafe {

0 commit comments

Comments
 (0)