{"action":"created","comment":{"url":"https://api.github.com/repos/dotnet/roslyn/pulls/comments/59463565","id":59463565,"diff_hunk":"@@ -0,0 +1,218 @@\n+﻿// Copyright (c) Microsoft.  All Rights Reserved.  Licensed under the Apache License, Version 2.0.  See License.txt in the project root for license information.\n+\n+using System;\n+using System.Collections.Generic;\n+using System.Collections.Immutable;\n+using System.Diagnostics;\n+using System.Linq;\n+using System.Runtime.CompilerServices;\n+using System.Threading;\n+using System.Threading.Tasks;\n+using Microsoft.CodeAnalysis.ErrorReporting;\n+using Roslyn.Utilities;\n+\n+namespace Microsoft.CodeAnalysis.Diagnostics.EngineV2\n+{\n+    internal partial class DiagnosticIncrementalAnalyzer\n+    {\n+        /// <summary>\n+        /// This cache CompilationWithAnalyzer for active/open files. \n+        /// This will aggressively let go cached compilationWithAnalyzers to not hold them into memory too long.\n+        /// </summary>\n+        private class CompilationManager\n+        {\n+            private readonly DiagnosticIncrementalAnalyzer _owner;\n+            private ConditionalWeakTable<Project, CompilationWithAnalyzers> _map;\n+\n+            public CompilationManager(DiagnosticIncrementalAnalyzer owner)\n+            {\n+                _owner = owner;\n+                _map = new ConditionalWeakTable<Project, CompilationWithAnalyzers>();\n+            }\n+\n+            /// <summary>\n+            /// Return CompilationWithAnalyzer for given project with given stateSets\n+            /// </summary>\n+            public async Task<CompilationWithAnalyzers> GetAnalyzerDriverAsync(Project project, IEnumerable<StateSet> stateSets, CancellationToken cancellationToken)\n+            {\n+                if (!project.SupportsCompilation)\n+                {\n+                    return null;\n+                }\n+\n+                CompilationWithAnalyzers analyzerDriverOpt;\n+                if (_map.TryGetValue(project, out analyzerDriverOpt))\n+                {\n+                    // we have cached one, return that.\n+                    AssertAnalyzers(analyzerDriverOpt, stateSets);\n+                    return analyzerDriverOpt;\n+                }\n+\n+                // Create driver that holds onto compilation and associated analyzers\n+                var includeSuppressedDiagnostics = true;\n+                var newAnalyzerDriverOpt = await CreateAnalyzerDriverAsync(project, stateSets, includeSuppressedDiagnostics, cancellationToken).ConfigureAwait(false);\n+\n+                // Add new analyzer driver to the map\n+                analyzerDriverOpt = _map.GetValue(project, _ => newAnalyzerDriverOpt);\n+\n+                // if somebody has beat us, make sure analyzers are good.\n+                if (analyzerDriverOpt != newAnalyzerDriverOpt)\n+                {\n+                    AssertAnalyzers(analyzerDriverOpt, stateSets);\n+                }\n+\n+                // return driver\n+                return analyzerDriverOpt;\n+            }\n+\n+            public Task<CompilationWithAnalyzers> CreateAnalyzerDriverAsync(Project project, IEnumerable<StateSet> stateSets, bool includeSuppressedDiagnostics, CancellationToken cancellationToken)\n+            {\n+                var analyzers = stateSets.Select(s => s.Analyzer).ToImmutableArrayOrEmpty();\n+                return CreateAnalyzerDriverAsync(project, analyzers, includeSuppressedDiagnostics, cancellationToken);\n+            }\n+\n+            public async Task<CompilationWithAnalyzers> CreateAnalyzerDriverAsync(\n+                Project project, ImmutableArray<DiagnosticAnalyzer> analyzers, bool includeSuppressedDiagnostics, CancellationToken cancellationToken)\n+            {\n+                if (!project.SupportsCompilation)\n+                {\n+                    return null;\n+                }\n+\n+                var compilation = await project.GetCompilationAsync(cancellationToken).ConfigureAwait(false);\n+\n+                // Create driver that holds onto compilation and associated analyzers\n+                return CreateAnalyzerDriver(\n+                    project, compilation, analyzers, logAnalyzerExecutionTime: false, reportSuppressedDiagnostics: includeSuppressedDiagnostics);\n+            }\n+\n+            private CompilationWithAnalyzers CreateAnalyzerDriver(\n+                Project project,\n+                Compilation compilation,\n+                ImmutableArray<DiagnosticAnalyzer> analyzers,\n+                bool logAnalyzerExecutionTime,\n+                bool reportSuppressedDiagnostics)\n+            {\n+                // PERF: there is no analyzers for this compilation.\n+                //       compilationWithAnalyzer will throw if it is created with no analyzers which is perf optimization.\n+                if (analyzers.IsEmpty)\n+                {\n+                    return null;\n+                }\n+\n+                Contract.ThrowIfFalse(project.SupportsCompilation);\n+                AssertCompilation(project, compilation);\n+\n+                var analysisOptions = GetAnalyzerOptions(project, logAnalyzerExecutionTime, reportSuppressedDiagnostics);\n+\n+                // Create driver that holds onto compilation and associated analyzers\n+                return compilation.WithAnalyzers(analyzers, analysisOptions);","path":"src/Features/Core/Portable/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.CompilationManager.cs","position":109,"original_position":109,"commit_id":"7fb3292abc5d915d958d4bce3789184afca43b9d","original_commit_id":"96a13f43740cac527ce561cad5432e0e170ce70b","user":{"login":"mavasani","id":10605811,"avatar_url":"https://avatars.githubusercontent.com/u/10605811?v=3","gravatar_id":"","url":"https://api.github.com/users/mavasani","html_url":"https://github.com/mavasani","followers_url":"https://api.github.com/users/mavasani/followers","following_url":"https://api.github.com/users/mavasani/following{/other_user}","gists_url":"https://api.github.com/users/mavasani/gists{/gist_id}","starred_url":"https://api.github.com/users/mavasani/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mavasani/subscriptions","organizations_url":"https://api.github.com/users/mavasani/orgs","repos_url":"https://api.github.com/users/mavasani/repos","events_url":"https://api.github.com/users/mavasani/events{/privacy}","received_events_url":"https://api.github.com/users/mavasani/received_events","type":"User","site_admin":false},"body":"Analyzers for which no rules are enabled, either by default or by ruleset - basically those which will be a no-op for analyzer execution.","created_at":"2016-04-12T22:14:16Z","updated_at":"2016-04-12T22:14:16Z","html_url":"https://github.com/dotnet/roslyn/pull/10509#discussion_r59463565","pull_request_url":"https://api.github.com/repos/dotnet/roslyn/pulls/10509","_links":{"self":{"href":"https://api.github.com/repos/dotnet/roslyn/pulls/comments/59463565"},"html":{"href":"https://github.com/dotnet/roslyn/pull/10509#discussion_r59463565"},"pull_request":{"href":"https://api.github.com/repos/dotnet/roslyn/pulls/10509"}}},"pull_request":{"url":"https://api.github.com/repos/dotnet/roslyn/pulls/10509","id":66211612,"html_url":"https://github.com/dotnet/roslyn/pull/10509","diff_url":"https://github.com/dotnet/roslyn/pull/10509.diff","patch_url":"https://github.com/dotnet/roslyn/pull/10509.patch","issue_url":"https://api.github.com/repos/dotnet/roslyn/issues/10509","number":10509,"state":"open","locked":false,"title":"OOP #1 - new analyzer engine that uses CompilerAnalyzer model","user":{"login":"heejaechang","id":1333179,"avatar_url":"https://avatars.githubusercontent.com/u/1333179?v=3","gravatar_id":"","url":"https://api.github.com/users/heejaechang","html_url":"https://github.com/heejaechang","followers_url":"https://api.github.com/users/heejaechang/followers","following_url":"https://api.github.com/users/heejaechang/following{/other_user}","gists_url":"https://api.github.com/users/heejaechang/gists{/gist_id}","starred_url":"https://api.github.com/users/heejaechang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/heejaechang/subscriptions","organizations_url":"https://api.github.com/users/heejaechang/orgs","repos_url":"https://api.github.com/users/heejaechang/repos","events_url":"https://api.github.com/users/heejaechang/events{/privacy}","received_events_url":"https://api.github.com/users/heejaechang/received_events","type":"User","site_admin":false},"body":"this is a rewrite of our analyzer engine (V2)\r\n\r\nunlike the v1, we no longer tries to do incremental analysis per document (except active/open files) rather we follow compiler model where we do every work in one shot.\r\n\r\nwe realized implementing this incremental analysis on top of compiler model (which doesn't support this incremental analysis naturally) cost more than just doing everything at once.\r\n\r\nthis should let us to remove any need to maintain state in compilationWithAnalyzer to track in progress state.\r\n\r\nalso, this make implementation a bit less complicated than before.","created_at":"2016-04-12T19:12:50Z","updated_at":"2016-04-12T22:14:16Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9ba010787a3b60e6d41ed21d2ab9d954f777663d","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/dotnet/roslyn/pulls/10509/commits","review_comments_url":"https://api.github.com/repos/dotnet/roslyn/pulls/10509/comments","review_comment_url":"https://api.github.com/repos/dotnet/roslyn/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dotnet/roslyn/issues/10509/comments","statuses_url":"https://api.github.com/repos/dotnet/roslyn/statuses/7fb3292abc5d915d958d4bce3789184afca43b9d","head":{"label":"heejaechang:oop2","ref":"oop2","sha":"7fb3292abc5d915d958d4bce3789184afca43b9d","user":{"login":"heejaechang","id":1333179,"avatar_url":"https://avatars.githubusercontent.com/u/1333179?v=3","gravatar_id":"","url":"https://api.github.com/users/heejaechang","html_url":"https://github.com/heejaechang","followers_url":"https://api.github.com/users/heejaechang/followers","following_url":"https://api.github.com/users/heejaechang/following{/other_user}","gists_url":"https://api.github.com/users/heejaechang/gists{/gist_id}","starred_url":"https://api.github.com/users/heejaechang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/heejaechang/subscriptions","organizations_url":"https://api.github.com/users/heejaechang/orgs","repos_url":"https://api.github.com/users/heejaechang/repos","events_url":"https://api.github.com/users/heejaechang/events{/privacy}","received_events_url":"https://api.github.com/users/heejaechang/received_events","type":"User","site_admin":false},"repo":{"id":30170221,"name":"roslyn","full_name":"heejaechang/roslyn","owner":{"login":"heejaechang","id":1333179,"avatar_url":"https://avatars.githubusercontent.com/u/1333179?v=3","gravatar_id":"","url":"https://api.github.com/users/heejaechang","html_url":"https://github.com/heejaechang","followers_url":"https://api.github.com/users/heejaechang/followers","following_url":"https://api.github.com/users/heejaechang/following{/other_user}","gists_url":"https://api.github.com/users/heejaechang/gists{/gist_id}","starred_url":"https://api.github.com/users/heejaechang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/heejaechang/subscriptions","organizations_url":"https://api.github.com/users/heejaechang/orgs","repos_url":"https://api.github.com/users/heejaechang/repos","events_url":"https://api.github.com/users/heejaechang/events{/privacy}","received_events_url":"https://api.github.com/users/heejaechang/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/heejaechang/roslyn","description":"The .NET Compiler Platform (\"Roslyn\") provides open-source C# and Visual Basic compilers with rich code analysis APIs.","fork":true,"url":"https://api.github.com/repos/heejaechang/roslyn","forks_url":"https://api.github.com/repos/heejaechang/roslyn/forks","keys_url":"https://api.github.com/repos/heejaechang/roslyn/keys{/key_id}","collaborators_url":"https://api.github.com/repos/heejaechang/roslyn/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/heejaechang/roslyn/teams","hooks_url":"https://api.github.com/repos/heejaechang/roslyn/hooks","issue_events_url":"https://api.github.com/repos/heejaechang/roslyn/issues/events{/number}","events_url":"https://api.github.com/repos/heejaechang/roslyn/events","assignees_url":"https://api.github.com/repos/heejaechang/roslyn/assignees{/user}","branches_url":"https://api.github.com/repos/heejaechang/roslyn/branches{/branch}","tags_url":"https://api.github.com/repos/heejaechang/roslyn/tags","blobs_url":"https://api.github.com/repos/heejaechang/roslyn/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/heejaechang/roslyn/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/heejaechang/roslyn/git/refs{/sha}","trees_url":"https://api.github.com/repos/heejaechang/roslyn/git/trees{/sha}","statuses_url":"https://api.github.com/repos/heejaechang/roslyn/statuses/{sha}","languages_url":"https://api.github.com/repos/heejaechang/roslyn/languages","stargazers_url":"https://api.github.com/repos/heejaechang/roslyn/stargazers","contributors_url":"https://api.github.com/repos/heejaechang/roslyn/contributors","subscribers_url":"https://api.github.com/repos/heejaechang/roslyn/subscribers","subscription_url":"https://api.github.com/repos/heejaechang/roslyn/subscription","commits_url":"https://api.github.com/repos/heejaechang/roslyn/commits{/sha}","git_commits_url":"https://api.github.com/repos/heejaechang/roslyn/git/commits{/sha}","comments_url":"https://api.github.com/repos/heejaechang/roslyn/comments{/number}","issue_comment_url":"https://api.github.com/repos/heejaechang/roslyn/issues/comments{/number}","contents_url":"https://api.github.com/repos/heejaechang/roslyn/contents/{+path}","compare_url":"https://api.github.com/repos/heejaechang/roslyn/compare/{base}...{head}","merges_url":"https://api.github.com/repos/heejaechang/roslyn/merges","archive_url":"https://api.github.com/repos/heejaechang/roslyn/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/heejaechang/roslyn/downloads","issues_url":"https://api.github.com/repos/heejaechang/roslyn/issues{/number}","pulls_url":"https://api.github.com/repos/heejaechang/roslyn/pulls{/number}","milestones_url":"https://api.github.com/repos/heejaechang/roslyn/milestones{/number}","notifications_url":"https://api.github.com/repos/heejaechang/roslyn/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/heejaechang/roslyn/labels{/name}","releases_url":"https://api.github.com/repos/heejaechang/roslyn/releases{/id}","deployments_url":"https://api.github.com/repos/heejaechang/roslyn/deployments","created_at":"2015-02-02T03:54:43Z","updated_at":"2016-03-09T20:46:51Z","pushed_at":"2016-04-12T22:10:10Z","git_url":"git://github.com/heejaechang/roslyn.git","ssh_url":"git@github.com:heejaechang/roslyn.git","clone_url":"https://github.com/heejaechang/roslyn.git","svn_url":"https://github.com/heejaechang/roslyn","homepage":"","size":148508,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"dotnet:master","ref":"master","sha":"7268bd0977104906f922feaa64e4fc6c03aa3eb1","user":{"login":"dotnet","id":9141961,"avatar_url":"https://avatars.githubusercontent.com/u/9141961?v=3","gravatar_id":"","url":"https://api.github.com/users/dotnet","html_url":"https://github.com/dotnet","followers_url":"https://api.github.com/users/dotnet/followers","following_url":"https://api.github.com/users/dotnet/following{/other_user}","gists_url":"https://api.github.com/users/dotnet/gists{/gist_id}","starred_url":"https://api.github.com/users/dotnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotnet/subscriptions","organizations_url":"https://api.github.com/users/dotnet/orgs","repos_url":"https://api.github.com/users/dotnet/repos","events_url":"https://api.github.com/users/dotnet/events{/privacy}","received_events_url":"https://api.github.com/users/dotnet/received_events","type":"Organization","site_admin":false},"repo":{"id":29078997,"name":"roslyn","full_name":"dotnet/roslyn","owner":{"login":"dotnet","id":9141961,"avatar_url":"https://avatars.githubusercontent.com/u/9141961?v=3","gravatar_id":"","url":"https://api.github.com/users/dotnet","html_url":"https://github.com/dotnet","followers_url":"https://api.github.com/users/dotnet/followers","following_url":"https://api.github.com/users/dotnet/following{/other_user}","gists_url":"https://api.github.com/users/dotnet/gists{/gist_id}","starred_url":"https://api.github.com/users/dotnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotnet/subscriptions","organizations_url":"https://api.github.com/users/dotnet/orgs","repos_url":"https://api.github.com/users/dotnet/repos","events_url":"https://api.github.com/users/dotnet/events{/privacy}","received_events_url":"https://api.github.com/users/dotnet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dotnet/roslyn","description":"The .NET Compiler Platform (\"Roslyn\") provides open-source C# and Visual Basic compilers with rich code analysis APIs.","fork":false,"url":"https://api.github.com/repos/dotnet/roslyn","forks_url":"https://api.github.com/repos/dotnet/roslyn/forks","keys_url":"https://api.github.com/repos/dotnet/roslyn/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dotnet/roslyn/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dotnet/roslyn/teams","hooks_url":"https://api.github.com/repos/dotnet/roslyn/hooks","issue_events_url":"https://api.github.com/repos/dotnet/roslyn/issues/events{/number}","events_url":"https://api.github.com/repos/dotnet/roslyn/events","assignees_url":"https://api.github.com/repos/dotnet/roslyn/assignees{/user}","branches_url":"https://api.github.com/repos/dotnet/roslyn/branches{/branch}","tags_url":"https://api.github.com/repos/dotnet/roslyn/tags","blobs_url":"https://api.github.com/repos/dotnet/roslyn/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dotnet/roslyn/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dotnet/roslyn/git/refs{/sha}","trees_url":"https://api.github.com/repos/dotnet/roslyn/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dotnet/roslyn/statuses/{sha}","languages_url":"https://api.github.com/repos/dotnet/roslyn/languages","stargazers_url":"https://api.github.com/repos/dotnet/roslyn/stargazers","contributors_url":"https://api.github.com/repos/dotnet/roslyn/contributors","subscribers_url":"https://api.github.com/repos/dotnet/roslyn/subscribers","subscription_url":"https://api.github.com/repos/dotnet/roslyn/subscription","commits_url":"https://api.github.com/repos/dotnet/roslyn/commits{/sha}","git_commits_url":"https://api.github.com/repos/dotnet/roslyn/git/commits{/sha}","comments_url":"https://api.github.com/repos/dotnet/roslyn/comments{/number}","issue_comment_url":"https://api.github.com/repos/dotnet/roslyn/issues/comments{/number}","contents_url":"https://api.github.com/repos/dotnet/roslyn/contents/{+path}","compare_url":"https://api.github.com/repos/dotnet/roslyn/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dotnet/roslyn/merges","archive_url":"https://api.github.com/repos/dotnet/roslyn/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dotnet/roslyn/downloads","issues_url":"https://api.github.com/repos/dotnet/roslyn/issues{/number}","pulls_url":"https://api.github.com/repos/dotnet/roslyn/pulls{/number}","milestones_url":"https://api.github.com/repos/dotnet/roslyn/milestones{/number}","notifications_url":"https://api.github.com/repos/dotnet/roslyn/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dotnet/roslyn/labels{/name}","releases_url":"https://api.github.com/repos/dotnet/roslyn/releases{/id}","deployments_url":"https://api.github.com/repos/dotnet/roslyn/deployments","created_at":"2015-01-11T02:39:03Z","updated_at":"2016-04-12T17:29:23Z","pushed_at":"2016-04-12T22:10:11Z","git_url":"git://github.com/dotnet/roslyn.git","ssh_url":"git@github.com:dotnet/roslyn.git","clone_url":"https://github.com/dotnet/roslyn.git","svn_url":"https://github.com/dotnet/roslyn","homepage":"","size":215688,"stargazers_count":4867,"watchers_count":4867,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1226,"mirror_url":null,"open_issues_count":2642,"forks":1226,"open_issues":2642,"watchers":4867,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dotnet/roslyn/pulls/10509"},"html":{"href":"https://github.com/dotnet/roslyn/pull/10509"},"issue":{"href":"https://api.github.com/repos/dotnet/roslyn/issues/10509"},"comments":{"href":"https://api.github.com/repos/dotnet/roslyn/issues/10509/comments"},"review_comments":{"href":"https://api.github.com/repos/dotnet/roslyn/pulls/10509/comments"},"review_comment":{"href":"https://api.github.com/repos/dotnet/roslyn/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dotnet/roslyn/pulls/10509/commits"},"statuses":{"href":"https://api.github.com/repos/dotnet/roslyn/statuses/7fb3292abc5d915d958d4bce3789184afca43b9d"}}}}