Skip to content

Commit bc08ca0

Browse files
committed
no more Reveal :(
1 parent 5359dc4 commit bc08ca0

File tree

47 files changed

+126
-330
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+126
-330
lines changed

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use rustc_trait_selection::infer::InferCtxtExt;
2626
use rustc_trait_selection::regions::InferCtxtRegionExt;
2727
use rustc_trait_selection::traits::outlives_bounds::InferCtxtExt as _;
2828
use rustc_trait_selection::traits::{
29-
self, FulfillmentError, ObligationCause, ObligationCauseCode, ObligationCtxt, Reveal,
29+
self, FulfillmentError, ObligationCause, ObligationCauseCode, ObligationCtxt,
3030
};
3131
use tracing::{debug, instrument};
3232

@@ -223,7 +223,7 @@ fn compare_method_predicate_entailment<'tcx>(
223223
}
224224

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

@@ -508,7 +508,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
508508
.into_iter()
509509
.chain(tcx.predicates_of(trait_m.def_id).instantiate_own(tcx, trait_to_impl_args))
510510
.map(|(clause, _)| clause);
511-
let param_env = ty::ParamEnv::new(tcx.mk_clauses_from_iter(hybrid_preds), Reveal::UserFacing);
511+
let param_env = ty::ParamEnv::new(tcx.mk_clauses_from_iter(hybrid_preds));
512512
let param_env = traits::normalize_param_env_or_error(
513513
tcx,
514514
param_env,
@@ -1793,7 +1793,7 @@ fn compare_const_predicate_entailment<'tcx>(
17931793
.map(|(predicate, _)| predicate),
17941794
);
17951795

1796-
let param_env = ty::ParamEnv::new(tcx.mk_clauses(&hybrid_preds), Reveal::UserFacing);
1796+
let param_env = ty::ParamEnv::new(tcx.mk_clauses(&hybrid_preds));
17971797
let param_env = traits::normalize_param_env_or_error(
17981798
tcx,
17991799
param_env,
@@ -1946,7 +1946,7 @@ fn compare_type_predicate_entailment<'tcx>(
19461946
);
19471947
}
19481948

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

@@ -2306,7 +2306,7 @@ fn param_env_with_gat_bounds<'tcx>(
23062306
};
23072307
}
23082308

2309-
ty::ParamEnv::new(tcx.mk_clauses(&predicates), Reveal::UserFacing)
2309+
ty::ParamEnv::new(tcx.mk_clauses(&predicates))
23102310
}
23112311

23122312
/// Manually check here that `async fn foo()` wasn't matched against `fn foo()`,

compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_infer::infer::TyCtxtInferExt;
66
use rustc_infer::infer::outlives::env::OutlivesEnvironment;
77
use rustc_lint_defs::builtin::{REFINING_IMPL_TRAIT_INTERNAL, REFINING_IMPL_TRAIT_REACHABLE};
88
use rustc_middle::span_bug;
9-
use rustc_middle::traits::{ObligationCause, Reveal};
9+
use rustc_middle::traits::ObligationCause;
1010
use rustc_middle::ty::{
1111
self, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperVisitable, TypeVisitable,
1212
TypeVisitableExt, TypeVisitor, TypingMode,
@@ -134,7 +134,7 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
134134
.into_iter()
135135
.chain(tcx.predicates_of(trait_m.def_id).instantiate_own(tcx, trait_m_to_impl_m_args))
136136
.map(|(clause, _)| clause);
137-
let param_env = ty::ParamEnv::new(tcx.mk_clauses_from_iter(hybrid_preds), Reveal::UserFacing);
137+
let param_env = ty::ParamEnv::new(tcx.mk_clauses_from_iter(hybrid_preds));
138138
let param_env = normalize_param_env_or_error(tcx, param_env, ObligationCause::dummy());
139139

140140
let ref infcx = tcx.infer_ctxt().build(TypingMode::non_body_analysis());

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ fn augment_param_env<'tcx>(
604604
);
605605
// FIXME(compiler-errors): Perhaps there is a case where we need to normalize this
606606
// i.e. traits::normalize_param_env_or_error
607-
ty::ParamEnv::new(bounds, param_env.reveal())
607+
ty::ParamEnv::new(bounds)
608608
}
609609

610610
/// We use the following trait as an example throughout this function.

compiler/rustc_infer/src/infer/canonical/canonicalizer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl<'tcx> InferCtxt<'tcx> {
7272
query_state,
7373
)
7474
.unchecked_map(|(param_env, value)| param_env.and(value));
75-
CanonicalQueryInput { canonical, typing_mode: self.typing_mode(param_env) }
75+
CanonicalQueryInput { canonical, typing_mode: self.typing_mode() }
7676
}
7777

7878
/// Canonicalizes a query *response* `V`. When we canonicalize a

compiler/rustc_infer/src/infer/context.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,8 @@ impl<'tcx> rustc_type_ir::InferCtxtLike for InferCtxt<'tcx> {
2020
self.next_trait_solver
2121
}
2222

23-
fn typing_mode(
24-
&self,
25-
param_env_for_debug_assertion: ty::ParamEnv<'tcx>,
26-
) -> ty::TypingMode<'tcx> {
27-
self.typing_mode(param_env_for_debug_assertion)
23+
fn typing_mode(&self) -> ty::TypingMode<'tcx> {
24+
self.typing_mode()
2825
}
2926

3027
fn universe(&self) -> ty::UniverseIndex {

compiler/rustc_infer/src/infer/mod.rs

+3-19
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ use rustc_middle::ty::{
4343
};
4444
use rustc_span::Span;
4545
use rustc_span::symbol::Symbol;
46-
use rustc_type_ir::solve::Reveal;
4746
use snapshot::undo_log::InferCtxtUndoLogs;
4847
use tracing::{debug, instrument};
4948
use type_variable::TypeVariableOrigin;
@@ -624,22 +623,7 @@ impl<'tcx> InferCtxt<'tcx> {
624623
}
625624

626625
#[inline(always)]
627-
pub fn typing_mode(
628-
&self,
629-
param_env_for_debug_assertion: ty::ParamEnv<'tcx>,
630-
) -> TypingMode<'tcx> {
631-
if cfg!(debug_assertions) {
632-
match (param_env_for_debug_assertion.reveal(), self.typing_mode) {
633-
(Reveal::All, TypingMode::PostAnalysis)
634-
| (Reveal::UserFacing, TypingMode::Coherence | TypingMode::Analysis { .. }) => {}
635-
(r, t) => unreachable!("TypingMode x Reveal mismatch: {r:?} {t:?}"),
636-
}
637-
}
638-
self.typing_mode
639-
}
640-
641-
#[inline(always)]
642-
pub fn typing_mode_unchecked(&self) -> TypingMode<'tcx> {
626+
pub fn typing_mode(&self) -> TypingMode<'tcx> {
643627
self.typing_mode
644628
}
645629

@@ -1005,7 +989,7 @@ impl<'tcx> InferCtxt<'tcx> {
1005989

1006990
#[inline(always)]
1007991
pub fn can_define_opaque_ty(&self, id: impl Into<DefId>) -> bool {
1008-
match self.typing_mode_unchecked() {
992+
match self.typing_mode() {
1009993
TypingMode::Analysis { defining_opaque_types } => {
1010994
id.into().as_local().is_some_and(|def_id| defining_opaque_types.contains(&def_id))
1011995
}
@@ -1290,7 +1274,7 @@ impl<'tcx> InferCtxt<'tcx> {
12901274
/// which contains the necessary information to use the trait system without
12911275
/// using canonicalization or carrying this inference context around.
12921276
pub fn typing_env(&self, param_env: ty::ParamEnv<'tcx>) -> ty::TypingEnv<'tcx> {
1293-
let typing_mode = match self.typing_mode(param_env) {
1277+
let typing_mode = match self.typing_mode() {
12941278
ty::TypingMode::Coherence => ty::TypingMode::Coherence,
12951279
// FIXME(#132279): This erases the `defining_opaque_types` as it isn't possible
12961280
// to handle them without proper canonicalization. This means we may cause cycle

compiler/rustc_infer/src/infer/opaque_types/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl<'tcx> InferCtxt<'tcx> {
101101
let process = |a: Ty<'tcx>, b: Ty<'tcx>| match *a.kind() {
102102
ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) if def_id.is_local() => {
103103
let def_id = def_id.expect_local();
104-
if let ty::TypingMode::Coherence = self.typing_mode(param_env) {
104+
if let ty::TypingMode::Coherence = self.typing_mode() {
105105
// See comment on `insert_hidden_type` for why this is sufficient in coherence
106106
return Some(self.register_hidden_type(
107107
OpaqueTypeKey { def_id, args },
@@ -522,7 +522,7 @@ impl<'tcx> InferCtxt<'tcx> {
522522
// value being folded. In simple cases like `-> impl Foo`,
523523
// these are the same span, but not in cases like `-> (impl
524524
// Foo, impl Bar)`.
525-
match self.typing_mode(param_env) {
525+
match self.typing_mode() {
526526
ty::TypingMode::Coherence => {
527527
// During intercrate we do not define opaque types but instead always
528528
// force ambiguity unless the hidden type is known to not implement

compiler/rustc_infer/src/infer/relate/generalize.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -520,10 +520,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Generalizer<'_, 'tcx> {
520520
//
521521
// cc trait-system-refactor-initiative#108
522522
if self.infcx.next_trait_solver()
523-
&& !matches!(
524-
self.infcx.typing_mode_unchecked(),
525-
TypingMode::Coherence
526-
)
523+
&& !matches!(self.infcx.typing_mode(), TypingMode::Coherence)
527524
&& self.in_alias
528525
{
529526
inner.type_variables().equate(vid, new_var_id);
@@ -654,10 +651,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Generalizer<'_, 'tcx> {
654651
// See the comment for type inference variables
655652
// for more details.
656653
if self.infcx.next_trait_solver()
657-
&& !matches!(
658-
self.infcx.typing_mode_unchecked(),
659-
TypingMode::Coherence
660-
)
654+
&& !matches!(self.infcx.typing_mode(), TypingMode::Coherence)
661655
&& self.in_alias
662656
{
663657
variable_table.union(vid, new_var_id);

compiler/rustc_lint/src/context.rs

-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use rustc_feature::Features;
1414
use rustc_hir::def::Res;
1515
use rustc_hir::def_id::{CrateNum, DefId};
1616
use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData};
17-
use rustc_infer::traits::Reveal;
1817
use rustc_middle::bug;
1918
use rustc_middle::middle::privacy::EffectiveVisibilities;
2019
use rustc_middle::ty::layout::{LayoutError, LayoutOfHelpers, TyAndLayout};
@@ -702,7 +701,6 @@ impl<'tcx> LateContext<'tcx> {
702701
/// The typing mode of the currently visited node. Use this when
703702
/// building a new `InferCtxt`.
704703
pub fn typing_mode(&self) -> TypingMode<'tcx> {
705-
debug_assert_eq!(self.param_env.reveal(), Reveal::UserFacing);
706704
// FIXME(#132279): In case we're in a body, we should use a typing
707705
// mode which reveals the opaque types defined by that body.
708706
TypingMode::non_body_analysis()

compiler/rustc_middle/src/mir/consts.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,10 @@ impl<'tcx> ConstValue<'tcx> {
105105
typing_env: ty::TypingEnv<'tcx>,
106106
ty: Ty<'tcx>,
107107
) -> Option<u128> {
108-
let size =
109-
tcx.layout_of(typing_env.with_reveal_all_normalized(tcx).as_query_input(ty)).ok()?.size;
108+
let size = tcx
109+
.layout_of(typing_env.with_post_analysis_normalized(tcx).as_query_input(ty))
110+
.ok()?
111+
.size;
110112
self.try_to_bits(size)
111113
}
112114

@@ -376,7 +378,7 @@ impl<'tcx> Const<'tcx> {
376378
) -> Option<u128> {
377379
let int = self.try_eval_scalar_int(tcx, typing_env)?;
378380
let size = tcx
379-
.layout_of(typing_env.with_reveal_all_normalized(tcx).as_query_input(self.ty()))
381+
.layout_of(typing_env.with_post_analysis_normalized(tcx).as_query_input(self.ty()))
380382
.ok()?
381383
.size;
382384
Some(int.to_bits(size))

compiler/rustc_middle/src/mir/interpret/queries.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ impl<'tcx> TyCtxt<'tcx> {
162162
// Const-eval shouldn't depend on lifetimes at all, so we can erase them, which should
163163
// improve caching of queries.
164164
let inputs =
165-
self.erase_regions(typing_env.with_reveal_all_normalized(self).as_query_input(cid));
165+
self.erase_regions(typing_env.with_post_analysis_normalized(self).as_query_input(cid));
166166
if !span.is_dummy() {
167167
// The query doesn't know where it is being invoked, so we need to fix the span.
168168
self.at(span).eval_to_const_value_raw(inputs).map_err(|e| e.with_span(span))
@@ -182,7 +182,7 @@ impl<'tcx> TyCtxt<'tcx> {
182182
// Const-eval shouldn't depend on lifetimes at all, so we can erase them, which should
183183
// improve caching of queries.
184184
let inputs =
185-
self.erase_regions(typing_env.with_reveal_all_normalized(self).as_query_input(cid));
185+
self.erase_regions(typing_env.with_post_analysis_normalized(self).as_query_input(cid));
186186
debug!(?inputs);
187187
if !span.is_dummy() {
188188
// The query doesn't know where it is being invoked, so we need to fix the span.

compiler/rustc_middle/src/query/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1381,10 +1381,10 @@ rustc_queries! {
13811381
feedable
13821382
}
13831383

1384-
/// Like `param_env`, but returns the `ParamEnv` in `Reveal::All` mode.
1385-
/// Prefer this over `tcx.param_env(def_id).with_reveal_all_normalized(tcx)`,
1386-
/// as this method is more efficient.
1387-
query param_env_reveal_all_normalized(def_id: DefId) -> ty::ParamEnv<'tcx> {
1384+
/// Like `param_env`, but returns the `ParamEnv` after all opaque types have been
1385+
/// replaced with their hidden type. This is used in the old trait solver
1386+
/// when in `PostAnalysis` mode and should not be called directly.
1387+
query param_env_normalized_for_post_analysis(def_id: DefId) -> ty::ParamEnv<'tcx> {
13881388
desc { |tcx| "computing revealed normalized predicates of `{}`", tcx.def_path_str(def_id) }
13891389
}
13901390

compiler/rustc_middle/src/traits/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use rustc_span::def_id::{CRATE_DEF_ID, LocalDefId};
2323
use rustc_span::symbol::Symbol;
2424
use rustc_span::{DUMMY_SP, Span};
2525
// FIXME: Remove this import and import via `solve::`
26-
pub use rustc_type_ir::solve::{BuiltinImplSource, Reveal};
26+
pub use rustc_type_ir::solve::BuiltinImplSource;
2727
use smallvec::{SmallVec, smallvec};
2828
use thin_vec::ThinVec;
2929

compiler/rustc_middle/src/ty/codec.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ impl<'tcx, E: TyEncoder<I = TyCtxt<'tcx>>> Encodable<E> for CtfeProvenance {
174174
impl<'tcx, E: TyEncoder<I = TyCtxt<'tcx>>> Encodable<E> for ty::ParamEnv<'tcx> {
175175
fn encode(&self, e: &mut E) {
176176
self.caller_bounds().encode(e);
177-
self.reveal().encode(e);
178177
}
179178
}
180179

@@ -310,8 +309,7 @@ impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for ty::SymbolName<'tcx>
310309
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for ty::ParamEnv<'tcx> {
311310
fn decode(d: &mut D) -> Self {
312311
let caller_bounds = Decodable::decode(d);
313-
let reveal = Decodable::decode(d);
314-
ty::ParamEnv::new(caller_bounds, reveal)
312+
ty::ParamEnv::new(caller_bounds)
315313
}
316314
}
317315

compiler/rustc_middle/src/ty/consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ impl<'tcx> Const<'tcx> {
336336
pub fn try_to_bits(self, tcx: TyCtxt<'tcx>, typing_env: ty::TypingEnv<'tcx>) -> Option<u128> {
337337
let (scalar, ty) = self.try_to_scalar()?;
338338
let scalar = scalar.try_to_scalar_int().ok()?;
339-
let input = typing_env.with_reveal_all_normalized(tcx).as_query_input(ty);
339+
let input = typing_env.with_post_analysis_normalized(tcx).as_query_input(ty);
340340
let size = tcx.layout_of(input).ok()?.size;
341341
Some(scalar.to_bits(size))
342342
}

0 commit comments

Comments
 (0)