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

Fix mapping of redeclared type parameters #86353

Merged
merged 4 commits into from
May 19, 2023
Merged

Conversation

sbomer
Copy link
Member

@sbomer sbomer commented May 16, 2023

Ported over from dotnet/linker#3167, and fixed in ILCompiler as well.

We were skipping the type parameter mapping of compiler-generated types whose only generic parameters were those implicitly created for the declaring type's type parameters.

For the testcase in question, the nested state machine inherited a generic parameter from the display class. This was causing unnecessary warnings in a field assignment that assigned this (an instance of the display class) to a field on the state machine. In IL, that assignment references a field type like DisplayClass<T> where T is the generic parameter on the state machine. Here we were properly mapping type parameters of the display class back to the annotated enclosing method's type parameters, so we could tell that the "target" required PublicMethods. But the substituted T from the state machine was not mapped, causing the mismatch.

Fixes the issue mentioned in dotnet/roslyn#46646 (comment).

@MichalStrehovsky
Copy link
Member

I'll leave reviewing this to Vitek, but I have a general question:

When ILLink was in a separate repo, the approach we had was that things got fixed in ILLink repo and at some point we'd go, copy the files from linker repo over to ReferenceSource directories in this repo and apply the diffs manually.

ILLink is now here so it's feasible to just update these in one go, but we didn't fully catch up with other changes. Changing things now will make ReferenceSource diffs harder to apply.

The question I have is whether we'd want to prioritize catching up and deleting ReferenceSource.

@marek-safar marek-safar added the area-Tools-ILLink .NET linker development as well as trimming analyzers label May 18, 2023
@ghost
Copy link

ghost commented May 18, 2023

Tagging subscribers to this area: @agocke, @sbomer, @vitek-karas
See info in area-owners.md if you want to be subscribed.

Issue Details

Ported over from dotnet/linker#3167, and fixed in ILCompiler as well.

We were skipping the type parameter mapping of compiler-generated types whose only generic parameters were those implicitly created for the declaring type's type parameters.

For the testcase in question, the nested state machine inherited a generic parameter from the display class. This was causing unnecessary warnings in a field assignment that assigned this (an instance of the display class) to a field on the state machine. In IL, that assignment references a field type like DisplayClass<T> where T is the generic parameter on the state machine. Here we were properly mapping type parameters of the display class back to the annotated enclosing method's type parameters, so we could tell that the "target" required PublicMethods. But the substituted T from the state machine was not mapped, causing the mismatch.

Fixes the issue mentioned in dotnet/roslyn#46646 (comment).

Author: sbomer
Assignees: sbomer
Labels:

area-Tools-ILLink, needs-area-label

Milestone: -

@sbomer
Copy link
Member Author

sbomer commented May 18, 2023

Seems like a good idea to me. I can work on this if @vitek-karas hasn't already started.

@vitek-karas
Copy link
Member

The source code should be very close for the most part. I did a sync before I started working on test bringup.
There might be some small refactorings which are present only in one and not the other.

As we do this I would like to think about sharing the code for real. This will obviously require some additional effort, but currently the amount of code which needs to be synced is pretty big. It's definitely good that it looks similar, but true sharing would be even better.

Copy link
Member

@vitek-karas vitek-karas left a comment

Choose a reason for hiding this comment

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

:shipit:

@sbomer
Copy link
Member Author

sbomer commented May 19, 2023

Failures are #80619 and #84995

@sbomer sbomer merged commit ea94440 into dotnet:main May 19, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Jun 18, 2023
@sbomer sbomer deleted the fixNestedAsyncCase branch November 3, 2023 18:38
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Tools-ILLink .NET linker development as well as trimming analyzers needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants