Skip to content
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

Order GlobalNamespace declarations to match Compilation.SyntaxTrees #11625

Merged
merged 1 commit into from
Jun 2, 2016

Conversation

cston
Copy link
Member

@cston cston commented May 27, 2016

The order of the root namespace declarations in DeclarationTable no longer matches the order of Compilation.SyntaxTrees after calling Compilation.ReplaceSyntaxTree, and ReplaceSyntaxTree is called by the IDE when opening or updating a document.

Fixes #11015.

@cston
Copy link
Member Author

cston commented May 27, 2016

@dotnet/roslyn-compiler, @mavasani please review.
@MattGertz for approval.

@MattGertz
Copy link
Contributor

Meets the bar, pending the usual criteria.

@jasonmalinowski jasonmalinowski modified the milestone: 1.3 May 28, 2016
@@ -2934,7 +2934,8 @@ public IEnumerable<ISymbol> GetSymbolsWithName(Func<string, bool> predicate, Sym
var result = new HashSet<ISymbol>();
var spine = new List<MergedNamespaceOrTypeDeclaration>();

AppendSymbolsWithName(spine, _compilation.Declarations.MergedRoot, predicate, filter, result, cancellationToken);
var mergedRoot = ((SourceNamespaceSymbol)_compilation.SourceModule.GlobalNamespace).MergedDeclaration;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be concerned with the fact that now we are always creating SourceModuleSymbol here, which means that references are getting resolved etc., whereas before, if result is empty, it looks like we could have avoided doing this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely interested in knowing the answer to this. In particular the potential impact this could have to performance.

@AlekseyTs
Copy link
Contributor

It feels like this change is decreasing our ability to take advantage of caching done in Declaration Table across different compilation versions when the set and the order of syntax trees is the same. It looks like for the purpose of creating symbols, each compilation would always create its own merged root of namespace declarations, regardless whether the order differs or not. In addition, some code still uses MergedRoot from the declaration table, so we are somewhere in between, which potentially could be a source of inconsistencies and again prevents us from taking full advantage of the caching (we are splitting between two caches). We still have a risk of someone using the “wrong” merged root in future code, introducing hard to detect bugs.
If I am not mistaken, DeclarationTable.MergedRoot is always accessed from a compilation instance. Even when it is done indirectly (I think there is only one place like that), the request is still initiated by a compilation instance. I propose to make the MergedRoot API context aware, convert it to a method that takes a compilation instance. That function would return cached root if there are no pending changes, or would create and cache a new root, applying appropriate ordering to its constituents given the compilation instance. This way the amount of changes that needs to be done elsewhere will be decreased, and we will be able to continue taking full advantage of the cache.

BTW, the test failures look like something that could be related to the change.

@KevinH-MS
Copy link
Contributor

Responding to @tmat's comment in the other PR, no concern about #loaded files here (they should be handled by this fix).

@cston cston force-pushed the 11015-s branch 2 times, most recently from a523fcb to 5ebaded Compare May 31, 2016 21:50
@cston
Copy link
Member Author

cston commented May 31, 2016

@AlekseyTs good catch regarding the caching. I've moved the caching back to the DeclarationTable classes as you suggested.

builder.AddRange(oldRootDeclarations);
builder.Add(_latestLazyRootDeclaration.Value);
// Sort the root namespace declarations to match the order of SyntaxTrees.
if (compilation != null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we expect compilation ever be null?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compilation is null in DeclarationTests.

@AlekseyTs
Copy link
Contributor

LGTM, modulo the test failures. I assume baseline for some tests should be adjusted?

@cston
Copy link
Member Author

cston commented Jun 1, 2016

@AlekseyTs handling the test failures required a fix in LexicalSortKey..ctor to handle EmbeddedKind.

@cston
Copy link
Member Author

cston commented Jun 1, 2016

@dotnet/roslyn-compiler please provide a second review, thanks.

@AlekseyTs
Copy link
Contributor

The current revision LGTM.

@cston cston merged commit b82d66c into dotnet:stabilization Jun 2, 2016
@cston cston deleted the 11015-s branch June 2, 2016 04:27
@gafter
Copy link
Member

gafter commented Jun 2, 2016

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants