Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
07d3e92
Unstably constify ptr::drop_in_place and related methods
clarfonthey Sep 4, 2025
f47c480
Reduce scope of unsafe block in cg_llvm allocator codegen
bjorn3 Oct 9, 2025
116f4ae
Support #[alloc_error_handler] without the allocator shim
bjorn3 Jun 26, 2025
7e467cd
Move computation of allocator shim contents to cg_ssa
bjorn3 Oct 9, 2025
2e25b58
Add a couple of comments
bjorn3 Oct 10, 2025
88e9820
Fix review comments
bjorn3 Oct 10, 2025
2611bf7
Tidy some patterns in `ChunkedBitSet` ops.
nnethercote Oct 12, 2025
6e85c4e
Remove some unused bitset code.
nnethercote Oct 12, 2025
056c2da
bpf: return results larger than one register indirectly
alessandrod Oct 13, 2025
8386278
Factor out a recurring pattern as `count_ones`.
nnethercote Oct 12, 2025
714843d
replace manual implementation with carrying_mul_add
Kivooeo Oct 14, 2025
18d1b69
fix missing link to `std::char` in `std` docs
cyrgani Oct 14, 2025
8a145ef
std: improve handling of timed condition variable waits on macOS
joboet Sep 13, 2025
fe1238e
miri: shim `pthread_cond_timedwait_relative_np`
joboet Sep 13, 2025
37fa60b
pretty print u128 with display
jdonszelmann Oct 14, 2025
7a368c8
Use span from parsed attribute
jdonszelmann Oct 14, 2025
c00b4ba
Fix ICE caused by associated_item_def_ids on wrong type in resolve diag
chenyukang Oct 14, 2025
a51a793
only check duplicates on old/unparsed attributes
jdonszelmann Oct 14, 2025
cf02560
Add comment to AllocatorKind and AllocatorMethod
bjorn3 Oct 14, 2025
047c37c
convert rustc_main to the new attribute parsing infrastructure
jdonszelmann Oct 14, 2025
252974a
Rollup merge of #146187 - clarfonthey:const-drop-in-place, r=oli-obk
matthiaskrgr Oct 14, 2025
dcd2dd9
Rollup merge of #146503 - joboet:macos-condvar-timeout, r=ibraheemdev
matthiaskrgr Oct 14, 2025
f8b65f7
Rollup merge of #147526 - bjorn3:alloc_shim_weak_shape, r=petrochenko…
matthiaskrgr Oct 14, 2025
b134c9c
Rollup merge of #147630 - nnethercote:bitset-cleanups, r=cjgillot,Zal…
matthiaskrgr Oct 14, 2025
10e535a
Rollup merge of #147638 - alessandrod:indirect-res, r=wesleywiser
matthiaskrgr Oct 14, 2025
49be94c
Rollup merge of #147666 - Kivooeo:full_mud_add-followup, r=scottmcm
matthiaskrgr Oct 14, 2025
2ab43c2
Rollup merge of #147669 - cyrgani:cyrgani-patch-1, r=joboet
matthiaskrgr Oct 14, 2025
5a2c639
Rollup merge of #147673 - jdonszelmann:u128-pp, r=JonathanBrouwer
matthiaskrgr Oct 14, 2025
783307c
Rollup merge of #147677 - jdonszelmann:fewer-span-exceptions, r=Waffl…
matthiaskrgr Oct 14, 2025
3856d0b
Rollup merge of #147680 - chenyukang:yukang-fix-ice-147325, r=estebank
matthiaskrgr Oct 14, 2025
ea0c8d8
Rollup merge of #147682 - jdonszelmann:convert-rustc-main, r=Jonathan…
matthiaskrgr Oct 14, 2025
545ee6f
Rollup merge of #147683 - jdonszelmann:less-duplicate-checking, r=Jon…
matthiaskrgr Oct 14, 2025
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: 2 additions & 4 deletions compiler/rustc_ast/src/entry.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use rustc_span::{Symbol, sym};

use crate::attr::{self, AttributeExt};

#[derive(Debug)]
pub enum EntryPointType {
/// This function is not an entrypoint.
Expand Down Expand Up @@ -30,11 +28,11 @@ pub enum EntryPointType {
}

pub fn entry_point_type(
attrs: &[impl AttributeExt],
has_rustc_main: bool,
at_root: bool,
name: Option<Symbol>,
) -> EntryPointType {
if attr::contains_name(attrs, sym::rustc_main) {
if has_rustc_main {
EntryPointType::RustcMainAttr
} else if let Some(name) = name
&& name == sym::main
Expand Down
15 changes: 8 additions & 7 deletions compiler/rustc_ast/src/expand/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ use rustc_span::{Symbol, sym};

#[derive(Clone, Debug, Copy, Eq, PartialEq, HashStable_Generic)]
pub enum AllocatorKind {
/// Use `#[global_allocator]` as global allocator.
Global,
/// Use the default implementation in libstd as global allocator.
Default,
}

Expand All @@ -15,23 +17,22 @@ pub fn default_fn_name(base: Symbol) -> String {
format!("__rdl_{base}")
}

pub fn alloc_error_handler_name(alloc_error_handler_kind: AllocatorKind) -> &'static str {
match alloc_error_handler_kind {
AllocatorKind::Global => "__rg_oom",
AllocatorKind::Default => "__rdl_oom",
}
}

pub const ALLOC_ERROR_HANDLER: Symbol = sym::alloc_error_handler;
pub const NO_ALLOC_SHIM_IS_UNSTABLE: &str = "__rust_no_alloc_shim_is_unstable_v2";

/// Argument or return type for methods in the allocator shim
#[derive(Copy, Clone)]
pub enum AllocatorTy {
Layout,
Never,
Ptr,
ResultPtr,
Unit,
Usize,
}

/// A method that will be codegened in the allocator shim.
#[derive(Copy, Clone)]
pub struct AllocatorMethod {
pub name: Symbol,
pub inputs: &'static [AllocatorMethodInput],
Expand Down
17 changes: 13 additions & 4 deletions compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
use super::prelude::*;
use super::util::parse_single_integer;

pub(crate) struct RustcLayoutScalarValidRangeStart;
pub(crate) struct RustcMainParser;

impl<S: Stage> SingleAttributeParser<S> for RustcLayoutScalarValidRangeStart {
impl<S: Stage> NoArgsAttributeParser<S> for RustcMainParser {
const PATH: &'static [Symbol] = &[sym::rustc_main];
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Fn)]);
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcMain;
}

pub(crate) struct RustcLayoutScalarValidRangeStartParser;

impl<S: Stage> SingleAttributeParser<S> for RustcLayoutScalarValidRangeStartParser {
const PATH: &'static [Symbol] = &[sym::rustc_layout_scalar_valid_range_start];
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepInnermost;
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
Expand All @@ -16,9 +25,9 @@ impl<S: Stage> SingleAttributeParser<S> for RustcLayoutScalarValidRangeStart {
}
}

pub(crate) struct RustcLayoutScalarValidRangeEnd;
pub(crate) struct RustcLayoutScalarValidRangeEndParser;

impl<S: Stage> SingleAttributeParser<S> for RustcLayoutScalarValidRangeEnd {
impl<S: Stage> SingleAttributeParser<S> for RustcLayoutScalarValidRangeEndParser {
const PATH: &'static [Symbol] = &[sym::rustc_layout_scalar_valid_range_end];
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepInnermost;
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
Expand Down
7 changes: 4 additions & 3 deletions compiler/rustc_attr_parsing/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ use crate::attributes::proc_macro_attrs::{
use crate::attributes::prototype::CustomMirParser;
use crate::attributes::repr::{AlignParser, AlignStaticParser, ReprParser};
use crate::attributes::rustc_internal::{
RustcLayoutScalarValidRangeEnd, RustcLayoutScalarValidRangeStart,
RustcLayoutScalarValidRangeEndParser, RustcLayoutScalarValidRangeStartParser, RustcMainParser,
RustcObjectLifetimeDefaultParser, RustcSimdMonomorphizeLaneLimitParser,
};
use crate::attributes::semantics::MayDangleParser;
Expand Down Expand Up @@ -197,8 +197,8 @@ attribute_parsers!(
Single<RecursionLimitParser>,
Single<RustcBuiltinMacroParser>,
Single<RustcForceInlineParser>,
Single<RustcLayoutScalarValidRangeEnd>,
Single<RustcLayoutScalarValidRangeStart>,
Single<RustcLayoutScalarValidRangeEndParser>,
Single<RustcLayoutScalarValidRangeStartParser>,
Single<RustcObjectLifetimeDefaultParser>,
Single<RustcSimdMonomorphizeLaneLimitParser>,
Single<SanitizeParser>,
Expand Down Expand Up @@ -238,6 +238,7 @@ attribute_parsers!(
Single<WithoutArgs<ProcMacroParser>>,
Single<WithoutArgs<PubTransparentParser>>,
Single<WithoutArgs<RustcCoherenceIsCoreParser>>,
Single<WithoutArgs<RustcMainParser>>,
Single<WithoutArgs<SpecializationTraitParser>>,
Single<WithoutArgs<StdInternalSymbolParser>>,
Single<WithoutArgs<TrackCallerParser>>,
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_builtin_macros/src/alloc_error_handler.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use rustc_ast::expand::allocator::{ALLOC_ERROR_HANDLER, global_fn_name};
use rustc_ast::{
self as ast, Fn, FnHeader, FnSig, Generics, ItemKind, Safety, Stmt, StmtKind, TyKind,
};
Expand Down Expand Up @@ -55,7 +56,7 @@ pub(crate) fn expand(
}

// #[rustc_std_internal_symbol]
// unsafe fn __rg_oom(size: usize, align: usize) -> ! {
// unsafe fn __rust_alloc_error_handler(size: usize, align: usize) -> ! {
// handler(core::alloc::Layout::from_size_align_unchecked(size, align))
// }
fn generate_handler(cx: &ExtCtxt<'_>, handler: Ident, span: Span, sig_span: Span) -> Stmt {
Expand Down Expand Up @@ -84,7 +85,7 @@ fn generate_handler(cx: &ExtCtxt<'_>, handler: Ident, span: Span, sig_span: Span
let kind = ItemKind::Fn(Box::new(Fn {
defaultness: ast::Defaultness::Final,
sig,
ident: Ident::from_str_and_span("__rg_oom", span),
ident: Ident::from_str_and_span(&global_fn_name(ALLOC_ERROR_HANDLER), span),
generics: Generics::default(),
contract: None,
body,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_builtin_macros/src/global_allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ impl AllocFnFactory<'_, '_> {
self.cx.expr_ident(self.span, ident)
}

AllocatorTy::ResultPtr | AllocatorTy::Unit => {
AllocatorTy::Never | AllocatorTy::ResultPtr | AllocatorTy::Unit => {
panic!("can't convert AllocatorTy to an argument")
}
}
Expand All @@ -163,7 +163,7 @@ impl AllocFnFactory<'_, '_> {

AllocatorTy::Unit => self.cx.ty(self.span, TyKind::Tup(ThinVec::new())),

AllocatorTy::Layout | AllocatorTy::Usize | AllocatorTy::Ptr => {
AllocatorTy::Layout | AllocatorTy::Never | AllocatorTy::Usize | AllocatorTy::Ptr => {
panic!("can't convert `AllocatorTy` to an output")
}
}
Expand Down
9 changes: 6 additions & 3 deletions compiler/rustc_builtin_macros/src/test_harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use std::mem;

use rustc_ast as ast;
use rustc_ast::attr::contains_name;
use rustc_ast::entry::EntryPointType;
use rustc_ast::mut_visit::*;
use rustc_ast::visit::Visitor;
Expand Down Expand Up @@ -172,9 +173,11 @@ impl<'a> Visitor<'a> for InnerItemLinter<'_> {

fn entry_point_type(item: &ast::Item, at_root: bool) -> EntryPointType {
match &item.kind {
ast::ItemKind::Fn(fn_) => {
rustc_ast::entry::entry_point_type(&item.attrs, at_root, Some(fn_.ident.name))
}
ast::ItemKind::Fn(fn_) => rustc_ast::entry::entry_point_type(
contains_name(&item.attrs, sym::rustc_main),
at_root,
Some(fn_.ident.name),
),
_ => EntryPointType::None,
}
}
Expand Down
91 changes: 36 additions & 55 deletions compiler/rustc_codegen_cranelift/src/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@

use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext};
use rustc_ast::expand::allocator::{
ALLOCATOR_METHODS, AllocatorKind, AllocatorTy, NO_ALLOC_SHIM_IS_UNSTABLE,
alloc_error_handler_name, default_fn_name, global_fn_name,
AllocatorMethod, AllocatorTy, NO_ALLOC_SHIM_IS_UNSTABLE, default_fn_name, global_fn_name,
};
use rustc_codegen_ssa::base::allocator_kind_for_codegen;
use rustc_codegen_ssa::base::{allocator_kind_for_codegen, allocator_shim_contents};
use rustc_session::config::OomStrategy;
use rustc_symbol_mangling::mangle_internal_symbol;

Expand All @@ -15,75 +14,57 @@ use crate::prelude::*;
/// Returns whether an allocator shim was created
pub(crate) fn codegen(tcx: TyCtxt<'_>, module: &mut dyn Module) -> bool {
let Some(kind) = allocator_kind_for_codegen(tcx) else { return false };
codegen_inner(
tcx,
module,
kind,
tcx.alloc_error_handler_kind(()).unwrap(),
tcx.sess.opts.unstable_opts.oom,
);
let methods = allocator_shim_contents(tcx, kind);
codegen_inner(tcx, module, &methods, tcx.sess.opts.unstable_opts.oom);
true
}

fn codegen_inner(
tcx: TyCtxt<'_>,
module: &mut dyn Module,
kind: AllocatorKind,
alloc_error_handler_kind: AllocatorKind,
methods: &[AllocatorMethod],
oom_strategy: OomStrategy,
) {
let usize_ty = module.target_config().pointer_type();

if kind == AllocatorKind::Default {
for method in ALLOCATOR_METHODS {
let mut arg_tys = Vec::with_capacity(method.inputs.len());
for input in method.inputs.iter() {
match input.ty {
AllocatorTy::Layout => {
arg_tys.push(usize_ty); // size
arg_tys.push(usize_ty); // align
}
AllocatorTy::Ptr => arg_tys.push(usize_ty),
AllocatorTy::Usize => arg_tys.push(usize_ty),
for method in methods {
let mut arg_tys = Vec::with_capacity(method.inputs.len());
for input in method.inputs.iter() {
match input.ty {
AllocatorTy::Layout => {
arg_tys.push(usize_ty); // size
arg_tys.push(usize_ty); // align
}
AllocatorTy::Ptr => arg_tys.push(usize_ty),
AllocatorTy::Usize => arg_tys.push(usize_ty),

AllocatorTy::ResultPtr | AllocatorTy::Unit => panic!("invalid allocator arg"),
AllocatorTy::Never | AllocatorTy::ResultPtr | AllocatorTy::Unit => {
panic!("invalid allocator arg")
}
}
let output = match method.output {
AllocatorTy::ResultPtr => Some(usize_ty),
AllocatorTy::Unit => None,
}
let output = match method.output {
AllocatorTy::ResultPtr => Some(usize_ty),
AllocatorTy::Never | AllocatorTy::Unit => None,

AllocatorTy::Layout | AllocatorTy::Usize | AllocatorTy::Ptr => {
panic!("invalid allocator output")
}
};
AllocatorTy::Layout | AllocatorTy::Usize | AllocatorTy::Ptr => {
panic!("invalid allocator output")
}
};

let sig = Signature {
call_conv: module.target_config().default_call_conv,
params: arg_tys.iter().cloned().map(AbiParam::new).collect(),
returns: output.into_iter().map(AbiParam::new).collect(),
};
crate::common::create_wrapper_function(
module,
sig,
&mangle_internal_symbol(tcx, &global_fn_name(method.name)),
&mangle_internal_symbol(tcx, &default_fn_name(method.name)),
);
}
let sig = Signature {
call_conv: module.target_config().default_call_conv,
params: arg_tys.iter().cloned().map(AbiParam::new).collect(),
returns: output.into_iter().map(AbiParam::new).collect(),
};
crate::common::create_wrapper_function(
module,
sig,
&mangle_internal_symbol(tcx, &global_fn_name(method.name)),
&mangle_internal_symbol(tcx, &default_fn_name(method.name)),
);
}

let sig = Signature {
call_conv: module.target_config().default_call_conv,
params: vec![AbiParam::new(usize_ty), AbiParam::new(usize_ty)],
returns: vec![],
};
crate::common::create_wrapper_function(
module,
sig,
&mangle_internal_symbol(tcx, "__rust_alloc_error_handler"),
&mangle_internal_symbol(tcx, alloc_error_handler_name(alloc_error_handler_kind)),
);

{
let sig = Signature {
call_conv: module.target_config().default_call_conv,
Expand Down
64 changes: 26 additions & 38 deletions compiler/rustc_codegen_gcc/src/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
use gccjit::FnAttribute;
use gccjit::{Context, FunctionType, RValue, ToRValue, Type};
use rustc_ast::expand::allocator::{
ALLOCATOR_METHODS, AllocatorKind, AllocatorTy, NO_ALLOC_SHIM_IS_UNSTABLE,
alloc_error_handler_name, default_fn_name, global_fn_name,
AllocatorMethod, AllocatorTy, NO_ALLOC_SHIM_IS_UNSTABLE, default_fn_name, global_fn_name,
};
use rustc_middle::bug;
use rustc_middle::ty::TyCtxt;
Expand All @@ -18,8 +17,7 @@ pub(crate) unsafe fn codegen(
tcx: TyCtxt<'_>,
mods: &mut GccContext,
_module_name: &str,
kind: AllocatorKind,
alloc_error_handler_kind: AllocatorKind,
methods: &[AllocatorMethod],
) {
let context = &mods.context;
let usize = match tcx.sess.target.pointer_width {
Expand All @@ -31,45 +29,35 @@ pub(crate) unsafe fn codegen(
let i8 = context.new_type::<i8>();
let i8p = i8.make_pointer();

if kind == AllocatorKind::Default {
for method in ALLOCATOR_METHODS {
let mut types = Vec::with_capacity(method.inputs.len());
for input in method.inputs.iter() {
match input.ty {
AllocatorTy::Layout => {
types.push(usize);
types.push(usize);
}
AllocatorTy::Ptr => types.push(i8p),
AllocatorTy::Usize => types.push(usize),

AllocatorTy::ResultPtr | AllocatorTy::Unit => panic!("invalid allocator arg"),
for method in methods {
let mut types = Vec::with_capacity(method.inputs.len());
for input in method.inputs.iter() {
match input.ty {
AllocatorTy::Layout => {
types.push(usize);
types.push(usize);
}
}
let output = match method.output {
AllocatorTy::ResultPtr => Some(i8p),
AllocatorTy::Unit => None,
AllocatorTy::Ptr => types.push(i8p),
AllocatorTy::Usize => types.push(usize),

AllocatorTy::Layout | AllocatorTy::Usize | AllocatorTy::Ptr => {
panic!("invalid allocator output")
AllocatorTy::Never | AllocatorTy::ResultPtr | AllocatorTy::Unit => {
panic!("invalid allocator arg")
}
};
let from_name = mangle_internal_symbol(tcx, &global_fn_name(method.name));
let to_name = mangle_internal_symbol(tcx, &default_fn_name(method.name));

create_wrapper_function(tcx, context, &from_name, Some(&to_name), &types, output);
}
}
}
let output = match method.output {
AllocatorTy::ResultPtr => Some(i8p),
AllocatorTy::Never | AllocatorTy::Unit => None,

// FIXME(bjorn3): Add noreturn attribute
create_wrapper_function(
tcx,
context,
&mangle_internal_symbol(tcx, "__rust_alloc_error_handler"),
Some(&mangle_internal_symbol(tcx, alloc_error_handler_name(alloc_error_handler_kind))),
&[usize, usize],
None,
);
AllocatorTy::Layout | AllocatorTy::Usize | AllocatorTy::Ptr => {
panic!("invalid allocator output")
}
};
let from_name = mangle_internal_symbol(tcx, &global_fn_name(method.name));
let to_name = mangle_internal_symbol(tcx, &default_fn_name(method.name));

create_wrapper_function(tcx, context, &from_name, Some(&to_name), &types, output);
}

create_const_value_function(
tcx,
Expand Down
Loading
Loading