2021-05-13 12:04:41 +02:00
|
|
|
//! Normalizes MIR in RevealAll mode.
|
|
|
|
|
|
|
|
use crate::MirPass;
|
|
|
|
use rustc_middle::mir::visit::*;
|
|
|
|
use rustc_middle::mir::*;
|
|
|
|
use rustc_middle::ty::{self, Ty, TyCtxt};
|
|
|
|
|
|
|
|
pub struct RevealAll;
|
|
|
|
|
|
|
|
impl<'tcx> MirPass<'tcx> for RevealAll {
|
2021-12-02 09:17:32 -08:00
|
|
|
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
|
|
|
|
sess.opts.mir_opt_level() >= 3 || super::inline::Inline.is_enabled(sess)
|
|
|
|
}
|
|
|
|
|
2021-05-13 12:04:41 +02:00
|
|
|
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
|
|
|
// Do not apply this transformation to generators.
|
2021-12-02 09:17:32 -08:00
|
|
|
if body.generator.is_some() {
|
|
|
|
return;
|
2021-05-13 12:04:41 +02:00
|
|
|
}
|
2021-12-02 09:17:32 -08:00
|
|
|
|
|
|
|
let param_env = tcx.param_env_reveal_all_normalized(body.source.def_id());
|
|
|
|
RevealAllVisitor { tcx, param_env }.visit_body(body);
|
2021-05-13 12:04:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct RevealAllVisitor<'tcx> {
|
|
|
|
tcx: TyCtxt<'tcx>,
|
|
|
|
param_env: ty::ParamEnv<'tcx>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx> MutVisitor<'tcx> for RevealAllVisitor<'tcx> {
|
|
|
|
#[inline]
|
|
|
|
fn tcx(&self) -> TyCtxt<'tcx> {
|
|
|
|
self.tcx
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn visit_ty(&mut self, ty: &mut Ty<'tcx>, _: TyContext) {
|
2021-12-13 22:24:08 +01:00
|
|
|
// We have to use `try_normalize_erasing_regions` here, since it's
|
|
|
|
// possible that we visit impossible-to-satisfy where clauses here,
|
|
|
|
// see #91745
|
Overhaul `TyS` and `Ty`.
Specifically, change `Ty` from this:
```
pub type Ty<'tcx> = &'tcx TyS<'tcx>;
```
to this
```
pub struct Ty<'tcx>(Interned<'tcx, TyS<'tcx>>);
```
There are two benefits to this.
- It's now a first class type, so we can define methods on it. This
means we can move a lot of methods away from `TyS`, leaving `TyS` as a
barely-used type, which is appropriate given that it's not meant to
be used directly.
- The uniqueness requirement is now explicit, via the `Interned` type.
E.g. the pointer-based `Eq` and `Hash` comes from `Interned`, rather
than via `TyS`, which wasn't obvious at all.
Much of this commit is boring churn. The interesting changes are in
these files:
- compiler/rustc_middle/src/arena.rs
- compiler/rustc_middle/src/mir/visit.rs
- compiler/rustc_middle/src/ty/context.rs
- compiler/rustc_middle/src/ty/mod.rs
Specifically:
- Most mentions of `TyS` are removed. It's very much a dumb struct now;
`Ty` has all the smarts.
- `TyS` now has `crate` visibility instead of `pub`.
- `TyS::make_for_test` is removed in favour of the static `BOOL_TY`,
which just works better with the new structure.
- The `Eq`/`Ord`/`Hash` impls are removed from `TyS`. `Interned`s impls
of `Eq`/`Hash` now suffice. `Ord` is now partly on `Interned`
(pointer-based, for the `Equal` case) and partly on `TyS`
(contents-based, for the other cases).
- There are many tedious sigil adjustments, i.e. adding or removing `*`
or `&`. They seem to be unavoidable.
2022-01-25 14:13:38 +11:00
|
|
|
*ty = self.tcx.try_normalize_erasing_regions(self.param_env, *ty).unwrap_or(*ty);
|
2021-05-13 12:04:41 +02:00
|
|
|
}
|
|
|
|
}
|