predicates of

This commit is contained in:
Eric Mark Martin 2023-08-22 01:09:10 -04:00 committed by Santiago Pastorino
parent 735e9c0c51
commit 107cb5c904
No known key found for this signature in database
GPG Key ID: 8131A24E0C79EFAF
3 changed files with 43 additions and 12 deletions

View File

@ -108,6 +108,23 @@ impl<'tcx> Context for Tables<'tcx> {
let generic_def = self.tcx.generics_of(def_id);
generic_def.stable(self)
}
fn predicates_of(
&mut self,
trait_def: &stable_mir::ty::TraitDef,
) -> stable_mir::GenericPredicates {
let trait_def_id = self.trait_def_id(trait_def);
let ty::GenericPredicates { parent, predicates } = self.tcx.predicates_of(trait_def_id);
stable_mir::GenericPredicates {
parent: parent.map(|did| self.trait_def(did)),
predicates: predicates
.iter()
.map(|(clause, span)| {
(clause.as_predicate().kind().skip_binder().stable(self), span.stable(self))
})
.collect(),
}
}
}
pub struct Tables<'tcx> {
@ -947,12 +964,12 @@ impl<'tcx> Stable<'tcx> for ty::BoundTyKind {
impl<'tcx> Stable<'tcx> for ty::BoundRegionKind {
type T = stable_mir::ty::BoundRegionKind;
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
use stable_mir::ty::BoundRegionKind;
match self {
ty::BoundRegionKind::BrAnon(option_span) => {
BoundRegionKind::BrAnon(option_span.map(|span| opaque(&span)))
BoundRegionKind::BrAnon(option_span.map(|span| span.stable(tables)))
}
ty::BoundRegionKind::BrNamed(def_id, symbol) => {
BoundRegionKind::BrNamed(rustc_internal::br_named_def(*def_id), symbol.to_string())
@ -1242,14 +1259,6 @@ impl<'tcx> Stable<'tcx> for ty::Generics {
}
}
impl<'tcx> Stable<'tcx> for rustc_span::Span {
type T = stable_mir::ty::Span;
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
opaque(self)
}
}
impl<'tcx> Stable<'tcx> for rustc_middle::ty::GenericParamDefKind {
type T = stable_mir::ty::GenericParamDefKind;
@ -1456,3 +1465,12 @@ impl<'tcx> Stable<'tcx> for ty::Region<'tcx> {
opaque(self)
}
}
impl<'tcx> Stable<'tcx> for rustc_span::Span {
type T = stable_mir::ty::Span;
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
// FIXME: add a real implementation of stable spans
opaque(self)
}
}

View File

@ -15,7 +15,9 @@ use std::cell::Cell;
use crate::rustc_smir::Tables;
use self::ty::{GenericDef, Generics, ImplDef, ImplTrait, TraitDecl, TraitDef, Ty, TyKind};
use self::ty::{
GenericDef, Generics, ImplDef, ImplTrait, PredicateKind, Span, TraitDecl, TraitDef, Ty, TyKind,
};
pub mod mir;
pub mod ty;
@ -38,6 +40,12 @@ pub type TraitDecls = Vec<TraitDef>;
/// A list of impl trait decls.
pub type ImplTraitDecls = Vec<ImplDef>;
/// A list of predicates.
pub struct GenericPredicates {
pub parent: Option<TraitDef>,
pub predicates: Vec<(PredicateKind, Span)>,
}
/// Holds information about a crate.
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct Crate {
@ -101,6 +109,10 @@ pub fn trait_impl(trait_impl: &ImplDef) -> ImplTrait {
with(|cx| cx.trait_impl(trait_impl))
}
pub fn predicates_of(trait_def: &TraitDef) -> GenericPredicates {
with(|cx| cx.predicates_of(trait_def))
}
pub trait Context {
fn entry_fn(&mut self) -> Option<CrateItem>;
/// Retrieve all items of the local crate that have a MIR associated with them.
@ -111,6 +123,7 @@ pub trait Context {
fn all_trait_impls(&mut self) -> ImplTraitDecls;
fn trait_impl(&mut self, trait_impl: &ImplDef) -> ImplTrait;
fn generics_of(&mut self, generic_def: &GenericDef) -> Generics;
fn predicates_of(&mut self, trait_def: &TraitDef) -> GenericPredicates;
/// Get information about the local crate.
fn local_crate(&self) -> Crate;
/// Retrieve a list of all external crates.

View File

@ -22,7 +22,7 @@ pub struct Const {
type Ident = Opaque;
pub(crate) type Region = Opaque;
pub type Span = Opaque;
pub(crate) type Span = Opaque;
#[derive(Clone, Debug)]
pub enum TyKind {