Erase late bound regions from instance fn_sig()

Late bound regions were still part of the signature.
This commit is contained in:
Celina G. Val 2023-12-13 16:33:26 -08:00
parent eeff92ad32
commit c3a2302fb0
3 changed files with 19 additions and 7 deletions

View File

@ -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<Body> {
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 {

View File

@ -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;

View File

@ -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.