move intrinsic to CTFE, add FIXME
This commit is contained in:
parent
899a59e7ca
commit
bc6eb6fa5d
3 changed files with 20 additions and 19 deletions
|
@ -13,6 +13,7 @@ use rustc_hir::def_id::DefId;
|
||||||
use rustc_middle::mir::AssertMessage;
|
use rustc_middle::mir::AssertMessage;
|
||||||
use rustc_session::Limit;
|
use rustc_session::Limit;
|
||||||
use rustc_span::symbol::{sym, Symbol};
|
use rustc_span::symbol::{sym, Symbol};
|
||||||
|
use rustc_target::abi::{Align, Size};
|
||||||
|
|
||||||
use crate::interpret::{
|
use crate::interpret::{
|
||||||
self, compile_time_machine, AllocId, Allocation, Frame, GlobalId, ImmTy, InterpCx,
|
self, compile_time_machine, AllocId, Allocation, Frame, GlobalId, ImmTy, InterpCx,
|
||||||
|
@ -304,6 +305,22 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
|
||||||
};
|
};
|
||||||
ecx.write_scalar(Scalar::from_bool(cmp), dest)?;
|
ecx.write_scalar(Scalar::from_bool(cmp), dest)?;
|
||||||
}
|
}
|
||||||
|
sym::const_allocate => {
|
||||||
|
let size = ecx.read_scalar(args[0])?.to_machine_usize(ecx)?;
|
||||||
|
let align = ecx.read_scalar(args[1])?.to_machine_usize(ecx)?;
|
||||||
|
|
||||||
|
let align = match Align::from_bytes(align) {
|
||||||
|
Ok(a) => a,
|
||||||
|
Err(err) => throw_ub_format!("align has to be a power of 2, {}", err),
|
||||||
|
};
|
||||||
|
|
||||||
|
let ptr = ecx.memory.allocate(
|
||||||
|
Size::from_bytes(size as u64),
|
||||||
|
align,
|
||||||
|
interpret::MemoryKind::ConstHeap,
|
||||||
|
);
|
||||||
|
ecx.write_scalar(Scalar::Ptr(ptr), dest)?;
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
return Err(ConstEvalErrKind::NeedsRfc(format!(
|
return Err(ConstEvalErrKind::NeedsRfc(format!(
|
||||||
"calling intrinsic `{}`",
|
"calling intrinsic `{}`",
|
||||||
|
|
|
@ -14,11 +14,10 @@ use rustc_middle::ty;
|
||||||
use rustc_middle::ty::subst::SubstsRef;
|
use rustc_middle::ty::subst::SubstsRef;
|
||||||
use rustc_middle::ty::{Ty, TyCtxt};
|
use rustc_middle::ty::{Ty, TyCtxt};
|
||||||
use rustc_span::symbol::{sym, Symbol};
|
use rustc_span::symbol::{sym, Symbol};
|
||||||
use rustc_target::abi::{Abi, Align, LayoutOf as _, Primitive, Size};
|
use rustc_target::abi::{Abi, LayoutOf as _, Primitive, Size};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
util::ensure_monomorphic_enough, CheckInAllocMsg, ImmTy, InterpCx, Machine, MemoryKind, OpTy,
|
util::ensure_monomorphic_enough, CheckInAllocMsg, ImmTy, InterpCx, Machine, OpTy, PlaceTy,
|
||||||
PlaceTy,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
mod caller_location;
|
mod caller_location;
|
||||||
|
@ -338,22 +337,6 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||||
let result = Scalar::from_uint(truncated_bits, layout.size);
|
let result = Scalar::from_uint(truncated_bits, layout.size);
|
||||||
self.write_scalar(result, dest)?;
|
self.write_scalar(result, dest)?;
|
||||||
}
|
}
|
||||||
sym::const_allocate => {
|
|
||||||
let size = self.read_scalar(args[0])?.to_machine_usize(self)?;
|
|
||||||
let align = self.read_scalar(args[1])?.to_machine_usize(self)?;
|
|
||||||
|
|
||||||
let align = match Align::from_bytes(align) {
|
|
||||||
Ok(a) => a,
|
|
||||||
Err(err) => throw_ub_format!("align has to be a power of 2, {}", err),
|
|
||||||
};
|
|
||||||
|
|
||||||
let ptr = self.memory.allocate(
|
|
||||||
Size::from_bytes(size as u64),
|
|
||||||
align,
|
|
||||||
MemoryKind::ConstHeap,
|
|
||||||
);
|
|
||||||
self.write_scalar(Scalar::Ptr(ptr), dest)?;
|
|
||||||
}
|
|
||||||
sym::offset => {
|
sym::offset => {
|
||||||
let ptr = self.read_scalar(args[0])?.check_init()?;
|
let ptr = self.read_scalar(args[0])?.check_init()?;
|
||||||
let offset_count = self.read_scalar(args[1])?.to_machine_isize(self)?;
|
let offset_count = self.read_scalar(args[1])?.to_machine_isize(self)?;
|
||||||
|
|
|
@ -28,6 +28,7 @@ pub enum MemoryKind<T> {
|
||||||
/// Stack memory. Error if deallocated except during a stack pop.
|
/// Stack memory. Error if deallocated except during a stack pop.
|
||||||
Stack,
|
Stack,
|
||||||
/// Heap memory.
|
/// Heap memory.
|
||||||
|
/// FIXME: this variant should be in const_eval
|
||||||
ConstHeap,
|
ConstHeap,
|
||||||
/// Memory backing vtables. Error if ever deallocated.
|
/// Memory backing vtables. Error if ever deallocated.
|
||||||
Vtable,
|
Vtable,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue