@@ -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 ; 7 ] > ( ) ] ;
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
///
@@ -165,13 +169,10 @@ impl ValueShared {
165
169
}
166
170
}
167
171
168
- impl < C > Value < C >
169
- where
170
- C : Configuration ,
171
- {
172
+ impl < Fields > Value < Fields > {
172
173
/// Fields of this interned struct.
173
174
#[ cfg( feature = "salsa_unstable" ) ]
174
- pub fn fields ( & self ) -> & C :: Fields < ' static > {
175
+ pub fn fields ( & self ) -> & Fields {
175
176
// SAFETY: The fact that this function is safe is technically unsound. However, interned
176
177
// values are only exposed if they have been validated in the current revision, which
177
178
// ensures that they are not reused while being accessed.
@@ -548,7 +549,9 @@ where
548
549
. unwrap_or ( ( Durability :: MAX , Revision :: max ( ) ) ) ;
549
550
550
551
// Allocate the value slot.
551
- let id = zalsa_local. allocate ( zalsa, self . ingredient_index , |id| Value :: < C > {
552
+ let id = zalsa_local. allocate ( zalsa, self . ingredient_index , |id| ValueForConfiguration :: <
553
+ C ,
554
+ > {
552
555
shard : shard_index as u16 ,
553
556
link : LinkedListLink :: new ( ) ,
554
557
memos : UnsafeCell :: new ( MemoTable :: default ( ) ) ,
@@ -561,7 +564,7 @@ where
561
564
} ) ,
562
565
} ) ;
563
566
564
- let value = zalsa . table ( ) . get :: < Value < C > > ( id) ;
567
+ let value = Self :: table_get ( zalsa , id) ;
565
568
// SAFETY: We hold the lock for the shard containing the value.
566
569
let value_shared = unsafe { & mut * value. shared . get ( ) } ;
567
570
@@ -580,7 +583,7 @@ where
580
583
shard. key_map . insert_unique ( hash, id, hasher) ;
581
584
582
585
debug_assert_eq ! ( hash, {
583
- let value = zalsa . table ( ) . get :: < Value < C >> ( id) ;
586
+ let value = Self :: table_get ( zalsa , id) ;
584
587
585
588
// SAFETY: We hold the lock for the shard containing the value.
586
589
unsafe { self . hasher. hash_one( & * value. fields. get( ) ) }
@@ -652,7 +655,7 @@ where
652
655
unsafe fn value_hash < ' db > ( & ' db self , id : Id , zalsa : & ' db Zalsa ) -> u64 {
653
656
// This closure is only called if the table is resized. So while it's expensive
654
657
// to lookup all values, it will only happen rarely.
655
- let value = zalsa . table ( ) . get :: < Value < C > > ( id) ;
658
+ let value = Self :: table_get ( zalsa , id) ;
656
659
657
660
// SAFETY: We hold the lock for the shard containing the value.
658
661
unsafe { self . hasher . hash_one ( & * value. fields . get ( ) ) }
@@ -667,12 +670,12 @@ where
667
670
id : Id ,
668
671
key : & Key ,
669
672
zalsa : & ' db Zalsa ,
670
- found_value : & Cell < Option < & ' db Value < C > > > ,
673
+ found_value : & Cell < Option < & ' db ValueForConfiguration < C > > > ,
671
674
) -> bool
672
675
where
673
676
C :: Fields < ' db > : HashEqLike < Key > ,
674
677
{
675
- let value = zalsa . table ( ) . get :: < Value < C > > ( id) ;
678
+ let value = Self :: table_get ( zalsa , id) ;
676
679
found_value. set ( Some ( value) ) ;
677
680
678
681
// SAFETY: We hold the lock for the shard containing the value.
@@ -690,7 +693,7 @@ where
690
693
/// Lookup the data for an interned value based on its ID.
691
694
pub fn data < ' db > ( & ' db self , db : & ' db dyn Database , id : Id ) -> & ' db C :: Fields < ' db > {
692
695
let zalsa = db. zalsa ( ) ;
693
- let value = zalsa . table ( ) . get :: < Value < C > > ( id) ;
696
+ let value = Self :: table_get ( zalsa , id) ;
694
697
695
698
debug_assert ! (
696
699
{
@@ -732,8 +735,16 @@ where
732
735
pub fn entries < ' db > (
733
736
& ' db self ,
734
737
db : & ' db dyn crate :: Database ,
735
- ) -> impl Iterator < Item = & ' db Value < C > > {
736
- db. zalsa ( ) . table ( ) . slots_of :: < Value < C > > ( )
738
+ ) -> impl Iterator < Item = & ' db ValueForConfiguration < C > > {
739
+ db. zalsa ( ) . table ( ) . slots_of :: < ValueForConfiguration < C > > ( )
740
+ }
741
+
742
+ #[ inline]
743
+ fn table_get ( zalsa : & Zalsa , id : Id ) -> & ValueForConfiguration < C >
744
+ where
745
+ C : Configuration ,
746
+ {
747
+ zalsa. table ( ) . get :: < ValueForConfiguration < C > > ( id)
737
748
}
738
749
}
739
750
@@ -762,7 +773,7 @@ where
762
773
let current_revision = zalsa. current_revision ( ) ;
763
774
self . revision_queue . record ( current_revision) ;
764
775
765
- let value = zalsa. table ( ) . get :: < Value < C > > ( input) ;
776
+ let value = zalsa. table ( ) . get :: < ValueForConfiguration < C > > ( input) ;
766
777
767
778
// SAFETY: `value.shard` is guaranteed to be in-bounds for `self.shards`.
768
779
let _shard = unsafe { self . shards . get_unchecked ( value. shard as usize ) } . lock ( ) ;
@@ -811,10 +822,7 @@ where
811
822
}
812
823
}
813
824
814
- impl < C > Slot for Value < C >
815
- where
816
- C : Configuration ,
817
- {
825
+ impl < Fields : Send + Sync + ' static > Slot for Value < Fields > {
818
826
#[ inline( always) ]
819
827
unsafe fn memos ( & self , _current_revision : Revision ) -> & MemoTable {
820
828
// SAFETY: The fact that we have a reference to the `Value` means it must
0 commit comments