@@ -797,10 +797,10 @@ fn inner_optimized_mir(tcx: TyCtxt<'_>, did: LocalDefId) -> Body<'_> {
797
797
vis. visit_body ( & body) ;
798
798
799
799
// If the MIR is already monomorphic, we can transform it to codegen MIR right away.
800
- if !tcx. generics_of ( did) . requires_monomorphization ( tcx) && !vis . contains_ubcheck {
801
- if vis. contains_alias {
802
- eprintln ! ( "alias: {:?}" , did ) ;
803
- }
800
+ if !tcx. generics_of ( did) . requires_monomorphization ( tcx)
801
+ && ! vis. contains_ubcheck
802
+ && !vis . contains_alias
803
+ {
804
804
let instance = Instance :: mono ( tcx, did. into ( ) ) ;
805
805
body = instance. instantiate_mir_and_normalize_erasing_regions (
806
806
tcx,
@@ -817,6 +817,12 @@ use rustc_middle::mir::visit::{TyContext, Visitor};
817
817
use rustc_middle:: mir:: { Location , NullOp } ;
818
818
use rustc_middle:: ty:: { Ty , TypeFlags } ;
819
819
820
+ // FIXME: This visitor looks for properties of MIR that would forbid using optimized MIR as codegen
821
+ // MIR.
822
+ // Currently, it looks for NullOp::UbChecks because that must be resolved at codegen, and also for
823
+ // type projections because those are the only way I've found to realize that we are generating MIR
824
+ // for a body with an unsatisafiable predicate. Such bodies cannot be normalized, so we must not
825
+ // try to create codegen MIR for them.
820
826
struct MonoCompatVisitor {
821
827
contains_alias : bool ,
822
828
contains_ubcheck : bool ,
@@ -825,7 +831,7 @@ struct MonoCompatVisitor {
825
831
impl < ' tcx > Visitor < ' tcx > for MonoCompatVisitor {
826
832
fn visit_ty ( & mut self , ty : Ty < ' tcx > , _: TyContext ) {
827
833
debug ! ( "{:?} {:?}" , ty, ty. flags( ) ) ;
828
- if ty. flags ( ) . contains ( TypeFlags :: HAS_ALIAS ) {
834
+ if ty. has_aliases ( ) || ty . flags ( ) . contains ( TypeFlags :: HAS_TY_PROJECTION ) {
829
835
self . contains_alias = true ;
830
836
}
831
837
}
0 commit comments