compiler: Factor rustc_target::abi out of const_eval
This commit is contained in:
parent
11c48bee11
commit
9d95c8bd16
@ -6,6 +6,7 @@ edition = "2021"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
# tidy-alphabetical-start
|
# tidy-alphabetical-start
|
||||||
either = "1"
|
either = "1"
|
||||||
|
rustc_abi = { path = "../rustc_abi" }
|
||||||
rustc_apfloat = "0.2.0"
|
rustc_apfloat = "0.2.0"
|
||||||
rustc_ast = { path = "../rustc_ast" }
|
rustc_ast = { path = "../rustc_ast" }
|
||||||
rustc_attr = { path = "../rustc_attr" }
|
rustc_attr = { path = "../rustc_attr" }
|
||||||
|
@ -4,13 +4,14 @@
|
|||||||
use std::assert_matches::assert_matches;
|
use std::assert_matches::assert_matches;
|
||||||
|
|
||||||
use either::{Either, Left, Right};
|
use either::{Either, Left, Right};
|
||||||
|
use rustc_abi as abi;
|
||||||
|
use rustc_abi::{Abi, HasDataLayout, Size};
|
||||||
use rustc_hir::def::Namespace;
|
use rustc_hir::def::Namespace;
|
||||||
use rustc_middle::mir::interpret::ScalarSizeMismatch;
|
use rustc_middle::mir::interpret::ScalarSizeMismatch;
|
||||||
use rustc_middle::ty::layout::{HasParamEnv, HasTyCtxt, LayoutOf, TyAndLayout};
|
use rustc_middle::ty::layout::{HasParamEnv, HasTyCtxt, LayoutOf, TyAndLayout};
|
||||||
use rustc_middle::ty::print::{FmtPrinter, PrettyPrinter};
|
use rustc_middle::ty::print::{FmtPrinter, PrettyPrinter};
|
||||||
use rustc_middle::ty::{ConstInt, ScalarInt, Ty, TyCtxt};
|
use rustc_middle::ty::{ConstInt, ScalarInt, Ty, TyCtxt};
|
||||||
use rustc_middle::{bug, mir, span_bug, ty};
|
use rustc_middle::{bug, mir, span_bug, ty};
|
||||||
use rustc_target::abi::{self, Abi, HasDataLayout, Size};
|
|
||||||
use tracing::trace;
|
use tracing::trace;
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
@ -117,7 +118,7 @@ pub fn assert_matches_abi(self, abi: Abi, msg: &str, cx: &impl HasDataLayout) {
|
|||||||
match (self, abi) {
|
match (self, abi) {
|
||||||
(Immediate::Scalar(scalar), Abi::Scalar(s)) => {
|
(Immediate::Scalar(scalar), Abi::Scalar(s)) => {
|
||||||
assert_eq!(scalar.size(), s.size(cx), "{msg}: scalar value has wrong size");
|
assert_eq!(scalar.size(), s.size(cx), "{msg}: scalar value has wrong size");
|
||||||
if !matches!(s.primitive(), abi::Pointer(..)) {
|
if !matches!(s.primitive(), abi::Primitive::Pointer(..)) {
|
||||||
// This is not a pointer, it should not carry provenance.
|
// This is not a pointer, it should not carry provenance.
|
||||||
assert!(
|
assert!(
|
||||||
matches!(scalar, Scalar::Int(..)),
|
matches!(scalar, Scalar::Int(..)),
|
||||||
@ -131,7 +132,7 @@ pub fn assert_matches_abi(self, abi: Abi, msg: &str, cx: &impl HasDataLayout) {
|
|||||||
a.size(cx),
|
a.size(cx),
|
||||||
"{msg}: first component of scalar pair has wrong size"
|
"{msg}: first component of scalar pair has wrong size"
|
||||||
);
|
);
|
||||||
if !matches!(a.primitive(), abi::Pointer(..)) {
|
if !matches!(a.primitive(), abi::Primitive::Pointer(..)) {
|
||||||
assert!(
|
assert!(
|
||||||
matches!(a_val, Scalar::Int(..)),
|
matches!(a_val, Scalar::Int(..)),
|
||||||
"{msg}: first component of scalar pair should be an integer, but has provenance"
|
"{msg}: first component of scalar pair should be an integer, but has provenance"
|
||||||
@ -142,7 +143,7 @@ pub fn assert_matches_abi(self, abi: Abi, msg: &str, cx: &impl HasDataLayout) {
|
|||||||
b.size(cx),
|
b.size(cx),
|
||||||
"{msg}: second component of scalar pair has wrong size"
|
"{msg}: second component of scalar pair has wrong size"
|
||||||
);
|
);
|
||||||
if !matches!(b.primitive(), abi::Pointer(..)) {
|
if !matches!(b.primitive(), abi::Primitive::Pointer(..)) {
|
||||||
assert!(
|
assert!(
|
||||||
matches!(b_val, Scalar::Int(..)),
|
matches!(b_val, Scalar::Int(..)),
|
||||||
"{msg}: second component of scalar pair should be an integer, but has provenance"
|
"{msg}: second component of scalar pair should be an integer, but has provenance"
|
||||||
@ -572,7 +573,7 @@ fn read_immediate_from_mplace_raw(
|
|||||||
assert_eq!(size, mplace.layout.size, "abi::Scalar size does not match layout size");
|
assert_eq!(size, mplace.layout.size, "abi::Scalar size does not match layout size");
|
||||||
let scalar = alloc.read_scalar(
|
let scalar = alloc.read_scalar(
|
||||||
alloc_range(Size::ZERO, size),
|
alloc_range(Size::ZERO, size),
|
||||||
/*read_provenance*/ matches!(s, abi::Pointer(_)),
|
/*read_provenance*/ matches!(s, abi::Primitive::Pointer(_)),
|
||||||
)?;
|
)?;
|
||||||
Some(ImmTy::from_scalar(scalar, mplace.layout))
|
Some(ImmTy::from_scalar(scalar, mplace.layout))
|
||||||
}
|
}
|
||||||
@ -588,11 +589,11 @@ fn read_immediate_from_mplace_raw(
|
|||||||
assert!(b_offset.bytes() > 0); // in `operand_field` we use the offset to tell apart the fields
|
assert!(b_offset.bytes() > 0); // in `operand_field` we use the offset to tell apart the fields
|
||||||
let a_val = alloc.read_scalar(
|
let a_val = alloc.read_scalar(
|
||||||
alloc_range(Size::ZERO, a_size),
|
alloc_range(Size::ZERO, a_size),
|
||||||
/*read_provenance*/ matches!(a, abi::Pointer(_)),
|
/*read_provenance*/ matches!(a, abi::Primitive::Pointer(_)),
|
||||||
)?;
|
)?;
|
||||||
let b_val = alloc.read_scalar(
|
let b_val = alloc.read_scalar(
|
||||||
alloc_range(b_offset, b_size),
|
alloc_range(b_offset, b_size),
|
||||||
/*read_provenance*/ matches!(b, abi::Pointer(_)),
|
/*read_provenance*/ matches!(b, abi::Primitive::Pointer(_)),
|
||||||
)?;
|
)?;
|
||||||
Some(ImmTy::from_immediate(Immediate::ScalarPair(a_val, b_val), mplace.layout))
|
Some(ImmTy::from_immediate(Immediate::ScalarPair(a_val, b_val), mplace.layout))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user