Skip to content

Commit a57df6c

Browse files
committed
Drop clone requirement for accumulated values
1 parent 9107eeb commit a57df6c

File tree

6 files changed

+8
-71
lines changed

6 files changed

+8
-71
lines changed

components/salsa-macro-rules/src/setup_tracked_fn.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ macro_rules! setup_tracked_fn {
277277
pub fn accumulated<$db_lt, A: salsa::Accumulator>(
278278
$db: &$db_lt dyn $Db,
279279
$($input_id: $input_ty,)*
280-
) -> Vec<A> {
280+
) -> Vec<&$db_lt A> {
281281
use salsa::plumbing as $zalsa;
282282
let key = $zalsa::macro_if! {
283283
if $needs_interner {

src/accumulator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub(crate) mod accumulated_map;
2424

2525
/// Trait implemented on the struct that user annotated with `#[salsa::accumulator]`.
2626
/// The `Self` type is therefore the types to be accumulated.
27-
pub trait Accumulator: Clone + Debug + Send + Sync + Any + Sized + UnwindSafe {
27+
pub trait Accumulator: Debug + Send + Sync + Any + Sized + UnwindSafe {
2828
const DEBUG_NAME: &'static str;
2929

3030
/// Accumulate an instance of this in the database for later retrieval.

src/accumulator/accumulated.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,15 @@ pub(crate) struct Accumulated<A: Accumulator> {
1111
pub(crate) trait AnyAccumulated: Any + Debug + Send + Sync {
1212
fn as_dyn_any(&self) -> &dyn Any;
1313
fn as_dyn_any_mut(&mut self) -> &mut dyn Any;
14-
fn cloned(&self) -> Box<dyn AnyAccumulated>;
1514
}
1615

1716
impl<A: Accumulator> Accumulated<A> {
1817
pub fn push(&mut self, value: A) {
1918
self.values.push(value);
2019
}
2120

22-
pub fn extend_with_accumulated(&self, values: &mut Vec<A>) {
23-
values.extend_from_slice(&self.values);
21+
pub fn extend_with_accumulated<'slf>(&'slf self, values: &mut Vec<&'slf A>) {
22+
values.extend(&self.values);
2423
}
2524
}
2625

@@ -43,11 +42,6 @@ where
4342
fn as_dyn_any_mut(&mut self) -> &mut dyn Any {
4443
self
4544
}
46-
47-
fn cloned(&self) -> Box<dyn AnyAccumulated> {
48-
let this: Self = self.clone();
49-
Box::new(this)
50-
}
5145
}
5246

5347
impl dyn AnyAccumulated {

src/accumulator/accumulated_map.rs

+3-15
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ impl AccumulatedMap {
2222
.accumulate(value);
2323
}
2424

25-
pub fn extend_with_accumulated<A: Accumulator>(
26-
&self,
25+
pub fn extend_with_accumulated<'slf, A: Accumulator>(
26+
&'slf self,
2727
index: IngredientIndex,
28-
output: &mut Vec<A>,
28+
output: &mut Vec<&'slf A>,
2929
) {
3030
let Some(a) = self.map.get(&index) else {
3131
return;
@@ -42,18 +42,6 @@ impl AccumulatedMap {
4242
}
4343
}
4444

45-
impl Clone for AccumulatedMap {
46-
fn clone(&self) -> Self {
47-
Self {
48-
map: self
49-
.map
50-
.iter()
51-
.map(|(&key, value)| (key, value.cloned()))
52-
.collect(),
53-
}
54-
}
55-
}
56-
5745
/// Tracks whether any input read during a query's execution has any accumulated values.
5846
///
5947
/// Knowning whether any input has accumulated values makes aggregating the accumulated values

src/function/accumulated.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ where
1414
{
1515
/// Helper used by `accumulate` functions. Computes the results accumulated by `database_key_index`
1616
/// and its inputs.
17-
pub fn accumulated_by<A>(&self, db: &C::DbView, key: Id) -> Vec<A>
17+
pub fn accumulated_by<'db, A>(&self, db: &'db C::DbView, key: Id) -> Vec<&'db A>
1818
where
1919
A: accumulator::Accumulator,
2020
{

tests/accumulate-custom-clone.rs

-45
This file was deleted.

0 commit comments

Comments
 (0)