77using System . Collections . Generic ;
88using System . Collections . Immutable ;
99using System . Diagnostics ;
10- using System . Diagnostics . CodeAnalysis ;
1110using System . Linq ;
1211using Microsoft . CodeAnalysis . CodeGen ;
12+ using Microsoft . CodeAnalysis . Collections ;
1313using Microsoft . CodeAnalysis . CSharp . Symbols ;
1414using Microsoft . CodeAnalysis . CSharp . Symbols . Metadata . PE ;
1515using Microsoft . CodeAnalysis . Emit ;
16- using Microsoft . CodeAnalysis . Emit . EditAndContinue ;
1716using Microsoft . CodeAnalysis . PooledObjects ;
1817using Microsoft . CodeAnalysis . Symbols ;
1918using Roslyn . Utilities ;
@@ -27,25 +26,31 @@ internal sealed class CSharpSymbolMatcher : SymbolMatcher
2726 public CSharpSymbolMatcher (
2827 SourceAssemblySymbol sourceAssembly ,
2928 SourceAssemblySymbol otherAssembly ,
30- SynthesizedTypeMaps synthesizedTypes ,
31- IReadOnlyDictionary < ISymbolInternal , ImmutableArray < ISymbolInternal > > ? otherSynthesizedMembers ,
32- IReadOnlyDictionary < ISymbolInternal , ImmutableArray < ISymbolInternal > > ? otherDeletedMembers )
29+ SynthesizedTypeMaps otherSynthesizedTypes ,
30+ IReadOnlyDictionary < ISymbolInternal , ImmutableArray < ISymbolInternal > > otherSynthesizedMembers ,
31+ IReadOnlyDictionary < ISymbolInternal , ImmutableArray < ISymbolInternal > > otherDeletedMembers )
3332 {
34- _visitor = new Visitor ( sourceAssembly , otherAssembly , synthesizedTypes , otherSynthesizedMembers , otherDeletedMembers , new DeepTranslator ( otherAssembly . GetSpecialType ( SpecialType . System_Object ) ) ) ;
33+ _visitor = new Visitor (
34+ sourceAssembly ,
35+ otherAssembly ,
36+ otherSynthesizedTypes ,
37+ otherSynthesizedMembers ,
38+ otherDeletedMembers ,
39+ new DeepTranslator ( otherAssembly . GetSpecialType ( SpecialType . System_Object ) ) ) ;
3540 }
3641
3742 public CSharpSymbolMatcher (
38- SynthesizedTypeMaps synthesizedTypes ,
3943 SourceAssemblySymbol sourceAssembly ,
40- PEAssemblySymbol otherAssembly )
44+ PEAssemblySymbol otherAssembly ,
45+ SynthesizedTypeMaps otherSynthesizedTypes )
4146 {
4247 _visitor = new Visitor (
4348 sourceAssembly ,
4449 otherAssembly ,
45- synthesizedTypes ,
46- otherSynthesizedMembers : null ,
47- deepTranslator : null ,
48- otherDeletedMembers : null ) ;
50+ otherSynthesizedTypes ,
51+ otherSynthesizedMembers : SpecializedCollections . EmptyReadOnlyDictionary < ISymbolInternal , ImmutableArray < ISymbolInternal > > ( ) ,
52+ otherDeletedMembers : SpecializedCollections . EmptyReadOnlyDictionary < ISymbolInternal , ImmutableArray < ISymbolInternal > > ( ) ,
53+ deepTranslator : null ) ;
4954 }
5055
5156 public override Cci . IDefinition ? MapDefinition ( Cci . IDefinition definition )
@@ -93,9 +98,12 @@ static bool isPrivateImplementationDetail(Cci.IDefinition definition)
9398 internal bool TryGetAnonymousTypeValue ( AnonymousTypeManager . AnonymousTypeOrDelegateTemplateSymbol template , out AnonymousTypeValue typeValue )
9499 => _visitor . TryGetAnonymousTypeValue ( template , out typeValue ) ;
95100
101+ protected override bool TryGetMatchingDelegateWithIndexedName ( INamedTypeSymbolInternal delegateTemplate , ImmutableArray < AnonymousTypeValue > values , out AnonymousTypeValue match )
102+ => _visitor . TryGetMatchingDelegateWithIndexedName ( ( AnonymousTypeManager . AnonymousDelegateTemplateSymbol ) delegateTemplate , values , out match ) ;
103+
96104 private sealed class Visitor : CSharpSymbolVisitor < Symbol ? >
97105 {
98- private readonly SynthesizedTypeMaps _synthesizedTypes ;
106+ private readonly SynthesizedTypeMaps _otherSynthesizedTypes ;
99107 private readonly SourceAssemblySymbol _sourceAssembly ;
100108
101109 // metadata or source assembly:
@@ -105,9 +113,9 @@ private sealed class Visitor : CSharpSymbolVisitor<Symbol?>
105113 /// Members that are not listed directly on their containing type or namespace symbol as they were synthesized in a lowering phase,
106114 /// after the symbol has been created.
107115 /// </summary>
108- private readonly IReadOnlyDictionary < ISymbolInternal , ImmutableArray < ISymbolInternal > > ? _otherSynthesizedMembers ;
116+ private readonly IReadOnlyDictionary < ISymbolInternal , ImmutableArray < ISymbolInternal > > _otherSynthesizedMembers ;
109117
110- private readonly IReadOnlyDictionary < ISymbolInternal , ImmutableArray < ISymbolInternal > > ? _otherDeletedMembers ;
118+ private readonly IReadOnlyDictionary < ISymbolInternal , ImmutableArray < ISymbolInternal > > _otherDeletedMembers ;
111119
112120 private readonly SymbolComparer _comparer ;
113121 private readonly ConcurrentDictionary < Symbol , Symbol ? > _matches = new ( ReferenceEqualityComparer . Instance ) ;
@@ -123,12 +131,12 @@ private sealed class Visitor : CSharpSymbolVisitor<Symbol?>
123131 public Visitor (
124132 SourceAssemblySymbol sourceAssembly ,
125133 AssemblySymbol otherAssembly ,
126- SynthesizedTypeMaps synthesizedTypes ,
127- IReadOnlyDictionary < ISymbolInternal , ImmutableArray < ISymbolInternal > > ? otherSynthesizedMembers ,
128- IReadOnlyDictionary < ISymbolInternal , ImmutableArray < ISymbolInternal > > ? otherDeletedMembers ,
134+ SynthesizedTypeMaps otherSynthesizedTypes ,
135+ IReadOnlyDictionary < ISymbolInternal , ImmutableArray < ISymbolInternal > > otherSynthesizedMembers ,
136+ IReadOnlyDictionary < ISymbolInternal , ImmutableArray < ISymbolInternal > > otherDeletedMembers ,
129137 DeepTranslator ? deepTranslator )
130138 {
131- _synthesizedTypes = synthesizedTypes ;
139+ _otherSynthesizedTypes = otherSynthesizedTypes ;
132140 _sourceAssembly = sourceAssembly ;
133141 _otherAssembly = otherAssembly ;
134142 _otherSynthesizedMembers = otherSynthesizedMembers ;
@@ -470,45 +478,44 @@ private CustomModifier VisitCustomModifier(CustomModifier modifier)
470478 CSharpCustomModifier . CreateRequired ( type ) ;
471479 }
472480
473- internal bool TryGetAnonymousDelegateValue ( AnonymousTypeManager . AnonymousDelegateTemplateSymbol delegateSymbol , out SynthesizedDelegateValue otherDelegateSymbol )
481+ private bool TryGetAnonymousDelegateValue ( AnonymousTypeManager . AnonymousDelegateTemplateSymbol delegateSymbol , out SynthesizedDelegateValue otherDelegateSymbol )
474482 {
475- Debug . Assert ( ( object ) delegateSymbol . ContainingSymbol == ( object ) _sourceAssembly . GlobalNamespace ) ;
476-
477483 var key = new SynthesizedDelegateKey ( delegateSymbol . MetadataName ) ;
478- return _synthesizedTypes . AnonymousDelegates . TryGetValue ( key , out otherDelegateSymbol ) ;
484+ return _otherSynthesizedTypes . AnonymousDelegates . TryGetValue ( key , out otherDelegateSymbol ) ;
479485 }
480486
481487 internal bool TryGetAnonymousTypeValue ( AnonymousTypeManager . AnonymousTypeOrDelegateTemplateSymbol template , out AnonymousTypeValue otherType )
482488 {
483- Debug . Assert ( ( object ) template . ContainingSymbol == ( object ) _sourceAssembly . GlobalNamespace ) ;
484-
485489 if ( template is AnonymousTypeManager . AnonymousTypeTemplateSymbol typeTemplate )
486490 {
487- return _synthesizedTypes . AnonymousTypes . TryGetValue ( typeTemplate . GetAnonymousTypeKey ( ) , out otherType ) ;
491+ return _otherSynthesizedTypes . AnonymousTypes . TryGetValue ( typeTemplate . GetAnonymousTypeKey ( ) , out otherType ) ;
488492 }
489493
490494 var delegateTemplate = ( AnonymousTypeManager . AnonymousDelegateTemplateSymbol ) template ;
491495 Debug . Assert ( delegateTemplate . DelegateInvokeMethod != null ) ;
492496
497+ otherType = default ;
498+
493499 var key = new AnonymousDelegateWithIndexedNamePartialKey ( delegateTemplate . Arity , delegateTemplate . DelegateInvokeMethod . ParameterCount ) ;
494- if ( _synthesizedTypes . AnonymousDelegatesWithIndexedNames . TryGetValue ( key , out var otherTypeCandidates ) )
500+ return _otherSynthesizedTypes . AnonymousDelegatesWithIndexedNames . TryGetValue ( key , out var otherTypeCandidates ) &&
501+ TryGetMatchingDelegateWithIndexedName ( delegateTemplate , otherTypeCandidates , out otherType ) ;
502+ }
503+
504+ internal bool TryGetMatchingDelegateWithIndexedName ( AnonymousTypeManager . AnonymousDelegateTemplateSymbol delegateTemplate , ImmutableArray < AnonymousTypeValue > values , out AnonymousTypeValue match )
505+ {
506+ foreach ( var otherTypeCandidate in values )
495507 {
496- // The key is partial (not unique). Find a matching Invoke method signature.
508+ var otherDelegateType = ( NamedTypeSymbol ? ) otherTypeCandidate . Type . GetInternalSymbol ( ) ;
509+ Debug . Assert ( otherDelegateType is not null ) ;
497510
498- foreach ( var otherTypeCandidate in otherTypeCandidates )
511+ if ( isCorrespondingAnonymousDelegate ( delegateTemplate , otherDelegateType ) )
499512 {
500- var otherDelegateType = ( NamedTypeSymbol ? ) otherTypeCandidate . Type . GetInternalSymbol ( ) ;
501- Debug . Assert ( otherDelegateType is not null ) ;
502-
503- if ( isCorrespondingAnonymousDelegate ( delegateTemplate , otherDelegateType ) )
504- {
505- otherType = otherTypeCandidate ;
506- return true ;
507- }
513+ match = otherTypeCandidate ;
514+ return true ;
508515 }
509516 }
510517
511- otherType = default ;
518+ match = default ;
512519 return false ;
513520
514521 bool isCorrespondingAnonymousDelegate ( NamedTypeSymbol type , NamedTypeSymbol otherType )
@@ -526,12 +533,12 @@ otherType.DelegateInvokeMethod is { } otherInvokeMethod &&
526533 x . IsParamsArray == y . IsParamsArray &&
527534 x . IsParamsCollection == y . IsParamsCollection ) &&
528535 isCorrespondingType ( invokeMethod . ReturnTypeWithAnnotations , otherInvokeMethod . ReturnTypeWithAnnotations ) ;
529- }
530536
531- bool isCorrespondingType ( TypeWithAnnotations type , TypeWithAnnotations expectedType )
532- {
533- var otherType = type . WithTypeAndModifiers ( ( TypeSymbol ? ) this . Visit ( type . Type ) , this . VisitCustomModifiers ( type . CustomModifiers ) ) ;
534- return otherType . Equals ( expectedType , TypeCompareKind . CLRSignatureCompareOptions ) ;
537+ bool isCorrespondingType ( TypeWithAnnotations type , TypeWithAnnotations expectedType )
538+ {
539+ var otherType = type . WithTypeAndModifiers ( ( TypeSymbol ? ) this . Visit ( type . Type ) , this . VisitCustomModifiers ( type . CustomModifiers ) ) ;
540+ return otherType . Equals ( expectedType , TypeCompareKind . CLRSignatureCompareOptions ) ;
541+ }
535542 }
536543 }
537544
@@ -799,12 +806,12 @@ private IReadOnlyDictionary<string, ImmutableArray<ISymbolInternal>> GetAllEmitt
799806 members . AddRange ( ( ( NamespaceSymbol ) symbol ) . GetMembers ( ) ) ;
800807 }
801808
802- if ( _otherSynthesizedMembers != null && _otherSynthesizedMembers . TryGetValue ( symbol , out var synthesizedMembers ) )
809+ if ( _otherSynthesizedMembers . TryGetValue ( symbol , out var synthesizedMembers ) )
803810 {
804811 members . AddRange ( synthesizedMembers ) ;
805812 }
806813
807- if ( _otherDeletedMembers ? . TryGetValue ( symbol , out var deletedMembers ) == true )
814+ if ( _otherDeletedMembers . TryGetValue ( symbol , out var deletedMembers ) )
808815 {
809816 members . AddRange ( deletedMembers ) ;
810817 }
0 commit comments