Skip to content

Commit 6f1899c

Browse files
committed
Sync from rust adaa838976ff99a4f0661136322f64cb466b58a0
2 parents 5aabbb6 + b548b29 commit 6f1899c

File tree

6 files changed

+27
-28
lines changed

6 files changed

+27
-28
lines changed

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,
@@ -596,7 +597,7 @@ impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Box<U>> for Box<T> {}
596597
impl<T> Box<T> {
597598
pub fn new(val: T) -> Box<T> {
598599
unsafe {
599-
let size = intrinsics::size_of::<T>();
600+
let size = size_of::<T>();
600601
let ptr = libc::malloc(size);
601602
intrinsics::copy(&val as *const T as *const u8, ptr, size);
602603
Box(Unique { pointer: NonNull(ptr as *const T), _marker: PhantomData }, Global)
@@ -648,11 +649,11 @@ pub mod intrinsics {
648649
#[rustc_intrinsic]
649650
pub fn abort() -> !;
650651
#[rustc_intrinsic]
651-
pub fn size_of<T>() -> usize;
652+
pub const fn size_of<T>() -> usize;
652653
#[rustc_intrinsic]
653654
pub unsafe fn size_of_val<T: ?crate::Sized>(val: *const T) -> usize;
654655
#[rustc_intrinsic]
655-
pub fn align_of<T>() -> usize;
656+
pub const fn align_of<T>() -> usize;
656657
#[rustc_intrinsic]
657658
pub unsafe fn align_of_val<T: ?crate::Sized>(val: *const T) -> usize;
658659
#[rustc_intrinsic]
@@ -717,6 +718,23 @@ impl<T> Index<usize> for [T] {
717718
}
718719
}
719720

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

example/mini_core_hello_world.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ fn start<T: Termination + 'static>(
100100
puts(*argv as *const i8);
101101
}
102102
unsafe {
103-
puts(*((argv as usize + intrinsics::size_of::<*const u8>()) as *const *const i8));
103+
puts(*((argv as usize + size_of::<*const u8>()) as *const *const i8));
104104
}
105105
unsafe {
106-
puts(*((argv as usize + 2 * intrinsics::size_of::<*const u8>()) as *const *const i8));
106+
puts(*((argv as usize + 2 * size_of::<*const u8>()) as *const *const i8));
107107
}
108108
}
109109

@@ -206,8 +206,8 @@ fn main() {
206206
assert_eq!(intrinsics::size_of_val(a) as u8, 16);
207207
assert_eq!(intrinsics::size_of_val(&0u32) as u8, 4);
208208

209-
assert_eq!(intrinsics::align_of::<u16>() as u8, 2);
210-
assert_eq!(intrinsics::align_of_val(&a) as u8, intrinsics::align_of::<&str>() as u8);
209+
assert_eq!(align_of::<u16>() as u8, 2);
210+
assert_eq!(intrinsics::align_of_val(&a) as u8, align_of::<&str>() as u8);
211211

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

src/base.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -857,8 +857,6 @@ fn codegen_stmt<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, cur_block: Block, stmt:
857857
assert!(lval.layout().ty.is_sized(fx.tcx, fx.typing_env()));
858858
let layout = fx.layout_of(fx.monomorphize(ty));
859859
let val = match null_op {
860-
NullOp::SizeOf => layout.size.bytes(),
861-
NullOp::AlignOf => layout.align.bytes(),
862860
NullOp::OffsetOf(fields) => fx
863861
.tcx
864862
.offset_of_subfield(

src/driver/aot.rs

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

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

690679
if tcx.dep_graph.is_fully_enabled() {
691680
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>, Option<DebugC
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");

0 commit comments

Comments
 (0)