Skip to content

Commit f981b2e

Browse files
committed
Auto merge of #133659 - jieyouxu:rollup-576gh4p, r=jieyouxu
Rollup of 6 pull requests Successful merges: - #131551 (Support input/output in vector registers of PowerPC inline assembly) - #132515 (Fix and undeprecate home_dir()) - #132721 (CI: split x86_64-mingw job) - #133106 (changes old intrinsic declaration to new declaration) - #133496 (thread::available_parallelism for wasm32-wasip1-threads) - #133548 (Add `BTreeSet` entry APIs to match `HashSet`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents e93e096 + 132fcd8 commit f981b2e

File tree

25 files changed

+2230
-978
lines changed

25 files changed

+2230
-978
lines changed

compiler/rustc_codegen_gcc/src/asm.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -656,9 +656,9 @@ fn reg_to_gcc(reg: InlineAsmRegOrRegClass) -> ConstraintOrRegister {
656656
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::reg) => "r",
657657
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::reg_nonzero) => "b",
658658
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::freg) => "f",
659+
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::vreg) => "v",
659660
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::cr)
660-
| InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::xer)
661-
| InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::vreg) => {
661+
| InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::xer) => {
662662
unreachable!("clobber-only")
663663
}
664664
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::reg) => "r",
@@ -736,9 +736,11 @@ fn dummy_output_type<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, reg: InlineAsmRegCl
736736
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::reg) => cx.type_i32(),
737737
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::reg_nonzero) => cx.type_i32(),
738738
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::freg) => cx.type_f64(),
739+
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::vreg) => {
740+
cx.type_vector(cx.type_i32(), 4)
741+
}
739742
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::cr)
740-
| InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::xer)
741-
| InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::vreg) => {
743+
| InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::xer) => {
742744
unreachable!("clobber-only")
743745
}
744746
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::reg) => cx.type_i32(),

compiler/rustc_codegen_llvm/src/asm.rs

