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

ILLink: Remove ScopeStack from MarkStep #102282

Merged
merged 11 commits into from
May 17, 2024

Conversation

jtschuster
Copy link
Member

Removes the ScopeStack from the MarkStep to make the MessageOrigin flow clearly traceable. This should be very helpful as we transition to the dependency analysis framework.

The changes were fairly mechanical, each place that pushed a scope onto the stack, a new MessageOrigin was created, and all places that used ScopeStack.CurrentScope added a new origin parameter, and the parameter bubbled up to the ProcessX methods.

Passing MessageOrigin by value was slightly faster than as an in parameter (and overall this is slightly faster than main), so I made MessageOrigin.ILOffset a non-nullable int to make the struct a bit smaller. I ran the aspnetcore benchmarks trim step and didn't run into issues, so the stack should be large enough to handle it.

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-Tools-ILLink .NET linker development as well as trimming analyzers label May 15, 2024
@dotnet-policy-service dotnet-policy-service bot added the linkable-framework Issues associated with delivering a linker friendly framework label May 15, 2024
Comment on lines -1813 to -1817
if (origin.Provider != ScopeStack.CurrentScope.Origin.Provider) {
Debug.Assert (dependencyKind == DependencyKind.DynamicallyAccessedMemberOnType ||
(origin.Provider is MethodDefinition originMethod && CompilerGeneratedState.IsNestedFunctionOrStateMachineMember (originMethod)));
}

Copy link
Member Author

Choose a reason for hiding this comment

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

This assertion was to make sure that we always passed ScopeStack.CurrentScope.Origin unless the call to MarkField originated from the ReflectionMarker. It always used the parameter origin, so the behavior is the same and this check isn't necessary.

Comment on lines -3061 to -3070
// There are only two ways to get there such that the origin isn't the same as the top of the scopestack.
// - For DAM on type, the current scope is the caller of GetType, while the origin is the type itself.
// - For warnings produced inside compiler-generated code, the current scope is the user code that
// owns the compiler-generated code, while the origin is the compiler-generated code.
// In either case any warnings produced here should use the origin instead of the scopestack.
if (origin.Provider != ScopeStack.CurrentScope.Origin.Provider) {
Debug.Assert (dependencyKind == DependencyKind.DynamicallyAccessedMemberOnType ||
(origin.Provider is MethodDefinition originMethod && CompilerGeneratedState.IsNestedFunctionOrStateMachineMember (originMethod)));
}

Copy link
Member Author

Choose a reason for hiding this comment

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

This is similar to above with ProcessAnalysisAnnotationsForField. Since we no longer use ScopeStack, this can be removed.

@jtschuster jtschuster removed the linkable-framework Issues associated with delivering a linker friendly framework label May 15, 2024
@dotnet-policy-service dotnet-policy-service bot added the linkable-framework Issues associated with delivering a linker friendly framework label May 15, 2024
Copy link
Member

@sbomer sbomer left a comment

Choose a reason for hiding this comment

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

LGTM, thanks a lot!

@vitek-karas
Copy link
Member

Thanks a lot - I always hated this part of the mark step, but was never brave enough to tackle it :-). I remember that when I introduced this even then we didn't like it very much, but it worked... sooo.

@jtschuster jtschuster merged commit 333b3d8 into dotnet:main May 17, 2024
74 of 76 checks passed
Ruihan-Yin pushed a commit to Ruihan-Yin/runtime that referenced this pull request May 30, 2024
Removes the ScopeStack from the MarkStep to make the MessageOrigin flow clearly traceable. This should be very helpful as we transition to the dependency analysis framework.

The changes were fairly mechanical, each place that pushed a scope onto the stack, a new MessageOrigin was created, and all places that used ScopeStack.CurrentScope added a new origin parameter, and the parameter bubbled up to the ProcessX methods.

Passing MessageOrigin by value was slightly faster than as an in parameter (and overall this is slightly faster than main), so I made MessageOrigin.ILOffset a non-nullable int to make the struct a bit smaller. I ran the aspnetcore benchmarks trim step and didn't run into issues, so the stack should be large enough to handle it.
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 linkable-framework Issues associated with delivering a linker friendly framework
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants