Rollup merge of #115972 - RalfJung:const-consistency, r=oli-obk
rename mir::Constant -> mir::ConstOperand, mir::ConstKind -> mir::Const Also, be more consistent with the `to/eval_bits` methods... we had some that take a type and some that take a size, and then sometimes the one that takes a type is called `bits_for_ty`. Turns out that `ty::Const`/`mir::ConstKind` carry their type with them, so we don't need to even pass the type to those `eval_bits` functions at all. However this is not properly consistent yet: in `ty` we have most of the methods on `ty::Const`, but in `mir` we have them on `mir::ConstKind`. And indeed those two types are the ones that correspond to each other. So `mir::ConstantKind` should actually be renamed to `mir::Const`. But what to do with `mir::Constant`? It carries around a span, that's really more like a constant operand that appears as a MIR operand... it's more suited for `syntax.rs` than `consts.rs`, but the bigger question is, which name should it get if we want to align the `mir` and `ty` types? `ConstOperand`? `ConstOp`? `Literal`? It's not a literal but it has a field called `literal` so it would at least be consistently wrong-ish... ``@oli-obk`` any ideas?
This commit is contained in:
commit
208f6ed95c
76 changed files with 461 additions and 493 deletions
|
@ -746,20 +746,20 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
|
|||
/// to walk it would attempt to evaluate the `ty::Const` inside, which doesn't necessarily
|
||||
/// work, as some constants cannot be represented in the type system.
|
||||
#[instrument(skip(self), level = "debug")]
|
||||
fn visit_constant(&mut self, constant: &mir::Constant<'tcx>, location: Location) {
|
||||
let literal = self.monomorphize(constant.literal);
|
||||
fn visit_constant(&mut self, constant: &mir::ConstOperand<'tcx>, location: Location) {
|
||||
let const_ = self.monomorphize(constant.const_);
|
||||
let param_env = ty::ParamEnv::reveal_all();
|
||||
let val = match literal.eval(self.tcx, param_env, None) {
|
||||
let val = match const_.eval(self.tcx, param_env, None) {
|
||||
Ok(v) => v,
|
||||
Err(ErrorHandled::Reported(..)) => return,
|
||||
Err(ErrorHandled::TooGeneric(..)) => span_bug!(
|
||||
self.body.source_info(location).span,
|
||||
"collection encountered polymorphic constant: {:?}",
|
||||
literal
|
||||
const_
|
||||
),
|
||||
};
|
||||
collect_const_value(self.tcx, val, self.output);
|
||||
MirVisitor::visit_ty(self, literal.ty(), TyContext::Location(location));
|
||||
MirVisitor::visit_ty(self, const_.ty(), TyContext::Location(location));
|
||||
}
|
||||
|
||||
fn visit_terminator(&mut self, terminator: &mir::Terminator<'tcx>, location: Location) {
|
||||
|
@ -796,7 +796,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
|
|||
for op in operands {
|
||||
match *op {
|
||||
mir::InlineAsmOperand::SymFn { ref value } => {
|
||||
let fn_ty = self.monomorphize(value.literal.ty());
|
||||
let fn_ty = self.monomorphize(value.const_.ty());
|
||||
visit_fn_use(self.tcx, fn_ty, false, source, &mut self.output, &[]);
|
||||
}
|
||||
mir::InlineAsmOperand::SymStatic { def_id } => {
|
||||
|
|
|
@ -9,13 +9,13 @@ use rustc_hir::{def::DefKind, def_id::DefId, ConstContext};
|
|||
use rustc_middle::mir::{
|
||||
self,
|
||||
visit::{TyContext, Visitor},
|
||||
Constant, ConstantKind, Local, LocalDecl, Location,
|
||||
Local, LocalDecl, Location,
|
||||
};
|
||||
use rustc_middle::query::Providers;
|
||||
use rustc_middle::ty::{
|
||||
self,
|
||||
visit::{TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor},
|
||||
Const, GenericArgsRef, Ty, TyCtxt, UnusedGenericParams,
|
||||
GenericArgsRef, Ty, TyCtxt, UnusedGenericParams,
|
||||
};
|
||||
use rustc_span::symbol::sym;
|
||||
use std::ops::ControlFlow;
|
||||
|
@ -261,12 +261,12 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> {
|
|||
self.super_local_decl(local, local_decl);
|
||||
}
|
||||
|
||||
fn visit_constant(&mut self, ct: &Constant<'tcx>, location: Location) {
|
||||
match ct.literal {
|
||||
ConstantKind::Ty(c) => {
|
||||
fn visit_constant(&mut self, ct: &mir::ConstOperand<'tcx>, location: Location) {
|
||||
match ct.const_ {
|
||||
mir::Const::Ty(c) => {
|
||||
c.visit_with(self);
|
||||
}
|
||||
ConstantKind::Unevaluated(mir::UnevaluatedConst { def, args: _, promoted }, ty) => {
|
||||
mir::Const::Unevaluated(mir::UnevaluatedConst { def, args: _, promoted }, ty) => {
|
||||
// Avoid considering `T` unused when constants are of the form:
|
||||
// `<Self as Foo<T>>::foo::promoted[p]`
|
||||
if let Some(p) = promoted {
|
||||
|
@ -280,7 +280,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> {
|
|||
|
||||
Visitor::visit_ty(self, ty, TyContext::Location(location));
|
||||
}
|
||||
ConstantKind::Val(_, ty) => Visitor::visit_ty(self, ty, TyContext::Location(location)),
|
||||
mir::Const::Val(_, ty) => Visitor::visit_ty(self, ty, TyContext::Location(location)),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -291,7 +291,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> {
|
|||
|
||||
impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for MarkUsedGenericParams<'a, 'tcx> {
|
||||
#[instrument(level = "debug", skip(self))]
|
||||
fn visit_const(&mut self, c: Const<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||
fn visit_const(&mut self, c: ty::Const<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||
if !c.has_non_region_param() {
|
||||
return ControlFlow::Continue(());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue