Skip to content

Commit bde56cb

Browse files
committed
Rename UpCaster back to DownCaster
1 parent 70bdaef commit bde56cb

File tree

9 files changed

+77
-72
lines changed

9 files changed

+77
-72
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,11 @@ macro_rules! setup_tracked_fn {
185185
unsafe {
186186
$FN_CACHE.get_or_create(zalsa, || zalsa.lookup_jar_by_type::<$fn_name>())
187187
}
188-
.get_or_init(|| *<dyn $Db as $Db>::zalsa_register_upcaster(db))
188+
.get_or_init(|| *<dyn $Db as $Db>::zalsa_register_downcaster(db))
189189
}
190190

191191
pub fn fn_ingredient_mut(db: &mut dyn $Db) -> &mut $zalsa::function::IngredientImpl<Self> {
192-
let view = *<dyn $Db as $Db>::zalsa_register_upcaster(db);
192+
let view = *<dyn $Db as $Db>::zalsa_register_downcaster(db);
193193
let zalsa_mut = db.zalsa_mut();
194194
let index = zalsa_mut.lookup_jar_by_type::<$fn_name>();
195195
let (ingredient, _) = zalsa_mut.lookup_ingredient_mut(index);

components/salsa-macros/src/db.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,14 @@ impl DbMacro {
110110
let trait_name = &input.ident;
111111
input.items.push(parse_quote! {
112112
#[doc(hidden)]
113-
fn zalsa_register_upcaster(&self) -> &salsa::plumbing::DatabaseUpCaster<dyn #trait_name>;
113+
fn zalsa_register_downcaster(&self) -> &salsa::plumbing::DatabaseDownCaster<dyn #trait_name>;
114114
});
115115

116-
let comment = format!(" upcast `Self` to a [`dyn {trait_name}`]");
116+
let comment = format!(" downcast `Self` to a [`dyn {trait_name}`]");
117117
input.items.push(parse_quote! {
118118
#[doc = #comment]
119119
#[doc(hidden)]
120-
fn upcast(&self) -> &dyn #trait_name where Self: Sized;
120+
fn downcast(&self) -> &dyn #trait_name where Self: Sized;
121121
});
122122
Ok(())
123123
}
@@ -134,14 +134,14 @@ impl DbMacro {
134134
#[cold]
135135
#[inline(never)]
136136
#[doc(hidden)]
137-
fn zalsa_register_upcaster(&self) -> &salsa::plumbing::DatabaseUpCaster<dyn #TraitPath> {
138-
salsa::plumbing::views(self).add(<Self as #TraitPath>::upcast)
137+
fn zalsa_register_downcaster(&self) -> &salsa::plumbing::DatabaseDownCaster<dyn #TraitPath> {
138+
salsa::plumbing::views(self).add(<Self as #TraitPath>::downcast)
139139
}
140140
});
141141
input.items.push(parse_quote! {
142142
#[doc(hidden)]
143143
#[inline(always)]
144-
fn upcast(&self) -> &dyn #TraitPath where Self: Sized {
144+
fn downcast(&self) -> &dyn #TraitPath where Self: Sized {
145145
self
146146
}
147147
});

src/database.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::borrow::Cow;
22
use std::ptr::NonNull;
33

4-
use crate::views::DatabaseUpCaster;
4+
use crate::views::DatabaseDownCaster;
55
use crate::zalsa::{IngredientIndex, ZalsaDatabase};
66
use crate::{Durability, Revision};
77

@@ -110,14 +110,14 @@ pub trait Database: Send + ZalsaDatabase + AsDynDatabase {
110110
#[cold]
111111
#[inline(never)]
112112
#[doc(hidden)]
113-
fn zalsa_register_upcaster(&self) -> &DatabaseUpCaster<dyn Database> {
114-
self.zalsa().views().upcaster_for::<dyn Database>()
113+
fn zalsa_register_downcaster(&self) -> &DatabaseDownCaster<dyn Database> {
114+
self.zalsa().views().downcaster_for::<dyn Database>()
115115
// The no-op downcaster is special cased in view caster construction.
116116
}
117117

118118
#[doc(hidden)]
119119
#[inline(always)]
120-
fn upcast(&self) -> &dyn Database
120+
fn downcast(&self) -> &dyn Database
121121
where
122122
Self: Sized,
123123
{

src/function.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use crate::salsa_struct::SalsaStructInDb;
2020
use crate::sync::Arc;
2121
use crate::table::memo::MemoTableTypes;
2222
use crate::table::Table;
23-
use crate::views::DatabaseUpCaster;
23+
use crate::views::DatabaseDownCaster;
2424
use crate::zalsa::{IngredientIndex, MemoIngredientIndex, Zalsa};
2525
use crate::zalsa_local::QueryOriginRef;
2626
use crate::{Id, Revision};
@@ -124,14 +124,14 @@ pub struct IngredientImpl<C: Configuration> {
124124
/// Used to find memos to throw out when we have too many memoized values.
125125
lru: lru::Lru,
126126

127-
/// An upcaster to `C::DbView`.
127+
/// An downcaster to `C::DbView`.
128128
///
129129
/// # Safety
130130
///
131131
/// The supplied database must be be the same as the database used to construct the [`Views`]
132-
/// instances that this upcaster was derived from.
133132
/// instances that this downcaster was derived from.
134-
view_caster: OnceLock<DatabaseUpCaster<C::DbView>>,
133+
/// instances that this downcaster was derived from.
134+
view_caster: OnceLock<DatabaseDownCaster<C::DbView>>,
135135

136136
sync_table: SyncTable,
137137

@@ -173,7 +173,7 @@ where
173173
/// Set the view-caster for this tracked function ingredient, if it has
174174
/// not already been initialized.
175175
#[inline]
176-
pub fn get_or_init(&self, view_caster: impl FnOnce() -> DatabaseUpCaster<C::DbView>) -> &Self {
176+
pub fn get_or_init(&self, view_caster: impl FnOnce() -> DatabaseDownCaster<C::DbView>) -> &Self {
177177
// Note that we must set this lazily as we don't have access to the database
178178
// type when ingredients are registered into the `Zalsa`.
179179
self.view_caster.get_or_init(view_caster);
@@ -239,7 +239,7 @@ where
239239
self.memo_ingredient_indices.get_zalsa_id(zalsa, id)
240240
}
241241

242-
fn view_caster(&self) -> &DatabaseUpCaster<C::DbView> {
242+
fn view_caster(&self) -> &DatabaseDownCaster<C::DbView> {
243243
self.view_caster
244244
.get()
245245
.expect("tracked function ingredients cannot be accessed before calling `init`")
@@ -267,7 +267,7 @@ where
267267
cycle_heads: &mut CycleHeads,
268268
) -> VerifyResult {
269269
// SAFETY: The `db` belongs to the ingredient as per caller invariant
270-
let db = unsafe { self.view_caster().upcast_unchecked(db) };
270+
let db = unsafe { self.view_caster().downcast_unchecked(db) };
271271
self.maybe_changed_after(db, input, revision, cycle_heads)
272272
}
273273

@@ -376,7 +376,7 @@ where
376376
key_index: Id,
377377
) -> (Option<&'db AccumulatedMap>, InputAccumulatedValues) {
378378
// SAFETY: The `db` belongs to the ingredient as per caller invariant
379-
let db = unsafe { self.view_caster().upcast_unchecked(db) };
379+
let db = unsafe { self.view_caster().downcast_unchecked(db) };
380380
self.accumulated_map(db, key_index)
381381
}
382382
}

src/ingredient.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ pub trait Ingredient: Any + std::fmt::Debug + Send + Sync {
185185
impl dyn Ingredient {
186186
/// Equivalent to the `downcast` method on `Any`.
187187
///
188-
/// Because we do not have dyn-upcasting support, we need this workaround.
188+
/// Because we do not have dyn-downcasting support, we need this workaround.
189189
pub fn assert_type<T: Any>(&self) -> &T {
190190
assert_eq!(
191191
self.type_id(),
@@ -201,7 +201,7 @@ impl dyn Ingredient {
201201

202202
/// Equivalent to the `downcast` methods on `Any`.
203203
///
204-
/// Because we do not have dyn-upcasting support, we need this workaround.
204+
/// Because we do not have dyn-downcasting support, we need this workaround.
205205
///
206206
/// # Safety
207207
///
@@ -220,7 +220,7 @@ impl dyn Ingredient {
220220

221221
/// Equivalent to the `downcast` method on `Any`.
222222
///
223-
/// Because we do not have dyn-upcasting support, we need this workaround.
223+
/// Because we do not have dyn-downcasting support, we need this workaround.
224224
pub fn assert_type_mut<T: Any>(&mut self) -> &mut T {
225225
assert_eq!(
226226
Any::type_id(self),

src/key.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl DatabaseKeyIndex {
5050
.maybe_changed_after(
5151
zalsa,
5252
// lets say we do turn this into an opaque pair of data and vtable pointer
53-
// then we also need an upcast function, from our dbview to the ingredients
53+
// then we also need an downcast function, from our dbview to the ingredients
5454
// dbview
5555
db,
5656
self.key_index(),

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ pub mod plumbing {
109109
pub use crate::tracked_struct::TrackedStructInDb;
110110
pub use crate::update::helper::{Dispatch as UpdateDispatch, Fallback as UpdateFallback};
111111
pub use crate::update::{always_update, Update};
112-
pub use crate::views::DatabaseUpCaster;
112+
pub use crate::views::DatabaseDownCaster;
113113
pub use crate::zalsa::{
114114
register_jar, transmute_data_ptr, views, ErasedJar, HasJar, IngredientIndex, JarKind,
115115
Zalsa, ZalsaDatabase,

src/parallel.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rayon::iter::{FromParallelIterator, IntoParallelIterator, ParallelIterator};
22

3-
use crate::{database::RawDatabasePointer, views::DatabaseUpCaster, Database};
3+
use crate::{database::RawDatabasePointer, views::DatabaseDownCaster, Database};
44

55
pub fn par_map<Db, F, T, R, C>(db: &Db, inputs: impl IntoParallelIterator<Item = T>, op: F) -> C
66
where
@@ -11,8 +11,8 @@ where
1111
C: FromParallelIterator<R>,
1212
{
1313
let views = db.zalsa().views();
14-
let caster = &views.upcaster_for::<Db>();
15-
let db_caster = &views.base_database_upcaster();
14+
let caster = &views.downcaster_for::<Db>();
15+
let db_caster = &views.base_database_downcaster();
1616
inputs
1717
.into_par_iter()
1818
.map_with(
@@ -24,24 +24,24 @@ where
2424

2525
struct DbForkOnClone<'views, Db: Database + ?Sized>(
2626
RawDatabasePointer<'static>,
27-
&'views DatabaseUpCaster<Db>,
28-
&'views DatabaseUpCaster<dyn Database>,
27+
&'views DatabaseDownCaster<Db>,
28+
&'views DatabaseDownCaster<dyn Database>,
2929
);
3030

3131
// SAFETY: `T: Send` -> `&own T: Send`, `DbForkOnClone` is an owning pointer
3232
unsafe impl<Db: Send + Database + ?Sized> Send for DbForkOnClone<'_, Db> {}
3333

3434
impl<Db: Database + ?Sized> DbForkOnClone<'_, Db> {
3535
fn as_view(&self) -> &Db {
36-
// SAFETY: The upcaster ensures that the pointer is valid for the lifetime of the view.
37-
unsafe { self.1.upcast_unchecked(self.0) }
36+
// SAFETY: The downcaster ensures that the pointer is valid for the lifetime of the view.
37+
unsafe { self.1.downcast_unchecked(self.0) }
3838
}
3939
}
4040

4141
impl<Db: Database + ?Sized> Drop for DbForkOnClone<'_, Db> {
4242
fn drop(&mut self) {
4343
// SAFETY: `caster` is derived from a `db` fitting for our database clone
44-
let db = unsafe { self.1.upcast_mut_unchecked(self.0) };
44+
let db = unsafe { self.1.downcast_mut_unchecked(self.0) };
4545
// SAFETY: `db` has been box allocated and leaked by `fork_db`
4646
_ = unsafe { Box::from_raw(db) };
4747
}
@@ -51,7 +51,7 @@ impl<Db: Database + ?Sized> Clone for DbForkOnClone<'_, Db> {
5151
fn clone(&self) -> Self {
5252
DbForkOnClone(
5353
// SAFETY: `caster` is derived from a `db` fitting for our database clone
54-
unsafe { self.2.upcast_unchecked(self.0) }.fork_db(),
54+
unsafe { self.2.downcast_unchecked(self.0) }.fork_db(),
5555
self.1,
5656
self.2,
5757
)
@@ -70,22 +70,22 @@ where
7070
// SAFETY: We send owning pointers over, which are Send, given the `Db` type parameter above is Send
7171
unsafe impl<T> Send for AssertSend<T> {}
7272

73-
let caster = &db.zalsa().views().upcaster_for::<Db>();
73+
let caster = &db.zalsa().views().downcaster_for::<Db>();
7474
// we need to fork eagerly, as `rayon::join_context` gives us no option to tell whether we get
7575
// moved to another thread before the closure is executed
7676
let db_a = AssertSend(db.fork_db());
7777
let db_b = AssertSend(db.fork_db());
7878
let res = rayon::join(
7979
// SAFETY: `caster` is derived from a `db` fitting for our database clone
80-
move || a(unsafe { caster.upcast_unchecked({ db_a }.0) }),
80+
move || a(unsafe { caster.downcast_unchecked({ db_a }.0) }),
8181
// SAFETY: `caster` is derived from a `db` fitting for our database clone
82-
move || b(unsafe { caster.upcast_unchecked({ db_b }.0) }),
82+
move || b(unsafe { caster.downcast_unchecked({ db_b }.0) }),
8383
);
8484

8585
// SAFETY: `db` has been box allocated and leaked by `fork_db`
8686
// FIXME: Clean this mess up, RAII
87-
_ = unsafe { Box::from_raw(caster.upcast_mut_unchecked(db_a.0)) };
87+
_ = unsafe { Box::from_raw(caster.downcast_mut_unchecked(db_a.0)) };
8888
// SAFETY: `db` has been box allocated and leaked by `fork_db`
89-
_ = unsafe { Box::from_raw(caster.upcast_mut_unchecked(db_b.0)) };
89+
_ = unsafe { Box::from_raw(caster.downcast_mut_unchecked(db_b.0)) };
9090
res
9191
}

0 commit comments

Comments
 (0)