Skip to content

Commit b6a8915

Browse files
authored
Rollup merge of rust-lang#72538 - rakshith-ravi:refactor/remove-const-query, r=oli-obk
Removed all instances of const_field. Fixes rust-lang#72264 r? @oli-obk
2 parents 036688f + 245ebc7 commit b6a8915

File tree

6 files changed

+7
-51
lines changed

6 files changed

+7
-51
lines changed

src/librustc_codegen_ssa/mir/constant.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::mir::operand::OperandRef;
22
use crate::traits::*;
3-
use rustc_index::vec::Idx;
43
use rustc_middle::mir;
54
use rustc_middle::mir::interpret::{ConstValue, ErrorHandled};
65
use rustc_middle::ty::layout::HasTyCtxt;
@@ -59,17 +58,14 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
5958
constant
6059
.map(|val| {
6160
let field_ty = ty.builtin_index().unwrap();
62-
let fields = match ty.kind {
63-
ty::Array(_, n) => n.eval_usize(bx.tcx(), ty::ParamEnv::reveal_all()),
64-
_ => bug!("invalid simd shuffle type: {}", ty),
65-
};
6661
let c = ty::Const::from_value(bx.tcx(), val, ty);
67-
let values: Vec<_> = (0..fields)
62+
let values: Vec<_> = bx
63+
.tcx()
64+
.destructure_const(ty::ParamEnv::reveal_all().and(&c))
65+
.fields
66+
.into_iter()
6867
.map(|field| {
69-
let field = bx.tcx().const_field(
70-
ty::ParamEnv::reveal_all().and((&c, mir::Field::new(field as usize))),
71-
);
72-
if let Some(prim) = field.try_to_scalar() {
68+
if let Some(prim) = field.val.try_to_scalar() {
7369
let layout = bx.layout_of(field_ty);
7470
let scalar = match layout.abi {
7571
Abi::Scalar(ref x) => x,

src/librustc_middle/dep_graph/dep_node.rs

-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
//! user of the `DepNode` API of having to know how to compute the expected
5050
//! fingerprint for a given set of node parameters.
5151
52-
use crate::mir;
5352
use crate::mir::interpret::{GlobalId, LitToConstInput};
5453
use crate::traits;
5554
use crate::traits::query::{

src/librustc_middle/query/mod.rs

-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::dep_graph::SerializedDepNodeIndex;
2-
use crate::mir;
32
use crate::mir::interpret::{GlobalId, LitToConstInput};
43
use crate::traits;
54
use crate::traits::query::{
@@ -553,13 +552,6 @@ rustc_queries! {
553552
}
554553
}
555554

556-
/// Extracts a field of a (variant of a) const.
557-
query const_field(
558-
key: ty::ParamEnvAnd<'tcx, (&'tcx ty::Const<'tcx>, mir::Field)>
559-
) -> ConstValue<'tcx> {
560-
desc { "extract field of const" }
561-
}
562-
563555
/// Destructure a constant ADT or array into its variant index and its
564556
/// field values.
565557
query destructure_const(

src/librustc_mir/const_eval/eval_queries.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ pub(super) fn op_to_const<'tcx>(
122122
} else {
123123
// It is guaranteed that any non-slice scalar pair is actually ByRef here.
124124
// When we come back from raw const eval, we are always by-ref. The only way our op here is
125-
// by-val is if we are in const_field, i.e., if this is (a field of) something that we
125+
// by-val is if we are in destructure_const, i.e., if this is (a field of) something that we
126126
// "tried to make immediate" before. We wouldn't do that for non-slice scalar pairs or
127127
// structs containing such.
128128
op.try_as_mplace(ecx)

src/librustc_mir/const_eval/mod.rs

-27
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use std::convert::TryFrom;
55
use rustc_middle::mir;
66
use rustc_middle::ty::{self, TyCtxt};
77
use rustc_span::{source_map::DUMMY_SP, symbol::Symbol};
8-
use rustc_target::abi::VariantIdx;
98

109
use crate::interpret::{intern_const_alloc_recursive, ConstValue, InternKind, InterpCx};
1110

@@ -19,32 +18,6 @@ pub use eval_queries::*;
1918
pub use fn_queries::*;
2019
pub use machine::*;
2120

22-
/// Extracts a field of a (variant of a) const.
23-
// this function uses `unwrap` copiously, because an already validated constant must have valid
24-
// fields and can thus never fail outside of compiler bugs
25-
pub(crate) fn const_field<'tcx>(
26-
tcx: TyCtxt<'tcx>,
27-
param_env: ty::ParamEnv<'tcx>,
28-
variant: Option<VariantIdx>,
29-
field: mir::Field,
30-
value: &'tcx ty::Const<'tcx>,
31-
) -> ConstValue<'tcx> {
32-
trace!("const_field: {:?}, {:?}", field, value);
33-
let ecx = mk_eval_cx(tcx, DUMMY_SP, param_env, false);
34-
// get the operand again
35-
let op = ecx.eval_const_to_op(value, None).unwrap();
36-
// downcast
37-
let down = match variant {
38-
None => op,
39-
Some(variant) => ecx.operand_downcast(op, variant).unwrap(),
40-
};
41-
// then project
42-
let field = ecx.operand_field(down, field.index()).unwrap();
43-
// and finally move back to the const world, always normalizing because
44-
// this is not called for statics.
45-
op_to_const(&ecx, field)
46-
}
47-
4821
pub(crate) fn const_caller_location(
4922
tcx: TyCtxt<'tcx>,
5023
(file, line, col): (Symbol, u32, u32),

src/librustc_mir/lib.rs

-4
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,6 @@ pub fn provide(providers: &mut Providers<'_>) {
5656
providers.const_eval_validated = const_eval::const_eval_validated_provider;
5757
providers.const_eval_raw = const_eval::const_eval_raw_provider;
5858
providers.const_caller_location = const_eval::const_caller_location;
59-
providers.const_field = |tcx, param_env_and_value| {
60-
let (param_env, (value, field)) = param_env_and_value.into_parts();
61-
const_eval::const_field(tcx, param_env, None, field, value)
62-
};
6359
providers.destructure_const = |tcx, param_env_and_value| {
6460
let (param_env, value) = param_env_and_value.into_parts();
6561
const_eval::destructure_const(tcx, param_env, value)

0 commit comments

Comments
 (0)