Skip to content

Commit

Permalink
compiler: Factor rustc_target::abi out of const_eval
Browse files Browse the repository at this point in the history
  • Loading branch information
workingjubilee committed Oct 9, 2024
1 parent 11c48be commit 9d95c8b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
1 change: 1 addition & 0 deletions compiler/rustc_const_eval/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition = "2021"
[dependencies]
# tidy-alphabetical-start
either = "1"
rustc_abi = { path = "../rustc_abi" }
rustc_apfloat = "0.2.0"
rustc_ast = { path = "../rustc_ast" }
rustc_attr = { path = "../rustc_attr" }
Expand Down
15 changes: 8 additions & 7 deletions compiler/rustc_const_eval/src/interpret/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
use std::assert_matches::assert_matches;

use either::{Either, Left, Right};
use rustc_abi as abi;
use rustc_abi::{Abi, HasDataLayout, Size};
use rustc_hir::def::Namespace;
use rustc_middle::mir::interpret::ScalarSizeMismatch;
use rustc_middle::ty::layout::{HasParamEnv, HasTyCtxt, LayoutOf, TyAndLayout};
use rustc_middle::ty::print::{FmtPrinter, PrettyPrinter};
use rustc_middle::ty::{ConstInt, ScalarInt, Ty, TyCtxt};
use rustc_middle::{bug, mir, span_bug, ty};
use rustc_target::abi::{self, Abi, HasDataLayout, Size};
use tracing::trace;

use super::{
Expand Down Expand Up @@ -117,7 +118,7 @@ impl<Prov: Provenance> Immediate<Prov> {
match (self, abi) {
(Immediate::Scalar(scalar), Abi::Scalar(s)) => {
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.
assert!(
matches!(scalar, Scalar::Int(..)),
Expand All @@ -131,7 +132,7 @@ impl<Prov: Provenance> Immediate<Prov> {
a.size(cx),
"{msg}: first component of scalar pair has wrong size"
);
if !matches!(a.primitive(), abi::Pointer(..)) {
if !matches!(a.primitive(), abi::Primitive::Pointer(..)) {
assert!(
matches!(a_val, Scalar::Int(..)),
"{msg}: first component of scalar pair should be an integer, but has provenance"
Expand All @@ -142,7 +143,7 @@ impl<Prov: Provenance> Immediate<Prov> {
b.size(cx),
"{msg}: second component of scalar pair has wrong size"
);
if !matches!(b.primitive(), abi::Pointer(..)) {
if !matches!(b.primitive(), abi::Primitive::Pointer(..)) {
assert!(
matches!(b_val, Scalar::Int(..)),
"{msg}: second component of scalar pair should be an integer, but has provenance"
Expand Down Expand Up @@ -572,7 +573,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
assert_eq!(size, mplace.layout.size, "abi::Scalar size does not match layout size");
let scalar = alloc.read_scalar(
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))
}
Expand All @@ -588,11 +589,11 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
assert!(b_offset.bytes() > 0); // in `operand_field` we use the offset to tell apart the fields
let a_val = alloc.read_scalar(
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(
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))
}
Expand Down

0 comments on commit 9d95c8b

Please sign in to comment.