Skip to content

Commit 425fedc

Browse files
github-actions[bot]tannergoodingMichalStrehovsky
authored
[release/7.0-preview5] Refactoring the generic-math CreateChecked/Saturating/Truncating APIs to match API review (dotnet#70034)
* Update MicrosoftNetCompilersToolsetVersion to 4.3.0-2.22270.4 * Moving System.Runtime.InteropServices.NFloat down to System.Runtime * Removing the generic-math CreateChecked, CreateSaturating, CreateTruncating, and TryCreate implementations * Removing the generic-math TryCreate tests * Adding the TryConvertTo* and TryConvertFrom* generic math APIs for Checked, Saturating, and Truncating * Filling out test coverage for the CreateChecked generic-math API * Fix some edge cases for the CreateSaturating generic-math APIs * Filling out test coverage for the CreateSaturating generic-math API * Fix some edge cases for the CreateTruncating generic-math APIs * Filling out test coverage for the CreateTruncating generic-math API * Fixing some edge cases in converting BigInteger/Complex to the primitive types * Filling out test coverage for converting BigInteger and Complex to the primitive types * Fixing some 32-bit generic-math tests * Removing the static virtual declarations since things are falling over * Skipping some tests on Mono where it has bad behavior * Revert "Removing the static virtual declarations since things are falling over" This reverts commit baf69de. * Move NFloat back to System.Runtime.InteropServices based on feedback * Fixing the Int128/UInt128 to Decimal tests * Ensure `JIT_Dbl2ULng` correctly handles NaN * Revert "Ensure `JIT_Dbl2ULng` correctly handles NaN" This reverts commit 3298345. * Explicitly ensure floating-point to ulong conversion returns 0 for NaN * Add default method support to virtual statics (dotnet#69783) Corresponds to dotnet#64717 that I somehow missed, despite commenting on it. We still don't allow interfaces to implement methods of other interfaces. The CLR VM doesn't allow either. Co-authored-by: Tanner Gooding <tagoo@outlook.com> Co-authored-by: Michal Strehovský <MichalStrehovsky@users.noreply.github.com>
1 parent e8dfdb0 commit 425fedc

Some content is hidden

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

53 files changed

+17340
-11327
lines changed

eng/Versions.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
<!--
5050
TODO: Remove pinned version once arcade supplies a 4.3 compiler.
5151
-->
52-
<MicrosoftNetCompilersToolsetVersion>4.3.0-2.22270.2</MicrosoftNetCompilersToolsetVersion>
52+
<MicrosoftNetCompilersToolsetVersion>4.3.0-2.22270.4</MicrosoftNetCompilersToolsetVersion>
5353
<!-- SDK dependencies -->
5454
<MicrosoftDotNetCompatibilityVersion>2.0.0-preview.4.22252.4</MicrosoftDotNetCompatibilityVersion>
5555
<!-- Arcade dependencies -->

src/coreclr/tools/Common/Compiler/TypeExtensions.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,16 @@ public static MethodDesc TryResolveConstraintMethodApprox(this TypeDesc constrai
562562
method = null;
563563
}
564564

565+
// Default implementation logic, which only kicks in for default implementations when looking up on an exact interface target
566+
if (isStaticVirtualMethod && method == null && !genInterfaceMethod.IsAbstract && !constrainedType.IsCanonicalSubtype(CanonicalFormKind.Any))
567+
{
568+
MethodDesc exactInterfaceMethod = genInterfaceMethod;
569+
if (genInterfaceMethod.OwningType != interfaceType)
570+
exactInterfaceMethod = context.GetMethodForInstantiatedType(
571+
genInterfaceMethod.GetTypicalMethodDefinition(), (InstantiatedType)interfaceType);
572+
method = exactInterfaceMethod;
573+
}
574+
565575
if (method == null)
566576
{
567577
// Fall back to VSD

src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/GenericLookupResult.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1438,6 +1438,10 @@ public override ISymbolNode GetTarget(NodeFactory factory, GenericLookupResultCo
14381438
if (instantiatedConstrainedMethod.Signature.IsStatic)
14391439
{
14401440
implMethod = instantiatedConstraintType.GetClosestDefType().ResolveVariantInterfaceMethodToStaticVirtualMethodOnType(instantiatedConstrainedMethod);
1441+
if (implMethod == null && !instantiatedConstrainedMethod.IsAbstract)
1442+
{
1443+
implMethod = instantiatedConstrainedMethod;
1444+
}
14411445
}
14421446
else
14431447
{
@@ -1451,7 +1455,6 @@ public override ISymbolNode GetTarget(NodeFactory factory, GenericLookupResultCo
14511455

14521456
// AOT use of this generic lookup is restricted to finding methods on valuetypes (runtime usage of this slot in universal generics is more flexible)
14531457
Debug.Assert(instantiatedConstraintType.IsValueType || (instantiatedConstrainedMethod.OwningType.IsInterface && instantiatedConstrainedMethod.Signature.IsStatic));
1454-
Debug.Assert(!instantiatedConstraintType.IsValueType || implMethod.OwningType == instantiatedConstraintType);
14551458

14561459
if (implMethod.Signature.IsStatic)
14571460
{

src/coreclr/tools/aot/ILCompiler.Compiler/IL/ILImporter.Scanner.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,8 @@ private void ImportCall(ILOpcode opcode, int token)
424424

425425
methodAfterConstraintResolution = directMethod;
426426

427-
Debug.Assert(!methodAfterConstraintResolution.OwningType.IsInterface);
427+
Debug.Assert(!methodAfterConstraintResolution.OwningType.IsInterface
428+
|| methodAfterConstraintResolution.Signature.IsStatic);
428429
resolvedConstraint = true;
429430

430431
exactType = constrained;

src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1203,7 +1203,8 @@ private void getCallInfo(ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_RESO
12031203

12041204
methodAfterConstraintResolution = directMethod;
12051205

1206-
Debug.Assert(!methodAfterConstraintResolution.OwningType.IsInterface);
1206+
Debug.Assert(!methodAfterConstraintResolution.OwningType.IsInterface
1207+
|| methodAfterConstraintResolution.Signature.IsStatic);
12071208
resolvedConstraint = true;
12081209
pResult->thisTransform = CORINFO_THIS_TRANSFORM.CORINFO_NO_THIS_TRANSFORM;
12091210

src/coreclr/vm/methodtable.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8067,7 +8067,7 @@ MethodTable::ResolveVirtualStaticMethod(MethodTable* pInterfaceType, MethodDesc*
80678067
}
80688068
}
80698069

8070-
// Default implementation logic, which only kicks in for default implementations when lookin up on an exact interface target
8070+
// Default implementation logic, which only kicks in for default implementations when looking up on an exact interface target
80718071
if (!pInterfaceMD->IsAbstract() && !(this == g_pCanonMethodTableClass) && !IsSharedByGenericInstantiations())
80728072
{
80738073
return pInterfaceMD->FindOrCreateAssociatedMethodDesc(pInterfaceMD, pInterfaceType, FALSE, pInterfaceMD->GetMethodInstantiation(), FALSE);

src/libraries/Common/tests/System/GenericMathHelpers.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,6 @@ public static TSelf CreateTruncating<TOther>(TOther value)
358358

359359
public static TSelf Parse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider provider) => TSelf.Parse(s, style, provider);
360360

361-
public static bool TryCreate<TOther>(TOther value, out TSelf result)
362-
where TOther : INumberBase<TOther> => TSelf.TryCreate(value, out result);
363-
364361
public static bool TryParse(string s, NumberStyles style, IFormatProvider provider, out TSelf result) => TSelf.TryParse(s, style, provider, out result);
365362

366363
public static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider provider, out TSelf result) => TSelf.TryParse(s, style, provider, out result);

0 commit comments

Comments
 (0)