+46-6
Original file line numberDiff line numberDiff line change
@@ -656,9 +656,8 @@ fn reg_to_llvm(reg: InlineAsmRegOrRegClass, layout: Option<&TyAndLayout<'_>>) ->
656656
PowerPC(PowerPCInlineAsmRegClass::reg) => "r",
657657
PowerPC(PowerPCInlineAsmRegClass::reg_nonzero) => "b",
658658
PowerPC(PowerPCInlineAsmRegClass::freg) => "f",
659-
PowerPC(PowerPCInlineAsmRegClass::cr)
660-
| PowerPC(PowerPCInlineAsmRegClass::xer)
661-
| PowerPC(PowerPCInlineAsmRegClass::vreg) => {
659+
PowerPC(PowerPCInlineAsmRegClass::vreg) => "v",
660+
PowerPC(PowerPCInlineAsmRegClass::cr) | PowerPC(PowerPCInlineAsmRegClass::xer) => {
662661
unreachable!("clobber-only")
663662
}
664663
RiscV(RiscVInlineAsmRegClass::reg) => "r",
@@ -825,9 +824,8 @@ fn dummy_output_type<'ll>(cx: &CodegenCx<'ll, '_>, reg: InlineAsmRegClass) -> &'
825824
PowerPC(PowerPCInlineAsmRegClass::reg) => cx.type_i32(),
826825
PowerPC(PowerPCInlineAsmRegClass::reg_nonzero) => cx.type_i32(),
827826
PowerPC(PowerPCInlineAsmRegClass::freg) => cx.type_f64(),
828-
PowerPC(PowerPCInlineAsmRegClass::cr)
829-
| PowerPC(PowerPCInlineAsmRegClass::xer)
830-
| PowerPC(PowerPCInlineAsmRegClass::vreg) => {
827+
PowerPC(PowerPCInlineAsmRegClass::vreg) => cx.type_vector(cx.type_i32(), 4),
828+
PowerPC(PowerPCInlineAsmRegClass::cr) | PowerPC(PowerPCInlineAsmRegClass::xer) => {
831829
unreachable!("clobber-only")
832830
}
833831
RiscV(RiscVInlineAsmRegClass::reg) => cx.type_i32(),
@@ -1042,6 +1040,26 @@ fn llvm_fixup_input<'ll, 'tcx>(
10421040
let value = bx.or(value, bx.const_u32(0xFFFF_0000));
10431041
bx.bitcast(value, bx.type_f32())
10441042
}
1043+
(PowerPC(PowerPCInlineAsmRegClass::vreg), BackendRepr::Scalar(s))
1044+
if s.primitive() == Primitive::Float(Float::F32) =>
1045+
{
1046+
let value = bx.insert_element(
1047+
bx.const_undef(bx.type_vector(bx.type_f32(), 4)),
1048+
value,
1049+
bx.const_usize(0),
1050+
);
1051+
bx.bitcast(value, bx.type_vector(bx.type_f32(), 4))
1052+
}
1053+
(PowerPC(PowerPCInlineAsmRegClass::vreg), BackendRepr::Scalar(s))
1054+
if s.primitive() == Primitive::Float(Float::F64) =>
1055+
{
1056+
let value = bx.insert_element(
1057+
bx.const_undef(bx.type_vector(bx.type_f64(), 2)),
1058+
value,
1059+
bx.const_usize(0),
1060+
);
1061+
bx.bitcast(value, bx.type_vector(bx.type_f64(), 2))
1062+
}
10451063
_ => value,
10461064
}
10471065
}
@@ -1177,6 +1195,18 @@ fn llvm_fixup_output<'ll, 'tcx>(
11771195
let value = bx.trunc(value, bx.type_i16());
11781196
bx.bitcast(value, bx.type_f16())
11791197
}
1198+
(PowerPC(PowerPCInlineAsmRegClass::vreg), BackendRepr::Scalar(s))
1199+
if s.primitive() == Primitive::Float(Float::F32) =>
1200+
{
1201+
let value = bx.bitcast(value, bx.type_vector(bx.type_f32(), 4));
1202+
bx.extract_element(value, bx.const_usize(0))
1203+
}
1204+
(PowerPC(PowerPCInlineAsmRegClass::vreg), BackendRepr::Scalar(s))
1205+
if s.primitive() == Primitive::Float(Float::F64) =>
1206+
{
1207+
let value = bx.bitcast(value, bx.type_vector(bx.type_f64(), 2));
1208+
bx.extract_element(value, bx.const_usize(0))
1209+
}
11801210
_ => value,
11811211
}
11821212
}
@@ -1301,6 +1331,16 @@ fn llvm_fixup_output_type<'ll, 'tcx>(
13011331
{
13021332
cx.type_f32()
13031333
}
1334+
(PowerPC(PowerPCInlineAsmRegClass::vreg), BackendRepr::Scalar(s))
1335+
if s.primitive() == Primitive::Float(Float::F32) =>
1336+
{
1337+
cx.type_vector(cx.type_f32(), 4)
1338+
}
1339+
(PowerPC(PowerPCInlineAsmRegClass::vreg), BackendRepr::Scalar(s))
1340+
if s.primitive() == Primitive::Float(Float::F64) =>
1341+
{
1342+
cx.type_vector(cx.type_f64(), 2)
1343+
}
13041344
_ => layout.llvm_type(cx),
13051345
}
13061346
}

compiler/rustc_span/src/symbol.rs

+2
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ symbols! {
392392
allow_fail,
393393
allow_internal_unsafe,
394394
allow_internal_unstable,
395+
altivec,
395396
alu32,
396397
always,
397398
and,
@@ -2154,6 +2155,7 @@ symbols! {
21542155
volatile_store,
21552156
vreg,
21562157
vreg_low16,
2158+
vsx,
21572159
vtable_align,
21582160
vtable_size,
21592161
warn,

compiler/rustc_target/src/asm/powerpc.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ impl PowerPCInlineAsmRegClass {
5151
}
5252
}
5353
Self::freg => types! { _: F32, F64; },
54-
Self::vreg => &[],
54+
// FIXME: vsx also supports integers?: https://github.com/rust-lang/rust/pull/131551#discussion_r1862535963
55+
Self::vreg => types! {
56+
altivec: VecI8(16), VecI16(8), VecI32(4), VecF32(4);
57+
vsx: F32, F64, VecI64(2), VecF64(2);
58+
},
5559
Self::cr | Self::xer => &[],
5660
}
5761
}

library/alloc/src/collections/btree/map.rs

+28-1
Original file line numberDiff line numberDiff line change
@@ -308,11 +308,38 @@ impl<K, A: Allocator + Clone> BTreeMap<K, SetValZST, A> {
308308
alloc: (*map.alloc).clone(),
309309
_marker: PhantomData,
310310
}
311-
.insert(SetValZST::default());
311+
.insert(SetValZST);
312312
None
313313
}
314314
}
315315
}
316+
317+
pub(super) fn get_or_insert_with<Q: ?Sized, F>(&mut self, q: &Q, f: F) -> &K
318+
where
319+
K: Borrow<Q> + Ord,
320+
Q: Ord,
321+
F: FnOnce(&Q) -> K,
322+
{
323+
let (map, dormant_map) = DormantMutRef::new(self);
324+
let root_node =
325+
map.root.get_or_insert_with(|| Root::new((*map.alloc).clone())).borrow_mut();
326+
match root_node.search_tree(q) {
327+
Found(handle) => handle.into_kv_mut().0,
328+
GoDown(handle) => {
329+
let key = f(q);
330+
assert!(*key.borrow() == *q, "new value is not equal");
331+
VacantEntry {
332+
key,
333+
handle: Some(handle),
334+
dormant_map,
335+
alloc: (*map.alloc).clone(),
336+
_marker: PhantomData,
337+
}
338+
.insert_entry(SetValZST)
339+
.into_key()
340+
}
341+
}
342+
}
316343
}
317344

318345
/// An iterator over the entries of a `BTreeMap`.

library/alloc/src/collections/btree/map/entry.rs

+5
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,11 @@ impl<'a, K: Ord, V, A: Allocator + Clone> OccupiedEntry<'a, K, V, A> {
449449
self.handle.reborrow().into_kv().0
450450
}
451451

452+
/// Converts the entry into a reference to its key.
453+
pub(crate) fn into_key(self) -> &'a K {
454+
self.handle.into_kv_mut().0
455+
}
456+
452457
/// Take ownership of the key and value from the map.
453458
///
454459
/// # Examples

library/alloc/src/collections/btree/set.rs

+109-1
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,17 @@ use core::iter::{FusedIterator, Peekable};
77
use core::mem::ManuallyDrop;
88
use core::ops::{BitAnd, BitOr, BitXor, Bound, RangeBounds, Sub};
99

10-
use super::map::{BTreeMap, Keys};
10+
use super::map::{self, BTreeMap, Keys};
1111
use super::merge_iter::MergeIterInner;
1212
use super::set_val::SetValZST;
1313
use crate::alloc::{Allocator, Global};
1414
use crate::vec::Vec;
1515

16+
mod entry;
17+
18+
#[unstable(feature = "btree_set_entry", issue = "133549")]
19+
pub use self::entry::{Entry, OccupiedEntry, VacantEntry};
20+
1621
/// An ordered set based on a B-Tree.
1722
///
1823
/// See [`BTreeMap`]'s documentation for a detailed discussion of this collection's performance
@@ -928,6 +933,109 @@ impl<T, A: Allocator + Clone> BTreeSet<T, A> {
928933
self.map.replace(value)
929934
}
930935

936+
/// Inserts the given `value` into the set if it is not present, then
937+
/// returns a reference to the value in the set.
938+
///
939+
/// # Examples
940+
///
941+
/// ```
942+
/// #![feature(btree_set_entry)]
943+
///
944+
/// use std::collections::BTreeSet;
945+
///
946+
/// let mut set = BTreeSet::from([1, 2, 3]);
947+
/// assert_eq!(set.len(), 3);
948+
/// assert_eq!(set.get_or_insert(2), &2);
949+
/// assert_eq!(set.get_or_insert(100), &100);
950+
/// assert_eq!(set.len(), 4); // 100 was inserted
951+
/// ```
952+
#[inline]
953+
#[unstable(feature = "btree_set_entry", issue = "133549")]
954+
pub fn get_or_insert(&mut self, value: T) -> &T
955+
where
956+
T: Ord,
957+
{
958+
self.map.entry(value).insert_entry(SetValZST).into_key()
959+
}
960+
961+
/// Inserts a value computed from `f` into the set if the given `value` is
962+
/// not present, then returns a reference to the value in the set.
963+
///
964+
/// # Examples
965+
///
966+
/// ```
967+
/// #![feature(btree_set_entry)]
968+
///
969+
/// use std::collections::BTreeSet;
970+
///
971+
/// let mut set: BTreeSet<String> = ["cat", "dog", "horse"]
972+
/// .iter().map(|&pet| pet.to_owned()).collect();
973+
///
974+
/// assert_eq!(set.len(), 3);
975+
/// for &pet in &["cat", "dog", "fish"] {
976+
/// let value = set.get_or_insert_with(pet, str::to_owned);
977+
/// assert_eq!(value, pet);
978+
/// }
979+
/// assert_eq!(set.len(), 4); // a new "fish" was inserted
980+
/// ```
981+
#[inline]
982+
#[unstable(feature = "btree_set_entry", issue = "133549")]
983+
pub fn get_or_insert_with<Q: ?Sized, F>(&mut self, value: &Q, f: F) -> &T
984+
where
985+
T: Borrow<Q> + Ord,
986+
Q: Ord,
987+
F: FnOnce(&Q) -> T,
988+
{
989+
self.map.get_or_insert_with(value, f)
990+
}
991+
992+
/// Gets the given value's corresponding entry in the set for in-place manipulation.
993+
///
994+
/// # Examples
995+
///
996+
/// ```
997+
/// #![feature(btree_set_entry)]
998+
///
999+
/// use std::collections::BTreeSet;
1000+
/// use std::collections::btree_set::Entry::*;
1001+
///
1002+
/// let mut singles = BTreeSet::new();
1003+
/// let mut dupes = BTreeSet::new();
1004+
///
1005+
/// for ch in "a short treatise on fungi".chars() {
1006+
/// if let Vacant(dupe_entry) = dupes.entry(ch) {
1007+
/// // We haven't already seen a duplicate, so
1008+
/// // check if we've at least seen it once.
1009+
/// match singles.entry(ch) {
1010+
/// Vacant(single_entry) => {
1011+
/// // We found a new character for the first time.
1012+
/// single_entry.insert()
1013+
/// }
1014+
/// Occupied(single_entry) => {
1015+
/// // We've already seen this once, "move" it to dupes.
1016+
/// single_entry.remove();
1017+
/// dupe_entry.insert();
1018+
/// }
1019+
/// }
1020+
/// }
1021+
/// }
1022+
///
1023+
/// assert!(!singles.contains(&'t') && dupes.contains(&'t'));
1024+
/// assert!(singles.contains(&'u') && !dupes.contains(&'u'));
1025+
/// assert!(!singles.contains(&'v') && !dupes.contains(&'v'));
1026+
/// ```
1027+
#[inline]
1028+
#[unstable(feature = "btree_set_entry", issue = "133549")]
1029+
pub fn entry(&mut self, value: T) -> Entry<'_, T, A>
1030+
where
1031+
T: Ord,
1032+
{
1033+
match self.map.entry(value) {
1034+
map::Entry::Occupied(entry) => Entry::Occupied(OccupiedEntry { inner: entry }),
1035+
map::Entry::Vacant(entry) => Entry::Vacant(VacantEntry { inner: entry }),
1036+
}
1037+
}
1038+
9311039
/// If the set contains an element equal to the value, removes it from the
9321040
/// set and drops it. Returns whether such an element was present.
9331041
///

0 commit comments

Comments
 (0)