misc: Fix broken doc links, remove "pool" from index_map.rs

This commit is contained in:
John 2024-05-19 15:32:57 -05:00
parent 406bfb8882
commit 1c3a56f5b5
4 changed files with 42 additions and 42 deletions

View File

@ -5,12 +5,13 @@
//! - [Item] and [ItemKind]: Top-level constructs //! - [Item] and [ItemKind]: Top-level constructs
//! - [Stmt] and [StmtKind]: Statements //! - [Stmt] and [StmtKind]: Statements
//! - [Expr] and [ExprKind]: Expressions //! - [Expr] and [ExprKind]: Expressions
//! - [Assign], [Binary], and [Unary] expressions //! - [Assign], [Modify], [Binary], and [Unary] expressions
//! - [AssignKind], [BinaryKind], and [UnaryKind] operators //! - [ModifyKind], [BinaryKind], and [UnaryKind] operators
//! - [Ty] and [TyKind]: Type qualifiers //! - [Ty] and [TyKind]: Type qualifiers
//! - [Path]: Path expressions //! - [Path]: Path expressions
use cl_structures::{intern::interned::Interned, span::*}; use cl_structures::{intern::interned::Interned, span::*};
/// An [Interned] static [str], used in place of an identifier
pub type Sym = Interned<'static, str>; pub type Sym = Interned<'static, str>;
/// Whether a binding ([Static] or [Let]) or reference is mutable or not /// Whether a binding ([Static] or [Let]) or reference is mutable or not
@ -388,7 +389,7 @@ pub enum ExprKind {
Continue(Continue), Continue(Continue),
} }
/// An [Assign]ment expression: [`Expr`] ([`AssignKind`] [`Expr`])\+ /// An [Assign]ment expression: [`Expr`] ([`ModifyKind`] [`Expr`])\+
#[derive(Clone, Debug, PartialEq, Eq, Hash)] #[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Assign { pub struct Assign {
pub parts: Box<(ExprKind, ExprKind)>, pub parts: Box<(ExprKind, ExprKind)>,

View File

@ -6,7 +6,7 @@
//! - [Stmt] and [StmtKind]: Statements //! - [Stmt] and [StmtKind]: Statements
//! - [Expr] and [ExprKind]: Expressions //! - [Expr] and [ExprKind]: Expressions
//! - [Assign], [Binary], and [Unary] expressions //! - [Assign], [Binary], and [Unary] expressions
//! - [AssignKind], [BinaryKind], and [UnaryKind] operators //! - [ModifyKind], [BinaryKind], and [UnaryKind] operators
//! - [Ty] and [TyKind]: Type qualifiers //! - [Ty] and [TyKind]: Type qualifiers
//! - [Path]: Path expressions //! - [Path]: Path expressions
#![warn(clippy::all)] #![warn(clippy::all)]

View File

@ -756,7 +756,7 @@ macro path_like() {
} }
/// # Path parsing /// # Path parsing
impl<'t> Parser<'t> { impl<'t> Parser<'t> {
/// [PathPart] = `super` | `self` | [Identifier] /// [PathPart] = `super` | `self` | [`Identifier`](TokenKind::Identifier)
pub fn path_part(&mut self) -> PResult<PathPart> { pub fn path_part(&mut self) -> PResult<PathPart> {
const PARSING: Parsing = Parsing::PathPart; const PARSING: Parsing = Parsing::PathPart;
let out = match self.peek_kind(PARSING)? { let out = match self.peek_kind(PARSING)? {
@ -981,7 +981,7 @@ impl<'t> Parser<'t> {
Ok(Structor { to, init }) Ok(Structor { to, init })
} }
/// [Fielder] = [Identifier] (`:` [Expr])? /// [Fielder] = [`Identifier`](TokenKind::Identifier) (`:` [Expr])?
pub fn fielder(&mut self) -> PResult<Fielder> { pub fn fielder(&mut self) -> PResult<Fielder> {
const PARSING: Parsing = Parsing::Fielder; const PARSING: Parsing = Parsing::Fielder;
Ok(Fielder { Ok(Fielder {

View File

@ -1,4 +1,5 @@
//! Trivially-copyable, easily comparable typed [indices](MapIndex), and a [Pool] to contain them //! Trivially-copyable, easily comparable typed [indices](MapIndex),
//! and an [IndexMap] to contain them.
//! //!
//! # Examples //! # Examples
//! //!
@ -9,8 +10,8 @@
//! NumbersKey //! NumbersKey
//! } //! }
//! //!
//! // then, create a pool with that type //! // then, create a map with that type
//! let mut numbers: Pool<i32, NumbersKey> = Pool::new(); //! let mut numbers: IndexMap<i32, NumbersKey> = IndexMap::new();
//! let first = numbers.insert(1); //! let first = numbers.insert(1);
//! let second = numbers.insert(2); //! let second = numbers.insert(2);
//! let third = numbers.insert(3); //! let third = numbers.insert(3);
@ -27,7 +28,7 @@
//! assert_eq!(Some(&100000), numbers.get(first)); //! assert_eq!(Some(&100000), numbers.get(first));
//! ``` //! ```
/// Creates newtype indices over [`usize`] for use as [Pool] keys. /// Creates newtype indices over [`usize`] for use as [IndexMap] keys.
#[macro_export] #[macro_export]
macro_rules! make_index {($($(#[$meta:meta])* $name:ident),*$(,)?) => {$( macro_rules! make_index {($($(#[$meta:meta])* $name:ident),*$(,)?) => {$(
$(#[$meta])* $(#[$meta])*
@ -58,24 +59,22 @@ pub use make_index;
use self::iter::MapIndexIter; use self::iter::MapIndexIter;
/// An index into a [Pool]. For full type-safety, /// An index into a [IndexMap]. For full type-safety,
/// there should be a unique [InternKey] for each [Pool] /// there should be a unique [MapIndex] for each [IndexMap].
pub trait MapIndex: std::fmt::Debug { pub trait MapIndex: std::fmt::Debug {
/// Constructs an [`MapIndex`] from a [`usize`] without checking bounds. /// Constructs an [`MapIndex`] from a [`usize`] without checking bounds.
/// ///
/// # Safety
///
/// The provided value should be within the bounds of its associated container. /// The provided value should be within the bounds of its associated container.
// ID::from_raw_unchecked here isn't *actually* unsafe, since bounds should always be // ID::from_raw_unchecked here isn't *actually* unsafe, since bounds should always be
// checked, however, the function has unverifiable preconditions. // checked, however, the function has unverifiable preconditions.
fn from_usize(value: usize) -> Self; fn from_usize(value: usize) -> Self;
/// Gets the index of the [`InternKey`] by value /// Gets the index of the [`MapIndex`] by value
fn get(&self) -> usize; fn get(&self) -> usize;
} }
#[derive(Clone, Debug, PartialEq, Eq)] #[derive(Clone, Debug, PartialEq, Eq)]
pub struct IndexMap<K: MapIndex, V> { pub struct IndexMap<K: MapIndex, V> {
pool: Vec<V>, map: Vec<V>,
id_type: std::marker::PhantomData<K>, id_type: std::marker::PhantomData<K>,
} }
@ -84,48 +83,48 @@ impl<V, K: MapIndex> IndexMap<K, V> {
Self::default() Self::default()
} }
pub fn get(&self, index: K) -> Option<&V> { pub fn get(&self, index: K) -> Option<&V> {
self.pool.get(index.get()) self.map.get(index.get())
} }
pub fn get_mut(&mut self, index: K) -> Option<&mut V> { pub fn get_mut(&mut self, index: K) -> Option<&mut V> {
self.pool.get_mut(index.get()) self.map.get_mut(index.get())
} }
pub fn get_many_mut<const N: usize>( pub fn get_many_mut<const N: usize>(
&mut self, &mut self,
indices: [K; N], indices: [K; N],
) -> Result<[&mut V; N], GetManyMutError<N>> { ) -> Result<[&mut V; N], GetManyMutError<N>> {
self.pool.get_many_mut(indices.map(|id| id.get())) self.map.get_many_mut(indices.map(|id| id.get()))
} }
pub fn iter(&self) -> impl Iterator<Item = &V> { pub fn iter(&self) -> impl Iterator<Item = &V> {
self.pool.iter() self.map.iter()
} }
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut V> { pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut V> {
self.pool.iter_mut() self.map.iter_mut()
} }
pub fn key_iter(&self) -> iter::MapIndexIter<K> { pub fn key_iter(&self) -> iter::MapIndexIter<K> {
// Safety: Pool currently has pool.len() entries, and data cannot be removed // Safety: IndexMap currently has map.len() entries, and data cannot be removed
MapIndexIter::new(0..self.pool.len()) MapIndexIter::new(0..self.map.len())
} }
/// Constructs an [ID](InternKey) from a [usize], if it's within bounds /// Constructs an [ID](MapIndex) from a [usize], if it's within bounds
#[doc(hidden)] #[doc(hidden)]
pub fn try_key_from(&self, value: usize) -> Option<K> { pub fn try_key_from(&self, value: usize) -> Option<K> {
(value < self.pool.len()).then(|| K::from_usize(value)) (value < self.map.len()).then(|| K::from_usize(value))
} }
pub fn insert(&mut self, value: V) -> K { pub fn insert(&mut self, value: V) -> K {
let id = self.pool.len(); let id = self.map.len();
self.pool.push(value); self.map.push(value);
// Safety: value was pushed to `self.pool[id]` // Safety: value was pushed to `self.map[id]`
K::from_usize(id) K::from_usize(id)
} }
} }
impl<K: MapIndex, V> Default for IndexMap<K, V> { impl<K: MapIndex, V> Default for IndexMap<K, V> {
fn default() -> Self { fn default() -> Self {
Self { pool: vec![], id_type: std::marker::PhantomData } Self { map: vec![], id_type: std::marker::PhantomData }
} }
} }
@ -133,16 +132,16 @@ impl<K: MapIndex, V> Index<K> for IndexMap<K, V> {
type Output = V; type Output = V;
fn index(&self, index: K) -> &Self::Output { fn index(&self, index: K) -> &Self::Output {
match self.pool.get(index.get()) { match self.map.get(index.get()) {
None => panic!("Index {:?} out of bounds in pool!", index), None => panic!("Index {:?} out of bounds in IndexMap!", index),
Some(value) => value, Some(value) => value,
} }
} }
} }
impl<K: MapIndex, V> IndexMut<K> for IndexMap<K, V> { impl<K: MapIndex, V> IndexMut<K> for IndexMap<K, V> {
fn index_mut(&mut self, index: K) -> &mut Self::Output { fn index_mut(&mut self, index: K) -> &mut Self::Output {
match self.pool.get_mut(index.get()) { match self.map.get_mut(index.get()) {
None => panic!("Index {:?} out of bounds in pool!", index), None => panic!("Index {:?} out of bounds in IndexMap!", index),
Some(value) => value, Some(value) => value,
} }
} }
@ -153,11 +152,11 @@ mod iter {
use super::MapIndex; use super::MapIndex;
/// Iterates over the keys of a [Pool](super::Pool) independently of the pool itself. /// Iterates over the keys of an [IndexMap](super::IndexMap), independently of the map.
/// ///
/// This is guaranteed to never overrun the length of the pool, /// This is guaranteed to never overrun the length of the map,
/// but is *NOT* guaranteed to iterate over all elements of the pool /// but is *NOT* guaranteed to iterate over all elements of the map
/// if the pool is extended during iteration. /// if the map is extended during iteration.
#[derive(Clone, Debug, PartialEq, Eq, Hash)] #[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct MapIndexIter<K: MapIndex> { pub struct MapIndexIter<K: MapIndex> {
range: Range<usize>, range: Range<usize>,
@ -165,12 +164,12 @@ mod iter {
} }
impl<K: MapIndex> MapIndexIter<K> { impl<K: MapIndex> MapIndexIter<K> {
/// Creates a new [InternKeyIter] producing the given [InternKey] /// Creates a new [MapIndexIter] producing the given [MapIndex]
/// ///
/// # Safety: /// # Safety:
/// - Range must not exceed bounds of the associated [Pool](super::Pool) /// - Range must not exceed bounds of the associated [IndexMap](super::IndexMap)
/// - Items must not be removed from the pool /// - Items must not be removed from the map
/// - Items must be contiguous within the pool /// - Items must be contiguous within the map
pub(super) fn new(range: Range<usize>) -> Self { pub(super) fn new(range: Range<usize>) -> Self {
Self { range, _id: Default::default() } Self { range, _id: Default::default() }
} }
@ -180,7 +179,7 @@ mod iter {
type Item = ID; type Item = ID;
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
// Safety: InternKeyIter can only be created by InternKeyIter::new() // Safety: MapIndexIter can only be created by MapIndexIter::new()
Some(ID::from_usize(self.range.next()?)) Some(ID::from_usize(self.range.next()?))
} }
fn size_hint(&self) -> (usize, Option<usize>) { fn size_hint(&self) -> (usize, Option<usize>) {