Skip to content

Commit

Permalink
[release/7.0-preview5] Refactoring the generic-math CreateChecked/Sat…
Browse files Browse the repository at this point in the history
…urating/Truncating APIs to match API review (#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 (#69783)

Corresponds to #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 <[email protected]>
Co-authored-by: Michal Strehovský <[email protected]>
  • Loading branch information
3 people authored Jun 2, 2022
1 parent e8dfdb0 commit 425fedc
Show file tree
Hide file tree
Showing 53 changed files with 17,340 additions and 11,327 deletions.
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<!--
TODO: Remove pinned version once arcade supplies a 4.3 compiler.
-->
<MicrosoftNetCompilersToolsetVersion>4.3.0-2.22270.2</MicrosoftNetCompilersToolsetVersion>
<MicrosoftNetCompilersToolsetVersion>4.3.0-2.22270.4</MicrosoftNetCompilersToolsetVersion>
<!-- SDK dependencies -->
<MicrosoftDotNetCompatibilityVersion>2.0.0-preview.4.22252.4</MicrosoftDotNetCompatibilityVersion>
<!-- Arcade dependencies -->
Expand Down
10 changes: 10 additions & 0 deletions src/coreclr/tools/Common/Compiler/TypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,16 @@ public static MethodDesc TryResolveConstraintMethodApprox(this TypeDesc constrai
method = null;
}

// Default implementation logic, which only kicks in for default implementations when looking up on an exact interface target
if (isStaticVirtualMethod && method == null && !genInterfaceMethod.IsAbstract && !constrainedType.IsCanonicalSubtype(CanonicalFormKind.Any))
{
MethodDesc exactInterfaceMethod = genInterfaceMethod;
if (genInterfaceMethod.OwningType != interfaceType)
exactInterfaceMethod = context.GetMethodForInstantiatedType(
genInterfaceMethod.GetTypicalMethodDefinition(), (InstantiatedType)interfaceType);
method = exactInterfaceMethod;
}

if (method == null)
{
// Fall back to VSD
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1438,6 +1438,10 @@ public override ISymbolNode GetTarget(NodeFactory factory, GenericLookupResultCo
if (instantiatedConstrainedMethod.Signature.IsStatic)
{
implMethod = instantiatedConstraintType.GetClosestDefType().ResolveVariantInterfaceMethodToStaticVirtualMethodOnType(instantiatedConstrainedMethod);
if (implMethod == null && !instantiatedConstrainedMethod.IsAbstract)
{
implMethod = instantiatedConstrainedMethod;
}
}
else
{
Expand All @@ -1451,7 +1455,6 @@ public override ISymbolNode GetTarget(NodeFactory factory, GenericLookupResultCo

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

if (implMethod.Signature.IsStatic)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,8 @@ private void ImportCall(ILOpcode opcode, int token)

methodAfterConstraintResolution = directMethod;

Debug.Assert(!methodAfterConstraintResolution.OwningType.IsInterface);
Debug.Assert(!methodAfterConstraintResolution.OwningType.IsInterface
|| methodAfterConstraintResolution.Signature.IsStatic);
resolvedConstraint = true;

exactType = constrained;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1203,7 +1203,8 @@ private void getCallInfo(ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_RESO

methodAfterConstraintResolution = directMethod;

Debug.Assert(!methodAfterConstraintResolution.OwningType.IsInterface);
Debug.Assert(!methodAfterConstraintResolution.OwningType.IsInterface
|| methodAfterConstraintResolution.Signature.IsStatic);
resolvedConstraint = true;
pResult->thisTransform = CORINFO_THIS_TRANSFORM.CORINFO_NO_THIS_TRANSFORM;

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/methodtable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8067,7 +8067,7 @@ MethodTable::ResolveVirtualStaticMethod(MethodTable* pInterfaceType, MethodDesc*
}
}

// Default implementation logic, which only kicks in for default implementations when lookin up on an exact interface target
// Default implementation logic, which only kicks in for default implementations when looking up on an exact interface target
if (!pInterfaceMD->IsAbstract() && !(this == g_pCanonMethodTableClass) && !IsSharedByGenericInstantiations())
{
return pInterfaceMD->FindOrCreateAssociatedMethodDesc(pInterfaceMD, pInterfaceType, FALSE, pInterfaceMD->GetMethodInstantiation(), FALSE);
Expand Down
3 changes: 0 additions & 3 deletions src/libraries/Common/tests/System/GenericMathHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,6 @@ public static TSelf CreateTruncating<TOther>(TOther value)

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

public static bool TryCreate<TOther>(TOther value, out TSelf result)
where TOther : INumberBase<TOther> => TSelf.TryCreate(value, out result);

public static bool TryParse(string s, NumberStyles style, IFormatProvider provider, out TSelf result) => TSelf.TryParse(s, style, provider, out result);

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

0 comments on commit 425fedc

Please sign in to comment.