From 7f41dad5e06b61b430bcec13448a391e654c1667 Mon Sep 17 00:00:00 2001 From: CyrusNajmabadi Date: Mon, 12 Jun 2017 18:56:47 -0700 Subject: [PATCH] Revert "Cache symbol finding results to help callers who are making many calls into it." This reverts commit 95a2444883741b61d44385d9bb7040ba33778ca3. --- .../FindReferences/DependentTypeFinder.cs | 85 ++++--------------- 1 file changed, 17 insertions(+), 68 deletions(-) diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/DependentTypeFinder.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/DependentTypeFinder.cs index 2f9f06d69bf..ee601d73a63 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/DependentTypeFinder.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/DependentTypeFinder.cs @@ -1,15 +1,12 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections.Concurrent; using System.Collections.Generic; using System.Collections.Immutable; using System.Diagnostics; using System.Linq; -using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.LanguageServices; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Shared.Utilities; using Roslyn.Utilities; @@ -18,8 +15,6 @@ namespace Microsoft.CodeAnalysis.FindSymbols { using SymbolAndProjectIdSet = HashSet>; - using RelatedTypeCache = ConditionalWeakTable>>>>; - /// /// Provides helper methods for finding dependent types (derivations, implementations, /// etc.) across a solution. The results found are returned in pairs of s @@ -43,44 +38,17 @@ internal static class DependentTypeFinder private static readonly ObjectPool s_setPool = new ObjectPool( () => new SymbolAndProjectIdSet(SymbolAndProjectIdComparer.SymbolEquivalenceInstance)); - // Caches from a types to their related types (in the context of a specific solution). - // Kept as a cache so that clients who make many calls into us won't end up computing - // the same data over and over again. Will be let go the moment the solution they're - // based off of is no longer alive. - - private static readonly RelatedTypeCache s_typeToImmediatelyDerivedClassesMap = new RelatedTypeCache(); - private static readonly RelatedTypeCache s_typeToTransitivelyDerivedClassesMap = new RelatedTypeCache(); - private static readonly RelatedTypeCache s_typeToTransitivelyImplementingTypesMap = new RelatedTypeCache(); - private static readonly RelatedTypeCache s_typeToImmediatelyDerivedAndImplementingTypesMap = new RelatedTypeCache(); - - public static async Task>> FindTypesFromCacheOrComputeAsync( - INamedTypeSymbol type, - Solution solution, - RelatedTypeCache cache, - Func>>> findAsync, - CancellationToken cancellationToken) - { - var dictionary = cache.GetOrCreateValue(solution); - var lazy = dictionary.GetOrAdd(type, new AsyncLazy>>( - asynchronousComputeFunction: findAsync, cacheResult: true)); - - return await lazy.GetValueAsync(cancellationToken).ConfigureAwait(false); - } - /// /// Used for implementing the Inherited-By relation for progression. /// - public static Task>> FindImmediatelyDerivedClassesAsync( + internal static Task>> FindImmediatelyDerivedClassesAsync( INamedTypeSymbol type, Solution solution, CancellationToken cancellationToken) { - return FindTypesFromCacheOrComputeAsync( - type, solution, s_typeToImmediatelyDerivedClassesMap, - c => FindDerivedClassesAsync( - SymbolAndProjectId.Create(type, projectId: null), solution, projects: null, - transitive: false, cancellationToken: c), - cancellationToken); + return FindDerivedClassesAsync( + SymbolAndProjectId.Create(type, projectId: null), solution, projects: null, + transitive: false, cancellationToken: cancellationToken); } /// @@ -92,12 +60,9 @@ internal static class DependentTypeFinder IImmutableSet projects, CancellationToken cancellationToken) { - return FindTypesFromCacheOrComputeAsync( - type, solution, s_typeToTransitivelyDerivedClassesMap, - c => FindDerivedClassesAsync( - SymbolAndProjectId.Create(type, projectId: null), solution, projects, - transitive: true, cancellationToken: c), - cancellationToken); + return FindDerivedClassesAsync( + SymbolAndProjectId.Create(type, projectId: null), solution, projects, + transitive: true, cancellationToken: cancellationToken); } private static Task>> FindDerivedClassesAsync( @@ -130,19 +95,7 @@ internal static class DependentTypeFinder /// Implementation of for /// s /// - public static Task>> FindTransitivelyImplementingTypesAsync( - INamedTypeSymbol type, - Solution solution, - IImmutableSet projects, - CancellationToken cancellationToken) - { - return FindTypesFromCacheOrComputeAsync( - type, solution, s_typeToTransitivelyImplementingTypesMap, - c => FindTransitivelyImplementingTypesWorkerAsync(type, solution, projects, c), - cancellationToken); - } - - private static async Task>> FindTransitivelyImplementingTypesWorkerAsync( + public static async Task>> FindTransitivelyImplementingTypesAsync( INamedTypeSymbol type, Solution solution, IImmutableSet projects, @@ -160,17 +113,14 @@ internal static class DependentTypeFinder /// /// Used for implementing the Inherited-By relation for progression. /// - public static Task>> FindImmediatelyDerivedAndImplementingTypesAsync( + internal static Task>> FindImmediatelyDerivedAndImplementingTypesAsync( INamedTypeSymbol type, Solution solution, CancellationToken cancellationToken) { - return FindTypesFromCacheOrComputeAsync( - type, solution, s_typeToImmediatelyDerivedAndImplementingTypesMap, - c => FindDerivedAndImplementingTypesAsync( - SymbolAndProjectId.Create(type, projectId: null), solution, projects: null, - transitive: false, cancellationToken: c), - cancellationToken); + return FindDerivedAndImplementingTypesAsync( + SymbolAndProjectId.Create(type, projectId: null), solution, projects: null, + transitive: false, cancellationToken: cancellationToken); } private static Task>> FindDerivedAndImplementingTypesAsync( @@ -603,8 +553,7 @@ internal static class DependentTypeFinder var typesToSearchFor = CreateSymbolAndProjectIdSet(); typesToSearchFor.AddAll(sourceAndMetadataTypes); - var caseSensitive = project.LanguageServices.GetService().IsCaseSensitive; - var inheritanceQuery = new InheritanceQuery(sourceAndMetadataTypes, caseSensitive); + var inheritanceQuery = new InheritanceQuery(sourceAndMetadataTypes); // As long as there are new types to search for, keep looping. while (typesToSearchFor.Count > 0) @@ -613,10 +562,10 @@ internal static class DependentTypeFinder inheritanceQuery.TypeNames.AddRange(typesToSearchFor.Select(c => c.Symbol.Name)); // Search all the documents of this project in parallel. - var tasks = project.Documents.Select(d => Task.Run(() => FindImmediatelyInheritingTypesInDocumentAsync( + var tasks = project.Documents.Select(d => FindImmediatelyInheritingTypesInDocumentAsync( d, typesToSearchFor, inheritanceQuery, cachedModels, cachedInfos, - sourceTypeImmediatelyMatches, cancellationToken), cancellationToken)).ToArray(); + sourceTypeImmediatelyMatches, cancellationToken)).ToArray(); await Task.WhenAll(tasks).ConfigureAwait(false); @@ -771,13 +720,13 @@ private class InheritanceQuery public readonly HashSet TypeNames; - public InheritanceQuery(SymbolAndProjectIdSet sourceAndMetadataTypes, bool caseSensitive) + public InheritanceQuery(SymbolAndProjectIdSet sourceAndMetadataTypes) { DerivesFromSystemObject = sourceAndMetadataTypes.Any(t => t.Symbol.SpecialType == SpecialType.System_Object); DerivesFromSystemValueType = sourceAndMetadataTypes.Any(t => t.Symbol.SpecialType == SpecialType.System_ValueType); DerivesFromSystemEnum = sourceAndMetadataTypes.Any(t => t.Symbol.SpecialType == SpecialType.System_Enum); DerivesFromSystemMulticastDelegate = sourceAndMetadataTypes.Any(t => t.Symbol.SpecialType == SpecialType.System_MulticastDelegate); - TypeNames = caseSensitive ? new HashSet() : new HashSet(StringComparer.OrdinalIgnoreCase); + TypeNames = new HashSet(StringComparer.OrdinalIgnoreCase); } } -- GitLab