use TypingEnv
when no infcx
is available
the behavior of the type system not only depends on the current assumptions, but also the currentnphase of the compiler. This is mostly necessary as we need to decide whether and how to reveal opaque types. We track this via the `TypingMode`.
This commit is contained in:
parent
bf6adec108
commit
9cba14b95b
240 changed files with 1739 additions and 1340 deletions
|
@ -41,7 +41,7 @@ pub(crate) fn try_new_allocation<'tcx>(
|
|||
let size = scalar.size();
|
||||
let align = tables
|
||||
.tcx
|
||||
.layout_of(rustc_middle::ty::ParamEnv::reveal_all().and(ty))
|
||||
.layout_of(rustc_middle::ty::TypingEnv::fully_monomorphized().as_query_input(ty))
|
||||
.map_err(|e| e.stable(tables))?
|
||||
.align;
|
||||
let mut allocation = rustc_middle::mir::interpret::Allocation::uninit(size, align.abi);
|
||||
|
@ -53,7 +53,7 @@ pub(crate) fn try_new_allocation<'tcx>(
|
|||
ConstValue::ZeroSized => {
|
||||
let align = tables
|
||||
.tcx
|
||||
.layout_of(rustc_middle::ty::ParamEnv::empty().and(ty))
|
||||
.layout_of(rustc_middle::ty::TypingEnv::fully_monomorphized().as_query_input(ty))
|
||||
.map_err(|e| e.stable(tables))?
|
||||
.align;
|
||||
new_empty_allocation(align.abi)
|
||||
|
@ -66,7 +66,7 @@ pub(crate) fn try_new_allocation<'tcx>(
|
|||
rustc_middle::mir::interpret::Scalar::from_target_usize(meta, &tables.tcx);
|
||||
let layout = tables
|
||||
.tcx
|
||||
.layout_of(rustc_middle::ty::ParamEnv::reveal_all().and(ty))
|
||||
.layout_of(rustc_middle::ty::TypingEnv::fully_monomorphized().as_query_input(ty))
|
||||
.map_err(|e| e.stable(tables))?;
|
||||
let mut allocation =
|
||||
rustc_middle::mir::interpret::Allocation::uninit(layout.size, layout.align.abi);
|
||||
|
@ -90,7 +90,7 @@ pub(crate) fn try_new_allocation<'tcx>(
|
|||
let alloc = tables.tcx.global_alloc(alloc_id).unwrap_memory();
|
||||
let ty_size = tables
|
||||
.tcx
|
||||
.layout_of(rustc_middle::ty::ParamEnv::reveal_all().and(ty))
|
||||
.layout_of(rustc_middle::ty::TypingEnv::fully_monomorphized().as_query_input(ty))
|
||||
.map_err(|e| e.stable(tables))?
|
||||
.size;
|
||||
allocation_filter(&alloc.0, alloc_range(offset, ty_size), tables)
|
||||
|
|
|
@ -40,7 +40,7 @@ impl<'tcx> BodyBuilder<'tcx> {
|
|||
{
|
||||
let mut mono_body = self.instance.instantiate_mir_and_normalize_erasing_regions(
|
||||
tables.tcx,
|
||||
ty::ParamEnv::reveal_all(),
|
||||
ty::TypingEnv::fully_monomorphized(),
|
||||
ty::EarlyBinder::bind(body),
|
||||
);
|
||||
self.visit_body(&mut mono_body);
|
||||
|
@ -60,7 +60,7 @@ impl<'tcx> MutVisitor<'tcx> for BodyBuilder<'tcx> {
|
|||
location: mir::Location,
|
||||
) {
|
||||
let const_ = constant.const_;
|
||||
let val = match const_.eval(self.tcx, ty::ParamEnv::reveal_all(), constant.span) {
|
||||
let val = match const_.eval(self.tcx, ty::TypingEnv::fully_monomorphized(), constant.span) {
|
||||
Ok(v) => v,
|
||||
Err(mir::interpret::ErrorHandled::Reported(..)) => return,
|
||||
Err(mir::interpret::ErrorHandled::TooGeneric(..)) => {
|
||||
|
|
|
@ -11,7 +11,7 @@ use std::iter;
|
|||
use rustc_abi::HasDataLayout;
|
||||
use rustc_hir::LangItem;
|
||||
use rustc_middle::ty::layout::{
|
||||
FnAbiOf, FnAbiOfHelpers, HasParamEnv, HasTyCtxt, LayoutOf, LayoutOfHelpers,
|
||||
FnAbiOf, FnAbiOfHelpers, HasTyCtxt, HasTypingEnv, LayoutOf, LayoutOfHelpers,
|
||||
};
|
||||
use rustc_middle::ty::print::{with_forced_trimmed_paths, with_no_trimmed_paths};
|
||||
use rustc_middle::ty::{
|
||||
|
@ -410,7 +410,7 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
|
|||
let tcx = tables.tcx;
|
||||
let mir_const = cnst.internal(&mut *tables, tcx);
|
||||
mir_const
|
||||
.try_eval_target_usize(tables.tcx, ParamEnv::empty())
|
||||
.try_eval_target_usize(tables.tcx, ty::TypingEnv::fully_monomorphized())
|
||||
.ok_or_else(|| Error::new(format!("Const `{cnst:?}` cannot be encoded as u64")))
|
||||
}
|
||||
fn eval_target_usize_ty(&self, cnst: &TyConst) -> Result<u64, Error> {
|
||||
|
@ -428,7 +428,7 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
|
|||
let ty_internal = ty.internal(&mut *tables, tcx);
|
||||
let size = tables
|
||||
.tcx
|
||||
.layout_of(ParamEnv::empty().and(ty_internal))
|
||||
.layout_of(ty::TypingEnv::fully_monomorphized().as_query_input(ty_internal))
|
||||
.map_err(|err| {
|
||||
Error::new(format!(
|
||||
"Cannot create a zero-sized constant for type `{ty_internal}`: {err}"
|
||||
|
@ -469,7 +469,11 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
|
|||
let mut tables = self.0.borrow_mut();
|
||||
let tcx = tables.tcx;
|
||||
let ty = ty::Ty::new_uint(tcx, uint_ty.internal(&mut *tables, tcx));
|
||||
let size = tables.tcx.layout_of(ParamEnv::empty().and(ty)).unwrap().size;
|
||||
let size = tables
|
||||
.tcx
|
||||
.layout_of(ty::TypingEnv::fully_monomorphized().as_query_input(ty))
|
||||
.unwrap()
|
||||
.size;
|
||||
|
||||
// We don't use Const::from_bits since it doesn't have any error checking.
|
||||
let scalar = ScalarInt::try_from_uint(value, size).ok_or_else(|| {
|
||||
|
@ -486,7 +490,11 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
|
|||
let mut tables = self.0.borrow_mut();
|
||||
let tcx = tables.tcx;
|
||||
let ty = ty::Ty::new_uint(tcx, uint_ty.internal(&mut *tables, tcx));
|
||||
let size = tables.tcx.layout_of(ParamEnv::empty().and(ty)).unwrap().size;
|
||||
let size = tables
|
||||
.tcx
|
||||
.layout_of(ty::TypingEnv::fully_monomorphized().as_query_input(ty))
|
||||
.unwrap()
|
||||
.size;
|
||||
|
||||
// We don't use Const::from_bits since it doesn't have any error checking.
|
||||
let scalar = ScalarInt::try_from_uint(value, size).ok_or_else(|| {
|
||||
|
@ -523,7 +531,11 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
|
|||
let def_ty = tables.tcx.type_of(item.internal(&mut *tables, tcx));
|
||||
tables
|
||||
.tcx
|
||||
.instantiate_and_normalize_erasing_regions(args, ty::ParamEnv::reveal_all(), def_ty)
|
||||
.instantiate_and_normalize_erasing_regions(
|
||||
args,
|
||||
ty::TypingEnv::fully_monomorphized(),
|
||||
def_ty,
|
||||
)
|
||||
.stable(&mut *tables)
|
||||
}
|
||||
|
||||
|
@ -573,7 +585,7 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
|
|||
let mut tables = self.0.borrow_mut();
|
||||
let instance = tables.instances[def];
|
||||
assert!(!instance.has_non_region_param(), "{instance:?} needs further instantiation");
|
||||
instance.ty(tables.tcx, ParamEnv::reveal_all()).stable(&mut *tables)
|
||||
instance.ty(tables.tcx, ty::TypingEnv::fully_monomorphized()).stable(&mut *tables)
|
||||
}
|
||||
|
||||
fn instance_args(&self, def: InstanceDef) -> GenericArgs {
|
||||
|
@ -642,7 +654,12 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
|
|||
let tcx = tables.tcx;
|
||||
let def_id = def.0.internal(&mut *tables, tcx);
|
||||
let args_ref = args.internal(&mut *tables, tcx);
|
||||
match Instance::try_resolve(tables.tcx, ParamEnv::reveal_all(), def_id, args_ref) {
|
||||
match Instance::try_resolve(
|
||||
tables.tcx,
|
||||
ty::TypingEnv::fully_monomorphized(),
|
||||
def_id,
|
||||
args_ref,
|
||||
) {
|
||||
Ok(Some(instance)) => Some(instance.stable(&mut *tables)),
|
||||
Ok(None) | Err(_) => None,
|
||||
}
|
||||
|
@ -665,8 +682,13 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
|
|||
let tcx = tables.tcx;
|
||||
let def_id = def.0.internal(&mut *tables, tcx);
|
||||
let args_ref = args.internal(&mut *tables, tcx);
|
||||
Instance::resolve_for_fn_ptr(tables.tcx, ParamEnv::reveal_all(), def_id, args_ref)
|
||||
.stable(&mut *tables)
|
||||
Instance::resolve_for_fn_ptr(
|
||||
tables.tcx,
|
||||
ty::TypingEnv::fully_monomorphized(),
|
||||
def_id,
|
||||
args_ref,
|
||||
)
|
||||
.stable(&mut *tables)
|
||||
}
|
||||
|
||||
fn resolve_closure(
|
||||
|
@ -827,9 +849,9 @@ impl<'tcx> LayoutOfHelpers<'tcx> for Tables<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'tcx> HasParamEnv<'tcx> for Tables<'tcx> {
|
||||
fn param_env(&self) -> ty::ParamEnv<'tcx> {
|
||||
ty::ParamEnv::reveal_all()
|
||||
impl<'tcx> HasTypingEnv<'tcx> for Tables<'tcx> {
|
||||
fn typing_env(&self) -> ty::TypingEnv<'tcx> {
|
||||
ty::TypingEnv::fully_monomorphized()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue