Skip to content

Commit ac1c5d6

Browse files
committed
Rustup to rustc 1.44.0-nightly (537ccdf3a 2020-04-02)
1 parent 17f99b4 commit ac1c5d6

File tree

14 files changed

+128
-52
lines changed

14 files changed

+128
-52
lines changed

build_sysroot/alloc_system/lib.rs

Lines changed: 89 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#![feature(nll)]
1919
#![feature(staged_api)]
2020
#![feature(rustc_attrs)]
21+
#![feature(alloc_layout_extra)]
2122
#![cfg_attr(
2223
all(target_arch = "wasm32", not(target_os = "emscripten")),
2324
feature(integer_atomics, stdsimd)
@@ -41,8 +42,10 @@ const MIN_ALIGN: usize = 8;
4142
target_arch = "sparc64")))]
4243
#[allow(dead_code)]
4344
const MIN_ALIGN: usize = 16;
44-
use core::alloc::{AllocRef, GlobalAlloc, AllocErr, Layout};
45+
use core::alloc::*;
4546
use core::ptr::NonNull;
47+
use core::intrinsics;
48+
4649
/// The default memory allocator provided by the operating system.
4750
///
4851
/// This is based on `malloc` on Unix platforms and `HeapAlloc` on Windows,
@@ -72,29 +75,97 @@ pub struct System;
7275
#[unstable(feature = "allocator_api", issue = "32838")]
7376
unsafe impl AllocRef for System {
7477
#[inline]
75-
fn alloc(&mut self, layout: Layout) -> Result<(NonNull<u8>, usize), AllocErr> {
76-
NonNull::new(unsafe { GlobalAlloc::alloc(self, layout) })
77-
.ok_or(AllocErr)
78-
.map(|p| (p, layout.size()))
78+
fn alloc(&mut self, layout: Layout, init: AllocInit) -> Result<MemoryBlock, AllocErr> {
79+
unsafe {
80+
let size = layout.size();
81+
if size == 0 {
82+
Ok(MemoryBlock { ptr: layout.dangling(), size: 0 })
83+
} else {
84+
let raw_ptr = match init {
85+
AllocInit::Uninitialized => GlobalAlloc::alloc(self, layout),
86+
AllocInit::Zeroed => GlobalAlloc::alloc_zeroed(self, layout),
87+
};
88+
let ptr = NonNull::new(raw_ptr).ok_or(AllocErr)?;
89+
Ok(MemoryBlock { ptr, size })
90+
}
91+
}
7992
}
93+
8094
#[inline]
81-
fn alloc_zeroed(&mut self, layout: Layout) -> Result<(NonNull<u8>, usize), AllocErr> {
82-
NonNull::new(unsafe { GlobalAlloc::alloc_zeroed(self, layout) })
83-
.ok_or(AllocErr)
84-
.map(|p| (p, layout.size()))
95+
unsafe fn dealloc(&mut self, ptr: NonNull<u8>, layout: Layout) {
96+
if layout.size() != 0 {
97+
GlobalAlloc::dealloc(self, ptr.as_ptr(), layout)
98+
}
8599
}
100+
86101
#[inline]
87-
unsafe fn dealloc(&mut self, ptr: NonNull<u8>, layout: Layout) {
88-
GlobalAlloc::dealloc(self, ptr.as_ptr(), layout)
102+
unsafe fn grow(
103+
&mut self,
104+
ptr: NonNull<u8>,
105+
layout: Layout,
106+
new_size: usize,
107+
placement: ReallocPlacement,
108+
init: AllocInit,
109+
) -> Result<MemoryBlock, AllocErr> {
110+
let size = layout.size();
111+
debug_assert!(
112+
new_size >= size,
113+
"`new_size` must be greater than or equal to `memory.size()`"
114+
);
115+
116+
if size == new_size {
117+
return Ok(MemoryBlock { ptr, size });
118+
}
119+
120+
match placement {
121+
ReallocPlacement::InPlace => Err(AllocErr),
122+
ReallocPlacement::MayMove if layout.size() == 0 => {
123+
let new_layout = Layout::from_size_align_unchecked(new_size, layout.align());
124+
self.alloc(new_layout, init)
125+
}
126+
ReallocPlacement::MayMove => {
127+
// `realloc` probably checks for `new_size > size` or something similar.
128+
intrinsics::assume(new_size > size);
129+
let ptr = GlobalAlloc::realloc(self, ptr.as_ptr(), layout, new_size);
130+
let memory =
131+
MemoryBlock { ptr: NonNull::new(ptr).ok_or(AllocErr)?, size: new_size };
132+
init.init_offset(memory, size);
133+
Ok(memory)
134+
}
135+
}
89136
}
137+
90138
#[inline]
91-
unsafe fn realloc(&mut self,
92-
ptr: NonNull<u8>,
93-
layout: Layout,
94-
new_size: usize) -> Result<(NonNull<u8>, usize), AllocErr> {
95-
NonNull::new(GlobalAlloc::realloc(self, ptr.as_ptr(), layout, new_size))
96-
.ok_or(AllocErr)
97-
.map(|p| (p, layout.size()))
139+
unsafe fn shrink(
140+
&mut self,
141+
ptr: NonNull<u8>,
142+
layout: Layout,
143+
new_size: usize,
144+
placement: ReallocPlacement,
145+
) -> Result<MemoryBlock, AllocErr> {
146+
let size = layout.size();
147+
debug_assert!(
148+
new_size <= size,
149+
"`new_size` must be smaller than or equal to `memory.size()`"
150+
);
151+
152+
if size == new_size {
153+
return Ok(MemoryBlock { ptr, size });
154+
}
155+
156+
match placement {
157+
ReallocPlacement::InPlace => Err(AllocErr),
158+
ReallocPlacement::MayMove if new_size == 0 => {
159+
self.dealloc(ptr, layout);
160+
Ok(MemoryBlock { ptr: layout.dangling(), size: 0 })
161+
}
162+
ReallocPlacement::MayMove => {
163+
// `realloc` probably checks for `new_size < size` or something similar.
164+
intrinsics::assume(new_size < size);
165+
let ptr = GlobalAlloc::realloc(self, ptr.as_ptr(), layout, new_size);
166+
Ok(MemoryBlock { ptr: NonNull::new(ptr).ok_or(AllocErr)?, size: new_size })
167+
}
168+
}
98169
}
99170
}
100171
#[cfg(any(windows, unix, target_os = "cloudabi", target_os = "redox"))]

rust-toolchain

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
nightly-2020-04-02
1+
nightly-2020-04-03

src/abi/comments.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub(super) fn add_local_place_comments<'tcx>(
6262
local: Local,
6363
) {
6464
let TyAndLayout { ty, layout } = place.layout();
65-
let ty::layout::Layout {
65+
let rustc_target::abi::Layout {
6666
size,
6767
align,
6868
abi: _,

src/abi/pass_mode.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ pub(super) fn get_pass_mode<'tcx>(tcx: TyCtxt<'tcx>, layout: TyAndLayout<'tcx>)
8282
PassMode::NoPass
8383
} else {
8484
match &layout.abi {
85-
layout::Abi::Uninhabited => PassMode::NoPass,
86-
layout::Abi::Scalar(scalar) => {
85+
Abi::Uninhabited => PassMode::NoPass,
86+
Abi::Scalar(scalar) => {
8787
PassMode::ByVal(scalar_to_clif_type(tcx, scalar.clone()))
8888
}
89-
layout::Abi::ScalarPair(a, b) => {
89+
Abi::ScalarPair(a, b) => {
9090
let a = scalar_to_clif_type(tcx, a.clone());
9191
let b = scalar_to_clif_type(tcx, b.clone());
9292
if a == types::I128 && b == types::I128 {
@@ -100,9 +100,9 @@ pub(super) fn get_pass_mode<'tcx>(tcx: TyCtxt<'tcx>, layout: TyAndLayout<'tcx>)
100100
}
101101

102102
// FIXME implement Vector Abi in a cg_llvm compatible way
103-
layout::Abi::Vector { .. } => PassMode::ByRef { sized: true },
103+
Abi::Vector { .. } => PassMode::ByRef { sized: true },
104104

105-
&layout::Abi::Aggregate { sized } => PassMode::ByRef { sized },
105+
&Abi::Aggregate { sized } => PassMode::ByRef { sized },
106106
}
107107
}
108108
}

src/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ fn trans_stmt<'tcx>(
592592
lval.write_cvalue(fx, CValue::by_val(len, usize_layout));
593593
}
594594
Rvalue::NullaryOp(NullOp::Box, content_ty) => {
595-
use rustc_middle::middle::lang_items::ExchangeMallocFnLangItem;
595+
use rustc_hir::lang_items::ExchangeMallocFnLangItem;
596596

597597
let usize_type = fx.clif_type(fx.tcx.types.usize).unwrap();
598598
let content_ty = fx.monomorphize(content_ty);

src/common.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rustc_middle::ty::layout::{Integer, Primitive};
1+
use rustc_target::abi::{Integer, Primitive};
22
use rustc_target::spec::{HasTargetSpec, Target};
33
use rustc_index::vec::IndexVec;
44

@@ -304,8 +304,8 @@ impl<'tcx, B: Backend + 'static> layout::HasTyCtxt<'tcx> for FunctionCx<'_, 'tcx
304304
}
305305
}
306306

307-
impl<'tcx, B: Backend + 'static> layout::HasDataLayout for FunctionCx<'_, 'tcx, B> {
308-
fn data_layout(&self) -> &layout::TargetDataLayout {
307+
impl<'tcx, B: Backend + 'static> rustc_target::abi::HasDataLayout for FunctionCx<'_, 'tcx, B> {
308+
fn data_layout(&self) -> &rustc_target::abi::TargetDataLayout {
309309
&self.tcx.data_layout
310310
}
311311
}

src/constant.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
66
use rustc_middle::mir::interpret::{
77
read_target_uint, AllocId, Allocation, ConstValue, GlobalAlloc, InterpResult, Scalar,
88
};
9-
use rustc_middle::ty::{layout::Align, Const, ConstKind};
9+
use rustc_middle::ty::{Const, ConstKind};
10+
use rustc_target::abi::Align;
1011
use rustc_data_structures::fx::FxHashSet;
1112
use rustc_mir::interpret::{
1213
ImmTy, InterpCx, Machine, Memory, MemoryKind, OpTy, PlaceTy, Pointer,

src/debuginfo/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use gimli::{Encoding, Format, LineEncoding, RunTimeEndian, X86_64};
1616
pub(crate) use emit::{DebugReloc, DebugRelocName};
1717

1818
fn target_endian(tcx: TyCtxt) -> RunTimeEndian {
19-
use rustc_middle::ty::layout::Endian;
19+
use rustc_target::abi::Endian;
2020

2121
match tcx.data_layout.endian {
2222
Endian::Big => RunTimeEndian::Big,

src/discriminant.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Adapted from https://github.com/rust-lang/rust/blob/d760df5aea483aae041c9a241e7acacf48f75035/src/librustc_codegen_ssa/mir/place.rs
22
3+
use rustc_target::abi::{DiscriminantKind, Int, Variants};
4+
35
use crate::prelude::*;
46

57
pub(crate) fn codegen_set_discriminant<'tcx>(
@@ -12,13 +14,13 @@ pub(crate) fn codegen_set_discriminant<'tcx>(
1214
return;
1315
}
1416
match layout.variants {
15-
layout::Variants::Single { index } => {
17+
Variants::Single { index } => {
1618
assert_eq!(index, variant_index);
1719
}
18-
layout::Variants::Multiple {
20+
Variants::Multiple {
1921
discr: _,
2022
discr_index,
21-
discr_kind: layout::DiscriminantKind::Tag,
23+
discr_kind: DiscriminantKind::Tag,
2224
variants: _,
2325
} => {
2426
let ptr = place.place_field(fx, mir::Field::new(discr_index));
@@ -30,11 +32,11 @@ pub(crate) fn codegen_set_discriminant<'tcx>(
3032
let discr = CValue::const_val(fx, ptr.layout(), to);
3133
ptr.write_cvalue(fx, discr);
3234
}
33-
layout::Variants::Multiple {
35+
Variants::Multiple {
3436
discr: _,
3537
discr_index,
3638
discr_kind:
37-
layout::DiscriminantKind::Niche {
39+
DiscriminantKind::Niche {
3840
dataful_variant,
3941
ref niche_variants,
4042
niche_start,
@@ -59,7 +61,7 @@ pub(crate) fn codegen_get_discriminant<'tcx>(
5961
) -> CValue<'tcx> {
6062
let layout = value.layout();
6163

62-
if layout.abi == layout::Abi::Uninhabited {
64+
if layout.abi == Abi::Uninhabited {
6365
return trap_unreachable_ret_value(
6466
fx,
6567
dest_layout,
@@ -68,14 +70,14 @@ pub(crate) fn codegen_get_discriminant<'tcx>(
6870
}
6971

7072
let (discr_scalar, discr_index, discr_kind) = match &layout.variants {
71-
layout::Variants::Single { index } => {
73+
Variants::Single { index } => {
7274
let discr_val = layout
7375
.ty
7476
.discriminant_for_variant(fx.tcx, *index)
7577
.map_or(u128::from(index.as_u32()), |discr| discr.val);
7678
return CValue::const_val(fx, dest_layout, discr_val);
7779
}
78-
layout::Variants::Multiple {
80+
Variants::Multiple {
7981
discr,
8082
discr_index,
8183
discr_kind,
@@ -91,15 +93,15 @@ pub(crate) fn codegen_get_discriminant<'tcx>(
9193

9294
// Decode the discriminant (specifically if it's niche-encoded).
9395
match *discr_kind {
94-
layout::DiscriminantKind::Tag => {
96+
DiscriminantKind::Tag => {
9597
let signed = match discr_scalar.value {
96-
layout::Int(_, signed) => signed,
98+
Int(_, signed) => signed,
9799
_ => false,
98100
};
99101
let val = clif_intcast(fx, encoded_discr, cast_to, signed);
100102
return CValue::by_val(val, dest_layout);
101103
}
102-
layout::DiscriminantKind::Niche {
104+
DiscriminantKind::Niche {
103105
dataful_variant,
104106
ref niche_variants,
105107
niche_start,

src/intrinsics/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ fn lane_type_and_count<'tcx>(
144144
) -> (TyAndLayout<'tcx>, u16) {
145145
assert!(layout.ty.is_simd());
146146
let lane_count = match layout.fields {
147-
layout::FieldsShape::Array { stride: _, count } => u16::try_from(count).unwrap(),
147+
rustc_target::abi::FieldsShape::Array { stride: _, count } => u16::try_from(count).unwrap(),
148148
_ => unreachable!("lane_type_and_count({:?})", layout),
149149
};
150150
let lane_layout = layout.field(&ty::layout::LayoutCx {

0 commit comments

Comments
 (0)