Skip to content

Unions: enforce the same order of processing for base interfaces of a member provider interface source vs. metadata. - #84664

Merged
AlekseyTs merged 2 commits into
dotnet:mainfrom
AlekseyTs:Unions_84
Jul 31, 2026
Merged

Unions: enforce the same order of processing for base interfaces of a member provider interface source vs. metadata.#84664
AlekseyTs merged 2 commits into
dotnet:mainfrom
AlekseyTs:Unions_84

Conversation

@AlekseyTs

@AlekseyTs AlekseyTs commented Jul 28, 2026

Copy link
Copy Markdown
Contributor
Microsoft Reviewers: Open in CodeFlow

… member provider interface source vs. metadata.
@AlekseyTs
AlekseyTs requested a review from a team as a code owner July 28, 2026 18:38
Copilot AI review requested due to automatic review settings July 28, 2026 18:38
@azure-pipelines

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

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 updates the union-member-provider interface processing so that base interfaces are traversed in a consistent, deterministic order across source vs. metadata, and it re-enables a previously skipped regression test covering the scenario.

Changes:

  • Re-enabled determinism regression coverage by un-skipping NonBoxingUnionMatching_MemberProvider_TryGetValue_Inheritance_37_ImplicitReferenceConversion_Determinism.
  • Added caching + a deterministic “all interfaces” computation for the union member-provider interface, and switched union-member discovery/use-site accumulation to use that cached ordering.
  • Made TypeSymbol.MakeAllInterfaces() non-virtual (still protected) as part of standardizing interface processing behavior.

Reviewed changes

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

File Description
src/Compilers/CSharp/Test/CSharp15/UnionsTests.cs Un-skips a theory to validate source/metadata determinism for union matching.
src/Compilers/CSharp/Portable/Symbols/TypeSymbol.cs Adjusts MakeAllInterfaces to be non-virtual.
src/Compilers/CSharp/Portable/Symbols/NamedTypeSymbol.cs Introduces cached base-interface ordering for union member-provider interfaces and uses it for union member/method discovery and use-site info.

Comment thread src/Compilers/CSharp/Portable/Symbols/NamedTypeSymbol.cs
@AlekseyTs

Copy link
Copy Markdown
Contributor Author

@RikkiGibson, @jjonescz Please review

Comment thread src/Compilers/CSharp/Portable/Symbols/NamedTypeSymbol.cs Outdated
/// long dependency cycles removed. Consequently, it is possible (and we do) use the
/// simplest version of Tarjan's topological sorting algorithm.
protected virtual ImmutableArray<NamedTypeSymbol> MakeAllInterfaces()
protected ImmutableArray<NamedTypeSymbol> MakeAllInterfaces()

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.

Since we should keep TypeSymbol.cs and TypeSymbol.vb in sync per a comment near the top of the file, should we make a similar change in VB?

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 assume you are referring to a comment about public API surface. First, this isn't a public method. Second, C# and VB symbols are no longer public.

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.

Nevertheless, it feels like if we can make the same change on the VB side, perhaps we should?

Copilot AI review requested due to automatic review settings July 29, 2026 12:04
@AlekseyTs
AlekseyTs requested a review from jjonescz July 29, 2026 12:06

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

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (2)

src/Compilers/CSharp/Portable/Symbols/NamedTypeSymbol.cs:2237

  • GetMemberProviderInterfaceAllInterfacesForDefinition returns a default ImmutableArray when the member-provider interface is missing. Default ImmutableArray values are easy to misuse (e.g., foreach/Length can throw), and this method is internal so future callers might not consistently guard against IsDefault. Consider caching/returning ImmutableArray.Empty instead.
            NamedTypeSymbol? memberProviderInterface = GetMemberProviderInterfaceForDefinition();
            if (memberProviderInterface is null)
            {
                return default;
            }

src/Compilers/CSharp/Portable/Symbols/TypeSymbol.cs:339

  • TypeSymbol contains a repo convention comment that its public interface should stay synchronized with the VB TypeSymbol. The VB implementation still has an overridable MakeAllInterfaces, but this change removes virtual from the C# version, which risks diverging the two implementations over time.
        protected ImmutableArray<NamedTypeSymbol> MakeAllInterfaces()

/// long dependency cycles removed. Consequently, it is possible (and we do) use the
/// simplest version of Tarjan's topological sorting algorithm.
protected virtual ImmutableArray<NamedTypeSymbol> MakeAllInterfaces()
protected ImmutableArray<NamedTypeSymbol> MakeAllInterfaces()

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.

Nevertheless, it feels like if we can make the same change on the VB side, perhaps we should?

@AlekseyTs

Copy link
Copy Markdown
Contributor Author

Nevertheless, it feels like if we can make the same change on the VB side, perhaps we should?

There is no behavior change here, therefore, I don't think any synchronization is necessary. I removed the modifier to confirm that there is no alternative implementation.

@AlekseyTs
AlekseyTs requested a review from a team July 29, 2026 13:14
@AlekseyTs

Copy link
Copy Markdown
Contributor Author

@RikkiGibson, @dotnet/roslyn-compiler For a second review

@AlekseyTs

Copy link
Copy Markdown
Contributor Author

@RikkiGibson, @dotnet/roslyn-compiler For a second review

1 similar comment
@AlekseyTs

Copy link
Copy Markdown
Contributor Author

@RikkiGibson, @dotnet/roslyn-compiler For a second review

@jjonescz jjonescz added this to the 18.11 milestone Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants