Skip to content

Commit 107cb5c

Browse files
ericmarkmartinspastorino
authored andcommitted
predicates of
1 parent 735e9c0 commit 107cb5c

File tree

3 files changed

+43
-12
lines changed

3 files changed

+43
-12
lines changed

compiler/rustc_smir/src/rustc_smir/mod.rs

+28-10
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,23 @@ impl<'tcx> Context for Tables<'tcx> {
108108
let generic_def = self.tcx.generics_of(def_id);
109109
generic_def.stable(self)
110110
}
111+
112+
fn predicates_of(
113+
&mut self,
114+
trait_def: &stable_mir::ty::TraitDef,
115+
) -> stable_mir::GenericPredicates {
116+
let trait_def_id = self.trait_def_id(trait_def);
117+
let ty::GenericPredicates { parent, predicates } = self.tcx.predicates_of(trait_def_id);
118+
stable_mir::GenericPredicates {
119+
parent: parent.map(|did| self.trait_def(did)),
120+
predicates: predicates
121+
.iter()
122+
.map(|(clause, span)| {
123+
(clause.as_predicate().kind().skip_binder().stable(self), span.stable(self))
124+
})
125+
.collect(),
126+
}
127+
}
111128
}
112129

113130
pub struct Tables<'tcx> {
@@ -947,12 +964,12 @@ impl<'tcx> Stable<'tcx> for ty::BoundTyKind {
947964
impl<'tcx> Stable<'tcx> for ty::BoundRegionKind {
948965
type T = stable_mir::ty::BoundRegionKind;
949966

950-
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
967+
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
951968
use stable_mir::ty::BoundRegionKind;
952969

953970
match self {
954971
ty::BoundRegionKind::BrAnon(option_span) => {
955-
BoundRegionKind::BrAnon(option_span.map(|span| opaque(&span)))
972+
BoundRegionKind::BrAnon(option_span.map(|span| span.stable(tables)))
956973
}
957974
ty::BoundRegionKind::BrNamed(def_id, symbol) => {
958975
BoundRegionKind::BrNamed(rustc_internal::br_named_def(*def_id), symbol.to_string())
@@ -1242,14 +1259,6 @@ impl<'tcx> Stable<'tcx> for ty::Generics {
12421259
}
12431260
}
12441261

1245-
impl<'tcx> Stable<'tcx> for rustc_span::Span {
1246-
type T = stable_mir::ty::Span;
1247-
1248-
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
1249-
opaque(self)
1250-
}
1251-
}
1252-
12531262
impl<'tcx> Stable<'tcx> for rustc_middle::ty::GenericParamDefKind {
12541263
type T = stable_mir::ty::GenericParamDefKind;
12551264

@@ -1456,3 +1465,12 @@ impl<'tcx> Stable<'tcx> for ty::Region<'tcx> {
14561465
opaque(self)
14571466
}
14581467
}
1468+
1469+
impl<'tcx> Stable<'tcx> for rustc_span::Span {
1470+
type T = stable_mir::ty::Span;
1471+
1472+
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
1473+
// FIXME: add a real implementation of stable spans
1474+
opaque(self)
1475+
}
1476+
}

compiler/rustc_smir/src/stable_mir/mod.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ use std::cell::Cell;
1515

1616
use crate::rustc_smir::Tables;
1717

18-
use self::ty::{GenericDef, Generics, ImplDef, ImplTrait, TraitDecl, TraitDef, Ty, TyKind};
18+
use self::ty::{
19+
GenericDef, Generics, ImplDef, ImplTrait, PredicateKind, Span, TraitDecl, TraitDef, Ty, TyKind,
20+
};
1921

2022
pub mod mir;
2123
pub mod ty;
@@ -38,6 +40,12 @@ pub type TraitDecls = Vec<TraitDef>;
3840
/// A list of impl trait decls.
3941
pub type ImplTraitDecls = Vec<ImplDef>;
4042

43+
/// A list of predicates.
44+
pub struct GenericPredicates {
45+
pub parent: Option<TraitDef>,
46+
pub predicates: Vec<(PredicateKind, Span)>,
47+
}
48+
4149
/// Holds information about a crate.
4250
#[derive(Clone, PartialEq, Eq, Debug)]
4351
pub struct Crate {
@@ -101,6 +109,10 @@ pub fn trait_impl(trait_impl: &ImplDef) -> ImplTrait {
101109
with(|cx| cx.trait_impl(trait_impl))
102110
}
103111

112+
pub fn predicates_of(trait_def: &TraitDef) -> GenericPredicates {
113+
with(|cx| cx.predicates_of(trait_def))
114+
}
115+
104116
pub trait Context {
105117
fn entry_fn(&mut self) -> Option<CrateItem>;
106118
/// Retrieve all items of the local crate that have a MIR associated with them.
@@ -111,6 +123,7 @@ pub trait Context {
111123
fn all_trait_impls(&mut self) -> ImplTraitDecls;
112124
fn trait_impl(&mut self, trait_impl: &ImplDef) -> ImplTrait;
113125
fn generics_of(&mut self, generic_def: &GenericDef) -> Generics;
126+
fn predicates_of(&mut self, trait_def: &TraitDef) -> GenericPredicates;
114127
/// Get information about the local crate.
115128
fn local_crate(&self) -> Crate;
116129
/// Retrieve a list of all external crates.

compiler/rustc_smir/src/stable_mir/ty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub struct Const {
2222

2323
type Ident = Opaque;
2424
pub(crate) type Region = Opaque;
25-
pub type Span = Opaque;
25+
pub(crate) type Span = Opaque;
2626

2727
#[derive(Clone, Debug)]
2828
pub enum TyKind {

0 commit comments

Comments
 (0)