Skip to content

Commit 50bee58

Browse files
authored
Merge pull request #20960 from rust-lang/rustc-pull
minor: Rustc pull update
2 parents 8894253 + ac45201 commit 50bee58

12 files changed

Lines changed: 88 additions & 96 deletions

File tree

example/example.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,6 @@ pub fn debug_tuple() -> DebugTuple {
7272
DebugTuple(())
7373
}
7474

75-
pub fn size_of<T>() -> usize {
76-
intrinsics::size_of::<T>()
77-
}
78-
7975
pub fn use_size_of() -> usize {
8076
size_of::<u64>()
8177
}

example/mini_core.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
extern_types,
77
decl_macro,
88
rustc_attrs,
9+
rustc_private,
910
transparent_unions,
1011
auto_traits,
1112
freeze_impls,
@@ -594,7 +595,7 @@ impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Box<U>> for Box<T> {}
594595
impl<T> Box<T> {
595596
pub fn new(val: T) -> Box<T> {
596597
unsafe {
597-
let size = intrinsics::size_of::<T>();
598+
let size = size_of::<T>();
598599
let ptr = libc::malloc(size);
599600
intrinsics::copy(&val as *const T as *const u8, ptr, size);
600601
Box(Unique { pointer: NonNull(ptr as *const T), _marker: PhantomData }, Global)
@@ -646,11 +647,11 @@ pub mod intrinsics {
646647
#[rustc_intrinsic]
647648
pub fn abort() -> !;
648649
#[rustc_intrinsic]
649-
pub fn size_of<T>() -> usize;
650+
pub const fn size_of<T>() -> usize;
650651
#[rustc_intrinsic]
651652
pub unsafe fn size_of_val<T: ?::Sized>(val: *const T) -> usize;
652653
#[rustc_intrinsic]
653-
pub fn align_of<T>() -> usize;
654+
pub const fn align_of<T>() -> usize;
654655
#[rustc_intrinsic]
655656
pub unsafe fn align_of_val<T: ?::Sized>(val: *const T) -> usize;
656657
#[rustc_intrinsic]
@@ -715,6 +716,23 @@ impl<T> Index<usize> for [T] {
715716
}
716717
}
717718

719+
pub const fn size_of<T>() -> usize {
720+
<T as SizedTypeProperties>::SIZE
721+
}
722+
723+
pub const fn align_of<T>() -> usize {
724+
<T as SizedTypeProperties>::ALIGN
725+
}
726+
727+
trait SizedTypeProperties: Sized {
728+
#[lang = "mem_size_const"]
729+
const SIZE: usize = intrinsics::size_of::<Self>();
730+
731+
#[lang = "mem_align_const"]
732+
const ALIGN: usize = intrinsics::align_of::<Self>();
733+
}
734+
impl<T> SizedTypeProperties for T {}
735+
718736
extern "C" {
719737
type VaListImpl;
720738
}

example/mini_core_hello_world.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@ fn start<T: Termination + 'static>(
109109
puts(*argv as *const i8);
110110
}
111111
unsafe {
112-
puts(*((argv as usize + intrinsics::size_of::<*const u8>()) as *const *const i8));
112+
puts(*((argv as usize + size_of::<*const u8>()) as *const *const i8));
113113
}
114114
unsafe {
115-
puts(*((argv as usize + 2 * intrinsics::size_of::<*const u8>()) as *const *const i8));
115+
puts(*((argv as usize + 2 * size_of::<*const u8>()) as *const *const i8));
116116
}
117117
}
118118

@@ -213,8 +213,8 @@ fn main() {
213213
assert_eq!(intrinsics::size_of_val(a) as u8, 16);
214214
assert_eq!(intrinsics::size_of_val(&0u32) as u8, 4);
215215

216-
assert_eq!(intrinsics::align_of::<u16>() as u8, 2);
217-
assert_eq!(intrinsics::align_of_val(&a) as u8, intrinsics::align_of::<&str>() as u8);
216+
assert_eq!(align_of::<u16>() as u8, 2);
217+
assert_eq!(intrinsics::align_of_val(&a) as u8, align_of::<&str>() as u8);
218218

219219
let u8_needs_drop = const { intrinsics::needs_drop::<u8>() };
220220
assert!(!u8_needs_drop);

src/abi/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
467467
true
468468
} else {
469469
instance.is_some_and(|inst| {
470-
fx.tcx.codegen_fn_attrs(inst.def_id()).flags.contains(CodegenFnAttrFlags::COLD)
470+
fx.tcx.codegen_instance_attrs(inst.def).flags.contains(CodegenFnAttrFlags::COLD)
471471
})
472472
};
473473
if is_cold {

src/allocator.rs

Lines changed: 36 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33

44
use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext};
55
use rustc_ast::expand::allocator::{
6-
ALLOCATOR_METHODS, AllocatorKind, AllocatorTy, NO_ALLOC_SHIM_IS_UNSTABLE,
7-
alloc_error_handler_name, default_fn_name, global_fn_name,
6+
AllocatorMethod, AllocatorTy, NO_ALLOC_SHIM_IS_UNSTABLE, default_fn_name, global_fn_name,
87
};
9-
use rustc_codegen_ssa::base::allocator_kind_for_codegen;
8+
use rustc_codegen_ssa::base::{allocator_kind_for_codegen, allocator_shim_contents};
109
use rustc_session::config::OomStrategy;
1110
use rustc_symbol_mangling::mangle_internal_symbol;
1211

@@ -15,75 +14,57 @@ use crate::prelude::*;
1514
/// Returns whether an allocator shim was created
1615
pub(crate) fn codegen(tcx: TyCtxt<'_>, module: &mut dyn Module) -> bool {
1716
let Some(kind) = allocator_kind_for_codegen(tcx) else { return false };
18-
codegen_inner(
19-
tcx,
20-
module,
21-
kind,
22-
tcx.alloc_error_handler_kind(()).unwrap(),
23-
tcx.sess.opts.unstable_opts.oom,
24-
);
17+
let methods = allocator_shim_contents(tcx, kind);
18+
codegen_inner(tcx, module, &methods, tcx.sess.opts.unstable_opts.oom);
2519
true
2620
}
2721

2822
fn codegen_inner(
2923
tcx: TyCtxt<'_>,
3024
module: &mut dyn Module,
31-
kind: AllocatorKind,
32-
alloc_error_handler_kind: AllocatorKind,
25+
methods: &[AllocatorMethod],
3326
oom_strategy: OomStrategy,
3427
) {
3528
let usize_ty = module.target_config().pointer_type();
3629

37-
if kind == AllocatorKind::Default {
38-
for method in ALLOCATOR_METHODS {
39-
let mut arg_tys = Vec::with_capacity(method.inputs.len());
40-
for input in method.inputs.iter() {
41-
match input.ty {
42-
AllocatorTy::Layout => {
43-
arg_tys.push(usize_ty); // size
44-
arg_tys.push(usize_ty); // align
45-
}
46-
AllocatorTy::Ptr => arg_tys.push(usize_ty),
47-
AllocatorTy::Usize => arg_tys.push(usize_ty),
30+
for method in methods {
31+
let mut arg_tys = Vec::with_capacity(method.inputs.len());
32+
for input in method.inputs.iter() {
33+
match input.ty {
34+
AllocatorTy::Layout => {
35+
arg_tys.push(usize_ty); // size
36+
arg_tys.push(usize_ty); // align
37+
}
38+
AllocatorTy::Ptr => arg_tys.push(usize_ty),
39+
AllocatorTy::Usize => arg_tys.push(usize_ty),
4840

49-
AllocatorTy::ResultPtr | AllocatorTy::Unit => panic!("invalid allocator arg"),
41+
AllocatorTy::Never | AllocatorTy::ResultPtr | AllocatorTy::Unit => {
42+
panic!("invalid allocator arg")
5043
}
5144
}
52-
let output = match method.output {
53-
AllocatorTy::ResultPtr => Some(usize_ty),
54-
AllocatorTy::Unit => None,
45+
}
46+
let output = match method.output {
47+
AllocatorTy::ResultPtr => Some(usize_ty),
48+
AllocatorTy::Never | AllocatorTy::Unit => None,
5549

56-
AllocatorTy::Layout | AllocatorTy::Usize | AllocatorTy::Ptr => {
57-
panic!("invalid allocator output")
58-
}
59-
};
50+
AllocatorTy::Layout | AllocatorTy::Usize | AllocatorTy::Ptr => {
51+
panic!("invalid allocator output")
52+
}
53+
};
6054

61-
let sig = Signature {
62-
call_conv: module.target_config().default_call_conv,
63-
params: arg_tys.iter().cloned().map(AbiParam::new).collect(),
64-
returns: output.into_iter().map(AbiParam::new).collect(),
65-
};
66-
crate::common::create_wrapper_function(
67-
module,
68-
sig,
69-
&mangle_internal_symbol(tcx, &global_fn_name(method.name)),
70-
&mangle_internal_symbol(tcx, &default_fn_name(method.name)),
71-
);
72-
}
55+
let sig = Signature {
56+
call_conv: module.target_config().default_call_conv,
57+
params: arg_tys.iter().cloned().map(AbiParam::new).collect(),
58+
returns: output.into_iter().map(AbiParam::new).collect(),
59+
};
60+
crate::common::create_wrapper_function(
61+
module,
62+
sig,
63+
&mangle_internal_symbol(tcx, &global_fn_name(method.name)),
64+
&mangle_internal_symbol(tcx, &default_fn_name(method.name)),
65+
);
7366
}
7467

75-
let sig = Signature {
76-
call_conv: module.target_config().default_call_conv,
77-
params: vec![AbiParam::new(usize_ty), AbiParam::new(usize_ty)],
78-
returns: vec![],
79-
};
80-
crate::common::create_wrapper_function(
81-
module,
82-
sig,
83-
&mangle_internal_symbol(tcx, "__rust_alloc_error_handler"),
84-
&mangle_internal_symbol(tcx, alloc_error_handler_name(alloc_error_handler_kind)),
85-
);
86-
8768
{
8869
let sig = Signature {
8970
call_conv: module.target_config().default_call_conv,

src/base.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -829,19 +829,10 @@ fn codegen_stmt<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, cur_block: Block, stmt:
829829
fx.bcx.ins().nop();
830830
}
831831
}
832-
Rvalue::ShallowInitBox(ref operand, content_ty) => {
833-
let content_ty = fx.monomorphize(content_ty);
834-
let box_layout = fx.layout_of(Ty::new_box(fx.tcx, content_ty));
835-
let operand = codegen_operand(fx, operand);
836-
let operand = operand.load_scalar(fx);
837-
lval.write_cvalue(fx, CValue::by_val(operand, box_layout));
838-
}
839832
Rvalue::NullaryOp(ref null_op, ty) => {
840833
assert!(lval.layout().ty.is_sized(fx.tcx, fx.typing_env()));
841834
let layout = fx.layout_of(fx.monomorphize(ty));
842835
let val = match null_op {
843-
NullOp::SizeOf => layout.size.bytes(),
844-
NullOp::AlignOf => layout.align.bytes(),
845836
NullOp::OffsetOf(fields) => fx
846837
.tcx
847838
.offset_of_subfield(
@@ -924,6 +915,7 @@ fn codegen_stmt<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, cur_block: Block, stmt:
924915
lval.write_cvalue_transmute(fx, operand);
925916
}
926917
Rvalue::CopyForDeref(_) => bug!("`CopyForDeref` in codegen"),
918+
Rvalue::ShallowInitBox(..) => bug!("`ShallowInitBox` in codegen"),
927919
}
928920
}
929921
StatementKind::StorageLive(_)

src/constant.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ use std::cmp::Ordering;
55
use cranelift_module::*;
66
use rustc_data_structures::fx::FxHashSet;
77
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
8-
use rustc_middle::mir::interpret::{AllocId, GlobalAlloc, Scalar, read_target_uint};
8+
use rustc_middle::mir::interpret::{
9+
AllocId, GlobalAlloc, PointerArithmetic, Scalar, read_target_uint,
10+
};
911
use rustc_middle::ty::{ExistentialTraitRef, ScalarInt};
1012

1113
use crate::prelude::*;
@@ -138,8 +140,11 @@ pub(crate) fn codegen_const_value<'tcx>(
138140
let base_addr = match fx.tcx.global_alloc(alloc_id) {
139141
GlobalAlloc::Memory(alloc) => {
140142
if alloc.inner().len() == 0 {
141-
assert_eq!(offset, Size::ZERO);
142-
fx.bcx.ins().iconst(fx.pointer_type, alloc.inner().align.bytes() as i64)
143+
let val = alloc.inner().align.bytes().wrapping_add(offset.bytes());
144+
fx.bcx.ins().iconst(
145+
fx.pointer_type,
146+
fx.tcx.truncate_to_target_usize(val) as i64,
147+
)
143148
} else {
144149
let data_id = data_id_for_alloc_id(
145150
&mut fx.constants_cx,

src/driver/aot.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -671,18 +671,7 @@ pub(crate) fn run_aot(tcx: TyCtxt<'_>) -> Box<OngoingCodegen> {
671671
}
672672
.to_owned();
673673

674-
let cgus = if tcx.sess.opts.output_types.should_codegen() {
675-
tcx.collect_and_partition_mono_items(()).codegen_units
676-
} else {
677-
// If only `--emit metadata` is used, we shouldn't perform any codegen.
678-
// Also `tcx.collect_and_partition_mono_items` may panic in that case.
679-
return Box::new(OngoingCodegen {
680-
modules: vec![],
681-
allocator_module: None,
682-
crate_info: CrateInfo::new(tcx, target_cpu),
683-
concurrency_limiter: ConcurrencyLimiter::new(0),
684-
});
685-
};
674+
let cgus = tcx.collect_and_partition_mono_items(()).codegen_units;
686675

687676
if tcx.dep_graph.is_fully_enabled() {
688677
for cgu in cgus {

src/driver/jit.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ fn create_jit_module(tcx: TyCtxt<'_>) -> (UnwindModule<JITModule>, CodegenCx) {
3333
}
3434

3535
pub(crate) fn run_jit(tcx: TyCtxt<'_>, jit_args: Vec<String>) -> ! {
36-
if !tcx.sess.opts.output_types.should_codegen() {
37-
tcx.dcx().fatal("JIT mode doesn't work with `cargo check`");
38-
}
36+
// FIXME error on check mode or crate types other than bin in CodegenBackend::init()
3937

4038
if !tcx.crate_types().contains(&rustc_session::config::CrateType::Executable) {
4139
tcx.dcx().fatal("can't jit non-executable crate");

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,12 @@ extern crate rustc_fs_util;
2626
extern crate rustc_hir;
2727
extern crate rustc_incremental;
2828
extern crate rustc_index;
29+
extern crate rustc_log;
2930
extern crate rustc_metadata;
3031
extern crate rustc_session;
3132
extern crate rustc_span;
3233
extern crate rustc_symbol_mangling;
3334
extern crate rustc_target;
34-
#[macro_use]
35-
extern crate tracing;
3635

3736
// This prevents duplicating functions and statics that are already part of the host rustc process.
3837
#[allow(unused_extern_crates)]
@@ -46,6 +45,7 @@ use cranelift_codegen::isa::TargetIsa;
4645
use cranelift_codegen::settings::{self, Configurable};
4746
use rustc_codegen_ssa::traits::CodegenBackend;
4847
use rustc_codegen_ssa::{CodegenResults, TargetConfig};
48+
use rustc_log::tracing::info;
4949
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
5050
use rustc_session::Session;
5151
use rustc_session::config::OutputFilenames;

0 commit comments

Comments
 (0)