11// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
22
3+ #nullable enable
4+
35using System ;
46using System . Collections . Generic ;
57using System . Collections . Immutable ;
@@ -53,7 +55,7 @@ public partial class CSharpCompilation
5355 /// </summary>
5456 internal sealed class ReferenceManager : CommonReferenceManager < CSharpCompilation , AssemblySymbol >
5557 {
56- public ReferenceManager ( string simpleAssemblyName , AssemblyIdentityComparer identityComparer , Dictionary < MetadataReference , MetadataOrDiagnostic > observedMetadata )
58+ public ReferenceManager ( string simpleAssemblyName , AssemblyIdentityComparer identityComparer , Dictionary < MetadataReference , MetadataOrDiagnostic > ? observedMetadata )
5759 : base ( simpleAssemblyName , identityComparer , observedMetadata )
5860 {
5961 }
@@ -89,7 +91,7 @@ protected override AssemblyData CreateAssemblyDataForCompilation(CompilationRefe
8991 }
9092
9193 var result = new AssemblyDataForCompilation ( csReference . Compilation , csReference . Properties . EmbedInteropTypes ) ;
92- Debug . Assert ( ( object ) csReference . Compilation . _lazyAssemblySymbol != null ) ;
94+ Debug . Assert ( csReference . Compilation . _lazyAssemblySymbol is object ) ;
9395 return result ;
9496 }
9597
@@ -120,9 +122,9 @@ protected override bool WeakIdentityPropertiesEquivalent(AssemblyIdentity identi
120122 return AssemblyIdentityComparer . CultureComparer . Equals ( identity1 . CultureName , identity2 . CultureName ) ;
121123 }
122124
123- protected override AssemblySymbol [ ] GetActualBoundReferencesUsedBy ( AssemblySymbol assemblySymbol )
125+ protected override AssemblySymbol ? [ ] GetActualBoundReferencesUsedBy ( AssemblySymbol assemblySymbol )
124126 {
125- var refs = new List < AssemblySymbol > ( ) ;
127+ var refs = new List < AssemblySymbol ? > ( ) ;
126128
127129 foreach ( var module in assemblySymbol . Modules )
128130 {
@@ -131,7 +133,7 @@ protected override AssemblySymbol[] GetActualBoundReferencesUsedBy(AssemblySymbo
131133
132134 for ( int i = 0 ; i < refs . Count ; i ++ )
133135 {
134- if ( refs [ i ] . IsMissing )
136+ if ( refs [ i ] ! . IsMissing )
135137 {
136138 refs [ i ] = null ; // Do not expose missing assembly symbols to ReferenceManager.Binder
137139 }
@@ -158,7 +160,7 @@ protected override bool IsLinked(AssemblySymbol candidateAssembly)
158160 return candidateAssembly . IsLinked ;
159161 }
160162
161- protected override AssemblySymbol GetCorLibrary ( AssemblySymbol candidateAssembly )
163+ protected override AssemblySymbol ? GetCorLibrary ( AssemblySymbol candidateAssembly )
162164 {
163165 AssemblySymbol corLibrary = candidateAssembly . CorLibrary ;
164166
@@ -211,7 +213,7 @@ public void CreateSourceAssemblyForCompilation(CSharpCompilation compilation)
211213 }
212214
213215 AssertBound ( ) ;
214- Debug . Assert ( ( object ) compilation . _lazyAssemblySymbol != null ) ;
216+ Debug . Assert ( compilation . _lazyAssemblySymbol is object ) ;
215217 }
216218
217219 /// <summary>
@@ -306,11 +308,11 @@ private void CreateAndSetSourceAssemblyReuseData(CSharpCompilation compilation)
306308
307309 InitializeAssemblyReuseData ( assemblySymbol , this . ReferencedAssemblies , this . UnifiedAssemblies ) ;
308310
309- if ( ( object ) compilation . _lazyAssemblySymbol == null )
311+ if ( compilation . _lazyAssemblySymbol is null )
310312 {
311313 lock ( SymbolCacheAndReferenceManagerStateGuard )
312314 {
313- if ( ( object ) compilation . _lazyAssemblySymbol == null )
315+ if ( compilation . _lazyAssemblySymbol is null )
314316 {
315317 compilation . _lazyAssemblySymbol = assemblySymbol ;
316318 Debug . Assert ( ReferenceEquals ( compilation . _referenceManager , this ) ) ;
@@ -451,7 +453,7 @@ private bool CreateAndSetSourceAssemblyFullBind(CSharpCompilation compilation)
451453
452454 // Setup bound references for newly created AssemblySymbols
453455 // This should be done after we created/found all AssemblySymbols
454- Dictionary < AssemblyIdentity , MissingAssemblySymbol > missingAssemblies = null ;
456+ Dictionary < AssemblyIdentity , MissingAssemblySymbol > ? missingAssemblies = null ;
455457
456458 // -1 for assembly being built:
457459 int totalReferencedAssemblyCount = allAssemblyData . Length - 1 ;
@@ -478,11 +480,11 @@ private bool CreateAndSetSourceAssemblyFullBind(CSharpCompilation compilation)
478480 InitializeNewSymbols ( newSymbols , assemblySymbol , allAssemblyData , bindingResult , missingAssemblies ) ;
479481 }
480482
481- if ( ( object ) compilation . _lazyAssemblySymbol == null )
483+ if ( compilation . _lazyAssemblySymbol is null )
482484 {
483485 lock ( SymbolCacheAndReferenceManagerStateGuard )
484486 {
485- if ( ( object ) compilation . _lazyAssemblySymbol == null )
487+ if ( compilation . _lazyAssemblySymbol is null )
486488 {
487489 if ( IsBound )
488490 {
@@ -502,7 +504,7 @@ private bool CreateAndSetSourceAssemblyFullBind(CSharpCompilation compilation)
502504 implicitReferenceResolutions ,
503505 hasCircularReference ,
504506 resolutionDiagnostics . ToReadOnly ( ) ,
505- ReferenceEquals ( corLibrary , assemblySymbol ) ? null : corLibrary ,
507+ ReferenceEquals ( corLibrary , assemblySymbol ) ? null ! : corLibrary , // https://github.com/dotnet/roslyn/issues/40751 Unnecessary suppression
506508 modules ,
507509 moduleReferences ,
508510 assemblySymbol . SourceModule . GetReferencedAssemblySymbols ( ) ,
@@ -534,12 +536,12 @@ private static void InitializeNewSymbols(
534536 SourceAssemblySymbol sourceAssembly ,
535537 ImmutableArray < AssemblyData > assemblies ,
536538 BoundInputAssembly [ ] bindingResult ,
537- Dictionary < AssemblyIdentity , MissingAssemblySymbol > missingAssemblies )
539+ Dictionary < AssemblyIdentity , MissingAssemblySymbol > ? missingAssemblies )
538540 {
539541 Debug . Assert ( newSymbols . Count > 0 ) ;
540542
541543 var corLibrary = sourceAssembly . CorLibrary ;
542- Debug . Assert ( ( object ) corLibrary != null ) ;
544+ RoslynDebug . Assert ( ( object ) corLibrary != null ) ;
543545
544546 foreach ( int i in newSymbols )
545547 {
@@ -628,7 +630,7 @@ private static void UpdateSymbolCacheNoLock(List<int> newSymbols, ImmutableArray
628630 private static void SetupReferencesForRetargetingAssembly (
629631 BoundInputAssembly [ ] bindingResult ,
630632 int bindingIndex ,
631- ref Dictionary < AssemblyIdentity , MissingAssemblySymbol > missingAssemblies ,
633+ ref Dictionary < AssemblyIdentity , MissingAssemblySymbol > ? missingAssemblies ,
632634 SourceAssemblySymbol sourceAssemblyDebugOnly )
633635 {
634636 var retargetingAssemblySymbol = ( RetargetingAssemblySymbol ) bindingResult [ bindingIndex ] . AssemblySymbol ;
@@ -677,7 +679,7 @@ private static void SetupReferencesForRetargetingAssembly(
677679
678680 int refsCount = referencedAssemblies . Length ;
679681 AssemblySymbol [ ] symbols = new AssemblySymbol [ refsCount ] ;
680- ArrayBuilder < UnifiedAssembly < AssemblySymbol > > unifiedAssemblies = null ;
682+ ArrayBuilder < UnifiedAssembly < AssemblySymbol > > ? unifiedAssemblies = null ;
681683
682684 for ( int k = 0 ; k < refsCount ; k ++ )
683685 {
@@ -703,7 +705,7 @@ private static void SetupReferencesForFileAssembly(
703705 AssemblyDataForFile fileData ,
704706 BoundInputAssembly [ ] bindingResult ,
705707 int bindingIndex ,
706- ref Dictionary < AssemblyIdentity , MissingAssemblySymbol > missingAssemblies ,
708+ ref Dictionary < AssemblyIdentity , MissingAssemblySymbol > ? missingAssemblies ,
707709 SourceAssemblySymbol sourceAssemblyDebugOnly )
708710 {
709711 var portableExecutableAssemblySymbol = ( PEAssemblySymbol ) bindingResult [ bindingIndex ] . AssemblySymbol ;
@@ -720,7 +722,7 @@ private static void SetupReferencesForFileAssembly(
720722
721723 fileData . AssemblyReferences . CopyTo ( refsUsed , identities , 0 , moduleReferenceCount ) ;
722724
723- ArrayBuilder < UnifiedAssembly < AssemblySymbol > > unifiedAssemblies = null ;
725+ ArrayBuilder < UnifiedAssembly < AssemblySymbol > > ? unifiedAssemblies = null ;
724726 for ( int k = 0 ; k < moduleReferenceCount ; k ++ )
725727 {
726728 var boundReference = bindingResult [ bindingIndex ] . ReferenceBinding [ refsUsed + k ] ;
@@ -746,7 +748,7 @@ private static void SetupReferencesForSourceAssembly(
746748 ImmutableArray < PEModule > modules ,
747749 int totalReferencedAssemblyCount ,
748750 BoundInputAssembly [ ] bindingResult ,
749- ref Dictionary < AssemblyIdentity , MissingAssemblySymbol > missingAssemblies ,
751+ ref Dictionary < AssemblyIdentity , MissingAssemblySymbol > ? missingAssemblies ,
750752 out ImmutableArray < ModuleReferences < AssemblySymbol > > moduleReferences )
751753 {
752754 var moduleSymbols = sourceAssembly . Modules ;
@@ -762,7 +764,7 @@ private static void SetupReferencesForSourceAssembly(
762764 var identities = new AssemblyIdentity [ refsCount ] ;
763765 var symbols = new AssemblySymbol [ refsCount ] ;
764766
765- ArrayBuilder < UnifiedAssembly < AssemblySymbol > > unifiedAssemblies = null ;
767+ ArrayBuilder < UnifiedAssembly < AssemblySymbol > > ? unifiedAssemblies = null ;
766768
767769 for ( int k = 0 ; k < refsCount ; k ++ )
768770 {
@@ -786,7 +788,7 @@ private static void SetupReferencesForSourceAssembly(
786788
787789 if ( moduleIndex > 0 )
788790 {
789- moduleReferencesBuilder . Add ( references ) ;
791+ moduleReferencesBuilder ! . Add ( references ) ;
790792 }
791793
792794 moduleSymbols [ moduleIndex ] . SetReferences ( references , sourceAssembly ) ;
@@ -800,12 +802,12 @@ private static void SetupReferencesForSourceAssembly(
800802 private static AssemblySymbol GetAssemblyDefinitionSymbol (
801803 BoundInputAssembly [ ] bindingResult ,
802804 AssemblyReferenceBinding referenceBinding ,
803- ref ArrayBuilder < UnifiedAssembly < AssemblySymbol > > unifiedAssemblies )
805+ ref ArrayBuilder < UnifiedAssembly < AssemblySymbol > > ? unifiedAssemblies )
804806 {
805807 Debug . Assert ( referenceBinding . IsBound ) ;
806808
807809 var assembly = bindingResult [ referenceBinding . DefinitionIndex ] . AssemblySymbol ;
808- Debug . Assert ( ( object ) assembly != null ) ;
810+ RoslynDebug . Assert ( ( object ) assembly != null ) ;
809811
810812 if ( referenceBinding . VersionDifference != 0 )
811813 {
@@ -822,7 +824,7 @@ private static AssemblySymbol GetAssemblyDefinitionSymbol(
822824
823825 private static MissingAssemblySymbol GetOrAddMissingAssemblySymbol (
824826 AssemblyIdentity assemblyIdentity ,
825- ref Dictionary < AssemblyIdentity , MissingAssemblySymbol > missingAssemblies )
827+ ref Dictionary < AssemblyIdentity , MissingAssemblySymbol > ? missingAssemblies )
826828 {
827829 MissingAssemblySymbol missingAssembly ;
828830
@@ -843,7 +845,7 @@ private static MissingAssemblySymbol GetOrAddMissingAssemblySymbol(
843845
844846 private abstract class AssemblyDataForMetadataOrCompilation : AssemblyData
845847 {
846- private List < AssemblySymbol > _assemblies ;
848+ private List < AssemblySymbol > ? _assemblies ;
847849 private readonly AssemblyIdentity _identity ;
848850 private readonly ImmutableArray < AssemblyIdentity > _referencedAssemblies ;
849851 private readonly bool _embedInteropTypes ;
@@ -853,7 +855,7 @@ protected AssemblyDataForMetadataOrCompilation(
853855 ImmutableArray < AssemblyIdentity > referencedAssemblies ,
854856 bool embedInteropTypes )
855857 {
856- Debug . Assert ( identity != null ) ;
858+ RoslynDebug . Assert ( identity != null ) ;
857859 Debug . Assert ( ! referencedAssemblies . IsDefault ) ;
858860
859861 _embedInteropTypes = embedInteropTypes ;
@@ -948,8 +950,8 @@ public AssemblyDataForFile(
948950 MetadataImportOptions compilationImportOptions )
949951 : base ( assembly . Identity , assembly . AssemblyReferences , embedInteropTypes )
950952 {
951- Debug . Assert ( documentationProvider != null ) ;
952- Debug . Assert ( cachedSymbols != null ) ;
953+ RoslynDebug . Assert ( documentationProvider != null ) ;
954+ RoslynDebug . Assert ( cachedSymbols != null ) ;
953955
954956 CachedSymbols = cachedSymbols ;
955957 Assembly = assembly ;
@@ -1001,7 +1003,7 @@ protected override void AddAvailableSymbols(List<AssemblySymbol> assemblies)
10011003 var peAssembly = assembly as PEAssemblySymbol ;
10021004 if ( IsMatchingAssembly ( peAssembly ) )
10031005 {
1004- assemblies . Add ( peAssembly ) ;
1006+ assemblies . Add ( peAssembly ! ) ;
10051007 }
10061008 }
10071009 }
@@ -1012,9 +1014,9 @@ public override bool IsMatchingAssembly(AssemblySymbol candidateAssembly)
10121014 return IsMatchingAssembly ( candidateAssembly as PEAssemblySymbol ) ;
10131015 }
10141016
1015- private bool IsMatchingAssembly ( PEAssemblySymbol peAssembly )
1017+ private bool IsMatchingAssembly ( PEAssemblySymbol ? peAssembly )
10161018 {
1017- if ( ( object ) peAssembly == null )
1019+ if ( peAssembly is null )
10181020 {
10191021 return false ;
10201022 }
@@ -1057,7 +1059,7 @@ public override bool DeclaresTheObjectClass
10571059 }
10581060 }
10591061
1060- public override Compilation SourceCompilation => null ;
1062+ public override Compilation ? SourceCompilation => null ;
10611063 }
10621064
10631065 private sealed class AssemblyDataForCompilation : AssemblyDataForMetadataOrCompilation
@@ -1118,9 +1120,9 @@ protected override void AddAvailableSymbols(List<AssemblySymbol> assemblies)
11181120 public override bool IsMatchingAssembly ( AssemblySymbol candidateAssembly )
11191121 {
11201122 var retargeting = candidateAssembly as RetargetingAssemblySymbol ;
1121- AssemblySymbol asm ;
1123+ AssemblySymbol ? asm ;
11221124
1123- if ( ( object ) retargeting != null )
1125+ if ( retargeting is object )
11241126 {
11251127 asm = retargeting . UnderlyingAssembly ;
11261128 }
@@ -1158,7 +1160,7 @@ public override bool DeclaresTheObjectClass
11581160 /// </summary>
11591161 internal static bool IsSourceAssemblySymbolCreated ( CSharpCompilation compilation )
11601162 {
1161- return ( object ) compilation . _lazyAssemblySymbol != null ;
1163+ return compilation . _lazyAssemblySymbol is object ;
11621164 }
11631165
11641166 /// <summary>
0 commit comments