Skip to content

Cleanup dead delegate code#129662

Open
MichalPetryka wants to merge 1 commit into
dotnet:mainfrom
MichalPetryka:dead-delegate
Open

Cleanup dead delegate code#129662
MichalPetryka wants to merge 1 commit into
dotnet:mainfrom
MichalPetryka:dead-delegate

Conversation

@MichalPetryka

Copy link
Copy Markdown
Contributor

Split off from #99200

cc @jkotas

@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Jun 21, 2026

internal void StoreDynamicMethod(MethodInfo dynamicMethod)
{
Debug.Assert(_invocationCount == 0);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This assert was incorrect for oven virtual delegates.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This method is only ever used to create dynamic method delegate. I do not think there is a way to have open virtual delegate that points to dynamic method.

We may want to delete this method instead (see my other feedback).

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

// in the other cases we return the method desc for the invoke
innerDel = (DELEGATEREF) thisDel->GetInvocationList();
bool fOpenVirtualDelegate = false;
// or _invocationList points to a LoaderAllocator/DynamicResolver

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I do not think _invocationList ever points to a LoaderAllocator/DynamicResolver in the current implementation. Do you agree? I think all comments and code (e.g. InvocationListLogicallyNull ) that deal with it can be deleted.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah right I've only moved it there in my other PR. Since that makes it the case, I'd not touch this however.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Before this delta, the comment was referring to wrapper Delegate so one can guess it is obsolete. After this delta, the comment is simply incorrect that is not an improvement.

I understand that some of the changes will conflict. It is the cost of splitting large changes into multiple PRs. It is important that each of the split PRs is coherent on its own as much as possible.

@@ -379,8 +379,7 @@

// Initialize the method...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
// Initialize the method...

Non-sensical comment

Delegate d = InternalAlloc(rtType);
// This is a new internal API added in Whidbey. Currently it's only
// used by the dynamic method code to generate a wrapper delegate.
// This is a new internal API added in Whidbey.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
// This is a new internal API added in Whidbey.

Whibey shipped in 2005. This is not new anymore.

@@ -3268,7 +3268,6 @@ DacDbiInterfaceImpl::DelegateType DacDbiInterfaceImpl::GetDelegateType(VMPTR_Obj
{
// If this delegate points to a static function or this is a open virtual delegate, this should be non-null

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this comment correct? Open virtual delegate is going to have _invocationCount != 0.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

// Classify by invocation count first:
// anything other than 0 indicates a multicast/wrapper/special-sig delegate
// that this API does not interpret further. Only when invocationCount==0
// do MethodPtr/MethodPtrAux unambiguously identify a closed/open delegate.
DelegateType delegateType = DelegateType.Unknown;

0 => del.MethodPtrAux == TargetCodePointer.Null

should be update to match too

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've fixed that in the other PR so I'd rather not touch this here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I thought that the primary goal of this PR is to delete all remnants of the wrapper stubs that I have missed.

// internal implementation details (FCALLS and utilities)
//

// V2 internal API.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change

//

// V2 internal API.
internal static Delegate CreateDelegateNoSecurityCheck(Type type, object? target, RuntimeMethodHandle method)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
internal static Delegate CreateDelegateForDynamicMethod(Type type, object? target, RuntimeMethodHandle method)

We may want to give this method more self-describing name.

Also, we may want to pass in MethodInfo as an argument and delete StoreDynamicMethod.
.


internal void StoreDynamicMethod(MethodInfo dynamicMethod)
{
Debug.Assert(_invocationCount == 0);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This method is only ever used to create dynamic method delegate. I do not think there is a way to have open virtual delegate that points to dynamic method.

We may want to delete this method instead (see my other feedback).

fOpenVirtualDelegate = true;
}
}
// we return the method desc for the invoke

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks like unfinished sentence. Should this say "... for the first two cases" or something?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-VM-coreclr community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants