From c3a2302fb068fe61c7c7fb1bc751abe2daa631e4 Mon Sep 17 00:00:00 2001 From: "Celina G. Val" Date: Wed, 13 Dec 2023 16:33:26 -0800 Subject: [PATCH] Erase late bound regions from instance `fn_sig()` Late bound regions were still part of the signature. --- compiler/rustc_smir/src/rustc_smir/context.rs | 15 ++++++++++++--- compiler/stable_mir/src/compiler_interface.rs | 9 ++++++--- compiler/stable_mir/src/mir/mono.rs | 2 +- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_smir/src/rustc_smir/context.rs b/compiler/rustc_smir/src/rustc_smir/context.rs index 241a0c22310..5516ca0a599 100644 --- a/compiler/rustc_smir/src/rustc_smir/context.rs +++ b/compiler/rustc_smir/src/rustc_smir/context.rs @@ -13,8 +13,8 @@ use stable_mir::mir::Body; use stable_mir::target::{MachineInfo, MachineSize}; use stable_mir::ty::{ - AdtDef, AdtKind, Allocation, ClosureDef, ClosureKind, Const, FieldDef, FnDef, GenericArgs, - LineInfo, PolyFnSig, RigidTy, Span, Ty, TyKind, VariantDef, + AdtDef, AdtKind, Allocation, ClosureDef, ClosureKind, Const, FieldDef, FnDef, FnSig, + GenericArgs, LineInfo, PolyFnSig, RigidTy, Span, Ty, TyKind, VariantDef, }; use stable_mir::{Crate, CrateItem, DefId, Error, Filename, ItemKind, Symbol}; use std::cell::RefCell; @@ -324,7 +324,16 @@ fn instance_body(&self, def: InstanceDef) -> Option { fn instance_ty(&self, def: InstanceDef) -> stable_mir::ty::Ty { let mut tables = self.0.borrow_mut(); let instance = tables.instances[def]; - instance.ty(tables.tcx, ParamEnv::empty()).stable(&mut *tables) + instance.ty(tables.tcx, ParamEnv::reveal_all()).stable(&mut *tables) + } + + fn instance_sig(&self, def: InstanceDef) -> FnSig { + let mut tables = self.0.borrow_mut(); + let instance = tables.instances[def]; + let ty = instance.ty(tables.tcx, ParamEnv::reveal_all()); + let sig = if ty.is_fn() { ty.fn_sig(tables.tcx) } else { instance.args.as_closure().sig() }; + // Erase late bound regions. + tables.tcx.instantiate_bound_regions_with_erased(sig).stable(&mut *tables) } fn instance_def_id(&self, def: InstanceDef) -> stable_mir::DefId { diff --git a/compiler/stable_mir/src/compiler_interface.rs b/compiler/stable_mir/src/compiler_interface.rs index 2fac59e71fd..8ee82c24130 100644 --- a/compiler/stable_mir/src/compiler_interface.rs +++ b/compiler/stable_mir/src/compiler_interface.rs @@ -10,9 +10,9 @@ use crate::mir::Body; use crate::target::MachineInfo; use crate::ty::{ - AdtDef, AdtKind, Allocation, ClosureDef, ClosureKind, Const, FieldDef, FnDef, GenericArgs, - GenericPredicates, Generics, ImplDef, ImplTrait, LineInfo, PolyFnSig, RigidTy, Span, TraitDecl, - TraitDef, Ty, TyKind, VariantDef, + AdtDef, AdtKind, Allocation, ClosureDef, ClosureKind, Const, FieldDef, FnDef, FnSig, + GenericArgs, GenericPredicates, Generics, ImplDef, ImplTrait, LineInfo, PolyFnSig, RigidTy, + Span, TraitDecl, TraitDef, Ty, TyKind, VariantDef, }; use crate::{ mir, Crate, CrateItem, CrateItems, DefId, Error, Filename, ImplTraitDecls, ItemKind, Symbol, @@ -121,6 +121,9 @@ pub trait Context { /// Get the instance type with generic substitutions applied and lifetimes erased. fn instance_ty(&self, instance: InstanceDef) -> Ty; + /// Get the instance signature with . + fn instance_sig(&self, def: InstanceDef) -> FnSig; + /// Get the instance. fn instance_def_id(&self, instance: InstanceDef) -> DefId; diff --git a/compiler/stable_mir/src/mir/mono.rs b/compiler/stable_mir/src/mir/mono.rs index bc5d4a3b8f4..6b8c69d14ee 100644 --- a/compiler/stable_mir/src/mir/mono.rs +++ b/compiler/stable_mir/src/mir/mono.rs @@ -117,7 +117,7 @@ pub fn resolve_closure( /// Get this function signature with all types already instantiated. pub fn fn_sig(&self) -> FnSig { - self.ty().kind().fn_sig().unwrap().skip_binder() + with(|cx| cx.instance_sig(self.def)) } /// Check whether this instance is an empty shim.