Skip to content

Commit fdaba23

Browse files
committed
Auto merge of #155964 - JonathanBrouwer:rollup-801OvoN, r=JonathanBrouwer
Rollup of 12 pull requests Successful merges: - #155189 (simd_reduce_min/max: remove float support) - #155721 (When archive format is wrong produce an error instead of ICE) - #155794 (privacy: share effective visibility initialization) - #155856 (std_detect: support detecting more features on aarch64 Windows) - #155861 (Suggest `[const] Trait` bounds in more places) - #155899 (`dlltool`: Set the working directory to workaround `--temp-prefix` bug) - #155916 (Update with new LLVM 22 target for `wasm32-wali-linux-musl` target) - #155935 (remap OUT_DIR paths to fix build script path leakage in crate metadata. ) - #155950 (use the new `//@ needs-asm-mnemonic: ret` more) - #155958 (ci(free-disk-space): remove more tools and fix warnings) - #155949 (Update `opt_ast_lowering_delayed_lints` query to allow "stealing" lints, allowing to use `FnOnce` instead of `Fn`) - #155951 (Make `FlatMapInPlaceVec` an unsafe trait.)
2 parents c935696 + 212ddcd commit fdaba23

41 files changed

Lines changed: 437 additions & 159 deletions

File tree

Some content is hidden

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

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
765765
let mut bodies = std::mem::take(&mut self.bodies);
766766
let define_opaque = std::mem::take(&mut self.define_opaque);
767767
let trait_map = std::mem::take(&mut self.trait_map);
768-
let delayed_lints = std::mem::take(&mut self.delayed_lints).into_boxed_slice();
768+
let delayed_lints = Steal::new(std::mem::take(&mut self.delayed_lints).into_boxed_slice());
769769

770770
#[cfg(debug_assertions)]
771771
for (id, attrs) in attrs.iter() {

compiler/rustc_codegen_gcc/src/builder.rs

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -2313,67 +2313,10 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
23132313
self.vector_extremum(a, b, ExtremumOperation::Min)
23142314
}
23152315

2316-
#[cfg(feature = "master")]
2317-
pub fn vector_reduce_fmin(&mut self, src: RValue<'gcc>) -> RValue<'gcc> {
2318-
let vector_type = src.get_type().unqualified().dyncast_vector().expect("vector type");
2319-
let element_count = vector_type.get_num_units();
2320-
let mut acc = self
2321-
.context
2322-
.new_vector_access(self.location, src, self.context.new_rvalue_zero(self.int_type))
2323-
.to_rvalue();
2324-
for i in 1..element_count {
2325-
let elem = self
2326-
.context
2327-
.new_vector_access(
2328-
self.location,
2329-
src,
2330-
self.context.new_rvalue_from_int(self.int_type, i as _),
2331-
)
2332-
.to_rvalue();
2333-
let cmp = self.context.new_comparison(self.location, ComparisonOp::LessThan, acc, elem);
2334-
acc = self.select(cmp, acc, elem);
2335-
}
2336-
acc
2337-
}
2338-
2339-
#[cfg(not(feature = "master"))]
2340-
pub fn vector_reduce_fmin(&mut self, _src: RValue<'gcc>) -> RValue<'gcc> {
2341-
unimplemented!();
2342-
}
2343-
23442316
pub fn vector_maximum_number_nsz(&mut self, a: RValue<'gcc>, b: RValue<'gcc>) -> RValue<'gcc> {
23452317
self.vector_extremum(a, b, ExtremumOperation::Max)
23462318
}
23472319

2348-
#[cfg(feature = "master")]
2349-
pub fn vector_reduce_fmax(&mut self, src: RValue<'gcc>) -> RValue<'gcc> {
2350-
let vector_type = src.get_type().unqualified().dyncast_vector().expect("vector type");
2351-
let element_count = vector_type.get_num_units();
2352-
let mut acc = self
2353-
.context
2354-
.new_vector_access(self.location, src, self.context.new_rvalue_zero(self.int_type))
2355-
.to_rvalue();
2356-
for i in 1..element_count {
2357-
let elem = self
2358-
.context
2359-
.new_vector_access(
2360-
self.location,
2361-
src,
2362-
self.context.new_rvalue_from_int(self.int_type, i as _),
2363-
)
2364-
.to_rvalue();
2365-
let cmp =
2366-
self.context.new_comparison(self.location, ComparisonOp::GreaterThan, acc, elem);
2367-
acc = self.select(cmp, acc, elem);
2368-
}
2369-
acc
2370-
}
2371-
2372-
#[cfg(not(feature = "master"))]
2373-
pub fn vector_reduce_fmax(&mut self, _src: RValue<'gcc>) -> RValue<'gcc> {
2374-
unimplemented!();
2375-
}
2376-
23772320
pub fn vector_select(
23782321
&mut self,
23792322
cond: RValue<'gcc>,

compiler/rustc_codegen_gcc/src/intrinsic/simd.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,15 +1422,14 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
14221422
);
14231423

14241424
macro_rules! minmax_red {
1425-
($name:ident: $int_red:ident, $float_red:ident) => {
1425+
($name:ident: $int_red:ident) => {
14261426
if name == sym::$name {
14271427
require!(
14281428
ret_ty == in_elem,
14291429
InvalidMonomorphization::ReturnType { span, name, in_elem, in_ty, ret_ty }
14301430
);
14311431
return match *in_elem.kind() {
14321432
ty::Int(_) | ty::Uint(_) => Ok(bx.$int_red(args[0].immediate())),
1433-
ty::Float(_) => Ok(bx.$float_red(args[0].immediate())),
14341433
_ => return_error!(InvalidMonomorphization::UnsupportedSymbol {
14351434
span,
14361435
name,
@@ -1444,8 +1443,8 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
14441443
};
14451444
}
14461445

1447-
minmax_red!(simd_reduce_min: vector_reduce_min, vector_reduce_fmin);
1448-
minmax_red!(simd_reduce_max: vector_reduce_max, vector_reduce_fmax);
1446+
minmax_red!(simd_reduce_min: vector_reduce_min);
1447+
minmax_red!(simd_reduce_max: vector_reduce_max);
14491448

14501449
macro_rules! bitwise_red {
14511450
($name:ident : $op:expr, $boolean:expr) => {

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,12 +1668,6 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
16681668
pub(crate) fn vector_reduce_xor(&mut self, src: &'ll Value) -> &'ll Value {
16691669
self.call_intrinsic("llvm.vector.reduce.xor", &[self.val_ty(src)], &[src])
16701670
}
1671-
pub(crate) fn vector_reduce_fmin(&mut self, src: &'ll Value) -> &'ll Value {
1672-
self.call_intrinsic("llvm.vector.reduce.fmin", &[self.val_ty(src)], &[src])
1673-
}
1674-
pub(crate) fn vector_reduce_fmax(&mut self, src: &'ll Value) -> &'ll Value {
1675-
self.call_intrinsic("llvm.vector.reduce.fmax", &[self.val_ty(src)], &[src])
1676-
}
16771671
pub(crate) fn vector_reduce_min(&mut self, src: &'ll Value, is_signed: bool) -> &'ll Value {
16781672
self.call_intrinsic(
16791673
if is_signed { "llvm.vector.reduce.smin" } else { "llvm.vector.reduce.umin" },

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2922,7 +2922,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
29222922
);
29232923

29242924
macro_rules! minmax_red {
2925-
($name:ident: $int_red:ident, $float_red:ident) => {
2925+
($name:ident: $int_red:ident) => {
29262926
if name == sym::$name {
29272927
require!(
29282928
ret_ty == in_elem,
@@ -2931,7 +2931,6 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
29312931
return match in_elem.kind() {
29322932
ty::Int(_i) => Ok(bx.$int_red(args[0].immediate(), true)),
29332933
ty::Uint(_u) => Ok(bx.$int_red(args[0].immediate(), false)),
2934-
ty::Float(_f) => Ok(bx.$float_red(args[0].immediate())),
29352934
_ => return_error!(InvalidMonomorphization::UnsupportedSymbol {
29362935
span,
29372936
name,
@@ -2945,8 +2944,9 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
29452944
};
29462945
}
29472946

2948-
minmax_red!(simd_reduce_min: vector_reduce_min, vector_reduce_fmin);
2949-
minmax_red!(simd_reduce_max: vector_reduce_max, vector_reduce_fmax);
2947+
// Currently no support for float due to <https://github.com/llvm/llvm-project/issues/185827>.
2948+
minmax_red!(simd_reduce_min: vector_reduce_min);
2949+
minmax_red!(simd_reduce_max: vector_reduce_max);
29502950

29512951
macro_rules! bitwise_red {
29522952
($name:ident : $red:ident, $boolean:expr) => {

compiler/rustc_codegen_ssa/src/back/archive.rs

Lines changed: 82 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use ar_archive_writer::{
99
ArchiveKind, COFFShortExport, MachineTypes, NewArchiveMember, write_archive_to_stream,
1010
};
1111
pub use ar_archive_writer::{DEFAULT_OBJECT_READER, ObjectReader};
12-
use object::read::archive::ArchiveFile;
12+
use object::read::archive::{ArchiveFile, ArchiveKind as ObjectArchiveKind};
1313
use object::read::macho::FatArch;
1414
use rustc_data_structures::fx::FxIndexSet;
1515
use rustc_data_structures::memmap::Mmap;
@@ -217,12 +217,10 @@ fn create_mingw_dll_import_lib(
217217
// able to control the *exact* spelling of each of the symbols that are being imported:
218218
// hence we don't want `dlltool` adding leading underscores automatically.
219219
let dlltool = find_binutils_dlltool(sess);
220-
let temp_prefix = {
221-
let mut path = PathBuf::from(&output_path);
222-
path.pop();
223-
path.push(lib_name);
224-
path
225-
};
220+
// temp_prefix doesn't handle paths with spaces so
221+
// use a relative path and set the current working directory
222+
let cwd = output_path.parent().unwrap_or(output_path);
223+
let temp_prefix = lib_name;
226224
// dlltool target architecture args from:
227225
// https://github.com/llvm/llvm-project-release-prs/blob/llvmorg-15.0.6/llvm/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp#L69
228226
let (dlltool_target_arch, dlltool_target_bitness) = match &sess.target.arch {
@@ -246,7 +244,8 @@ fn create_mingw_dll_import_lib(
246244
.arg(dlltool_target_bitness)
247245
.arg("--no-leading-underscore")
248246
.arg("--temp-prefix")
249-
.arg(temp_prefix);
247+
.arg(temp_prefix)
248+
.current_dir(cwd);
250249

251250
match dlltool_cmd.output() {
252251
Err(e) => {
@@ -320,6 +319,50 @@ pub trait ArchiveBuilder {
320319
fn build(self: Box<Self>, output: &Path) -> bool;
321320
}
322321

322+
fn target_archive_format_to_object_kind(format: &str) -> Option<ObjectArchiveKind> {
323+
match format {
324+
"gnu" => Some(ObjectArchiveKind::Gnu),
325+
"bsd" => Some(ObjectArchiveKind::Bsd),
326+
"darwin" => Some(ObjectArchiveKind::Bsd64),
327+
"coff" => Some(ObjectArchiveKind::Coff),
328+
"aix_big" => Some(ObjectArchiveKind::AixBig),
329+
_ => None,
330+
}
331+
}
332+
333+
fn archive_kinds_compatible(actual: ObjectArchiveKind, expected: ObjectArchiveKind) -> bool {
334+
if actual == expected {
335+
return true;
336+
}
337+
matches!(
338+
(actual, expected),
339+
// An archive without long filenames or symbol table is detected as Unknown;
340+
// this is compatible with any target format.
341+
(ObjectArchiveKind::Unknown, _)
342+
// 64-bit symbol table variants are compatible with their 32-bit counterparts
343+
| (ObjectArchiveKind::Gnu64, ObjectArchiveKind::Gnu)
344+
| (ObjectArchiveKind::Gnu, ObjectArchiveKind::Gnu64)
345+
| (ObjectArchiveKind::Bsd64, ObjectArchiveKind::Bsd)
346+
| (ObjectArchiveKind::Bsd, ObjectArchiveKind::Bsd64)
347+
// GNU and COFF archives share the same magic and member header format;
348+
// only the symbol table layout differs.
349+
| (ObjectArchiveKind::Gnu, ObjectArchiveKind::Coff)
350+
| (ObjectArchiveKind::Coff, ObjectArchiveKind::Gnu)
351+
| (ObjectArchiveKind::Gnu64, ObjectArchiveKind::Coff)
352+
)
353+
}
354+
355+
fn archive_kind_display_name(kind: ObjectArchiveKind) -> String {
356+
match kind {
357+
ObjectArchiveKind::Gnu | ObjectArchiveKind::Gnu64 => "GNU".to_string(),
358+
ObjectArchiveKind::Bsd => "BSD".to_string(),
359+
ObjectArchiveKind::Bsd64 => "Darwin".to_string(),
360+
ObjectArchiveKind::Coff => "COFF".to_string(),
361+
ObjectArchiveKind::AixBig => "AIX big".to_string(),
362+
_ => format!("{kind:?}"),
363+
}
364+
}
365+
323366
pub struct ArArchiveBuilderBuilder;
324367

325368
impl ArchiveBuilderBuilder for ArArchiveBuilderBuilder {
@@ -420,6 +463,19 @@ impl<'a> ArchiveBuilder for ArArchiveBuilder<'a> {
420463
.map_err(|err| io::Error::new(io::ErrorKind::InvalidData, err))?;
421464
let archive_index = self.src_archives.len();
422465

466+
if let Some(expected_kind) =
467+
target_archive_format_to_object_kind(&self.sess.target.archive_format)
468+
{
469+
let actual_kind = archive.kind();
470+
if !archive_kinds_compatible(actual_kind, expected_kind) {
471+
self.sess.dcx().emit_warn(crate::errors::IncompatibleArchiveFormat {
472+
path: archive_path.clone(),
473+
actual: archive_kind_display_name(actual_kind),
474+
expected: archive_kind_display_name(expected_kind),
475+
});
476+
}
477+
}
478+
423479
for entry in archive.members() {
424480
let entry = entry.map_err(|err| io::Error::new(io::ErrorKind::InvalidData, err))?;
425481
let file_name = String::from_utf8(entry.name().to_vec())
@@ -482,9 +538,24 @@ impl<'a> ArArchiveBuilder<'a> {
482538
match entry {
483539
ArchiveEntry::FromArchive { archive_index, file_range } => {
484540
let src_archive = &self.src_archives[archive_index];
485-
486-
let data = &src_archive.1
487-
[file_range.0 as usize..file_range.0 as usize + file_range.1 as usize];
541+
let archive_data = &src_archive.1;
542+
let start = file_range.0 as usize;
543+
let end = start + file_range.1 as usize;
544+
let Some(data) = archive_data.get(start..end) else {
545+
return Err(io_error_context(
546+
"invalid archive member",
547+
io::Error::new(
548+
io::ErrorKind::InvalidData,
549+
format!(
550+
"archive member at offset {start} with size {} \
551+
exceeds archive size {} in `{}`",
552+
file_range.1,
553+
archive_data.len(),
554+
src_archive.0.display(),
555+
),
556+
),
557+
));
558+
};
488559

489560
Box::new(data) as Box<dyn AsRef<[u8]>>
490561
}

compiler/rustc_codegen_ssa/src/errors.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,18 @@ pub(crate) struct UnknownArchiveKind<'a> {
677677
pub kind: &'a str,
678678
}
679679

680+
#[derive(Diagnostic)]
681+
#[diag("archive `{$path}` was built as {$actual} format, but the target expects {$expected}")]
682+
#[help(
683+
"this often occurs when using BSD-format archive tools on a Linux target; \
684+
rebuild the archive with the correct format for the target platform"
685+
)]
686+
pub(crate) struct IncompatibleArchiveFormat {
687+
pub path: PathBuf,
688+
pub actual: String,
689+
pub expected: String,
690+
}
691+
680692
#[derive(Diagnostic)]
681693
#[diag("linking static libraries is not supported for BPF")]
682694
pub(crate) struct BpfStaticlibNotSupported;

compiler/rustc_data_structures/src/flat_map_in_place.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,13 @@ impl<V: FlatMapInPlaceVec> FlatMapInPlace<V::Elem> for V {
6767
}
6868
}
6969

70-
// A vec-like type must implement these operations to support `flat_map_in_place`.
71-
pub trait FlatMapInPlaceVec {
70+
/// A vec-like type must implement these operations to support `flat_map_in_place`.
71+
///
72+
/// # Safety
73+
///
74+
/// The memory safety of the unsafe block in `flat_map_in_place` relies on impls of this trait
75+
/// implementing all the operations correctly.
76+
pub unsafe trait FlatMapInPlaceVec {
7277
type Elem;
7378

7479
fn len(&self) -> usize;
@@ -78,7 +83,7 @@ pub trait FlatMapInPlaceVec {
7883
fn insert(&mut self, idx: usize, elem: Self::Elem);
7984
}
8085

81-
impl<T> FlatMapInPlaceVec for Vec<T> {
86+
unsafe impl<T> FlatMapInPlaceVec for Vec<T> {
8287
type Elem = T;
8388

8489
fn len(&self) -> usize {
@@ -104,7 +109,7 @@ impl<T> FlatMapInPlaceVec for Vec<T> {
104109
}
105110
}
106111

107-
impl<T> FlatMapInPlaceVec for ThinVec<T> {
112+
unsafe impl<T> FlatMapInPlaceVec for ThinVec<T> {
108113
type Elem = T;
109114

110115
fn len(&self) -> usize {
@@ -130,7 +135,7 @@ impl<T> FlatMapInPlaceVec for ThinVec<T> {
130135
}
131136
}
132137

133-
impl<T, const N: usize> FlatMapInPlaceVec for SmallVec<[T; N]> {
138+
unsafe impl<T, const N: usize> FlatMapInPlaceVec for SmallVec<[T; N]> {
134139
type Elem = T;
135140

136141
fn len(&self) -> usize {

compiler/rustc_hir/src/hir.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub use rustc_ast::{
1818
};
1919
use rustc_data_structures::fingerprint::Fingerprint;
2020
use rustc_data_structures::sorted_map::SortedMap;
21+
use rustc_data_structures::steal::Steal;
2122
use rustc_data_structures::tagged_ptr::TaggedRef;
2223
use rustc_error_messages::{DiagArgValue, IntoDiagArg};
2324
use rustc_index::IndexVec;
@@ -1636,7 +1637,7 @@ pub struct OwnerInfo<'hir> {
16361637
/// WARNING: The delayed lints are not hashed as a part of the `OwnerInfo`, and therefore
16371638
/// should only be accessed in `eval_always` queries.
16381639
#[stable_hasher(ignore)]
1639-
pub delayed_lints: DelayedLints,
1640+
pub delayed_lints: Steal<DelayedLints>,
16401641
}
16411642

16421643
impl<'tcx> OwnerInfo<'tcx> {

compiler/rustc_hir_analysis/src/check/always_applicable.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,16 +217,26 @@ fn ensure_all_fields_are_const_destruct<'tcx>(
217217
unreachable!()
218218
};
219219
let field_ty = eff.trait_ref.self_ty();
220-
let diag = struct_span_code_err!(
220+
let mut diag = struct_span_code_err!(
221221
tcx.dcx(),
222222
error.root_obligation.cause.span,
223223
E0367,
224224
"`{field_ty}` does not implement `[const] Destruct`",
225225
)
226226
.with_span_note(impl_span, "required for this `Drop` impl");
227-
if field_ty.has_param() {
228-
// FIXME: suggest adding `[const] Destruct` by teaching
229-
// `suggest_restricting_param_bound` about const traits.
227+
if field_ty.has_param()
228+
&& let Some(generics) = tcx.hir_node_by_def_id(impl_def_id).generics()
229+
{
230+
let destruct_def_id = tcx.lang_items().destruct_trait();
231+
ty::suggest_constraining_type_param(
232+
tcx,
233+
generics,
234+
&mut diag,
235+
&field_ty.to_string(),
236+
"[const] Destruct",
237+
destruct_def_id,
238+
None,
239+
);
230240
}
231241
Err(diag.emit())
232242
})

0 commit comments

Comments
 (0)