Skip to content

Commit 768e7a2

Browse files
committed
Track FnDef information in databases
1 parent 9bce539 commit 768e7a2

File tree

4 files changed

+42
-7
lines changed

4 files changed

+42
-7
lines changed

chalk-integration/src/db.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use chalk_ir::AssocTypeId;
1010
use chalk_ir::Canonical;
1111
use chalk_ir::ConstrainedSubst;
1212
use chalk_ir::Environment;
13+
use chalk_ir::FnDefId;
1314
use chalk_ir::GenericArg;
1415
use chalk_ir::Goal;
1516
use chalk_ir::ImplId;
@@ -22,6 +23,7 @@ use chalk_rust_ir::AdtDatum;
2223
use chalk_rust_ir::AssociatedTyDatum;
2324
use chalk_rust_ir::AssociatedTyValue;
2425
use chalk_rust_ir::AssociatedTyValueId;
26+
use chalk_rust_ir::FnDefDatum;
2527
use chalk_rust_ir::ImplDatum;
2628
use chalk_rust_ir::OpaqueTyDatum;
2729
use chalk_rust_ir::TraitDatum;
@@ -114,6 +116,10 @@ impl RustIrDatabase<ChalkIr> for ChalkDatabase {
114116
self.program_ir().unwrap().adt_datum(id)
115117
}
116118

119+
fn fn_def_datum(&self, id: FnDefId<ChalkIr>) -> Arc<FnDefDatum<ChalkIr>> {
120+
self.program_ir().unwrap().fn_def_datum(id)
121+
}
122+
117123
fn impls_for_trait(
118124
&self,
119125
trait_id: TraitId<ChalkIr>,

chalk-integration/src/program.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ use crate::{tls, Identifier, TypeKind};
33
use chalk_ir::could_match::CouldMatch;
44
use chalk_ir::debug::Angle;
55
use chalk_ir::{
6-
debug::SeparatorTraitRef, AdtId, AliasTy, ApplicationTy, AssocTypeId, GenericArg, Goal, Goals,
7-
ImplId, Lifetime, OpaqueTy, OpaqueTyId, ProgramClause, ProgramClauseImplication,
6+
debug::SeparatorTraitRef, AdtId, AliasTy, ApplicationTy, AssocTypeId, FnDefId, GenericArg,
7+
Goal, Goals, ImplId, Lifetime, OpaqueTy, OpaqueTyId, ProgramClause, ProgramClauseImplication,
88
ProgramClauses, ProjectionTy, Substitution, TraitId, Ty,
99
};
1010
use chalk_rust_ir::{
11-
AdtDatum, AssociatedTyDatum, AssociatedTyValue, AssociatedTyValueId, ImplDatum, ImplType,
12-
OpaqueTyDatum, TraitDatum, WellKnownTrait,
11+
AdtDatum, AssociatedTyDatum, AssociatedTyValue, AssociatedTyValueId, FnDefDatum, ImplDatum,
12+
ImplType, OpaqueTyDatum, TraitDatum, WellKnownTrait,
1313
};
1414
use chalk_solve::split::Split;
1515
use chalk_solve::RustIrDatabase;
@@ -25,6 +25,10 @@ pub struct Program {
2525
/// For each ADT:
2626
pub adt_kinds: BTreeMap<AdtId<ChalkIr>, TypeKind>,
2727

28+
pub fn_def_ids: BTreeMap<Identifier, FnDefId<ChalkIr>>,
29+
30+
pub fn_def_kinds: BTreeMap<FnDefId<ChalkIr>, TypeKind>,
31+
2832
/// From trait name to item-id. Used during lowering only.
2933
pub trait_ids: BTreeMap<Identifier, TraitId<ChalkIr>>,
3034

@@ -34,6 +38,8 @@ pub struct Program {
3438
/// For each ADT:
3539
pub adt_data: BTreeMap<AdtId<ChalkIr>, Arc<AdtDatum<ChalkIr>>>,
3640

41+
pub fn_def_data: BTreeMap<FnDefId<ChalkIr>, Arc<FnDefDatum<ChalkIr>>>,
42+
3743
/// For each impl:
3844
pub impl_data: BTreeMap<ImplId<ChalkIr>, Arc<ImplDatum<ChalkIr>>>,
3945

@@ -334,6 +340,10 @@ impl RustIrDatabase<ChalkIr> for Program {
334340
self.adt_data[&id].clone()
335341
}
336342

343+
fn fn_def_datum(&self, id: FnDefId<ChalkIr>) -> Arc<FnDefDatum<ChalkIr>> {
344+
self.fn_def_data[&id].clone()
345+
}
346+
337347
fn impls_for_trait(
338348
&self,
339349
trait_id: TraitId<ChalkIr>,

chalk-rust-ir/src/lib.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ use chalk_ir::cast::Cast;
99
use chalk_ir::fold::shift::Shift;
1010
use chalk_ir::interner::{Interner, TargetInterner};
1111
use chalk_ir::{
12-
AdtId, AliasEq, AliasTy, AssocTypeId, Binders, DebruijnIndex, GenericArg, ImplId, OpaqueTyId,
13-
ProjectionTy, QuantifiedWhereClause, Substitution, ToGenericArg, TraitId, TraitRef, Ty, TyData,
14-
TypeName, VariableKind, WhereClause, WithKind,
12+
AdtId, AliasEq, AliasTy, AssocTypeId, Binders, DebruijnIndex, FnDefId, GenericArg, ImplId,
13+
OpaqueTyId, ProjectionTy, QuantifiedWhereClause, Substitution, ToGenericArg, TraitId, TraitRef,
14+
Ty, TyData, TypeName, VariableKind, WhereClause, WithKind,
1515
};
1616
use std::iter;
1717

@@ -103,6 +103,23 @@ pub struct AdtFlags {
103103
pub fundamental: bool,
104104
}
105105

106+
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
107+
pub struct FnDefDatum<I: Interner> {
108+
pub id: FnDefId<I>,
109+
pub binders: Binders<FnDefDatumBound<I>>,
110+
pub flags: FnDefFlags,
111+
}
112+
113+
#[derive(Clone, Debug, PartialEq, Eq, Hash, Fold, HasInterner)]
114+
pub struct FnDefDatumBound<I: Interner> {
115+
pub argument_types: Vec<Ty<I>>,
116+
pub return_type: Ty<I>,
117+
pub where_clauses: Vec<QuantifiedWhereClause<I>>,
118+
}
119+
120+
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
121+
pub struct FnDefFlags {}
122+
106123
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
107124
/// A rust intermediate representation (rust_ir) of a Trait Definition. For
108125
/// example, given the following rust code:

chalk-solve/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ pub trait RustIrDatabase<I: Interner>: Debug {
3838
/// Returns the datum for the impl with the given id.
3939
fn adt_datum(&self, adt_id: AdtId<I>) -> Arc<AdtDatum<I>>;
4040

41+
fn fn_def_datum(&self, fn_def_id: FnDefId<I>) -> Arc<FnDefDatum<I>>;
42+
4143
/// Returns the datum for the impl with the given id.
4244
fn impl_datum(&self, impl_id: ImplId<I>) -> Arc<ImplDatum<I>>;
4345

0 commit comments

Comments
 (0)