Skip to content

Commit 5413f7d

Browse files
committed
Auto merge of #147715 - matthiaskrgr:rollup-611b4x4, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #146841 (Stabilise `rotate_left` and `rotate_right` in `[_]` as `const fn` items.) - #146949 (Add vsx register support for ppc inline asm, and implement preserves_flag option) - #147539 (resolve: Use primitives for conditional mutability more consistently) - #147685 (remove span calls from deprecated attribute checking) - #147699 (Clairify docs for `AttributeKind::DocComment`) - #147706 (Add myself to review rotation) - #147711 (Clarify that UB will occur, not can/may in GlobalAlloc docs) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 235a4c0 + ed6077a commit 5413f7d

File tree

24 files changed

+3151
-275
lines changed

24 files changed

+3151
-275
lines changed

compiler/rustc_codegen_gcc/src/asm.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -546,9 +546,16 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
546546
}
547547

548548
if !options.contains(InlineAsmOptions::PRESERVES_FLAGS) {
549-
// TODO(@Commeownist): I'm not 100% sure this one clobber is sufficient
550-
// on all architectures. For instance, what about FP stack?
551-
extended_asm.add_clobber("cc");
549+
match asm_arch {
550+
InlineAsmArch::PowerPC | InlineAsmArch::PowerPC64 => {
551+
// "cc" is cr0 on powerpc.
552+
}
553+
// TODO(@Commeownist): I'm not 100% sure this one clobber is sufficient
554+
// on all architectures. For instance, what about FP stack?
555+
_ => {
556+
extended_asm.add_clobber("cc");
557+
}
558+
}
552559
}
553560
if !options.contains(InlineAsmOptions::NOMEM) {
554561
extended_asm.add_clobber("memory");
@@ -698,6 +705,7 @@ fn reg_class_to_gcc(reg_class: InlineAsmRegClass) -> &'static str {
698705
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::reg_nonzero) => "b",
699706
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::freg) => "f",
700707
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::vreg) => "v",
708+
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::vsreg) => "wa",
701709
InlineAsmRegClass::PowerPC(
702710
PowerPCInlineAsmRegClass::cr
703711
| PowerPCInlineAsmRegClass::ctr
@@ -778,9 +786,9 @@ fn dummy_output_type<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, reg: InlineAsmRegCl
778786
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::reg) => cx.type_i32(),
779787
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::reg_nonzero) => cx.type_i32(),
780788
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::freg) => cx.type_f64(),
781-
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::vreg) => {
782-
cx.type_vector(cx.type_i32(), 4)
783-
}
789+
InlineAsmRegClass::PowerPC(
790+
PowerPCInlineAsmRegClass::vreg | PowerPCInlineAsmRegClass::vsreg,
791+
) => cx.type_vector(cx.type_i32(), 4),
784792
InlineAsmRegClass::PowerPC(
785793
PowerPCInlineAsmRegClass::cr
786794
| PowerPCInlineAsmRegClass::ctr
@@ -957,6 +965,13 @@ fn modifier_to_gcc(
957965
InlineAsmRegClass::LoongArch(_) => None,
958966
InlineAsmRegClass::Mips(_) => None,
959967
InlineAsmRegClass::Nvptx(_) => None,
968+
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::vsreg) => {
969+
if modifier.is_none() {
970+
Some('x')
971+
} else {
972+
modifier
973+
}
974+
}
960975
InlineAsmRegClass::PowerPC(_) => None,
961976
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::reg)
962977
| InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::freg) => None,

