Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
1629bcd
Add useful APIs to `Unique(Arc|Rc)`
maxdexh Sep 13, 2026
a1864bd
Ping T-libs-ping instead of T-libs-fcp for backports
clarfonthey Sep 16, 2026
085678a
Add address_space and byref to abi PassMode::Indirect
Flakebi Sep 1, 2026
bf91751
Pre-commit amdgpu gpu-kernel ABI test
Flakebi Sep 3, 2026
c498254
Properly implement the gpu-kernel ABI for amdgpu
Flakebi Sep 15, 2026
653076c
yeet AliasConstKind::opt_def_id
khyperia Sep 18, 2026
9e7d4b2
Don't double-allocate `OwnerInfo`
nnethercote Sep 1, 2026
9a03326
Convert some `&mut self` to `&self` in the lowerer
nnethercote Sep 1, 2026
990c292
Reduce the scope of a local
nnethercote Sep 1, 2026
9b817c5
Rename `LoweringContext::current_item`
nnethercote Sep 1, 2026
3ee39bd
Fix an inconsistent comment
nnethercote Sep 1, 2026
6e7d014
Inline and remove `lower_delim_args`
nnethercote Sep 1, 2026
11b373e
Eliminate `ItemLowerer`
nnethercote Sep 1, 2026
501bf1d
`f16b` Implementation and documentation
Jamesbarford Sep 18, 2026
47abb2a
Add `F16B` to `Float` enum & wireup trivial matches
Jamesbarford Sep 18, 2026
3e5d69e
Wire up f16b in backends
Jamesbarford Sep 18, 2026
960fdef
Update Tidy rules to allow for `//@ revision`
Jamesbarford Sep 18, 2026
c1287ce
Update and write tests
Jamesbarford Sep 18, 2026
b0f83b7
Update `browser-ui-test` version to `0.25.2`
GuillaumeGomez Sep 18, 2026
e7d3a6a
Move parse error recovery from some invalid expr ops out of line
fmease Sep 10, 2026
b945d68
Don't needlessly pass the operand through some recovery functions by …
fmease Sep 10, 2026
ceede0b
Remove odd special case of some parse error recovery functions
fmease Sep 6, 2026
6c0ab88
Dismantle bespoke diagnostic suggestion wrapper API
fmease Sep 6, 2026
ddb9380
Move parse error recovery from C-style inc/dec ops out of line
fmease Sep 10, 2026
1adccf2
Inline fns & data types related to parse error recovery from C-style …
fmease Sep 10, 2026
d85d3f5
Refactor the way we finish parsing expr ops
fmease Sep 10, 2026
f0ae097
Refactor `check_assoc_op` to make it more legible
fmease Aug 25, 2026
2815872
Don't mistake `<->` for `<>`
fmease Sep 11, 2026
7e2fbe4
Rollup merge of #160859 - Jamesbarford:feat/fb16-pt1, r=folkertdev
JonathanBrouwer Sep 18, 2026
246c9f2
Rollup merge of #162177 - Flakebi:amdgpu-kernel-cc, r=bjorn3
JonathanBrouwer Sep 18, 2026
3336bb4
Rollup merge of #162591 - fmease:out-of-line-recovery, r=petrochenkov
JonathanBrouwer Sep 18, 2026
3cb338a
Rollup merge of #162733 - maxdexh:unique-arc-pub-apis, r=nia-e
JonathanBrouwer Sep 18, 2026
54c252f
Rollup merge of #162950 - nnethercote:more-lowering-cleanups, r=spast…
JonathanBrouwer Sep 18, 2026
047170c
Rollup merge of #162964 - GuillaumeGomez:update-browser-ui-test, r=ji…
JonathanBrouwer Sep 18, 2026
1f5fbbe
Rollup merge of #162797 - khyperia:yeet-opt_def_id, r=BoxyUwU,bit-aloo
JonathanBrouwer Sep 18, 2026
d2d7897
Rollup merge of #162836 - clarfonthey:libs-ping, r=ChrisDenton
JonathanBrouwer Sep 18, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions compiler/rustc_abi/src/layout/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
}

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

Expand Down
12 changes: 11 additions & 1 deletion compiler/rustc_abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1420,6 +1420,10 @@ impl Integer {
#[cfg_attr(feature = "nightly", derive(StableHash))]
pub enum Float {
F16,
/// `f16b`. This is not a builtin type in Rust (it is exposed as a lang item),
/// but it is a builtin type in LLVM so needs to be explicitly represented
/// in the backend.
F16B,
F32,
F64,
F128,
Expand All @@ -1431,6 +1435,7 @@ impl Float {

match self {
F16 => Size::from_bits(16),
F16B => Size::from_bits(16),
F32 => Size::from_bits(32),
F64 => Size::from_bits(64),
F128 => Size::from_bits(128),
Expand All @@ -1442,7 +1447,7 @@ impl Float {
let dl = cx.data_layout();

AbiAlign::new(match self {
F16 => dl.f16_align,
F16 | F16B => dl.f16_align,
F32 => dl.f32_align,
F64 => dl.f64_align,
F128 => dl.f128_align,
Expand All @@ -1454,6 +1459,7 @@ impl Float {

match self {
F16 => "f16",
F16B => "f16b",
F32 => "f32",
F64 => "f64",
F128 => "f128",
Expand Down Expand Up @@ -1772,6 +1778,10 @@ pub struct AddressSpace(pub u32);
impl AddressSpace {
/// LLVM's `0` address space.
pub const ZERO: Self = AddressSpace(0);
/// The address space for constant memory on nvptx and amdgpu.
/// This address space is used e.g. for kernel arguments that are constant throughout the
/// execution.
pub const GPU_CONSTANT: Self = AddressSpace(4);
/// The address space for workgroup memory on nvptx and amdgpu.
/// See e.g. the `gpu_launch_sized_workgroup_mem` intrinsic for details.
pub const GPU_WORKGROUP: Self = AddressSpace(3);
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
expr.span,
hir::ExprKind::Err(self.dcx().emit_err(AwaitOnlyInAsyncFnAndBlocks {
await_kw_span,
item_span: self.current_item,
item_span: self.current_item_span,
})),
);
return hir::ExprKind::Block(
Expand Down Expand Up @@ -1712,7 +1712,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
Some(hir::CoroutineKind::Coroutine(_)) => false,
None => {
let suggestion = self.current_item.map(|s| s.shrink_to_lo());
let suggestion = self.current_item_span.map(|s| s.shrink_to_lo());
self.dcx().emit_err(YieldInClosure { span, suggestion });
self.coroutine_kind = Some(hir::CoroutineKind::Coroutine(Movability::Movable));

Expand Down
68 changes: 9 additions & 59 deletions compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ use rustc_errors::{E0570, ErrorGuaranteed, struct_span_code_err};
use rustc_hir::attrs::{AttributeKind, EiiImplResolution};
use rustc_hir::def::{DefKind, PerNS, Res};
use rustc_hir::{
self as hir, CRATE_OWNER_ID, HirId, ImplItemImplKind, LifetimeSource, PredicateOrigin, Target,
find_attr,
self as hir, HirId, ImplItemImplKind, LifetimeSource, PredicateOrigin, Target, find_attr,
};
use rustc_middle::middle::resolve::ResolverAstLowering;
use rustc_middle::ty::TyCtxt;
use rustc_middle::ty::data_structures::IndexMap;
use rustc_span::def_id::{DefId, LocalDefId};
use rustc_span::edit_distance::find_best_match_for_name;
Expand All @@ -28,14 +25,9 @@ use super::{
};
use crate::diagnostics::{ConstComptimeFn, ResolvingRestrictionKind, RestrictionAncestorOnly};

pub(super) struct ItemLowerer<'a, 'hir> {
pub(super) tcx: TyCtxt<'hir>,
pub(super) resolver: &'a ResolverAstLowering<'hir>,
}

/// When we have a ty alias we *may* have two where clauses. To give the best diagnostics, we set the span
/// to the where clause that is preferred, if it exists. Otherwise, it sets the span to the other where
/// clause if it exists.
/// When we have a ty alias we *may* have two where clauses. To give the best diagnostics, we set
/// the span to the where clause that is preferred, if it exists. Otherwise, it sets the span to
/// the other where clause if it exists.
fn add_ty_alias_where_clause(
generics: &mut ast::Generics,
after_where_clause: &ast::WhereClause,
Expand All @@ -52,48 +44,6 @@ fn add_ty_alias_where_clause(
if before.0 || !after.0 { before } else { after };
}

impl<'hir> ItemLowerer<'_, 'hir> {
fn with_lctx(
&mut self,
owner: NodeId,
f: impl FnOnce(&mut LoweringContext<'_, 'hir>) -> hir::OwnerNode<'hir>,
) -> hir::MaybeOwner<'hir> {
let mut lctx = LoweringContext::new(self.tcx, self.resolver, owner);

let item = f(&mut lctx);

let info = lctx.curr_owner.into_owner_info(self.tcx, item);
hir::MaybeOwner::Owner(lctx.arena.alloc(info))
}

#[instrument(level = "debug", skip(self, c))]
pub(super) fn lower_crate(&mut self, c: &Crate) -> hir::MaybeOwner<'hir> {
self.with_lctx(CRATE_NODE_ID, |lctx| {
debug_assert_eq!(lctx.curr_owner.owner_id(), CRATE_OWNER_ID);
let module = lctx.lower_mod(&c.items, &c.spans);
lctx.lower_attrs(hir::CRATE_HIR_ID, &c.attrs, c.spans.inner_span, Target::Crate);
hir::OwnerNode::Crate(module)
})
}

#[instrument(level = "debug", skip(self))]
pub(super) fn lower_item(&mut self, item: &Item) -> hir::MaybeOwner<'hir> {
self.with_lctx(item.id, |lctx| hir::OwnerNode::Item(lctx.lower_item(item)))
}

pub(super) fn lower_trait_item(&mut self, item: &AssocItem) -> hir::MaybeOwner<'hir> {
self.with_lctx(item.id, |lctx| hir::OwnerNode::TraitItem(lctx.lower_trait_item(item)))
}

pub(super) fn lower_impl_item(&mut self, item: &AssocItem) -> hir::MaybeOwner<'hir> {
self.with_lctx(item.id, |lctx| hir::OwnerNode::ImplItem(lctx.lower_impl_item(item)))
}

pub(super) fn lower_foreign_item(&mut self, item: &ForeignItem) -> hir::MaybeOwner<'hir> {
self.with_lctx(item.id, |lctx| hir::OwnerNode::ForeignItem(lctx.lower_foreign_item(item)))
}
}

impl<'hir> LoweringContext<'_, 'hir> {
pub(super) fn lower_mod(
&mut self,
Expand Down Expand Up @@ -203,7 +153,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
}

fn lower_item(&mut self, i: &Item) -> &'hir hir::Item<'hir> {
pub(super) fn lower_item(&mut self, i: &Item) -> &'hir hir::Item<'hir> {
let owner_id = self.curr_owner.owner_id();
let hir_id: HirId = owner_id.into();
let vis_span = self.lower_span(i.vis.span);
Expand Down Expand Up @@ -544,7 +494,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
ItemKind::MacroDef(ident, MacroDef { body, macro_rules, eii_declaration: _ }) => {
let ident = self.lower_ident(*ident);
let body = Box::new(self.lower_delim_args(body));
let body = body.clone();
let def_id = self.curr_owner.owner.def_id;
let def_kind = self.tcx.def_kind(def_id);
let DefKind::Macro(macro_kinds) = def_kind else {
Expand Down Expand Up @@ -730,7 +680,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
}

fn lower_foreign_item(&mut self, i: &ForeignItem) -> &'hir hir::ForeignItem<'hir> {
pub(super) fn lower_foreign_item(&mut self, i: &ForeignItem) -> &'hir hir::ForeignItem<'hir> {
let owner_id = self.curr_owner.owner_id();
let hir_id: HirId = owner_id.into();
let attrs =
Expand Down Expand Up @@ -911,7 +861,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
}

fn lower_trait_item(&mut self, i: &AssocItem) -> &'hir hir::TraitItem<'hir> {
pub(super) fn lower_trait_item(&mut self, i: &AssocItem) -> &'hir hir::TraitItem<'hir> {
let trait_item_def_id = self.curr_owner.owner_id();
let hir_id: HirId = trait_item_def_id.into();
let attrs = self.lower_attrs(
Expand Down Expand Up @@ -1160,7 +1110,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
ident
}

fn lower_impl_item(&mut self, i: &AssocItem) -> &'hir hir::ImplItem<'hir> {
pub(super) fn lower_impl_item(&mut self, i: &AssocItem) -> &'hir hir::ImplItem<'hir> {
let owner_id = self.curr_owner.owner_id();
let hir_id: HirId = owner_id.into();
let parent_id = self.tcx.local_parent(owner_id.def_id);
Expand Down
71 changes: 44 additions & 27 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ use rustc_hir::def_id::{DefId, LOCAL_CRATE, LocalDefId, LocalDefIdMap};
use rustc_hir::definitions::PerParentDisambiguatorState;
use rustc_hir::lints::DelayedLint;
use rustc_hir::{
self as hir, AngleBrackets, ConstArg, GenericArg, HirId, ItemLocalMap, LifetimeSource,
LifetimeSyntax, MissingLifetimeKind, ParamName, Target, TraitCandidate, find_attr,
self as hir, AngleBrackets, CRATE_OWNER_ID, ConstArg, GenericArg, HirId, ItemLocalMap,
LifetimeSource, LifetimeSyntax, MissingLifetimeKind, ParamName, Target, TraitCandidate,
find_attr,
};
use rustc_index::{Idx, IndexSlice, IndexVec};
use rustc_macros::extension;
Expand Down Expand Up @@ -296,7 +297,7 @@ struct LoweringContext<'a, 'hir> {

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

try_block_scope: TryBlockScope,
loop_scope: Option<HirId>,
Expand Down Expand Up @@ -366,7 +367,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
is_in_dyn_type: false,
coroutine_kind: None,
task_context: None,
current_item: None,
current_item_span: None,

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

let mut item_lowerer = item::ItemLowerer { tcx, resolver: &*resolver };
fn with_lctx<'hir>(
tcx: TyCtxt<'hir>,
resolver: &ResolverAstLowering<'hir>,
owner: NodeId,
f: impl FnOnce(&mut LoweringContext<'_, 'hir>) -> hir::OwnerNode<'hir>,
) -> hir::MaybeOwner<'hir> {
let mut lctx = LoweringContext::new(tcx, resolver, owner);
let item = f(&mut lctx);
hir::MaybeOwner::Owner(lctx.curr_owner.into_owner_info(tcx, item))
}

let item = match &node {
// The item existed in the AST.
AstOwner::Crate(c) => item_lowerer.lower_crate(&c),
AstOwner::Item(item) => item_lowerer.lower_item(&item),
AstOwner::TraitItem(item) => item_lowerer.lower_trait_item(&item),
AstOwner::ImplItem(item) => item_lowerer.lower_impl_item(&item),
AstOwner::ForeignItem(item) => item_lowerer.lower_foreign_item(&item),
AstOwner::Crate(c) => with_lctx(tcx, &*resolver, CRATE_NODE_ID, |lctx| {
debug_assert_eq!(lctx.curr_owner.owner_id(), CRATE_OWNER_ID);
let module = lctx.lower_mod(&c.items, &c.spans);
lctx.lower_attrs(hir::CRATE_HIR_ID, &c.attrs, c.spans.inner_span, Target::Crate);
hir::OwnerNode::Crate(module)
}),
AstOwner::Item(item) => {
with_lctx(tcx, &*resolver, item.id, |lctx| hir::OwnerNode::Item(lctx.lower_item(item)))
}
AstOwner::TraitItem(item) => with_lctx(tcx, &*resolver, item.id, |lctx| {
hir::OwnerNode::TraitItem(lctx.lower_trait_item(item))
}),
AstOwner::ImplItem(item) => with_lctx(tcx, &*resolver, item.id, |lctx| {
hir::OwnerNode::ImplItem(lctx.lower_impl_item(item))
}),
AstOwner::ForeignItem(item) => with_lctx(tcx, &*resolver, item.id, |lctx| {
hir::OwnerNode::ForeignItem(lctx.lower_foreign_item(item))
}),
AstOwner::NestedUseTree(owner_id) => fallback_to_ancestor(*owner_id),
// The item existed in the AST, but is not a HIR owner.
// Fetch the correct information from its parent.
Expand Down Expand Up @@ -824,7 +847,7 @@ enum GenericArgsMode {
ParenSugar,
/// Allow RTN, don't allow paren sugar.
ReturnTypeNotation,
// Error if parenthesized generics or RTN are encountered.
/// Error if parenthesized generics or RTN are encountered.
Err,
/// Silence errors when lowering generics. Only used with `Res::Err`.
Silence,
Expand Down Expand Up @@ -982,7 +1005,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
}

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

fn expect_full_res(&mut self, id: NodeId) -> Res<NodeId> {
fn expect_full_res(&self, id: NodeId) -> Res<NodeId> {
self.get_partial_res(id).map_or(Res::Err, |pr| pr.expect_full_res())
}

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

fn with_new_scopes<T>(&mut self, scope_span: Span, f: impl FnOnce(&mut Self) -> T) -> T {
let current_item = self.current_item;
self.current_item = Some(scope_span);
let current_item_span = self.current_item_span;
self.current_item_span = Some(scope_span);

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

self.is_in_loop_condition = was_in_loop_condition;

self.current_item = current_item;
self.current_item_span = current_item_span;

ret
}
Expand Down Expand Up @@ -1261,10 +1284,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
}

fn lower_delim_args(&self, args: &DelimArgs) -> DelimArgs {
args.clone()
}

/// Lower an associated item constraint.
#[instrument(level = "debug", skip_all)]
fn lower_assoc_item_constraint(
Expand Down Expand Up @@ -1647,8 +1666,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
self.lower_array_length_to_const_arg(length),
),
TyKind::TraitObject(bounds, kind) => {
let mut lifetime_bound = None;
let (bounds, lifetime_bound) = self.with_dyn_type_scope(true, |this| {
let mut lifetime_bound = None;
let bounds =
this.arena.alloc_from_iter(bounds.iter().filter_map(|bound| match bound {
// We can safely ignore constness here since AST validation
Expand Down Expand Up @@ -1681,9 +1700,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
None
}
}));
let lifetime_bound =
lifetime_bound.unwrap_or_else(|| this.elided_dyn_bound(t.span));
(bounds, lifetime_bound)
(bounds, lifetime_bound.unwrap_or_else(|| this.elided_dyn_bound(t.span)))
});
hir::TyKind::TraitObject(bounds, TaggedRef::new(lifetime_bound, *kind))
}
Expand Down Expand Up @@ -3058,15 +3075,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
}))
}

fn lower_unsafe_source(&mut self, u: UnsafeSource) -> hir::UnsafeSource {
fn lower_unsafe_source(&self, u: UnsafeSource) -> hir::UnsafeSource {
match u {
CompilerGenerated => hir::UnsafeSource::CompilerGenerated,
UserProvided => hir::UnsafeSource::UserProvided,
}
}

fn lower_trait_bound_modifiers(
&mut self,
&self,
modifiers: TraitBoundModifiers,
) -> hir::TraitBoundModifiers {
let constness = match modifiers.constness {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_attr_ir/src/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ language_item_table! {
PartialEq, sym::eq, eq_trait, Target::Trait, GenericRequirement::Exact(1);
PartialOrd, sym::partial_ord, partial_ord_trait, Target::Trait, GenericRequirement::Exact(1);
CVoid, sym::c_void, c_void, Target::Enum, GenericRequirement::None;
F16B, sym::f16b, f16b, Target::Struct, GenericRequirement::Exact(0);

Type, sym::type_info, type_struct, Target::Struct, GenericRequirement::None;
TypeGeneric, sym::type_info_generic, type_generic, Target::Enum, GenericRequirement::None;
Expand Down
Loading
Loading