@@ -22,15 +22,10 @@ public SolutionCompilationStateChecksums(
2222 Checksum solutionState ,
2323 Checksum sourceGeneratorExecutionVersionMap ,
2424 // These arrays are all the same length if present, and reference the same documents in the same order.
25- DocumentChecksumsAndIds ? frozenSourceGeneratedDocuments ,
26- ChecksumCollection ? frozenSourceGeneratedDocumentIdentities ,
25+ DocumentChecksumsAndIds frozenSourceGeneratedDocuments ,
26+ ChecksumCollection frozenSourceGeneratedDocumentIdentities ,
2727 ImmutableArray < DateTime > frozenSourceGeneratedDocumentGenerationDateTimes )
2828 {
29- // For the frozen source generated document info, we expect two either have both checksum collections or neither, and they
30- // should both be the same length as there is a 1:1 correspondence between them.
31- Contract . ThrowIfFalse ( frozenSourceGeneratedDocumentIdentities . HasValue == frozenSourceGeneratedDocuments . HasValue ) ;
32- Contract . ThrowIfFalse ( frozenSourceGeneratedDocumentIdentities ? . Count == frozenSourceGeneratedDocuments ? . Length ) ;
33-
3429 SolutionState = solutionState ;
3530 SourceGeneratorExecutionVersionMap = sourceGeneratorExecutionVersionMap ;
3631 FrozenSourceGeneratedDocuments = frozenSourceGeneratedDocuments ;
@@ -42,8 +37,8 @@ public SolutionCompilationStateChecksums(
4237 Checksum = Checksum . Create (
4338 SolutionState ,
4439 SourceGeneratorExecutionVersionMap ,
45- FrozenSourceGeneratedDocumentIdentities ? . Checksum ?? Checksum . Null ,
46- frozenSourceGeneratedDocuments ? . Checksum ?? Checksum . Null ) ;
40+ FrozenSourceGeneratedDocumentIdentities . Checksum ,
41+ frozenSourceGeneratedDocuments . Checksum ) ;
4742 }
4843
4944 public Checksum Checksum { get ; }
@@ -53,8 +48,8 @@ public SolutionCompilationStateChecksums(
5348 /// <summary>
5449 /// Checksums of the SourceTexts of the frozen documents directly. Not checksums of their DocumentStates.
5550 /// </summary>
56- public DocumentChecksumsAndIds ? FrozenSourceGeneratedDocuments { get ; }
57- public ChecksumCollection ? FrozenSourceGeneratedDocumentIdentities { get ; }
51+ public DocumentChecksumsAndIds FrozenSourceGeneratedDocuments { get ; }
52+ public ChecksumCollection FrozenSourceGeneratedDocumentIdentities { get ; }
5853
5954 // note: intentionally not part of the identity contract of this type.
6055 public ImmutableArray < DateTime > FrozenSourceGeneratedDocumentGenerationDateTimes { get ; }
@@ -64,8 +59,8 @@ public void AddAllTo(HashSet<Checksum> checksums)
6459 checksums . AddIfNotNullChecksum ( this . Checksum ) ;
6560 checksums . AddIfNotNullChecksum ( this . SolutionState ) ;
6661 checksums . AddIfNotNullChecksum ( this . SourceGeneratorExecutionVersionMap ) ;
67- this . FrozenSourceGeneratedDocumentIdentities ? . AddAllTo ( checksums ) ;
68- this . FrozenSourceGeneratedDocuments ? . AddAllTo ( checksums ) ;
62+ this . FrozenSourceGeneratedDocumentIdentities . AddAllTo ( checksums ) ;
63+ this . FrozenSourceGeneratedDocuments . AddAllTo ( checksums ) ;
6964 }
7065
7166 public void Serialize ( ObjectWriter writer )
@@ -76,13 +71,9 @@ public void Serialize(ObjectWriter writer)
7671 this . SourceGeneratorExecutionVersionMap . WriteTo ( writer ) ;
7772
7873 // Write out a boolean to know whether we'll have this extra information
79- writer . WriteBoolean ( this . FrozenSourceGeneratedDocumentIdentities . HasValue ) ;
80- if ( FrozenSourceGeneratedDocumentIdentities . HasValue )
81- {
82- this . FrozenSourceGeneratedDocuments ! . Value . WriteTo ( writer ) ;
83- this . FrozenSourceGeneratedDocumentIdentities . Value . WriteTo ( writer ) ;
84- writer . WriteArray ( this . FrozenSourceGeneratedDocumentGenerationDateTimes , static ( w , d ) => w . WriteInt64 ( d . Ticks ) ) ;
85- }
74+ this . FrozenSourceGeneratedDocuments . WriteTo ( writer ) ;
75+ this . FrozenSourceGeneratedDocumentIdentities . WriteTo ( writer ) ;
76+ writer . WriteArray ( this . FrozenSourceGeneratedDocumentGenerationDateTimes , static ( w , d ) => w . WriteInt64 ( d . Ticks ) ) ;
8677 }
8778
8879 public static SolutionCompilationStateChecksums Deserialize ( ObjectReader reader )
@@ -91,17 +82,9 @@ public static SolutionCompilationStateChecksums Deserialize(ObjectReader reader)
9182 var solutionState = Checksum . ReadFrom ( reader ) ;
9283 var sourceGeneratorExecutionVersionMap = Checksum . ReadFrom ( reader ) ;
9384
94- var hasFrozenSourceGeneratedDocuments = reader . ReadBoolean ( ) ;
95- DocumentChecksumsAndIds ? frozenSourceGeneratedDocumentTexts = null ;
96- ChecksumCollection ? frozenSourceGeneratedDocumentIdentities = null ;
97- ImmutableArray < DateTime > frozenSourceGeneratedDocumentGenerationDateTimes = default ;
98-
99- if ( hasFrozenSourceGeneratedDocuments )
100- {
101- frozenSourceGeneratedDocumentTexts = DocumentChecksumsAndIds . ReadFrom ( reader ) ;
102- frozenSourceGeneratedDocumentIdentities = ChecksumCollection . ReadFrom ( reader ) ;
103- frozenSourceGeneratedDocumentGenerationDateTimes = reader . ReadArray ( r => new DateTime ( r . ReadInt64 ( ) ) ) ;
104- }
85+ var frozenSourceGeneratedDocumentTexts = DocumentChecksumsAndIds . ReadFrom ( reader ) ;
86+ var frozenSourceGeneratedDocumentIdentities = ChecksumCollection . ReadFrom ( reader ) ;
87+ var frozenSourceGeneratedDocumentGenerationDateTimes = reader . ReadArray ( r => new DateTime ( r . ReadInt64 ( ) ) ) ;
10588
10689 var result = new SolutionCompilationStateChecksums (
10790 solutionState : solutionState ,
@@ -138,50 +121,44 @@ public async Task FindAsync<TArg>(
138121 onAssetFound ( this . SourceGeneratorExecutionVersionMap , filteredExecutionMap , arg ) ;
139122 }
140123
141- if ( compilationState . FrozenSourceGeneratedDocumentStates != null )
124+ // This could either be the checksum for the text (which we'll use our regular helper for first)...
125+ if ( assetPath . IncludeSolutionFrozenSourceGeneratedDocumentText )
142126 {
143- Contract . ThrowIfFalse ( FrozenSourceGeneratedDocumentIdentities . HasValue ) ;
144- Contract . ThrowIfFalse ( FrozenSourceGeneratedDocuments . HasValue ) ;
145-
146- // This could either be the checksum for the text (which we'll use our regular helper for first)...
147- if ( assetPath . IncludeSolutionFrozenSourceGeneratedDocumentText )
148- {
149- await ChecksumCollection . FindAsync (
150- new AssetPath ( AssetPathKind . DocumentText , assetPath . ProjectId , assetPath . DocumentId ) ,
151- compilationState . FrozenSourceGeneratedDocumentStates , searchingChecksumsLeft , onAssetFound , arg , cancellationToken ) . ConfigureAwait ( false ) ;
152- }
127+ await ChecksumCollection . FindAsync (
128+ new AssetPath ( AssetPathKind . DocumentText , assetPath . ProjectId , assetPath . DocumentId ) ,
129+ compilationState . FrozenSourceGeneratedDocumentStates , searchingChecksumsLeft , onAssetFound , arg , cancellationToken ) . ConfigureAwait ( false ) ;
130+ }
153131
154- // ... or one of the identities. In this case, we'll use the fact that there's a 1:1 correspondence between the
155- // two collections we hold onto.
156- if ( assetPath . IncludeSolutionFrozenSourceGeneratedDocumentIdentities )
132+ // ... or one of the identities. In this case, we'll use the fact that there's a 1:1 correspondence between the
133+ // two collections we hold onto.
134+ if ( assetPath . IncludeSolutionFrozenSourceGeneratedDocumentIdentities )
135+ {
136+ var documentId = assetPath . DocumentId ;
137+ if ( documentId != null )
157138 {
158- var documentId = assetPath . DocumentId ;
159- if ( documentId != null )
139+ // If the caller is asking for a specific document, we can just look it up directly.
140+ var index = FrozenSourceGeneratedDocuments . Ids . IndexOf ( documentId ) ;
141+ if ( index >= 0 )
160142 {
161- // If the caller is asking for a specific document, we can just look it up directly.
162- var index = FrozenSourceGeneratedDocuments . Value . Ids . IndexOf ( documentId ) ;
163- if ( index >= 0 )
143+ var identityChecksum = FrozenSourceGeneratedDocumentIdentities . Children [ index ] ;
144+ if ( searchingChecksumsLeft . Remove ( identityChecksum ) )
164145 {
165- var identityChecksum = FrozenSourceGeneratedDocumentIdentities . Value . Children [ index ] ;
166- if ( searchingChecksumsLeft . Remove ( identityChecksum ) )
167- {
168- Contract . ThrowIfFalse ( compilationState . FrozenSourceGeneratedDocumentStates . TryGetState ( documentId , out var state ) ) ;
169- onAssetFound ( identityChecksum , state . Identity , arg ) ;
170- }
146+ Contract . ThrowIfFalse ( compilationState . FrozenSourceGeneratedDocumentStates . TryGetState ( documentId , out var state ) ) ;
147+ onAssetFound ( identityChecksum , state . Identity , arg ) ;
171148 }
172149 }
173- else
150+ }
151+ else
152+ {
153+ // Otherwise, we'll have to search through all of them.
154+ for ( var i = 0 ; i < FrozenSourceGeneratedDocumentIdentities . Count ; i ++ )
174155 {
175- // Otherwise, we'll have to search through all of them.
176- for ( var i = 0 ; i < FrozenSourceGeneratedDocumentIdentities . Value . Count ; i ++ )
156+ var identityChecksum = FrozenSourceGeneratedDocumentIdentities [ 0 ] ;
157+ if ( searchingChecksumsLeft . Remove ( identityChecksum ) )
177158 {
178- var identityChecksum = FrozenSourceGeneratedDocumentIdentities . Value [ 0 ] ;
179- if ( searchingChecksumsLeft . Remove ( identityChecksum ) )
180- {
181- var id = FrozenSourceGeneratedDocuments . Value . Ids [ i ] ;
182- Contract . ThrowIfFalse ( compilationState . FrozenSourceGeneratedDocumentStates . TryGetState ( id , out var state ) ) ;
183- onAssetFound ( identityChecksum , state . Identity , arg ) ;
184- }
159+ var id = FrozenSourceGeneratedDocuments . Ids [ i ] ;
160+ Contract . ThrowIfFalse ( compilationState . FrozenSourceGeneratedDocumentStates . TryGetState ( id , out var state ) ) ;
161+ onAssetFound ( identityChecksum , state . Identity , arg ) ;
185162 }
186163 }
187164 }
0 commit comments