Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

finish Reveal removal #133242

Merged
merged 7 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions compiler/rustc_codegen_cranelift/src/abi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub(crate) fn get_function_sig<'tcx>(
clif_sig_from_fn_abi(
tcx,
default_call_conv,
&RevealAllLayoutCx(tcx).fn_abi_of_instance(inst, ty::List::empty()),
&FullyMonomorphizedLayoutCx(tcx).fn_abi_of_instance(inst, ty::List::empty()),
)
}

Expand Down Expand Up @@ -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))),
);
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 {
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 {
Expand Down Expand Up @@ -721,8 +721,8 @@ pub(crate) fn codegen_drop<'tcx>(
def: ty::InstanceKind::Virtual(drop_instance.def_id(), 0),
args: drop_instance.args,
};
let fn_abi =
RevealAllLayoutCx(fx.tcx).fn_abi_of_instance(virtual_drop, ty::List::empty());
let fn_abi = FullyMonomorphizedLayoutCx(fx.tcx)
.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 = fx.bcx.import_signature(sig);
Expand Down Expand Up @@ -764,8 +764,8 @@ pub(crate) fn codegen_drop<'tcx>(
def: ty::InstanceKind::Virtual(drop_instance.def_id(), 0),
args: drop_instance.args,
};
let fn_abi =
RevealAllLayoutCx(fx.tcx).fn_abi_of_instance(virtual_drop, ty::List::empty());
let fn_abi = FullyMonomorphizedLayoutCx(fx.tcx)
.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 = fx.bcx.import_signature(sig);
Expand All @@ -774,8 +774,8 @@ pub(crate) fn codegen_drop<'tcx>(
_ => {
assert!(!matches!(drop_instance.def, InstanceKind::Virtual(_, _)));

let fn_abi =
RevealAllLayoutCx(fx.tcx).fn_abi_of_instance(drop_instance, ty::List::empty());
let fn_abi = FullyMonomorphizedLayoutCx(fx.tcx)
.fn_abi_of_instance(drop_instance, ty::List::empty());

let arg_value = drop_place.place_ref(
fx,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ pub(crate) fn codegen_fn<'tcx>(
let block_map: IndexVec<BasicBlock, Block> =
(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
let target_config = module.target_config();
Expand Down
18 changes: 9 additions & 9 deletions compiler/rustc_codegen_cranelift/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ pub(crate) struct FunctionCx<'m, 'clif, 'tcx: 'm> {
impl<'tcx> LayoutOfHelpers<'tcx> for FunctionCx<'_, '_, 'tcx> {
#[inline]
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)
}
}

Expand All @@ -323,7 +323,7 @@ impl<'tcx> FnAbiOfHelpers<'tcx> for FunctionCx<'_, '_, 'tcx> {
span: Span,
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)
}
}

Expand Down Expand Up @@ -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]
fn handle_layout_err(&self, err: LayoutError<'tcx>, span: Span, ty: Ty<'tcx>) -> ! {
if let LayoutError::SizeOverflow(_) | LayoutError::ReferencesError(_) = err {
Expand All @@ -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]
fn handle_fn_abi_err(
&self,
Expand All @@ -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> {
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 {
&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> {
ty::TypingEnv::fully_monomorphized()
}
}

impl<'tcx> HasTargetSpec for RevealAllLayoutCx<'tcx> {
impl<'tcx> HasTargetSpec for FullyMonomorphizedLayoutCx<'tcx> {
fn target_spec(&self) -> &Target {
&self.0.sess.target
}
Expand Down
16 changes: 11 additions & 5 deletions compiler/rustc_codegen_cranelift/src/debuginfo/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use rustc_data_structures::fx::FxHashMap;
use rustc_middle::ty::layout::LayoutOf;
use rustc_middle::ty::{self, Ty, TyCtxt};

use crate::{DebugContext, RevealAllLayoutCx, has_ptr_meta};
use crate::{DebugContext, FullyMonomorphizedLayoutCx, has_ptr_meta};

#[derive(Default)]
pub(crate) struct TypeDebugContext<'tcx> {
Expand Down Expand Up @@ -85,7 +85,7 @@ impl DebugContext {
type_entry.set(gimli::DW_AT_encoding, AttributeValue::Encoding(encoding));
type_entry.set(
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
Expand Down Expand Up @@ -159,7 +159,7 @@ impl DebugContext {
return_if_type_created_in_meantime!(type_dbg, tuple_type);

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 =
self.dwarf.unit.add(self.dwarf.unit.root(), gimli::DW_TAG_structure_type);
Expand All @@ -178,7 +178,9 @@ impl DebugContext {
member_entry.set(gimli::DW_AT_type, AttributeValue::UnitRef(dw_ty));
member_entry.set(
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(
gimli::DW_AT_data_member_location,
Expand All @@ -198,7 +200,11 @@ impl DebugContext {
self.debug_type(
tcx,
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(),
),
)
}
}
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/src/global_asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub(crate) fn codegen_global_asm_item(tcx: TyCtxt<'_>, global_asm: &mut String,
tcx,
op_sp,
const_value,
RevealAllLayoutCx(tcx).layout_of(ty),
FullyMonomorphizedLayoutCx(tcx).layout_of(ty),
);
global_asm.push_str(&string);
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/src/inline_asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ pub(crate) fn codegen_naked_asm<'tcx>(
tcx,
span,
const_value,
RevealAllLayoutCx(tcx).layout_of(cv.ty()),
FullyMonomorphizedLayoutCx(tcx).layout_of(cv.ty()),
);
CInlineAsmOperand::Const { value }
}
Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_hir_analysis/src/check/compare_impl_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use rustc_trait_selection::infer::InferCtxtExt;
use rustc_trait_selection::regions::InferCtxtRegionExt;
use rustc_trait_selection::traits::outlives_bounds::InferCtxtExt as _;
use rustc_trait_selection::traits::{
self, FulfillmentError, ObligationCause, ObligationCauseCode, ObligationCtxt, Reveal,
self, FulfillmentError, ObligationCause, ObligationCauseCode, ObligationCtxt,
};
use tracing::{debug, instrument};

Expand Down Expand Up @@ -223,7 +223,7 @@ fn compare_method_predicate_entailment<'tcx>(
}

let normalize_cause = traits::ObligationCause::misc(impl_m_span, impl_m_def_id);
let param_env = ty::ParamEnv::new(tcx.mk_clauses(&hybrid_preds), Reveal::UserFacing);
let param_env = ty::ParamEnv::new(tcx.mk_clauses(&hybrid_preds));
let param_env = traits::normalize_param_env_or_error(tcx, param_env, normalize_cause);
debug!(caller_bounds=?param_env.caller_bounds());

Expand Down Expand Up @@ -508,7 +508,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
.into_iter()
.chain(tcx.predicates_of(trait_m.def_id).instantiate_own(tcx, trait_to_impl_args))
.map(|(clause, _)| clause);
let param_env = ty::ParamEnv::new(tcx.mk_clauses_from_iter(hybrid_preds), Reveal::UserFacing);
let param_env = ty::ParamEnv::new(tcx.mk_clauses_from_iter(hybrid_preds));
let param_env = traits::normalize_param_env_or_error(
tcx,
param_env,
Expand Down Expand Up @@ -1793,7 +1793,7 @@ fn compare_const_predicate_entailment<'tcx>(
.map(|(predicate, _)| predicate),
);

let param_env = ty::ParamEnv::new(tcx.mk_clauses(&hybrid_preds), Reveal::UserFacing);
let param_env = ty::ParamEnv::new(tcx.mk_clauses(&hybrid_preds));
let param_env = traits::normalize_param_env_or_error(
tcx,
param_env,
Expand Down Expand Up @@ -1946,7 +1946,7 @@ fn compare_type_predicate_entailment<'tcx>(
);
}

let param_env = ty::ParamEnv::new(tcx.mk_clauses(&hybrid_preds), Reveal::UserFacing);
let param_env = ty::ParamEnv::new(tcx.mk_clauses(&hybrid_preds));
let param_env = traits::normalize_param_env_or_error(tcx, param_env, normalize_cause);
debug!(caller_bounds=?param_env.caller_bounds());

Expand Down Expand Up @@ -2306,7 +2306,7 @@ fn param_env_with_gat_bounds<'tcx>(
};
}

ty::ParamEnv::new(tcx.mk_clauses(&predicates), Reveal::UserFacing)
ty::ParamEnv::new(tcx.mk_clauses(&predicates))
}

/// Manually check here that `async fn foo()` wasn't matched against `fn foo()`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use rustc_infer::infer::TyCtxtInferExt;
use rustc_infer::infer::outlives::env::OutlivesEnvironment;
use rustc_lint_defs::builtin::{REFINING_IMPL_TRAIT_INTERNAL, REFINING_IMPL_TRAIT_REACHABLE};
use rustc_middle::span_bug;
use rustc_middle::traits::{ObligationCause, Reveal};
use rustc_middle::traits::ObligationCause;
use rustc_middle::ty::{
self, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperVisitable, TypeVisitable,
TypeVisitableExt, TypeVisitor, TypingMode,
Expand Down Expand Up @@ -134,7 +134,7 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
.into_iter()
.chain(tcx.predicates_of(trait_m.def_id).instantiate_own(tcx, trait_m_to_impl_m_args))
.map(|(clause, _)| clause);
let param_env = ty::ParamEnv::new(tcx.mk_clauses_from_iter(hybrid_preds), Reveal::UserFacing);
let param_env = ty::ParamEnv::new(tcx.mk_clauses_from_iter(hybrid_preds));
let param_env = normalize_param_env_or_error(tcx, param_env, ObligationCause::dummy());

let ref infcx = tcx.infer_ctxt().build(TypingMode::non_body_analysis());
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ fn augment_param_env<'tcx>(
);
// FIXME(compiler-errors): Perhaps there is a case where we need to normalize this
// i.e. traits::normalize_param_env_or_error
ty::ParamEnv::new(bounds, param_env.reveal())
ty::ParamEnv::new(bounds)
}

/// We use the following trait as an example throughout this function.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/canonical/canonicalizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl<'tcx> InferCtxt<'tcx> {
query_state,
)
.unchecked_map(|(param_env, value)| param_env.and(value));
CanonicalQueryInput { canonical, typing_mode: self.typing_mode(param_env) }
CanonicalQueryInput { canonical, typing_mode: self.typing_mode() }
}

/// Canonicalizes a query *response* `V`. When we canonicalize a
Expand Down
7 changes: 2 additions & 5 deletions compiler/rustc_infer/src/infer/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@ impl<'tcx> rustc_type_ir::InferCtxtLike for InferCtxt<'tcx> {
self.next_trait_solver
}

fn typing_mode(
&self,
param_env_for_debug_assertion: ty::ParamEnv<'tcx>,
) -> ty::TypingMode<'tcx> {
self.typing_mode(param_env_for_debug_assertion)
fn typing_mode(&self) -> ty::TypingMode<'tcx> {
self.typing_mode()
}

fn universe(&self) -> ty::UniverseIndex {
Expand Down
31 changes: 8 additions & 23 deletions compiler/rustc_infer/src/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ use rustc_middle::ty::{
};
use rustc_span::Span;
use rustc_span::symbol::Symbol;
use rustc_type_ir::solve::Reveal;
use snapshot::undo_log::InferCtxtUndoLogs;
use tracing::{debug, instrument};
use type_variable::TypeVariableOrigin;
Expand Down Expand Up @@ -265,11 +264,12 @@ pub struct InferCtxt<'tcx> {
lexical_region_resolutions: RefCell<Option<LexicalRegionResolutions<'tcx>>>,

/// Caches the results of trait selection. This cache is used
/// for things that have to do with the parameters in scope.
pub selection_cache: select::SelectionCache<'tcx>,
/// for things that depends on inference variables or placeholders.
pub selection_cache: select::SelectionCache<'tcx, ty::ParamEnv<'tcx>>,

/// Caches the results of trait evaluation.
pub evaluation_cache: select::EvaluationCache<'tcx>,
/// Caches the results of trait evaluation. This cache is used
/// for things that depends on inference variables or placeholders.
pub evaluation_cache: select::EvaluationCache<'tcx, ty::ParamEnv<'tcx>>,

/// The set of predicates on which errors have been reported, to
/// avoid reporting the same error twice.
Expand Down Expand Up @@ -624,22 +624,7 @@ impl<'tcx> InferCtxt<'tcx> {
}

#[inline(always)]
pub fn typing_mode(
&self,
param_env_for_debug_assertion: ty::ParamEnv<'tcx>,
) -> TypingMode<'tcx> {
if cfg!(debug_assertions) {
match (param_env_for_debug_assertion.reveal(), self.typing_mode) {
(Reveal::All, TypingMode::PostAnalysis)
| (Reveal::UserFacing, TypingMode::Coherence | TypingMode::Analysis { .. }) => {}
(r, t) => unreachable!("TypingMode x Reveal mismatch: {r:?} {t:?}"),
}
}
self.typing_mode
}

