From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- vendor/chalk-engine/src/tables.rs | 72 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 vendor/chalk-engine/src/tables.rs (limited to 'vendor/chalk-engine/src/tables.rs') diff --git a/vendor/chalk-engine/src/tables.rs b/vendor/chalk-engine/src/tables.rs new file mode 100644 index 000000000..76508eaa8 --- /dev/null +++ b/vendor/chalk-engine/src/tables.rs @@ -0,0 +1,72 @@ +use crate::table::Table; +use crate::TableIndex; +use rustc_hash::FxHashMap; +use std::ops::{Index, IndexMut}; + +use chalk_ir::interner::Interner; +use chalk_ir::{Goal, InEnvironment, UCanonical}; + +/// See `Forest`. +#[derive(Debug)] +pub(crate) struct Tables { + /// Maps from a canonical goal to the index of its table. + table_indices: FxHashMap>>, TableIndex>, + + /// Table: as described above, stores the key information for each + /// tree in the forest. + tables: Vec>, +} + +impl Tables { + pub(crate) fn new() -> Tables { + Tables { + table_indices: FxHashMap::default(), + tables: Vec::default(), + } + } + + /// The index that will be given to the next table to be inserted. + pub(super) fn next_index(&self) -> TableIndex { + TableIndex { + value: self.tables.len(), + } + } + + pub(super) fn insert(&mut self, table: Table) -> TableIndex { + let goal = table.table_goal.clone(); + let index = self.next_index(); + self.tables.push(table); + self.table_indices.insert(goal, index); + index + } + + pub(super) fn index_of( + &self, + literal: &UCanonical>>, + ) -> Option { + self.table_indices.get(literal).cloned() + } +} + +impl Index for Tables { + type Output = Table; + + fn index(&self, index: TableIndex) -> &Table { + &self.tables[index.value] + } +} + +impl IndexMut for Tables { + fn index_mut(&mut self, index: TableIndex) -> &mut Table { + &mut self.tables[index.value] + } +} + +impl<'a, I: Interner> IntoIterator for &'a mut Tables { + type IntoIter = <&'a mut Vec> as IntoIterator>::IntoIter; + type Item = <&'a mut Vec> as IntoIterator>::Item; + + fn into_iter(self) -> Self::IntoIter { + IntoIterator::into_iter(&mut self.tables) + } +} -- cgit v1.2.3