Skip to content

Commit dddac7b

Browse files
authored
Merge pull request #39053 from sharwell/compiler-annotations-2
Annotate more compiler internal types
2 parents 2ae01f8 + 82f09c4 commit dddac7b

File tree

76 files changed

+415
-237
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+415
-237
lines changed

src/Compilers/Core/Portable/Binding/AbstractLookupSymbolsInfo.cs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
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+
35
using System;
46
using System.Collections.Generic;
57
using System.Diagnostics;
@@ -15,12 +17,12 @@ public struct ArityEnumerator : IEnumerator<int>
1517
{
1618
private int _current;
1719
private readonly int _low32bits;
18-
private int[] _arities;
20+
private int[]? _arities;
1921

2022
private const int resetValue = -1;
2123
private const int reachedEndValue = int.MaxValue;
2224

23-
internal ArityEnumerator(int bitVector, HashSet<int> arities)
25+
internal ArityEnumerator(int bitVector, HashSet<int>? arities)
2426
{
2527
_current = resetValue;
2628
_low32bits = bitVector;
@@ -39,7 +41,7 @@ internal ArityEnumerator(int bitVector, HashSet<int> arities)
3941

4042
public void Dispose() => _arities = null;
4143

42-
object System.Collections.IEnumerator.Current => _current;
44+
object? System.Collections.IEnumerator.Current => _current;
4345

4446
public bool MoveNext()
4547
{
@@ -118,7 +120,7 @@ private struct UniqueSymbolOrArities : IArityEnumerable
118120
// Then arityBitVectorOrUniqueArity is interpreted as a bitvector
119121
// of arities for arities from zero to 31 and the HashSet contains
120122
// arities of 32 or more.
121-
private object _uniqueSymbolOrArities;
123+
private object? _uniqueSymbolOrArities;
122124
private int _arityBitVectorOrUniqueArity;
123125

124126
public UniqueSymbolOrArities(int arity, TSymbol uniqueSymbol)
@@ -181,12 +183,14 @@ private void AddArity(int arity)
181183
hashSet.Add(arity);
182184
}
183185

184-
public void GetUniqueSymbolOrArities(out IArityEnumerable arities, out TSymbol uniqueSymbol)
186+
public void GetUniqueSymbolOrArities(out IArityEnumerable? arities, out TSymbol? uniqueSymbol)
185187
{
186188
if (this.HasUniqueSymbol)
187189
{
188190
arities = null;
191+
#nullable disable // Can '_uniqueSymbolOrArities' be null? https://github.com/dotnet/roslyn/issues/39166
189192
uniqueSymbol = (TSymbol)_uniqueSymbolOrArities;
193+
#nullable enable
190194
}
191195
else
192196
{
@@ -198,7 +202,7 @@ public void GetUniqueSymbolOrArities(out IArityEnumerable arities, out TSymbol u
198202
public ArityEnumerator GetEnumerator()
199203
{
200204
Debug.Assert(!this.HasUniqueSymbol);
201-
return new ArityEnumerator(_arityBitVectorOrUniqueArity, (HashSet<int>)_uniqueSymbolOrArities);
205+
return new ArityEnumerator(_arityBitVectorOrUniqueArity, (HashSet<int>?)_uniqueSymbolOrArities);
202206
}
203207

204208
public int Count
@@ -207,7 +211,7 @@ public int Count
207211
{
208212
Debug.Assert(!this.HasUniqueSymbol);
209213
int count = BitArithmeticUtilities.CountBits(_arityBitVectorOrUniqueArity);
210-
var set = (HashSet<int>)_uniqueSymbolOrArities;
214+
var set = (HashSet<int>?)_uniqueSymbolOrArities;
211215
if (set != null)
212216
{
213217
count += set.Count;
@@ -218,13 +222,13 @@ public int Count
218222
}
219223

220224
#if DEBUG
221-
internal TSymbol UniqueSymbol => _uniqueSymbolOrArities as TSymbol;
225+
internal TSymbol? UniqueSymbol => _uniqueSymbolOrArities as TSymbol;
222226
#endif
223227
}
224228

225229
private readonly IEqualityComparer<string> _comparer;
226230
private readonly Dictionary<string, UniqueSymbolOrArities> _nameMap;
227-
internal string FilterName { get; set; }
231+
internal string? FilterName { get; set; }
228232

229233
protected AbstractLookupSymbolsInfo(IEqualityComparer<string> comparer)
230234
{
@@ -275,8 +279,8 @@ public void AddSymbol(TSymbol symbol, string name, int arity)
275279
/// <returns></returns>
276280
public bool TryGetAritiesAndUniqueSymbol(
277281
string name,
278-
out IArityEnumerable arities,
279-
out TSymbol uniqueSymbol)
282+
out IArityEnumerable? arities,
283+
out TSymbol? uniqueSymbol)
280284
{
281285
Debug.Assert(CanBeAdded(name));
282286

src/Compilers/Core/Portable/CodeGen/ArrayMembers.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
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+
35
using Microsoft.CodeAnalysis.PooledObjects;
46
using Roslyn.Utilities;
57
using System;
@@ -324,14 +326,14 @@ protected virtual ImmutableArray<ArrayMethodParameterInfo> MakeParameters()
324326

325327
public bool IsGeneric => false;
326328

327-
public Cci.IMethodDefinition GetResolvedMethod(EmitContext context) => null;
329+
public Cci.IMethodDefinition? GetResolvedMethod(EmitContext context) => null;
328330

329331
public ImmutableArray<Cci.IParameterTypeInformation> ExtraParameters
330332
=> ImmutableArray<Cci.IParameterTypeInformation>.Empty;
331333

332-
public Cci.IGenericMethodInstanceReference AsGenericMethodInstanceReference => null;
334+
public Cci.IGenericMethodInstanceReference? AsGenericMethodInstanceReference => null;
333335

334-
public Cci.ISpecializedMethodReference AsSpecializedMethodReference => null;
336+
public Cci.ISpecializedMethodReference? AsSpecializedMethodReference => null;
335337

336338
public Cci.CallingConvention CallingConvention => Cci.CallingConvention.HasThis;
337339

@@ -356,7 +358,7 @@ public Cci.ITypeReference GetContainingType(EmitContext context)
356358
public void Dispatch(Cci.MetadataVisitor visitor)
357359
=> visitor.Visit(this);
358360

359-
public Cci.IDefinition AsDefinition(EmitContext context)
361+
public Cci.IDefinition? AsDefinition(EmitContext context)
360362
=> null;
361363

362364
public override string ToString()

src/Compilers/Core/Portable/CodeGen/ClosureDebugInfo.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
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+
35
using System;
46
using System.Diagnostics;
57
using Roslyn.Utilities;
@@ -24,7 +26,7 @@ public bool Equals(ClosureDebugInfo other)
2426
ClosureId.Equals(other.ClosureId);
2527
}
2628

27-
public override bool Equals(object obj)
29+
public override bool Equals(object? obj)
2830
{
2931
return obj is ClosureDebugInfo && Equals((ClosureDebugInfo)obj);
3032
}

src/Compilers/Core/Portable/CodeGen/CompilationTestData.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
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+
35
using Microsoft.CodeAnalysis.Emit;
46
using Microsoft.DiaSymReader;
57
using System;
@@ -29,16 +31,16 @@ public MethodData(ILBuilder ilBuilder, IMethodSymbol method)
2931
public readonly ConcurrentDictionary<IMethodSymbol, MethodData> Methods = new ConcurrentDictionary<IMethodSymbol, MethodData>();
3032

3133
// The emitted module.
32-
public CommonPEModuleBuilder Module;
34+
public CommonPEModuleBuilder? Module;
3335

34-
public Func<ISymWriterMetadataProvider, SymUnmanagedWriter> SymWriterFactory;
36+
public Func<ISymWriterMetadataProvider, SymUnmanagedWriter>? SymWriterFactory;
3537

3638
public ILBuilder GetIL(Func<IMethodSymbol, bool> predicate)
3739
{
3840
return Methods.Single(p => predicate(p.Key)).Value.ILBuilder;
3941
}
4042

41-
private ImmutableDictionary<string, MethodData> _lazyMethodsByName;
43+
private ImmutableDictionary<string, MethodData>? _lazyMethodsByName;
4244

4345
// Returns map indexed by name for those methods that have a unique name.
4446
public ImmutableDictionary<string, MethodData> GetMethodsByName()

src/Compilers/Core/Portable/CodeGen/DebugDocumentProvider.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
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+
35
namespace Microsoft.CodeAnalysis.CodeGen
46
{
57
internal delegate Cci.DebugSourceDocument DebugDocumentProvider(string path, string basePath);

src/Compilers/Core/Portable/CodeGen/DebugId.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
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+
35
using System;
46
using System.Diagnostics;
57
using Roslyn.Utilities;
@@ -43,7 +45,7 @@ public bool Equals(DebugId other)
4345
&& this.Generation == other.Generation;
4446
}
4547

46-
public override bool Equals(object obj)
48+
public override bool Equals(object? obj)
4749
{
4850
return obj is DebugId && Equals((DebugId)obj);
4951
}

src/Compilers/Core/Portable/CodeGen/DynamicAnalysisMethodBodyData.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
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+
35
using System.Collections.Immutable;
46
using System.Diagnostics;
57

src/Compilers/Core/Portable/CodeGen/EmitState.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
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+
35
using System;
46
using System.Diagnostics;
57
using Microsoft.CodeAnalysis.Text;

src/Compilers/Core/Portable/CodeGen/ILBuilderConversions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
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+
35
using System;
46
using System.Diagnostics;
57
using System.Reflection.Metadata;

src/Compilers/Core/Portable/CodeGen/ILBuilderEmit.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
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+
35
using System;
46
using System.Collections.Generic;
57
using System.Collections.Immutable;
@@ -240,7 +242,7 @@ internal void EmitStringSwitchJumpTable(
240242
KeyValuePair<ConstantValue, object>[] caseLabels,
241243
object fallThroughLabel,
242244
LocalOrParameter key,
243-
LocalDefinition keyHash,
245+
LocalDefinition? keyHash,
244246
SwitchStringJumpTableEmitter.EmitStringCompareAndBranch emitStringCondBranchDelegate,
245247
SwitchStringJumpTableEmitter.GetStringHashCode computeStringHashcodeDelegate)
246248
{

0 commit comments

Comments
 (0)