#[inline(always)]
pub fn typing_mode_unchecked(&self) -> TypingMode<'tcx> {
pub fn typing_mode(&self) -> TypingMode<'tcx> {
self.typing_mode
}

Expand Down Expand Up @@ -1005,7 +990,7 @@ impl<'tcx> InferCtxt<'tcx> {

#[inline(always)]
pub fn can_define_opaque_ty(&self, id: impl Into<DefId>) -> bool {
match self.typing_mode_unchecked() {
match self.typing_mode() {
TypingMode::Analysis { defining_opaque_types } => {
id.into().as_local().is_some_and(|def_id| defining_opaque_types.contains(&def_id))
}
Expand Down Expand Up @@ -1290,7 +1275,7 @@ impl<'tcx> InferCtxt<'tcx> {
/// which contains the necessary information to use the trait system without
/// using canonicalization or carrying this inference context around.
pub fn typing_env(&self, param_env: ty::ParamEnv<'tcx>) -> ty::TypingEnv<'tcx> {
let typing_mode = match self.typing_mode(param_env) {
let typing_mode = match self.typing_mode() {
ty::TypingMode::Coherence => ty::TypingMode::Coherence,
// FIXME(#132279): This erases the `defining_opaque_types` as it isn't possible
// to handle them without proper canonicalization. This means we may cause cycle
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_infer/src/infer/opaque_types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl<'tcx> InferCtxt<'tcx> {
let process = |a: Ty<'tcx>, b: Ty<'tcx>| match *a.kind() {
ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) if def_id.is_local() => {
let def_id = def_id.expect_local();
if let ty::TypingMode::Coherence = self.typing_mode(param_env) {
if let ty::TypingMode::Coherence = self.typing_mode() {
// See comment on `insert_hidden_type` for why this is sufficient in coherence
return Some(self.register_hidden_type(
OpaqueTypeKey { def_id, args },
Expand Down Expand Up @@ -522,7 +522,7 @@ impl<'tcx> InferCtxt<'tcx> {
// value being folded. In simple cases like `-> impl Foo`,
// these are the same span, but not in cases like `-> (impl
// Foo, impl Bar)`.
match self.typing_mode(param_env) {
match self.typing_mode() {
ty::TypingMode::Coherence => {
// During intercrate we do not define opaque types but instead always
// force ambiguity unless the hidden type is known to not implement
Expand Down
Loading
Loading