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

Find the right symbol when following type forwards #62406

Merged
merged 13 commits into from
Jul 20, 2022

Conversation

davidwengier
Copy link
Contributor

Fixes an issue I found while recording a showcase demo this morning :)

@davidwengier davidwengier requested a review from a team as a code owner July 6, 2022 04:29
@@ -457,6 +457,50 @@ public class C
{
}
}
";

await RunTestAsync(async path =>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The diff on this is weird. This test is actually old, just with a few bits of code removed. This wasn't testing type forwards at all, but their presence made me think I was correctly testing them.. which I wasn't!

}

[Fact]
public async Task Net6SdkLayout_TypeForward()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test is actually entirely new, and correctly tests type forwards, in the manner that the .NET sdk uses them. This test fails without the changes in this PR.

@davidwengier
Copy link
Contributor Author

davidwengier commented Jul 8, 2022

Sorry, had to push more stuff to this.

@chuckries found some issues (I was being silly, and not using the full namespace when trying to find types in the cache), and then when doing more testing, I found more issues with type forwards, so I've fixed them too. Basically, I have to reference any DLL that was found on the journey of following type forwards, otherwise symbol key resolution failed.

There are still some issues though, and it seems that symbol keys might be a little bit too fussy for my needs. For example, the System.Uri(string) constructor is defined in System.Runtime.dll, which type forwards to System.Private.Uri.dll, which we correctly find. However when we then try to find the symbol from System.Private.Uri.dll, symbol key resolution fails because System.String is defined in System.Private.CoreLib.dll, which is not part of the compilation. I could try to reference every DLL referenced by the implementation DLL (and any DLL we looked at on the way??) but not sure thats a good idea. Alternatively, I could go back to the logic I had when I first attempted this of finding the symbol myself. We just need the metadata token after all.

Thoughts @tmat @jasonmalinowski ?

@davidwengier
Copy link
Contributor Author

Ping @tmat @jasonmalinowski for review.

It would be good to get your thoughts on my question above, but its not necessary for this PR, so I can file an issue and follow up later if its easier

@tmat
Copy link
Member

tmat commented Jul 12, 2022

However when we then try to find the symbol from System.Private.Uri.dll, symbol key resolution fails because System.String is defined in System.Private.CoreLib.dll, which is not part of the compilation.

Is SymbolKey not able to work with missing type symbols? Seems like we should be able to match missing types if their full names and assembly identities match.

We no longer need to reference any DLLs in our temporary compilation, because symbol key resolution is smart enough to deal with error type symbols.
@davidwengier
Copy link
Contributor Author

With the changes to symbol key, this just fixes a bug I had in namespace lookups, and adds a bunch of tests. Which is a pretty good result :)

// is SymbolDisplayFormat.QualifiedNameOnlyFormat, which this is a copy of.
var namespaceName = typeSymbol.ContainingNamespace.ToDisplayString(new SymbolDisplayFormat(
globalNamespaceStyle: SymbolDisplayGlobalNamespaceStyle.Omitted,
typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces));
Copy link
Member

Choose a reason for hiding this comment

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

Consider storing the format in a static field.

Copy link
Member

@tmat tmat left a comment

Choose a reason for hiding this comment

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

:shipit:

@davidwengier davidwengier enabled auto-merge (squash) July 19, 2022 02:59
@davidwengier davidwengier merged commit 1c480b0 into dotnet:main Jul 20, 2022
@ghost ghost added this to the Next milestone Jul 20, 2022
@davidwengier davidwengier deleted the FixTypeForwardsInGTD branch July 20, 2022 17:49
333fred added a commit to 333fred/roslyn that referenced this pull request Jul 20, 2022
* upstream/main: (66 commits)
  Merge release/dev17.3 to main (dotnet#62573)
  Fix
  Find the right symbol when following type forwards (dotnet#62406)
  Remove unused parameter (dotnet#62685)
  Fix NRE in nullable walker (dotnet#62773)
  Delete obsolete internal options (dotnet#62746)
  Optimize away unchecked conversions between nint and nuint types. (dotnet#62774)
  Delete
  Inline members
  Clean up global options usage in tests (dotnet#62692)
  Update dependencies from https://github.com/dotnet/source-build-externals build 20220719.2 (dotnet#62787)
  Update src/Workspaces/Remote/ServiceHub/Services/Renamer/RemoteRenamerService.cs
  No need to roundtrip symbol
  Unused variable
  formatting
  Get document properly
  Lint
  Simplify
  Remove unnecessary callbacks
  Add telemetry
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants