1 //! Encapsulates the concrete representation of core types such as types and goals. 2 use crate::AliasTy; 3 use crate::AssocTypeId; 4 use crate::CanonicalVarKind; 5 use crate::CanonicalVarKinds; 6 use crate::ClosureId; 7 use crate::Constraint; 8 use crate::Constraints; 9 use crate::FnDefId; 10 use crate::ForeignDefId; 11 use crate::GeneratorId; 12 use crate::GenericArg; 13 use crate::GenericArgData; 14 use crate::Goal; 15 use crate::GoalData; 16 use crate::Goals; 17 use crate::InEnvironment; 18 use crate::Lifetime; 19 use crate::LifetimeData; 20 use crate::OpaqueTy; 21 use crate::OpaqueTyId; 22 use crate::ProgramClause; 23 use crate::ProgramClauseData; 24 use crate::ProgramClauseImplication; 25 use crate::ProgramClauses; 26 use crate::ProjectionTy; 27 use crate::QuantifiedWhereClause; 28 use crate::QuantifiedWhereClauses; 29 use crate::SeparatorTraitRef; 30 use crate::Substitution; 31 use crate::TraitId; 32 use crate::Ty; 33 use crate::TyData; 34 use crate::VariableKind; 35 use crate::VariableKinds; 36 use crate::Variance; 37 use crate::Variances; 38 use crate::{AdtId, TyKind}; 39 use crate::{Const, ConstData}; 40 use std::fmt::{self, Debug}; 41 use std::hash::Hash; 42 use std::marker::PhantomData; 43 use std::sync::Arc; 44 45 /// A "interner" encapsulates the concrete representation of 46 /// certain "core types" from chalk-ir. All the types in chalk-ir are 47 /// parameterized by a `I: Interner`, and so (e.g.) if they want to 48 /// store a type, they don't store a `Ty<I>` instance directly, but 49 /// rather prefer a `Ty<I>`. You can think of `I::Type` as the 50 /// interned representation (and, indeed, it may well be an interned 51 /// pointer, e.g. in rustc). 52 /// 53 /// Type families allow chalk to be embedded in different contexts 54 /// where the concrete representation of core types varies. They also 55 /// allow us to write generic code that reasons about multiple 56 /// distinct sets of types by using distinct generic type parameters 57 /// (e.g., `SourceI` and `TargetI`) -- even if those type parameters 58 /// wind up being mapped to the same underlying type families in the 59 /// end. 60 pub trait Interner: Debug + Copy + Eq + Ord + Hash + Sized { 61 /// "Interned" representation of types. In normal user code, 62 /// `Self::InternedType` is not referenced. Instead, we refer to 63 /// `Ty<Self>`, which wraps this type. 64 /// 65 /// An `InternedType` must be something that can be created from a 66 /// `TyKind` (by the [`intern_ty`][Self::intern_ty] method) and then later 67 /// converted back (by the [`ty_data`][Self::ty_data] method). The interned form 68 /// must also introduce indirection, either via a `Box`, `&`, or 69 /// other pointer type. 70 type InternedType: Debug + Clone + Eq + Hash; 71 72 /// "Interned" representation of lifetimes. In normal user code, 73 /// `Self::InternedLifetime` is not referenced. Instead, we refer to 74 /// `Lifetime<Self>`, which wraps this type. 75 /// 76 /// An `InternedLifetime` must be something that can be created 77 /// from a `LifetimeData` (by the [`intern_lifetime`][Self::intern_lifetime] method) and 78 /// then later converted back (by the [`lifetime_data`][Self::lifetime_data] method). 79 type InternedLifetime: Debug + Clone + Eq + Hash; 80 81 /// "Interned" representation of const expressions. In normal user code, 82 /// `Self::InternedConst` is not referenced. Instead, we refer to 83 /// `Const<Self>`, which wraps this type. 84 /// 85 /// An `InternedConst` must be something that can be created 86 /// from a `ConstData` (by the [`intern_const`][Self::intern_const] method) and 87 /// then later converted back (by the [`const_data`][Self::const_data] method). 88 type InternedConst: Debug + Clone + Eq + Hash; 89 90 /// "Interned" representation of an evaluated const value. 91 /// `Self::InternedConcreteConst` is not referenced. Instead, 92 /// we refer to `ConcreteConst<Self>`, which wraps this type. 93 /// 94 /// `InternedConcreteConst` instances are not created by chalk, 95 /// it can only make a query asking about equality of two 96 /// evaluated consts. 97 type InternedConcreteConst: Debug + Clone + Eq + Hash; 98 99 /// "Interned" representation of a "generic parameter", which can 100 /// be either a type or a lifetime. In normal user code, 101 /// `Self::InternedGenericArg` is not referenced. Instead, we refer to 102 /// `GenericArg<Self>`, which wraps this type. 103 /// 104 /// An `InternedType` is created by `intern_generic_arg` and can be 105 /// converted back to its underlying data via `generic_arg_data`. 106 type InternedGenericArg: Debug + Clone + Eq + Hash; 107 108 /// "Interned" representation of a "goal". In normal user code, 109 /// `Self::InternedGoal` is not referenced. Instead, we refer to 110 /// `Goal<Self>`, which wraps this type. 111 /// 112 /// An `InternedGoal` is created by `intern_goal` and can be 113 /// converted back to its underlying data via `goal_data`. 114 type InternedGoal: Debug + Clone + Eq + Hash; 115 116 /// "Interned" representation of a list of goals. In normal user code, 117 /// `Self::InternedGoals` is not referenced. Instead, we refer to 118 /// `Goals<Self>`, which wraps this type. 119 /// 120 /// An `InternedGoals` is created by `intern_goals` and can be 121 /// converted back to its underlying data via `goals_data`. 122 type InternedGoals: Debug + Clone + Eq + Hash; 123 124 /// "Interned" representation of a "substitution". In normal user code, 125 /// `Self::InternedSubstitution` is not referenced. Instead, we refer to 126 /// `Substitution<Self>`, which wraps this type. 127 /// 128 /// An `InternedSubstitution` is created by `intern_substitution` and can be 129 /// converted back to its underlying data via `substitution_data`. 130 type InternedSubstitution: Debug + Clone + Eq + Hash; 131 132 /// "Interned" representation of a list of program clauses. In normal user code, 133 /// `Self::InternedProgramClauses` is not referenced. Instead, we refer to 134 /// `ProgramClauses<Self>`, which wraps this type. 135 /// 136 /// An `InternedProgramClauses` is created by `intern_program_clauses` and can be 137 /// converted back to its underlying data via `program_clauses_data`. 138 type InternedProgramClauses: Debug + Clone + Eq + Hash; 139 140 /// "Interned" representation of a "program clause". In normal user code, 141 /// `Self::InternedProgramClause` is not referenced. Instead, we refer to 142 /// `ProgramClause<Self>`, which wraps this type. 143 /// 144 /// An `InternedProgramClause` is created by `intern_program_clause` and can be 145 /// converted back to its underlying data via `program_clause_data`. 146 type InternedProgramClause: Debug + Clone + Eq + Hash; 147 148 /// "Interned" representation of a list of quantified where clauses. 149 /// In normal user code, `Self::InternedQuantifiedWhereClauses` is not referenced. 150 /// Instead, we refer to `QuantifiedWhereClauses<Self>`, which wraps this type. 151 /// 152 /// An `InternedQuantifiedWhereClauses` is created by `intern_quantified_where_clauses` 153 /// and can be converted back to its underlying data via `quantified_where_clauses_data`. 154 type InternedQuantifiedWhereClauses: Debug + Clone + Eq + Hash; 155 156 /// "Interned" representation of a list of variable kinds. 157 /// In normal user code, `Self::InternedVariableKinds` is not referenced. 158 /// Instead, we refer to `VariableKinds<Self>`, which wraps this type. 159 /// 160 /// An `InternedVariableKinds` is created by `intern_generic_arg_kinds` 161 /// and can be converted back to its underlying data via `variable_kinds_data`. 162 type InternedVariableKinds: Debug + Clone + Eq + Hash; 163 164 /// "Interned" representation of a list of variable kinds with universe index. 165 /// In normal user code, `Self::InternedCanonicalVarKinds` is not referenced. 166 /// Instead, we refer to `CanonicalVarKinds<Self>`, which wraps this type. 167 /// 168 /// An `InternedCanonicalVarKinds` is created by 169 /// `intern_canonical_var_kinds` and can be converted back 170 /// to its underlying data via `canonical_var_kinds_data`. 171 type InternedCanonicalVarKinds: Debug + Clone + Eq + Hash; 172 173 /// "Interned" representation of a list of region constraints. 174 /// In normal user code, `Self::InternedConstraints` is not referenced. 175 /// Instead, we refer to `Constraints<Self>`, which wraps this type. 176 /// 177 /// An `InternedConstraints` is created by `intern_constraints` 178 /// and can be converted back to its underlying data via `constraints_data`. 179 type InternedConstraints: Debug + Clone + Eq + Hash; 180 181 /// "Interned" representation of a list of `chalk_ir::Variance`. 182 /// In normal user code, `Self::InternedVariances` is not referenced. 183 /// Instead, we refer to `Variances<Self>`, which wraps this type. 184 /// 185 /// An `InternedVariances` is created by 186 /// `intern_variances` and can be converted back 187 /// to its underlying data via `variances_data`. 188 type InternedVariances: Debug + Clone + Eq + Hash; 189 190 /// The core "id" type used for trait-ids and the like. 191 type DefId: Debug + Copy + Eq + Ord + Hash; 192 193 /// The ID type for ADTs 194 type InternedAdtId: Debug + Copy + Eq + Ord + Hash; 195 196 /// Representation of identifiers. 197 type Identifier: Debug + Clone + Eq + Hash; 198 199 /// Representation of function ABI (e.g. calling convention). 200 type FnAbi: Debug + Copy + Eq + Hash; 201 202 /// Prints the debug representation of a type-kind-id. 203 /// Returns `None` to fallback to the default debug output. 204 #[allow(unused_variables)] debug_adt_id(adt_id: AdtId<Self>, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result>205 fn debug_adt_id(adt_id: AdtId<Self>, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> { 206 None 207 } 208 209 /// Prints the debug representation of a type-kind-id. 210 /// Returns `None` to fallback to the default debug output (e.g., 211 /// if no info about current program is available from TLS). 212 #[allow(unused_variables)] debug_trait_id( trait_id: TraitId<Self>, fmt: &mut fmt::Formatter<'_>, ) -> Option<fmt::Result>213 fn debug_trait_id( 214 trait_id: TraitId<Self>, 215 fmt: &mut fmt::Formatter<'_>, 216 ) -> Option<fmt::Result> { 217 None 218 } 219 220 /// Prints the debug representation of a type-kind-id. 221 /// Returns `None` to fallback to the default debug output. 222 #[allow(unused_variables)] debug_assoc_type_id( type_id: AssocTypeId<Self>, fmt: &mut fmt::Formatter<'_>, ) -> Option<fmt::Result>223 fn debug_assoc_type_id( 224 type_id: AssocTypeId<Self>, 225 fmt: &mut fmt::Formatter<'_>, 226 ) -> Option<fmt::Result> { 227 None 228 } 229 230 /// Prints the debug representation of an opaque type. 231 /// Returns `None` to fallback to the default debug output. 232 #[allow(unused_variables)] debug_opaque_ty_id( opaque_ty_id: OpaqueTyId<Self>, fmt: &mut fmt::Formatter<'_>, ) -> Option<fmt::Result>233 fn debug_opaque_ty_id( 234 opaque_ty_id: OpaqueTyId<Self>, 235 fmt: &mut fmt::Formatter<'_>, 236 ) -> Option<fmt::Result> { 237 None 238 } 239 240 /// Prints the debug representation of a function-def-id. 241 /// Returns `None` to fallback to the default debug output. 242 #[allow(unused_variables)] debug_fn_def_id( fn_def_id: FnDefId<Self>, fmt: &mut fmt::Formatter<'_>, ) -> Option<fmt::Result>243 fn debug_fn_def_id( 244 fn_def_id: FnDefId<Self>, 245 fmt: &mut fmt::Formatter<'_>, 246 ) -> Option<fmt::Result> { 247 None 248 } 249 250 /// Prints the debug representation of a closure id. 251 /// Returns `None` to fallback to the default debug output. 252 #[allow(unused_variables)] debug_closure_id( fn_def_id: ClosureId<Self>, fmt: &mut fmt::Formatter<'_>, ) -> Option<fmt::Result>253 fn debug_closure_id( 254 fn_def_id: ClosureId<Self>, 255 fmt: &mut fmt::Formatter<'_>, 256 ) -> Option<fmt::Result> { 257 None 258 } 259 260 /// Prints the debug representation of a foreign-def-id. 261 /// Returns `None` to fallback to the default debug output. 262 #[allow(unused_variables)] debug_foreign_def_id( foreign_def_id: ForeignDefId<Self>, fmt: &mut fmt::Formatter<'_>, ) -> Option<fmt::Result>263 fn debug_foreign_def_id( 264 foreign_def_id: ForeignDefId<Self>, 265 fmt: &mut fmt::Formatter<'_>, 266 ) -> Option<fmt::Result> { 267 None 268 } 269 270 /// Prints the debug representation of an alias. 271 /// Returns `None` to fallback to the default debug output. 272 #[allow(unused_variables)] debug_generator_id( generator_id: GeneratorId<Self>, fmt: &mut fmt::Formatter<'_>, ) -> Option<fmt::Result>273 fn debug_generator_id( 274 generator_id: GeneratorId<Self>, 275 fmt: &mut fmt::Formatter<'_>, 276 ) -> Option<fmt::Result> { 277 None 278 } 279 280 /// Prints the debug representation of an alias. To get good 281 /// results, this requires inspecting TLS, and is difficult to 282 /// code without reference to a specific interner (and hence 283 /// fully known types). 284 /// 285 /// Returns `None` to fallback to the default debug output (e.g., 286 /// if no info about current program is available from TLS). 287 #[allow(unused_variables)] debug_alias(alias: &AliasTy<Self>, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result>288 fn debug_alias(alias: &AliasTy<Self>, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> { 289 None 290 } 291 292 /// Prints the debug representation of a ProjectionTy. 293 /// Returns `None` to fallback to the default debug output. 294 #[allow(unused_variables)] debug_projection_ty( projection_ty: &ProjectionTy<Self>, fmt: &mut fmt::Formatter<'_>, ) -> Option<fmt::Result>295 fn debug_projection_ty( 296 projection_ty: &ProjectionTy<Self>, 297 fmt: &mut fmt::Formatter<'_>, 298 ) -> Option<fmt::Result> { 299 None 300 } 301 302 /// Prints the debug representation of an OpaqueTy. 303 /// Returns `None` to fallback to the default debug output. 304 #[allow(unused_variables)] debug_opaque_ty( opaque_ty: &OpaqueTy<Self>, fmt: &mut fmt::Formatter<'_>, ) -> Option<fmt::Result>305 fn debug_opaque_ty( 306 opaque_ty: &OpaqueTy<Self>, 307 fmt: &mut fmt::Formatter<'_>, 308 ) -> Option<fmt::Result> { 309 None 310 } 311 312 /// Prints the debug representation of a type. 313 /// Returns `None` to fallback to the default debug output. 314 #[allow(unused_variables)] debug_ty(ty: &Ty<Self>, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result>315 fn debug_ty(ty: &Ty<Self>, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> { 316 None 317 } 318 319 /// Prints the debug representation of a lifetime. 320 /// Returns `None` to fallback to the default debug output. 321 #[allow(unused_variables)] debug_lifetime( lifetime: &Lifetime<Self>, fmt: &mut fmt::Formatter<'_>, ) -> Option<fmt::Result>322 fn debug_lifetime( 323 lifetime: &Lifetime<Self>, 324 fmt: &mut fmt::Formatter<'_>, 325 ) -> Option<fmt::Result> { 326 None 327 } 328 329 /// Prints the debug representation of a const. 330 /// Returns `None` to fallback to the default debug output. 331 #[allow(unused_variables)] debug_const(constant: &Const<Self>, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result>332 fn debug_const(constant: &Const<Self>, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> { 333 None 334 } 335 336 /// Prints the debug representation of an parameter. 337 /// Returns `None` to fallback to the default debug output. 338 #[allow(unused_variables)] debug_generic_arg( generic_arg: &GenericArg<Self>, fmt: &mut fmt::Formatter<'_>, ) -> Option<fmt::Result>339 fn debug_generic_arg( 340 generic_arg: &GenericArg<Self>, 341 fmt: &mut fmt::Formatter<'_>, 342 ) -> Option<fmt::Result> { 343 None 344 } 345 346 /// Prints the debug representation of a parameter kinds list. 347 /// Returns `None` to fallback to the default debug output. 348 #[allow(unused_variables)] debug_variable_kinds( variable_kinds: &VariableKinds<Self>, fmt: &mut fmt::Formatter<'_>, ) -> Option<fmt::Result>349 fn debug_variable_kinds( 350 variable_kinds: &VariableKinds<Self>, 351 fmt: &mut fmt::Formatter<'_>, 352 ) -> Option<fmt::Result> { 353 None 354 } 355 356 /// Prints the debug representation of a parameter kinds list, with angle brackets. 357 /// Returns `None` to fallback to the default debug output. 358 #[allow(unused_variables)] debug_variable_kinds_with_angles( variable_kinds: &VariableKinds<Self>, fmt: &mut fmt::Formatter<'_>, ) -> Option<fmt::Result>359 fn debug_variable_kinds_with_angles( 360 variable_kinds: &VariableKinds<Self>, 361 fmt: &mut fmt::Formatter<'_>, 362 ) -> Option<fmt::Result> { 363 None 364 } 365 366 /// Prints the debug representation of an parameter kinds list with universe index. 367 /// Returns `None` to fallback to the default debug output. 368 #[allow(unused_variables)] debug_canonical_var_kinds( canonical_var_kinds: &CanonicalVarKinds<Self>, fmt: &mut fmt::Formatter<'_>, ) -> Option<fmt::Result>369 fn debug_canonical_var_kinds( 370 canonical_var_kinds: &CanonicalVarKinds<Self>, 371 fmt: &mut fmt::Formatter<'_>, 372 ) -> Option<fmt::Result> { 373 None 374 } 375 376 /// Prints the debug representation of an goal. 377 /// Returns `None` to fallback to the default debug output. 378 #[allow(unused_variables)] debug_goal(goal: &Goal<Self>, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result>379 fn debug_goal(goal: &Goal<Self>, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> { 380 None 381 } 382 383 /// Prints the debug representation of a list of goals. 384 /// Returns `None` to fallback to the default debug output. 385 #[allow(unused_variables)] debug_goals(goals: &Goals<Self>, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result>386 fn debug_goals(goals: &Goals<Self>, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> { 387 None 388 } 389 390 /// Prints the debug representation of a ProgramClauseImplication. 391 /// Returns `None` to fallback to the default debug output. 392 #[allow(unused_variables)] debug_program_clause_implication( pci: &ProgramClauseImplication<Self>, fmt: &mut fmt::Formatter<'_>, ) -> Option<fmt::Result>393 fn debug_program_clause_implication( 394 pci: &ProgramClauseImplication<Self>, 395 fmt: &mut fmt::Formatter<'_>, 396 ) -> Option<fmt::Result> { 397 None 398 } 399 400 /// Prints the debug representation of a ProgramClause. 401 /// Returns `None` to fallback to the default debug output. 402 #[allow(unused_variables)] debug_program_clause( clause: &ProgramClause<Self>, fmt: &mut fmt::Formatter<'_>, ) -> Option<fmt::Result>403 fn debug_program_clause( 404 clause: &ProgramClause<Self>, 405 fmt: &mut fmt::Formatter<'_>, 406 ) -> Option<fmt::Result> { 407 None 408 } 409 410 /// Prints the debug representation of a ProgramClauses. 411 /// Returns `None` to fallback to the default debug output. 412 #[allow(unused_variables)] debug_program_clauses( clauses: &ProgramClauses<Self>, fmt: &mut fmt::Formatter<'_>, ) -> Option<fmt::Result>413 fn debug_program_clauses( 414 clauses: &ProgramClauses<Self>, 415 fmt: &mut fmt::Formatter<'_>, 416 ) -> Option<fmt::Result> { 417 None 418 } 419 420 /// Prints the debug representation of a Substitution. 421 /// Returns `None` to fallback to the default debug output. 422 #[allow(unused_variables)] debug_substitution( substitution: &Substitution<Self>, fmt: &mut fmt::Formatter<'_>, ) -> Option<fmt::Result>423 fn debug_substitution( 424 substitution: &Substitution<Self>, 425 fmt: &mut fmt::Formatter<'_>, 426 ) -> Option<fmt::Result> { 427 None 428 } 429 430 /// Prints the debug representation of a SeparatorTraitRef. 431 /// Returns `None` to fallback to the default debug output. 432 #[allow(unused_variables)] debug_separator_trait_ref( separator_trait_ref: &SeparatorTraitRef<'_, Self>, fmt: &mut fmt::Formatter<'_>, ) -> Option<fmt::Result>433 fn debug_separator_trait_ref( 434 separator_trait_ref: &SeparatorTraitRef<'_, Self>, 435 fmt: &mut fmt::Formatter<'_>, 436 ) -> Option<fmt::Result> { 437 None 438 } 439 440 /// Prints the debug representation of a QuantifiedWhereClauses. 441 /// Returns `None` to fallback to the default debug output. 442 #[allow(unused_variables)] debug_quantified_where_clauses( clauses: &QuantifiedWhereClauses<Self>, fmt: &mut fmt::Formatter<'_>, ) -> Option<fmt::Result>443 fn debug_quantified_where_clauses( 444 clauses: &QuantifiedWhereClauses<Self>, 445 fmt: &mut fmt::Formatter<'_>, 446 ) -> Option<fmt::Result> { 447 None 448 } 449 450 /// Prints the debug representation of a Constraints. 451 /// Returns `None` to fallback to the default debug output. 452 #[allow(unused_variables)] debug_constraints( clauses: &Constraints<Self>, fmt: &mut fmt::Formatter<'_>, ) -> Option<fmt::Result>453 fn debug_constraints( 454 clauses: &Constraints<Self>, 455 fmt: &mut fmt::Formatter<'_>, 456 ) -> Option<fmt::Result> { 457 None 458 } 459 460 /// Prints the debug representation of a Variances. 461 /// Returns `None` to fallback to the default debug output. 462 #[allow(unused_variables)] debug_variances( variances: &Variances<Self>, fmt: &mut fmt::Formatter<'_>, ) -> Option<fmt::Result>463 fn debug_variances( 464 variances: &Variances<Self>, 465 fmt: &mut fmt::Formatter<'_>, 466 ) -> Option<fmt::Result> { 467 None 468 } 469 470 /// Create an "interned" type from `ty`. This is not normally 471 /// invoked directly; instead, you invoke `TyKind::intern` (which 472 /// will ultimately call this method). intern_ty(self, kind: TyKind<Self>) -> Self::InternedType473 fn intern_ty(self, kind: TyKind<Self>) -> Self::InternedType; 474 475 /// Lookup the `TyKind` from an interned type. ty_data<'a>(self, ty: &'a Self::InternedType) -> &'a TyData<Self>476 fn ty_data<'a>(self, ty: &'a Self::InternedType) -> &'a TyData<Self>; 477 478 /// Create an "interned" lifetime from `lifetime`. This is not 479 /// normally invoked directly; instead, you invoke 480 /// `LifetimeData::intern` (which will ultimately call this 481 /// method). intern_lifetime(self, lifetime: LifetimeData<Self>) -> Self::InternedLifetime482 fn intern_lifetime(self, lifetime: LifetimeData<Self>) -> Self::InternedLifetime; 483 484 /// Lookup the `LifetimeData` that was interned to create a `InternedLifetime`. lifetime_data<'a>(self, lifetime: &'a Self::InternedLifetime) -> &'a LifetimeData<Self>485 fn lifetime_data<'a>(self, lifetime: &'a Self::InternedLifetime) -> &'a LifetimeData<Self>; 486 487 /// Create an "interned" const from `const`. This is not 488 /// normally invoked directly; instead, you invoke 489 /// `ConstData::intern` (which will ultimately call this 490 /// method). intern_const(self, constant: ConstData<Self>) -> Self::InternedConst491 fn intern_const(self, constant: ConstData<Self>) -> Self::InternedConst; 492 493 /// Lookup the `ConstData` that was interned to create a `InternedConst`. const_data<'a>(self, constant: &'a Self::InternedConst) -> &'a ConstData<Self>494 fn const_data<'a>(self, constant: &'a Self::InternedConst) -> &'a ConstData<Self>; 495 496 /// Determine whether two concrete const values are equal. const_eq( self, ty: &Self::InternedType, c1: &Self::InternedConcreteConst, c2: &Self::InternedConcreteConst, ) -> bool497 fn const_eq( 498 self, 499 ty: &Self::InternedType, 500 c1: &Self::InternedConcreteConst, 501 c2: &Self::InternedConcreteConst, 502 ) -> bool; 503 504 /// Create an "interned" parameter from `data`. This is not 505 /// normally invoked directly; instead, you invoke 506 /// `GenericArgData::intern` (which will ultimately call this 507 /// method). intern_generic_arg(self, data: GenericArgData<Self>) -> Self::InternedGenericArg508 fn intern_generic_arg(self, data: GenericArgData<Self>) -> Self::InternedGenericArg; 509 510 /// Lookup the `LifetimeData` that was interned to create a `InternedLifetime`. generic_arg_data<'a>( self, lifetime: &'a Self::InternedGenericArg, ) -> &'a GenericArgData<Self>511 fn generic_arg_data<'a>( 512 self, 513 lifetime: &'a Self::InternedGenericArg, 514 ) -> &'a GenericArgData<Self>; 515 516 /// Create an "interned" goal from `data`. This is not 517 /// normally invoked directly; instead, you invoke 518 /// `GoalData::intern` (which will ultimately call this 519 /// method). intern_goal(self, data: GoalData<Self>) -> Self::InternedGoal520 fn intern_goal(self, data: GoalData<Self>) -> Self::InternedGoal; 521 522 /// Lookup the `GoalData` that was interned to create a `InternedGoal`. goal_data<'a>(self, goal: &'a Self::InternedGoal) -> &'a GoalData<Self>523 fn goal_data<'a>(self, goal: &'a Self::InternedGoal) -> &'a GoalData<Self>; 524 525 /// Create an "interned" goals from `data`. This is not 526 /// normally invoked directly; instead, you invoke 527 /// `GoalsData::intern` (which will ultimately call this 528 /// method). intern_goals<E>( self, data: impl IntoIterator<Item = Result<Goal<Self>, E>>, ) -> Result<Self::InternedGoals, E>529 fn intern_goals<E>( 530 self, 531 data: impl IntoIterator<Item = Result<Goal<Self>, E>>, 532 ) -> Result<Self::InternedGoals, E>; 533 534 /// Lookup the `GoalsData` that was interned to create a `InternedGoals`. goals_data<'a>(self, goals: &'a Self::InternedGoals) -> &'a [Goal<Self>]535 fn goals_data<'a>(self, goals: &'a Self::InternedGoals) -> &'a [Goal<Self>]; 536 537 /// Create an "interned" substitution from `data`. This is not 538 /// normally invoked directly; instead, you invoke 539 /// `SubstitutionData::intern` (which will ultimately call this 540 /// method). intern_substitution<E>( self, data: impl IntoIterator<Item = Result<GenericArg<Self>, E>>, ) -> Result<Self::InternedSubstitution, E>541 fn intern_substitution<E>( 542 self, 543 data: impl IntoIterator<Item = Result<GenericArg<Self>, E>>, 544 ) -> Result<Self::InternedSubstitution, E>; 545 546 /// Lookup the `SubstitutionData` that was interned to create a `InternedSubstitution`. substitution_data<'a>( self, substitution: &'a Self::InternedSubstitution, ) -> &'a [GenericArg<Self>]547 fn substitution_data<'a>( 548 self, 549 substitution: &'a Self::InternedSubstitution, 550 ) -> &'a [GenericArg<Self>]; 551 552 /// Create an "interned" program clause from `data`. This is not 553 /// normally invoked directly; instead, you invoke 554 /// `ProgramClauseData::intern` (which will ultimately call this 555 /// method). intern_program_clause(self, data: ProgramClauseData<Self>) -> Self::InternedProgramClause556 fn intern_program_clause(self, data: ProgramClauseData<Self>) -> Self::InternedProgramClause; 557 558 /// Lookup the `ProgramClauseData` that was interned to create a `ProgramClause`. program_clause_data<'a>( self, clause: &'a Self::InternedProgramClause, ) -> &'a ProgramClauseData<Self>559 fn program_clause_data<'a>( 560 self, 561 clause: &'a Self::InternedProgramClause, 562 ) -> &'a ProgramClauseData<Self>; 563 564 /// Create an "interned" program clauses from `data`. This is not 565 /// normally invoked directly; instead, you invoke 566 /// `ProgramClauses::from_iter` (which will ultimately call this 567 /// method). intern_program_clauses<E>( self, data: impl IntoIterator<Item = Result<ProgramClause<Self>, E>>, ) -> Result<Self::InternedProgramClauses, E>568 fn intern_program_clauses<E>( 569 self, 570 data: impl IntoIterator<Item = Result<ProgramClause<Self>, E>>, 571 ) -> Result<Self::InternedProgramClauses, E>; 572 573 /// Lookup the `ProgramClauseData` that was interned to create a `ProgramClause`. program_clauses_data<'a>( self, clauses: &'a Self::InternedProgramClauses, ) -> &'a [ProgramClause<Self>]574 fn program_clauses_data<'a>( 575 self, 576 clauses: &'a Self::InternedProgramClauses, 577 ) -> &'a [ProgramClause<Self>]; 578 579 /// Create an "interned" quantified where clauses from `data`. This is not 580 /// normally invoked directly; instead, you invoke 581 /// `QuantifiedWhereClauses::from_iter` (which will ultimately call this 582 /// method). intern_quantified_where_clauses<E>( self, data: impl IntoIterator<Item = Result<QuantifiedWhereClause<Self>, E>>, ) -> Result<Self::InternedQuantifiedWhereClauses, E>583 fn intern_quantified_where_clauses<E>( 584 self, 585 data: impl IntoIterator<Item = Result<QuantifiedWhereClause<Self>, E>>, 586 ) -> Result<Self::InternedQuantifiedWhereClauses, E>; 587 588 /// Lookup the slice of `QuantifiedWhereClause` that was interned to 589 /// create a `QuantifiedWhereClauses`. quantified_where_clauses_data<'a>( self, clauses: &'a Self::InternedQuantifiedWhereClauses, ) -> &'a [QuantifiedWhereClause<Self>]590 fn quantified_where_clauses_data<'a>( 591 self, 592 clauses: &'a Self::InternedQuantifiedWhereClauses, 593 ) -> &'a [QuantifiedWhereClause<Self>]; 594 595 /// Create an "interned" parameter kinds from `data`. This is not 596 /// normally invoked directly; instead, you invoke 597 /// `VariableKinds::from_iter` (which will ultimately call this 598 /// method). intern_generic_arg_kinds<E>( self, data: impl IntoIterator<Item = Result<VariableKind<Self>, E>>, ) -> Result<Self::InternedVariableKinds, E>599 fn intern_generic_arg_kinds<E>( 600 self, 601 data: impl IntoIterator<Item = Result<VariableKind<Self>, E>>, 602 ) -> Result<Self::InternedVariableKinds, E>; 603 604 /// Lookup the slice of `VariableKinds` that was interned to 605 /// create a `VariableKinds`. variable_kinds_data<'a>( self, variable_kinds: &'a Self::InternedVariableKinds, ) -> &'a [VariableKind<Self>]606 fn variable_kinds_data<'a>( 607 self, 608 variable_kinds: &'a Self::InternedVariableKinds, 609 ) -> &'a [VariableKind<Self>]; 610 611 /// Create "interned" variable kinds with universe index from `data`. This is not 612 /// normally invoked directly; instead, you invoke 613 /// `CanonicalVarKinds::from_iter` (which will ultimately call this 614 /// method). intern_canonical_var_kinds<E>( self, data: impl IntoIterator<Item = Result<CanonicalVarKind<Self>, E>>, ) -> Result<Self::InternedCanonicalVarKinds, E>615 fn intern_canonical_var_kinds<E>( 616 self, 617 data: impl IntoIterator<Item = Result<CanonicalVarKind<Self>, E>>, 618 ) -> Result<Self::InternedCanonicalVarKinds, E>; 619 620 /// Lookup the slice of `CanonicalVariableKind` that was interned to 621 /// create a `CanonicalVariableKinds`. canonical_var_kinds_data<'a>( self, canonical_var_kinds: &'a Self::InternedCanonicalVarKinds, ) -> &'a [CanonicalVarKind<Self>]622 fn canonical_var_kinds_data<'a>( 623 self, 624 canonical_var_kinds: &'a Self::InternedCanonicalVarKinds, 625 ) -> &'a [CanonicalVarKind<Self>]; 626 627 /// Create "interned" constraints from `data`. This is not 628 /// normally invoked dirctly; instead, you invoke 629 /// `Constraints::from_iter` (which will ultimately call this 630 /// method). intern_constraints<E>( self, data: impl IntoIterator<Item = Result<InEnvironment<Constraint<Self>>, E>>, ) -> Result<Self::InternedConstraints, E>631 fn intern_constraints<E>( 632 self, 633 data: impl IntoIterator<Item = Result<InEnvironment<Constraint<Self>>, E>>, 634 ) -> Result<Self::InternedConstraints, E>; 635 636 /// Lookup the slice of `Constraint` that was interned to 637 /// create a `Constraints`. constraints_data<'a>( self, constraints: &'a Self::InternedConstraints, ) -> &'a [InEnvironment<Constraint<Self>>]638 fn constraints_data<'a>( 639 self, 640 constraints: &'a Self::InternedConstraints, 641 ) -> &'a [InEnvironment<Constraint<Self>>]; 642 643 /// Create "interned" variances from `data`. This is not 644 /// normally invoked directly; instead, you invoke 645 /// `Variances::from` (which will ultimately call this 646 /// method). intern_variances<E>( self, data: impl IntoIterator<Item = Result<Variance, E>>, ) -> Result<Self::InternedVariances, E>647 fn intern_variances<E>( 648 self, 649 data: impl IntoIterator<Item = Result<Variance, E>>, 650 ) -> Result<Self::InternedVariances, E>; 651 652 /// Lookup the slice of `Variance` that was interned to 653 /// create a `Variances`. variances_data<'a>(self, variances: &'a Self::InternedVariances) -> &'a [Variance]654 fn variances_data<'a>(self, variances: &'a Self::InternedVariances) -> &'a [Variance]; 655 } 656 657 /// Implemented by types that have an associated interner (which 658 /// are virtually all of the types in chalk-ir, for example). 659 /// This lets us map from a type like `Ty<I>` to the parameter `I`. 660 /// 661 /// It's particularly useful for writing `Fold` impls for generic types like 662 /// `Binder<T>`, since it allows us to figure out the interner of `T`. 663 pub trait HasInterner { 664 /// The interner associated with the type. 665 type Interner: Interner; 666 } 667 668 impl<T: HasInterner> HasInterner for [T] { 669 type Interner = T::Interner; 670 } 671 672 impl<T: HasInterner> HasInterner for Vec<T> { 673 type Interner = T::Interner; 674 } 675 676 impl<T: HasInterner> HasInterner for Box<T> { 677 type Interner = T::Interner; 678 } 679 680 impl<T: HasInterner> HasInterner for Arc<T> { 681 type Interner = T::Interner; 682 } 683 684 impl<T: HasInterner + ?Sized> HasInterner for &T { 685 type Interner = T::Interner; 686 } 687 688 impl<I: Interner> HasInterner for PhantomData<I> { 689 type Interner = I; 690 } 691 692 impl<A, B, I> HasInterner for (A, B) 693 where 694 A: HasInterner<Interner = I>, 695 B: HasInterner<Interner = I>, 696 I: Interner, 697 { 698 type Interner = I; 699 } 700 701 impl<A, B, C, I> HasInterner for (A, B, C) 702 where 703 A: HasInterner<Interner = I>, 704 B: HasInterner<Interner = I>, 705 C: HasInterner<Interner = I>, 706 I: Interner, 707 { 708 type Interner = I; 709 } 710 711 impl<'a, T: HasInterner> HasInterner for std::slice::Iter<'a, T> { 712 type Interner = T::Interner; 713 } 714