-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Use generics in syncing code. #72929
Changes from 5 commits
fbae44f
4f41b24
3f0a815
d8d01db
d9b8df6
58bad7e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,24 +39,24 @@ public override async ValueTask<T> GetAssetAsync<T>( | |
using var _1 = PooledHashSet<Checksum>.GetInstance(out var checksums); | ||
checksums.Add(checksum); | ||
|
||
using var _2 = PooledDictionary<Checksum, object>.GetInstance(out var results); | ||
using var _2 = PooledDictionary<Checksum, T>.GetInstance(out var results); | ||
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. the method this is in is already generic. so this now allows that generic information to flow into SynchronizeAssetsAsync |
||
await this.SynchronizeAssetsAsync(assetPath, checksums, results, cancellationToken).ConfigureAwait(false); | ||
|
||
return (T)results[checksum]; | ||
return results[checksum]; | ||
} | ||
|
||
public override async ValueTask<ImmutableArray<(Checksum checksum, T asset)>> GetAssetsAsync<T>( | ||
AssetPath assetPath, HashSet<Checksum> checksums, CancellationToken cancellationToken) | ||
{ | ||
using var _ = PooledDictionary<Checksum, object>.GetInstance(out var results); | ||
using var _ = PooledDictionary<Checksum, T>.GetInstance(out var results); | ||
|
||
await this.SynchronizeAssetsAsync(assetPath, checksums, results, cancellationToken).ConfigureAwait(false); | ||
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. the method this is in is already generic. so this now allows that generic information to flow into SynchronizeAssetsAsync |
||
|
||
var result = new (Checksum checksum, T asset)[checksums.Count]; | ||
var index = 0; | ||
foreach (var (checksum, assetObject) in results) | ||
{ | ||
result[index] = (checksum, (T)assetObject); | ||
result[index] = (checksum, assetObject); | ||
index++; | ||
} | ||
|
||
|
@@ -98,7 +98,7 @@ async ValueTask SynchronizeSolutionAssetsWorkerAsync() | |
|
||
// second, get direct children of the solution compilation state. | ||
compilationStateChecksums.AddAllTo(checksums); | ||
await this.SynchronizeAssetsAsync(assetPath: AssetPath.SolutionOnly, checksums, results: null, cancellationToken).ConfigureAwait(false); | ||
await this.SynchronizeAssetsAsync<object>(assetPath: AssetPath.SolutionOnly, checksums, results: null, cancellationToken).ConfigureAwait(false); | ||
|
||
// third, get direct children of the solution state. | ||
var stateChecksums = await this.GetAssetAsync<SolutionStateChecksums>( | ||
|
@@ -151,7 +151,7 @@ async ValueTask SynchronizeProjectAssetsWorkerAsync() | |
AddAll(checksums, projectChecksums.AnalyzerConfigDocuments.Checksums); | ||
|
||
// First synchronize all the top-level info about this project. | ||
await this.SynchronizeAssetsAsync( | ||
await this.SynchronizeAssetsAsync<object>( | ||
assetPath: AssetPath.ProjectAndDocuments(projectChecksums.ProjectId), checksums, results: null, cancellationToken).ConfigureAwait(false); | ||
|
||
checksums.Clear(); | ||
|
@@ -161,7 +161,7 @@ await this.SynchronizeAssetsAsync( | |
await CollectChecksumChildrenAsync(checksums, projectChecksums.AdditionalDocuments).ConfigureAwait(false); | ||
await CollectChecksumChildrenAsync(checksums, projectChecksums.AnalyzerConfigDocuments).ConfigureAwait(false); | ||
|
||
await this.SynchronizeAssetsAsync( | ||
await this.SynchronizeAssetsAsync<object>( | ||
assetPath: AssetPath.ProjectAndDocuments(projectChecksums.ProjectId), checksums, results: null, cancellationToken).ConfigureAwait(false); | ||
} | ||
|
||
|
@@ -185,8 +185,8 @@ static void AddAll(HashSet<Checksum> checksums, ChecksumCollection checksumColle | |
} | ||
} | ||
|
||
public async ValueTask SynchronizeAssetsAsync( | ||
AssetPath assetPath, HashSet<Checksum> checksums, Dictionary<Checksum, object>? results, CancellationToken cancellationToken) | ||
public async ValueTask SynchronizeAssetsAsync<T>( | ||
AssetPath assetPath, HashSet<Checksum> checksums, Dictionary<Checksum, T>? results, CancellationToken cancellationToken) | ||
{ | ||
Contract.ThrowIfTrue(checksums.Contains(Checksum.Null)); | ||
if (checksums.Count == 0) | ||
|
@@ -209,7 +209,7 @@ public async ValueTask SynchronizeAssetsAsync( | |
missingChecksumsCount = 0; | ||
foreach (var checksum in checksums) | ||
{ | ||
if (_assetCache.TryGetAsset<object>(checksum, out var existing)) | ||
if (_assetCache.TryGetAsset<T>(checksum, out var existing)) | ||
{ | ||
AddResult(checksum, existing); | ||
} | ||
|
@@ -238,7 +238,7 @@ public async ValueTask SynchronizeAssetsAsync( | |
if (missingChecksumsCount > 0) | ||
{ | ||
var missingChecksumsMemory = new ReadOnlyMemory<Checksum>(missingChecksums, 0, missingChecksumsCount); | ||
var missingAssets = await RequestAssetsAsync(assetPath, missingChecksumsMemory, cancellationToken).ConfigureAwait(false); | ||
var missingAssets = await RequestAssetsAsync<T>(assetPath, missingChecksumsMemory, cancellationToken).ConfigureAwait(false); | ||
|
||
Contract.ThrowIfTrue(missingChecksumsMemory.Length != missingAssets.Length); | ||
|
||
|
@@ -248,7 +248,7 @@ public async ValueTask SynchronizeAssetsAsync( | |
var missingAsset = missingAssets[i]; | ||
|
||
AddResult(missingChecksum, missingAsset); | ||
_assetCache.GetOrAdd(missingChecksum, missingAsset); | ||
_assetCache.GetOrAdd(missingChecksum, missingAsset!); | ||
} | ||
} | ||
|
||
|
@@ -258,14 +258,14 @@ public async ValueTask SynchronizeAssetsAsync( | |
|
||
return; | ||
|
||
void AddResult(Checksum checksum, object result) | ||
void AddResult(Checksum checksum, T result) | ||
{ | ||
if (results != null) | ||
results[checksum] = result; | ||
} | ||
} | ||
|
||
private async ValueTask<ImmutableArray<object>> RequestAssetsAsync( | ||
private async ValueTask<ImmutableArray<T>> RequestAssetsAsync<T>( | ||
AssetPath assetPath, ReadOnlyMemory<Checksum> checksums, CancellationToken cancellationToken) | ||
{ | ||
#if NETCOREAPP | ||
|
@@ -277,6 +277,6 @@ private async ValueTask<ImmutableArray<object>> RequestAssetsAsync( | |
if (checksums.Length == 0) | ||
return []; | ||
|
||
return await _assetSource.GetAssetsAsync(_solutionChecksum, assetPath, checksums, _serializerService, cancellationToken).ConfigureAwait(false); | ||
return await _assetSource.GetAssetsAsync<T>(_solutionChecksum, assetPath, checksums, _serializerService, cancellationToken).ConfigureAwait(false); | ||
} | ||
} |
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.
<object>
is used when the request is genuinely asking for heterogenous data.