1
Fork 0

Rollup merge of #131856 - lcnr:typing-mode, r=compiler-errors

TypingMode: merge intercrate, reveal, and defining_opaque_types

This adds `TypingMode` and uses it in most places. We do not yet remove `Reveal` from `param_env`s. This and other future work as tracked in #132279 and via `FIXME`s.

Fetching the `TypingMode` of the `InferCtxt` asserts that the `TypingMode` agrees with `ParamEnv::reveal` to make sure we don't introduce any subtle bugs here. This will be unnecessary once `ParamEnv::reveal` no longer exists.

As the `TypingMode` is now a part of the query input, I've merged the coherence and non-coherence caches for the new solver. I've also enabled the local `infcx` cache during coherence by clearing the cache when forking it with a different `TypingMode`.

#### `TypingMode::from_param_env`

I am using this even in cases where I know that the `param_env` will always be `Reveal::UserFacing`. This is to make it easier to correctly refactor this code in the future, any time we use `Reveal::UserFacing` in a body while not defining its opaque types is incorrect and should use a `TypingMode` which only reveals opaques defined by that body instead, cc #124598

r? ``@compiler-errors``
This commit is contained in:
Matthias Krüger 2024-10-30 06:40:34 +01:00 committed by GitHub
commit 305508f969
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
89 changed files with 537 additions and 532 deletions

View file

@ -16,7 +16,7 @@ use rustc_middle::middle::region;
use rustc_middle::mir::*;
use rustc_middle::query::TyCtxtAt;
use rustc_middle::thir::{self, ExprId, LintLevel, LocalVarId, Param, ParamId, PatKind, Thir};
use rustc_middle::ty::{self, ScalarInt, Ty, TyCtxt, TypeVisitableExt};
use rustc_middle::ty::{self, ScalarInt, Ty, TyCtxt, TypeVisitableExt, TypingMode};
use rustc_middle::{bug, span_bug};
use rustc_span::symbol::sym;
use rustc_span::{Span, Symbol};
@ -500,7 +500,9 @@ fn construct_fn<'tcx>(
);
}
let infcx = tcx.infer_ctxt().build();
// FIXME(#132279): This should be able to reveal opaque
// types defined during HIR typeck.
let infcx = tcx.infer_ctxt().build(TypingMode::non_body_analysis());
let mut builder = Builder::new(
thir,
infcx,
@ -578,7 +580,9 @@ fn construct_const<'a, 'tcx>(
_ => span_bug!(tcx.def_span(def), "can't build MIR for {:?}", def),
};
let infcx = tcx.infer_ctxt().build();
// FIXME(#132279): We likely want to be able to use the hidden types of
// opaques used by this function here.
let infcx = tcx.infer_ctxt().build(TypingMode::non_body_analysis());
let mut builder =
Builder::new(thir, infcx, def, hir_id, span, 0, const_ty, const_ty_span, None);

View file

@ -7,7 +7,7 @@ use rustc_infer::traits::Obligation;
use rustc_middle::mir;
use rustc_middle::mir::interpret::ErrorHandled;
use rustc_middle::thir::{FieldPat, Pat, PatKind};
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt, ValTree};
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt, TypingMode, ValTree};
use rustc_span::Span;
use rustc_target::abi::{FieldIdx, VariantIdx};
use rustc_trait_selection::traits::ObligationCause;
@ -36,7 +36,9 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
id: hir::HirId,
span: Span,
) -> Box<Pat<'tcx>> {
let infcx = self.tcx.infer_ctxt().build();
// FIXME(#132279): We likely want to be able to reveal the hidden types
// of opaques defined in this function here.
let infcx = self.tcx.infer_ctxt().build(TypingMode::non_body_analysis());
let mut convert = ConstToPat::new(self, id, span, infcx);
convert.to_pat(c, ty)
}