-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Make frozen doc state non-nullable #77896
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
CyrusNajmabadi
merged 6 commits into
dotnet:release/dev17.15
from
CyrusNajmabadi:frozenDocs
Mar 31, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1aa5389
Make frozen doc state non-nullable
CyrusNajmabadi 8e4fdd8
Simplify
CyrusNajmabadi a1f4df0
Simplify serialization
CyrusNajmabadi edf3eae
Merge branch 'release/dev17.15' into frozenDocs
CyrusNajmabadi 0b1d99c
Fix
CyrusNajmabadi a1f0c49
Fix
CyrusNajmabadi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,15 +22,10 @@ public SolutionCompilationStateChecksums( | |
| Checksum solutionState, | ||
| Checksum sourceGeneratorExecutionVersionMap, | ||
| // These arrays are all the same length if present, and reference the same documents in the same order. | ||
| DocumentChecksumsAndIds? frozenSourceGeneratedDocuments, | ||
| ChecksumCollection? frozenSourceGeneratedDocumentIdentities, | ||
| DocumentChecksumsAndIds frozenSourceGeneratedDocuments, | ||
| ChecksumCollection frozenSourceGeneratedDocumentIdentities, | ||
| ImmutableArray<DateTime> frozenSourceGeneratedDocumentGenerationDateTimes) | ||
| { | ||
| // For the frozen source generated document info, we expect two either have both checksum collections or neither, and they | ||
| // should both be the same length as there is a 1:1 correspondence between them. | ||
| Contract.ThrowIfFalse(frozenSourceGeneratedDocumentIdentities.HasValue == frozenSourceGeneratedDocuments.HasValue); | ||
| Contract.ThrowIfFalse(frozenSourceGeneratedDocumentIdentities?.Count == frozenSourceGeneratedDocuments?.Length); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you still want to keep this assertion that the lengths match?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will add back. |
||
|
|
||
| SolutionState = solutionState; | ||
| SourceGeneratorExecutionVersionMap = sourceGeneratorExecutionVersionMap; | ||
| FrozenSourceGeneratedDocuments = frozenSourceGeneratedDocuments; | ||
|
|
@@ -42,8 +37,8 @@ public SolutionCompilationStateChecksums( | |
| Checksum = Checksum.Create( | ||
| SolutionState, | ||
| SourceGeneratorExecutionVersionMap, | ||
| FrozenSourceGeneratedDocumentIdentities?.Checksum ?? Checksum.Null, | ||
| frozenSourceGeneratedDocuments?.Checksum ?? Checksum.Null); | ||
| FrozenSourceGeneratedDocumentIdentities.Checksum, | ||
| frozenSourceGeneratedDocuments.Checksum); | ||
| } | ||
|
|
||
| public Checksum Checksum { get; } | ||
|
|
@@ -53,8 +48,8 @@ public SolutionCompilationStateChecksums( | |
| /// <summary> | ||
| /// Checksums of the SourceTexts of the frozen documents directly. Not checksums of their DocumentStates. | ||
| /// </summary> | ||
| public DocumentChecksumsAndIds? FrozenSourceGeneratedDocuments { get; } | ||
| public ChecksumCollection? FrozenSourceGeneratedDocumentIdentities { get; } | ||
| public DocumentChecksumsAndIds FrozenSourceGeneratedDocuments { get; } | ||
| public ChecksumCollection FrozenSourceGeneratedDocumentIdentities { get; } | ||
|
|
||
| // note: intentionally not part of the identity contract of this type. | ||
| public ImmutableArray<DateTime> FrozenSourceGeneratedDocumentGenerationDateTimes { get; } | ||
|
|
@@ -64,8 +59,8 @@ public void AddAllTo(HashSet<Checksum> checksums) | |
| checksums.AddIfNotNullChecksum(this.Checksum); | ||
| checksums.AddIfNotNullChecksum(this.SolutionState); | ||
| checksums.AddIfNotNullChecksum(this.SourceGeneratorExecutionVersionMap); | ||
| this.FrozenSourceGeneratedDocumentIdentities?.AddAllTo(checksums); | ||
| this.FrozenSourceGeneratedDocuments?.AddAllTo(checksums); | ||
| this.FrozenSourceGeneratedDocumentIdentities.AddAllTo(checksums); | ||
| this.FrozenSourceGeneratedDocuments.AddAllTo(checksums); | ||
| } | ||
|
|
||
| public void Serialize(ObjectWriter writer) | ||
|
|
@@ -76,13 +71,9 @@ public void Serialize(ObjectWriter writer) | |
| this.SourceGeneratorExecutionVersionMap.WriteTo(writer); | ||
|
|
||
| // Write out a boolean to know whether we'll have this extra information | ||
| writer.WriteBoolean(this.FrozenSourceGeneratedDocumentIdentities.HasValue); | ||
| if (FrozenSourceGeneratedDocumentIdentities.HasValue) | ||
| { | ||
| this.FrozenSourceGeneratedDocuments!.Value.WriteTo(writer); | ||
| this.FrozenSourceGeneratedDocumentIdentities.Value.WriteTo(writer); | ||
| writer.WriteArray(this.FrozenSourceGeneratedDocumentGenerationDateTimes, static (w, d) => w.WriteInt64(d.Ticks)); | ||
| } | ||
| this.FrozenSourceGeneratedDocuments.WriteTo(writer); | ||
| this.FrozenSourceGeneratedDocumentIdentities.WriteTo(writer); | ||
| writer.WriteArray(this.FrozenSourceGeneratedDocumentGenerationDateTimes, static (w, d) => w.WriteInt64(d.Ticks)); | ||
| } | ||
|
|
||
| public static SolutionCompilationStateChecksums Deserialize(ObjectReader reader) | ||
|
|
@@ -91,17 +82,9 @@ public static SolutionCompilationStateChecksums Deserialize(ObjectReader reader) | |
| var solutionState = Checksum.ReadFrom(reader); | ||
| var sourceGeneratorExecutionVersionMap = Checksum.ReadFrom(reader); | ||
|
|
||
| var hasFrozenSourceGeneratedDocuments = reader.ReadBoolean(); | ||
| DocumentChecksumsAndIds? frozenSourceGeneratedDocumentTexts = null; | ||
| ChecksumCollection? frozenSourceGeneratedDocumentIdentities = null; | ||
| ImmutableArray<DateTime> frozenSourceGeneratedDocumentGenerationDateTimes = default; | ||
|
|
||
| if (hasFrozenSourceGeneratedDocuments) | ||
| { | ||
| frozenSourceGeneratedDocumentTexts = DocumentChecksumsAndIds.ReadFrom(reader); | ||
| frozenSourceGeneratedDocumentIdentities = ChecksumCollection.ReadFrom(reader); | ||
| frozenSourceGeneratedDocumentGenerationDateTimes = reader.ReadArray(r => new DateTime(r.ReadInt64())); | ||
| } | ||
| var frozenSourceGeneratedDocumentTexts = DocumentChecksumsAndIds.ReadFrom(reader); | ||
| var frozenSourceGeneratedDocumentIdentities = ChecksumCollection.ReadFrom(reader); | ||
| var frozenSourceGeneratedDocumentGenerationDateTimes = reader.ReadArray(r => new DateTime(r.ReadInt64())); | ||
|
|
||
| var result = new SolutionCompilationStateChecksums( | ||
| solutionState: solutionState, | ||
|
|
@@ -138,50 +121,44 @@ public async Task FindAsync<TArg>( | |
| onAssetFound(this.SourceGeneratorExecutionVersionMap, filteredExecutionMap, arg); | ||
| } | ||
|
|
||
| if (compilationState.FrozenSourceGeneratedDocumentStates != null) | ||
| // This could either be the checksum for the text (which we'll use our regular helper for first)... | ||
| if (assetPath.IncludeSolutionFrozenSourceGeneratedDocumentText) | ||
| { | ||
| Contract.ThrowIfFalse(FrozenSourceGeneratedDocumentIdentities.HasValue); | ||
| Contract.ThrowIfFalse(FrozenSourceGeneratedDocuments.HasValue); | ||
|
|
||
| // This could either be the checksum for the text (which we'll use our regular helper for first)... | ||
| if (assetPath.IncludeSolutionFrozenSourceGeneratedDocumentText) | ||
| { | ||
| await ChecksumCollection.FindAsync( | ||
| new AssetPath(AssetPathKind.DocumentText, assetPath.ProjectId, assetPath.DocumentId), | ||
| compilationState.FrozenSourceGeneratedDocumentStates, searchingChecksumsLeft, onAssetFound, arg, cancellationToken).ConfigureAwait(false); | ||
| } | ||
| await ChecksumCollection.FindAsync( | ||
| new AssetPath(AssetPathKind.DocumentText, assetPath.ProjectId, assetPath.DocumentId), | ||
| compilationState.FrozenSourceGeneratedDocumentStates, searchingChecksumsLeft, onAssetFound, arg, cancellationToken).ConfigureAwait(false); | ||
| } | ||
|
|
||
| // ... or one of the identities. In this case, we'll use the fact that there's a 1:1 correspondence between the | ||
| // two collections we hold onto. | ||
| if (assetPath.IncludeSolutionFrozenSourceGeneratedDocumentIdentities) | ||
| // ... or one of the identities. In this case, we'll use the fact that there's a 1:1 correspondence between the | ||
| // two collections we hold onto. | ||
| if (assetPath.IncludeSolutionFrozenSourceGeneratedDocumentIdentities) | ||
| { | ||
| var documentId = assetPath.DocumentId; | ||
| if (documentId != null) | ||
| { | ||
| var documentId = assetPath.DocumentId; | ||
| if (documentId != null) | ||
| // If the caller is asking for a specific document, we can just look it up directly. | ||
| var index = FrozenSourceGeneratedDocuments.Ids.IndexOf(documentId); | ||
| if (index >= 0) | ||
| { | ||
| // If the caller is asking for a specific document, we can just look it up directly. | ||
| var index = FrozenSourceGeneratedDocuments.Value.Ids.IndexOf(documentId); | ||
| if (index >= 0) | ||
| var identityChecksum = FrozenSourceGeneratedDocumentIdentities.Children[index]; | ||
| if (searchingChecksumsLeft.Remove(identityChecksum)) | ||
| { | ||
| var identityChecksum = FrozenSourceGeneratedDocumentIdentities.Value.Children[index]; | ||
| if (searchingChecksumsLeft.Remove(identityChecksum)) | ||
| { | ||
| Contract.ThrowIfFalse(compilationState.FrozenSourceGeneratedDocumentStates.TryGetState(documentId, out var state)); | ||
| onAssetFound(identityChecksum, state.Identity, arg); | ||
| } | ||
| Contract.ThrowIfFalse(compilationState.FrozenSourceGeneratedDocumentStates.TryGetState(documentId, out var state)); | ||
| onAssetFound(identityChecksum, state.Identity, arg); | ||
| } | ||
| } | ||
| else | ||
| } | ||
| else | ||
| { | ||
| // Otherwise, we'll have to search through all of them. | ||
| for (var i = 0; i < FrozenSourceGeneratedDocumentIdentities.Count; i++) | ||
| { | ||
| // Otherwise, we'll have to search through all of them. | ||
| for (var i = 0; i < FrozenSourceGeneratedDocumentIdentities.Value.Count; i++) | ||
| var identityChecksum = FrozenSourceGeneratedDocumentIdentities[0]; | ||
| if (searchingChecksumsLeft.Remove(identityChecksum)) | ||
| { | ||
| var identityChecksum = FrozenSourceGeneratedDocumentIdentities.Value[0]; | ||
| if (searchingChecksumsLeft.Remove(identityChecksum)) | ||
| { | ||
| var id = FrozenSourceGeneratedDocuments.Value.Ids[i]; | ||
| Contract.ThrowIfFalse(compilationState.FrozenSourceGeneratedDocumentStates.TryGetState(id, out var state)); | ||
| onAssetFound(identityChecksum, state.Identity, arg); | ||
| } | ||
| var id = FrozenSourceGeneratedDocuments.Ids[i]; | ||
| Contract.ThrowIfFalse(compilationState.FrozenSourceGeneratedDocumentStates.TryGetState(id, out var state)); | ||
| onAssetFound(identityChecksum, state.Identity, arg); | ||
| } | ||
| } | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need Optional here anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call. Simplifying.