Skip to content

Commit 3ae8739

Browse files
authored
Initial roll out of !! (#64720)
* Bump version of C# compiler This should be reverted when arcade brings in a new enough compiler. * Fix a few new warnings from updating compiler * Enable IDE0190 to employ parameter null checking * Initial roll out of !! * Fix more compiler warnings from upgrade, plus some test fixes / reverts * Fix a few more tests * Disable profiling test
1 parent 97fc0a4 commit 3ae8739

File tree

1,232 files changed

+4540
-21372
lines changed

Some content is hidden

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

1,232 files changed

+4540
-21372
lines changed

eng/CodeAnalysis.src.globalconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,6 +1539,9 @@ dotnet_diagnostic.IDE0160.severity = silent
15391539
# IDE0161: Convert to file-scoped namespace
15401540
dotnet_diagnostic.IDE0161.severity = silent
15411541

1542+
# IDE0190: Null check can be simplified
1543+
dotnet_diagnostic.IDE0190.severity = suggestion
1544+
15421545
# IDE1005: Delegate invocation can be simplified.
15431546
dotnet_diagnostic.IDE1005.severity = suggestion
15441547

eng/CodeAnalysis.test.globalconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,6 +1536,9 @@ dotnet_diagnostic.IDE0160.severity = silent
15361536
# IDE0161: Convert to file-scoped namespace
15371537
dotnet_diagnostic.IDE0161.severity = silent
15381538

1539+
# IDE0190: Null check can be simplified
1540+
dotnet_diagnostic.IDE0190.severity = silent
1541+
15391542
# IDE1005: Delegate invocation can be simplified.
15401543
dotnet_diagnostic.IDE1005.severity = silent
15411544

eng/Versions.props

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<UsingToolIbcOptimization>false</UsingToolIbcOptimization>
2121
<UsingToolXliff>false</UsingToolXliff>
2222
<LastReleasedStableAssemblyVersion>$(AssemblyVersion)</LastReleasedStableAssemblyVersion>
23+
<UsingToolMicrosoftNetCompilers>true</UsingToolMicrosoftNetCompilers>
2324
</PropertyGroup>
2425
<!--
2526
Servicing build settings for Setup/Installer packages. Instructions:
@@ -51,6 +52,8 @@
5152
<MicrosoftCodeAnalysisCSharpCodeStyleVersion>4.0.1</MicrosoftCodeAnalysisCSharpCodeStyleVersion>
5253
<MicrosoftCodeAnalysisCSharpVersion>4.0.1</MicrosoftCodeAnalysisCSharpVersion>
5354
<MicrosoftCodeAnalysisNetAnalyzersVersion>7.0.0-preview1.22102.1</MicrosoftCodeAnalysisNetAnalyzersVersion>
55+
<!-- TODO: Remove pinned compiler version once arcade supplies runtime with a compiler capable of handling !! -->
56+
<MicrosoftNetCompilersToolsetVersion>4.2.0-2.22105.4</MicrosoftNetCompilersToolsetVersion>
5457
<!-- SDK dependencies -->
5558
<MicrosoftDotNetCompatibilityVersion>2.0.0-alpha.1.21525.11</MicrosoftDotNetCompatibilityVersion>
5659
<!-- Arcade dependencies -->

src/coreclr/System.Private.CoreLib/src/Microsoft/Win32/OAVariantLib.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,8 @@ internal static class OAVariantLib
7272
* Variant and the types that CLR supports explicitly in the
7373
* CLR Variant class.
7474
*/
75-
internal static Variant ChangeType(Variant source, Type targetClass, short options, CultureInfo culture)
75+
internal static Variant ChangeType(Variant source, Type targetClass!!, short options, CultureInfo culture!!)
7676
{
77-
if (targetClass == null)
78-
throw new ArgumentNullException(nameof(targetClass));
79-
if (culture == null)
80-
throw new ArgumentNullException(nameof(culture));
8177
Variant result = default;
8278
ChangeTypeEx(ref result, ref source,
8379
culture.LCID,

src/coreclr/System.Private.CoreLib/src/System/Attribute.CoreCLR.cs

Lines changed: 12 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -450,14 +450,8 @@ public static Attribute[] GetCustomAttributes(MemberInfo element, Type attribute
450450
return GetCustomAttributes(element, attributeType, true);
451451
}
452452

453-
public static Attribute[] GetCustomAttributes(MemberInfo element, Type attributeType, bool inherit)
453+
public static Attribute[] GetCustomAttributes(MemberInfo element!!, Type attributeType!!, bool inherit)
454454
{
455-
if (element == null)
456-
throw new ArgumentNullException(nameof(element));
457-
458-
if (attributeType == null)
459-
throw new ArgumentNullException(nameof(attributeType));
460-
461455
if (!attributeType.IsSubclassOf(typeof(Attribute)) && attributeType != typeof(Attribute))
462456
throw new ArgumentException(SR.Argument_MustHaveAttributeBaseClass);
463457

@@ -474,11 +468,8 @@ public static Attribute[] GetCustomAttributes(MemberInfo element)
474468
return GetCustomAttributes(element, true);
475469
}
476470

477-
public static Attribute[] GetCustomAttributes(MemberInfo element, bool inherit)
471+
public static Attribute[] GetCustomAttributes(MemberInfo element!!, bool inherit)
478472
{
479-
if (element == null)
480-
throw new ArgumentNullException(nameof(element));
481-
482473
return element.MemberType switch
483474
{
484475
MemberTypes.Property => InternalGetCustomAttributes((PropertyInfo)element, typeof(Attribute), inherit),
@@ -492,15 +483,9 @@ public static bool IsDefined(MemberInfo element, Type attributeType)
492483
return IsDefined(element, attributeType, true);
493484
}
494485

495-
public static bool IsDefined(MemberInfo element, Type attributeType, bool inherit)
486+
public static bool IsDefined(MemberInfo element!!, Type attributeType!!, bool inherit)
496487
{
497488
// Returns true if a custom attribute subclass of attributeType class/interface with inheritance walk
498-
if (element == null)
499-
throw new ArgumentNullException(nameof(element));
500-
501-
if (attributeType == null)
502-
throw new ArgumentNullException(nameof(attributeType));
503-
504489
if (!attributeType.IsSubclassOf(typeof(Attribute)) && attributeType != typeof(Attribute))
505490
throw new ArgumentException(SR.Argument_MustHaveAttributeBaseClass);
506491

@@ -543,14 +528,8 @@ public static Attribute[] GetCustomAttributes(ParameterInfo element, Type attrib
543528
return GetCustomAttributes(element, attributeType, true);
544529
}
545530

546-
public static Attribute[] GetCustomAttributes(ParameterInfo element, Type attributeType, bool inherit)
531+
public static Attribute[] GetCustomAttributes(ParameterInfo element!!, Type attributeType!!, bool inherit)
547532
{
548-
if (element == null)
549-
throw new ArgumentNullException(nameof(element));
550-
551-
if (attributeType == null)
552-
throw new ArgumentNullException(nameof(attributeType));
553-
554533
if (!attributeType.IsSubclassOf(typeof(Attribute)) && attributeType != typeof(Attribute))
555534
throw new ArgumentException(SR.Argument_MustHaveAttributeBaseClass);
556535

@@ -565,11 +544,8 @@ public static Attribute[] GetCustomAttributes(ParameterInfo element, Type attrib
565544
return (element.GetCustomAttributes(attributeType, inherit) as Attribute[])!;
566545
}
567546

568-
public static Attribute[] GetCustomAttributes(ParameterInfo element, bool inherit)
547+
public static Attribute[] GetCustomAttributes(ParameterInfo element!!, bool inherit)
569548
{
570-
if (element == null)
571-
throw new ArgumentNullException(nameof(element));
572-
573549
if (element.Member == null)
574550
throw new ArgumentException(SR.Argument_InvalidParameterInfo, nameof(element));
575551

@@ -586,14 +562,9 @@ public static bool IsDefined(ParameterInfo element, Type attributeType)
586562
return IsDefined(element, attributeType, true);
587563
}
588564

589-
public static bool IsDefined(ParameterInfo element, Type attributeType, bool inherit)
565+
public static bool IsDefined(ParameterInfo element!!, Type attributeType!!, bool inherit)
590566
{
591567
// Returns true is a custom attribute subclass of attributeType class/interface with inheritance walk
592-
if (element == null)
593-
throw new ArgumentNullException(nameof(element));
594-
595-
if (attributeType == null)
596-
throw new ArgumentNullException(nameof(attributeType));
597568

598569
if (!attributeType.IsSubclassOf(typeof(Attribute)) && attributeType != typeof(Attribute))
599570
throw new ArgumentException(SR.Argument_MustHaveAttributeBaseClass);
@@ -653,22 +624,13 @@ public static Attribute[] GetCustomAttributes(Module element)
653624
return GetCustomAttributes(element, true);
654625
}
655626

656-
public static Attribute[] GetCustomAttributes(Module element, bool inherit)
627+
public static Attribute[] GetCustomAttributes(Module element!!, bool inherit)
657628
{
658-
if (element == null)
659-
throw new ArgumentNullException(nameof(element));
660-
661629
return (Attribute[])element.GetCustomAttributes(typeof(Attribute), inherit);
662630
}
663631

664-
public static Attribute[] GetCustomAttributes(Module element, Type attributeType, bool inherit)
632+
public static Attribute[] GetCustomAttributes(Module element!!, Type attributeType!!, bool inherit)
665633
{
666-
if (element == null)
667-
throw new ArgumentNullException(nameof(element));
668-
669-
if (attributeType == null)
670-
throw new ArgumentNullException(nameof(attributeType));
671-
672634
if (!attributeType.IsSubclassOf(typeof(Attribute)) && attributeType != typeof(Attribute))
673635
throw new ArgumentException(SR.Argument_MustHaveAttributeBaseClass);
674636

@@ -680,14 +642,9 @@ public static bool IsDefined(Module element, Type attributeType)
680642
return IsDefined(element, attributeType, false);
681643
}
682644

683-
public static bool IsDefined(Module element, Type attributeType, bool inherit)
645+
public static bool IsDefined(Module element!!, Type attributeType!!, bool inherit)
684646
{
685647
// Returns true is a custom attribute subclass of attributeType class/interface with no inheritance walk
686-
if (element == null)
687-
throw new ArgumentNullException(nameof(element));
688-
689-
if (attributeType == null)
690-
throw new ArgumentNullException(nameof(attributeType));
691648

692649
if (!attributeType.IsSubclassOf(typeof(Attribute)) && attributeType != typeof(Attribute))
693650
throw new ArgumentException(SR.Argument_MustHaveAttributeBaseClass);
@@ -723,14 +680,8 @@ public static Attribute[] GetCustomAttributes(Assembly element, Type attributeTy
723680
return GetCustomAttributes(element, attributeType, true);
724681
}
725682

726-
public static Attribute[] GetCustomAttributes(Assembly element, Type attributeType, bool inherit)
683+
public static Attribute[] GetCustomAttributes(Assembly element!!, Type attributeType!!, bool inherit)
727684
{
728-
if (element == null)
729-
throw new ArgumentNullException(nameof(element));
730-
731-
if (attributeType == null)
732-
throw new ArgumentNullException(nameof(attributeType));
733-
734685
if (!attributeType.IsSubclassOf(typeof(Attribute)) && attributeType != typeof(Attribute))
735686
throw new ArgumentException(SR.Argument_MustHaveAttributeBaseClass);
736687

@@ -742,11 +693,8 @@ public static Attribute[] GetCustomAttributes(Assembly element)
742693
return GetCustomAttributes(element, true);
743694
}
744695

745-
public static Attribute[] GetCustomAttributes(Assembly element, bool inherit)
696+
public static Attribute[] GetCustomAttributes(Assembly element!!, bool inherit)
746697
{
747-
if (element == null)
748-
throw new ArgumentNullException(nameof(element));
749-
750698
return (Attribute[])element.GetCustomAttributes(typeof(Attribute), inherit);
751699
}
752700

@@ -755,14 +703,9 @@ public static bool IsDefined(Assembly element, Type attributeType)
755703
return IsDefined(element, attributeType, true);
756704
}
757705

758-
public static bool IsDefined(Assembly element, Type attributeType, bool inherit)
706+
public static bool IsDefined(Assembly element!!, Type attributeType!!, bool inherit)
759707
{
760708
// Returns true is a custom attribute subclass of attributeType class/interface with no inheritance walk
761-
if (element == null)
762-
throw new ArgumentNullException(nameof(element));
763-
764-
if (attributeType == null)
765-
throw new ArgumentNullException(nameof(attributeType));
766709

767710
if (!attributeType.IsSubclassOf(typeof(Attribute)) && attributeType != typeof(Attribute))
768711
throw new ArgumentException(SR.Argument_MustHaveAttributeBaseClass);

src/coreclr/System.Private.CoreLib/src/System/Collections/EmptyReadOnlyDictionaryInternal.cs

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,8 @@ IEnumerator IEnumerable.GetEnumerator()
3333

3434
// ICollection members
3535

36-
public void CopyTo(Array array, int index)
36+
public void CopyTo(Array array!!, int index)
3737
{
38-
if (array == null)
39-
throw new ArgumentNullException(nameof(array));
40-
4138
if (array.Rank != 1)
4239
throw new ArgumentException(SR.Arg_RankMultiDimNotSupported);
4340

@@ -58,23 +55,14 @@ public void CopyTo(Array array, int index)
5855

5956
// IDictionary members
6057

61-
public object? this[object key]
58+
public object? this[object key!!]
6259
{
6360
get
6461
{
65-
if (key == null)
66-
{
67-
throw new ArgumentNullException(nameof(key), SR.ArgumentNull_Key);
68-
}
6962
return null;
7063
}
7164
set
7265
{
73-
if (key == null)
74-
{
75-
throw new ArgumentNullException(nameof(key), SR.ArgumentNull_Key);
76-
}
77-
7866
if (!key.GetType().IsSerializable)
7967
throw new ArgumentException(SR.Argument_NotSerializable, nameof(key));
8068

@@ -94,13 +82,8 @@ public bool Contains(object key)
9482
return false;
9583
}
9684

97-
public void Add(object key, object? value)
85+
public void Add(object key!!, object? value)
9886
{
99-
if (key == null)
100-
{
101-
throw new ArgumentNullException(nameof(key), SR.ArgumentNull_Key);
102-
}
103-
10487
if (!key.GetType().IsSerializable)
10588
throw new ArgumentException(SR.Argument_NotSerializable, nameof(key));
10689

src/coreclr/System.Private.CoreLib/src/System/Delegate.CoreCLR.cs

Lines changed: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,8 @@ public abstract partial class Delegate : ICloneable, ISerializable
3434
// This constructor is called from the class generated by the
3535
// compiler generated code
3636
[RequiresUnreferencedCode("The target method might be removed")]
37-
protected Delegate(object target, string method)
37+
protected Delegate(object target!!, string method!!)
3838
{
39-
if (target == null)
40-
throw new ArgumentNullException(nameof(target));
41-
42-
if (method == null)
43-
throw new ArgumentNullException(nameof(method));
44-
4539
// This API existed in v1/v1.1 and only expected to create closed
4640
// instance delegates. Constrain the call to BindToMethodName to
4741
// such and don't allow relaxed signature matching (which could make
@@ -57,17 +51,10 @@ protected Delegate(object target, string method)
5751
// This constructor is called from a class to generate a
5852
// delegate based upon a static method name and the Type object
5953
// for the class defining the method.
60-
protected Delegate([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type target, string method)
54+
protected Delegate([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type target!!, string method!!)
6155
{
62-
if (target == null)
63-
throw new ArgumentNullException(nameof(target));
64-
6556
if (target.ContainsGenericParameters)
6657
throw new ArgumentException(SR.Arg_UnboundGenParam, nameof(target));
67-
68-
if (method == null)
69-
throw new ArgumentNullException(nameof(method));
70-
7158
if (!(target is RuntimeType rtTarget))
7259
throw new ArgumentException(SR.Argument_MustBeRuntimeType, nameof(target));
7360

@@ -220,15 +207,8 @@ protected virtual MethodInfo GetMethodImpl()
220207

221208
// V1 API.
222209
[RequiresUnreferencedCode("The target method might be removed")]
223-
public static Delegate? CreateDelegate(Type type, object target, string method, bool ignoreCase, bool throwOnBindFailure)
210+
public static Delegate? CreateDelegate(Type type!!, object target!!, string method!!, bool ignoreCase, bool throwOnBindFailure)
224211
{
225-
if (type == null)
226-
throw new ArgumentNullException(nameof(type));
227-
if (target == null)
228-
throw new ArgumentNullException(nameof(target));
229-
if (method == null)
230-
throw new ArgumentNullException(nameof(method));
231-
232212
if (!(type is RuntimeType rtType))
233213
throw new ArgumentException(SR.Argument_MustBeRuntimeType, nameof(type));
234214
if (!rtType.IsDelegate())
@@ -258,17 +238,10 @@ protected virtual MethodInfo GetMethodImpl()
258238
}
259239

260240
// V1 API.
261-
public static Delegate? CreateDelegate(Type type, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type target, string method, bool ignoreCase, bool throwOnBindFailure)
241+
public static Delegate? CreateDelegate(Type type!!, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type target!!, string method!!, bool ignoreCase, bool throwOnBindFailure)
262242
{
263-
if (type == null)
264-
throw new ArgumentNullException(nameof(type));
265-
if (target == null)
266-
throw new ArgumentNullException(nameof(target));
267243
if (target.ContainsGenericParameters)
268244
throw new ArgumentException(SR.Arg_UnboundGenParam, nameof(target));
269-
if (method == null)
270-
throw new ArgumentNullException(nameof(method));
271-
272245
if (!(type is RuntimeType rtType))
273246
throw new ArgumentException(SR.Argument_MustBeRuntimeType, nameof(type));
274247
if (!(target is RuntimeType rtTarget))
@@ -297,13 +270,9 @@ protected virtual MethodInfo GetMethodImpl()
297270
}
298271

299272
// V1 API.
300-
public static Delegate? CreateDelegate(Type type, MethodInfo method, bool throwOnBindFailure)
273+
public static Delegate? CreateDelegate(Type type!!, MethodInfo method!!, bool throwOnBindFailure)
301274
{
302275
// Validate the parameters.
303-
if (type == null)
304-
throw new ArgumentNullException(nameof(type));
305-
if (method == null)
306-
throw new ArgumentNullException(nameof(method));
307276

308277
if (!(type is RuntimeType rtType))
309278
throw new ArgumentException(SR.Argument_MustBeRuntimeType, nameof(type));
@@ -374,11 +343,9 @@ protected virtual MethodInfo GetMethodImpl()
374343
//
375344

376345
// V2 internal API.
377-
internal static Delegate CreateDelegateNoSecurityCheck(Type type, object? target, RuntimeMethodHandle method)
346+
internal static Delegate CreateDelegateNoSecurityCheck(Type type!!, object? target, RuntimeMethodHandle method)
378347
{
379348
// Validate the parameters.
380-
if (type == null)
381-
throw new ArgumentNullException(nameof(type));
382349

383350
if (method.IsNullHandle())
384351
throw new ArgumentNullException(nameof(method));

0 commit comments

Comments
 (0)