remove remaining references to Reveal
This commit is contained in:
parent
319843d8cd
commit
a8c8ab1acd
34 changed files with 93 additions and 84 deletions
|
@ -80,7 +80,7 @@ pub(crate) fn get_function_sig<'tcx>(
|
||||||
clif_sig_from_fn_abi(
|
clif_sig_from_fn_abi(
|
||||||
tcx,
|
tcx,
|
||||||
default_call_conv,
|
default_call_conv,
|
||||||
&RevealAllLayoutCx(tcx).fn_abi_of_instance(inst, ty::List::empty()),
|
&FullyMonomorphizedLayoutCx(tcx).fn_abi_of_instance(inst, ty::List::empty()),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -438,9 +438,9 @@ pub(crate) fn codegen_terminator_call<'tcx>(
|
||||||
extra_args.iter().map(|op_arg| fx.monomorphize(op_arg.node.ty(fx.mir, fx.tcx))),
|
extra_args.iter().map(|op_arg| fx.monomorphize(op_arg.node.ty(fx.mir, fx.tcx))),
|
||||||
);
|
);
|
||||||
let fn_abi = if let Some(instance) = instance {
|
let fn_abi = if let Some(instance) = instance {
|
||||||
RevealAllLayoutCx(fx.tcx).fn_abi_of_instance(instance, extra_args)
|
FullyMonomorphizedLayoutCx(fx.tcx).fn_abi_of_instance(instance, extra_args)
|
||||||
} else {
|
} else {
|
||||||
RevealAllLayoutCx(fx.tcx).fn_abi_of_fn_ptr(fn_sig, extra_args)
|
FullyMonomorphizedLayoutCx(fx.tcx).fn_abi_of_fn_ptr(fn_sig, extra_args)
|
||||||
};
|
};
|
||||||
|
|
||||||
let is_cold = if fn_sig.abi() == ExternAbi::RustCold {
|
let is_cold = if fn_sig.abi() == ExternAbi::RustCold {
|
||||||
|
@ -721,8 +721,8 @@ pub(crate) fn codegen_drop<'tcx>(
|
||||||
def: ty::InstanceKind::Virtual(drop_instance.def_id(), 0),
|
def: ty::InstanceKind::Virtual(drop_instance.def_id(), 0),
|
||||||
args: drop_instance.args,
|
args: drop_instance.args,
|
||||||
};
|
};
|
||||||
let fn_abi =
|
let fn_abi = FullyMonomorphizedLayoutCx(fx.tcx)
|
||||||
RevealAllLayoutCx(fx.tcx).fn_abi_of_instance(virtual_drop, ty::List::empty());
|
.fn_abi_of_instance(virtual_drop, ty::List::empty());
|
||||||
|
|
||||||
let sig = clif_sig_from_fn_abi(fx.tcx, fx.target_config.default_call_conv, &fn_abi);
|
let sig = clif_sig_from_fn_abi(fx.tcx, fx.target_config.default_call_conv, &fn_abi);
|
||||||
let sig = fx.bcx.import_signature(sig);
|
let sig = fx.bcx.import_signature(sig);
|
||||||
|
@ -764,8 +764,8 @@ pub(crate) fn codegen_drop<'tcx>(
|
||||||
def: ty::InstanceKind::Virtual(drop_instance.def_id(), 0),
|
def: ty::InstanceKind::Virtual(drop_instance.def_id(), 0),
|
||||||
args: drop_instance.args,
|
args: drop_instance.args,
|
||||||
};
|
};
|
||||||
let fn_abi =
|
let fn_abi = FullyMonomorphizedLayoutCx(fx.tcx)
|
||||||
RevealAllLayoutCx(fx.tcx).fn_abi_of_instance(virtual_drop, ty::List::empty());
|
.fn_abi_of_instance(virtual_drop, ty::List::empty());
|
||||||
|
|
||||||
let sig = clif_sig_from_fn_abi(fx.tcx, fx.target_config.default_call_conv, &fn_abi);
|
let sig = clif_sig_from_fn_abi(fx.tcx, fx.target_config.default_call_conv, &fn_abi);
|
||||||
let sig = fx.bcx.import_signature(sig);
|
let sig = fx.bcx.import_signature(sig);
|
||||||
|
@ -774,8 +774,8 @@ pub(crate) fn codegen_drop<'tcx>(
|
||||||
_ => {
|
_ => {
|
||||||
assert!(!matches!(drop_instance.def, InstanceKind::Virtual(_, _)));
|
assert!(!matches!(drop_instance.def, InstanceKind::Virtual(_, _)));
|
||||||
|
|
||||||
let fn_abi =
|
let fn_abi = FullyMonomorphizedLayoutCx(fx.tcx)
|
||||||
RevealAllLayoutCx(fx.tcx).fn_abi_of_instance(drop_instance, ty::List::empty());
|
.fn_abi_of_instance(drop_instance, ty::List::empty());
|
||||||
|
|
||||||
let arg_value = drop_place.place_ref(
|
let arg_value = drop_place.place_ref(
|
||||||
fx,
|
fx,
|
||||||
|
|
|
@ -103,7 +103,7 @@ pub(crate) fn codegen_fn<'tcx>(
|
||||||
let block_map: IndexVec<BasicBlock, Block> =
|
let block_map: IndexVec<BasicBlock, Block> =
|
||||||
(0..mir.basic_blocks.len()).map(|_| bcx.create_block()).collect();
|
(0..mir.basic_blocks.len()).map(|_| bcx.create_block()).collect();
|
||||||
|
|
||||||
let fn_abi = RevealAllLayoutCx(tcx).fn_abi_of_instance(instance, ty::List::empty());
|
let fn_abi = FullyMonomorphizedLayoutCx(tcx).fn_abi_of_instance(instance, ty::List::empty());
|
||||||
|
|
||||||
// Make FunctionCx
|
// Make FunctionCx
|
||||||
let target_config = module.target_config();
|
let target_config = module.target_config();
|
||||||
|
|
|
@ -311,7 +311,7 @@ pub(crate) struct FunctionCx<'m, 'clif, 'tcx: 'm> {
|
||||||
impl<'tcx> LayoutOfHelpers<'tcx> for FunctionCx<'_, '_, 'tcx> {
|
impl<'tcx> LayoutOfHelpers<'tcx> for FunctionCx<'_, '_, 'tcx> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn handle_layout_err(&self, err: LayoutError<'tcx>, span: Span, ty: Ty<'tcx>) -> ! {
|
fn handle_layout_err(&self, err: LayoutError<'tcx>, span: Span, ty: Ty<'tcx>) -> ! {
|
||||||
RevealAllLayoutCx(self.tcx).handle_layout_err(err, span, ty)
|
FullyMonomorphizedLayoutCx(self.tcx).handle_layout_err(err, span, ty)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -323,7 +323,7 @@ impl<'tcx> FnAbiOfHelpers<'tcx> for FunctionCx<'_, '_, 'tcx> {
|
||||||
span: Span,
|
span: Span,
|
||||||
fn_abi_request: FnAbiRequest<'tcx>,
|
fn_abi_request: FnAbiRequest<'tcx>,
|
||||||
) -> ! {
|
) -> ! {
|
||||||
RevealAllLayoutCx(self.tcx).handle_fn_abi_err(err, span, fn_abi_request)
|
FullyMonomorphizedLayoutCx(self.tcx).handle_fn_abi_err(err, span, fn_abi_request)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -443,9 +443,9 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) struct RevealAllLayoutCx<'tcx>(pub(crate) TyCtxt<'tcx>);
|
pub(crate) struct FullyMonomorphizedLayoutCx<'tcx>(pub(crate) TyCtxt<'tcx>);
|
||||||
|
|
||||||
impl<'tcx> LayoutOfHelpers<'tcx> for RevealAllLayoutCx<'tcx> {
|
impl<'tcx> LayoutOfHelpers<'tcx> for FullyMonomorphizedLayoutCx<'tcx> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn handle_layout_err(&self, err: LayoutError<'tcx>, span: Span, ty: Ty<'tcx>) -> ! {
|
fn handle_layout_err(&self, err: LayoutError<'tcx>, span: Span, ty: Ty<'tcx>) -> ! {
|
||||||
if let LayoutError::SizeOverflow(_) | LayoutError::ReferencesError(_) = err {
|
if let LayoutError::SizeOverflow(_) | LayoutError::ReferencesError(_) = err {
|
||||||
|
@ -459,7 +459,7 @@ impl<'tcx> LayoutOfHelpers<'tcx> for RevealAllLayoutCx<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> FnAbiOfHelpers<'tcx> for RevealAllLayoutCx<'tcx> {
|
impl<'tcx> FnAbiOfHelpers<'tcx> for FullyMonomorphizedLayoutCx<'tcx> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn handle_fn_abi_err(
|
fn handle_fn_abi_err(
|
||||||
&self,
|
&self,
|
||||||
|
@ -485,25 +485,25 @@ impl<'tcx> FnAbiOfHelpers<'tcx> for RevealAllLayoutCx<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> layout::HasTyCtxt<'tcx> for RevealAllLayoutCx<'tcx> {
|
impl<'tcx> layout::HasTyCtxt<'tcx> for FullyMonomorphizedLayoutCx<'tcx> {
|
||||||
fn tcx<'b>(&'b self) -> TyCtxt<'tcx> {
|
fn tcx<'b>(&'b self) -> TyCtxt<'tcx> {
|
||||||
self.0
|
self.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> rustc_abi::HasDataLayout for RevealAllLayoutCx<'tcx> {
|
impl<'tcx> rustc_abi::HasDataLayout for FullyMonomorphizedLayoutCx<'tcx> {
|
||||||
fn data_layout(&self) -> &rustc_abi::TargetDataLayout {
|
fn data_layout(&self) -> &rustc_abi::TargetDataLayout {
|
||||||
&self.0.data_layout
|
&self.0.data_layout
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> layout::HasTypingEnv<'tcx> for RevealAllLayoutCx<'tcx> {
|
impl<'tcx> layout::HasTypingEnv<'tcx> for FullyMonomorphizedLayoutCx<'tcx> {
|
||||||
fn typing_env(&self) -> ty::TypingEnv<'tcx> {
|
fn typing_env(&self) -> ty::TypingEnv<'tcx> {
|
||||||
ty::TypingEnv::fully_monomorphized()
|
ty::TypingEnv::fully_monomorphized()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> HasTargetSpec for RevealAllLayoutCx<'tcx> {
|
impl<'tcx> HasTargetSpec for FullyMonomorphizedLayoutCx<'tcx> {
|
||||||
fn target_spec(&self) -> &Target {
|
fn target_spec(&self) -> &Target {
|
||||||
&self.0.sess.target
|
&self.0.sess.target
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_middle::ty::layout::LayoutOf;
|
use rustc_middle::ty::layout::LayoutOf;
|
||||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||||
|
|
||||||
use crate::{DebugContext, RevealAllLayoutCx, has_ptr_meta};
|
use crate::{DebugContext, FullyMonomorphizedLayoutCx, has_ptr_meta};
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub(crate) struct TypeDebugContext<'tcx> {
|
pub(crate) struct TypeDebugContext<'tcx> {
|
||||||
|
@ -85,7 +85,7 @@ impl DebugContext {
|
||||||
type_entry.set(gimli::DW_AT_encoding, AttributeValue::Encoding(encoding));
|
type_entry.set(gimli::DW_AT_encoding, AttributeValue::Encoding(encoding));
|
||||||
type_entry.set(
|
type_entry.set(
|
||||||
gimli::DW_AT_byte_size,
|
gimli::DW_AT_byte_size,
|
||||||
AttributeValue::Udata(RevealAllLayoutCx(tcx).layout_of(ty).size.bytes()),
|
AttributeValue::Udata(FullyMonomorphizedLayoutCx(tcx).layout_of(ty).size.bytes()),
|
||||||
);
|
);
|
||||||
|
|
||||||
type_id
|
type_id
|
||||||
|
@ -159,7 +159,7 @@ impl DebugContext {
|
||||||
return_if_type_created_in_meantime!(type_dbg, tuple_type);
|
return_if_type_created_in_meantime!(type_dbg, tuple_type);
|
||||||
|
|
||||||
let name = type_names::compute_debuginfo_type_name(tcx, tuple_type, false);
|
let name = type_names::compute_debuginfo_type_name(tcx, tuple_type, false);
|
||||||
let layout = RevealAllLayoutCx(tcx).layout_of(tuple_type);
|
let layout = FullyMonomorphizedLayoutCx(tcx).layout_of(tuple_type);
|
||||||
|
|
||||||
let tuple_type_id =
|
let tuple_type_id =
|
||||||
self.dwarf.unit.add(self.dwarf.unit.root(), gimli::DW_TAG_structure_type);
|
self.dwarf.unit.add(self.dwarf.unit.root(), gimli::DW_TAG_structure_type);
|
||||||
|
@ -178,7 +178,9 @@ impl DebugContext {
|
||||||
member_entry.set(gimli::DW_AT_type, AttributeValue::UnitRef(dw_ty));
|
member_entry.set(gimli::DW_AT_type, AttributeValue::UnitRef(dw_ty));
|
||||||
member_entry.set(
|
member_entry.set(
|
||||||
gimli::DW_AT_alignment,
|
gimli::DW_AT_alignment,
|
||||||
AttributeValue::Udata(RevealAllLayoutCx(tcx).layout_of(ty).align.pref.bytes()),
|
AttributeValue::Udata(
|
||||||
|
FullyMonomorphizedLayoutCx(tcx).layout_of(ty).align.pref.bytes(),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
member_entry.set(
|
member_entry.set(
|
||||||
gimli::DW_AT_data_member_location,
|
gimli::DW_AT_data_member_location,
|
||||||
|
@ -198,7 +200,11 @@ impl DebugContext {
|
||||||
self.debug_type(
|
self.debug_type(
|
||||||
tcx,
|
tcx,
|
||||||
type_dbg,
|
type_dbg,
|
||||||
Ty::new_array(tcx, tcx.types.u8, RevealAllLayoutCx(tcx).layout_of(ty).size.bytes()),
|
Ty::new_array(
|
||||||
|
tcx,
|
||||||
|
tcx.types.u8,
|
||||||
|
FullyMonomorphizedLayoutCx(tcx).layout_of(ty).size.bytes(),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ pub(crate) fn codegen_global_asm_item(tcx: TyCtxt<'_>, global_asm: &mut String,
|
||||||
tcx,
|
tcx,
|
||||||
op_sp,
|
op_sp,
|
||||||
const_value,
|
const_value,
|
||||||
RevealAllLayoutCx(tcx).layout_of(ty),
|
FullyMonomorphizedLayoutCx(tcx).layout_of(ty),
|
||||||
);
|
);
|
||||||
global_asm.push_str(&string);
|
global_asm.push_str(&string);
|
||||||
}
|
}
|
||||||
|
|
|
@ -238,7 +238,7 @@ pub(crate) fn codegen_naked_asm<'tcx>(
|
||||||
tcx,
|
tcx,
|
||||||
span,
|
span,
|
||||||
const_value,
|
const_value,
|
||||||
RevealAllLayoutCx(tcx).layout_of(cv.ty()),
|
FullyMonomorphizedLayoutCx(tcx).layout_of(cv.ty()),
|
||||||
);
|
);
|
||||||
CInlineAsmOperand::Const { value }
|
CInlineAsmOperand::Const { value }
|
||||||
}
|
}
|
||||||
|
|
|
@ -629,8 +629,7 @@ impl<'tcx> Body<'tcx> {
|
||||||
) -> Option<(u128, &'a SwitchTargets)> {
|
) -> Option<(u128, &'a SwitchTargets)> {
|
||||||
// There are two places here we need to evaluate a constant.
|
// There are two places here we need to evaluate a constant.
|
||||||
let eval_mono_const = |constant: &ConstOperand<'tcx>| {
|
let eval_mono_const = |constant: &ConstOperand<'tcx>| {
|
||||||
// FIXME(#132279): what is this, why are we using an empty environment with
|
// FIXME(#132279): what is this, why are we using an empty environment here.
|
||||||
// `RevealAll` here.
|
|
||||||
let typing_env = ty::TypingEnv::fully_monomorphized();
|
let typing_env = ty::TypingEnv::fully_monomorphized();
|
||||||
let mono_literal = instance.instantiate_mir_and_normalize_erasing_regions(
|
let mono_literal = instance.instantiate_mir_and_normalize_erasing_regions(
|
||||||
tcx,
|
tcx,
|
||||||
|
|
|
@ -1373,9 +1373,10 @@ rustc_queries! {
|
||||||
/// Gets the ParameterEnvironment for a given item; this environment
|
/// Gets the ParameterEnvironment for a given item; this environment
|
||||||
/// will be in "user-facing" mode, meaning that it is suitable for
|
/// will be in "user-facing" mode, meaning that it is suitable for
|
||||||
/// type-checking etc, and it does not normalize specializable
|
/// type-checking etc, and it does not normalize specializable
|
||||||
/// associated types. This is almost always what you want,
|
/// associated types.
|
||||||
/// unless you are doing MIR optimizations, in which case you
|
///
|
||||||
/// might want to use `reveal_all()` method to change modes.
|
/// You should pretty much only use this if an `infcx` is available,
|
||||||
|
/// otherwise use a `TypingEnv`.
|
||||||
query param_env(def_id: DefId) -> ty::ParamEnv<'tcx> {
|
query param_env(def_id: DefId) -> ty::ParamEnv<'tcx> {
|
||||||
desc { |tcx| "computing normalized predicates of `{}`", tcx.def_path_str(def_id) }
|
desc { |tcx| "computing normalized predicates of `{}`", tcx.def_path_str(def_id) }
|
||||||
feedable
|
feedable
|
||||||
|
@ -1471,7 +1472,7 @@ rustc_queries! {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Computes the layout of a type. Note that this implicitly
|
/// Computes the layout of a type. Note that this implicitly
|
||||||
/// executes in "reveal all" mode, and will normalize the input type.
|
/// executes in `TypingMode::PostAnalysis`, and will normalize the input type.
|
||||||
query layout_of(
|
query layout_of(
|
||||||
key: ty::PseudoCanonicalInput<'tcx, Ty<'tcx>>
|
key: ty::PseudoCanonicalInput<'tcx, Ty<'tcx>>
|
||||||
) -> Result<ty::layout::TyAndLayout<'tcx>, &'tcx ty::layout::LayoutError<'tcx>> {
|
) -> Result<ty::layout::TyAndLayout<'tcx>, &'tcx ty::layout::LayoutError<'tcx>> {
|
||||||
|
|
|
@ -504,8 +504,8 @@ impl<'tcx> Instance<'tcx> {
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// trying to resolve `Debug::fmt` applied to `T` will yield `Ok(None)`, because we do not
|
/// trying to resolve `Debug::fmt` applied to `T` will yield `Ok(None)`, because we do not
|
||||||
/// know what code ought to run. (Note that this setting is also affected by the
|
/// know what code ought to run. This setting is also affected by the current `TypingMode`
|
||||||
/// `RevealMode` in the parameter environment.)
|
/// of the environment.
|
||||||
///
|
///
|
||||||
/// Presuming that coherence and type-check have succeeded, if this method is invoked
|
/// Presuming that coherence and type-check have succeeded, if this method is invoked
|
||||||
/// in a monomorphic context (i.e., like during codegen), then it is guaranteed to return
|
/// in a monomorphic context (i.e., like during codegen), then it is guaranteed to return
|
||||||
|
|
|
@ -682,14 +682,14 @@ pub trait LayoutOfHelpers<'tcx>: HasDataLayout + HasTyCtxt<'tcx> + HasTypingEnv<
|
||||||
/// Blanket extension trait for contexts that can compute layouts of types.
|
/// Blanket extension trait for contexts that can compute layouts of types.
|
||||||
pub trait LayoutOf<'tcx>: LayoutOfHelpers<'tcx> {
|
pub trait LayoutOf<'tcx>: LayoutOfHelpers<'tcx> {
|
||||||
/// Computes the layout of a type. Note that this implicitly
|
/// Computes the layout of a type. Note that this implicitly
|
||||||
/// executes in "reveal all" mode, and will normalize the input type.
|
/// executes in `TypingMode::PostAnalysis`, and will normalize the input type.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn layout_of(&self, ty: Ty<'tcx>) -> Self::LayoutOfResult {
|
fn layout_of(&self, ty: Ty<'tcx>) -> Self::LayoutOfResult {
|
||||||
self.spanned_layout_of(ty, DUMMY_SP)
|
self.spanned_layout_of(ty, DUMMY_SP)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Computes the layout of a type, at `span`. Note that this implicitly
|
/// Computes the layout of a type, at `span`. Note that this implicitly
|
||||||
/// executes in "reveal all" mode, and will normalize the input type.
|
/// executes in `TypingMode::PostAnalysis`, and will normalize the input type.
|
||||||
// FIXME(eddyb) avoid passing information like this, and instead add more
|
// FIXME(eddyb) avoid passing information like this, and instead add more
|
||||||
// `TyCtxt::at`-like APIs to be able to do e.g. `cx.at(span).layout_of(ty)`.
|
// `TyCtxt::at`-like APIs to be able to do e.g. `cx.at(span).layout_of(ty)`.
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
@ -423,8 +423,8 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
pub fn async_drop_glue_morphology(self, did: DefId) -> AsyncDropGlueMorphology {
|
pub fn async_drop_glue_morphology(self, did: DefId) -> AsyncDropGlueMorphology {
|
||||||
let ty: Ty<'tcx> = self.type_of(did).instantiate_identity();
|
let ty: Ty<'tcx> = self.type_of(did).instantiate_identity();
|
||||||
|
|
||||||
// Async drop glue morphology is an internal detail, so reveal_all probably
|
// Async drop glue morphology is an internal detail, so
|
||||||
// should be fine
|
// using `TypingMode::PostAnalysis` probably should be fine.
|
||||||
let typing_env = ty::TypingEnv::fully_monomorphized();
|
let typing_env = ty::TypingEnv::fully_monomorphized();
|
||||||
if ty.needs_async_drop(self, typing_env) {
|
if ty.needs_async_drop(self, typing_env) {
|
||||||
AsyncDropGlueMorphology::Custom
|
AsyncDropGlueMorphology::Custom
|
||||||
|
|
|
@ -80,11 +80,11 @@ impl<'tcx> ConstToPat<'tcx> {
|
||||||
let pat_from_kind = |kind| Box::new(Pat { span: self.span, ty, kind });
|
let pat_from_kind = |kind| Box::new(Pat { span: self.span, ty, kind });
|
||||||
|
|
||||||
// It's not *technically* correct to be revealing opaque types here as borrowcheck has
|
// It's not *technically* correct to be revealing opaque types here as borrowcheck has
|
||||||
// not run yet. However, CTFE itself uses `Reveal::All` unconditionally even during
|
// not run yet. However, CTFE itself uses `TypingMode::PostAnalysis` unconditionally even
|
||||||
// typeck and not doing so has a lot of (undesirable) fallout (#101478, #119821). As a
|
// during typeck and not doing so has a lot of (undesirable) fallout (#101478, #119821).
|
||||||
// result we always use a revealed env when resolving the instance to evaluate.
|
// As a result we always use a revealed env when resolving the instance to evaluate.
|
||||||
//
|
//
|
||||||
// FIXME: `const_eval_resolve_for_typeck` should probably just set the env to `Reveal::All`
|
// FIXME: `const_eval_resolve_for_typeck` should probably just modify the env itself
|
||||||
// instead of having this logic here
|
// instead of having this logic here
|
||||||
let typing_env =
|
let typing_env =
|
||||||
self.tcx.erase_regions(self.typing_env).with_post_analysis_normalized(self.tcx);
|
self.tcx.erase_regions(self.typing_env).with_post_analysis_normalized(self.tcx);
|
||||||
|
|
|
@ -258,7 +258,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
|
||||||
// Normalization needed b/c known panics lint runs in
|
// Normalization needed b/c known panics lint runs in
|
||||||
// `mir_drops_elaborated_and_const_checked`, which happens before
|
// `mir_drops_elaborated_and_const_checked`, which happens before
|
||||||
// optimized MIR. Only after optimizing the MIR can we guarantee
|
// optimized MIR. Only after optimizing the MIR can we guarantee
|
||||||
// that the `RevealAll` pass has happened and that the body's consts
|
// that the `PostAnalysisNormalize` pass has happened and that the body's consts
|
||||||
// are normalized, so any call to resolve before that needs to be
|
// are normalized, so any call to resolve before that needs to be
|
||||||
// manually normalized.
|
// manually normalized.
|
||||||
let val = self.tcx.try_normalize_erasing_regions(self.typing_env, c.const_).ok()?;
|
let val = self.tcx.try_normalize_erasing_regions(self.typing_env, c.const_).ok()?;
|
||||||
|
|
|
@ -163,7 +163,7 @@ declare_passes! {
|
||||||
mod remove_unneeded_drops : RemoveUnneededDrops;
|
mod remove_unneeded_drops : RemoveUnneededDrops;
|
||||||
mod remove_zsts : RemoveZsts;
|
mod remove_zsts : RemoveZsts;
|
||||||
mod required_consts : RequiredConstsVisitor;
|
mod required_consts : RequiredConstsVisitor;
|
||||||
mod reveal_all : RevealAll;
|
mod post_analysis_normalize : PostAnalysisNormalize;
|
||||||
mod sanity_check : SanityCheck;
|
mod sanity_check : SanityCheck;
|
||||||
// This pass is public to allow external drivers to perform MIR cleanup
|
// This pass is public to allow external drivers to perform MIR cleanup
|
||||||
pub mod simplify :
|
pub mod simplify :
|
||||||
|
@ -604,8 +604,8 @@ fn run_runtime_lowering_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
||||||
// These next passes must be executed together.
|
// These next passes must be executed together.
|
||||||
&add_call_guards::CriticalCallEdges,
|
&add_call_guards::CriticalCallEdges,
|
||||||
// Must be done before drop elaboration because we need to drop opaque types, too.
|
// Must be done before drop elaboration because we need to drop opaque types, too.
|
||||||
&reveal_all::RevealAll,
|
&post_analysis_normalize::PostAnalysisNormalize,
|
||||||
// Calling this after reveal_all ensures that we don't deal with opaque types.
|
// Calling this after `PostAnalysisNormalize` ensures that we don't deal with opaque types.
|
||||||
&add_subtyping_projections::Subtyper,
|
&add_subtyping_projections::Subtyper,
|
||||||
&elaborate_drops::ElaborateDrops,
|
&elaborate_drops::ElaborateDrops,
|
||||||
// This will remove extraneous landing pads which are no longer
|
// This will remove extraneous landing pads which are no longer
|
||||||
|
|
|
@ -1,26 +1,27 @@
|
||||||
//! Normalizes MIR in RevealAll mode.
|
//! Normalizes MIR in TypingMode::PostAnalysis mode, most notably revealing
|
||||||
|
//! its opaques.
|
||||||
|
|
||||||
use rustc_middle::mir::visit::*;
|
use rustc_middle::mir::visit::*;
|
||||||
use rustc_middle::mir::*;
|
use rustc_middle::mir::*;
|
||||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||||
|
|
||||||
pub(super) struct RevealAll;
|
pub(super) struct PostAnalysisNormalize;
|
||||||
|
|
||||||
impl<'tcx> crate::MirPass<'tcx> for RevealAll {
|
impl<'tcx> crate::MirPass<'tcx> for PostAnalysisNormalize {
|
||||||
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
||||||
// FIXME(#132279): This is used during the phase transition from analysis
|
// FIXME(#132279): This is used during the phase transition from analysis
|
||||||
// to runtime, so we have to manually specify the correct typing mode.
|
// to runtime, so we have to manually specify the correct typing mode.
|
||||||
let typing_env = ty::TypingEnv::post_analysis(tcx, body.source.def_id());
|
let typing_env = ty::TypingEnv::post_analysis(tcx, body.source.def_id());
|
||||||
RevealAllVisitor { tcx, typing_env }.visit_body_preserves_cfg(body);
|
PostAnalysisNormalizeVisitor { tcx, typing_env }.visit_body_preserves_cfg(body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct RevealAllVisitor<'tcx> {
|
struct PostAnalysisNormalizeVisitor<'tcx> {
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
typing_env: ty::TypingEnv<'tcx>,
|
typing_env: ty::TypingEnv<'tcx>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> MutVisitor<'tcx> for RevealAllVisitor<'tcx> {
|
impl<'tcx> MutVisitor<'tcx> for PostAnalysisNormalizeVisitor<'tcx> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn tcx(&self) -> TyCtxt<'tcx> {
|
fn tcx(&self) -> TyCtxt<'tcx> {
|
||||||
self.tcx
|
self.tcx
|
||||||
|
@ -38,7 +39,7 @@ impl<'tcx> MutVisitor<'tcx> for RevealAllVisitor<'tcx> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// `OpaqueCast` projections are only needed if there are opaque types on which projections
|
// `OpaqueCast` projections are only needed if there are opaque types on which projections
|
||||||
// are performed. After the `RevealAll` pass, all opaque types are replaced with their
|
// are performed. After the `PostAnalysisNormalize` pass, all opaque types are replaced with their
|
||||||
// hidden types, so we don't need these projections anymore.
|
// hidden types, so we don't need these projections anymore.
|
||||||
place.projection = self.tcx.mk_place_elems(
|
place.projection = self.tcx.mk_place_elems(
|
||||||
&place
|
&place
|
|
@ -2,7 +2,8 @@
|
||||||
//!
|
//!
|
||||||
//! When the MIR is built, we check `needs_drop` before emitting a `Drop` for a place. This pass is
|
//! When the MIR is built, we check `needs_drop` before emitting a `Drop` for a place. This pass is
|
||||||
//! useful because (unlike MIR building) it runs after type checking, so it can make use of
|
//! useful because (unlike MIR building) it runs after type checking, so it can make use of
|
||||||
//! `Reveal::All` to provide more precise type information.
|
//! `TypingMode::PostAnalysis` to provide more precise type information, especially about opaque
|
||||||
|
//! types.
|
||||||
|
|
||||||
use rustc_middle::mir::*;
|
use rustc_middle::mir::*;
|
||||||
use rustc_middle::ty::TyCtxt;
|
use rustc_middle::ty::TyCtxt;
|
||||||
|
|
|
@ -141,7 +141,7 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceKind<'tcx>) -> Body<
|
||||||
debug!("make_shim({:?}) = untransformed {:?}", instance, result);
|
debug!("make_shim({:?}) = untransformed {:?}", instance, result);
|
||||||
|
|
||||||
// We don't validate MIR here because the shims may generate code that's
|
// We don't validate MIR here because the shims may generate code that's
|
||||||
// only valid in a reveal-all param-env. However, since we do initial
|
// only valid in a `PostAnalysis` param-env. However, since we do initial
|
||||||
// validation with the MirBuilt phase, which uses a user-facing param-env.
|
// validation with the MirBuilt phase, which uses a user-facing param-env.
|
||||||
// This causes validation errors when TAITs are involved.
|
// This causes validation errors when TAITs are involved.
|
||||||
pm::run_passes_no_validate(
|
pm::run_passes_no_validate(
|
||||||
|
|
|
@ -646,7 +646,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
|
||||||
{
|
{
|
||||||
self.fail(
|
self.fail(
|
||||||
location,
|
location,
|
||||||
format!("explicit opaque type cast to `{ty}` after `RevealAll`"),
|
format!("explicit opaque type cast to `{ty}` after `PostAnalysisNormalize`"),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
ProjectionElem::Index(index) => {
|
ProjectionElem::Index(index) => {
|
||||||
|
|
|
@ -1556,7 +1556,7 @@ fn create_mono_items_for_default_impls<'tcx>(
|
||||||
// Unlike 'lazy' monomorphization that begins by collecting items transitively
|
// Unlike 'lazy' monomorphization that begins by collecting items transitively
|
||||||
// called by `main` or other global items, when eagerly monomorphizing impl
|
// called by `main` or other global items, when eagerly monomorphizing impl
|
||||||
// items, we never actually check that the predicates of this impl are satisfied
|
// items, we never actually check that the predicates of this impl are satisfied
|
||||||
// in a empty reveal-all param env (i.e. with no assumptions).
|
// in a empty param env (i.e. with no assumptions).
|
||||||
//
|
//
|
||||||
// Even though this impl has no type or const generic parameters, because we don't
|
// Even though this impl has no type or const generic parameters, because we don't
|
||||||
// consider higher-ranked predicates such as `for<'a> &'a mut [u8]: Copy` to
|
// consider higher-ranked predicates such as `for<'a> &'a mut [u8]: Copy` to
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
//! Computes a normalizes-to (projection) goal for opaque types. This goal
|
//! Computes a normalizes-to (projection) goal for opaque types. This goal
|
||||||
//! behaves differently depending on the param-env's reveal mode and whether
|
//! behaves differently depending on the current `TypingMode`.
|
||||||
//! the opaque is in a defining scope.
|
|
||||||
|
|
||||||
use rustc_index::bit_set::GrowableBitSet;
|
use rustc_index::bit_set::GrowableBitSet;
|
||||||
use rustc_type_ir::inherent::*;
|
use rustc_type_ir::inherent::*;
|
||||||
|
|
|
@ -603,12 +603,12 @@ pub fn try_evaluate_const<'tcx>(
|
||||||
};
|
};
|
||||||
let uv = ty::UnevaluatedConst::new(uv.def, args);
|
let uv = ty::UnevaluatedConst::new(uv.def, args);
|
||||||
|
|
||||||
// It's not *technically* correct to be revealing opaque types here as we could still be
|
// It's not *technically* correct to be revealing opaque types here as borrowcheck has
|
||||||
// before borrowchecking. However, CTFE itself uses `Reveal::All` unconditionally even during
|
// not run yet. However, CTFE itself uses `TypingMode::PostAnalysis` unconditionally even
|
||||||
// typeck and not doing so has a lot of (undesirable) fallout (#101478, #119821). As a result we
|
// during typeck and not doing so has a lot of (undesirable) fallout (#101478, #119821).
|
||||||
// always use a revealed env when resolving the instance to evaluate.
|
// As a result we always use a revealed env when resolving the instance to evaluate.
|
||||||
//
|
//
|
||||||
// FIXME: `const_eval_resolve_for_typeck` should probably just set the env to `Reveal::All`
|
// FIXME: `const_eval_resolve_for_typeck` should probably just modify the env itself
|
||||||
// instead of having this logic here
|
// instead of having this logic here
|
||||||
let typing_env =
|
let typing_env =
|
||||||
tcx.erase_regions(infcx.typing_env(param_env)).with_post_analysis_normalized(tcx);
|
tcx.erase_regions(infcx.typing_env(param_env)).with_post_analysis_normalized(tcx);
|
||||||
|
|
|
@ -115,7 +115,7 @@ pub(super) fn needs_normalization<'tcx, T: TypeVisitable<TyCtxt<'tcx>>>(
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let mut flags = ty::TypeFlags::HAS_ALIAS;
|
let mut flags = ty::TypeFlags::HAS_ALIAS;
|
||||||
|
|
||||||
// Opaques are treated as rigid with `Reveal::UserFacing`,
|
// Opaques are treated as rigid outside of `TypingMode::PostAnalysis`,
|
||||||
// so we can ignore those.
|
// so we can ignore those.
|
||||||
match infcx.typing_mode() {
|
match infcx.typing_mode() {
|
||||||
TypingMode::Coherence | TypingMode::Analysis { defining_opaque_types: _ } => {
|
TypingMode::Coherence | TypingMode::Analysis { defining_opaque_types: _ } => {
|
||||||
|
|
|
@ -133,8 +133,10 @@ fn resolve_associated_item<'tcx>(
|
||||||
bug!("{:?} not found in {:?}", trait_item_id, impl_data.impl_def_id);
|
bug!("{:?} not found in {:?}", trait_item_id, impl_data.impl_def_id);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Since this is a trait item, we need to see if the item is either a trait default item
|
// Since this is a trait item, we need to see if the item is either a trait
|
||||||
// or a specialization because we can't resolve those unless we can `Reveal::All`.
|
// default item or a specialization because we can't resolve those until we're
|
||||||
|
// in `TypingMode::PostAnalysis`.
|
||||||
|
//
|
||||||
// NOTE: This should be kept in sync with the similar code in
|
// NOTE: This should be kept in sync with the similar code in
|
||||||
// `rustc_trait_selection::traits::project::assemble_candidates_from_impls()`.
|
// `rustc_trait_selection::traits::project::assemble_candidates_from_impls()`.
|
||||||
let eligible = if leaf_def.is_final() {
|
let eligible = if leaf_def.is_final() {
|
||||||
|
|
|
@ -46,9 +46,9 @@ fn layout_of<'tcx>(
|
||||||
let PseudoCanonicalInput { typing_env, value: ty } = query;
|
let PseudoCanonicalInput { typing_env, value: ty } = query;
|
||||||
debug!(?ty);
|
debug!(?ty);
|
||||||
|
|
||||||
// Optimization: We convert to RevealAll and convert opaque types in the where bounds
|
// Optimization: We convert to TypingMode::PostAnalysis and convert opaque types in
|
||||||
// to their hidden types. This reduces overall uncached invocations of `layout_of` and
|
// the where bounds to their hidden types. This reduces overall uncached invocations
|
||||||
// is thus a small performance improvement.
|
// of `layout_of` and is thus a small performance improvement.
|
||||||
let typing_env = typing_env.with_post_analysis_normalized(tcx);
|
let typing_env = typing_env.with_post_analysis_normalized(tcx);
|
||||||
let unnormalized_ty = ty;
|
let unnormalized_ty = ty;
|
||||||
|
|
||||||
|
|
|
@ -444,7 +444,7 @@ pub enum AliasTermKind {
|
||||||
/// An associated type in an inherent `impl`
|
/// An associated type in an inherent `impl`
|
||||||
InherentTy,
|
InherentTy,
|
||||||
/// An opaque type (usually from `impl Trait` in type aliases or function return types)
|
/// An opaque type (usually from `impl Trait` in type aliases or function return types)
|
||||||
/// Can only be normalized away in RevealAll mode
|
/// Can only be normalized away in PostAnalysis mode or its defining scope.
|
||||||
OpaqueTy,
|
OpaqueTy,
|
||||||
/// A type alias that actually checks its trait bounds.
|
/// A type alias that actually checks its trait bounds.
|
||||||
/// Currently only used if the type alias references opaque types.
|
/// Currently only used if the type alias references opaque types.
|
||||||
|
|
|
@ -41,7 +41,7 @@ pub enum AliasTyKind {
|
||||||
/// An associated type in an inherent `impl`
|
/// An associated type in an inherent `impl`
|
||||||
Inherent,
|
Inherent,
|
||||||
/// An opaque type (usually from `impl Trait` in type aliases or function return types)
|
/// An opaque type (usually from `impl Trait` in type aliases or function return types)
|
||||||
/// Can only be normalized away in RevealAll mode
|
/// Can only be normalized away in PostAnalysis mode or its defining scope.
|
||||||
Opaque,
|
Opaque,
|
||||||
/// A type alias that actually checks its trait bounds.
|
/// A type alias that actually checks its trait bounds.
|
||||||
/// Currently only used if the type alias references opaque types.
|
/// Currently only used if the type alias references opaque types.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
- // MIR for `bar` before RevealAll
|
- // MIR for `bar` before PostAnalysisNormalize
|
||||||
+ // MIR for `bar` after RevealAll
|
+ // MIR for `bar` after PostAnalysisNormalize
|
||||||
|
|
||||||
fn bar(_1: P) -> () {
|
fn bar(_1: P) -> () {
|
||||||
debug _baz => _1;
|
debug _baz => _1;
|
|
@ -1,5 +1,5 @@
|
||||||
- // MIR for `bar` before RevealAll
|
- // MIR for `bar` before PostAnalysisNormalize
|
||||||
+ // MIR for `bar` after RevealAll
|
+ // MIR for `bar` after PostAnalysisNormalize
|
||||||
|
|
||||||
fn bar(_1: P) -> () {
|
fn bar(_1: P) -> () {
|
||||||
debug _baz => _1;
|
debug _baz => _1;
|
|
@ -2,7 +2,7 @@
|
||||||
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
|
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
|
||||||
#![crate_type = "lib"]
|
#![crate_type = "lib"]
|
||||||
|
|
||||||
// EMIT_MIR issue_78442.bar.RevealAll.diff
|
// EMIT_MIR issue_78442.bar.PostAnalysisNormalize.diff
|
||||||
// EMIT_MIR issue_78442.bar.Inline.diff
|
// EMIT_MIR issue_78442.bar.Inline.diff
|
||||||
pub fn bar<P>(
|
pub fn bar<P>(
|
||||||
// Error won't happen if "bar" is not generic
|
// Error won't happen if "bar" is not generic
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// This causes a query cycle due to using `Reveal::All`,
|
// This causes a query cycle due to using `TypingEnv::PostAnalysis`,
|
||||||
// in #119821 const eval was changed to always use `Reveal::All`
|
// in #119821 const eval was changed to always use this mode.
|
||||||
//
|
//
|
||||||
// See that PR for more details.
|
// See that PR for more details.
|
||||||
use std::mem::transmute;
|
use std::mem::transmute;
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
// Regression test for #105009. the issue here was that even after the `RevealAll` pass,
|
// Regression test for #105009. the issue here was that even after the `PostAnalysisNormalize` pass,
|
||||||
// `validate` still used `Reveal::UserFacing`. This meant that it now ends up comparing
|
// `validate` still used `Reveal::UserFacing`. This meant that it now ends up comparing
|
||||||
// opaque types with their revealed version, resulting in an ICE.
|
// opaque types with their revealed version, resulting in an ICE.
|
||||||
//
|
//
|
||||||
// We're using these flags to run the `RevealAll` pass while making it less likely to
|
// We're using these flags to run the `PostAnalysisNormalize` pass while making it less likely to
|
||||||
// accidentally removing the assignment from `Foo<fn_ptr>` to `Foo<fn_def>`.
|
// accidentally removing the assignment from `Foo<fn_ptr>` to `Foo<fn_def>`.
|
||||||
|
|
||||||
//@ compile-flags: -Zinline_mir=yes -Zmir-opt-level=0 -Zvalidate-mir
|
//@ compile-flags: -Zinline_mir=yes -Zmir-opt-level=0 -Zvalidate-mir
|
||||||
|
|
|
@ -39,6 +39,6 @@ fn main() {
|
||||||
// So why is the second generic of `test` "`()`", and not the
|
// So why is the second generic of `test` "`()`", and not the
|
||||||
// `impl Sized` since we inferred it from the return type of `rpit_fn`
|
// `impl Sized` since we inferred it from the return type of `rpit_fn`
|
||||||
// during typeck? Well, that's because we're using the generics from the
|
// during typeck? Well, that's because we're using the generics from the
|
||||||
// terminator of the MIR, which has had the RevealAll pass performed on it.
|
// terminator of the MIR, which has had the PostAnalysisNormalize pass performed on it.
|
||||||
let _ = test(rpit_fn);
|
let _ = test(rpit_fn);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
//! We evaluate `1 + 2` with `Reveal::All` during typeck, causing
|
//! We evaluate `1 + 2` with `TypingMode::PostAnalysis` during typeck, causing
|
||||||
//! us to get the concrete type of `Bar` while computing it.
|
//! us to get the concrete type of `Bar` while computing it.
|
||||||
//! This again requires type checking `foo`.
|
//! This again requires type checking `foo`.
|
||||||
#![feature(type_alias_impl_trait)]
|
#![feature(type_alias_impl_trait)]
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//@ compile-flags: -Zvalidate-mir
|
//@ compile-flags: -Zvalidate-mir
|
||||||
//@ check-pass
|
//@ check-pass
|
||||||
|
|
||||||
// Check that we don't cause cycle errors when validating pre-`Reveal::All` MIR
|
// Check that we don't cause cycle errors when validating pre-`RevealOpaques` MIR
|
||||||
// that assigns opaques through normalized projections.
|
// that assigns opaques through normalized projections.
|
||||||
|
|
||||||
#![feature(impl_trait_in_assoc_type)]
|
#![feature(impl_trait_in_assoc_type)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue