Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
4d0b593
Make `HasTokens` a sub-trait of `HasAttrs`.
nnethercote Jul 12, 2026
8c2ed2f
Introduce InstanceKind::LlvmIntrinsic
bjorn3 Jan 8, 2026
aec727f
Stop using EmulateItemResult for LLVM intrinsics in miri
bjorn3 Jul 13, 2026
8583c9a
Add regression test for issue 95719
Joel-Wwalker Jul 13, 2026
09882ef
inline Once wait and wait_force
vilgotf Jul 13, 2026
9561a52
Bump rustc-perf submodule
Kobzol Jul 13, 2026
5f35fc8
Replace shortened type with `_` instead of `...` as placeholder
estebank Jul 13, 2026
301e1cd
Add Into<DefId> to is_descendant_of
camsteffen Jul 12, 2026
89a46d2
Inline typed_def_id macro
camsteffen Jul 12, 2026
e399c8f
Rename ModDefId to ModId
camsteffen Jul 12, 2026
3b290b2
Use ModId more
camsteffen Jul 12, 2026
453c1e2
Fix rustdoc with ModId refactors
camsteffen Jul 14, 2026
acdd18e
Fix clippy with ModId refactors
camsteffen Jul 14, 2026
8e12609
Add regression test for issue 144033
Joel-Wwalker Jul 14, 2026
bf52201
Skip intrinsic-test when rustfmt is unavailable
xonx4l Jul 14, 2026
f3f4235
Simplify regression test for issue 144033
Joel-Wwalker Jul 14, 2026
ca15064
Add regression test
oli-obk Jun 12, 2026
5b3e95d
Add regression test
oli-obk Jun 12, 2026
7139a2b
disable range-len-try-from.rs on s390x
fneddy Jul 14, 2026
edbbeae
Update tidy licenses
Kobzol Jul 13, 2026
7d5c925
slice: make swap delegate to swap_unchecked
Rachit2323 Jul 14, 2026
dff3fde
Rename `std_crates_for_run_make` to `std_crates_for_make_run`
Zalathar Jul 14, 2026
070dd68
remove obsolete comment
tshepang Jul 14, 2026
6741f56
Add ´#[rustc_comptime]` inherent impls
oli-obk Jun 12, 2026
a8019c5
rerun if we meet any opaques in post analysis
adwinwhite Jul 8, 2026
1409d92
Rollup merge of #157824 - oli-obk:comptime-impls, r=fee1-dead
JonathanBrouwer Jul 14, 2026
f42afe6
Rollup merge of #158993 - adwinwhite:rigid-opaque-in-codegen, r=jdons…
JonathanBrouwer Jul 14, 2026
693c3c4
Rollup merge of #159160 - nnethercote:HasAttrs-HasTokens, r=petrochenkov
JonathanBrouwer Jul 14, 2026
a9d6b45
Rollup merge of #159183 - bjorn3:instance_llvm_intrinsic, r=RalfJung,…
JonathanBrouwer Jul 14, 2026
eb096b3
Rollup merge of #159197 - camsteffen:more-modid, r=petrochenkov
JonathanBrouwer Jul 14, 2026
0c00c67
Rollup merge of #159251 - Kobzol:update-rustc-perf, r=lqd
JonathanBrouwer Jul 14, 2026
629b8fb
Rollup merge of #159235 - Joel-Wwalker:95719-regression-test, r=oli-obk
JonathanBrouwer Jul 14, 2026
8c8bcc2
Rollup merge of #159243 - vilgotf:once-inline, r=joboet
JonathanBrouwer Jul 14, 2026
2214bfe
Rollup merge of #159255 - estebank:shortened-ty-placeholder, r=Kivooeo
JonathanBrouwer Jul 14, 2026
34fff5f
Rollup merge of #159259 - Joel-Wwalker:144033-regression-test, r=Kivooeo
JonathanBrouwer Jul 14, 2026
df8f47a
Rollup merge of #159265 - xonx4l:skip-intrinsic-test-missing-rustfmt,…
JonathanBrouwer Jul 14, 2026
1141565
Rollup merge of #159269 - fneddy:disable-test-rltf, r=folkertdev
JonathanBrouwer Jul 14, 2026
35bf135
Rollup merge of #159272 - Rachit2323:fix-slice-swap-use-swap-unchecke…
JonathanBrouwer Jul 14, 2026
65ea275
Rollup merge of #159274 - Zalathar:did-you-mean-make-run, r=jieyouxu
JonathanBrouwer Jul 14, 2026
7fc7316
Rollup merge of #159275 - tshepang:patch-2, r=Kivooeo
JonathanBrouwer Jul 14, 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
4 changes: 2 additions & 2 deletions compiler/rustc_ast/src/ast_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl<T: HasNodeId> HasNodeId for Box<T> {
}

/// A trait for AST nodes having (or not having) collected tokens.
pub trait HasTokens {
pub trait HasTokens: HasAttrs {
fn tokens(&self) -> Option<&LazyAttrTokenStream>;
fn tokens_mut(&mut self) -> Option<&mut Option<LazyAttrTokenStream>>;
}
Expand Down Expand Up @@ -109,7 +109,7 @@ impl_has_tokens_none!(
WherePredicate
);

impl<T> HasTokens for WithTokens<T> {
impl<T: HasAttrs> HasTokens for WithTokens<T> {
fn tokens(&self) -> Option<&LazyAttrTokenStream> {
self.tokens.as_ref()
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ast/src/tokenstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use rustc_span::{DUMMY_SP, Span, SpanDecoder, SpanEncoder, Symbol, sym};
use thin_vec::ThinVec;

use crate::ast::AttrStyle;
use crate::ast_traits::{HasAttrs, HasTokens};
use crate::ast_traits::HasTokens;
use crate::token::{self, Delimiter, Token, TokenKind};
use crate::{AttrVec, Attribute};

Expand Down Expand Up @@ -653,7 +653,7 @@ impl TokenStream {
TokenStream::new(vec![TokenTree::token_alone(kind, span)])
}

pub fn from_ast(node: &(impl HasAttrs + HasTokens + fmt::Debug)) -> TokenStream {
pub fn from_ast(node: &(impl HasTokens + fmt::Debug)) -> TokenStream {
let tokens = node.tokens().unwrap_or_else(|| panic!("missing tokens for node: {:?}", node));
let mut tts = vec![];
attrs_and_tokens_to_token_trees(node.attrs(), tokens, &mut tts);
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_ast_lowering/src/expr/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
&closure.body,
closure.fn_decl_span,
closure.fn_arg_span,
attrs,
),
span: self.lower_span(e.span),
},
Expand Down Expand Up @@ -240,7 +241,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
fn_decl_span: self.lower_span(fn_decl_span),
fn_arg_span: Some(self.lower_span(fn_arg_span)),
kind: closure_kind,
constness: self.lower_constness(constness),
constness: self.lower_constness(attrs, constness),
explicit_captures,
});

Expand Down Expand Up @@ -308,6 +309,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
body: &Expr,
fn_decl_span: Span,
fn_arg_span: Span,
attrs: &[hir::Attribute],
) -> hir::ExprKind<'hir> {
let closure_def_id = self.local_def_id(closure_id);
let (binder_clause, generic_params) = self.lower_closure_binder(binder);
Expand Down Expand Up @@ -369,7 +371,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
// knows that a `FnDecl` output type like `-> &str` actually means
// "coroutine that returns &str", rather than directly returning a `&str`.
kind: hir::ClosureKind::CoroutineClosure(coroutine_desugaring),
constness: self.lower_constness(constness),
constness: self.lower_constness(attrs, constness),
explicit_captures: &[],
});
hir::ExprKind::Closure(c)
Expand Down
45 changes: 25 additions & 20 deletions compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
.arena
.alloc_from_iter(impl_items.iter().map(|item| self.lower_impl_item_ref(item)));

let constness = self.lower_constness(*constness);
let constness = self.lower_constness(attrs, *constness);

hir::ItemKind::Impl(hir::Impl {
generics,
Expand All @@ -499,7 +499,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
bounds,
items,
}) => {
let constness = self.lower_constness(*constness);
let constness = self.lower_constness(attrs, *constness);
let impl_restriction = self.lower_impl_restriction(impl_restriction);
let ident = self.lower_ident(*ident);
let (generics, (safety, items, bounds)) = self.lower_generics(
Expand Down Expand Up @@ -530,7 +530,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
}
ItemKind::TraitAlias(TraitAlias { constness, ident, generics, bounds }) => {
let constness = self.lower_constness(*constness);
let constness = self.lower_constness(attrs, *constness);
let ident = self.lower_ident(*ident);
let (generics, bounds) = self.lower_generics(
generics,
Expand Down Expand Up @@ -1702,21 +1702,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
safety.into()
};

let mut constness = self.lower_constness(h.constness);
if let Some(&attr_span) = find_attr!(attrs, RustcComptime(span) => span) {
match std::mem::replace(&mut constness, rustc_hir::Constness::Const { always: true }) {
rustc_hir::Constness::Const { always: true } => {
unreachable!("lower_constness cannot produce comptime")
}
// A function can't be `const` and `comptime` at the same time
rustc_hir::Constness::Const { always: false } => {
let Const::Yes(span) = h.constness else { unreachable!() };
self.dcx().emit_err(ConstComptimeFn { span, attr_span });
}
// Good
rustc_hir::Constness::NotConst => {}
}
}
let constness = self.lower_constness(attrs, h.constness);

hir::FnHeader { safety, asyncness, constness, abi: self.lower_extern(h.ext) }
}
Expand Down Expand Up @@ -1778,11 +1764,30 @@ impl<'hir> LoweringContext<'_, 'hir> {
});
}

pub(super) fn lower_constness(&mut self, c: Const) -> hir::Constness {
match c {
/// Lowers constness or comptime attribute.
/// Whether `const` is allowed here is checked by ast validation.
/// Whether `comptime` is allowed here is checked by the `comptime` attribute parser.
pub(super) fn lower_constness(&mut self, attrs: &[hir::Attribute], c: Const) -> hir::Constness {
let mut constness = match c {
Const::Yes(_) => hir::Constness::Const { always: false },
Const::No => hir::Constness::NotConst,
};

if let Some(&attr_span) = find_attr!(attrs, RustcComptime(span) => span) {
match std::mem::replace(&mut constness, hir::Constness::Const { always: true }) {
hir::Constness::Const { always: true } => {
unreachable!("lower_constness cannot produce comptime")
}
// A function can't be `const` and `comptime` at the same time
hir::Constness::Const { always: false } => {
let Const::Yes(span) = c else { unreachable!() };
self.dcx().emit_err(ConstComptimeFn { span, attr_span });
}
// Good
hir::Constness::NotConst => {}
}
}
constness
}

pub(super) fn lower_safety(&self, s: Safety, default: hir::Safety) -> hir::Safety {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_attr_parsing/src/attributes/semantics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ impl NoArgsAttributeParser for ComptimeParser {
const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowList(&[
Allow(Target::Method(MethodKind::Inherent)),
Allow(Target::Fn),
Allow(Target::Impl { of_trait: false }),
]);
const STABILITY: AttributeStability = unstable!(rustc_attrs);
const CREATE: fn(Span) -> AttributeKind = AttributeKind::RustcComptime;
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_builtin_macros/src/cfg_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use core::ops::ControlFlow;
use rustc_ast as ast;
use rustc_ast::mut_visit::MutVisitor;
use rustc_ast::visit::{AssocCtxt, Visitor};
use rustc_ast::{Attribute, HasAttrs, HasTokens, NodeId, mut_visit, visit};
use rustc_ast::{Attribute, HasTokens, NodeId, mut_visit, visit};
use rustc_errors::PResult;
use rustc_expand::base::{Annotatable, ExtCtxt};
use rustc_expand::config::StripUnconfigured;
Expand Down Expand Up @@ -67,7 +67,7 @@ fn has_cfg_or_cfg_attr(annotatable: &Annotatable) -> bool {
}

impl CfgEval<'_> {
fn configure<T: HasAttrs + HasTokens>(&mut self, node: T) -> Option<T> {
fn configure<T: HasTokens>(&mut self, node: T) -> Option<T> {
self.0.configure(node)
}

Expand Down
23 changes: 11 additions & 12 deletions compiler/rustc_codegen_cranelift/src/abi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,18 +440,6 @@ pub(crate) fn codegen_terminator_call<'tcx>(
}
}

if fx.tcx.symbol_name(instance).name.starts_with("llvm.") {
crate::intrinsics::codegen_llvm_intrinsic_call(
fx,
fx.tcx.symbol_name(instance).name,
args,
ret_place,
target,
source_info.span,
);
return;
}

match instance.def {
InstanceKind::Intrinsic(_) => {
match crate::intrinsics::codegen_intrinsic_call(
Expand All @@ -466,6 +454,17 @@ pub(crate) fn codegen_terminator_call<'tcx>(
Err(instance) => Some(instance),
}
}
InstanceKind::LlvmIntrinsic(_) => {
crate::intrinsics::codegen_llvm_intrinsic_call(
fx,
fx.tcx.symbol_name(instance).name,
args,
ret_place,
target,
source_info.span,
);
return;
}
// We don't need AsyncDropGlueCtorShim here because it is not `noop func`,
// it is `func returning noop future`
InstanceKind::Shim(ShimKind::DropGlue(_, None)) => {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,7 @@ fn visibility_di_flags<'ll, 'tcx>(
match visibility {
Visibility::Public => DIFlags::FlagPublic,
// Private fields have a restricted visibility of the module containing the type.
Visibility::Restricted(did) if did == parent_did => DIFlags::FlagPrivate,
Visibility::Restricted(did) if did.to_def_id() == parent_did => DIFlags::FlagPrivate,
// `pub(crate)`/`pub(super)` visibilities are any other restricted visibility.
Visibility::Restricted(..) => DIFlags::FlagProtected,
}
Expand Down
9 changes: 2 additions & 7 deletions compiler/rustc_codegen_ssa/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -892,12 +892,8 @@ pub fn is_call_from_compiler_builtins_to_upstream_monomorphization<'tcx>(
tcx: TyCtxt<'tcx>,
instance: Instance<'tcx>,
) -> bool {
fn is_llvm_intrinsic(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
if let Some(name) = tcx.codegen_fn_attrs(def_id).symbol_name {
name.as_str().starts_with("llvm.")
} else {
false
}
if let ty::InstanceKind::LlvmIntrinsic(_) = instance.def {
return false;
}

fn is_extern_call_to_local_crate<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> bool {
Expand All @@ -910,7 +906,6 @@ pub fn is_call_from_compiler_builtins_to_upstream_monomorphization<'tcx>(
let def_id = instance.def_id();
!def_id.is_local()
&& tcx.is_compiler_builtins(LOCAL_CRATE)
&& !is_llvm_intrinsic(tcx, def_id)
&& !tcx.should_codegen_locally(instance)
&& !is_extern_call_to_local_crate(tcx, instance)
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/mir/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1112,8 +1112,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
};

if let Some(instance) = instance
&& let ty::InstanceKind::LlvmIntrinsic(_) = instance.def
&& let Some(name) = bx.tcx().codegen_fn_attrs(instance.def_id()).symbol_name
&& name.as_str().starts_with("llvm.")
// This is the only LLVM intrinsic we use that unwinds
// FIXME either add unwind support to codegen_llvm_intrinsic_call or replace usage of
// this intrinsic with something else
Expand Down
10 changes: 10 additions & 0 deletions compiler/rustc_const_eval/src/const_eval/dummy_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ impl<'tcx> interpret::Machine<'tcx> for DummyMachine {
unimplemented!()
}

fn call_llvm_intrinsic(
_ecx: &mut InterpCx<'tcx, Self>,
_instance: ty::Instance<'tcx>,
_args: &[interpret::OpTy<'tcx, Self::Provenance>],
_destination: &interpret::PlaceTy<'tcx, Self::Provenance>,
_target: Option<BasicBlock>,
) -> interpret::InterpResult<'tcx> {
unimplemented!()
}

fn assert_panic(
_ecx: &mut InterpCx<'tcx, Self>,
_msg: &rustc_middle::mir::AssertMessage<'tcx>,
Expand Down
12 changes: 12 additions & 0 deletions compiler/rustc_const_eval/src/const_eval/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,18 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> {
interp_ok(None)
}

fn call_llvm_intrinsic(
ecx: &mut InterpCx<'tcx, Self>,
instance: ty::Instance<'tcx>,
_args: &[OpTy<'tcx>],
_dest: &PlaceTy<'tcx, Self::Provenance>,
_target: Option<mir::BasicBlock>,
) -> InterpResult<'tcx> {
let intrinsic_name = ecx.tcx.codegen_fn_attrs(instance.def_id()).symbol_name.unwrap();

throw_unsup_format!("LLVM intrinsic `{intrinsic_name}` is not supported at compile-time");
}

fn assert_panic(
ecx: &mut InterpCx<'tcx, Self>,
msg: &AssertMessage<'tcx>,
Expand Down
10 changes: 10 additions & 0 deletions compiler/rustc_const_eval/src/interpret/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,16 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
interp_ok(())
}
}
ty::InstanceKind::LlvmIntrinsic(_) => {
// FIXME: Should `InPlace` arguments be reset to uninit?
M::call_llvm_intrinsic(
self,
instance,
&Self::copy_fn_args(args),
destination,
target,
)
}
ty::InstanceKind::Shim(ty::ShimKind::VTable(..))
| ty::InstanceKind::Shim(ty::ShimKind::Reify(..))
| ty::InstanceKind::Shim(ty::ShimKind::ClosureOnce { .. })
Expand Down
10 changes: 10 additions & 0 deletions compiler/rustc_const_eval/src/interpret/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,16 @@ pub trait Machine<'tcx>: Sized {
unwind: mir::UnwindAction,
) -> InterpResult<'tcx, Option<ty::Instance<'tcx>>>;

/// Directly process an LLVM intrinsic without pushing a stack frame. It is the hook's
/// responsibility to advance the instruction pointer as appropriate.
fn call_llvm_intrinsic(
ecx: &mut InterpCx<'tcx, Self>,
instance: ty::Instance<'tcx>,
args: &[OpTy<'tcx, Self::Provenance>],
destination: &PlaceTy<'tcx, Self::Provenance>,
target: Option<mir::BasicBlock>,
) -> InterpResult<'tcx>;

/// Check whether the given function may be executed on the current machine, in terms of the
/// target features is requires.
fn check_fn_target_features(
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_expand/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use rustc_parse::MACRO_ARGUMENTS;
use rustc_parse::parser::Parser;
use rustc_session::Session;
use rustc_session::parse::ParseSess;
use rustc_span::def_id::{CrateNum, DefId, LocalDefId};
use rustc_span::def_id::{CrateNum, DefId, LocalDefId, ModId};
use rustc_span::edition::Edition;
use rustc_span::hygiene::{AstPass, ExpnData, ExpnKind, LocalExpnId, MacroKind};
use rustc_span::source_map::SourceMap;
Expand Down Expand Up @@ -1003,7 +1003,7 @@ impl SyntaxExtension {
descr: Symbol,
kind: MacroKind,
macro_def_id: Option<DefId>,
parent_module: Option<DefId>,
parent_module: Option<ModId>,
) -> ExpnData {
ExpnData::new(
ExpnKind::Macro(kind, descr),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_expand/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ macro_rules! configure {
}

impl<'a> StripUnconfigured<'a> {
pub fn configure<T: HasAttrs + HasTokens>(&self, mut node: T) -> Option<T> {
pub fn configure<T: HasTokens>(&self, mut node: T) -> Option<T> {
self.process_cfg_attrs(&mut node);
self.in_cfg(node.attrs()).then(|| {
self.try_configure_tokens(&mut node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use rustc_middle::ty::{
TypeVisitableExt, TypeVisitor, TypingMode, Unnormalized,
};
use rustc_span::Span;
use rustc_span::def_id::ModId;
use rustc_trait_selection::regions::InferCtxtRegionExt;
use rustc_trait_selection::traits::{ObligationCtxt, elaborate, normalize_param_env_or_error};

Expand Down Expand Up @@ -380,7 +381,7 @@ fn report_mismatched_rpitit_signature<'tcx>(
);
}

fn type_visibility<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<ty::Visibility<DefId>> {
fn type_visibility<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<ty::Visibility<ModId>> {
match *ty.kind() {
ty::Ref(_, ty, _) => type_visibility(tcx, ty),
ty::Adt(def, args) => {
Expand Down
Loading
Loading