Skip to content

Cleanup multicast delegate handling#130905

Merged
jkotas merged 4 commits into
dotnet:mainfrom
MichalPetryka:multicast-array
Jul 19, 2026
Merged

Cleanup multicast delegate handling#130905
jkotas merged 4 commits into
dotnet:mainfrom
MichalPetryka:multicast-array

Conversation

@MichalPetryka

@MichalPetryka MichalPetryka commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Builds on previous PRs.

Switches multicast to Wrapper[], cleans up and spanifies combine/remove.

Cleans up code after the moves and type changes.

cc @jkotas @tannergooding

@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Jul 16, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@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.

@MichalPetryka

Copy link
Copy Markdown
Contributor Author

@MihuBot -nuget

Comment thread src/coreclr/System.Private.CoreLib/src/System/Delegate.CoreCLR.cs
Comment thread src/coreclr/System.Private.CoreLib/src/System/Delegate.CoreCLR.cs
Comment thread src/coreclr/System.Private.CoreLib/src/System/Delegate.CoreCLR.cs Outdated
Comment thread src/coreclr/vm/comdelegate.cpp Outdated
Comment thread src/coreclr/System.Private.CoreLib/src/System/Delegate.CoreCLR.cs Outdated
Comment thread src/coreclr/System.Private.CoreLib/src/System/Delegate.CoreCLR.cs
Comment thread src/coreclr/System.Private.CoreLib/src/System/Delegate.CoreCLR.cs

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors CoreCLR multicast delegate internals to store invocation lists as a strongly-typed Delegate.Wrapper[] instead of object[], and updates the VM-side multicast invoke stub generation accordingly. The change primarily aims to simplify/“spanify” combine/remove paths and reduce reliance on object[]-based casting.

Changes:

  • Switch multicast invocation list storage from object[] to Delegate.Wrapper[] in CoreLib, updating TryGetInvocations, GetInvocationList, Target, GetMethodImpl, CombineImpl, and RemoveImpl.
  • Update the VM multicast invoke IL stub to index a Wrapper[] (via ldelema) and then load the wrapped delegate (ldfld Value).
  • Add CoreLib binder entries for System.Delegate+Wrapper and its Value field for the stub generator.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/coreclr/vm/corelib.h Adds CoreLibBinder definitions for Delegate+Wrapper and Wrapper.Value.
src/coreclr/vm/comdelegate.cpp Updates multicast invoke stub IL emission to load delegates out of Wrapper[] via ldelema + ldfld.
src/coreclr/System.Private.CoreLib/src/System/Delegate.CoreCLR.cs Implements Wrapper[]-based multicast storage and span-based combine/remove/equality/hash code paths.

Comment thread src/coreclr/System.Private.CoreLib/src/System/Delegate.CoreCLR.cs
@jkotas

jkotas commented Jul 19, 2026

Copy link
Copy Markdown
Member

@EgorBot

using System;
using BenchmarkDotNet.Attributes;

public class Test
{
    private Action _a, _b;

    [GlobalSetup]
    public void GlobalSetup()
    {
        _a = new Action(new Test().GlobalSetup) + new Action(new Test().GlobalSetup);
        _b = new Action(new Test().GlobalSetup) + new Action(new Test().GlobalSetup);
    }

    [Benchmark]
    public bool Equals() => _a.Equals(_b);
}

@jkotas jkotas left a comment

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.

Thank you!

@jkotas

jkotas commented Jul 19, 2026

Copy link
Copy Markdown
Member

/ba-g known failure that has been fixed in main already

@jkotas
jkotas merged commit efba6da into dotnet:main Jul 19, 2026
112 of 114 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview7 milestone Jul 20, 2026
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.

4 participants