Skip to content

Fix type parameter mapping logic in ILLink/ILCompiler #92088

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

Merged
merged 4 commits into from
Sep 15, 2023

Conversation

sbomer
Copy link
Member

@sbomer sbomer commented Sep 14, 2023

The compiler-generated code for Container<T> in this testcase contains two closure types, one for each lambda in the expression (Func<T, T> x) => v => x(x(v));. The outer closure environment type is instantiated by its cctor, which stores an instance into a static field. It is never directly instantiated from another type - instead, the cctor is triggered when the cctor of Container<T> access this static field.

This case was missing from the compiler-generated type parameter mapping logic. We need to discover the substituted generic typeref for the outer closure environment from the ldsfld.

Fixes #91880.

@ghost ghost added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Sep 14, 2023
@ghost ghost assigned sbomer Sep 14, 2023
@marek-safar marek-safar added area-Tools-ILLink .NET linker development as well as trimming analyzers and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Sep 15, 2023
@ghost
Copy link

ghost commented Sep 15, 2023

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

Issue Details

The compiler-generated code for Container<T> in this testcase contains two closure types, one for each lambda in the expression (Func<T, T> x) => v => x(x(v));. The outer closure environment type is instantiated by its cctor, which stores an instance into a static field. It is never directly instantiated from another type - instead, the cctor is triggered when the cctor of Container<T> access this static field.

This case was missing from the compiler-generated type parameter mapping logic. We need to discover the substituted generic typeref for the outer closure environment from the ldsfld.

Fixes #91880.

Author: sbomer
Assignees: sbomer
Labels:

area-Tools-ILLink

Milestone: -

Copy link
Member

@agocke agocke left a comment

Choose a reason for hiding this comment

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

LGTM, I didn't anticipate that we could have only a ldsfld to the target, and no stsfld from the outside. But it looks like that's the case, so we need to track both loads and stores.

@sbomer sbomer merged commit 2dbb2fb into dotnet:main Sep 15, 2023
@sbomer
Copy link
Member Author

sbomer commented Sep 15, 2023

/backport to release/8.0

@github-actions
Copy link
Contributor

Started backporting to release/8.0: https://github.com/dotnet/runtime/actions/runs/6201152053

@ghost ghost locked as resolved and limited conversation to collaborators Oct 15, 2023
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[area-Tools-ILLink]: Error IL1012: IL Trimmer has encountered an unexpected error
4 participants