Skip to content

Commit f369cd1

Browse files
committed
Add interning for parameter kinds.
1 parent f438d7e commit f369cd1

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

chalk-ir/src/interner.rs

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::OpaqueTy;
1010
use crate::OpaqueTyId;
1111
use crate::Parameter;
1212
use crate::ParameterData;
13+
use crate::ParameterKind;
1314
use crate::ProgramClause;
1415
use crate::ProgramClauseData;
1516
use crate::ProgramClauseImplication;
@@ -23,6 +24,7 @@ use crate::Substitution;
2324
use crate::TraitId;
2425
use crate::Ty;
2526
use crate::TyData;
27+
use crate::UniverseIndex;
2628
use chalk_engine::context::Context;
2729
use chalk_engine::ExClause;
2830
use std::fmt::{self, Debug};
@@ -126,6 +128,23 @@ pub trait Interner: Debug + Copy + Eq + Ord + Hash {
126128
/// and can be converted back to its underlying data via `quantified_where_clauses_data`.
127129
type InternedQuantifiedWhereClauses: Debug + Clone + Eq + Hash;
128130

131+
/// "Interned" representation of a list of parameter kind.
132+
/// In normal user code, `Self::InternedParameterKinds` is not referenced.
133+
/// Instead, we refer to `ParameterKinds<Self>`, which wraps this type.
134+
///
135+
/// An `InternedParameterKinds` is created by `intern_parameter_kinds`
136+
/// and can be converted back to its underlying data via `parameter_kinds_data`.
137+
type InternedParameterKinds: Debug + Clone + Eq + Hash;
138+
139+
/// "Interned" representation of a list of parameter kind with universe index.
140+
/// In normal user code, `Self::InternedParameterKindsWithUniverseIndex` is not referenced.
141+
/// Instead, we refer to `ParameterKindsWithUniverseIndex<Self>`, which wraps this type.
142+
///
143+
/// An `InternedParameterKindsWithUniverseIndex` is created by
144+
/// `intern_parameter_kinds_with_universe_index` and can be converted back
145+
/// to its underlying data via `parameter_kinds_with_universe_index_data`.
146+
type InternedParameterKindsWithUniverseIndex: Debug + Clone + Eq + Hash;
147+
129148
/// The core "id" type used for struct-ids and the like.
130149
type DefId: Debug + Copy + Eq + Ord + Hash;
131150

@@ -493,6 +512,38 @@ pub trait Interner: Debug + Copy + Eq + Ord + Hash {
493512
&self,
494513
clauses: &'a Self::InternedQuantifiedWhereClauses,
495514
) -> &'a [QuantifiedWhereClause<Self>];
515+
516+
/// Create an "interned" parameter kinds from `data`. This is not
517+
/// normally invoked directly; instead, you invoke
518+
/// `ParameterKinds::from` (which will ultimately call this
519+
/// method).
520+
fn intern_parameter_kinds(
521+
&self,
522+
data: impl IntoIterator<Item = ParameterKind<()>>,
523+
) -> Self::InternedParameterKinds;
524+
525+
/// Lookup the slice of `ParameterKind` that was interned to
526+
/// create a `ParameterKinds`.
527+
fn parameter_kinds_data<'a>(
528+
&self,
529+
parameter_kinds: &'a Self::InternedParameterKinds,
530+
) -> &'a [ParameterKind<()>];
531+
532+
/// Create an "interned" parameter kinds with universe index from `data`. This is not
533+
/// normally invoked directly; instead, you invoke
534+
/// `ParameterKindsWithUniverseIndex::from` (which will ultimately call this
535+
/// method).
536+
fn intern_parameter_kinds_with_universe_index(
537+
&self,
538+
data: impl IntoIterator<Item = ParameterKind<UniverseIndex>>,
539+
) -> Self::InternedParameterKindsWithUniverseIndex;
540+
541+
/// Lookup the slice of `ParameterKind` that was interned to
542+
/// create a `ParameterKinds`.
543+
fn parameter_kinds_with_universe_index_data<'a>(
544+
&self,
545+
parameter_kinds_with_universe_index: &'a Self::InternedParameterKindsWithUniverseIndex,
546+
) -> &'a [ParameterKind<UniverseIndex>];
496547
}
497548

498549
pub trait TargetInterner<I: Interner>: Interner {
@@ -550,6 +601,8 @@ mod default {
550601
type InternedProgramClause = ProgramClauseData<ChalkIr>;
551602
type InternedProgramClauses = Vec<ProgramClause<ChalkIr>>;
552603
type InternedQuantifiedWhereClauses = Vec<QuantifiedWhereClause<ChalkIr>>;
604+
type InternedParameterKinds = Vec<ParameterKind<()>>;
605+
type InternedParameterKindsWithUniverseIndex = Vec<ParameterKind<UniverseIndex>>;
553606
type DefId = RawId;
554607
type Identifier = Identifier;
555608

@@ -786,6 +839,30 @@ mod default {
786839
) -> &'a [QuantifiedWhereClause<Self>] {
787840
clauses
788841
}
842+
fn intern_parameter_kinds(
843+
&self,
844+
data: impl IntoIterator<Item = ParameterKind<()>>,
845+
) -> Self::InternedParameterKinds {
846+
data.into_iter().collect()
847+
}
848+
fn parameter_kinds_data<'a>(
849+
&self,
850+
parameter_kinds: &'a Self::InternedParameterKinds,
851+
) -> &'a [ParameterKind<()>] {
852+
parameter_kinds
853+
}
854+
fn intern_parameter_kinds_with_universe_index(
855+
&self,
856+
data: impl IntoIterator<Item = ParameterKind<UniverseIndex>>,
857+
) -> Self::InternedParameterKindsWithUniverseIndex {
858+
data.into_iter().collect()
859+
}
860+
fn parameter_kinds_with_universe_index_data<'a>(
861+
&self,
862+
parameter_kinds_with_universe_index: &'a Self::InternedParameterKindsWithUniverseIndex,
863+
) -> &'a [ParameterKind<UniverseIndex>] {
864+
parameter_kinds_with_universe_index
865+
}
789866
}
790867

791868
impl HasInterner for ChalkIr {

0 commit comments

Comments
 (0)