@@ -100,19 +100,15 @@ impl<C: Configuration> Default for IngredientShard<C> {
100
100
101
101
// SAFETY: `LinkedListLink` is `!Sync`, however, the linked list is only accessed through the
102
102
// ingredient lock, and values are only ever linked to a single list on the ingredient.
103
- unsafe impl < Fields : Sync > Sync for Value < Fields > { }
103
+ unsafe impl < C : Configuration > Sync for Value < C > { }
104
104
105
- intrusive_adapter ! ( ValueAdapter <C > = UnsafeRef <ValueForConfiguration <C >>: ValueForConfiguration <C > { link: LinkedListLink } where C : Configuration ) ;
106
-
107
- #[ cfg( not( feature = "shuttle" ) ) ]
108
- #[ cfg( target_pointer_width = "64" ) ]
109
- const _: [ ( ) ; std:: mem:: size_of :: < Value < ( ) > > ( ) ] = [ ( ) ; std:: mem:: size_of :: < [ usize ; 7 ] > ( ) ] ;
110
-
111
- #[ allow( type_alias_bounds) ]
112
- type ValueForConfiguration < C : Configuration > = Value < C :: Fields < ' static > > ;
105
+ intrusive_adapter ! ( ValueAdapter <C > = UnsafeRef <Value <C >>: Value <C > { link: LinkedListLink } where C : Configuration ) ;
113
106
114
107
/// Struct storing the interned fields.
115
- pub struct Value < Fields > {
108
+ pub struct Value < C >
109
+ where
110
+ C : Configuration ,
111
+ {
116
112
/// The index of the shard containing this value.
117
113
shard : u16 ,
118
114
@@ -123,7 +119,7 @@ pub struct Value<Fields> {
123
119
///
124
120
/// These are valid for read-only access as long as the lock is held
125
121
/// or the value has been validated in the current revision.
126
- fields : UnsafeCell < Fields > ,
122
+ fields : UnsafeCell < C :: Fields < ' static > > ,
127
123
128
124
/// Memos attached to this interned value.
129
125
///
@@ -182,10 +178,13 @@ impl ValueShared {
182
178
}
183
179
}
184
180
185
- impl < Fields > Value < Fields > {
181
+ impl < C > Value < C >
182
+ where
183
+ C : Configuration ,
184
+ {
186
185
/// Fields of this interned struct.
187
186
#[ cfg( feature = "salsa_unstable" ) ]
188
- pub fn fields ( & self ) -> & Fields {
187
+ pub fn fields ( & self ) -> & C :: Fields < ' static > {
189
188
// SAFETY: The fact that this function is safe is technically unsound. However, interned
190
189
// values are only exposed if they have been validated in the current revision, which
191
190
// ensures that they are not reused while being accessed.
@@ -574,9 +573,7 @@ where
574
573
. unwrap_or ( ( Durability :: MAX , Revision :: max ( ) ) ) ;
575
574
576
575
// Allocate the value slot.
577
- let id = zalsa_local. allocate ( zalsa, self . ingredient_index , |id| ValueForConfiguration :: <
578
- C ,
579
- > {
576
+ let id = zalsa_local. allocate ( zalsa, self . ingredient_index , |id| Value :: < C > {
580
577
shard : shard_index as u16 ,
581
578
link : LinkedListLink :: new ( ) ,
582
579
memos : UnsafeCell :: new ( MemoTable :: default ( ) ) ,
@@ -589,7 +586,7 @@ where
589
586
} ) ,
590
587
} ) ;
591
588
592
- let value = Self :: table_get ( zalsa , id) ;
589
+ let value = zalsa . table ( ) . get :: < Value < C > > ( id) ;
593
590
// SAFETY: We hold the lock for the shard containing the value.
594
591
let value_shared = unsafe { & mut * value. shared . get ( ) } ;
595
592
@@ -608,7 +605,7 @@ where
608
605
shard. key_map . insert_unique ( hash, id, hasher) ;
609
606
610
607
debug_assert_eq ! ( hash, {
611
- let value = Self :: table_get ( zalsa , id) ;
608
+ let value = zalsa . table ( ) . get :: < Value < C >> ( id) ;
612
609
613
610
// SAFETY: We hold the lock for the shard containing the value.
614
611
unsafe { self . hasher. hash_one( & * value. fields. get( ) ) }
@@ -687,7 +684,7 @@ where
687
684
unsafe fn value_hash < ' db > ( & ' db self , id : Id , zalsa : & ' db Zalsa ) -> u64 {
688
685
// This closure is only called if the table is resized. So while it's expensive
689
686
// to lookup all values, it will only happen rarely.
690
- let value = Self :: table_get ( zalsa , id) ;
687
+ let value = zalsa . table ( ) . get :: < Value < C > > ( id) ;
691
688
692
689
// SAFETY: We hold the lock for the shard containing the value.
693
690
unsafe { self . hasher . hash_one ( & * value. fields . get ( ) ) }
@@ -702,12 +699,12 @@ where
702
699
id : Id ,
703
700
key : & Key ,
704
701
zalsa : & ' db Zalsa ,
705
- found_value : & Cell < Option < & ' db ValueForConfiguration < C > > > ,
702
+ found_value : & Cell < Option < & ' db Value < C > > > ,
706
703
) -> bool
707
704
where
708
705
C :: Fields < ' db > : HashEqLike < Key > ,
709
706
{
710
- let value = Self :: table_get ( zalsa , id) ;
707
+ let value = zalsa . table ( ) . get :: < Value < C > > ( id) ;
711
708
found_value. set ( Some ( value) ) ;
712
709
713
710
// SAFETY: We hold the lock for the shard containing the value.
@@ -725,7 +722,7 @@ where
725
722
/// Lookup the data for an interned value based on its ID.
726
723
pub fn data < ' db > ( & ' db self , db : & ' db dyn Database , id : Id ) -> & ' db C :: Fields < ' db > {
727
724
let zalsa = db. zalsa ( ) ;
728
- let value = Self :: table_get ( zalsa , id) ;
725
+ let value = zalsa . table ( ) . get :: < Value < C > > ( id) ;
729
726
730
727
debug_assert ! (
731
728
{
@@ -767,16 +764,8 @@ where
767
764
pub fn entries < ' db > (
768
765
& ' db self ,
769
766
db : & ' db dyn crate :: Database ,
770
- ) -> impl Iterator < Item = & ' db ValueForConfiguration < C > > {
771
- db. zalsa ( ) . table ( ) . slots_of :: < ValueForConfiguration < C > > ( )
772
- }
773
-
774
- #[ inline]
775
- fn table_get ( zalsa : & Zalsa , id : Id ) -> & ValueForConfiguration < C >
776
- where
777
- C : Configuration ,
778
- {
779
- zalsa. table ( ) . get :: < ValueForConfiguration < C > > ( id)
767
+ ) -> impl Iterator < Item = & ' db Value < C > > {
768
+ db. zalsa ( ) . table ( ) . slots_of :: < Value < C > > ( )
780
769
}
781
770
}
782
771
@@ -805,7 +794,7 @@ where
805
794
let current_revision = zalsa. current_revision ( ) ;
806
795
self . revision_queue . record ( current_revision) ;
807
796
808
- let value = zalsa. table ( ) . get :: < ValueForConfiguration < C > > ( input) ;
797
+ let value = zalsa. table ( ) . get :: < Value < C > > ( input) ;
809
798
810
799
// SAFETY: `value.shard` is guaranteed to be in-bounds for `self.shards`.
811
800
let _shard = unsafe { self . shards . get_unchecked ( value. shard as usize ) } . lock ( ) ;
@@ -854,7 +843,11 @@ where
854
843
}
855
844
}
856
845
857
- impl < Fields : Send + Sync + ' static > Slot for Value < Fields > {
846
+ // SAFETY: `Value<C>` is our private type branded over the unique configuration `C`.
847
+ unsafe impl < C > Slot for Value < C >
848
+ where
849
+ C : Configuration ,
850
+ {
858
851
#[ inline( always) ]
859
852
unsafe fn memos ( & self , _current_revision : Revision ) -> & MemoTable {
860
853
// SAFETY: The fact that we have a reference to the `Value` means it must
0 commit comments