clock: Cleanup ReplicaId, Lamport and Global (#40600)

- Notable change is the use of a newtype for `ReplicaId`
- Fixes `WorktreeStore::create_remote_worktree` creating a remote
worktree with the local replica id, though this is not currently used
- Fixes observing the `Agent` (that is following the agent) causing
global clocks to allocate 65535 elements
- Shrinks the size of `Global` a bit. In a local or non-collab remote
session it won't ever allocate still.

Release Notes:

- N/A *or* Added/Fixed/Improved ...
This commit is contained in:
Lukas Wirth
2025-10-20 13:26:20 +02:00
committed by GitHub
parent 37e264ab99
commit 43a9368dff
33 changed files with 427 additions and 284 deletions
+11 -5
View File
@@ -1,3 +1,4 @@
use clock::Lamport;
use std::{fmt::Debug, ops::Add};
use sum_tree::{ContextLessSummary, Dimension, Edit, Item, KeyedItem, SumTree};
@@ -11,10 +12,10 @@ struct OperationItem<T>(T);
#[derive(Clone, Debug)]
pub struct OperationQueue<T: Operation>(SumTree<OperationItem<T>>);
#[derive(Clone, Copy, Debug, Default, Eq, Ord, PartialEq, PartialOrd)]
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
pub struct OperationKey(clock::Lamport);
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct OperationSummary {
pub key: OperationKey,
pub len: usize,
@@ -69,7 +70,10 @@ impl<T: Operation> OperationQueue<T> {
impl ContextLessSummary for OperationSummary {
fn zero() -> Self {
Default::default()
OperationSummary {
key: OperationKey::new(Lamport::MIN),
len: 0,
}
}
fn add_summary(&mut self, other: &Self) {
@@ -93,7 +97,7 @@ impl Add<&Self> for OperationSummary {
impl Dimension<'_, OperationSummary> for OperationKey {
fn zero(_cx: ()) -> Self {
Default::default()
OperationKey::new(Lamport::MIN)
}
fn add_summary(&mut self, summary: &OperationSummary, _: ()) {
@@ -123,11 +127,13 @@ impl<T: Operation> KeyedItem for OperationItem<T> {
#[cfg(test)]
mod tests {
use clock::ReplicaId;
use super::*;
#[test]
fn test_len() {
let mut clock = clock::Lamport::new(0);
let mut clock = clock::Lamport::new(ReplicaId::LOCAL);
let mut queue = OperationQueue::new();
assert_eq!(queue.len(), 0);