Skip to content

Transfer ownership in ReflectionMetadataHook.Register instead of cloning by @Evangelink in #9586 (backport to rel/4.3) - #9589

Merged
Evangelink merged 2 commits into
microsoft:rel/4.3from
nohwnd-bot:backport/9586/to/rel/4.3
Jul 3, 2026
Merged

Transfer ownership in ReflectionMetadataHook.Register instead of cloning by @Evangelink in #9586 (backport to rel/4.3)#9589
Evangelink merged 2 commits into
microsoft:rel/4.3from
nohwnd-bot:backport/9586/to/rel/4.3

Conversation

@nohwnd-bot

Copy link
Copy Markdown
Contributor

Backport of #9586 to rel/4.3

/cc @Evangelink

Evangelink and others added 2 commits July 3, 2026 14:58
The source-gen Register hook defensively cloned every array and dictionary it received. The only sanctioned caller is the MSTest source generator's [ModuleInitializer], which emits fresh, throwaway collections it never mutates, so the copies guarded against a mutation that cannot happen.

Store the passed arrays by reference and reuse caller dictionaries when already concrete (AsOwnedDictionary), only materializing exotic IReadOnlyDictionary implementations. The ConstructorInvokerInfo -> ConstructorInvoker projection remains (a representation change, not a defensive copy) but no longer clones parameter arrays. Documents the ownership-transfer contract on the hook.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The API is public and callable from any code; the contract is about ownership and mutation, not caller identity. Clarify accordingly.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@Evangelink
Evangelink merged commit 9ce9843 into microsoft:rel/4.3 Jul 3, 2026
6 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants