Skip to content

Commit d0bc013

Browse files
committed
Auto merge of #162975 - JonathanBrouwer:rollup-S1YbZhb, r=JonathanBrouwer
Rollup of 8 pull requests Successful merges: - #160859 (`core::num::f16b` Rust's 16bit Brain Float) - #162177 (Properly implement the gpu-kernel ABI for amdgpu) - #162591 (Move parse error recovery for expression operators "out of line" & refactor in the area) - #162733 (Add useful APIs to `Unique(Arc|Rc)`) - #162950 (More AST lowering cleanups) - #162964 (Update `browser-ui-test` version to `0.25.2`) - #162797 (yeet AliasConstKind::opt_def_id) - #162836 (Ping T-libs-ping instead of T-libs-fcp for backports)
2 parents 420ed2a + d2d7897 commit d0bc013

101 files changed

Lines changed: 2251 additions & 871 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_abi/src/layout/ty.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,8 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
233233
}
234234

235235
/// If this method returns `true`, then this type should always have a `PassMode` of
236-
/// `Indirect { on_stack: false, .. }` when being used as the argument type of a function with a
237-
/// non-Rustic ABI (this is true for structs annotated with the
236+
/// `Indirect { mode: IndirectMode::Pointer, .. }` when being used as the argument type of a
237+
/// function with a non-Rustic ABI (this is true for structs annotated with the
238238
/// `#[rustc_pass_indirectly_in_non_rustic_abis]` attribute).
239239
///
240240
/// This is used to replicate some of the behaviour of C array-to-pointer decay; however unlike
@@ -342,7 +342,7 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
342342
Primitive::Float(float @ (Float::F16 | Float::F32 | Float::F64 | Float::F128)) => {
343343
Some(Numeric::Float(float))
344344
}
345-
Primitive::Pointer(..) => None,
345+
Primitive::Pointer(..) | Primitive::Float(Float::F16B) => None,
346346
}
347347
}
348348

compiler/rustc_abi/src/lib.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1420,6 +1420,10 @@ impl Integer {
14201420
#[cfg_attr(feature = "nightly", derive(StableHash))]
14211421
pub enum Float {
14221422
F16,
1423+
/// `f16b`. This is not a builtin type in Rust (it is exposed as a lang item),
1424+
/// but it is a builtin type in LLVM so needs to be explicitly represented
1425+
/// in the backend.
1426+
F16B,
14231427
F32,
14241428
F64,
14251429
F128,
@@ -1431,6 +1435,7 @@ impl Float {
14311435

14321436
match self {
14331437
F16 => Size::from_bits(16),
1438+
F16B => Size::from_bits(16),
14341439
F32 => Size::from_bits(32),
14351440
F64 => Size::from_bits(64),
14361441
F128 => Size::from_bits(128),
@@ -1442,7 +1447,7 @@ impl Float {
14421447
let dl = cx.data_layout();
14431448

14441449
AbiAlign::new(match self {
1445-
F16 => dl.f16_align,
1450+
F16 | F16B => dl.f16_align,
14461451
F32 => dl.f32_align,
14471452
F64 => dl.f64_align,
14481453
F128 => dl.f128_align,
@@ -1454,6 +1459,7 @@ impl Float {
14541459

14551460
match self {
14561461
F16 => "f16",
1462+
F16B => "f16b",
14571463
F32 => "f32",
14581464
F64 => "f64",
14591465
F128 => "f128",
@@ -1772,6 +1778,10 @@ pub struct AddressSpace(pub u32);
17721778
impl AddressSpace {
17731779
/// LLVM's `0` address space.
17741780
pub const ZERO: Self = AddressSpace(0);
1781+
/// The address space for constant memory on nvptx and amdgpu.
1782+
/// This address space is used e.g. for kernel arguments that are constant throughout the
1783+
/// execution.
1784+
pub const GPU_CONSTANT: Self = AddressSpace(4);
17751785
/// The address space for workgroup memory on nvptx and amdgpu.
17761786
/// See e.g. the `gpu_launch_sized_workgroup_mem` intrinsic for details.
17771787
pub const GPU_WORKGROUP: Self = AddressSpace(3);

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
10181018
expr.span,
10191019
hir::ExprKind::Err(self.dcx().emit_err(AwaitOnlyInAsyncFnAndBlocks {
10201020
await_kw_span,
1021-
item_span: self.current_item,
1021+
item_span: self.current_item_span,
10221022
})),
10231023
);
10241024
return hir::ExprKind::Block(
@@ -1712,7 +1712,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
17121712
}
17131713
Some(hir::CoroutineKind::Coroutine(_)) => false,
17141714
None => {
1715-
let suggestion = self.current_item.map(|s| s.shrink_to_lo());
1715+
let suggestion = self.current_item_span.map(|s| s.shrink_to_lo());
17161716
self.dcx().emit_err(YieldInClosure { span, suggestion });
17171717
self.coroutine_kind = Some(hir::CoroutineKind::Coroutine(Movability::Movable));
17181718

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 9 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@ use rustc_errors::{E0570, ErrorGuaranteed, struct_span_code_err};
55
use rustc_hir::attrs::{AttributeKind, EiiImplResolution};
66
use rustc_hir::def::{DefKind, PerNS, Res};
77
use rustc_hir::{
8-
self as hir, CRATE_OWNER_ID, HirId, ImplItemImplKind, LifetimeSource, PredicateOrigin, Target,
9-
find_attr,
8+
self as hir, HirId, ImplItemImplKind, LifetimeSource, PredicateOrigin, Target, find_attr,
109
};
11-
use rustc_middle::middle::resolve::ResolverAstLowering;
12-
use rustc_middle::ty::TyCtxt;
1310
use rustc_middle::ty::data_structures::IndexMap;
1411
use rustc_span::def_id::{DefId, LocalDefId};
1512
use rustc_span::edit_distance::find_best_match_for_name;
@@ -28,14 +25,9 @@ use super::{
2825
};
2926
use crate::diagnostics::{ConstComptimeFn, ResolvingRestrictionKind, RestrictionAncestorOnly};
3027

31-
pub(super) struct ItemLowerer<'a, 'hir> {
32-
pub(super) tcx: TyCtxt<'hir>,
33-
pub(super) resolver: &'a ResolverAstLowering<'hir>,
34-
}
35-
36-
/// When we have a ty alias we *may* have two where clauses. To give the best diagnostics, we set the span
37-
/// to the where clause that is preferred, if it exists. Otherwise, it sets the span to the other where
38-
/// clause if it exists.
28+
/// When we have a ty alias we *may* have two where clauses. To give the best diagnostics, we set
29+
/// the span to the where clause that is preferred, if it exists. Otherwise, it sets the span to
30+
/// the other where clause if it exists.
3931
fn add_ty_alias_where_clause(
4032
generics: &mut ast::Generics,
4133
after_where_clause: &ast::WhereClause,
@@ -52,48 +44,6 @@ fn add_ty_alias_where_clause(
5244
if before.0 || !after.0 { before } else { after };
5345
}
5446

55-
impl<'hir> ItemLowerer<'_, 'hir> {
56-
fn with_lctx(
57-
&mut self,
58-
owner: NodeId,
59-
f: impl FnOnce(&mut LoweringContext<'_, 'hir>) -> hir::OwnerNode<'hir>,
60-
) -> hir::MaybeOwner<'hir> {
61-
let mut lctx = LoweringContext::new(self.tcx, self.resolver, owner);
62-
63-
let item = f(&mut lctx);
64-
65-
let info = lctx.curr_owner.into_owner_info(self.tcx, item);
66-
hir::MaybeOwner::Owner(lctx.arena.alloc(info))
67-
}
68-
69-
#[instrument(level = "debug", skip(self, c))]
70-
pub(super) fn lower_crate(&mut self, c: &Crate) -> hir::MaybeOwner<'hir> {
71-
self.with_lctx(CRATE_NODE_ID, |lctx| {
72-
debug_assert_eq!(lctx.curr_owner.owner_id(), CRATE_OWNER_ID);
73-
let module = lctx.lower_mod(&c.items, &c.spans);
74-
lctx.lower_attrs(hir::CRATE_HIR_ID, &c.attrs, c.spans.inner_span, Target::Crate);
75-
hir::OwnerNode::Crate(module)
76-
})
77-
}
78-
79-
#[instrument(level = "debug", skip(self))]
80-
pub(super) fn lower_item(&mut self, item: &Item) -> hir::MaybeOwner<'hir> {
81-
self.with_lctx(item.id, |lctx| hir::OwnerNode::Item(lctx.lower_item(item)))
82-
}
83-
84-
pub(super) fn lower_trait_item(&mut self, item: &AssocItem) -> hir::MaybeOwner<'hir> {
85-
self.with_lctx(item.id, |lctx| hir::OwnerNode::TraitItem(lctx.lower_trait_item(item)))
86-
}
87-
88-
pub(super) fn lower_impl_item(&mut self, item: &AssocItem) -> hir::MaybeOwner<'hir> {
89-
self.with_lctx(item.id, |lctx| hir::OwnerNode::ImplItem(lctx.lower_impl_item(item)))
90-
}
91-
92-
pub(super) fn lower_foreign_item(&mut self, item: &ForeignItem) -> hir::MaybeOwner<'hir> {
93-
self.with_lctx(item.id, |lctx| hir::OwnerNode::ForeignItem(lctx.lower_foreign_item(item)))
94-
}
95-
}
96-
9747
impl<'hir> LoweringContext<'_, 'hir> {
9848
pub(super) fn lower_mod(
9949
&mut self,
@@ -203,7 +153,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
203153
}
204154
}
205155

206-
fn lower_item(&mut self, i: &Item) -> &'hir hir::Item<'hir> {
156+
pub(super) fn lower_item(&mut self, i: &Item) -> &'hir hir::Item<'hir> {
207157
let owner_id = self.curr_owner.owner_id();
208158
let hir_id: HirId = owner_id.into();
209159
let vis_span = self.lower_span(i.vis.span);
@@ -544,7 +494,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
544494
}
545495
ItemKind::MacroDef(ident, MacroDef { body, macro_rules, eii_declaration: _ }) => {
546496
let ident = self.lower_ident(*ident);
547-
let body = Box::new(self.lower_delim_args(body));
497+
let body = body.clone();
548498
let def_id = self.curr_owner.owner.def_id;
549499
let def_kind = self.tcx.def_kind(def_id);
550500
let DefKind::Macro(macro_kinds) = def_kind else {
@@ -730,7 +680,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
730680
}
731681
}
732682

733-
fn lower_foreign_item(&mut self, i: &ForeignItem) -> &'hir hir::ForeignItem<'hir> {
683+
pub(super) fn lower_foreign_item(&mut self, i: &ForeignItem) -> &'hir hir::ForeignItem<'hir> {
734684
let owner_id = self.curr_owner.owner_id();
735685
let hir_id: HirId = owner_id.into();
736686
let attrs =
@@ -911,7 +861,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
911861
}
912862
}
913863

914-
fn lower_trait_item(&mut self, i: &AssocItem) -> &'hir hir::TraitItem<'hir> {
864+
pub(super) fn lower_trait_item(&mut self, i: &AssocItem) -> &'hir hir::TraitItem<'hir> {
915865
let trait_item_def_id = self.curr_owner.owner_id();
916866
let hir_id: HirId = trait_item_def_id.into();
917867
let attrs = self.lower_attrs(
@@ -1160,7 +1110,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
11601110
ident
11611111
}
11621112

1163-
fn lower_impl_item(&mut self, i: &AssocItem) -> &'hir hir::ImplItem<'hir> {
1113+
pub(super) fn lower_impl_item(&mut self, i: &AssocItem) -> &'hir hir::ImplItem<'hir> {
11641114
let owner_id = self.curr_owner.owner_id();
11651115
let hir_id: HirId = owner_id.into();
11661116
let parent_id = self.tcx.local_parent(owner_id.def_id);

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ use rustc_hir::def_id::{DefId, LOCAL_CRATE, LocalDefId, LocalDefIdMap};
6060
use rustc_hir::definitions::PerParentDisambiguatorState;
6161
use rustc_hir::lints::DelayedLint;
6262
use rustc_hir::{
63-
self as hir, AngleBrackets, ConstArg, GenericArg, HirId, ItemLocalMap, LifetimeSource,
64-
LifetimeSyntax, MissingLifetimeKind, ParamName, Target, TraitCandidate, find_attr,
63+
self as hir, AngleBrackets, CRATE_OWNER_ID, ConstArg, GenericArg, HirId, ItemLocalMap,
64+
LifetimeSource, LifetimeSyntax, MissingLifetimeKind, ParamName, Target, TraitCandidate,
65+
find_attr,
6566
};
6667
use rustc_index::{Idx, IndexSlice, IndexVec};
6768
use rustc_macros::extension;
@@ -296,7 +297,7 @@ struct LoweringContext<'a, 'hir> {
296297

297298
/// Used to get the current `fn`'s def span to point to when using `await`
298299
/// outside of an `async fn`.
299-
current_item: Option<Span>,
300+
current_item_span: Option<Span>,
300301

301302
try_block_scope: TryBlockScope,
302303
loop_scope: Option<HirId>,
@@ -366,7 +367,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
366367
is_in_dyn_type: false,
367368
coroutine_kind: None,
368369
task_context: None,
369-
current_item: None,
370+
current_item_span: None,
370371

371372
move_expr_bindings: Vec::new(),
372373
lowering_move_expr_initializer: false,
@@ -783,15 +784,37 @@ fn lower_to_hir(tcx: TyCtxt<'_>, def_id: LocalDefId) -> hir::MaybeOwner<'_> {
783784
return fallback_to_ancestor(tcx.local_parent(def_id));
784785
};
785786

786-
let mut item_lowerer = item::ItemLowerer { tcx, resolver: &*resolver };
787+
fn with_lctx<'hir>(
788+
tcx: TyCtxt<'hir>,
789+
resolver: &ResolverAstLowering<'hir>,
790+
owner: NodeId,
791+
f: impl FnOnce(&mut LoweringContext<'_, 'hir>) -> hir::OwnerNode<'hir>,
792+
) -> hir::MaybeOwner<'hir> {
793+
let mut lctx = LoweringContext::new(tcx, resolver, owner);
794+
let item = f(&mut lctx);
795+
hir::MaybeOwner::Owner(lctx.curr_owner.into_owner_info(tcx, item))
796+
}
787797

788798
let item = match &node {
789799
// The item existed in the AST.
790-
AstOwner::Crate(c) => item_lowerer.lower_crate(&c),
791-
AstOwner::Item(item) => item_lowerer.lower_item(&item),
792-
AstOwner::TraitItem(item) => item_lowerer.lower_trait_item(&item),
793-
AstOwner::ImplItem(item) => item_lowerer.lower_impl_item(&item),
794-
AstOwner::ForeignItem(item) => item_lowerer.lower_foreign_item(&item),
800+
AstOwner::Crate(c) => with_lctx(tcx, &*resolver, CRATE_NODE_ID, |lctx| {
801+
debug_assert_eq!(lctx.curr_owner.owner_id(), CRATE_OWNER_ID);
802+
let module = lctx.lower_mod(&c.items, &c.spans);
803+
lctx.lower_attrs(hir::CRATE_HIR_ID, &c.attrs, c.spans.inner_span, Target::Crate);
804+
hir::OwnerNode::Crate(module)
805+
}),
806+
AstOwner::Item(item) => {
807+
with_lctx(tcx, &*resolver, item.id, |lctx| hir::OwnerNode::Item(lctx.lower_item(item)))
808+
}
809+
AstOwner::TraitItem(item) => with_lctx(tcx, &*resolver, item.id, |lctx| {
810+
hir::OwnerNode::TraitItem(lctx.lower_trait_item(item))
811+
}),
812+
AstOwner::ImplItem(item) => with_lctx(tcx, &*resolver, item.id, |lctx| {
813+
hir::OwnerNode::ImplItem(lctx.lower_impl_item(item))
814+
}),
815+
AstOwner::ForeignItem(item) => with_lctx(tcx, &*resolver, item.id, |lctx| {
816+
hir::OwnerNode::ForeignItem(lctx.lower_foreign_item(item))
817+
}),
795818
AstOwner::NestedUseTree(owner_id) => fallback_to_ancestor(*owner_id),
796819
// The item existed in the AST, but is not a HIR owner.
797820
// Fetch the correct information from its parent.
@@ -824,7 +847,7 @@ enum GenericArgsMode {
824847
ParenSugar,
825848
/// Allow RTN, don't allow paren sugar.
826849
ReturnTypeNotation,
827-
// Error if parenthesized generics or RTN are encountered.
850+
/// Error if parenthesized generics or RTN are encountered.
828851
Err,
829852
/// Silence errors when lowering generics. Only used with `Res::Err`.
830853
Silence,
@@ -982,7 +1005,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
9821005
}
9831006

9841007
#[instrument(level = "trace", skip(self))]
985-
fn lower_res(&mut self, res: Res<NodeId>) -> Res {
1008+
fn lower_res(&self, res: Res<NodeId>) -> Res {
9861009
let res: Result<Res, ()> = res.apply_id(|id| {
9871010
let owner = self.curr_owner.owner_id();
9881011
let local_id =
@@ -999,11 +1022,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
9991022
res.unwrap_or(Res::Err)
10001023
}
10011024

1002-
fn expect_full_res(&mut self, id: NodeId) -> Res<NodeId> {
1025+
fn expect_full_res(&self, id: NodeId) -> Res<NodeId> {
10031026
self.get_partial_res(id).map_or(Res::Err, |pr| pr.expect_full_res())
10041027
}
10051028

1006-
fn lower_import_res(&mut self, id: NodeId, span: Span) -> PerNS<Option<Res>> {
1029+
fn lower_import_res(&self, id: NodeId, span: Span) -> PerNS<Option<Res>> {
10071030
debug_assert_eq!(id, self.curr_owner.owner.id);
10081031
let per_ns = self.curr_owner.owner.import_res.map(|res| res.map(|res| self.lower_res(res)));
10091032
if per_ns.is_empty() {
@@ -1154,8 +1177,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
11541177
}
11551178

11561179
fn with_new_scopes<T>(&mut self, scope_span: Span, f: impl FnOnce(&mut Self) -> T) -> T {
1157-
let current_item = self.current_item;
1158-
self.current_item = Some(scope_span);
1180+
let current_item_span = self.current_item_span;
1181+
self.current_item_span = Some(scope_span);
11591182

11601183
let was_in_loop_condition = self.is_in_loop_condition;
11611184
self.is_in_loop_condition = false;
@@ -1172,7 +1195,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
11721195

11731196
self.is_in_loop_condition = was_in_loop_condition;
11741197

1175-
self.current_item = current_item;
1198+
self.current_item_span = current_item_span;
11761199

11771200
ret
11781201
}
@@ -1261,10 +1284,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
12611284
}
12621285
}
12631286

1264-
fn lower_delim_args(&self, args: &DelimArgs) -> DelimArgs {
1265-
args.clone()
1266-
}
1267-
12681287
/// Lower an associated item constraint.
12691288
#[instrument(level = "debug", skip_all)]
12701289
fn lower_assoc_item_constraint(
@@ -1647,8 +1666,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
16471666
self.lower_array_length_to_const_arg(length),
16481667
),
16491668
TyKind::TraitObject(bounds, kind) => {
1650-
let mut lifetime_bound = None;
16511669
let (bounds, lifetime_bound) = self.with_dyn_type_scope(true, |this| {
1670+
let mut lifetime_bound = None;
16521671
let bounds =
16531672
this.arena.alloc_from_iter(bounds.iter().filter_map(|bound| match bound {
16541673
// We can safely ignore constness here since AST validation
@@ -1681,9 +1700,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
16811700
None
16821701
}
16831702
}));
1684-
let lifetime_bound =
1685-
lifetime_bound.unwrap_or_else(|| this.elided_dyn_bound(t.span));
1686-
(bounds, lifetime_bound)
1703+
(bounds, lifetime_bound.unwrap_or_else(|| this.elided_dyn_bound(t.span)))
16871704
});
16881705
hir::TyKind::TraitObject(bounds, TaggedRef::new(lifetime_bound, *kind))
16891706
}
@@ -3058,15 +3075,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
30583075
}))
30593076
}
30603077

3061-
fn lower_unsafe_source(&mut self, u: UnsafeSource) -> hir::UnsafeSource {
3078+
fn lower_unsafe_source(&self, u: UnsafeSource) -> hir::UnsafeSource {
30623079
match u {
30633080
CompilerGenerated => hir::UnsafeSource::CompilerGenerated,
30643081
UserProvided => hir::UnsafeSource::UserProvided,
30653082
}
30663083
}
30673084

30683085
fn lower_trait_bound_modifiers(
3069-
&mut self,
3086+
&self,
30703087
modifiers: TraitBoundModifiers,
30713088
) -> hir::TraitBoundModifiers {
30723089
let constness = match modifiers.constness {

compiler/rustc_attr_ir/src/lang_items.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ language_item_table! {
281281
PartialEq, sym::eq, eq_trait, Target::Trait, GenericRequirement::Exact(1);
282282
PartialOrd, sym::partial_ord, partial_ord_trait, Target::Trait, GenericRequirement::Exact(1);
283283
CVoid, sym::c_void, c_void, Target::Enum, GenericRequirement::None;
284+
F16B, sym::f16b, f16b, Target::Struct, GenericRequirement::Exact(0);
284285

285286
Type, sym::type_info, type_struct, Target::Struct, GenericRequirement::None;
286287
TypeGeneric, sym::type_info_generic, type_generic, Target::Enum, GenericRequirement::None;

0 commit comments

Comments
 (0)