Skip to content

[release/7.0-preview5] Refactoring the generic-math CreateChecked/Saturating/Truncating APIs to match API review #70034

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
73b1bce
Update MicrosoftNetCompilersToolsetVersion to 4.3.0-2.22270.4
tannergooding May 24, 2022
5c3094d
Moving System.Runtime.InteropServices.NFloat down to System.Runtime
tannergooding May 24, 2022
fa4c37b
Removing the generic-math CreateChecked, CreateSaturating, CreateTrun…
tannergooding May 24, 2022
1ff63d9
Removing the generic-math TryCreate tests
tannergooding May 24, 2022
418d6bf
Adding the TryConvertTo* and TryConvertFrom* generic math APIs for Ch…
tannergooding May 24, 2022
e828b1a
Filling out test coverage for the CreateChecked generic-math API
tannergooding May 24, 2022
dd70e10
Fix some edge cases for the CreateSaturating generic-math APIs
tannergooding May 24, 2022
6299de1
Filling out test coverage for the CreateSaturating generic-math API
tannergooding May 24, 2022
39cb560
Fix some edge cases for the CreateTruncating generic-math APIs
tannergooding May 25, 2022
62eb36f
Filling out test coverage for the CreateTruncating generic-math API
tannergooding May 25, 2022
848008d
Fixing some edge cases in converting BigInteger/Complex to the primit…
tannergooding May 25, 2022
4cdae9d
Filling out test coverage for converting BigInteger and Complex to th…
tannergooding May 25, 2022
b6391a0
Fixing some 32-bit generic-math tests
tannergooding May 25, 2022
0295996
Removing the static virtual declarations since things are falling over
tannergooding May 25, 2022
cbd2ec3
Skipping some tests on Mono where it has bad behavior
tannergooding May 25, 2022
d6b0a18
Revert "Removing the static virtual declarations since things are fal…
tannergooding May 26, 2022
4a317e2
Move NFloat back to System.Runtime.InteropServices based on feedback
tannergooding May 26, 2022
9ba7574
Fixing the Int128/UInt128 to Decimal tests
tannergooding May 26, 2022
bafd958
Ensure `JIT_Dbl2ULng` correctly handles NaN
tannergooding May 27, 2022
dc5dd04
Revert "Ensure `JIT_Dbl2ULng` correctly handles NaN"
tannergooding May 27, 2022
3a46868
Explicitly ensure floating-point to ulong conversion returns 0 for NaN
tannergooding May 27, 2022
b99bfd7
Add default method support to virtual statics (#69783)
MichalStrehovsky May 26, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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