compiler/rustc_codegen_llvm/src/asm.rs

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,7 @@ fn reg_to_llvm(reg: InlineAsmRegOrRegClass, layout: Option<&TyAndLayout<'_>>) ->
658658
PowerPC(PowerPCInlineAsmRegClass::reg_nonzero) => "b",
659659
PowerPC(PowerPCInlineAsmRegClass::freg) => "f",
660660
PowerPC(PowerPCInlineAsmRegClass::vreg) => "v",
661+
PowerPC(PowerPCInlineAsmRegClass::vsreg) => "^wa",
661662
PowerPC(
662663
PowerPCInlineAsmRegClass::cr
663664
| PowerPCInlineAsmRegClass::ctr
@@ -748,6 +749,12 @@ fn modifier_to_llvm(
748749
LoongArch(_) => None,
749750
Mips(_) => None,
750751
Nvptx(_) => None,
752+
PowerPC(PowerPCInlineAsmRegClass::vsreg) => {
753+
// The documentation for the 'x' modifier is missing for llvm, and the gcc
754+
// documentation is simply "use this for any vsx argument". It is needed
755+
// to ensure the correct vsx register number is used.
756+
if modifier.is_none() { Some('x') } else { modifier }
757+
}
751758
PowerPC(_) => None,
752759
RiscV(RiscVInlineAsmRegClass::reg) | RiscV(RiscVInlineAsmRegClass::freg) => None,
753760
RiscV(RiscVInlineAsmRegClass::vreg) => unreachable!("clobber-only"),
@@ -831,6 +838,7 @@ fn dummy_output_type<'ll>(cx: &CodegenCx<'ll, '_>, reg: InlineAsmRegClass) -> &'
831838
PowerPC(PowerPCInlineAsmRegClass::reg_nonzero) => cx.type_i32(),
832839
PowerPC(PowerPCInlineAsmRegClass::freg) => cx.type_f64(),
833840
PowerPC(PowerPCInlineAsmRegClass::vreg) => cx.type_vector(cx.type_i32(), 4),
841+
PowerPC(PowerPCInlineAsmRegClass::vsreg) => cx.type_vector(cx.type_i32(), 4),
834842
PowerPC(
835843
PowerPCInlineAsmRegClass::cr
836844
| PowerPCInlineAsmRegClass::ctr
@@ -1061,19 +1069,21 @@ fn llvm_fixup_input<'ll, 'tcx>(
10611069
let value = bx.or(value, bx.const_u32(0xFFFF_0000));
10621070
bx.bitcast(value, bx.type_f32())
10631071
}
1064-
(PowerPC(PowerPCInlineAsmRegClass::vreg), BackendRepr::Scalar(s))
1065-
if s.primitive() == Primitive::Float(Float::F32) =>
1066-
{
1072+
(
1073+
PowerPC(PowerPCInlineAsmRegClass::vreg | PowerPCInlineAsmRegClass::vsreg),
1074+
BackendRepr::Scalar(s),
1075+
) if s.primitive() == Primitive::Float(Float::F32) => {
10671076
let value = bx.insert_element(
10681077
bx.const_undef(bx.type_vector(bx.type_f32(), 4)),
10691078
value,
10701079
bx.const_usize(0),
10711080
);
10721081
bx.bitcast(value, bx.type_vector(bx.type_f32(), 4))
10731082
}
1074-
(PowerPC(PowerPCInlineAsmRegClass::vreg), BackendRepr::Scalar(s))
1075-
if s.primitive() == Primitive::Float(Float::F64) =>
1076-
{
1083+
(
1084+
PowerPC(PowerPCInlineAsmRegClass::vreg | PowerPCInlineAsmRegClass::vsreg),
1085+
BackendRepr::Scalar(s),
1086+
) if s.primitive() == Primitive::Float(Float::F64) => {
10771087
let value = bx.insert_element(
10781088
bx.const_undef(bx.type_vector(bx.type_f64(), 2)),
10791089
value,
@@ -1224,15 +1234,17 @@ fn llvm_fixup_output<'ll, 'tcx>(
12241234
let value = bx.trunc(value, bx.type_i16());
12251235
bx.bitcast(value, bx.type_f16())
12261236
}
1227-
(PowerPC(PowerPCInlineAsmRegClass::vreg), BackendRepr::Scalar(s))
1228-
if s.primitive() == Primitive::Float(Float::F32) =>
1229-
{
1237+
(
1238+
PowerPC(PowerPCInlineAsmRegClass::vreg | PowerPCInlineAsmRegClass::vsreg),
1239+
BackendRepr::Scalar(s),
1240+
) if s.primitive() == Primitive::Float(Float::F32) => {
12301241
let value = bx.bitcast(value, bx.type_vector(bx.type_f32(), 4));
12311242
bx.extract_element(value, bx.const_usize(0))
12321243
}
1233-
(PowerPC(PowerPCInlineAsmRegClass::vreg), BackendRepr::Scalar(s))
1234-
if s.primitive() == Primitive::Float(Float::F64) =>
1235-
{
1244+
(
1245+
PowerPC(PowerPCInlineAsmRegClass::vreg | PowerPCInlineAsmRegClass::vsreg),
1246+
BackendRepr::Scalar(s),
1247+
) if s.primitive() == Primitive::Float(Float::F64) => {
12361248
let value = bx.bitcast(value, bx.type_vector(bx.type_f64(), 2));
12371249
bx.extract_element(value, bx.const_usize(0))
12381250
}
@@ -1366,16 +1378,14 @@ fn llvm_fixup_output_type<'ll, 'tcx>(
13661378
{
13671379
cx.type_f32()
13681380
}
1369-
(PowerPC(PowerPCInlineAsmRegClass::vreg), BackendRepr::Scalar(s))
1370-
if s.primitive() == Primitive::Float(Float::F32) =>
1371-
{
1372-
cx.type_vector(cx.type_f32(), 4)
1373-
}
1374-
(PowerPC(PowerPCInlineAsmRegClass::vreg), BackendRepr::Scalar(s))
1375-
if s.primitive() == Primitive::Float(Float::F64) =>
1376-
{
1377-
cx.type_vector(cx.type_f64(), 2)
1378-
}
1381+
(
1382+
PowerPC(PowerPCInlineAsmRegClass::vreg | PowerPCInlineAsmRegClass::vsreg),
1383+
BackendRepr::Scalar(s),
1384+
) if s.primitive() == Primitive::Float(Float::F32) => cx.type_vector(cx.type_f32(), 4),
1385+
(
1386+
PowerPC(PowerPCInlineAsmRegClass::vreg | PowerPCInlineAsmRegClass::vsreg),
1387+
BackendRepr::Scalar(s),
1388+
) if s.primitive() == Primitive::Float(Float::F64) => cx.type_vector(cx.type_f64(), 2),
13791389
_ => layout.llvm_type(cx),
13801390
}
13811391
}

compiler/rustc_hir/src/attrs/data_structures.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ pub enum AttributeKind {
516516
/// Represents `#[rustc_do_not_implement_via_object]`.
517517
DoNotImplementViaObject(Span),
518518

519-
/// Represents [`#[doc]`](https://doc.rust-lang.org/stable/rustdoc/write-documentation/the-doc-attribute.html).
519+
/// Represents [`#[doc = "..."]`](https://doc.rust-lang.org/stable/rustdoc/write-documentation/the-doc-attribute.html).
520520
DocComment { style: AttrStyle, kind: CommentKind, span: Span, comment: Symbol },
521521

522522
/// Represents `#[rustc_dummy]`.

compiler/rustc_passes/src/check_attr.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
179179
Attribute::Parsed(AttributeKind::AllowConstFnUnstable(_, first_span)) => {
180180
self.check_rustc_allow_const_fn_unstable(hir_id, *first_span, span, target)
181181
}
182-
Attribute::Parsed(AttributeKind::Deprecation { .. }) => {
183-
self.check_deprecated(hir_id, attr, span, target)
182+
Attribute::Parsed(AttributeKind::Deprecation {span: attr_span, .. }) => {
183+
self.check_deprecated(hir_id, *attr_span, target)
184184
}
185185
Attribute::Parsed(AttributeKind::TargetFeature{ attr_span, ..}) => {
186186
self.check_target_feature(hir_id, *attr_span, target, attrs)
@@ -1872,7 +1872,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
18721872
}
18731873
}
18741874

1875-
fn check_deprecated(&self, hir_id: HirId, attr: &Attribute, _span: Span, target: Target) {
1875+
fn check_deprecated(&self, hir_id: HirId, attr_span: Span, target: Target) {
18761876
match target {
18771877
Target::AssocConst | Target::Method(..) | Target::AssocTy
18781878
if matches!(
@@ -1883,8 +1883,8 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
18831883
self.tcx.emit_node_span_lint(
18841884
UNUSED_ATTRIBUTES,
18851885
hir_id,
1886-
attr.span(),
1887-
errors::DeprecatedAnnotationHasNoEffect { span: attr.span() },
1886+
attr_span,
1887+
errors::DeprecatedAnnotationHasNoEffect { span: attr_span },
18881888
);
18891889
}
18901890
_ => {}

compiler/rustc_resolve/src/build_reduced_graph.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
8787
// because they can be fetched by glob imports from those modules, and bring traits
8888
// into scope both directly and through glob imports.
8989
let key = BindingKey::new_disambiguated(ident, ns, || {
90-
// FIXME(batched): Will be fixed in batched resolution.
9190
parent.underscore_disambiguator.update_unchecked(|d| d + 1);
9291
parent.underscore_disambiguator.get()
9392
});
9493
if self
9594
.resolution_or_default(parent, key)
96-
.borrow_mut()
95+
.borrow_mut_unchecked()
9796
.non_glob_binding
9897
.replace(binding)
9998
.is_some()
@@ -499,7 +498,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
499498
if !type_ns_only || ns == TypeNS {
500499
let key = BindingKey::new(target, ns);
501500
this.resolution_or_default(current_module, key)
502-
.borrow_mut()
501+
.borrow_mut(this)
503502
.single_imports
504503
.insert(import);
505504
}

compiler/rustc_resolve/src/check_unused.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ impl Resolver<'_, '_> {
507507

508508
let unused_imports = visitor.unused_imports;
509509
let mut check_redundant_imports = FxIndexSet::default();
510-
for module in self.arenas.local_modules().iter() {
510+
for module in &self.local_modules {
511511
for (_key, resolution) in self.resolutions(*module).borrow().iter() {
512512
if let Some(binding) = resolution.borrow().best_binding()
513513
&& let NameBindingKind::Import { import, .. } = binding.kind

compiler/rustc_resolve/src/ident.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
891891
// the exclusive access infinite recursion will crash the compiler with stack overflow.
892892
let resolution = &*self
893893
.resolution_or_default(module, key)
894-
.try_borrow_mut()
894+
.try_borrow_mut_unchecked()
895895
.map_err(|_| (Determined, Weak::No))?;
896896

897897
// If the primary binding is unusable, search further and return the shadowed glob

compiler/rustc_resolve/src/imports.rs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_data_structures::intern::Interned;
88
use rustc_errors::codes::*;
99
use rustc_errors::{Applicability, MultiSpan, pluralize, struct_span_code_err};
1010
use rustc_hir::def::{self, DefKind, PartialRes};
11-
use rustc_hir::def_id::DefId;
11+
use rustc_hir::def_id::{DefId, LocalDefIdMap};
1212
use rustc_middle::metadata::{ModChild, Reexport};
1313
use rustc_middle::span_bug;
1414
use rustc_middle::ty::Visibility;
@@ -320,7 +320,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
320320
&& (vis == import_vis
321321
|| max_vis.get().is_none_or(|max_vis| vis.is_at_least(max_vis, self.tcx)))
322322
{
323-
// FIXME(batched): Will be fixed in batched import resolution.
324323
max_vis.set_unchecked(Some(vis.expect_local()))
325324
}
326325

@@ -350,7 +349,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
350349
// because they can be fetched by glob imports from those modules, and bring traits
351350
// into scope both directly and through glob imports.
352351
let key = BindingKey::new_disambiguated(ident, ns, || {
353-
// FIXME(batched): Will be fixed in batched resolution.
354352
module.underscore_disambiguator.update_unchecked(|d| d + 1);
355353
module.underscore_disambiguator.get()
356354
});
@@ -470,7 +468,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
470468
// Ensure that `resolution` isn't borrowed when defining in the module's glob importers,
471469
// during which the resolution might end up getting re-defined via a glob cycle.
472470
let (binding, t, warn_ambiguity) = {
473-
let resolution = &mut *self.resolution_or_default(module, key).borrow_mut();
471+
let resolution = &mut *self.resolution_or_default(module, key).borrow_mut_unchecked();
474472
let old_binding = resolution.binding();
475473

476474
let t = f(self, resolution);
@@ -553,12 +551,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
553551
/// Resolves all imports for the crate. This method performs the fixed-
554552
/// point iteration.
555553
pub(crate) fn resolve_imports(&mut self) {
556-
self.assert_speculative = true;
557554
let mut prev_indeterminate_count = usize::MAX;
558555
let mut indeterminate_count = self.indeterminate_imports.len() * 3;
559556
while indeterminate_count < prev_indeterminate_count {
560557
prev_indeterminate_count = indeterminate_count;
561558
indeterminate_count = 0;
559+
self.assert_speculative = true;
562560
for import in mem::take(&mut self.indeterminate_imports) {
563561
let import_indeterminate_count = self.cm().resolve_import(import);
564562
indeterminate_count += import_indeterminate_count;
@@ -567,14 +565,16 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
567565
_ => self.indeterminate_imports.push(import),
568566
}
569567
}
568+
self.assert_speculative = false;
570569
}
571-
self.assert_speculative = false;
572570
}
573571

574572
pub(crate) fn finalize_imports(&mut self) {
575-
for module in self.arenas.local_modules().iter() {
576-
self.finalize_resolutions_in(*module);
573+
let mut module_children = Default::default();
574+
for module in &self.local_modules {
575+
self.finalize_resolutions_in(*module, &mut module_children);
577576
}
577+
self.module_children = module_children;
578578

579579
let mut seen_spans = FxHashSet::default();
580580
let mut errors = vec![];
@@ -651,7 +651,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
651651
}
652652

653653
pub(crate) fn lint_reexports(&mut self, exported_ambiguities: FxHashSet<NameBinding<'ra>>) {
654-
for module in self.arenas.local_modules().iter() {
654+
for module in &self.local_modules {
655655
for (key, resolution) in self.resolutions(*module).borrow().iter() {
656656
let resolution = resolution.borrow();
657657
let Some(binding) = resolution.best_binding() else { continue };
@@ -860,15 +860,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
860860
}
861861
};
862862

863-
// FIXME(batched): Will be fixed in batched import resolution.
864863
import.imported_module.set_unchecked(Some(module));
865864
let (source, target, bindings, type_ns_only) = match import.kind {
866865
ImportKind::Single { source, target, ref bindings, type_ns_only, .. } => {
867866
(source, target, bindings, type_ns_only)
868867
}
869868
ImportKind::Glob { .. } => {
870-
// FIXME: Use mutable resolver directly as a hack, this should be an output of
871-
// speculative resolution.
872869
self.get_mut_unchecked().resolve_glob_import(import);
873870
return 0;
874871
}
@@ -904,8 +901,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
904901
}
905902
// We need the `target`, `source` can be extracted.
906903
let imported_binding = this.import(binding, import);
907-
// FIXME: Use mutable resolver directly as a hack, this should be an output of
908-
// speculative resolution.
909904
this.get_mut_unchecked().define_binding_local(
910905
parent,
911906
target,
@@ -918,8 +913,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
918913
// Don't remove underscores from `single_imports`, they were never added.
919914
if target.name != kw::Underscore {
920915
let key = BindingKey::new(target, ns);
921-
// FIXME: Use mutable resolver directly as a hack, this should be an output of
922-
// speculative resolution.
923916
this.get_mut_unchecked().update_local_resolution(
924917
parent,
925918
key,
@@ -936,7 +929,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
936929
PendingBinding::Pending
937930
}
938931
};
939-
// FIXME(batched): Will be fixed in batched import resolution.
940932
bindings[ns].set_unchecked(binding);
941933
}
942934
});
@@ -1548,7 +1540,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
15481540

15491541
// Miscellaneous post-processing, including recording re-exports,
15501542
// reporting conflicts, and reporting unresolved imports.
1551-
fn finalize_resolutions_in(&mut self, module: Module<'ra>) {
1543+
fn finalize_resolutions_in(
1544+
&self,
1545+
module: Module<'ra>,
1546+
module_children: &mut LocalDefIdMap<Vec<ModChild>>,
1547+
) {
15521548
// Since import resolution is finished, globs will not define any more names.
15531549
*module.globs.borrow_mut(self) = Vec::new();
15541550

@@ -1573,7 +1569,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
15731569

15741570
if !children.is_empty() {
15751571
// Should be fine because this code is only called for local modules.
1576-
self.module_children.insert(def_id.expect_local(), children);
1572+
module_children.insert(def_id.expect_local(), children);
15771573
}
15781574
}
15791575
}

0 commit comments

Comments
 (0)