@@ -92,15 +92,19 @@ impl<C: Configuration> Default for IngredientShard<C> {
92
92
93
93
// SAFETY: `LinkedListLink` is `!Sync`, however, the linked list is only accessed through the
94
94
// ingredient lock, and values are only ever linked to a single list on the ingredient.
95
- unsafe impl < C : Configuration > Sync for Value < C > { }
95
+ unsafe impl < Fields : Sync > Sync for Value < Fields > { }
96
96
97
- intrusive_adapter ! ( ValueAdapter <C > = UnsafeRef <Value <C >>: Value <C > { link: LinkedListLink } where C : Configuration ) ;
97
+ intrusive_adapter ! ( ValueAdapter <C > = UnsafeRef <ValueForConfiguration <C >>: ValueForConfiguration <C > { link: LinkedListLink } where C : Configuration ) ;
98
+
99
+ #[ cfg( not( feature = "shuttle" ) ) ]
100
+ #[ cfg( target_pointer_width = "64" ) ]
101
+ const _: [ ( ) ; std:: mem:: size_of :: < Value < ( ) > > ( ) ] = [ ( ) ; std:: mem:: size_of :: < [ usize ; 8 ] > ( ) ] ;
102
+
103
+ #[ allow( type_alias_bounds) ]
104
+ type ValueForConfiguration < C : Configuration > = Value < C :: Fields < ' static > > ;
98
105
99
106
/// Struct storing the interned fields.
100
- pub struct Value < C >
101
- where
102
- C : Configuration ,
103
- {
107
+ pub struct Value < Fields > {
104
108
/// The index of the shard containing this value.
105
109
shard : u16 ,
106
110
@@ -111,7 +115,7 @@ where
111
115
///
112
116
/// These are valid for read-only access as long as the lock is held
113
117
/// or the value has been validated in the current revision.
114
- fields : UnsafeCell < C :: Fields < ' static > > ,
118
+ fields : UnsafeCell < Fields > ,
115
119
116
120
/// Memos attached to this interned value.
117
121
///
@@ -164,13 +168,10 @@ impl ValueShared {
164
168
}
165
169
}
166
170
167
- impl < C > Value < C >
168
- where
169
- C : Configuration ,
170
- {
171
+ impl < Fields > Value < Fields > {
171
172
/// Fields of this interned struct.
172
173
#[ cfg( feature = "salsa_unstable" ) ]
173
- pub fn fields ( & self ) -> & C :: Fields < ' static > {
174
+ pub fn fields ( & self ) -> & Fields {
174
175
// SAFETY: The fact that this function is safe is technically unsound. However, interned
175
176
// values are only exposed if they have been validated in the current revision, which
176
177
// ensures that they are not reused while being accessed.
@@ -547,7 +548,9 @@ where
547
548
. unwrap_or ( ( Durability :: MAX , Revision :: max ( ) ) ) ;
548
549
549
550
// Allocate the value slot.
550
- let id = zalsa_local. allocate ( zalsa, self . ingredient_index , |id| Value :: < C > {
551
+ let id = zalsa_local. allocate ( zalsa, self . ingredient_index , |id| ValueForConfiguration :: <
552
+ C ,
553
+ > {
551
554
shard : shard_index as u16 ,
552
555
link : LinkedListLink :: new ( ) ,
553
556
memos : UnsafeCell :: new ( MemoTable :: default ( ) ) ,
@@ -560,7 +563,7 @@ where
560
563
} ) ,
561
564
} ) ;
562
565
563
- let value = zalsa . table ( ) . get :: < Value < C > > ( id) ;
566
+ let value = Self :: table_get ( zalsa , id) ;
564
567
// SAFETY: We hold the lock for the shard containing the value.
565
568
let value_shared = unsafe { & mut * value. shared . get ( ) } ;
566
569
@@ -579,7 +582,7 @@ where
579
582
shard. key_map . insert_unique ( hash, id, hasher) ;
580
583
581
584
debug_assert_eq ! ( hash, {
582
- let value = zalsa . table ( ) . get :: < Value < C >> ( id) ;
585
+ let value = Self :: table_get ( zalsa , id) ;
583
586
584
587
// SAFETY: We hold the lock for the shard containing the value.
585
588
unsafe { self . hasher. hash_one( & * value. fields. get( ) ) }
@@ -651,7 +654,7 @@ where
651
654
unsafe fn value_hash < ' db > ( & ' db self , id : Id , zalsa : & ' db Zalsa ) -> u64 {
652
655
// This closure is only called if the table is resized. So while it's expensive
653
656
// to lookup all values, it will only happen rarely.
654
- let value = zalsa . table ( ) . get :: < Value < C > > ( id) ;
657
+ let value = Self :: table_get ( zalsa , id) ;
655
658
656
659
// SAFETY: We hold the lock for the shard containing the value.
657
660
unsafe { self . hasher . hash_one ( & * value. fields . get ( ) ) }
@@ -666,12 +669,12 @@ where
666
669
id : Id ,
667
670
key : & Key ,
668
671
zalsa : & ' db Zalsa ,
669
- found_value : & Cell < Option < & ' db Value < C > > > ,
672
+ found_value : & Cell < Option < & ' db ValueForConfiguration < C > > > ,
670
673
) -> bool
671
674
where
672
675
C :: Fields < ' db > : HashEqLike < Key > ,
673
676
{
674
- let value = zalsa . table ( ) . get :: < Value < C > > ( id) ;
677
+ let value = Self :: table_get ( zalsa , id) ;
675
678
found_value. set ( Some ( value) ) ;
676
679
677
680
// SAFETY: We hold the lock for the shard containing the value.
@@ -689,7 +692,7 @@ where
689
692
/// Lookup the data for an interned value based on its ID.
690
693
pub fn data < ' db > ( & ' db self , db : & ' db dyn Database , id : Id ) -> & ' db C :: Fields < ' db > {
691
694
let zalsa = db. zalsa ( ) ;
692
- let value = zalsa . table ( ) . get :: < Value < C > > ( id) ;
695
+ let value = Self :: table_get ( zalsa , id) ;
693
696
694
697
debug_assert ! (
695
698
{
@@ -731,8 +734,16 @@ where
731
734
pub fn entries < ' db > (
732
735
& ' db self ,
733
736
db : & ' db dyn crate :: Database ,
734
- ) -> impl Iterator < Item = & ' db Value < C > > {
735
- db. zalsa ( ) . table ( ) . slots_of :: < Value < C > > ( )
737
+ ) -> impl Iterator < Item = & ' db ValueForConfiguration < C > > {
738
+ db. zalsa ( ) . table ( ) . slots_of :: < ValueForConfiguration < C > > ( )
739
+ }
740
+
741
+ #[ inline]
742
+ fn table_get ( zalsa : & Zalsa , id : Id ) -> & ValueForConfiguration < C >
743
+ where
744
+ C : Configuration ,
745
+ {
746
+ zalsa. table ( ) . get :: < ValueForConfiguration < C > > ( id)
736
747
}
737
748
}
738
749
@@ -761,7 +772,7 @@ where
761
772
let current_revision = zalsa. current_revision ( ) ;
762
773
self . revision_queue . record ( current_revision) ;
763
774
764
- let value = zalsa. table ( ) . get :: < Value < C > > ( input) ;
775
+ let value = zalsa. table ( ) . get :: < ValueForConfiguration < C > > ( input) ;
765
776
766
777
// SAFETY: `value.shard` is guaranteed to be in-bounds for `self.shards`.
767
778
let _shard = unsafe { self . shards . get_unchecked ( value. shard as usize ) } . lock ( ) ;
@@ -810,10 +821,7 @@ where
810
821
}
811
822
}
812
823
813
- impl < C > Slot for Value < C >
814
- where
815
- C : Configuration ,
816
- {
824
+ impl < Fields : Send + Sync + ' static > Slot for Value < Fields > {
817
825
#[ inline( always) ]
818
826
unsafe fn memos ( & self , _current_revision : Revision ) -> & MemoTable {
819
827
// SAFETY: The fact that we have a reference to the `Value` means it must
0 commit comments