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

Trim analysis fails to track integer across iterator yield #110553

Open
sbomer opened this issue Dec 9, 2024 · 1 comment
Open

Trim analysis fails to track integer across iterator yield #110553

sbomer opened this issue Dec 9, 2024 · 1 comment
Assignees
Labels
area-Tools-ILLink .NET linker development as well as trimming analyzers
Milestone

Comments

@sbomer
Copy link
Member

sbomer commented Dec 9, 2024

For code like this:

public static IEnumerable<int> IteratorWithIntegerDataflow ()
{
	int integerLocal = 0;
	yield return 0;
	var types = new Type[] { GetWithPublicMethods (), GetWithPublicFields () };
	types[integerLocal].RequiresPublicMethods ();
}

ILLink tracks assignments and reads of the int local, and before #110105 this was enough for the analysis to determine that array element 0 satisfies PublicMethods.

The dependency update changed the iterator codegen, introducing a dispose method that assigns null to the array. This interferes with the analysis and causes this to report a warning:

Trim analysis warning IL2062: Mono.Linker.Tests.Cases.DataFlow.CompilerGeneratedCodeAccessedViaReflection.IteratorStateMachines.<IteratorWithIntegerDataflow>d__3.MoveNext(): Value passed to parameter 'type' of method 'Mono.Linker.Tests.Cases.Expectations.Helpers.DataFlowTypeExtensions.RequiresPublicMethods(Type)' can not be statically determined and may not meet 'DynamicallyAccessedMembersAttribute' requirements.
@sbomer sbomer added the area-Tools-ILLink .NET linker development as well as trimming analyzers label Dec 9, 2024
@sbomer sbomer added this to the 10.0.0 milestone Dec 9, 2024
@sbomer sbomer self-assigned this Dec 9, 2024
@sbomer sbomer added this to AppModel Dec 9, 2024
Copy link
Contributor

Tagging subscribers to this area: @dotnet/illink
See info in area-owners.md if you want to be subscribed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Tools-ILLink .NET linker development as well as trimming analyzers
Projects
Status: No status
Development

No branches or pull requests

1 participant